
calculate Up Vector
Hi,
here is my code:
Vector3f CameraUpVector() const
{
Vector3f cameraDirection = m_cameraTarget  m_cameraPosition;
cameraDirection = cameraDirection.Normalize();
Vector3f cameraUp = cameraDirection.Cross(Vector3f(1.0f, 0.0f, 0.0f));
return cameraUp;
}
Vector3f cameraUp = CameraUpVector();
p.SetCamera(m_cameraPosition , m_cameraTarget , cameraUp);
Is this calculation OK?

Senior Member
OpenGL Pro
No, it is not. If camera is looking down the Xaxis, you'll get zerovector.
Up vector should be the property of the camera. Or even better, use quaternions.

i AM NEW IN opengl
PLEASE IF YOU CAN SHOW ME HOW TO CORRECT IT
because now my target is (0,0,0)
and the camrea pos is (0,500,0) and I cant see nothing
How can I use Quaternions?

Senior Member
OpenGL Pro
If the camera position is (0,500,0) and the target is at (0,0,0), there is an infinite number of Up vectors that can produce valid output.
For example, if Up vector is (0,1,0) you'll see the object at the origin like you are inclined toward Z axis. Also, (1,0,0) will form the same result as previous, but rotated 90 degrees to the right. Can you understand that there is an infinite number of Up vectors? So, in order to have an unique camera orientation, you need to store Up vector in an attribute of the camera and rotate it along with Direction vector (only together they define camera orientation).
Quaternions are the further abstraction of the complex numbers. They proved to be very useful in defining orientation, since they are more numerically stable and avoid some problems (like gimbal lock). It would be ideally to define a camera position/orientation as a pair (P,Q), where P is a 3D vector and defines a position, while Q is quaternion defining orientation.

so what I need to change in the code above if I want to define camera and up vector orientation?

Senior Member
OpenGL Pro
You can't determine it! You have to set it.
Please, carefully read the following chapter, and take a look at fig.312.
Up vector can be whatever you set. It should be perpendicular to Direction, but it is not required.

Ok
i CHANGED THE FUNC TO :
Vector3f CameraUpVector() const
{
Vector3f cameraDirection = m_cameraTarget  m_cameraPosition;
Vector3f cameraRight = cameraDirection.Cross(Vector3f(0.0f, 1.0f, 0.0f));
Vector3f cameraUp = cameraRight.Cross(cameraDirection );
return cameraUp.Normalize();
}
now my target is (0,0,0) and the camrea pos is (0,500,0) and the up vector is (0,1,)
Is this ok? now I can see the model from an upper view?
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules