摄像机旋转
2011-03-30 11:11
134 查看
三维场景中的旋转,是摄像机本身在世界坐标系中绕Y轴进行旋转,从而改变位置,而其他的姿态不变,也就是摄像机的Position向量绕着世界坐标系的Y轴进行旋转。
三种方式:
1,采用角度(不通用),此方法适合目标点是世界坐标系原点。
[/code]
[/code]
2,采用Matrix.RotationY方法对Position向量进行旋转(较为通用)
[/code]
[/code]
3,原理和2中一样,不过在旋转计算时,采用四元素数进行处理
[/code]
[/code]
三种方式:
1,采用角度(不通用),此方法适合目标点是世界坐标系原点。
[code] [code]private float angleFirst = 0;
private void RotateYFirst(float paAngle)
{
//通过角度
angleFirst += paAngle;
if (angle > 6.28f)
{
angle -= 6.28f;
}
camPosition = new Vector3(4 * (float)Math.Cos(angleFirst), 0, 4 * (float)Math.Sin(angleFirst));
Matrix view = Matrix.LookAtLH(camPosition, camTarget, camUp);
device.SetTransform(TransformType.View, view);
}
[/code]
[/code]
2,采用Matrix.RotationY方法对Position向量进行旋转(较为通用)
[code] [code]//通过世界矩阵的Transform
private void RotateYSecond(float paAngle)
{
//摄像机绕世界坐标系的Y轴进行旋转,摄像机本身的姿态不进行任何改变
Vector4 tempRotate = Vector3.Transform(
camPosition, Matrix.RotationY(paAngle));
camPosition = new Vector3(tempRotate.X, tempRotate.Y, tempRotate.Z);
Matrix view = Matrix.LookAtLH(
camPosition,
camTarget,
camUp);
device.SetTransform(TransformType.View, view);
}
[/code]
[/code]
3,原理和2中一样,不过在旋转计算时,采用四元素数进行处理
[code] [code]//通过四元素数进行旋转变换(同样绕着世界坐标系的Y轴)
private void RotateYThree(float paAngle)
{
Vector4 tempRotate = Vector3.Transform(
camPosition,
Matrix.RotationQuaternion(Quaternion.RotationAxis(new Vector3(0, 1, 0), paAngle)));
camPosition = new Vector3(tempRotate.X, tempRotate.Y, tempRotate.Z);
Matrix view = Matrix.LookAtLH(camPosition, camTarget, camUp);
device.SetTransform(TransformType.View, view);
}
[/code]
[/code]
相关文章推荐
- Unity 点击模型上任意位置,模型旋转,点击位置朝向摄像机
- Unity摄像机跟随Target快速位移和旋转
- 摄像机的旋转缩放与跟随,并且保持跟随的时候不受人物的影响。
- Unity 摄像机旋转初探
- UGUI点击按钮穿透、UI跟随摄像机旋转
- 摄像机旋转移动
- Unity摄像机旋转和位移跟随
- Unity_简单的摄像机绕物体旋转
- D3D中使用鼠标控制摄像机旋转
- Unity实现摄像机围绕物体旋转
- unity重力感应控制摄像机旋转
- Unity摄像机跟随Target快速位移和旋转
- unity 控制摄像机旋转和缩放
- Windows 8 Directx 开发学习笔记(三)摄像机设置及控制正方体旋转
- 解决三维建模软件中摄像机旋转的问题
- 转载:摄像机、投影、3D旋转、缩放
- UE4学习5 第三人称使用自己的摄像机旋转方法(不用controller)
- Unity摄像机跟随Target快速位移和旋转
- Unity物体或摄像机的旋转缩放
- 自由视角摄像机,实现旋转,缩放