// tick for OpenGL rendering code public void RenderGL() { // measure frame duration float frameDuration = timer.ElapsedMilliseconds; timer.Reset(); timer.Start(); a += 0.001f * frameDuration; if (a > 2 * PI) { a -= 2 * PI; } float angle90degrees = PI / 2; Matrix4 Tcamera = Matrix4.CreateTranslation( new Vector3(xMove, -14.5f, zMove)) * Matrix4.CreateFromAxisAngle( new Vector3(1, 0, 0), angle90degrees) * Matrix4.CreateFromAxisAngle( new Vector3(0, 0, 1), rotate); Matrix4 Tview = Matrix4.CreatePerspectiveFieldOfView(1.2f, 1.3f, .1f, 1000); int specIn = GL.GetUniformLocation(shader.programID, "specRef"); GL.UseProgram(shader.programID); GL.Uniform3(specIn, new Vector3(0.1f, 0.1f, 0.1f)); sGraph.Render(Tcamera, Tview, target); }
// tick for OpenGL rendering code public void RenderGL() { screen.Print("Camera Move: UP, DOWN, LEFT, RIGHT", 2, 2, 0xffff00); screen.Print("Rotate: MOUSE LEFT, MOUSE RIGHT", 2, 32, 0xffff00); // measure frame duration float frameDuration = timer.ElapsedMilliseconds; timer.Reset(); timer.Start(); // prepare matrix for vertex shader float angle90degrees = PI / 2; Matrix4 Tpot = Matrix4.CreateScale(0.2f) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), a); Matrix4 Tplane1 = Matrix4.CreateScale(0.25f) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), -15 * a) * Matrix4.CreateTranslation(new Vector3(10, 0, 8)); Matrix4 Tfloor = Matrix4.CreateScale(6.0f) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), 0); Matrix4 Tplane2 = Matrix4.CreateScale(0.25f) * Matrix4.CreateTranslation(new Vector3(15, 0, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(0, 1, 0), -30 * a); Matrix4 toWorld = Tfloor; Matrix4 Tcamera = Matrix4.CreateTranslation(new Vector3(0, -25.5f, 0)) * Matrix4.CreateFromAxisAngle(new Vector3(1, 0, 0), angle90degrees); Matrix4 Tview = Matrix4.CreatePerspectiveFieldOfView(1.2f, 1.3f, .1f, 1000); //change transforms meshes.localT = Tfloor; meshes.getChildren()[0].localT = Tpot; meshes.getChildren()[0].getChildren()[0].localT = Tplane1; meshes.getChildren()[0].getChildren()[0].getChildren()[0].localT = Tplane2; // update rotation a += 0.0001f * frameDuration; if (a > 2 * PI) { a -= 2 * PI; } //render via scenegraph meshes.Render(Tmove * Tcamera * Tview, toWorld, Tmove); // render scene //mesh.Render(shader, Tpot * Tcamera * Tview, wood); //floor.Render(shader, Tfloor * Tcamera * Tview, wood); }