Graphics Reference
In-Depth Information
Finally, we assign the input layout to the IA, add the constant buffer to the vertex shader
stage, set the vertex shader and pixel shader programs, and set the OM depth stencil state.
Note that when setting the constant buffer, we have used slot 0.
This correlates with register(b0) in the shader code.
Render loop
The code within our D3DApp.Run() method first initializes our renderers, then sets up
our initial camera position, sets up our view and projection matrices, and finally starts our
rendering loop.
We have initialized a world matrix using an identity matrix which effectively means that we
are not translating, rotating, or scaling any of the objects in this scene.
In Direct3D, the traditional coordinate system is left-handed, with the camera view looking
down the Z+ axis with X+ to the right, and Y+ as up. The view matrix is created with the
camera position and where it is looking at and which direction is up. Here, we are placing the
camera slightly up, to the right, and behind the origin to give us a better view of the scene.
var cameraPosition = new Vector3(1, 1, -2);
var cameraTarget = Vector3.Zero; // Looking at the origin 0,0,0
var cameraUp = Vector3.UnitY; // Y+ is Up
var viewMatrix = Matrix.LookAtLH(cameraPosition, cameraTarget,
cameraUp);
Although we have used a left-handed coordinate system in this
recipe, we will move to using a right-handed coordinate system
in all subsequent chapters.
The projection matrix is created using the desired field-of-view angle, aspect ratio, and the
near and far Z-planes. This matrix gives us our perspective.
// FoV 60degrees = Pi/3 radians
var projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI / 3f,
Width / (float)Height, 0.5f, 100f);
 
Search WWH ::




Custom Search