赞
踩
yaw: 水平偏航转角 (绕Y轴旋转, Y轴向上)
pitch: 上下俯仰转角 (绕X轴 旋转, X轴向右)
roll: 旋转角(绕Z轴 旋转, Z轴向前)
Direct3D 左手坐标
图见: yaw pitch roll 图
注意: 第一个 旋转计算 完毕之后, 第二个旋转的参考轴仍然是全局坐标, 而不是自身参考轴。
- D3DXMATRIXA16 mx_xlib;
- D3DXMATRIXA16 mx_pitch_first;
- D3DXMATRIXA16 mx_yaw_first;
- D3DXMATRIXA16 mx_yaw, mx_pitch;
-
-
- float yaw, pitch, roll =0.0f;
- yaw = D3DX_PI/6;
- pitch = D3DX_PI/3;
-
- TRACE( "yaw: %f pitch: %f\n", yaw, pitch );
- D3DXMatrixRotationYawPitchRoll( &mx_xlib, yaw, pitch, roll );
-
- D3DXMatrixRotationY( &mx_yaw, yaw );
- D3DXMatrixRotationX( &mx_pitch, pitch );
-
- mx_pitch_first = mx_pitch * mx_yaw ;
- mx_yaw_first = mx_yaw * mx_pitch ;
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- D3DXMATRIXA16 mx_yp_local;
- D3DXMATRIXA16 mx_local_pitch;
- D3DXVECTOR3 vAxisX( 1.0, 0, 0 );
- D3DXVECTOR3 vLocalX;
-
- D3DXVec3TransformCoord( &vLocalX, &vAxisX, &mx_yaw );
- D3DXMatrixRotationAxis( &mx_local_pitch, &vLocalX, pitch );
-
- mx_yp_local = mx_yaw * mx_local_pitch ;
2. D3DXMatrixRotationYawPitchRoll 生成的旋转矩阵 不等于 摄像的视角矩阵。
视角矩阵 是通过 旋转一个标准 z轴单位向量( 0,0,1) , 再通过 两个点 来 确定 视角矩阵。 代码见下:
- D3DXVECTOR3 vUp (0,1,0);
- D3DXVECTOR3 vZero(0,0,0);
- D3DXVECTOR3 vZ(0,0,1.0f);
- D3DXVECTOR3 vNewZ;
-
- D3DXMATRIX mRotView;
-
- D3DXVec3TransformCoord( &vNewZ, &vZ, &d_xlib );
- D3DXMatrixLookAtLH( &mRotView, &vZero, &vNewZ, & vUp );
3. 视角矩阵 ==> 计算 yaw, pitch, roll
- D3DXMATRIX mInvView;
- D3DXMatrixInverse( &mInvView, NULL, &mRotView );
-
- // The axis basis vectors and camera position are stored inside the
- // position matrix in the 4 rows of the camera's world matrix.
- // To figure out the yaw/pitch of the camera, we just need the Z basis vector
- D3DXVECTOR3* pZBasis = (D3DXVECTOR3*) &mInvView._31;
-
- float fCameraYawAngle = atan2f( pZBasis->x, pZBasis->z );
- float fLen = sqrtf(pZBasis->z*pZBasis->z + pZBasis->x*pZBasis->x);
- float fCameraPitchAngle = -atan2f( pZBasis->y, fLen );
云台 支持 pan, tilt, zoom,focus 四个参数,常用前三个,简称PTZ.
云台一般只能 水平(pan),上下(tilt)动作。
不支持旋转。
对于Pan, tilt 构造 旋转矩阵 次序
1. tilt[全局 x 轴] -> Pan [全局轴 y ]
2. Pan [全局轴 y轴] -> tilt [自身轴 x 轴]
和 yaw pitch roll 概念, 完全相同。
1. 对于旋转矩阵, 它的逆矩阵 和 转置矩阵 是相同。 所以可以用 旋转矩阵 直接 变换 方向矢量。
2. 视角矩阵 虽然 和 yaw-pitch-roll 不同, 但是其实就是 逆(或转置) 的关系。
3. 如果一个 先yaw, 后pitch的视角矩阵 (全局轴) ==> 计算 yaw, pitch , 见下式。
- D3DXMATRIX mInvView;
- D3DXMatrixInverse( &mInvView, NULL, &mRotView );
-
- // The axis basis vectors and camera position are stored inside the
- // position matrix in the 4 rows of the camera's world matrix.
- // To figure out the yaw/pitch of the camera, we just need the Z basis vector
- D3DXVECTOR3* pZBasis = (D3DXVECTOR3*) &mInvView._31;
-
- float fYawFirst_PitchAngle = -atan2f( pZBasis->y, pZBasis->z );
- float fYawFirst_Len = sqrtf(pZBasis->z*pZBasis->z + pZBasis->y*pZBasis->y);
- float fYawFirst_YawAngle = atan2f( pZBasis->x, fYawFirst_Len );
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。