CodePudding user response:
//tracking the implementation of the (DX c + +)Void CBullet: : followMove float (dt)
{
//limit the euler angles of the bullet between 0 to 2 PI
If (m_vRotate. Z & gt; D3DX_PI * 2)
M_vRotate. Z -=D3DX_PI * 2;
If (m_vRotate. Z & lt; 0)
M_vRotate. Z +=D3DX_PI * 2;
//to find the target Angle
Float targetAngle=atan (- (m_vPos. X-ray mTargetPos. X)/(m_vPos. Y - mTargetPos. Y));
If (m_vPos. Y - mTargetPos. Y & lt; 0)
TargetAngle +=D3DX_PI;
//limit target Angle to 0 to 2 PI
If (targetAngle & lt; 0) targetAngle +=D3DX_PI * 2;
//calculate turn the direction of the small Angle
Float f=fabs (targetAngle - m_vRotate. Z);
If (f & lt; D3DX_PI) {
If (targetAngle & gt; M_vRotate. Z)
M_vRotate. Z + dt=mAngleSpeed *;
The else
M_vRotate. Z -=mAngleSpeed * dt;
}
The else {
If (targetAngle & gt; M_vRotate. Z)
M_vRotate. Z -=mAngleSpeed * dt;
The else
M_vRotate. Z + dt=mAngleSpeed *;
}
D3DXVECTOR3 v={0, 1, 0};//positive direction
D3DXMATRIX rotateX;//euler Angle rotation
D3DXMatrixRotationX (& amp; RotateX, m_vRotate. X);
D3DXMATRIX rotateY;
D3DXMatrixRotationY (& amp; RotateY, m_vRotate. Y);
D3DXMATRIX rotateZ;
D3DXMatrixRotationZ (& amp; RotateZ, m_vRotate. Z);
D3DXMATRIX mat=rotateX rotateY * * rotateZ;
D3DXVec3TransformCoord (& amp; V, & amp; V, & amp; Mat);
D3DXVec3Normalize (& amp; V, & amp; V);
MMoveSpeed m_vPos +=v * * dt;
}