Jump to content
  • Advertisement
Sign in to follow this  
at0m

Tags/Behaviors for classes ?

This topic is 2850 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I'm implementing a scene graph.
The Base Nodes have basic transformation operations, but I would like to be able to add some sort of tag for targeting (the forward vector of the node would be set toward another node (the target)) this is inspired from a 3d modeling/rendering software called Cinema4D : http://cgtuts.s3.amazonaws.com/077_C4D_Room2/14.jpg basically you select a node and add a tag. Once set, the node automatically fixes the target.
The only thing I can think of is building some sort of observer pattern, where the node is an observer and a subject...

I would like the code (C++) to look like this :
Node myTargeterNode;
Node myTargetNode;
/* add the target Tag */
myTargeterNode.addTag(TargetTag(myTargetNode));
/* Now, the targeter node is fixing the target.
After a translation, the axis of the targeter must be recomputed */

myTargetNode.translate(vec3(10,10,10)); // targeter need update



Can someone help me out ?

Share this post


Link to post
Share on other sites
Advertisement
How is your scenegraph updated? More importantly, how is it queried for node positions? Do you have a movement tick that updates everything into a cache, which is then used by external code? Or do you query nodes directly each time you want their position? Some more details on how you have that set up will help narrow down potentially good solutions.

Share this post


Link to post
Share on other sites
Quote:
How is your scenegraph updated?

If a Node has a parent, its world matrix is the result of the parent's local matrix and world matrix. Else, just the local matrix. (See code below)
The position of the node is queried with getters (ex : Node::getPosition())

Here's the UML diagram of my base node class (so far) :
UML Node

I'm thinking of adding to the prototype an array of Tags (Tag being a base class), having an abstract method update taking a node pointer as a parameter, which would be called in the node's update method.
Illustration :
namespace Node
{
void Base::update(float delta)
{
// matrix computation
if(myParent != NULL)
myWorld = myParent->myWorld * myTransformations;
else
myWorld = myTransformations;

// tag manipulation
if(!myTagArray.empty())
for(TagArray::iterator it = myTagArray.begin(); it!=myTagArray.end(); ++it)
(*it)->update(this);

// update children ...
}
}



[Edited by - at0m on August 25, 2010 10:18:35 AM]

Share this post


Link to post
Share on other sites
So... do you have a per-frame tick that calls Update(), or what? I'm not clear on exactly how you actually change object positions etc. within your scenegraph design.

Share this post


Link to post
Share on other sites
Yes the graph is updated by calling the update method from the root node. I intend to add a delta parameter in the Node::update method in order to get the elapsed time between two update calls (in a loop). The update computes the new transformation matrices for the drawable entities held in the nodes. The local axis and the position can be recovered from the Node::myWorld member. I Hope I made myself clear enough :)

Share this post


Link to post
Share on other sites
Shouldn't be too hard then; as you traverse the scenegraph in Update(), for each node, check the tag list, and do the appropriate updates (i.e. either use the original forward vector or the targeted vector depending on what tags are set). Cache the computed position/forward vector/et. al. in each node, and then have the cached value be returned by your getFoo() accessors.

Share this post


Link to post
Share on other sites
Ok got it quite figured out.
One thing I'll have to keep in mind with this design is that some tags will require the graph to be fully updated (ex : node targeting another "branch" in the hierarchy).
Thanks for your help and time ApochPiQ ^^

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!