cmodel.cs

来自「一个Wince的小程序」· CS 代码 · 共 79 行

CS
79
字号
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace WindowsFormsApplication1
{
    public class cModel
    {
        private Earth mesh1 = null;
        private Earth mesh2 = null;
        private bool modelloaded;
        public void Load(ref Device device)
        {
            mesh1 = new Earth(ref device);
            mesh2 = new Earth(ref device);
            if (mesh1.LoadMesh(@"..\..\earth2.x"))
            {
                modelloaded = true;
            }
            else
            {
                modelloaded = false;
            }
            if (mesh2.LoadMesh(@"..\..\moon.x"))
            {
                mesh2.XLoc += 20.0f;
                modelloaded = true;
            }
            else
            {
                modelloaded = false;
            }
        }

        public void Update(int dir)
        {
            if (dir > 0)
            {
                mesh1.YRot += 0.02f;
                mesh2.YRot += 0.05f;
            }
            else if (dir < 0)
            {
                mesh1.YRot -= 0.02f;
                mesh2.YRot -= 0.05f;
            }
        }

        public void Render(ref Device device)
        {
            device.Transform.World = Matrix.Identity;
            if (modelloaded)
            {
                mesh1.Render();
                mesh2.Render();
            }
        }

        public void LoadLights(ref Device device)
        {
            device.Lights[0].Type = LightType.Directional;
            device.Lights[0].Diffuse = Color.White;
            device.Lights[0].Position = new Vector3(0.0f, 0.0f, 25.0f);
            device.Lights[0].Direction = new Vector3(0, 0, -1);
        }
        public void Light(ref Device device)
        {
            device.Lights[0].Update();
            device.Lights[0].Enabled = true;
        }


    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?