Ignoring the rotation values of the parent node(s)?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Ignoring the rotation values of the parent node(s)?

Post by Castaa »

Hi all,

My problem:

I have a child node attached to at least one parent node in my scene hierarchy, but I need the child node to use a different rotation that is independent of the rotation values of the parent(s).

I still need it to be an attached child node because of the need to follow any position movements and visibility of the parent node.


An example would be trying to have eyeball object "look at" a point in space, while the "body" and "head" (in which the eyeball is attached to in the hierarchy) are translating and rotating.

Any help would be great. I'm sure this has been solved many times. I search the forums before asking this but no luck.
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I guess you have to create a custom scene node for this, which simply ignores the parent's rotation in the calculation of the absolute transformation. Note, though, that also parent scale is to be ignored then.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Alternatively you could just not parent the eyeballs to the head but just set their position properly each frame.

Though of course you SHOULD take the parents rotation because what if the head tips backwards or forwards for example? Then the rotation of the head will change which will change the required rotation and positioning for the eyes. Basically i guess you should just get the absolute rotation of the eyes and calculate their rotation, to look at a certain point, based on that, each frame.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

JP wrote:Alternatively you could just not parent the eyeballs to the head but just set their position properly each frame.
And the easiest way to do that would be to use... a custom scene node. ;)

I'm still burned out from my burst of maths yesterday, but I'll try and have a think about a custom node to do this, where "this" is defined as:

Rotate to look at a specific point, clamping the allowed rotation to some delta from the parent node's rotation.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

Thanks guys for the tips.
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

Sorry I'm back. I've been reading up on building my own custom scene nodes to make sure my child node's rotation is replaced by an absolute custom node rotation of my choosing that's independent of the parent's rotation.

It appears that I need to override a virtual function in ISceneNode and get the value of AbsoluteTransformation and modify it to it ignore all the rotation values. But which function do I change this value in? Or am I completely off here?
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

can you post the code when you're done with the mod. i'd like to have a copy of it.

thanks much.
Image
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

dlangdev wrote:can you post the code when you're done with the mod. i'd like to have a copy of it.

thanks much.
Yep I will. I think might have it figured out. But I'm still writing it.
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

Ok what if I just want to override one function in the class heirarchy of CAnimatedMeshSceneNode or even CMeshSceneNode.

I understand the IMeshSceneNode abstract philosophy but I just want to modify one virtual member function via an inherited class called e.g. class myCAnimatedMeshSceneNode.


I don't understand how do this without cutting and pasting a ton of code from CAnimatedMeshSceneNode to meet the needs of the abstract interfeace of IAnimatedMeshSceneNode. :(
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Suck it up, soldier. Copying CAnimatedMeshSceneNode, renaming it, and doing a find and replace on CAnimatedMeshSceneNode inside it would take, what, 2 minutes?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

rogerborg wrote:Suck it up, soldier. Copying CAnimatedMeshSceneNode, renaming it, and doing a find and replace on CAnimatedMeshSceneNode inside it would take, what, 2 minutes?
Ya, I feel ya. :D Thanks.


<mini rant>

Maybe I'm mistaken but I'm a little bit surprised that the Irrlicht design actually forces a very bad and dangerous coding practice. What if one requires a dozen custom anim node classes? This is code bloat and cache unfriendly.

And what if there is a bug fix or change in the original Irrlicht anim node. The change potentially would have to be propagated to all the custom versions of the copied code.

I don't see why they actively discourage me from inheriting from CAnimatedMeshSceneNode given these drawbacks given these problems?

</rant>


Yes, I know it's free. And I'm very grateful for any work done by open source developers but I'm confused.
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Can't you just put up a custom scene node which ignores the rotation and parent it to the animated scnee node?
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

hybrid wrote:Can't you just put up a custom scene node which ignores the rotation and parent it to the animated scene node?
Oh! I think that might work. Thanks. :D
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

Castaa wrote:
hybrid wrote:Can't you just put up a custom scene node which ignores the rotation and parent it to the animated scene node?
Oh! I think that might work. Thanks. :D
Yep that did the trick. Thanks. You helped me think of a new way to attacking my problem. Much appreciated.
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
Castaa
Posts: 39
Joined: Mon Jul 07, 2008 7:38 pm
Location: San Francisco
Contact:

Post by Castaa »

dlangdev wrote:can you post the code when you're done with the mod. i'd like to have a copy of it.

thanks much.

Code: Select all

// this class is a special node that blocks the parent rotation from being used to calculate the child's rotation //
class CTargetRingAdjustmentNode : public irr::scene::ISceneNode
{
  core::aabbox3d<f32> m_Box;

public:
  CTargetRingAdjustmentNode(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr)
		: scene::ISceneNode(parent, mgr)
	{
      #ifdef _DEBUG
      setDebugName("CTargetRingAdjustmentNode");
      #endif
  }

  virtual void updateAbsolutePosition()
  {
    if( Parent )
    {
      core::matrix4 mat = Parent->getAbsoluteTransformation();
      mat.setRotationDegrees(irr::core::vector3df(0,0,0));
      AbsoluteTransformation = mat * getRelativeTransformation();
    }
    else
    {
      AbsoluteTransformation = getRelativeTransformation();
    }
  }

  virtual void OnRegisterSceneNode()
  {
    if (IsVisible)
    {
      SceneManager->registerNodeForRendering(this);
    }
    ISceneNode::OnRegisterSceneNode();
  }

  virtual void render()
  {
    // this node only effects rotations of it's children and doesn't render anything //
  }

  virtual const core::aabbox3d<f32>& getBoundingBox() const
	{
    return m_Box;
	}

};
I put this custom node between the IAnimatedMeshSceneNode parent and the IAnimatedMeshSceneNode child. My situation is a simple case, so it might not work for more complicated scene node hierarchies.
My game: Star Sonata
Star Sonata is a massively multiplayer space game.
Post Reply