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

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

## 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.

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;
}


Edited by FantasyVII

##### Share on other sites
There is nothing wrong with those results.

L. Spiro

##### Share on other sites

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

##### 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.

Alright. Thanks

##### Share on other sites

Yeah that's normal. Maybe you're being thrown off by the FOV angle?

##### 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634136
• Total Posts
3015755
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!