Jump to content
  • Advertisement
Sign in to follow this  
Althar

[XNA] Slight confusion with CreatePerspective and BoundingFrustum

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

Hey everyone,

I am currently working on the camera code of my 2D game project. Now, although I have said "2D", entities have a 3D location, which is to be used both for a free parallax effect, as well as gameplay. I initially had an orthographic projection set up, in the following way :

mProjection = Matrix.CreateOrthographic(mRenderer.backBufferWidth * mDistance, mRenderer.backBufferHeight * mDistance, mNear, mFar);

The code is quite explicit, apart from mDistance maybe. This variable simply represents the distance/scaling factor of the camera, and otherwise expands the projection range to show a bigger part of the screen (in essence, zooming in and out).

I have switched this method to using "CreatePerspective" in the following way :

mProjection = Matrix.CreatePerspective(mRenderer.backBufferWidth, mRenderer.backBufferHeight, mNear, mFar);

The mDistance variable was moved to the actual view matrix computation, which is why it does not appear here. Although it works "visually", I found that the BoundingFrustum I compute for my Camera is no longer valid :

mFrustum.Matrix = this.view * this.projection;

The frustum is used for the culling of my entities, and the algorithm will work with the original orthographic projection, and perspective projection matrices defined in the following way :

mProjection = Matrix.CreatePerspective(1.0f, 1.0f/1.33f, mNear, mFar);

I am slightly confused, and failing to see why my solution fails : shouldn't I be allowed to project coordinates as I like. Essentially, with my setup, I am trying to map a unit to a single pixel. In other words, I would like an object of size 64*64 to be exactly 64*64 pixels on the screen, when it sits on the near plane.

Where have I gone wrong with my thinking process?

Your help and explanations would be appreciated biggrin.png !

Share this post


Link to post
Share on other sites
Advertisement
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!