2016-08-07 1 views
-1

나는 8 면체를 만들기 위해 OpenTK를 사용하고 있습니다. 나는 사각 피라미드를 만들었고 꼭대기 꼭대기 아래에있는 다른 것을 번역하고 그것을 뒤집어서 팔면체를 만들어야합니다.10 면체 만들기 (뒤집힌 뒤집기 피라미드) OpenTK

두 번째 피라미드를 거꾸로 뒤집으려면 어떻게해야합니까?

#region --- Using Directives --- 

using System; 
using System.Collections.Generic; 
using System.Windows.Forms; 
using System.Threading; 
using System.Drawing; 

using OpenTK; 
using OpenTK.Graphics; 
using OpenTK.Graphics.OpenGL; 
using OpenTK.Platform; 

#endregion 

namespace Octahedron 
{ 

    public class Octahedron : GameWindow 
    { 
     #region --- Fields --- 

     const float rotation_speed = 180.0f; 
     float angle; 

     #endregion 

     #region --- Constructor --- 

     public Octahedron() 
      : base(800, 600) 
     { } 

     #endregion 

     #region OnLoad 

     protected override void OnLoad(EventArgs e) 
     { 
      base.OnLoad(e); 

      GL.ClearColor(Color.MidnightBlue); 
      GL.Enable(EnableCap.DepthTest); 
     } 

     #endregion 

     #region OnResize 

     protected override void OnResize(EventArgs e) 
     { 
      base.OnResize(e); 

      GL.Viewport(0, 0, Width, Height); 

      double aspect_ratio = Width/(double)Height; 

      OpenTK.Matrix4 perspective = OpenTK.Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)aspect_ratio, 1, 64); 
      GL.MatrixMode(MatrixMode.Projection); 
      GL.LoadMatrix(ref perspective); 
     } 

     #endregion 

     #region OnUpdateFrame 

     protected override void OnUpdateFrame(FrameEventArgs e) 
     { 
      base.OnUpdateFrame(e); 

      var keyboard = OpenTK.Input.Keyboard.GetState(); 
      if (keyboard[OpenTK.Input.Key.Escape]) 
      { 
       this.Exit(); 
       return; 
      } 
     } 

     #endregion 

     #region OnRenderFrame 

     protected override void OnRenderFrame(FrameEventArgs e) 
     { 
      base.OnRenderFrame(e); 

      GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); 

      Matrix4 lookat = Matrix4.LookAt(0, 5, 10, 0, 0, 2, 0, 5, 0); 
      GL.MatrixMode(MatrixMode.Modelview); 
      GL.LoadMatrix(ref lookat); 

      angle += rotation_speed * (float)e.Time; 
      GL.Rotate(angle, 0.0f, 1.0f, 0.0f); 
      DrawPyramid(); 

      GL.Translate(0.0f, -2.0f, 0.0f); 
      DrawPyramid(); 

      this.SwapBuffers(); 
      Thread.Sleep(1); 
     } 

     #endregion 

     #region private void DrawPyramid() 

     private void DrawPyramid() 
     { 
      GL.Begin(PrimitiveType.Triangles); 
     //Side0 (red) 
                //x, y, z 
      GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(0.0f, 1.0f, 0.0f);//Top Vertex 

                //x,  y, z 
      GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);//Bottom Left Vertex 

                //x,  y, z 
      GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);//Bottom Right Vertex 

     //Side1 (blue) 

                //x, y, z 
      GL.Color3(0.0f, 0.0f, 1.0f); GL.Vertex3(0.0f, 1.0f, 0.0f);//Top Vertex 

                //x, y, z 
      GL.Color3(0.0f, 0.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);//Bottom Left Vertex 

                //x, y, z 
      GL.Color3(0.0f, 0.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, -1.0f);//Bottom Right Vertex 

     // Side2 (yellow) 

                //x, y, z 
      GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(0.0f, 1.0f, 0.0f); 

                //x,  y,  z 
      GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(1.0f, -1.0f, -1.0f); 

                //x,  y,  z 
      GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); 

     // Side3 (pink) 

                //x, y, z 
      GL.Color3(1.0f, 0.0f, 1.0f); GL.Vertex3(0.0f, 1.0f, 0.0f); 

                //x,  y,  z 
      GL.Color3(1.0f, 0.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, -1.0f); 

                //x,  y, z 
      GL.Color3(1.0f, 0.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f); 

    //Side4 (red) 
                //x, y, z 
      GL.Color3(1.0f, 1.0f, 1.0f); GL.Vertex3(0.0f, 1.0f, 0.0f);//Top Vertex 

                //x,  y, z 
      GL.Color3(1.0f, 1.0f, 1.0f); GL.Vertex3(-1.0f, -1.0f, 1.0f);//Bottom Left Vertex 

                //x,  y, z 
      GL.Color3(1.0f, 1.0f, 1.0f); GL.Vertex3(1.0f, -1.0f, 1.0f);//Bottom Right Vertex 

      GL.End(); 
     } 

     #endregion 


     #region public static void Main() 

     [STAThread] 
     public static void Main() 
     { 
      using (Octahedron oct = new Octahedron()) 
      { 
       oct.Run(60.0, 0.0); 
      } 
     } 

     #endregion 
    } 
} 

답변

1

힌트 : 여기서

내 원경 코드 X의 기준면 깔끔하게 정렬 단순하게, 예를 들면, Z 공간 (즉, 평면 (X, Y), (X 좌표 , z), (y, z)), 특정 축을 따라 무언가를 뒤집는 것은 특정 좌표에 -1을 곱하는 것과 같습니다. 보다 일반적인 경우 모든 좌표의 올바른 회전을 나타내는 미리 정의 된 행렬을 사용하여 행렬 곱셈을 사용할 수 있습니다.