I want to display coordinates from 0 to n, where n is int > 0.
The map is displayed correctly heaving it's center in the middle of the screen pointing top right. I would like to have it pointing bottom right.

My implementation is:

effect.Parameters["wvp"].SetValue(Matrix.Translation(0, 0, 0) *
    Matrix.LookAtLH(Vector3.Zero, Vector3.UnitZ, Vector3.Up) *
    Matrix.OrthoLH(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 1));


GraphicsDevice.Draw(PrimitiveType.TriangleList, layer.Buffer.ElementCount);

And a screenshot of the situation now. Screenshot The white area is around coordinate (0, 0). The line is just at X = Y for orientation. The black line should be pointing bottom right as mentioned above. Any Idea how this can be done?


To do this the right way, you'll need to do two things. First, adjust your Translation matrix to offset by -1 in the Y direction (0, -1, 0). Second, you should adjust the texture coordinates in your layer.Buffer data so that it matches what you want. Alternatively, if you are reusing the layer.Buffer for multiple positions, you can programmatically adjust the coordinates by modifying effect parameters other than wvp, assuming the effect supports it.

  • \$\begingroup\$ using your method now but without translation of (0, -1, 0) because it's a normal RPG. Had a multiplication mistake in shader aswell (vector * matrix or matrix * vector. Damnit.) \$\endgroup\$ – AliveDevil Oct 4 '13 at 20:00

Negate the height in your OrthoLH call and that should do the trick.

Note that if you're using backface culling, you'll have to reverse the culling orientation after making this change, as it switches the handedness of the coordinate system.

  • \$\begingroup\$ This is a terrible hack! What happens when he wants to add a second object in the scene? Add a new projection matrix for every one? \$\endgroup\$ – MooseBoys Oct 4 '13 at 18:20
  • \$\begingroup\$ @MooseBoys I read the question as being about setting up the whole view so that the world Y axis points down - not about the specific object. Of course, if it's just one object that needs to be reoriented then it should be done in the world matrix for that object. \$\endgroup\$ – Nathan Reed Oct 4 '13 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.