Direction vector rotation by 90 degrees down

Started by
4 comments, last by AalaarDB 15 years, 4 months ago
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?
Advertisement
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.
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?
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.
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.

The rest of your answer is here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=517723

This topic is closed to new replies.

Advertisement