public MainWindow() { InitializeComponent(); //当前窗口创建graphics canvas = this.CreateGraphics(); //当前窗口的宽高值 buffer = new Bitmap(this.Width, this.Height); RenderUtility.SetFrameBuffer(buffer); //根据buffer的大小设定zbuffer zbuffer = new float[this.Width, this.Height]; RenderUtility.SetZBuffer(zbuffer); //创建平行光,平行光的位置默认为(0, 20, 0),光照颜色为橘黄色,环境光颜色为白色 light = new Light(new Vector3(0, 20, 0, 1), new Color4(Color.Orange), new Color4(Color.White)); RenderUtility.SetLight(light); //创建摄像机, 摄像机位置默认为(0,0,0),朝向z轴方向(0,0,1),以(0,1,0)为单位up向量,y方向的视角为90度,zn = 1, zf = 500 float aspect = (float)this.Width / (float)this.Height; camera = new Camera(new Vector3(0, 0, 0, 1), new Vector3(0, 0, 1, 0), new Vector3(0, 1, 0, 0), 3.1415926f / 4, aspect, 1.0f, 500.0f); //设定渲染的模式 renderType = RenderType.WireFrame; renderType = RenderType.VertexColor; RenderUtility.SetRenderType(renderType); //加载模型 //meshs,要渲染的网格列表 meshs = new List <Mesh>(); Mesh cube = new Mesh(Cube.positions, Cube.indices, Cube.colors); meshs.Add(cube); //开启计时器 SetupTimer(); }