Jump to content
  • Advertisement
Sign in to follow this  
FantasyVII

My cube is deformed. Did I mess up my perspective matrix?

This topic is 955 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I implemented my own math library so I can understand computer graphics math better. But I think I didn't implement my perspective matrix correctly. I think my white cube is deformed.

 

 

 

CQcDpyS.png?1

 

 

 

nbtuTUY.png?1

 

 

My view matrix which is my camera, only translate everything by Vector3(0.0f, 0.0f, -2.0f). My red cube is at Vector3(0.0f, 0.0f, 0.0f). My white cub is translated by Vector3(2.0f, 0.0f, 0.0f).

 

Here is my perspective matrix implementation.

Matrix4 Matrix4::Perspective(const float FieldOfView, const float AspectRatio, const float Near, const float Far)
{
    Matrix4 PerspectiveMatrix = Matrix4::Identity();

    float t = 1.f / tan(ToRadians(FieldOfView / 2));
    
    //MATRIX_SIZE = 4
    PerspectiveMatrix.Elements[0 + 0 * MATRIX_SIZE] = t / AspectRatio;
    PerspectiveMatrix.Elements[1 + 1 * MATRIX_SIZE] = t;
    PerspectiveMatrix.Elements[2 + 2 * MATRIX_SIZE] = (Near + Far) / (Near - Far);
    PerspectiveMatrix.Elements[3 + 2 * MATRIX_SIZE] = -1.f;
    PerspectiveMatrix.Elements[2 + 3 * MATRIX_SIZE] = (2.f * Near * Far) / (Near - Far);

    return PerspectiveMatrix;
}

appc_fig02.jpg

Edited by FantasyVII

Share this post


Link to post
Share on other sites
Advertisement

There is nothing wrong with those results.


L. Spiro

 

Really? It feels weird to my. I don't know. I guess because I have never done any 3D programming before. Alright.

 

Thanks happy.png

Share this post


Link to post
Share on other sites

Here's your vanishing point, basically in the center of the screen as one would expect. Try changing your field of view if you don't like it.

 

T39bcEA.png

 

 

Alright. Thanks happy.png

Share this post


Link to post
Share on other sites

perspective projection will always change appearance of objects. If you want exact/architectural observing of objects, (not considering their depth etc.), you need to use ortho projection matrix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!