コード例 #1
0
        static void Main()
        {
            int width = 300, height = 300;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1        gameForm = new Form1();
            RenderDevice device   = new RenderDevice(gameForm, width, height);

            gameForm.Show();

            Viewport vp;

            vp.X      = 0;
            vp.Y      = 0;
            vp.Near   = 0.0f;
            vp.Far    = 1.0f;
            vp.Width  = width;
            vp.Height = height;

            device.Viewport = vp;

            device.ShadeMode        = ShadeMode.Smooth;
            device.DepthTestEnabled = true;
            device.DepthFunction    = DepthFunction.LessEqual;
            device.ClearColor       = Color.Black;
            device.DepthClearValue  = 1.0f;

            ReadMesh();

            while (gameForm.Created)
            {
                device.Clear(ClearFlags.Color | ClearFlags.Depth);

                // setup transforms

                device.ModelMatrix = Matrix.Scale(3, 3, 3) * Matrix.RotateY(Environment.TickCount / 180.0f);
                device.ViewMatrix  = Matrix.LookAt(new Vector3(0, 3, 5),
                                                   new Vector3(0, 0, 0),
                                                   new Vector3(0, 1, 0));
                device.ProjectionMatrix = Matrix.PerspectiveFOV((float)Math.PI / 4, width / height, 1.0f, 100.0f);

                // setup material
                Material mtrl = new Material();
                mtrl.Diffuse    = mtrl.Ambient = Color.White;
                device.Material = mtrl;

                // setup light
                Vector3 vecDir;
                Light   light = new Light();
                light.Type    = LightType.Directional;
                light.Diffuse = Color.White;
                vecDir        = new Vector3(0, 0, -1);
                vecDir.Normalize();
                light.Direction       = vecDir;
                light.Range           = 1000.0f;
                light.Enabled         = true;
                device.Light[0]       = light;
                device.LightEnabled   = true;
                device.AmbientLight   = Color.FromArgb(0x00202020);
                device.MaterialSource = MaterialSource.Material;

                device.BeginScene();
                device.DrawPrimitive(vertices, PrimitiveType.TriangleList, 0, polyNum);
                device.EndScene();

                device.Present();

                Application.DoEvents();
            }
        }