Graphics Reference
In-Depth Information
var cameraPosition = new Vector3(1, 1, -2);
var cameraTarget = Vector3.Zero; // Looking at origin 0,0,0
var cameraUp = Vector3.UnitY; // Y+ is Up
// Create view matrix from our camera pos, target and up
var viewMatrix = Matrix.LookAtLH(cameraPosition, cameraTarget,
cameraUp);
// Create the projection matrix
// Field of View 60degrees = Pi/3 radians
// Aspect ratio (based on window size), Near clip, Far clip
var projectionMatrix = Matrix.PerspectiveFovLH((float)Math.PI /
3f, Width / (float)Height, 0.5f, 100f);
// Maintain the correct aspect ratio on resize
Window.Resize += (s, e) => {
projectionMatrix = Matrix.PerspectiveFovLH( (float)Math.PI / 3f,
Width / (float)Height, 0.5f, 100f);
};
Note that we are using a left-handed coordinate system for this recipe.
13. We can now implement our render loop. This is done the same way as in the previous
chapter, that is, by a call to RenderLoop.Run(Window, () => { ... }); .
After retrieving our device context, we first clear the depth stencil view and clear
the render target.
// Clear depth stencil view
context.ClearDepthStencilView(DepthStencilView,
DepthStencilClearFlags.Depth|DepthStencilClearFlags.
Stencil,1.0f,0);
// Clear render target view
context.ClearRenderTargetView(RenderTargetView, Color.White);
14. Next, we will multiply the view and projection matrices, and then create our WVP
matrix. Then this matrix is assigned to our constant buffer resource.
// Create viewProjection matrix
var viewProjection = Matrix.Multiply(viewMatrix,
projectionMatrix);
// Create WorldViewProjection Matrix
 
Search WWH ::




Custom Search