Speed of object

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
cookie
Posts: 83
Joined: Sun Aug 23, 2009 9:30 pm

Speed of object

Post by cookie »

I've got a vector which contains the speed of an object on the X,Y and Z-Axis. How can I get the "absolute" speed of this objects by using the X Y and Z Speed of it?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

I am not sure what you mean. can you give an example of what you are trying to do?
DarkDepths
Posts: 126
Joined: Sun Apr 02, 2006 1:21 am
Location: Canada

Post by DarkDepths »

I think you mean that you want to know the magnitude of the vector (ie the "length" of the line from your current position to the one indicated by the vector)?

Doing that, if I remember my math correctly, is fairly simple. Just square all the values, add them together, and then take the square root.

sqrt( x^2 + y^2 + z^2 )

For example, x = 2, y = 3, z = 4:

sqrt ( (2)^2 + (3)^2 + (4)^2 )
= sqrt( 4 + 9 + 16 )
= sqrt( 29 )
= ~5.4


Is this what you were looking for?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

vector3df.getLength()? seemed to easy........

//! Get length of the vector.
T getLength() const { return core::squareroot( X*X + Y*Y + Z*Z ); }
DarkDepths
Posts: 126
Joined: Sun Apr 02, 2006 1:21 am
Location: Canada

Post by DarkDepths »

Seven wrote:vector3df.getLength()? seemed to easy........

//! Get length of the vector.
T getLength() const { return core::squareroot( X*X + Y*Y + Z*Z ); }
Oh, haha. I figured there would be a function for it. Looks like i'm still retaining my math fairly well though :P
cookie
Posts: 83
Joined: Sun Aug 23, 2009 9:30 pm

Post by cookie »

Yeah, thats what I was looking for.

Thanks :)
Post Reply