|
START LEARNING
FLASH NOW
|
|
Get instant access to over
45 minutes of FREE Flash
tutorials on video
and our newsletter.
|
.
.
.
. .
|
3d Engine Design Deconstruction
This tutorial uses the blast3d engine written in C by tobias johansson
, as a learning experience for me and for
my readers. I will attempt to pull apart this engine and make it work in Flash, and to make it in an OOP structure.
This page is a description of the classes members and methods.
Vector3d class
| Class | Member Variables | Type | Description |
| Vector3d | x | Number | posn |
| | y | Number | " |
| | z | Number | " |
| Class | Methods | Returns | Description |
| Vector3d | addVecNew(vec) | Vector3d | Add 2 vectors |
| | minVecNew(vec) | Vector3d | subtraction |
| | magnitude(vec) | Number | length of vector |
| | normalize(vec) | Void | Divides x,y,z by it magnitude |
| | dot(vec) | Number | returns cosine of angle between vectors |
| | cross(vec) | Vector3d | returns vector perpendicular to both vectors |
| | distance(vec) | Number | Distance between 2 vectors |
Flash Tutorials in Video Format -
Watch them now at LearnFlash.com
Matrix class
3x3 matrix
| Class | Methods | Returns | Description |
| Matrix | ident() | Void | Sets the matrix to an identity matrix |
| | copyMatrix(dest) | Void | copies this to dest matrix |
| | mult(matrix) | Matrix | return = this * matrix |
| Class | Member Variables | Type | Description |
| Screen3d | x | Number | screen coords |
| | y | Number | |
| | z | Number | |
| | u | Number | texture coords |
| | v | Number | |
| Class | Member Variables | Type | Description |
| TexCoord2d | u | Number | Texture coord |
| | v | Number | " |
| | r | Number | red |
| | g | Number | green |
| | b | Number | blue |
| | a | Number | |
| Class | Member Variables | Type | Description |
| Poly3d | numverts | Number | Number of vertices |
| | vertices[ ] | Array | Array the size of max verts |
| | txtcoords[] | Array | " |
| | normal | Vector3d | Poly's normal |
| | flag | Number | |
| | colour | Number | |
| | texture | Number | |
| | textflags | Number | |
| | shade | Number | |
| | r | Number | red |
| | g | Number | green |
| | b | Number | blue |
| Class | Member Variables | Type | Description |
| PolyClipped | numverts | Number | number of vertices |
| | vertices[] | Screen3d Array | maxverts size |
| | txtcoords | Texcoord2d Array | " |
| | fillflags | Number | shader flag |
| | colour | Number | colour |
| | texture | Number | texture |
| | average_z | Number | Average z value for face |
| Class | Member Variables | Type | Description |
| Movement | flags | Number | flag settings |
| | xrot | " | rotation increments |
| | yrot | " | " |
| | zrot | " | " |
| | xinc | " | translation increments |
| | yinc | " | " |
| | zinc | " | " |
Object3d class
| Class | Member Variables | Type | Description |
| Object3d | numVerts | Number | Number of vertices |
| | numPolys | Number | Number of ploygons |
| | original | Vector3d | Original v3d |
| | transformed | Vector3d | rotated, translated |
| | projected | Screen3d | Calculated for screen coords |
| | polys | Poly3d | polygons |
| | maxradius | Number | Max radius for frustum sphere |
| | radius | Number | Actual radius of frustum |
| | flags | Number | settings |
| | position | Vector3d | posn |
| | angle | Vector3d | angle |
| | movement | Movement | Movement controller |
| | numFrames | Number | ? |
| | currFrame | Number | ? |
| Class | Methods | Returns | Description |
| Object3d | Object3d(numverts,numpolys,numframes) | Constructor | |
| | tranWorld( ) | Void | Transform the points form object to world coords |
| | tranView() | Void | world to view transform |
| | cull( ) | Void | backface culling |
| | project(object3d) | Void | Projects the object |
| | render(bmp,object3d , color) | Void | Render object on buffer, color only used for dotrendering |
| | move(object3d ) | Void | Moves an objects according to its movement_controller |
| | zclip(object3d) | Void | zclip the object |
| | init(object3d) | Void | Calculates the radius of the object |
| | loadasc(filename,object3d , scale) | Void | Loads an ascii object file |
| | reversewinding(object3d ) | Void | Reverses winding of polygons (doesn't work) |
| | showinfo(bmp, object3d ) | Void | Shows some info about the object |
| | checksphere(obj) | Void | Test the object against the frustum and turns it off if outside |
| | | | |
| | | | |
Plane3d
| Class | Member Variables | Type | Description |
| Plane3d | normal | vector3d | normal to the plane |
| | distance | Number | distance |
| | | | |
| | | | |
| | | | |
Camera
| Class | Member Variables | Type | Description |
| Camera | fov | Number | field of view |
| | flags | Number | settings |
| | positions | Vector3d | posn |
| | angle | Vector3d | angle |
| | forward | Number | axes |
| | right | Number | " |
| | down | Number | " |
| Class | Methods | Returns | Description |
| Camera | setsize(width, height) | Void | Set the size of the screen |
| | setfov( fov) | Void | set the fov |
| | setpos( x, y, z) | Void | set the position |
| | setang(x, y, z) | Void | set the angle |
| | setflags( flags) | Void | set the flags settings |
| | usethiscam(cam) | Void | set the cam to this camera |
| | moveforward(howmuch) | Void | move the cam forward |
| | movebackward(howmuch) | Void | move back |
| | makecameramatrix() | Void | Creates the camera matrix |
| | getcamera(cam) | Void | sets the current position etc into cam |
| | movecamera(right,down,forward) | Void | move cam |
Engine class
| Class | Member Variables | Type | Description |
| Engine | matrix | Matrix | |
| | | | |
| | | | |
| | | | |
| | | | |
| Class | Methods | Type | Description |
| Engine | setnearfar(near, far) | Void | Set near-far clip planes |
| | init() | Void | init engine |
| | shut() | Void | Shuts it down(deallocates memory?) |
| | setambientlight(ltNum) | Void | Set the ambient lightlevel |
| | setlightsource(lightVec) | Void | Set posn of light to be used |
| | setlightcolor(r,g,b) | Void | Set the color of the light |
| | setclipborders(left,top,right,bottom) | Void | Set the borders for 2d - clipping |
| | newframe() | Void | Call this every new frame (clear the zbuffer etc) |
| | error(msg, type) | Void | Handles errors |
| | setfog(fogdiv,r,g,b) | Void | Set the fog properties |
| | polygonDRAW(bmp,verts,numverts,color) | Void | Draws a singlecolored polygon |
| | polygonTEXTUREDRAW(bmp,verts,numverts,texture,flags) | Void | Draw a texturemapped polygon |
| | add_texture(fname) | Void | Adds a texture to the texture list |
| | destroy_all_textures() | Void | Destroy (deallocates) all textures in memory |
| | add_to_poly_list(verts, txtc,numverts,fillflags,color,texture) | Void | Adds a polygon to the global polygon list |
| | polygon_clip(obj,nump,out,flags) | Void | Clip the polygon with the index nump of object obj and stores it in out |
| | plane3d_construct(p, va, vb, vc) | Void | Constructs a plane from three points |
| | setup_frustum(FOV,sizex,sizey) | Void | Creates a frustum; sizex, sizey is screen size (320,240) |
| | render_poly_list(bmp) | Void | Render all the poly's in the polylist |
Go to the next phase
|
.
|