I am currently developing a Direct3D 11 rendering engine using C#.
I have already succeded in drawing triangles, applying color and textures, etc.
The object I am trying to display now is a rotated cube with a side length of 1 placed at the origin of the world space.
But I am getting unsatisfying results when applying the view and especially the projection matrix. As it is difficult to explain, I just show you what result I get for different view/projection combinations:
HLSL snippet from my vertex shader:
float4x4 wvpMatrix = mul(World, mul(View, Projection));
output.Position = mul(input.Position, wvpMatrix);
The world matrix I use:
// Static rotation around all three axes
matrices.World = Matrix.Identity * Matrix.CreateFromYawPitchRoll(0.5f, 0.6f, 1.0f);
Test A
Simple view vector from origin in the positive z direction. No projection used.
You can see that the back of the cube is being clipped.
matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, 1), Vector3.Up);
matrices.Projection = Matrix.Identity;

Test B
View matrix stays the same, but now I am using an orthographic projection matrix.
This time the front of the cube vanishes. The parts you can see are those which were clipped in Test A.
matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, 1), Vector3.Up);
matrices.Projection = Matrix.CreateOrthographic(2, 2, 0.01f, 100.0f);

Test C
Again no projection, just like in Test A. This time the scene is being viewed from a point three units in the negative z direction.
The cube looks distorted when the camera position is not set to the origin of the system. I think there is also some clipping.
matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, -3), new Vector3(0, 0, 1), Vector3.Up);
matrices.Projection = Matrix.Identity;

Test D
Finally, I use a perspective projection. Up to now I have not found a camera position from which any part of the cube is visible. All I get is fullscreen cornflower blue.
matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, -3), new Vector3(0, 0, 1), Vector3.Up);
matrices.Projection = Matrix.CreatePerspectiveFieldOfView(1, 1, 0.1f, 100);

First thing I want to do is drawing the full cube – no clipping. I tried different combinations of near/far plane values but I could not find an acceptable solution.
My final goal would be to have a perspective projection. But as you see I can’t even get a good orthagonal view of the scene.
The matrices must be transposed at some point.
Reason:
The layout of the
Microsoft.Xna.Framework.Matrixstruct is row-based. Matrices in HLSL are column-based.From the XNA Documentation:
From the Wikipedia article on matrix order:
Solution A:
Transpose all matrices before they are sent to the shader:
Solution B:
Put this line in your shader code: