Skip to content

Instantly share code, notes, and snippets.

@mellinoe
Created February 8, 2017 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mellinoe/14cf10705a8039463231fe798e181786 to your computer and use it in GitHub Desktop.
Save mellinoe/14cf10705a8039463231fe798e181786 to your computer and use it in GitHub Desktop.
while (window.Exists)
{
InputSnapshot snapshot = window.GetInputSnapshot(); // Process window events.
rc.ClearBuffer(); // Clear the screen.
rc.SetViewport(0, 0, window.Width, window.Height); // Ensure the viewport covers the whole window, in case it was resized.
float timeFactor = Environment.TickCount / 1000f; // Get a rough time estimate.
viewProjection.Data =
// Create a rotated camera matrix based on the current time.
Matrix4x4.CreateLookAt(
new Vector3(2 * (float)Math.Sin(timeFactor), (float)Math.Sin(timeFactor), 2 * (float)Math.Cos(timeFactor)),
Vector3.Zero, // Always look at the world origin.
Vector3.UnitY)
// And combine it with a perspective projection matrix.
* Matrix4x4.CreatePerspectiveFieldOfView(1.05f, (float)window.Width / window.Height, .5f, 10f);
rc.SetVertexBuffer(vb); // Attach the cube vertex buffer.
rc.SetIndexBuffer(ib); // Attach the cube index buffer.
rc.SetMaterial(material); // Attach the material.
rc.DrawIndexedPrimitives(Cube.Indices.Length); // Draw the cube.
rc.SwapBuffers(); // Swap the back-buffer and present the scene to the window.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment