続々々WindowsフォームアプリでXNAを使ってみる

XNA 4.0になって Effect.Begin、Effect.Endメソッドが無くなっていたので、Effectのクローンを作って対応してみた。 正解かどうかは不明だが・・・

1.共通情報であるViewとProjectionをセットした後にクローンを作成

            effect.View = Matrix.CreateLookAt(new Vector3(0, 0, -5), Vector3.Zero, Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 1, 10);
            //レクタングル描画用に複製を作る
            effectRect = (BasicEffect)effect.Clone();

2.描画

            // トライアングルを描画
            effect.VertexColorEnabled = true;
            effect.TextureEnabled = false;
            effect.World = Matrix.CreateFromYawPitchRoll(pitch, yaw, roll);
            effect.CurrentTechnique.Passes[0].Apply();
            GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, Vertices, 0, 1);
            // レクタングルを描画
            effectRect.VertexColorEnabled = false;
            effectRect.TextureEnabled = true;
            effectRect.Texture = texture;
            effectRect.World = Matrix.CreateFromYawPitchRoll(-pitch, yaw, roll);
            effectRect.CurrentTechnique.Passes[0].Apply();
            GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, VerticesRect, 0, 2);


コメント

このブログの人気の投稿

ARM用クロスコンパイラのビルド(Windows8+Cygwin)

Raspberry Pi のsleep時間測定

Cygwin+Emacs Problem