What to do when forward vector equals up vector

This topic is 1314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 19
• 20
• 14
• 14
• Forum Statistics

• Total Topics
633383
• Total Posts
3011582
• Who's Online (See full list)

There are no registered users currently online

×