How can i change the direction of movement of a node?
i have tried to rotate it but it keep moving in the same direction !!
Direction!?
-
- Posts: 616
- Joined: Wed Nov 01, 2006 6:26 pm
- Location: Cairo,Egypt
- Contact:
-
- Posts: 616
- Joined: Wed Nov 01, 2006 6:26 pm
- Location: Cairo,Egypt
- Contact:
There is another way. You keep a record of the forward vector of the node and then when you update its position you can do node->setPosition(node->getPosition()+forwardVector*amount);
amount being how far you want to go forward. The forward vector would be vector3df(1,0,0) if it was facing straight down the x axis and then you can rotate it using trig or matrices to keep it updated as your node rotates.
I think that would work anyway, my mind isn't in much of a working mood atm!
amount being how far you want to go forward. The forward vector would be vector3df(1,0,0) if it was facing straight down the x axis and then you can rotate it using trig or matrices to keep it updated as your node rotates.
I think that would work anyway, my mind isn't in much of a working mood atm!
-
- Posts: 616
- Joined: Wed Nov 01, 2006 6:26 pm
- Location: Cairo,Egypt
- Contact:
-
- Posts: 616
- Joined: Wed Nov 01, 2006 6:26 pm
- Location: Cairo,Egypt
- Contact:
Code: Select all
core::vector3df forward(0, 0, 1);
core::matrix4 m;
m.setRotationDegrees( node->getRotationDegrees() );
// rotate the forward vector into parent coords
m.rotateVect(forward);
// get the old position
core::vector3df position(node->getPosition());
// get the distance moved this time slice
f32 distance = velocity * time;
// augment the node position
position += (forward * distance);
node->setPosition(position);
Last edited by vitek on Sun Nov 19, 2006 3:46 pm, edited 1 time in total.
-
- Posts: 616
- Joined: Wed Nov 01, 2006 6:26 pm
- Location: Cairo,Egypt
- Contact:
Finally after 3 hours i made this code
thanx every one for your suport and thanx vitek but i will use my way
Code: Select all
core::vector3df c = ship->getPosition();
core::vector3df d= ship->getRotation();
float diry = ((d.Y+90)*3.14)/180;
if (up)
{
c.X += speed * cos((d.Y) * 3.14 / 180);
c.Z -= speed * sin((d.Y) * 3.14 / 180);
}
if (down)
{
c.X -= speed * cos((d.Y) * 3.14 / 180);
c.Z += speed * sin((d.Y) * 3.14 / 180);
}
if (left)
{
d.Y -= 0.1;
}
if (right)
{
d.Y += 0.1;
}
ship->setRotation(d);
core::stringw cy = d.Y;
device->setWindowCaption(cy.c_str());
int xf = (c.X-sin(diry)*125);
int yf =(c.Z-cos(diry)*125);
int zf =100;
ship->setPosition(c);
camera->setTarget(c);
c.Y +=200.f;
c.Z -= 150.f;
camera->setPosition(vector3df(xf,zf,yf));
}
else
{
// clear keys when window goes out of focus
up = down = left = right = false;
}
}
device->drop();
return 0;
}