LoginSignup
1
1

More than 5 years have passed since last update.

vs2010でmanaged directx その10

Posted at

概要

c#で、3Dやりたかった。
RotationYawPitchRoll、使ってみた。

写真

image

サンプルコード

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        private Device device = null;
        private Mesh mesh = null;

        float x = 0,
            y = (float) Math.PI / 2,
            z = 0;
        private Matrix rot = Matrix.Identity;

        public Form1()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            PresentParameters pp = new PresentParameters();
            pp.Windowed = true;
            pp.SwapEffect = SwapEffect.Discard;
            device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pp);
            mesh = Mesh.Cylinder(device, 0.2f, 0.8f, 1.5f, 8, 1);
                        rot.Multiply(Matrix.RotationYawPitchRoll(y, x, z));
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 1.0f, 7.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
            device.Transform.Projection = Matrix.PerspectiveFovLH((float) (Math.PI / 4), 1.0f, 0.1f, 1000.0f);
            device.Clear(ClearFlags.Target, Color.DarkBlue, 1.0f, 0);
            device.BeginScene();
            device.SetTransform(TransformType.World, Matrix.Identity);
            device.RenderState.Lighting = false;


            device.Transform.World = rot;

            mesh.DrawSubset(0);

            device.EndScene();
            device.Present();
            this.Invalidate();
        }
    }
}

以上。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1