I would like to use a Perspective projection to create the following effect in XNA:
Cubes are simply made up of 8 vertices and drawn using
Any extra suggestions, are also welcome.
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
If what you want is indeed like your drawing suggests, then you're looking to implement an oblique projection. Check this video for an example of this type of projection in a game. The big difference is that the game in the video uses a set of pre-made tiles, while you're trying to do the projection mathematically.
For starters, here's a picture which should make evident the difference between perspective, isometric and oblique projections. Use it to decide which of these you really want.
Now, you can implement both Perspective and Isometric projections using methods already available in the XNA API:
Matrix.CreatePerspectivefamily of methods.
Matrix.CreateOrthographicfamily of methods, and rotate your camera (or your objects) a bit in the X and Y axes so that they match the isometric look.
As for an Oblique Projection, I think it will be a bit more complicated. I've actually never seen an implementation of this before, so I'll just be going with my intuition. Someone let me know if there's a better, known solution to the problem. You're going to need a vertex shader. Here's the steps:
Use a vertex shader, and after applying the projection matrix, modify the X and Y values using the following formula taken from the wikipedia article above. The angle should probably be around 45 degrees (you might have to invert the sign of Z depending in which space you do the calculation):
Optionally you could do this last calculation with a vector instead. For instance, if the angle is indeed 45 degrees, you could do this last step as something like:
position.xy += z * normalize(float2(1,1));
This should make vertices that are further away from the camera, be rendered more to the right, and up from their original positions.