What to do when forward vector equals up vector

Started by
4 comments, last by Fredericvo 9 years ago

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...

Advertisement

This is a good blog which may help you.

http://blog.selfshadow.com/2011/10/17/perp-vectors/

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.

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?

Multiply right by look instead of doing a cross? I am not looking at how I did it just suggesting this from memory.

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.

This topic is closed to new replies.

Advertisement