Page 1 of 1
Node "move" rather than position [Solved]
Posted: Sun May 07, 2006 12:08 am
by TheC
Hi,
I have searched the forums, but I couldn't find any help with this, so sorry if its been posted before.
I have managed to move a scene node by settings its position, or by translating it using its current position then adding an x,y,z increment.
Next, I would like to make it move relative to rotation, so if its yaw has been rotated 45 degrees, the Z adjustment won't make it move further away in a straight line, but instead, at an angle!
Is this possible? If so, how?
Thanks for any help!
Posted: Sun May 07, 2006 7:34 am
by mR.haHN
Yeah, I think you have 2 possibilities:
1.Do it like this:
Code: Select all
if(targetpos.X > nodepos.X) nodepos.X+=0.3;
if(targetpos.X < nodepos.X) nodepos.X-=0.3;
if(targetpos.Z > nodepos.Z) nodepos.Z+=0.3;
if(targetpos.Z < nodepos.Z) nodepos.Z-=0.3;
node->setPosition(nodepos);
A bit nooby, but it works.
2.Use the FlyStraightAnimator:
Code: Select all
anim=smgr->createFlyStraightAnimator(YOURSTARTINGPOS,
YOURENDINGPOS,100, false);
node->addAnimator(anim);
anim->drop();
YOURSTARTING and YOURENDINGPOS need to be a vector3d, the 100 is the time in which the node should move from start to end, and if you set the *FALSE* to *TRUE* the move will be repeating.
Posted: Sun May 07, 2006 8:57 am
by $L!M
My english knowledge is not very good. So I could wrong understood your problem.
Try this:
Code: Select all
vector3df rot=node->getRotation();
vector3df pos=node->getAbsolutePosition()-vector3df(speed*cos(rot.Y/(180/3.1416)),0,-sin(rot.Y/(180/3.1416))*speed);
node->setPosition(pos);
Posted: Sun May 07, 2006 11:33 am
by TheC
Hi,
Thanks for helping, but neither of these options seem suitable.
mR.haHN:
The problem with both your solutions is that there is no way to detect where the target position is. Especially iif the object has been rotated.
$L!M:
Yours appears close, but it only handles rotation around the yaw? how would I apply this technique to all axis?
For clarification, here is a picture of the problem, the third is what I want to happen.
Posted: Sun May 07, 2006 11:38 am
by mR.haHN
Well actually there IS a method to get the target. Just take a look at the CCameraFPSSceneNode.cpp in the Source Archive. There the target of the camera is being detected.
Posted: Sun May 07, 2006 12:48 pm
by TheC
Thanks alot for pointing me to that part of the source!
For anyone who need to knwo the answer to this in future:
Code: Select all
// Set Target (Movement Increments)
vector3df Target = vector3df(x,y,z);
// Get Rotation of node
vector3df rot = node->getRotation();
// Create a matrix, rotate it then move it
matrix4 mat;
mat.setRotationDegrees(rot);
mat.transformVect(Target);
// Get Position of node
vector3df pos = node->getPosition();
// Set the movement increment
vector3df movedir = Target;
// Normalize movement
movedir.normalize();
// Add movement increment vector to the position of the node
pos += movedir;
// Reposition node
node->setPosition(pos);