Jump to content
  • Advertisement
Sign in to follow this  
Seiko

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!