本文整理汇总了C++中D3DXMatrixRotationAxis函数的典型用法代码示例。如果您正苦于以下问题:C++ D3DXMatrixRotationAxis函数的具体用法?C++ D3DXMatrixRotationAxis怎么用?C++ D3DXMatrixRotationAxis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了D3DXMatrixRotationAxis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: D3DXVec3Normalize
void ElCamera::setDirection(const D3DXVECTOR3& vec)
{
// Do nothing if given a zero vector
if (vec == D3DXVECTOR3(0.0f, 0.0f, 0.0f))
return;
D3DXVECTOR3 adjustVec = vec;
if (mYawFixed)
adjustVec.y = 0.0f;
D3DXVec3Normalize(&adjustVec, &adjustVec);
D3DXMATRIX m;
if (D3DXVec3LengthSq(&(D3DXVECTOR3(0.0f, 0.0f, 1.0f) + adjustVec)) < 0.00005f)
{
// Oops, a 180 degree turn (infinite possible rotation axes)
// Default to yaw i.e. use current DOWN
D3DXMatrixRotationAxis(&m, &D3DXVECTOR3(0.0f, -1.0f, 0.0f), D3DX_PI);
}
else
{
D3DXVECTOR3 axe;
D3DXVec3Cross(&axe, &D3DXVECTOR3(0.0f, 0.0f, 1.0f), &adjustVec);
float dot = D3DXVec3Dot(&D3DXVECTOR3(0.0f, 0.0f, 1.0f), &adjustVec);
D3DXMatrixRotationAxis(&m, &axe, acos(dot));
}
mLook = vec;
D3DXVec3TransformCoord(&mUp, &D3DXVECTOR3(0.0f, 1.0f, 0.0f), &m);
D3DXVec3TransformCoord(&mRight, &D3DXVECTOR3(1.0f, 0.0f, 0.0f), &m);
calcViewOrientation();
invalidateView();
}
示例2: RotateCameraHorizontally
void RotateCameraHorizontally(float radian)
{
/*
常规变换
*/
//将eyePoint绕lookAt点旋转
D3DXMATRIX rotation;
//D3DXMatrixRotationAxis:
// D3DXMATRIX * D3DXMatrixRotationAxis(
//__inout D3DXMATRIX *pOut,
// __in const D3DXVECTOR3 *pV,
// __in FLOAT Angle
// );
//其功能是生成绕原点处的方向向量为pV的轴旋转角度Angle的旋转变换矩阵
//所以在绕非原点旋转时需要先将目标点的旋转变换为绕原点旋转
D3DXMatrixRotationAxis(&rotation, &up, radian);
D3DXVECTOR4 tmp;
D3DXVec3Transform(&tmp, &(eyePoint-lookAt), &rotation);
eyePoint = lookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);
/*
fixed 变换
*/
{
//将eyePoint绕lookAt点旋转
D3DXMATRIX rotation;
D3DXMatrixRotationAxis(&rotation, &fixedUp, radian);
D3DXVECTOR4 tmp;
D3DXVec3Transform(&tmp, &(fixedEyePoint-fixedLookAt), &rotation);
fixedEyePoint = fixedLookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);
}
}
示例3: HandleMouseInputLightRotate
//-------------------------------------------------------------------------------
// handle mouse input for the light rotation
//
// Axes: global x/y axis
//-------------------------------------------------------------------------------
void HandleMouseInputLightRotate( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
if (g_bMousePressedR)
{
int nXDiff = -(g_mousePos.x - g_LastmousePos.x);
int nYDiff = -(g_mousePos.y - g_LastmousePos.y);
aiVector3D v = aiVector3D(1.0f,0.0f,0.0f);
aiMatrix4x4 mTemp;
D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nYDiff / 2.0f));
D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
v = aiVector3D(0.0f,1.0f,0.0f);
D3DXMatrixRotationAxis( (D3DXMATRIX*) &mTemp, (D3DXVECTOR3*)&v, D3DXToRadian((float)nXDiff / 2.0f));
D3DXVec3TransformCoord((D3DXVECTOR3*)&g_avLightDirs[0],
(const D3DXVECTOR3*)&g_avLightDirs[0],(const D3DXMATRIX*)&mTemp);
}
return;
}
示例4: D3DXToRadian
/*
*
* @author Michael McQuarrie
* @param _pParticle The particle that needs to be reset
* @return void
*/
void
CFlagParticleEmitter::Resetparticle(TParticle *_pParticle)
{
//Initalise origin
_pParticle->vec3Position = m_vec3Origin += m_pFlag->GetUp() * 4.18f;
float32 fAngleHor = D3DXToRadian(rand() % 360);
float32 fAngleVer = -D3DXToRadian((rand() % 61) + 60);
D3DXMATRIX yawMat;
D3DXMATRIX pitchMat;
D3DXMatrixRotationAxis(&yawMat, &m_pFlag->GetUp(), fAngleHor);
D3DXMatrixRotationAxis(&pitchMat, &m_pFlag->GetRight(), fAngleVer);
_pParticle->vec3Velocity = m_pFlag->GetDirection();
D3DXVec3TransformCoord(&_pParticle->vec3Velocity, &_pParticle->vec3Velocity, &pitchMat);
D3DXVec3TransformCoord(&_pParticle->vec3Velocity, &_pParticle->vec3Velocity, &yawMat);
//Setting it
D3DXVec3Normalize(&_pParticle->vec3Velocity, &_pParticle->vec3Velocity);
_pParticle->vec3Velocity += m_pFlag->GetUp();
//Setting the life timer
_pParticle->fAge = 1.0f;
_pParticle->fLifeTime = 0.0f;
_pParticle->colour = (m_pFlag->GetTeam() == TEAM_GREEN)?(KCOLTEAM_GREEN):(KCOLTEAM_PURPLE);
_pParticle->bAlive = true;
}
示例5: HandleMouseInputFPS
//-------------------------------------------------------------------------------
// Handle mouse input for the FPS input behaviour
//
// Movement in x and y axis is possible
//-------------------------------------------------------------------------------
void HandleMouseInputFPS( void )
{
POINT mousePos;
GetCursorPos( &mousePos );
ScreenToClient( GetDlgItem(g_hDlg,IDC_RT), &mousePos );
g_mousePos.x = mousePos.x;
g_mousePos.y = mousePos.y;
D3DXMATRIX matRotation;
if (g_bMousePressed)
{
int nXDiff = (g_mousePos.x - g_LastmousePos.x);
int nYDiff = (g_mousePos.y - g_LastmousePos.y);
if( 0 != nYDiff)
{
D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)& g_sCamera.vRight, D3DXToRadian((float)nYDiff / 6.0f));
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)& g_sCamera.vLookAt, &matRotation );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vUp, (D3DXVECTOR3*)&g_sCamera.vUp, &matRotation );
}
if( 0 != nXDiff )
{
D3DXVECTOR3 v(0,1,0);
D3DXMatrixRotationAxis( &matRotation, (D3DXVECTOR3*)&g_sCamera.vUp, D3DXToRadian((float)nXDiff / 6.0f) );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vLookAt, (D3DXVECTOR3*)&g_sCamera.vLookAt, &matRotation );
D3DXVec3TransformCoord( (D3DXVECTOR3*)&g_sCamera.vRight,(D3DXVECTOR3*) &g_sCamera.vRight, &matRotation );
}
}
g_LastmousePos.x = g_mousePos.x;
g_LastmousePos.y = g_mousePos.y;
}
示例6: D3DXMatrixRotationAxis
void FreeCameraController::recompute_rotation()
{
D3DXVECTOR3 view_temp;
D3DXVECTOR3 view_temp2;
D3DXVECTOR3 right_temp;
D3DXVECTOR3 up_temp;
D3DXVECTOR3 right_vector_v3 = right_vector_;
D3DXVECTOR3 up_vector_v3 = up_vector_;
D3DXVECTOR3 view_vector_v3 = view_vector_;
D3DXVECTOR3 default_right_v3 = default_right_;
D3DXVECTOR3 default_forward_v3 = default_forward_;
D3DXVECTOR3 default_up_v3 = default_up_;
D3DXMATRIX m_1;
D3DXMATRIX m_2;
D3DXMatrixRotationAxis(&m_2, &default_up_v3, yaw_);
D3DXVec3TransformCoord(&view_temp2, &default_forward_v3, &m_2);
D3DXVec3TransformCoord(&right_temp, &default_right_v3, &m_2);
D3DXMatrixRotationAxis(&m_1, &right_temp, -pitch_);
D3DXVec3TransformCoord(&view_temp, &view_temp2, &m_1);
D3DXVec3TransformCoord(&up_temp, &default_up_v3, &m_1);
D3DXVec3Normalize(&up_vector_v3, &up_temp);
D3DXVec3Normalize(&view_vector_v3, &view_temp);
D3DXVec3Normalize(&right_vector_v3, &right_temp);
right_vector_ = D3DXVECTOR4(right_vector_v3.x, right_vector_v3.y, right_vector_v3.z, 1);
up_vector_ = D3DXVECTOR4(up_vector_v3.x, up_vector_v3.y, up_vector_v3.z, 1);
view_vector_ = D3DXVECTOR4(view_vector_v3.x, view_vector_v3.y, view_vector_v3.z, 1);
}
示例7: D3DXMatrixRotationAxis
void Camera::Update()
{
static D3DXVECTOR2 lastMousePosition = theInput->GetMousePosition();
// Rotate the camera
if (theInput->GetKey(VK_LBUTTON))
{
D3DXVECTOR2 curMousePosition = theInput->GetMousePosition();
float xDiff = curMousePosition.x - lastMousePosition.x;
float yDiff = curMousePosition.y - lastMousePosition.y;
lastMousePosition = curMousePosition;
D3DXMATRIX matRotation;
if (yDiff != 0)
{
D3DXMatrixRotationAxis(&matRotation, &m_right, D3DXToRadian(yDiff / 3.0f));
D3DXVec3TransformCoord(&m_look, &m_look, &matRotation);
D3DXVec3TransformCoord(&m_up, &m_up, &matRotation);
}
if (xDiff != 0)
{
D3DXMatrixRotationAxis(&matRotation, &D3DXVECTOR3(0, 1, 0), D3DXToRadian(xDiff / 3.0f));
D3DXVec3TransformCoord(&m_look, &m_look, &matRotation);
D3DXVec3TransformCoord(&m_up, &m_up, &matRotation);
D3DXVec3TransformCoord(&m_right, &m_right, &matRotation);
}
}
else
{
lastMousePosition = theInput->GetMousePosition();
}
// Move the Camera
float moveX = 0.0f, moveY = 0.0f, moveZ = 0.0f;
if (theInput->GetKey(VK_UP) || theInput->GetKey('W'))
moveZ += 1.0f;
if (theInput->GetKey(VK_DOWN) || theInput->GetKey('S'))
moveZ -= 1.0f;
if (theInput->GetKey(VK_LEFT) || theInput->GetKey('A'))
moveX -= 1.0f;
if (theInput->GetKey(VK_RIGHT) || theInput->GetKey('D'))
moveX += 1.0f;
if (theInput->GetKey(VK_HOME) || theInput->GetKey('Q'))
moveY += 1.0f;
if (theInput->GetKey(VK_END) || theInput->GetKey('E'))
moveY -= 1.0f;
D3DXVECTOR3 move = moveX * m_right + moveY * m_up + moveZ * m_look;
D3DXVec3Normalize(&move, &move);
m_position += move * m_moveSpeed * theTime->GetDeltaTime();
UpdateViewMatrix();
}
示例8: shape
void Camera::CalculateViewMatrix(D3DXMATRIX *viewMatrix)
{
/* Start with our camera axis pointing down z
An alternative method is to just keep adjusting our axis but if we do that the
axis can start to lose its orthogonal shape (due to floating point innacuracies).
This could be solved by rebuilding the orthogonal shape each time with the following:
1. normalising the look vector
2. creating the up vector from the cross product of the look and the right
3. normalising up
4. creating the right vector from the cross product of the look and the up
5. normalising right
*/
m_up=D3DXVECTOR3(0.0f,1.0f,0.0f);
m_look=D3DXVECTOR3(0.0f,0.0f,1.0f);
m_right=D3DXVECTOR3(1.0f,0.0f,0.0f);
// Yaw is rotation around the y axis (m_up)
// Create a matrix that can carry out this rotation
D3DXMATRIX yawMatrix;
D3DXMatrixRotationAxis(&yawMatrix, &m_up, m_yaw);
// To apply yaw we rotate the m_look & m_right vectors about the m_up vector (using our yaw matrix)
D3DXVec3TransformCoord(&m_look, &m_look, &yawMatrix);
D3DXVec3TransformCoord(&m_right, &m_right, &yawMatrix);
// Pitch is rotation around the x axis (m_right)
// Create a matrix that can carry out this rotation
D3DXMATRIX pitchMatrix;
D3DXMatrixRotationAxis(&pitchMatrix, &m_right, m_pitch);
// To apply pitch we rotate the m_look and m_up vectors about the m_right vector (using our pitch matrix)
D3DXVec3TransformCoord(&m_look, &m_look, &pitchMatrix);
D3DXVec3TransformCoord(&m_up, &m_up, &pitchMatrix);
// Roll is rotation around the z axis (m_look)
// Create a matrix that can carry out this rotation
D3DXMATRIX rollMatrix;
D3DXMatrixRotationAxis(&rollMatrix, &m_look, m_roll);
// To apply roll we rotate up and right about the look vector (using our roll matrix)
// Note: roll only really applies for things like aircraft unless you are implementing lean
D3DXVec3TransformCoord(&m_right, &m_right, &rollMatrix);
D3DXVec3TransformCoord(&m_up, &m_up, &rollMatrix);
// Build the view matrix from the transformed camera axis
D3DXMatrixIdentity(viewMatrix);
viewMatrix->_11 = m_right.x; viewMatrix->_12 = m_up.x; viewMatrix->_13 = m_look.x;
viewMatrix->_21 = m_right.y; viewMatrix->_22 = m_up.y; viewMatrix->_23 = m_look.y;
viewMatrix->_31 = m_right.z; viewMatrix->_32 = m_up.z; viewMatrix->_33 = m_look.z;
viewMatrix->_41 = - D3DXVec3Dot( &m_position,&m_right);
viewMatrix->_42 = - D3DXVec3Dot( &m_position,&m_up);
viewMatrix->_43 = - D3DXVec3Dot( &m_position,&m_look);
}
示例9: D3DXMatrixRotationAxis
void camera::angleUp(float a)
{
//THIS IS FOR TURNING
D3DXMATRIX rot;
D3DXMatrixRotationAxis(&rot,&right,a);
D3DXMatrixRotationAxis(&rot,&up,a);
D3DXVec3TransformCoord(&right,&right,&rot);
D3DXVec3TransformCoord(&look,&look,&rot);
}
示例10: RotateCameraVertically
void RotateCameraVertically(float radian)
{
/*
常规变换
*/
{
D3DXVECTOR3 vForward = lookAt - eyePoint;
D3DXVec3Normalize(&vForward, &vForward);
D3DXVECTOR3 vLeft;
D3DXVec3Cross(&vLeft, &up, &vForward);
D3DXVec3Normalize(&vLeft, &vLeft);
D3DXMATRIX rotation;
D3DXMatrixRotationAxis(&rotation, &vLeft, radian);
D3DXVECTOR4 tmp;
D3DXVec3Transform(&tmp, &(eyePoint-lookAt), &rotation);
eyePoint = lookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);
//竖直方向旋转时,up方向随之变化,需要更新
vForward = lookAt - eyePoint;
D3DXVec3Normalize(&vForward, &vForward);
D3DXVec3Cross(&up, &vForward, &vLeft);
D3DXVec3Normalize(&up, &up);
}
/*
fixed 变换
*/
{
D3DXVECTOR3 vForward = fixedLookAt - fixedEyePoint;
D3DXVec3Normalize(&vForward, &vForward);
D3DXVECTOR3 vLeft;
D3DXVec3Cross(&vLeft, &fixedUp, &vForward);
D3DXVec3Normalize(&vLeft, &vLeft);
D3DXMATRIX rotation;
D3DXMatrixRotationAxis(&rotation, &vLeft, radian);
D3DXVECTOR4 tmp;
D3DXVec3Transform(&tmp, &(fixedEyePoint-fixedLookAt), &rotation);
fixedEyePoint = fixedLookAt + D3DXVECTOR3(tmp.x, tmp.y, tmp.z);
//竖直方向旋转时,up方向随之变化,需要更新
vForward = fixedLookAt - fixedEyePoint;
D3DXVec3Normalize(&vForward, &vForward);
D3DXVec3Cross(&fixedUp, &vForward, &vLeft);
D3DXVec3Normalize(&fixedUp, &fixedUp);
}
}
示例11: D3DXMatrixRotationAxis
void MANIPULATEACTIVE::Rotation(float x,float y,float z)
{
D3DXMATRIX tmp;
D3DXMatrixRotationAxis(&tmp,&right,x/180.0f*D3DX_PI);
D3DXVec3TransformCoord(&up,&up,&tmp);
D3DXVec3TransformCoord(&look,&look,&tmp);
D3DXMatrixRotationAxis(&tmp,&up,y/180.0f*D3DX_PI);
D3DXVec3TransformCoord(&right,&right,&tmp);
D3DXVec3TransformCoord(&look,&look,&tmp);
D3DXMatrixRotationAxis(&tmp,&look,z/180.0f*D3DX_PI);
D3DXVec3TransformCoord(&right,&right,&tmp);
D3DXVec3TransformCoord(&up,&up,&tmp);
}
示例12: D3DXMatrixRotationAxis
void Camera::Yaw(float angle)
{
D3DXMATRIX mYaw;
if (m_Type==LANDOBJECT)
{
D3DXMatrixRotationAxis(&mYaw, &D3DXVECTOR3(0.0f,1.0f,0.0f), angle);
}
else
{
D3DXMatrixRotationAxis(&mYaw, &m_Up, angle);
}
D3DXVec3TransformCoord(&m_Look, &m_Look, &mYaw);
D3DXVec3TransformCoord(&m_Right, &m_Right, &mYaw);
}
示例13: D3DXMatrixRotationAxis
void Camera::Pitch( float angle )
{
D3DXMATRIX R;
D3DXMatrixRotationAxis(&R, &mRight, angle);
D3DXVec3TransformNormal(&mUp, &mUp, &R);
D3DXVec3TransformNormal(&mLook, &mLook, &R);
}
示例14: D3DXMatrixRotationAxis
void cCamera::roll (float angle) {
D3DXMATRIX T;
D3DXMatrixRotationAxis (&T, &look, angle);
D3DXVec3TransformCoord (&right, &right, &T);
D3DXVec3TransformCoord (&up, &up, &T);
}
示例15: D3DXMatrixRotationAxis
/*
* rotates the turret towards the inputed angle
*
* author Cameron MacIntosh
* param _fRadian the desired angle to rotate to
* param _fDeltaTick the amount of time available to turn
*/
void
CTower::RotateTurret(float32 _fRadian, float32 _fDeltaTick)
{
//if the turret angle is not equal to the desired angle
if(_fRadian!=m_turretAngle.GetAngle())
{
//turn the turret towards the desired angle, given possible turn amount
CAngle targetAngle;
targetAngle.SetAngle(_fRadian);
m_turretAngle.TurnTowardsAngle(targetAngle, m_fTurnSpeed * _fDeltaTick);
D3DXMATRIX mat;
D3DXMatrixRotationAxis(&mat, &m_vec3Up, m_turretAngle.GetAngle());
D3DXVec3TransformCoord(&m_vec3ShootDir, &g_atUpRightDirectionVecs[m_eFace].vec3Direction, &mat);
D3DXVec3TransformCoord(&m_vec3ShootRight, &g_atUpRightDirectionVecs[m_eFace].vec3Right, &mat);
//set the world matrix of the turret model
// Set the up, right and direction vectors into the world matirx.
m_matTurretWorld._11 = m_vec3ShootRight.x; m_matTurretWorld._21 = m_vec3Up.x; m_matTurretWorld._31 = m_vec3ShootDir.x;
m_matTurretWorld._12 = m_vec3ShootRight.y; m_matTurretWorld._22 = m_vec3Up.y; m_matTurretWorld._32 = m_vec3ShootDir.y;
m_matTurretWorld._13 = m_vec3ShootRight.z; m_matTurretWorld._23 = m_vec3Up.z; m_matTurretWorld._33 = m_vec3ShootDir.z;
m_matTurretWorld._41 = m_vec3Position.x;
m_matTurretWorld._42 = m_vec3Position.y;
m_matTurretWorld._43 = m_vec3Position.z;
}
}