public override void Render() { GL.Viewport(0, 0, MainGameWindow.Window.Width, MainGameWindow.Window.Height); GL.MatrixMode(MatrixMode.Projection); float aspect = (float)MainGameWindow.Window.Width / (float)MainGameWindow.Window.Height; Matrix4 perspective = Matrix4.Perspective(60, aspect, 0.01f, 1000.0f); GL.LoadMatrix(Matrix4.Transpose(perspective).Matrix); GL.MatrixMode(MatrixMode.Modelview); GL.LoadIdentity(); Matrix4 lookAt = Matrix4.LookAt(new Vector3(10.0f, 5.0f, 15.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); MatrixStack stack = new MatrixStack(); stack.Load(lookAt); GL.LoadMatrix(stack.OpenGL); grid.Render(); DrawPlanets(-1.0f, 1.0f, 0.0f,stack); }
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(); } }