Sign in to follow this  
CGEngine

What to do when forward vector equals up vector

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

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

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

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