WPF中3D旋转的实现
来源:互联网 发布:骑砍战团 for mac下载 编辑:程序博客网 时间:2024/04/30 03:41
关于3D旋转的原理,请看Daniel Lehenbauer的文章
《Rotating the Camera with the Mouse》
http://viewport3d.com/trackball.htm
里面非常清楚的讲解了原理和方法,很受用。
相关代码:
2.1 Finding the Point on the Sphere
private Vector3D ProjectToTrackball(Double width, Double height, Point point)
{
Double x = point.X / (width / 2); // Scale so bounds map to [0,0] - [2,2]
Double y = point.Y / (height / 2);
x = x - 1; // Translate 0,0 to the center
y = 1 - y; // Flip so +Y is up instead of down
Double z2 = 1 - x * x - y * y; // z^2 = 1 - x^2 - y^2
Double z = z2 > 0 ? Math.Sqrt(z2) : 0;
return new Vector3D(x, y, z);
}
2.2 Rotating Between the Points
private void Rotate(Point currentPosition)
{
Vector3D currentPosition3D = ProjectToTrackball(EventSource.ActualWidth, EventSource.ActualHeight, currentPosition);
Vector3D axis = Vector3D.CrossProduct(_previousRotPosition3D, currentPosition3D);
Double angle = Vector3D.AngleBetween(_previousRotPosition3D, currentPosition3D);
Rotate(axis, angle);
_previousRotPosition3D = currentPosition3D;
}
private void Rotate(Vector3D axis, Double angle)
{
Quaternion delta = new Quaternion(axis, -angle * _rotScale);
Quaternion q = new Quaternion(_axisAngleRotation3D.Axis, _axisAngleRotation3D.Angle);
q *= delta;
Vector3D zeorVec = new Vector3D(0.0, 0.0, 0.0);
if (Vector3D.Equals(q.Axis, zeorVec))
return;
_axisAngleRotation3D.Axis = q.Axis;
_axisAngleRotation3D.Angle = q.Angle;
}
- WPF中3D旋转的实现
- WPF中使用AxisAngleRotation3D实现CAD的2D旋转功能
- wpf 3D立方体旋转
- 好玩的WPF第四弹:用Viewport2DVisual3D实现3D旋转效果
- WPF中使用TranslateTransform3D修改CAD的3D旋转中心
- WPF旋转的界面实现
- 在Unity3D中使用uGUI实现3D旋转特效
- Android中 3D 圆形旋转动态实现
- WPF 3D:简单的Point3D和Vector3D动画创造一个旋转的正方体
- silverlight / wpf 旋转动画的实现
- unity 3d中简单巧妙的实现拖动鼠标旋转物体
- iOS实现3D旋转
- GPUImageTransformFilter实现3D旋转
- WPF中3D反转
- WPF实现3D翻转的动画效果
- WPF实现3D翻转的动画效果
- WPF实现3D翻转的动画效果
- WPF实现3D翻转的动画效果
- 结构体长度的计算
- 策划入门(九):测试方案的产生
- 关于线性表的C程序,语法问题?不会吧
- 游戏地图技术Terrain Splatting
- 用Visual Studio打包(转)
- WPF中3D旋转的实现
- 别人的回帖
- 学习linux的网址
- JAVA面试题解惑系列(七)——日期和时间的处理
- oracle nvl decode
- 字符串转换
- WoW服务器模拟器Ascent网络模块分析
- struts2中迭代标签嵌套的问题
- Mangos源码分析(1):服务器结构探讨之最简单的结构