Jump to content
  • Advertisement
Sign in to follow this  
peter_b

Getting a "up" vector from only having a "forward" vector.

This topic is 4502 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

Is it possible to get a up vector if i only have a forward vector? Ie i have no right vector. Holding my hand infront of me, pointing my fingers in the left hand coordinate system, i think this should be possible. Granted all "roll" around the forward vector axis would be lost. But that is ok. Up should always be "uppish" up(0,1,0) in this case, since its for a chase camera. Anyone know how to do this?

Share this post


Link to post
Share on other sites
Advertisement
If you want up to be, as you said, uppish, then you can find the up vector like this:

up = (forward cross (0, 1, 0)) cross forward

Share this post


Link to post
Share on other sites
Take the cross product of your forward vector with your global (0,1,0) up vector. This gives you a right vector. Cross the right vector with the forward vector to get a up vector that "points up" but is perpendicular to the forward and right vectors. Normalize all the vectors. You'll get problems if your forward vector is (0,1,0), but that shouldn't happen with a chase cam I guess.

Share this post


Link to post
Share on other sites
Hmm thats intresting puppet, because that is exactly my problem. When the camera starts its forward vector is (0,-1,0). Ie it is looking down onto the world and glides into position close to the object it is following. Using (0,1,0) as up here works, except for a few seconds in the beginning, when i guess forward is the same vector, and the cross between the two gets messed up because of that.


However. If i have these vectors:
up = 0,1,0
right = 1,0,0
forward 0,0,1

Then, shouldn't it be possible to to calculate the new right and up, if only forward have been alterd? Ie if forward is (0,-1,0), should there be a way to calculate that up should point into positiv z? If disregarding all roll around the forward vector.

Share this post


Link to post
Share on other sites
You can use a special upvector as a "tie-breaker" when the cross-product has length close to 0, although that'll produce a nasty discontinuity unless you have some sort of PD controller smoothing it out.

In the case you gave, where you have the old basis vectors, things get much simpler. Basically, just calculate the rotation matrix which rotates the old forward-vector to the new forward-vector. (To do this, calculate the cross-product of the two, calculate the angle between the two, and then use those as an axis-angle pair.) Transform the old basis vectors by that matrix and you'll have the new basis vector.

IMPORTANT: This will cause rolling over time if your motions are not planar. If roll gets to be a problem, you might want to introduce a "righting" force which pulls the basis vectors upright.

Share this post


Link to post
Share on other sites
You are entering an interesting area of control theory and coordinate systems. What you are encountering is essentially a singularity in your coordinate systems. Robotic manipulators run into this problem all of the time, and it's quite difficult to get around. Generally, they plan paths -away- from singularities. So starting on one is probably a bad idea :)

The problem is a relative "up" vector implies two qualities... it is perpendiculr to "forward" and it's the most "upward" facing. When you are facing along that vertical axis, all perpendicular vectors to your forward vector are equally "up" (that is to say, they are all not up at all)... so things break down.

Quote:

Then, shouldn't it be possible to to calculate the new right and up, if only forward have been alterd? Ie if forward is (0,-1,0), should there be a way to calculate that up should point into positiv z? If disregarding all roll around the forward vector.


In a word, no. Not without more information. Positive Z isn't any more up than any other direction. You are thinking that makes the most logical choice because it perserves continuity in your system. Notice two important facts:

1) Your answer only makes sense based on your starting direction (imagine facing a different direction, and rotating to (0,-1,0), you will get a different intuitive "up" vector).

2) The cross product solutions only deal with the _current_ position, thus, they don't have enough information to do what you are envisioning in part #1.

Using simple cross-products is simply asking, given this forward direction, and this global up, can I calculate my relative "up" vector? And the answer is... no, you can't. Because none of them are any more "up" than any others.

The answer to your question, unfortunately, is that you need to add more information to your coordinate system (or you need to change it. Changing it will move the singularities). In other words, a single "forward" vector is not sufficient for uniquely positioning a camera near this singularity, you may wish to explictly have a second vector.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!