Chapter 14 3D Scenes

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Chapter 14 3D Scenes

      Though this is a code correction it is code from out of the book. This code is the same in the GG3 code base and so I assume that it remains the same in 3rd edition (in the post :D ).

      Anyway, to quote a sentence in Scene graph basics "Every node in the hierarchy has a matrix that describes position and orientation relative to its parent node." (pg 491).

      From that sentence I assumed that if you were to add a child scene node to another node (parent), the transformation matrix of the child node would have to describe it's position and orientation in the parent node.

      However when we check visibility of a scene node against a camera frustum. We obtain the position of that node by obtaining the translation part of its transformation matrix.

      Source Code

      1. bool SceneNode::VIsVisible(Scene *pScene) const
      2. {
      3. // transform the location of this node into the camera space
      4. // of the camera attached to the scene
      5. Mat4x4 toWorld, fromWorld;
      6. pScene->GetCamera()->VGet()->Transform(&toWorld, &fromWorld);
      7. //Here
      8. Vec3 pos = VGet()->ToWorld().GetPosition();
      9. pos = fromWorld.Xform(pos);
      10. Frustum const &frustum = Scene->GetCamera()->GetFrustum();
      11. return frustum.Inside(pos, VGet()->Radius());
      12. }
      Display All

      This of course returns the matrix for the local->parent transformation and so the position is then transformed by world->camera matrix. What we really need is position from a local->world transformation matrix.

      This does mean however, that if your scene graph is shallow i.e children's parents contain identity matrix then you wouldn't notice the error. But as soon as a child parent is itself a child of another node VIsVisible is prone to incorrect behaviour.

      there is a simple remedy to this, as VIsVisible is called after VPreRender(), the scene graph already contains this nodes concatenated object->World matrix. Therefore you can replace a single line to get correct behaviour.

      Source Code

      1. Vec3f pos = pScene->GetTopMatrix()->GetPosition();


      I don't think I have missed a massive point and the above code was your intention, but if I am please correct me.

      Besides that, this book is absolutely brilliant, quite frankly its a bible and anyone who has anything to do with game programming should look at it. So good that my 3rd edition is in the post and I'd probably by the nth edition.

      The post was edited 1 time, last by fordprefect ().