Jump to content
  • Advertisement
Sign in to follow this  

Perspective Projection

This topic is 3338 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

I'm wanting to demo perspective projection and am currently working in DirectX. When I say demo I mean rotate around the scene and view the projection from different angles. I have a box mesh, that I create two copies of. I transform both copies somewhere, into the world, lets say 10.0 on the z-axis. I then apply the perspective transform to one of them and seem to get a correct result. What I am having a hard time visualising is how to demo it. Am I able to make sure the projected transform is always transformed to the same region. If my understanding is correct it gets transformed to the origin, between 0.0 and 1.0f. But as I move the box further away the projected box seems to move also, it makes it hard to keep a static camera on the projection. Here is my perspective transform code:
void Matrix4x4::setupPerspectiveProject(const float &fov, const float &aspect, const float &zNear, const float &zFar)
	float cotATwo = 1.0f / (tan(fov / 2.0f));

	m11 = (1.0f / aspect) * cotATwo;
	m12 = 0.0f; 
	m13 = 0.0f; 
	m14 = 0.0f;

	m21 = 0.0f;         
	m22 = cotATwo;    
	m23 = 0.0f; 
	m24 = 0.0f;

	m31 = 0.0f;         
	m32 = 0.0f; 
	m33 = zFar / (zFar - zNear);
	m34 = 1.0f;

	m41 = 0.0f;
	m42 = 0.0f;
	m43 = -((zFar * zNear) / (zFar - zNear));
	m44 = 0.0f;

Any tips would be appreciated.

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.

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!