Sign in to follow this  

Direction vector rotation by 90 degrees down

This topic is 3287 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have direction vector of my object (forward) and I have to rotate this vector by 90 degrees down eg. for gravitation. How can I calculate this vector?

Share this post


Link to post
Share on other sites
If you have a vector V and an axis that is parallel to vector W, to rotate V 90 degrees about W, perform the cross product between V and W. The order of the cross product depends on the right-hand rule. Or, alternatively, create a rotation matrix and multiply the vector by that matrix. That should give you enough terms to google for, should you not know how to do these.

But your example doesn't seem like a good place to do this. The direction gravity pulls you almost certainly isn't related to the direction you're moving. If I'm walking down a hill, gravity still pulls straight down, not at 90 degrees to the slope of the hill. If I take an elevator up, does gravity start to pull me to the side?

The more natural way is to have gravity independent of direction of movement. Just define gravity to be, say, <0,0,-9.8> globally. Unless you're playing with funky game play, gravity is constant.

Share this post


Link to post
Share on other sites
Yes, I know this is not good example, but in my project I have abnormal, special gravitation :) so for my project example is ok.

I don't have W vector, I have got only direction vector so I don't know how I can rotate my direction vector V. If solution is matrix how this matrix should looks?

Share this post


Link to post
Share on other sites
Ooh, long time and no replies.

Basically, what you are asking for is impossible. There are an infinite (or 2, if you're in 2 dimensions) number of vectors perpendicular to a vector. You need more information. No ifs ands or buts.

Give us more information, what are you *really* trying to do? Surely "gravity" is pulling from you to another object. Can't you create a vector from you to the object? Normalize that and use as the direction for your gravity. Add a couple of those, if you want.

If you're in 2D, say so, there might be something else you can do.

Share this post


Link to post
Share on other sites
Actually I think there is enough information. The extra information is the fact *down*. Suppose you are going straight forward but downhill (0,-1,1) (45* downhill), and because you are going straight forward your direction vector lies on the plane YZ. Your down vector will lie on the YZ plane too, incidently (0,-1,-1), but we don't know that yet.

How we would find that out is we form a plane with your direction vector as the axis and naturally (0,0,0) as the origin. We take any perpendicular vector P that lies on this plane, it could be pointing in any of the 360 degrees on this plane. We want it to be on this plane AND on the YZ plane. There are 2 ways we can get this point P to be on both planes, first is we can rotate about the direction vector aka the plane's axis some unknown number of degrees - and if you know how to do this then please help me here: http://www.gamedev.net/community/forums/topic.asp?topic_id=517723
The second way is to do plane plane intersection.

But suppose you aren't going straight forward, but also to the right, (1,-1,1). Well simple, first you rotate about the Y axis until the direction vector is aligned with the YZ plane (and direction.x is therefore 0) This new direction vector is something like (0,-1,sqrt(3)) Perform the above plane plane intersection, then rotate about the Y axis in the opposite direction!

See http://www.fundza.com/mel/axis_to_vector/align_axis_to_vector.html for aligning the direction vector to the YZ plane.

Please let me know how you handle the first step, since I don't know how to rotate about the direction axis or to do plane plane intersections.

Share this post


Link to post
Share on other sites

This topic is 3287 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this