Transforming scenegraph objects - translation/rotation nodes?
I'm curious how this is done. I'm having a really hard time controlling all the objects in my scenegraph, especially controlling how things rotate/translate around their parent object.
I have an updateOrientation() function within each object, where it can update it's rotation or translation information. But usually the parent wants to move around the child- say if a ball is a child of a box, the box wants to move around the ball somehow. Within the object itself, it doesn't know how it should move.
I've heard of abstracting out movement by creating nodes in the scenegraph that purely represent translations and rotations. However, I remember trying this, and I found it very limiting and annoying to always have to attach a movement node to every object. How is this usually handled? Some structure containing information on how the object is moved around, and the parent has access to this?
not exactly sure this is what you want but you can go for a pre and post render structure, it would look something like
so each node would call prerender then render all child nodes and then call postrender. What you could do is have the parent node push a matrix onto the stack and then transform however it wants. The child would push another and do its transformations while still being affected by the parents. In the post render you would pop the matricies off the stack.
HTH
node0 --prerender --child0 --prerender --postrender --child1 --prerender --child2 --prerender --postrender --postrender --postrender
so each node would call prerender then render all child nodes and then call postrender. What you could do is have the parent node push a matrix onto the stack and then transform however it wants. The child would push another and do its transformations while still being affected by the parents. In the post render you would pop the matricies off the stack.
HTH
I agree with NTS, however, NTS, how would you go about doing the camera transform? Say, there is a camera attached to child1 following it around wherever it goes. Now this camera needs to be transformed based on child1's transformation, but the view matrix needs to be set before anything is rendered. My question is how would you handle putting a camera node in that scene graph?
P.S: As much as it seems rude to steal the original poster's thread, I hope the original poster can also learn from my question, since NTS' solution is good.
P.S: As much as it seems rude to steal the original poster's thread, I hope the original poster can also learn from my question, since NTS' solution is good.
Quote:Original post by nts
not exactly sure this is what you want but you can go for a pre and post render structure, it would look something like
Yeah, I have system like that in place. I make a render queue and each object transforms its own stored matrix, and then I go through all the objects, load each matrix and render each one. It works well.
What I'm wondering is how you actually control the objects. I have a Parent node and a Child node. In the parent's update function, I want to rotate the child a certain way.
int parent::update() { //Is it: child.rotate(4.5f, 0.0f, 1.0f, 0.0f); //Or is it: child.rotationAxis = vec3(0.0f, 1.0f, 0.0f); child.rotationAngle = 4.5f; //Maybe, where circularMovement is a node which transforms objects in a circular fashion circularMovement.attach(child); attach(circularMovement);}
? I guess it's up to me to figure the best way to handle it. It depends pretty much on the system.
Quote:
My question is how would you handle putting a camera node in that scene graph?
The camera should always be one of the root nodes. Then I handle it just like any other node, with some special properties (it holds the view matrix, not the world matrix). Everything it does affects the whole scene. I do this more or less.
You could get more complex if you wanted cameras to easily rotate around objects. I don't see it being very hard. When you hit the camera node, set up the appropriate view matrix according to the current world matrix, set it as the view matrix and continue. Then when you start the render queue, load the view matrix and start rendering each object (multiplying each one's matrix of course).
You could only do that if you postpone the rendering with a render queue.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement