Game Development Reference
In-Depth Information
bool SceneNode::VIsVisible(Scene *pScene) const
{
// transform the location of this node into the camera space
// of the camera attached to the scene
Mat4x4 toWorld, fromWorld;
pScene->GetCamera()->VGet()->Transform(&toWorld, &fromWorld);
Vec3 pos = VGet()->ToWorld().GetPosition();
pos = fromWorld.Xform(pos);
Frustum const &frustum = pScene->GetCamera()->GetFrustum();
return frustum.Inside(pos, VGet()->Radius());
}
If you recall the
Frustum
class, you
ll realize that this object was in camera space,
with the camera at the origin and looking down the positive Z-axis. This means we
can
'
t just send the object location into the
Frustum::Inside()
routine; we have to
transform it into camera space first. The first lines of code in
VIsVisible()
do
exactly that. The location of the scene node is transformed into camera space and
sent into the frustum for testing. If the object passes the visibility test, it can be
rendered.
Any class that inherits from
SceneNode
will overload
VRender()
and do some-
thing useful like communicate with a shader. I
'
ll get to that when I talk about differ-
ent child classes of
SceneNode
, such as
CameraNode
or
SkyNode
.
VRenderChildren()
is responsible for iterating the other scene nodes stored in
m_Children
and calling the main rendering methods:
'
HRESULT SceneNode::VRenderChildren(Scene *pScene)
{
// Iterate through the children....
SceneNodeList::iterator i = m_Children.begin();
SceneNodeList::iterator end = m_Children.end();
while (i != end)
{
if ((*i)->VPreRender(pScene)==S_OK)
{
// You could short-circuit rendering
// if an object returns E_FAIL from
// VPreRender()
// Don
'
t render this node if you can
'
t see it
if ((*i)->VIsVisible(pScene))
{