I'm currently working on a small Camera (ArcBall) and I finally am starting to understand how it will work.

I will first create a basic View Matrix using a LookAt function.

Then, I will send the Camera Position and the Camera Target to a function which will:

1: Calculate the Vector of (Camera Position - Camera Target)

2: Rotate this vector by X Pitch 3: Rotate the same vector by Y Yaw

This will determine the new Camera position. Now I need to find the Up Vector to be able to use LookAt() so I need to do the cross product of the forward and the right vector to find the Up Vector.

4: I will do (Camera Target - Camera Position) and normalize it so this will be my new Forward vector

5: ??? I need to find the right vector. How can I find the Right vector if I do not have the Up vector?

If you see flaws with my ArcBall camera, tell me, I am new to OpenGl and I'm trying to learn.

  • \$\begingroup\$ Have you completed High School mathematics? I ask because the manner in which any answer is presented, concisely or verbosely, mathematically sophisticated or naïve, depends on your background. \$\endgroup\$ May 19, 2016 at 3:10
  • \$\begingroup\$ Not really, well, High School yes but where I lived, we have never learned Matrices and Vector. Sorry ! \$\endgroup\$ May 19, 2016 at 3:20
  • 2
    \$\begingroup\$ @GabrielRoy It will really be difficult to use OpenGL for 3D games without a good understanding of Linear Algebra, I strongly recommend learning everything you can about Vectors, Matrices, Transformations, and if you are so daring, Quaternions. \$\endgroup\$
    – user5665
    May 19, 2016 at 5:17

1 Answer 1


You can't get the "right" vector from just a "forward" vector. Any particular "forward" vector could have an infinite number of different legal "up" and "right" vectors.

For example, if I am looking forward along the z axis forwardVector = vec3(0,0,1), then I could have up be along the y axis upVector = vec3(0,1,0) and right therefore be along the x axis rightVector = vec3(1,0,0), or I could have up be along the -y axis upVector = vec3(0,-1,0) and therefore right would be along the -x axis rightVector = vec3(-1,0,0). Or I could even have 'up' be along the x axis upVector = vec3(1,0,0), which would mean that right is along the y axis rightVector = vec3(0,1,0). And so forth. No one "up" or "right" vector can be considered "correct" if all you have is a forward vector, without imposing some extra constraints on the system.

One common constraint to add to this kind of system is that "up" should be pointing as close as possible to some objective "up" in the scene. Lots of 3D platform games do this, for example. In these, you can calculate your "right" vector by taking the cross product of the forward vector against vec3(0,1,0) (or whatever your world-space 'up' is), and then the cross product of the right vector against the forward vector. And that would work.

But it wouldn't be an arcball, since the camera would always be re-orienting itself so that its local 'up' pointed upward in the world, where arcballs are supposed to maintain their accumulated orientation as you rotate.

For a proper arcball, you need to not be storing the camera position at all; instead, you should just store the camera's orientation. Keep its forward, its up, and its right vectors, and rotate all of them based on the pitch and yaw, and then reconstruct a new camera position based upon the target position and the forward vector. And then you can LookAt using the up vector that you already have!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .