Provided Code


You're given all the things from as3 except viewport mapping. Compile and run the provided code and open the sample SLF files. This will have the complete UI from as3. If you open any dynamic file (and turn on the viewport bounding box), you'll see how things go outside the viewport. We want to clip those. You'll also see how the lod.slf file does not respond to the lod values being changed, whereas in the reference solution it does. You'll have to write the LOD stuff too.


LOD flag

Set in the .slf file (either static or dynamic)
Just like other dynamic things, we mark stuff dynamic in Preprocess, and get the new values in Update.

Code Specifics

LOD calculation -
actual LOD of node = min(LOD of parent, current LOD of node) ... use this in ModifyLODFlag

SLF_OFF means ignore the node and its subtree. This means we will not render the subtree. This means m_bBoundEmpty will be true, and we will not compute/render the bounding box of this subtree (m_bound will be null). Keep this in mind, as you will be using this check for all your updates, recomputation of bboxes etc.

You should treat the m_dyniLOD member like any other dynamic variable (think: preprocessgraph, updategraph)..if its GetDynamic is true, the node is dynamic.
Changing the value of the LOD will change the bounds, so now you will have to include extra checks for m_bBoundChanged, m_bBoundEmpty etc.
If the m_dyniLOD is SLF_OFF, then m_bBounded should be false.
If the m_dyniLOD is dynamic, so is the node's bounding box.
Think of such changes to the existing code.

CSLIDENode::Render
implement bounding box rejection: you can do trivial accept (no clipping reqd.) or trivial reject (nothing needs to be done) if the necessary intersection conditions are met.

CSLIDEInstance::Render
If SLF_OFF, do nothing.
Draw the bounding box only if LOD is bound. Else, draw the geometry.




Modified Viewport Mapping

Allows one to specify the camera's frustum (in 2D, so Z component should be zero/ignored). This requires splitting the viewport mapping (which was earlier window->viewport to window->canonical clip volume->viewport). This time the scene is not getting scaled to fit the window...it is being clipped!

Code Specifics

CSLIDERender::Render
In mGvp_proj.SetViewPort(...), you need to add another parameter. If you understand what is missing in Matrix::SetViewPort(...), you'll know what parameter to add. Also, the given matrix goes from the world window to viewport...instead you want to go from the canonical square to the viewport (use the use m_vProjMin and m_vProjMax).
For mGproj_vrc, you need a translation and a scale.

Matrix::SetViewPort(...)
This is almost complete. Understand it well, so you'll know exactly what it is missing. Hint: it is missing a scale...a non-uniform scale that depends on the aspect ratio (y w.r.t. x). Another hint: you're given this distortion as one of the parameters. Any more hints will be a crime.



Bounding Box Culling

Classify nodes as: completely invisible, completely visible, partially visible. Note that the first two require no clipping...the third one does.

Code Specifics

CBound::BoundIntersectionType CBound::Intersect(const CBound &bound)
CBound::BoundIntersectionType CBound::Intersect(const Matrix &m, const CBound &bound)

These return whether the bound passed in intersects with, is contained within or envelopes the 'this' object. The second function applies the transform m to the points of 'bound' and then checks for intersection type. Here, Use the Cohen-Sutherland outcodes so you are only checking which halfspace the bound lies in.

Hint: You will need to write separate cases for InHalf depending on the value of the BoundType passed in - you need to return true if the point passed in is on the correct side of the min or the max.
Also, you will have to call InHalf both, for X and Y.




Polygon Clipping

Sutherland-Hodgman Polygon Clipping: make sure you maintain the topology of the object (i.e. move corresponding vertices to clip window edge locations). You may need to insert or delete vertices; see the comments in the Bound's polygon clipping function.

Code Specifics

CBound::Intercept(BoundType eType, UINT_32 uiCoord, const Point &pt0, const Point &pt1)
Returns the parameter value made by the X or Y coord. (given by uiCoord) of point of the bounding box (given by eType) on the line between pt0 and pt1.

CBound::ClipPolygon(CListInt &listVertices)
Sizeable amount of code required. Does the entire Sutherland-Hodgman polygon clipping. See CSLIDEFace::Render for when ClipPolygon is called.