Jump to content

  • Log In with Google      Sign In   
  • Create Account

Camera view matrix issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 BlackJoker   Members   -  Reputation: 532

Like
0Likes
Like

Posted 16 August 2014 - 12:16 PM

Hello.

I faced with the issue when creating my camera in SharpDX.

Whaen I create camera instance I could set any camera lookAt vector and it works, but when I rebuild view matrix with other VectorUP (form Y to Z for ex) camera starts to look at the center of coordinates from the same position, but it must only change its orientation and not more.

public void SetUp(Vector3 _up)
        {
            Matrix tmpMatrix = ViewMatrix;

            Vector3 currentLookAt = new Vector3(tmpMatrix.M13, tmpMatrix.M23, tmpMatrix.M33);
         

            ViewMatrix = Matrix.LookAtLH(position, currentLookAt, _up);


Vector3 scale;
            Quaternion rotation;
            Vector3 translation;

            ViewMatrix.Decompose(out scale, out rotation, out translation);
            rotation = Quaternion.Normalize(rotation);
 ViewMatrix = Matrix.Multiply(Matrix.Translation(Vector3.Negate(position)), Matrix.RotationQuaternion(rotation));
            xAxis = new Vector3(ViewMatrix.M11, ViewMatrix.M21, ViewMatrix.M31);
            yAxis = new Vector3(ViewMatrix.M12, ViewMatrix.M22, ViewMatrix.M32);
            zAxis = new Vector3(ViewMatrix.M13, ViewMatrix.M23, ViewMatrix.M33);
        }

Can someone say what I am doing wrong here? 



Sponsor:

#2 BlackJoker   Members   -  Reputation: 532

Like
0Likes
Like

Posted 20 August 2014 - 12:40 AM

This issue is not actual already.



#3 haegarr   Crossbones+   -  Reputation: 4311

Like
0Likes
Like

Posted 20 August 2014 - 01:29 AM

A transformation matrix expresses a position and an orientation (letting scaling aside here). The function Matrix.LookAtLH(...) expects the camera position, the target position, and the up vector as arguments. Your routine SetUp(...) is written so that it tries to read the target position (named currentLookAt therein) from the view's transformation matrix. But there is nothing within the matrix that stores those position, and there is not enough information available to reconstruct it. The only position within that matrix is the own (i.e. view's) position.

 

In other words, this line

ViewMatrix = Matrix.LookAtLH(position, currentLookAt, _up);

doesn't give you what you expect.

 

So the routine SetUp(...) need to be revised. I suggest to do something like the following:

1.) Get the scaling values from the matrix.

2.) Get the forward vector from the matrix.

3.) Compute the new side vector by using the cross-product of forward and new up vectors.

4.) Scale the three direction vectors accordingly to the values calculated in 1.)

5.) Insert the scaled up and new side vectors into the matrix.


Edited by haegarr, 20 August 2014 - 01:37 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS