Thread: Camera Up Vector Question

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    2

    Camera Up Vector Question

    Hi,
    Suppose that the lookAt vector is 0,0,1 (World Z Axis) and the camera up vector is 0,1,0 (World Y Axis ). In order to calculate the camera coodrinates we do the following:
    1- Camera Z axis: is the lookAt vector
    2- Camera X axis: is the cross product of the lookAt and the Camera up vector
    3- Camera Y axis: is the Cross product of Camera X and Camera Z
    4- Apply the rotation and translation matrix to align the camera calculated axes with the world axes

    Now assume that the camera up vector is tilted a little in the YZ plane so it is 0,1,1.

    Now the cross product of the lookAt and the camera up vector will give a vector in the same direction as the case when the camera up vector was 0,1,0. Consequently the camera Y axis will have the same direction as the camera up vector 0,1,0 case. as a result the rotation matrix that transfers from the wrold coordinates to camera coordinates will have the same values as when the camera up vector was 0,1,0. Which will give a similar view as if the camera is not tilted.
    What is wrong in my understanding? because when the camera is tilted the view should change.
    My best regards.

  2. #2
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    In your tilted camera case, the angle between up=(0,1,1) and lookAt=(0,0,1) is just 45°. Basically, you demanded that the angle between "straight forward" and "up" was only 45° (instead of the 90° degrees we're used to, assuming normal simple flat geometries). It should be no surprise you're unhappy with the results.

    Normally, lookAt and up are perpendicular. In that case, there are no conflicts or issues.
    Your problem lies in the fact that you have conflicting lookAt and up vectors, but your formulas do nothing to resolve that conflict.



    There are several ways to resolve the conflict, but usually one of two ways is used. Simply put, you decide which one is dominant, when the two vectors conflict.

    If lookAt is dominant, then the camera is rotated along that vector so that up corresponds to planar Y axis:
    Code:
    cameraX = up × lookAt
    cameraY = lookAt × cameraX
    cameraZ = lookAt
    This means the camera will always point towards lookAt, and that in the projection (display), up vector is vertical. However, any rotation in up vector that is not perpendicular to lookAt is irrelevant. It's like a stick bending in the wind towards or away from you: it still looks vertical to you. To tilt the camera up, you'd have to change the lookAt vector instead.
    One would typically use this in environments where there are no obvious psychovisual cues for "up" or "down", say in zero-gravity environments.

    If up is dominant, it determines the vertical direction for the camera. The camera is rotated around that axis so that it points (as best as it can) towards lookAt :
    Code:
    cameraX = up × lookAt
    cameraY = up
    cameraZ = cameraX × up
    In this case, up acts much like your own neck, the direction of the vector pointing from the top of your spine, towards the top of your skull. lookAt only defines the rotation of your neck. If lookAt points to a direction that would require your neck to be positioned differently to what up dictates, then you simply will not be able to look directly at lookAt, only that way as much as your current neck position will allow.
    This method is typically used in first person games, as the up vector is then the "head tilt".



    Let's see how the two methods differ in your tilted camera case, where
    Code:
    lookAt = ( 0, 0, 1 )
    up     = ( 0, 1, 1 )
    If we use the first method (where lookAt is dominant), then the camera is pointed directly at the Z axis, and the fact that the up vector is a bit tilted away from the lookAt vector does not matter. The camera will be
    Code:
    cameraX = ( 1, 0, 0 )
    cameraY = ( 0, 1, 0 )
    cameraZ = ( 0, 0, 1 )

    If we use the second method (where up is dominant), then the camera will be tilted:
    Code:
    cameraX = ( 1, 0, 0 )
    cameraY = ( 0, 1, 1 )
    cameraZ = ( 0,-1, 1 )
    Note that in both cases, all three camera vectors are orthogonal:
    Code:
    cameraX × cameraY = ( 1, 0, 0 ) × ( 0, 1, 1 ) = ( 0,-1, 1 ) = cameraZ
    cameraY × cameraZ = ( 0, 1, 1 ) × ( 0,-1, 1 ) = ( 2, 0, 0 ) = cameraX · 2
    cameraZ × cameraX = ( 0,-1, 1 ) × ( 1, 0, 0 ) = ( 0, 1, 1 ) = cameraY
    As long as lookAt and up differ (to sufficient precision), the camera vectors will be orthogonal (perpendicular to each other), only their length will vary. You won't get "skewed" projections using the above. The camera vectors will be unit vectors (length 1) -- and thus orthonormal -- only if lookAt and up are unit vectors and orthogonal (perpendicular to each other).

    However, to ensure the camera vectors are orthogonal, you can safely just scale the camera vectors to length 1 after the above calculations, to make sure they are orthonormal. (There might be some rounding errors, but even with single-precision floats they are too small to notice.)

    For example, scaling the tilted camera vectors yields
    Code:
    cameraX = ( 1.000000, 0.000000, 0.000000 )
    cameraY = ( 0.000000, 0.707107, 0.707107 )
    cameraZ = ( 0.000000,-0.707107, 0.707107 )
    
    cameraX × cameraY = cameraZ = ( 0.000000, -0.707107, 0.707107 )
    cameraY × cameraZ = cameraX = ( 1.000000,  0.000000, 0.000000 )
    cameraZ × cameraX = cameraY = ( 0.000000,  0.707107, 0.000000 )
    i.e. perfectly orthonormal camera vectors.

    Questions?

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    2
    Thank you very much for your detailed answer.

    To summarize:

    1- The camera up and look at vectors should be normal to each other
    2- To make sure that the camera vectors are normal to each other we use
    cameraX = up × lookAt
    cameraY = lookAt × cameraX
    cameraZ = lookAt



    3- Using the above formulas, if the up and look at were normal to each otherthen the camera Y will have the same direction of the up vector, but if they were not normal then the formulas will mak sure that the camera Y , X and Z are normal to each other. and in this case the tilting of the up vector will not be noticed because its projection on the view plane will have the same direction inspite of the tilting angle (the wind stick bending example).

    My best regards

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-22-2013, 07:00 AM
  2. Simple Question memset(vector<int>, 0, sizeof(vector<int>))
    By HyperShadow in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2007, 04:56 PM
  3. OpenGL Camera Question
    By Astra in forum Game Programming
    Replies: 2
    Last Post: 03-25-2007, 01:53 PM
  4. OGL camera movement and vector trouble
    By psychopath in forum Game Programming
    Replies: 1
    Last Post: 05-12-2004, 05:33 PM
  5. Digital Camera -> Slo-Mo Camera??
    By Masa in forum Tech Board
    Replies: 6
    Last Post: 12-24-2003, 11:11 AM

Tags for this Thread