[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
 
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
| 左スクリーン | 右スクリーン | |
| X | 0 | 左スクリーンの横幅 | 
| Width | 画面の横幅の半分 | 画面の横幅の半分 | 
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class MyGame : Game
{
    GraphicsDeviceManager graphics;
    BasicEffect basicEffect;
    VertexPositionColor[] vertices = {
        new VertexPositionColor(new Vector3(0, 1, 0), Color.White),
        new VertexPositionColor(new Vector3(1, 0, 0), Color.Blue),
        new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red)
    };
    public MyGame()
    {
        graphics = new GraphicsDeviceManager(this);
    }
    protected override void LoadGraphicsContent(bool loadAllContent)
    {
        if (loadAllContent)
        {
            basicEffect = new BasicEffect(graphics.GraphicsDevice, null);
            basicEffect.View = Matrix.CreateLookAt(
                new Vector3(0, 0, 3),
                new Vector3(),
                new Vector3(0, 1, 0));
            basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45),
                ((float)Window.ClientBounds.Width / Window.ClientBounds.Height)/2,
                1, 100
                );
            basicEffect.VertexColorEnabled = true;
        }
    }
    protected override void Draw(GameTime gameTime)
    {
        graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
        graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(
            graphics.GraphicsDevice,
            VertexPositionColor.VertexElements
            );
        Viewport fullViewport = graphics.GraphicsDevice.Viewport;
        Viewport leftViewport = fullViewport;
        leftViewport.Width /= 2;
        graphics.GraphicsDevice.Viewport = leftViewport;
        drawTriangle();
        Viewport rightViewport = leftViewport;
        rightViewport.X = leftViewport.Width;
        graphics.GraphicsDevice.Viewport = rightViewport;
        drawTriangle();
        graphics.GraphicsDevice.Viewport = fullViewport;
    }
    private void drawTriangle()
    {
        basicEffect.Begin();
        foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
        {
            pass.Begin();
            graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
                PrimitiveType.TriangleList,
                vertices,
                0,
                1
                );
            pass.End();
        }
        basicEffect.End();
    }
}