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

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

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633744
• Total Posts
3013654
×