예제 #1
0
파일: Form1.cs 프로젝트: kistvan/geditor
        public void init(StreamWriter st)
        {
            st.WriteLine("初期化開始");

            pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

            st.WriteLine("デバイス作成の開始");
            device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.pictureBox1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            {
                BackBufferWidth = this.pictureBox1.ClientSize.Width,
                BackBufferHeight = this.pictureBox1.ClientSize.Height,
                Windowed = true,
            });
            st.WriteLine("デバイス作成の終了");
            Capabilities caps = device.Capabilities;
            st.WriteLine("adapterOrdinal:" + caps.AdapterOrdinal);
            st.WriteLine("DeviceType:" + caps.DeviceType);
            if (caps.VertexShaderVersion.Major < 3)
            {
                MessageBox.Show("VertexShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }
            else if (caps.PixelShaderVersion.Major < 3)
            {
                MessageBox.Show("PixelShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }

            st.WriteLine("DeviceContextの初期化");
            DeviceContext.init(device);

            st.WriteLine("ZEnableの初期化");
            device.SetRenderState(RenderState.ZEnable, true);

            st.WriteLine("cameraの初期化");
            camera = new Camera(device);

            st.WriteLine("Floorの初期化");
            floorMap = new FloorMap(device);

            //            teapot = Mesh.CreateTeapot(device);
            //            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);

            st.WriteLine("照明の初期化");
            device.SetRenderState(RenderState.Lighting, true);
            device.SetLight(0, new Light() {
                Type = LightType.Directional,
                Diffuse = Color.White,
                Ambient = Color.Gray,
                Direction = new Vector3(1.0f, 1.0f, 0.0f),
            });
            device.EnableLight(0,true);
            standardLine = new StandardLine(device);
            //射影変換
            device.SetTransform(TransformState.Projection,
                                 Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                                                         (float)this.pictureBox1.ClientSize.Width / (float)this.pictureBox1.ClientSize.Height,
                                                         0.1f, 1500.0f));
            //ビュー
            device.SetTransform(TransformState.View,
                                 camera.getLookAtLh());

            device.SetTransform(TransformState.World, Matrix.Identity);

            st.WriteLine("FloorModelの初期化");
            floorModel = new FloorModel(new MqoParser(device).parse(".\\projects\\sample\\model\\floor.mqo", new MqoModel()));

            st.WriteLine("初期化終了");
        }