Node "move" rather than position [Solved]

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
TheC
Posts: 93
Joined: Fri May 05, 2006 7:50 am

Node "move" rather than position [Solved]

Post 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!
Last edited by TheC on Sun May 07, 2006 12:48 pm, edited 1 time in total.
mR.haHN
Posts: 49
Joined: Wed May 03, 2006 5:37 pm

Post 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.
$L!M
Posts: 28
Joined: Thu May 04, 2006 1:21 pm
Location: Ukraine :)

Post 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);
TheC
Posts: 93
Joined: Fri May 05, 2006 7:50 am

Post 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.

Image
mR.haHN
Posts: 49
Joined: Wed May 03, 2006 5:37 pm

Post 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.
TheC
Posts: 93
Joined: Fri May 05, 2006 7:50 am

Post 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);
Post Reply