Public Group

# 2D camera movement in DX9

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

## Recommended Posts

I'm trying to simulate a 2D scroller but when I scroll the camera the cube mesh begins to show it's sides. I'm using D3D within DX9 but believe it's my lack of understanding that's actually the problem. Here are my matrices. . . worldMatrix = Matrix.Identity projMatrix = Matrix.PerspectiveFovLH(System.Convert.ToSingle(Math.PI) / 4, Me.Width / Me.Height, 1.0F, 50000.0F) viewMatrix = Matrix.LookAtLH(New Vector3(sXposition, sYposition, sDistance), New Vector3(sXposition, sYposition, 0), New Vector3(0, 1, 0)) where sXposition, sYposition are singles used to move the camera in the X and Y direction by simply adding or subracting. I then calculate the rendering position each frame with Dim worldViewProj As Matrix = Matrix.Multiply(Matrix.Multiply(worldMatrix, viewMatrix), projMatrix) and pass it into my shader file like this effect.SetValue(EffectHandle.FromString("WorldViewProj"), worldViewProj) Although this does result in the cube appearing to move it begins to show it's side opposite the direction of the scroll movement. I.e. when I continue to scroll in the same direction the cube starts to rotate ever so slightly showing it's side? Is this simply due to the fact that if a camera was to pass directly overhead you would see any objects side slightly as you passed over it's center? Is there a way I can keep it so I only see the top of the object as I move the camera and if so what am I doing wrong? Many thanks Seiko

##### Share on other sites
The reason you can see the cubes sides is because of perspective, if you pick up a block at look at it straight on you can hold it in such a way that you can only see one face. If you move your head you'll be able to see more than one face, this is what's happening in your game.

What you need is an orthographic projection (you'd set an orthographic projection matrix for your projection matrix to do this). This will make everything appear flat without perspective.

##### Share on other sites
thanks for such a quick answer. works great
:)

1. 1
Rutin
35
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633343
• Total Posts
3011430
• ### Who's Online (See full list)

There are no registered users currently online

×