Pages: 2
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
fetch the texture and material for that subset

Fetch the texture and material for that subset

Why are we setting the same lights each time the render loop executes if they never change? The reasons are twofold. First, if you decide to integrate the light group system into this demo yourself, you will absolutely need to set and unset the lights belonging to each light group before rendering its assigned polygons. Second, this approach allows you to place code in the scene class that might dynamically change the light properties. By setting the light properties each time, we make sure that any dynamic changes to a light slot’s properties will be reflected in the next render.

The next section of code contains the significant changes from previous implementation of CScene. We render our scene by looping through each CObject in the scene object array. For each object we check its CTriMesh pointer and its CActor pointer to see which are valid. This will tell us whether the object contains a single mesh or an actor encapsulating a complete mesh hierarchy. If the mesh pointer is valid then we set the object’s world matrix and FVF flags on the device. If the actor pointer is valid then we pass the object’s world matrix into the CActor::SetWorldMatrix function. Earlier we saw that by passing true for the second parameter (as in this case) the hierarchy will be traversed and the absolute world matrices for each frame in the hierarchy will be generated. At this point, either the mesh or the actor is ready to be rendered.

Because the scene is using its meshes and actors in non-managed mode, we must now loop through every global subset in the scene’s ATTRIBUTE_ITEM array, fetch the texture and material for that subset, and set them on the device. If a subset contains no material, then a default material of bright white is used. If a subset has no texture, then the texture stage is set to NULL and the subset will be rendered in shaded mode only.

With the states set, we call either CTriMesh::DrawSubset or CActor::DrawSubset to render the given subset depending on which type of object we are processing.

// Set the states
if ( MaterialIndex >= 0 )
m_pD3DDevice->SetMaterial( &m_pMaterialList[ MaterialIndex ] ); else
m_pD3DDevice->SetMaterial( &m_DefaultMaterial );

if ( TextureIndex >= 0 )
m_pD3DDevice->SetTexture( 0, m_pTextureList[ TextureIndex ]->Texture ); else
m_pD3DDevice->SetTexture( 0, NULL );


As we know, CTriMesh::DrawSubset simply wraps a call to the ID3DXMesh::DrawSubset function, instructing the underlying mesh to render its subsets. If the object contains an actor then CActor::DrawSubset is called and this function does a lot more work. We examined this function earlier and saw how it traverses every frame in the hierarchy and searches for frames that have mesh containers attached. For each one found, the frame’s world matrix is set as the device world matrix and then CTriMesh::DrawSubset is called for each mesh attached to that frame. This will cause all matching subsets in all meshes contained in the hierarchy to be rendered.



You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File

Uploaded by : John Cooke

PageId: ELI148AAB6