using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace ConbinedTransformation
{
public partial class Form1 : Form
{
int flag = 0;
///立方体初始顶点坐标
float[,] Cube1 = { { -1, -0.5f, -1 }, { 1, -0.5f, -1 }, { 1, -0.5f, 1 }, { -1, -0.5f, 1 },
{ -1, 0.5f, -1 }, { 1, 0.5f, -1 }, { 1, 0.5f, 1 }, { -1, 0.5f, 1 } };
float[,] Cube2 = { { -1, -0.5f, -1 }, { 1, -0.5f, -1 }, { 1, -0.5f, 1 }, { -1, -0.5f, 1 },
{ -1, 0.5f, -1 }, { 1, 0.5f, -1 }, { 1, 0.5f, 1 }, { -1, 0.5f, 1 } };
Vector4[] tCube1 = new Vector4[8]; //变换后的Cube1顶点坐标
Vector4[] tCube2 = new Vector4[8];
float translationx, rotationy;//瞬时运动参数,平移、转角
float xstep, rstep; //单位时间移动、转动步长
float cx, cy, cz; //照相机位置
float dx, dy, dz; //照相机方向
float upx, upy, upz; //照相机上方
float ux, uy, uz, vx, vy, vz, nx, ny, nz; //照相机坐标系
float zp; //视平面位置
float wxl, wxr, wyb, wyt; //窗口参数
float vxl, vxr, vyb, vyt; //视区参数
Graphics g;
public Form1()
{
InitializeComponent();
g = CreateGraphics();
g.SmoothingMode = SmoothingMode.AntiAlias;
//图形运动参数,平移、转动、平移步长,转动步长为10度
translationx = 0;
rotationy = 0;
xstep = 0.2f;
rstep = 10;
cx = 2; cy = 5; cz = 12; //照相机位置
dx = -cx; dy = -cy; dz = -cz; //照相机方向
upx = 0; upy = 1; upz = 0; //照相机上方参考向量
zp = cz; //投影面位置
wxl = -5; wxr = 5; wyb = -3; wyt = 3; //窗口参数
vxl = 0; vxr = 640; vyb = 0; vyt = 480; //视区参数
float d; //单位化视线向量
d = (float)Math.Sqrt(dx * dx dy * dy dz * dz);
///照相机坐标系第3轴,N = (dx,dy,dz)
nx = dx / d;
ny = dy / d;
nz = dz / d;
///照相机坐标系第1轴,U = N * UP
ux = (ny * upz - nz * upy);
uy = (nz * upx - nx * upz);
uz = (nx * upy - ny * upx);
///照相机坐标系第2轴,V = U * N
vx = (uy * nz - uz * ny);
vy = (uz * nx - ux * nz);
vz = (ux * ny - uy * nx);
}
private void DrawString()
{
String str;
str = "点击鼠标: (暂停/继续)";
g.DrawString(str, new Font("宋体", 16, FontStyle.Regular), Brushes.Black, 300, 30);