public override void Render() { GL.Viewport(0, 0, MainGameWindow.Window.Width, MainGameWindow.Window.Height); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); Perspective(60.0f, (float)MainGameWindow.Window.Width / (float)MainGameWindow.Window.Height, 0.01f, 1000.0f); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); LookAt(10.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); grid.Render(); GL.PushMatrix(); { GL.Color3(1.0f, 0.0f, 0.0f); Matrix4 scale = Matrix4.Scale(new Vector3(0.5f, 0.5f, 0.5f)); Matrix4 rotation = Matrix4.AngleAxis(45.0f, 1.0f, 0.0f, 0.0f); Matrix4 translation = Matrix4.Translate(new Vector3(-2.0f, 1.0f, 3.0f)); Matrix4 model = translation * rotation * scale; GL.MultMatrix(Matrix4.Transpose(model).Matrix); DrawCube(); } GL.PopMatrix(); }
public void Pivot(float yaw, float pitch) { worldDirty = true; viewDirty = true; Matrix4 yawAngle = Matrix4.AngleAxis(yaw, up.X, up.Y, up.Z); forward = Matrix4.MultiplyVector(yawAngle, forward); Matrix4 pitchAngle = Matrix4.AngleAxis(pitch, right.X, right.Y, right.Z); forward = Matrix4.MultiplyVector(pitchAngle, forward); forward = Vector3.Normalize(forward); right = Vector3.Normalize(right); up = Vector3.Normalize(up); }
protected void DrawPlanets(float worldX, float worldY, float worldZ, MatrixStack stack) { stack.Push(); { GL.Color3(1.0f, 1.0f, 0.0f); //sun Matrix4 scale = Matrix4.Scale(new Vector3(0.5f, 0.5f, 0.5f)); Matrix4 translation = Matrix4.Translate(new Vector3(worldX, worldY, worldZ)); Matrix4 model = translation * scale; stack.Mul(model); GL.LoadMatrix(stack.OpenGL); Circle.DrawSphere(3); stack.Push(); { GL.Color3(0.0f, 1.0f, 0.0f); //first planet Matrix4 p1scale = Matrix4.Scale(new Vector3(0.8f, 0.8f, 0.8f)); Matrix4 p1rotation = Matrix4.AngleAxis(planet1RotSpeed, 0.0f, 1.0f, 1.0f); Matrix4 p1translation = Matrix4.Translate(new Vector3(-2.5f, 0.5f, 0.0f)); Matrix4 planet = p1rotation * p1translation * p1scale; stack.Mul(planet); GL.LoadMatrix(stack.OpenGL); Circle.DrawSphere(1); stack.Push(); { //draw planet1 moon GL.Color3(1.0f, 0.0f, 0.0f); Matrix4 m1Scale = Matrix4.Scale(new Vector3(0.5f, 0.5f, 0.5f)); Matrix4 m1Rotation = Matrix4.AngleAxis(moon1RotSpeed, 0.0f, 1.0f, 0.0f); Matrix4 m1Translation = Matrix4.Translate(new Vector3(-2.0f, 0.0f, 0.0f)); Matrix4 moon = m1Rotation * m1Translation * m1Scale; stack.Mul(moon); GL.LoadMatrix(stack.OpenGL); Circle.DrawSphere(1); } stack.Pop(); }//end first planet stack.Pop(); stack.Push(); { //second planet GL.Color3(0.0f, 0.0f, 1.0f); Matrix4 pscale = Matrix4.Scale(new Vector3(0.8f, 0.8f, 0.8f)); Matrix4 protation = Matrix4.AngleAxis(planet2RotSpeed, 0.0f, 1.0f, 0.0f); Matrix4 ptranslation = Matrix4.Translate(new Vector3(12.0f, 0.5f, 0.0f)); Matrix4 planet = protation * ptranslation * pscale; stack.Mul(planet); GL.LoadMatrix(stack.OpenGL); Circle.DrawSphere(1); stack.Push(); { //draw planet1 moon GL.Color3(0.5f, 1.0f, 1.0f); Matrix4 mScale = Matrix4.Scale(new Vector3(0.5f, 0.5f, 0.5f)); Matrix4 mRotation = Matrix4.AngleAxis(moon2RotSpeed, 1.0f, 1.0f, 1.0f); Matrix4 mTranslation = Matrix4.Translate(new Vector3(2.0f, 0.0f, 0.0f)); Matrix4 moon = mRotation * mTranslation * mScale; stack.Mul(moon); GL.LoadMatrix(stack.OpenGL); Circle.DrawSphere(1); } stack.Pop(); } stack.Pop(); } }