この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
c.sharp:opentk [2018/05/01 07:59] fifi |
c.sharp:opentk [2018/05/03 13:32] (現在) fifi |
||
|---|---|---|---|
| ライン 5: | ライン 5: | ||
| - [giawa/opengl4tutorials: Tutorial Particle](https://github.com/giawa/opengl4tutorials) | - [giawa/opengl4tutorials: Tutorial Particle](https://github.com/giawa/opengl4tutorials) | ||
| - [neokabuto/OpenTKTutorialContent: Project files from OpenTK tutorials from my blog](https://github.com/neokabuto/OpenTKTutorialContent) | - [neokabuto/OpenTKTutorialContent: Project files from OpenTK tutorials from my blog](https://github.com/neokabuto/OpenTKTutorialContent) | ||
| + | - [jeske/SimpleScene: Simple 3D scene manager in C# and OpenTK / OpenGL](https://github.com/jeske/SimpleScene) | ||
| + | # 座標変換を完全に理解する | ||
| + | |||
| + | - ワールド座標変換 | ||
| + | - ビュー/プロジェクション座標変換 | ||
| + | -- 2Dに変換する工程 | ||
| + | -- クリッピング座標系(正規化視野空間とか正規化デバイス座標系) | ||
| + | -- 透視投影変換 | ||
| + | -- 平行投影変換 | ||
| + | |||
| + | - 射影変換 | ||
| + | |||
| + | ```c | ||
| + | // 実際に表示されているアプリケーションの画面のどの領域に表示するかを指定 | ||
| + | GL.Viewport(0, Width, 0, Height); | ||
| + | |||
| + | // 基本形 | ||
| + | //画面描画で実行される。 | ||
| + | protected override void OnRenderFrame(FrameEventArgs e) | ||
| + | { | ||
| + | base.OnRenderFrame(e); | ||
| + | |||
| + | GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); | ||
| + | | ||
| + | // [クリッピング座標系] クリッピング空間の指定. カメラの表示画角を指定するだけ (順不動) | ||
| + | GL.MatrixMode(MatrixMode.Projection); | ||
| + | Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, (float)glControl.Size.Width / (float)glControl.Size.Height, 1.0f, 64.0f); | ||
| + | GL.LoadMatrix(ref projection); | ||
| + | | ||
| + | // [ビュー座標系] カメラの位置,方向,を指定するだけ (順不動) | ||
| + | GL.MatrixMode(MatrixMode.Modelview); | ||
| + | Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY); | ||
| + | GL.LoadMatrix(ref modelview); | ||
| + | | ||
| + | // ワールド座標系でオブジェクトを配置 | ||
| + | GL.Begin(BeginMode.Quads); | ||
| + | |||
| + | GL.Color4(Color4.White); //色名で指定 | ||
| + | GL.Vertex3(-1.0f, 1.0f, 4.0f); | ||
| + | GL.Color4(new float[] { 1.0f, 0.0f, 0.0f, 1.0f }); //配列で指定 | ||
| + | GL.Vertex3(-1.0f, -1.0f, 4.0f); | ||
| + | GL.Color4(0.0f, 1.0f, 0.0f, 1.0f); //4つの引数にfloat型で指定 | ||
| + | GL.Vertex3(1.0f, -1.0f, 4.0f); | ||
| + | GL.Color4((byte)0, (byte)0, (byte)255, (byte)255); //byte型で指定 | ||
| + | GL.Vertex3(1.0f, 1.0f, 4.0f); | ||
| + | |||
| + | GL.End(); | ||
| + | |||
| + | SwapBuffers(); | ||
| + | } | ||
| + | |||
| + | ``` | ||
| # 3Dの座標グリッドを美しく表示する方法 | # 3Dの座標グリッドを美しく表示する方法 | ||
| ライン 74: | ライン 126: | ||
| GL.Viewport(0, 0, Width, Height); | GL.Viewport(0, 0, Width, Height); | ||
| - | GL.Ortho(0, Width, Height, 0, -1, 1); | + | GL.Ortho(0, Width, Height, 0, -1, 1); // 射影変換 その他Perspectiveもある |
| // ******** Text Rendering | // ******** Text Rendering | ||