public void MouseMove(int x, int y) { if (this.mouseDownFlag) { IViewCamera camera = this.Camera; if (camera == null) { return; } vec3 back = this.back; vec3 right = this.right; vec3 up = this.up; Size bound = this.bound; Point downPosition = this.downPosition; { float deltaX = -horizontalRotationFactor * (x - downPosition.X) / bound.Width; float cos = (float)Math.Cos(deltaX); float sin = (float)Math.Sin(deltaX); vec3 newBack = new vec3( back.x * cos + right.x * sin, back.y * cos + right.y * sin, back.z * cos + right.z * sin); back = newBack; right = up.VectorProduct(back); back.Normalize(); right.Normalize(); } { float deltaY = verticalRotationFactor * (y - downPosition.Y) / bound.Height; float cos = (float)Math.Cos(deltaY); float sin = (float)Math.Sin(deltaY); vec3 newBack = new vec3( back.x * cos + up.x * sin, back.y * cos + up.y * sin, back.z * cos + up.z * sin); back = newBack; up = back.VectorProduct(right); back.Normalize(); up.Normalize(); } camera.Position = camera.Target + back * (float)((camera.Position - camera.Target).Magnitude()); camera.UpVector = up; this.back = back; this.right = right; this.up = up; this.downPosition.X = x; this.downPosition.Y = y; } }
private static void GetBackAndUp(out vec3 target2Position, out vec3 upVector, ViewTypes viewType) { switch (viewType) { case ViewTypes.UserView: //UserView 定义为从顶视图开始,绕X 轴旋转30 度,在绕Z 轴45 度,并且能看到整个模型的虚拟模型空间。 target2Position = new vec3((float)Math.Sqrt(3), (float)Math.Sqrt(3), -1); target2Position.Normalize(); upVector = new vec3(0, 0, -1); break; case ViewTypes.Top: target2Position = new vec3(0, 0, -1); upVector = new vec3(0, -1, 0); break; case ViewTypes.Bottom: target2Position = new vec3(0, 0, 1); upVector = new vec3(0, -1, 0); break; case ViewTypes.Left: target2Position = new vec3(-1, 0, 0); upVector = new vec3(0, 0, -1); break; case ViewTypes.Right: target2Position = new vec3(1, 0, 0); upVector = new vec3(0, 0, -1); break; case ViewTypes.Front: target2Position = new vec3(0, 1, 0); upVector = new vec3(0, 0, -1); break; case ViewTypes.Back: target2Position = new vec3(0, -1, 0); upVector = new vec3(0, 0, -1); break; default: throw new NotImplementedException(string.Format("new value({0}) of EViewType is not implemented!", viewType)); //break; } }