Game Development Reference
In-Depth Information
been completely traversed, the scene nodes in the alpha list get drawn. But wait,
there ' s more. You can ' t just stick a pointer to the scene node in a list. You have to
remember a few more things, like the value of the top of the matrix stack. When the
list gets traversed, it won
t have the benefit of the entire scene graph and all the calls
to VPreRender() and VPostRender() to keep track of it. To make things easy,
there
'
'
s a little structure that can help remember this data:
struct AlphaSceneNode
{
shared_ptr<ISceneNode> m_pNode;
Mat4x4 m_Concat;
float m_ScreenZ;
// For the STL sort...
bool const operator < (AlphaSceneNode const &other)
{ return m_ScreenZ < other.m_ScreenZ; }
};
typedef std::list<AlphaSceneNode *> AlphaSceneNodes;
The m_ScreenZ member stores the depth of the object in the scene. Larger values
are farther away from the camera and are therefore farther away. When you draw
transparent objects together, such as a forest of trees with transparent textures on
them, you have to draw them from back to front or they won
'
t look right. The list
'
of alpha objects is stored in the Scene class, which you
ll see in the next section.
You might wonder why the RenderPass enumeration doesn ' t just have a special
pass for transparent objects. The reason is that objects can dynamically change from
opaque to transparent at runtime, such as when a creature you just killed fades away
from sight. If there were some objects that were guaranteed to have translucency,
never to change, then a fair optimization to this design could make use of a special
render pass for those objects.
There
'
s only VAddChild() left, and besides adding a new scene node to the
m_Children member, it also sets a new radius for the parent. If the child node
extends geometry beyond the parent
'
s radius, the parent
'
s radius should be extended
to include the children:
bool SceneNode::VAddChild(shared_ptr<ISceneNode> kid)
{
m_Children.push_back(kid);
// The radius of the sphere should be fixed right here
Vec3 kidPos = kid->VGet()->ToWorld().GetPosition();
Vec3 dir = kidPos - m_Props.ToWorld().GetPosition();
Search WWH ::




Custom Search