Jump to content
  • Advertisement
Sign in to follow this  
CGEngine

What to do when forward vector equals up vector

This topic is 1226 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.

 

What should I do when the forward vector equals the up vector so calculating the cross product returns a zero vector.

 

This is causing some issues in my camera and when working with rotation axis etc...

 

 

Share this post


Link to post
Share on other sites
Advertisement

Using an "up" vector to generate a basis is only necessary when you don't have a basis to begin with. In other words, you should only need to do it when all you have is one "forward" direction and nothing else. This typically doesn't need to be the case for a camera: it's usually easy to hold onto a full basis for your camera, and then there's no need for generating perpendicular vectors. How you would implement this depends on how your camera works, but if you share some details about how you handle camera orientation then I can probably help you modify it so that you don't need an "up" vector.

Share this post


Link to post
Share on other sites

I already keep an orthogonal basis so I don't run into problems when rotating the camera.

 

The main problem is in the function:

void Camera::setLookDirection(Vector3D dir)
{
    m_Look = dir;

    m_Look.Normalize();

    m_Right = Vector3D(0.0f, 1.0f, 0.0f).Cross(m_Look);
    m_Right.Normalize();

    m_Up = m_Look.Cross(m_Right);
}

Setting the camera direction to (0.0f, 1.0f, 0.0f) causes problems.

 

I'm also having problems when using a function like this. What can I do when I want to generate a quaternion to rotate an object so it faces another object directly above it?

Share this post


Link to post
Share on other sites
Multiply right by look instead of doing a cross? I am not looking at how I did it just suggesting this from memory.

Share this post


Link to post
Share on other sites

Setting the camera direction to (0.0f, 1.0f, 0.0f) causes problems.


From the code snippet you showed, you should expect that your up vector becomes the zero vector as you cross your look direction with a hard coded <0,1,0> vector with which it is set parallel to.

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!