.
.
.
.
Elena Tresh Foundation Florida
.
|
Flash - 3D Engine design
I am going to redesign my 3D engine from the ground up. Now that I have some idea about how to
do the coding, I need to make sure that I have the most efficient structure. Especially for Flash.
This is the process that I will take.
- Requirements Doc
- Use Cases
- Assign Responsibilities - Drawing lines and pictures
- Class Diagram
- CRC cards - Class Descriptions
- Interaction Diagrams
- Algorithms
- Test first coding
- Re-iterate
Requirements Doc
- Import .obj Models
- Vertices, faces, normals, colours, materials
- Extensibility - can later add animation data, other formats - .3ds, .mdl
-
Data Structure
- Linked Lists - see Watt 3d book appendix
- Octrees
- BSP
-
Rotation and Translation - x y z
-
Terrain Generation
- Sinusoidal
- Fractal
- Other , heightmaps ?
-
Optimise Heavily
- Single animation loop - all rendering and calcs
- Precalculate as much as possible
- Bounding Boxes - AABB
- Collision Detection
- but how to detect collision with terrain
-
Frustum Culling
- BackFace Culling
- Occlusion Culling
- Camera
- Lighting
- Omnidirectional + ambient + inverse proportional distance
- Shading
- Flat
- Gouraud
- Textures
- Project to 2D
- Render/Draw to Screen
Use Cases
Import Model Data
Assign the Vertices to a pointsList Data Structure ,
assign Faces to a faceList, normals, colours
Create Models
From the data, create the model object and assign the data to object class variables.
Rotate Model x y z
Translate Model x y z
Import Terrain Data
Have the ability to parse terrain data from external sources
Create Terrain
Assign data to terrain class object variables
Place Terrain in World
set position and relation to the engine world system
Place Models in World
Position static and moveable objects in initial positions
Define Moveable and static Object Types
Moving Objects - planes, tanks, cars, spaceships
Static Objects - Terrain, Buildings , trees, Fortress that fires at you(eg)
Create Camera
Set Camera to follow Object
Change Camera settings
POV, follow another object
Light any/all Objects
Shade objects
Create Bounding Boxes - Detect Collisions
Perform Backface Culling
Occlusion Culling
Convert to 2D Coordinates
Draw/Render to screen
Z-Sort Objects
Flash - use swapDepths
Get average Z for face - Z sort routine
Class Definitions and Responsibilities
This is where I have done a first pass at working out what classes I will need and
what responsibilities each class will have. It is not a final list, just something to get the
mind working and starting to set some sort of platform. So here goes:
| Class | Responsiblities |
| Vector3D |
- Store Coordinates
- Able to do Vector maths , + - * /
|
| Matrix |
- Hold Matrix data
- create identity matrix
- Create rotation/translation matrices
- Create Scale/Shear/Deformation matrices
- Allow for matrix multiplication/concatenation
|
| Face |
- Store list of points
- store the normal, colour
- Set visibility
- Do occlusion, frustum and backface culling
|
| Mesh |
- Store list of faces
- set centrepoint
- set radius of bounding sphere
- Set moving flag
|
| Terrain |
- Set up grid
- set heightmap
- set texture or colour
- find nearest neighbour - interpolate/extrapolate heights
- draw it.
|
| Light |
- Hold the vector
- set brightness
- set ambience
- find distance from models
|
| Camera |
- Set it up
- Attach it to a model
- set position
- reset model to look at
- set a radius or viewAngle
|
| Engine |
- Oversee the engine
- interface or plugin for developers
- create models
- set to render
- Allow input for players
- Initialise Terrain and unmoving Models
|
Class Descriptions
Now i will assemble all the member variables and methods of each class and determine method arguments and
return types. Again, its a work in progress. You dont need to get it perfect. It is a process you work throught
that helps you organise your ideas, thoughts and structures.
Vector3D Class
| Class | Variable | Type | Description |
| Vector 3D | x | Number | x coordinate |
| | y | " | y " |
| | z | " | z " |
| Class | Method | Return Type | Description |
| Vector3D | Increment(x,y,z) | Void | Moves x,y,z by passed amount |
| | addVec(vec) | Vector3D | Adds two vectors |
| | minVec(vec) | Vector3D | Subtract 2 vectors |
| | scale(scalar) | Vector3D | Scales Vec by scalar amount |
| | dot(vec) | Number | Returns dot product of 2 vectors |
| | cross(vec) | Vector3D | Returns cross Product |
| | getNormal() | Number | gets the normal of a vec |
| | normalize() | Void | Normalizes the vector |
| | getUnitVec() | Vector3D | gets the unit vector |
Matrix Class
| Class | Variable | Type | Description |
| Matrix | mE | Array | Array elements |
| Class | Method | Return Type | Description |
| Matrix | loadIdentityMatrix() | Void | neutral matrix |
| | scalarMultiplication(scalar) | Matrix | Multiply matrix by scalar |
| | vectorMultiplication(vec:v3d) | Matrix | Multiply matrix by vector |
| | matrixMultiplication(matrix) | Matrix | multiply matrix by matrix - concatenation |
| | transposeMatrix() | Void | flips the elements |
| | rotationXYZ(sinX,cosX,sinY,cosY,sinZ,cosZ) | Void | Matrix for rotating models |
| | loadRotationAxis(vec,sin,cos) | Void | loads a rotation matrix around a unit vector |
Face Class
| Class | Variable | Type | Description |
| Face | vList | Array | List of vertices of a face |
| extends | normal | Vector3D | the normal vector of the face |
| Movieclip | rotNorm | Vector3D | rotated Normal |
| | colour | 0xffff00 | the colour of the face |
| | visible | Booelan | whether the face is visible |
| | depth | Number | depth of mc |
| | name | String | name of mc |
| | | | |
| | | | |
| | | | |
| Class | Method | Return Type | Description |
| Face | | | |
| | backCull() | Void | Sets face visibility |
| | OcclusionCull() | Void | Sets face visibility |
| | draw | Void | draw the faces |
Light Class
| Class | Variable | Type | Description |
| Light | location | Vector3D | light vector |
| | brightness | Number | brightness , from 0.0 to 1.0 |
| | ambience | Number | constant number for ambient lighting |
| | distance | Number | distance from object |
| | x | Number | x coordinate |
| | y | Number | y coordinate |
| | z | Number | z coordinate |
| Class | Method | Return Type | Description |
| Light | colorise() | Number | returns hex color e.g. 0x0000ff |
Mesh Class
| Class | Variable | Type | Description |
| Mesh | faceList | Array | List of faces |
| | meshCtr | Vector3D | centre of the object |
| | radius | Number | radius of bounding sphere |
| | moving | Boolean | flag whether moving or not |
| | | | |
| | | | |
| | | | |
| Class | Method | Return Type | Description |
| Mesh | setRadius() | Void | set the radius of the bounding sphere |
| | setPos(x,y,z) | Void | set the object in world position |
| | addPoint(x,y,z) | Void | add a vertex |
| | addFace(name,array,color,depth) | Void | add a Face |
| | computeNormals() | Void | calculate the normals of each face.. |
| | getBS() | Void | calculate the bounding sphere |
| | | | |
| | objCull() | Void | cull objects out of frustum |
| | | | |
Terrain Class
| Class | Variable | Type | Description |
| Terrain | tType | Number | type of terrain generation 0,1,2 ? |
| extends | faceList | | |
| Mesh | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| Class | Method | Return Type | Description |
| Terain | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| Class | Variable | Type | Description |
| Camera | | | |
| | campos | Vector | camera position |
| | up | Vector | y axis(0,1,0) |
| | side | Vector | x axis(1,0,0) |
| | down | Vector | z axis (0,0,1) |
| | rad | Number | radius for collision |
| | outMag | Number | length of vec |
| | outNorm | Vector | Camera normal |
| | frustAng | Number | angle of frustum |
| | frustCos | Number | |
| | frustTan | Number | |
| | | | |
| Class | Method | Return Type | Description |
| Camera | setPos(x,y,z) | void | set the camera position |
| | Constructor(loc,view_width,view_height,fov) | n/a | camera initialise |
| | translate(x,y,z) | void | move in any direction |
| | move_sideways( d) | void | move in side axis direction by amount d |
| | move_up(d) | void | displaces cam by 'd' in direction of 'up' axis |
| | move_forward(d) | void | " " forward |
| | rotate_around_side(sin,cos) | " | rotate cam around - cam axis |
| | rotate_around_up(sin,cos) | " | |
| | rotate_around_out(sin,cos) | " | |
| Class | Variable | Type | Description |
| Scene | mat | Matrix | matrix |
| | objList | Array | List of all objects |
| | cam | Camera | the camera |
| | vertList | Array | List of vertices |
| | | | |
| | | | |
| | | | |
| Class | Method | Return Type | Description |
| Scene | | | |
| | update_matrix() | void | update the matrix |
| | frustCull() | void | cull object outside frustum |
| | project2D() | void | project 3d points to 2d points |
| | calcLight() | void | calculate brightness of light/s |
| | render() | void | render the scene to screen |
| | collision() | void | detect object collisions |
| | sortDepths() | void | sort depths of faces according to distance from camera |
| | addObject(obj) | void | add object to object list |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| Class | Variable | Type | Description |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| Class | Method | Return Type | Description |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
.
|
|