Creating a node using relative transformation

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
NoisyPerlin
Posts: 11
Joined: Sat Sep 03, 2005 2:52 pm

Creating a node using relative transformation

Post by NoisyPerlin »

I've got a scenenode that moves around the screen. This node can shoot bullets in whatever direction it is facing. What I want is to create a new node for the bullet that uses the gun node's position and rotation. However, I don't want the bullet to be a child of the gun node, because then if the parent is destroyed, the child will be also. I've tried creating the bullet as a child, getting the absolute position and rotation of the bullet, then setting the parent to the root node, but this seems cumbersome. Is there a simpler way of doing this?

My current method looks like this, where node is the gun and testnode is the bullet:

Code: Select all

testnode =smgr->addTestSceneNode(1,node,-1,core::vector3df(5,0,1),core::vector3df(0.0f,0.0f,0.0f));

// testnode has now been created with parent set as "node".
vector3df abspos=testnode->getAbsolutePosition();
vector3df absrot=testnode->getRotation(); // get Absolute position
absrot=absrot+testnode->getParent()->getRotation(); // get absolute rotation
testnode->setParent(smgr->getRootSceneNode()); // set parent to root
testnode->setPosition(abspos);
testnode->setRotation(absrot);
SanderVocke
Posts: 40
Joined: Mon Oct 31, 2005 1:19 pm
Location: Netherlands

Post by SanderVocke »

If you want the bullet to have no parent at all, and have coordinates that are absolute, then you should find the absolute position and rotation of the gun (I assume that your gun is a child of the character holding it). You can use the function GunNode->getAbsoluteTransformation() to get a matrix holding the absolute position and rotation of the gun. then get the coordinates and rotation from that matrix using matrix->getRotationDegrees() and matrix->getTranslation(). Once you have this, you can set the rotation and position of the bullet to the same values, and it will be in the same place without having a parent.
"The shortest distance between two points is always under construction."
- Noelie Alite
Post Reply