private float rota = 0;//旋转 private void Tick(object sender, ElapsedEventArgs e) { lock (_frameBuff) { clearBuff(); rota += 0.05f; //获取旋转矩阵 Matrix4x4 rotaX = MathUntil.GetRotateX(rota); Matrix4x4 rotaY = MathUntil.GetRotateY(rota); Matrix4x4 translate = MathUntil.GetTranslate(0, 0, 10); Matrix4x4 m = rotaX * rotaY * translate; //计算相机视矩阵 Matrix4x4 v = MathUntil.GetView(_camera.pos, _camera.lookAt, _camera.up); //投影矩阵 Matrix4x4 p = MathUntil.GetProjection(_camera.fov, _camera.aspect, _camera.zn, _camera.zf); Draw(m, v, p); if (_frameG2 == null) { _frameG2 = CreateGraphics(); } _frameG2.Clear(System.Drawing.Color.Black); _frameG2.DrawImage(_frameBuff, 0, 0); } }
private void Tick(object sender, EventArgs e) { lock (_frameBuff) { ClearBuff(); rot += 0.05f; Matrix4x4 m = MathUntil.GetRotateX(rot) * MathUntil.GetRotateY(rot) * MathUntil.GetTranslate(0, 0, 10); Matrix4x4 v = MathUntil.GetView(_camera.pos, _camera.lookAt, _camera.up); Matrix4x4 p = MathUntil.GetProjection(_camera.fov, _camera.aspect, _camera.zn, _camera.zf); // Draw(m, v, p); if (g == null) { g = this.CreateGraphics(); } g.Clear(System.Drawing.Color.Black); g.DrawImage(_frameBuff, 0, 0); } }
private void timer1_Tick(object sender, EventArgs e) { lock (_frameBuff) { ClearBuff(); CMatrix4x4 m = new CMatrix4x4(); m.Identity(); m[3, 2] = 5; rot += 0.1f; m = MathUntil.GetRotateY(rot) * m; CMatrix4x4 v = MathUntil.GetView(new CVector3D(0, 0, 0, 1), new CVector3D(0, 0, 1, 1), new CVector3D(0, 1, 0, 1)); CMatrix4x4 p = MathUntil.GetProjection((float)System.Math.PI / 4, this.MaximumSize.Width / (float)this.MaximumSize.Height, 1f, 500f); // Draw(m, v, p); // if (g1 == null) { g1 = this.CreateGraphics(); } g1.Clear(System.Drawing.Color.Black); g1.DrawImage(_frameBuff, 0, 0); } this.Invalidate(); }