How do I use local Movement?[solved]
How do I use local Movement?[solved]
I Don't know how to use local Movement in irrlicht.
can anyone help me?
can anyone help me?
Last edited by trollger on Fri Jul 23, 2010 5:46 pm, edited 1 time in total.
Thanks but I mean lets say I have a cube that is controlled with the WASD keys and it turns left and right depending on the mouses position. The problem I have right now is when I rotate the cube and then move it forward it does not move toward the new direction it continues to move toward its absolute XY and Z not local
Have you ever heard of trigonometric functions?
You probably need something like this:
You probably need something like this:
Code: Select all
vector3df pos = node->getPosition();
f32 rot = node->getRotation().Y;
f32 distance = 10.f; //or speed, if you'd like to put it that way
pos.X += cos(rot * DEGTORAD) * distance;
pos.Z += sin(rot * DEGTORAD) * distance;
node->setPosition(pos);
-
- Posts: 194
- Joined: Thu Mar 18, 2010 3:31 am
- Contact:
Three functions which you should copy and use,
For translation:
Example:
Will move the node +1 on it's local Z axis.
For rotation:
Example:
Will rotate the node +1 along it's local X axis.
Hope that helps.
For translation:
Code: Select all
/*
==========
translateNodeLoc -- translate a scene node locally
==========
*/
void translateNodeLoc(ISceneNode *node, vector3df amt)
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
m.transformVect(amt);
node->setPosition(node->getPosition() + vel);
node->updateAbsolutePosition();
}
Code: Select all
translateNodeLoc(mySceneNode, vector3df(0,0,1));
For rotation:
Code: Select all
/*
==========
getMatrixRotation -- gets the real rotation of a matrix
==========
*/
vector3df getMatrixRotation(const matrix4& mx)
{
core::vector3df r;
r.X = asinf(-mx(2,1));
const f32 t = cosf(r.X);
if (.001f < t) {
r.Z = atan2f(mx(0,1), mx(1,1));
r.Y = atan2f(mx(2,0), mx(2,2));
}
else {
r.Z = atan2f(-mx (1,0), mx (0,0));
r.Y = 0.f;
}
return (r * (180/PI));
}
/*
==========
rotateNodeLoc -- rotate a scene node locally
==========
*/
void rotateNodeLoc(irr::scene::ISceneNode *node, irr::core::vector3df rot)
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
irr::core::matrix4 n;
n.setRotationDegrees(rot);
m *= n;
node->setRotation( getMatrixRotation(m) );
node->updateAbsolutePosition();
}
Example:
Code: Select all
rotateNodeLoc(mySceneNode, vector3df(1,0,0));
Hope that helps.
LazerBlade
When your mind is racing, make sure it's not racing in a circle.
3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
When your mind is racing, make sure it's not racing in a circle.
3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
hmm, I had a quick look at the functions and I wonder how this one works:lazerblade wrote:Three functions which you should copy and use
Code: Select all
void translateNodeLoc(ISceneNode *node, vector3df amt)
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
m.transformVect(amt);
node->setPosition(node->getPosition() + vel);
node->updateAbsolutePosition();
}
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
my guess was that vel is the speed (velocity) and has to be multiplied by amt...Lonesome Ducky wrote:Acki, I think he may have meant to put amt instead of vel, that would make much more sense.
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
-
- Posts: 194
- Joined: Thu Mar 18, 2010 3:31 am
- Contact:
Oops... I think I made a mistake when I copied it over...
This is what that function was supposed to be:
This is what that function was supposed to be:
Code: Select all
/*
==========
translateNodeLoc -- translate a scene node locally
==========
*/
void translateNodeLoc(ISceneNode *node, vector3df amt)
{
irr::core::matrix4 m;
m.setRotationDegrees(node->getRotation());
m.transformVect(amt);
node->setPosition(node->getPosition() + amt);
node->updateAbsolutePosition();
}
LazerBlade
When your mind is racing, make sure it's not racing in a circle.
3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
When your mind is racing, make sure it's not racing in a circle.
3d game engine: http://sites.google.com/site/lazerbladegames/home/ray3d
lazerBlade blog: http://lazerbladegames.blogspot.com/
-
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Lonesome Ducky wrote:YES! I WIN! HAHAHAHA!
while(!asleep) sheep++;
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
IrrExtensions:
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java