Matching view to world - help!

1. I have a number of meshes placed in world space.

2. Each mesh is being rendered using three vectors: scale, rotation and position.

3. I am calculating the world matrix with SCALE_VECTOR * ROTATION_VECTOR * POSITION_VECTOR .

4. One of these meshes represents the camera. So, when rendering this mesh I also set the view matrix.

5. The view matrix is calculated using LOOKATLH using the POSITION_VECTOR as the eye and POSITION_VECTOR+ROTATION_VECTOR for lookat.

6. Moving my camera around in the world works fine. The view matrix is providing a nice view into the world - all objects appear to be placed in proper relative positions.

7. THE PROBLEM: The "view rotation" of the camera object does not seem to be aligned with its "world rotation". It almost like I need some way of adjusting the view matrix that is calculated for the camera so that it is consistent with its ROTATION_VECTOR that is being used to render its mesh.

Any ideas about this type of conversion

Thanks,

Dana



Answer this question

Matching view to world - help!

  • Seraphic Raven

    What do you mean with “not aligned” Do you mean that if you rotate the “camera object” the view does not rotate with the object



  • LuckyAbhishek

    Thanks! You are really nice to help me like this.

    I will try that tomorrow and post what happens.

    Time for bed....(3am here).

    -Dana


  • flyingsnow

    If each camera is a cube with a disc (the lens) pasted on the "forward" side of the cube...

    And if I place two camera objects into the world and point them at one another....

    Each camera should be seeing a "camera lens" looking back.

    But instead, each camera sees a corner of the other camera's cube (instead of a lens).

    ----------------------------------------------

    Another way to describe this is:

    With just one camera "cube" with the lens disc floating in front of the camera in the forward direction...

    When looking through this camera - I would expect to see the lens floating in front of me - no matter which way I turn the camera.

    Instead, the lens seems to appear at random positions as I turn the camera. (Although another camera watching this sees the lens rotate properly with the camera.)

    -Dana


  • Gidon J

    Is it posible that origin of your camera object is on a corner and not in the middle of the lens

  • Scott L

    If I understand you right that you add your rotation vector to the eye vector to get the look at vector Additional you use the three components of the same vector as Yaw, Pitch and Roll parameters to generate a matrix with D3DXMatrixRotationYawPitchRoll

    In this case I believe I know the problem. Yaw, Pitch and Roll are angles in radians but you look at vector need absolute values. Using the same values with two different meanings could not work. A possible solution might be this:

    To calculate the lock at vector first build a matrix with D3DXMatrixRotationYawPitchRoll and the vector that contains your rotations angles. After this use this matrix to transform the default camera view vector (depends on your setup, 0,0,1 could be right). Now add this vector to your eye point to get the look at vector.



  • ESTAN

    Thank you.  Good thought.  Checking...

    OK:

    When I rotate camera 1, the cube rotates smoothly around its center.  The lens retains its proper position on one face of the cube.  (watching all of this from camera 2).

    But when I look out from camera 1 (while performing these rotations) the lens should be "blocking" my view.  Instead, the lens swings by at certain orientations, but is mostly absent.

    I think the problem may have something to do with the difference between a rotation and a vector.  Each object in the world stores its rotation using just a single vector (which I am also using as the forward vector for movement, rotation and calculating the view). 

    Maybe this vector cannot be both without a special adjustment  

    Maybe I cannot use this vector for both LOOKATLH  (for view matrix) and for YAWPITCHROLL (for world matrix)

    -Dana


  • Matching view to world - help!