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!
Node "move" rather than position [Solved]
Node "move" rather than position [Solved]
Last edited by TheC on Sun May 07, 2006 12:48 pm, edited 1 time in total.
Yeah, I think you have 2 possibilities:
1.Do it like this:
A bit nooby, but it works.
2.Use the FlyStraightAnimator:
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.
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);
2.Use the FlyStraightAnimator:
Code: Select all
anim=smgr->createFlyStraightAnimator(YOURSTARTINGPOS,
YOURENDINGPOS,100, false);
node->addAnimator(anim);
anim->drop();
My english knowledge is not very good. So I could wrong understood your problem.
Try this:
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);
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.
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.
Thanks alot for pointing me to that part of the source!
For anyone who need to knwo the answer to this in future:
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);