//============================================================================================================= void AirPlane::Update(double time) { // ez lesz a lagg effekt if( lastinput > 0 && (time - lastinput > 0.1f) ) state = Idle; float pitch = 0, roll = 0, yaw = 0, move = 0; if( state & RollLeft ) roll = -0.2f; else if( state & RollRight ) roll = 0.2f; else if( state & PitchUp ) pitch = -0.2f; else if( state & PitchDown ) pitch = 0.2f; else if( state & YawLeft ) yaw = -0.2f; else if( state & YawRight ) yaw = 0.2f; if( state & AirPlane::Move ) move = -2; D3DXVECTOR3& p = position.current; D3DXQUATERNION& q = rotation.current; D3DXVECTOR3 x, y, z; D3DXQUATERNION t, u, v, w; x.x = q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z; x.y = 2.0f * (q.z * q.w + q.x * q.y); x.z = 2.0f * (q.x * q.z - q.y * q.w); y.x = 2.0f * (q.y * q.x - q.z * q.w); y.y = q.w * q.w + q.y * q.y - q.z * q.z - q.x * q.x; y.z = 2.0f * (q.x * q.w + q.y * q.z); z.x = 2.0f * (q.y * q.w + q.z * q.x); z.y = 2.0f * (q.z * q.y - q.x * q.w); z.z = q.w * q.w + q.z * q.z - q.x * q.x - q.y * q.y; D3DXQuaternionRotationAxis(&u, &z, roll); D3DXQuaternionRotationAxis(&v, &x, pitch); D3DXQuaternionRotationAxis(&t, &y, yaw); D3DXQuaternionMultiply(&w, &u, &v); D3DXQuaternionMultiply(&w, &w, &t); rotation.previous = q; D3DXQuaternionMultiply(&q, &q, &w); D3DXVec3Normalize(&z, &z); position.previous = p; p += z * move; }
D3DXVECTOR3* D3DXVec3Rotation(D3DXVECTOR3* pvtOut, const D3DXVECTOR3* c_pvtSrc, const D3DXQUATERNION* c_pqtRot) { D3DXQUATERNION qtSrc(c_pvtSrc->x, c_pvtSrc->y, c_pvtSrc->z, 0); D3DXQUATERNION qtRet; D3DXQuaternionConjugate(&qtRet, c_pqtRot); D3DXQuaternionMultiply(&qtRet, &qtSrc, &qtRet); D3DXQuaternionMultiply(&qtRet, c_pqtRot, &qtRet); pvtOut->x=qtRet.x; pvtOut->y=qtRet.y; pvtOut->z=qtRet.z; return pvtOut; }
void Mesh::Rotate(D3DXVECTOR3 radians) { D3DXQUATERNION quaternion; D3DXQuaternionRotationYawPitchRoll(&quaternion, radians.y, radians.x, radians.z); D3DXQuaternionMultiply(&this->rotQuat, &this->rotQuat, &quaternion); this->RecreateWorldMatrix(); }
void CBody::AdjustAxisVelocity(D3DXVECTOR3& axis, float radianAngle) { D3DXQUATERNION thisRotation; D3DXQuaternionRotationAxis(&thisRotation, &axis, -radianAngle); D3DXQUATERNION angularVelocityTemp = m_angularVelocity; D3DXQuaternionMultiply(&m_angularVelocity, &thisRotation, &angularVelocityTemp); }
void Mesh::RotateAxis(D3DXVECTOR3 around, float angle) { D3DXQUATERNION quaternion = D3DXQUATERNION(0, 0, 0, 1); D3DXQuaternionRotationAxis(&quaternion, &around, angle); D3DXQuaternionMultiply(&this->rotQuat, &this->rotQuat, &quaternion); this->RecreateWorldMatrix(); }
void CRigidBody::Update(TimeMS now) { m_position += m_velocity * ((float)(now - m_lastUpdate) / 1000.0f); D3DXQUATERNION orientationTemp; while (now - m_lastUpdate > 1000) { orientationTemp = m_orientation; D3DXQuaternionMultiply(&m_orientation, &m_angularVelocity, &orientationTemp); m_lastUpdate += 1000; } orientationTemp = m_orientation; D3DXQUATERNION orientationFull; D3DXQuaternionMultiply(&orientationFull, &m_angularVelocity, &orientationTemp); D3DXQuaternionSlerp(&m_orientation, &orientationTemp, &orientationFull, (float)(now - m_lastUpdate) / 1000.0f); m_lastUpdate = now; }
void quater::mult(quater const& a, quater const& b) { #ifdef USE_D3DFUNC // important issue: D3DXQuaternionMultiply function outputs the rotation representing the rotation Q1 followed by the rotation Q2 . // This is done so that D3DXQuaternionMultiply maintain the same semantics as D3DXMatrixMultiply because unit quaternions can be considered as another way to represent rotation matrices // however this quater class is done by definition. So I changed the multiplying order. D3DXQuaternionMultiply(*this, b, a); #else w = a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z; x = a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y; y = a.w*b.y + a.y*b.w + a.z*b.x - a.x*b.z; z = a.w*b.z + a.z*b.w + a.x*b.y - a.y*b.x; #endif }
void CBody::AdjustAxisAngle(D3DXVECTOR3& axis, float radianAngle) { D3DXQUATERNION thisRotation; D3DXQuaternionRotationAxis(&thisRotation, &axis, -radianAngle); D3DXQUATERNION orientationTemp = m_orientation; D3DXQuaternionMultiply(&m_orientation, &thisRotation, &orientationTemp); /* D3DXVECTOR3 fwd, up; fwd = GetForward(); up = GetUp(); debugf("fwd: (%.0f, %.0f, %.0f)\tup: (%.0f, %.0f, %.0f)\n", fwd.x, fwd.y, fwd.z, up.x, up.y, up.z); */ }
void vrObject::Rotate( ) { /* if ( v_rot.x > v_maxrot.x ) v_rot.x = v_maxrot.x; if ( v_rot.y > v_maxrot.y ) v_rot.y = v_maxrot.y; if ( v_rot.z > v_maxrot.z ) v_rot.z = v_maxrot.z; */ vrQuaternion temp_quat; //D3DXQuaternionRotationYawPitchRoll( &temp_quat, v_rot.x*pi/2, v_rot.y*pi/2, v_rot.z*pi/2 ); D3DXQuaternionRotationYawPitchRoll( &temp_quat, f_yaw*pi/2, f_pitch*pi/2, f_yaw*pi/2 ); D3DXQuaternionMultiply( &q_orient, &q_orient, &temp_quat ); }
void vrObject::MoveX() { vrQuaternion TempQuat; vrQuaternion TempQuat2; D3DXQuaternionRotationYawPitchRoll( &TempQuat2, 0.0, -90.0*(pi/180), 0.0 ); D3DXQuaternionMultiply( &TempQuat, &q_orient, &TempQuat2 ); vrVector3 dir; TempQuat.GetDirectionVector( &dir ); v_pos.x += dir.x * v_speed.x; v_pos.y += dir.y * v_speed.x; v_pos.z += dir.z * v_speed.x; }
void Mesh::Rotate(D3DXQUATERNION quat) { D3DXQuaternionMultiply(&this->rotQuat, &this->rotQuat, &quat); this->RecreateWorldMatrix(); }
void _X3PCamera::Advance( void ) { BOOL changedcamerastatus = FALSE; FLOAT abscamvel_x = fabs(m_CameraVelocity.x); FLOAT abscamvel_y = fabs(m_CameraVelocity.y); FLOAT abscamvel_z = fabs(m_CameraVelocity.z); FLOAT abscamvel_dist = fabs(m_ZoominoutVelocity); if( abscamvel_x > EPSILON3 || abscamvel_y > EPSILON3 || abscamvel_z > EPSILON3 || abscamvel_dist > EPSILON3 ) { if( abscamvel_x > EPSILON3 ) { m_CameraVelocity.x *= _XDEF_CAMERADECREASERATE; // add yaw mp_fYaw += m_CameraVelocity.x; if( mp_fYaw > 360.0f ) mp_fYaw = (FLOAT)fmod(mp_fYaw, 360.0); } if( abscamvel_y > EPSILON3 ) { m_CameraVelocity.y *= _XDEF_CAMERADECREASERATE; //add pitch mp_fPitch += m_CameraVelocity.y; if(mp_fPitch < mp_fMinPitchLimit) mp_fPitch = mp_fMinPitchLimit; else if(mp_fPitch > mp_fMaxPitchLimit) mp_fPitch = mp_fMaxPitchLimit; } if( abscamvel_z > EPSILON3 ) { m_CameraVelocity.z *= _XDEF_CAMERADECREASERATE; //add roll mp_fRoll += m_CameraVelocity.z; if(mp_fRoll < mp_fMinRollLimit) mp_fRoll = mp_fMinRollLimit; else if(mp_fRoll > mp_fMaxRollLimit) mp_fRoll = mp_fMaxRollLimit; } if( abscamvel_dist > EPSILON3 ) { #ifdef _XDWDEBUG extern BOOL g_MouseLockFlag; if( !g_MouseLockFlag ) { #endif if( m_MinDistance + m_AdditionalHeightMinDistance < m_TargetDistance ) { m_ZoominoutVelocity *= _XDEF_CAMERAZOOMDECREASERATE; } else { m_ZoominoutVelocity *= 0.3f; } m_TargetDistance += m_ZoominoutVelocity; if( m_MinDistance > m_TargetDistance ) { m_TargetDistance = m_MinDistance; } else if( m_MaxDistance < m_TargetDistance ) { m_TargetDistance = m_MaxDistance; } #ifdef _XDWDEBUG } #endif } changedcamerastatus = TRUE; } if( m_QuaterViewChanging ) { D3DXQUATERNION nextrotquat; D3DXQUATERNION orgrotquat; D3DXQUATERNION targetrotquat; D3DXQuaternionRotationYawPitchRoll( &orgrotquat, _X_RAD(mp_fYaw), _X_RAD(mp_fPitch), _X_RAD(mp_fRoll) ); if( m_DefaultViewChanging ) { D3DXQuaternionRotationYawPitchRoll( &targetrotquat, _X_RAD(-45.0f), _X_RAD(30.0f), 0.0f ); } else { D3DXQuaternionRotationYawPitchRoll( &targetrotquat, _X_RAD(180.0f), _X_RAD(30.0f), 0.0f ); } FLOAT fElapsedTime = g_fElapsedFrameMilisecondTime*3.0f; if( fElapsedTime > 1.0f ) fElapsedTime = 1.0f; D3DXQuaternionSlerp( &nextrotquat, &orgrotquat, &targetrotquat, fElapsedTime ); FLOAT fyaw, fpitch, froll; _XMeshMath_QuaternionToEulerAngle( nextrotquat, fyaw, fpitch, froll ); fyaw = _X_DEG(fyaw); if( fyaw > 360.0f ) fyaw = (FLOAT)fmod(fyaw, 360.0); fpitch = _X_DEG(fpitch); if(fpitch < mp_fMinPitchLimit) fpitch = mp_fMinPitchLimit; else if(fpitch > mp_fMaxPitchLimit) fpitch = mp_fMaxPitchLimit; froll = _X_DEG(froll); if(froll < mp_fMinRollLimit) froll = mp_fMinRollLimit; else if(froll > mp_fMaxRollLimit) froll = mp_fMaxRollLimit; if( fabs( mp_fYaw - fyaw ) > EPSILON1 || fabs( mp_fPitch - fpitch ) > EPSILON1 || fabs( mp_fRoll - froll ) > EPSILON1 ) { mp_fYaw = fyaw; mp_fPitch = fpitch; mp_fRoll = froll; changedcamerastatus = TRUE; } else { m_QuaterViewChanging = FALSE; m_QuaterViewMode = TRUE; m_DefaultViewChanging = FALSE; } _XWindow_WorldMinimap* pminimapwindow = (_XWindow_WorldMinimap*)g_MainWindowManager.FindWindow( _XDEF_WTITLE_MINIMAPWINDOW ); if( pminimapwindow ) { // Set direction to minimap arrow pminimapwindow->SetRotateFrustum( _X_RAD( 180 - mp_fYaw ) ); } } else if( m_DefaultViewChanging ) { D3DXQUATERNION nextrotquat; D3DXQUATERNION orgrotquat; D3DXQUATERNION targetrotquat; D3DXQuaternionRotationYawPitchRoll( &orgrotquat, _X_RAD(mp_fYaw), _X_RAD(mp_fPitch), _X_RAD(mp_fRoll) ); D3DXQuaternionRotationYawPitchRoll( &targetrotquat, _X_RAD(180.0f), _X_RAD(mp_fPitch), 0.0f ); FLOAT fElapsedTime = g_fElapsedFrameMilisecondTime*3.0f; if( fElapsedTime > 1.0f ) fElapsedTime = 1.0f; D3DXQuaternionSlerp( &nextrotquat, &orgrotquat, &targetrotquat, fElapsedTime ); FLOAT fyaw, fpitch, froll; _XMeshMath_QuaternionToEulerAngle( nextrotquat, fyaw, fpitch, froll ); fyaw = _X_DEG(fyaw); if( fyaw > 360.0f ) fyaw = (FLOAT)fmod(fyaw, 360.0); fpitch = _X_DEG(fpitch); if(fpitch < mp_fMinPitchLimit) fpitch = mp_fMinPitchLimit; else if(fpitch > mp_fMaxPitchLimit) fpitch = mp_fMaxPitchLimit; froll = _X_DEG(froll); if(froll < mp_fMinRollLimit) froll = mp_fMinRollLimit; else if(froll > mp_fMaxRollLimit) froll = mp_fMaxRollLimit; if( fabs( mp_fYaw - fyaw ) > EPSILON1 || fabs( mp_fPitch - fpitch ) > EPSILON1 || fabs( mp_fRoll - froll ) > EPSILON1 ) { mp_fYaw = fyaw; mp_fPitch = fpitch; mp_fRoll = froll; changedcamerastatus = TRUE; } else { m_DefaultViewChanging = FALSE; } _XWindow_WorldMinimap* pminimapwindow = (_XWindow_WorldMinimap*)g_MainWindowManager.FindWindow( _XDEF_WTITLE_MINIMAPWINDOW ); if( pminimapwindow ) { // Set direction to minimap arrow pminimapwindow->SetRotateFrustum( _X_RAD( 180 - mp_fYaw ) ); } } else { if( !gpInput->GetMouseState()->bButton[1] && ( g_pLocalUser->GetMotionClass() == _XACTION_MOVE && ( g_pLocalUser->m_PathNodeCount >= 1 || g_pLocalUser->m_LeftFinalTargetLength > 64.0f ) ) && (fabs( g_pLocalUser->m_RotateAngle - g_pLocalUser->m_LastRotateAngle ) < EPSILON3) && m_AutoBackTrace ) { D3DXQUATERNION nextrotquat; D3DXQUATERNION orgrotquat; D3DXQUATERNION targetrotquat; D3DXMATRIX mtxRotate = g_pLocalUser->m_ModelDescriptor.m_Position; mtxRotate._41 = mtxRotate._42 = mtxRotate._43 = 0.0f; D3DXQuaternionRotationYawPitchRoll( &orgrotquat, 0.0f, _X_RAD(mp_fPitch), 0.0f ); D3DXQuaternionRotationMatrix( &targetrotquat, &mtxRotate ); D3DXQuaternionMultiply( &targetrotquat, &orgrotquat, &targetrotquat ); D3DXQuaternionRotationYawPitchRoll( &orgrotquat, _X_RAD(mp_fYaw), _X_RAD(mp_fPitch), _X_RAD(mp_fRoll) ); FLOAT fElapsedTime = g_fElapsedFrameMilisecondTime; if( fElapsedTime > 1.0f ) fElapsedTime = 1.0f; D3DXQuaternionSlerp( &nextrotquat, &orgrotquat, &targetrotquat, fElapsedTime ); FLOAT fyaw, fpitch, froll; _XMeshMath_QuaternionToEulerAngle( nextrotquat, fyaw, fpitch, froll ); fyaw = _X_DEG(fyaw); if( fyaw > 360.0f ) fyaw = (FLOAT)fmod(fyaw, 360.0); fpitch = _X_DEG(fpitch); if(fpitch < mp_fMinPitchLimit) fpitch = mp_fMinPitchLimit; else if(fpitch > mp_fMaxPitchLimit) fpitch = mp_fMaxPitchLimit; froll = _X_DEG(froll); if(froll < mp_fMinRollLimit) froll = mp_fMinRollLimit; else if(froll > mp_fMaxRollLimit) froll = mp_fMaxRollLimit; if( fabs( mp_fYaw - fyaw ) > EPSILON3 || fabs( mp_fPitch - fpitch ) > EPSILON3 || fabs( mp_fRoll - froll ) > EPSILON3 ) { mp_fYaw = fyaw; mp_fPitch = fpitch; mp_fRoll = froll; changedcamerastatus = TRUE; } } } if( m_CameraShakeMode ) { if( !m_CameraShakeDelayMode ) { const FLOAT shakeadditionalfactor = 10.0f; FLOAT fshakefactor = _XLinearGraph( 0.1f,0.05f, 0.5f,0.0f ).GetValueAt( g_fElapsedFrameMilisecondTime ); m_CameraShakeFactor.x = fshakefactor * sinf(rand()); m_CameraShakeFactor.y = fshakefactor * sinf(rand()); m_CameraShakeFactor.z = fshakefactor * sinf(rand()); D3DXMATRIX matOrientation; D3DXMatrixInverse( &matOrientation, NULL, &mp_view_matrix ); D3DXVec3TransformNormal( &m_CameraShakeFactor, &m_CameraShakeFactor, &matOrientation ); changedcamerastatus = TRUE; m_fCameraShakeTimer -= g_fElapsedFrameMilisecondTime; if( m_fCameraShakeTimer < 0.0f ) { m_CameraShakeMode = FALSE; m_CameraShakeFactor = D3DXVECTOR3( 0.0f,0.0f,0.0f ); } } else { if( g_LocalSystemTime - m_fCameraShakeStartTimer < m_fCameraShakeTimer*1000 ) { int temp = (int)(((g_LocalSystemTime - m_fCameraShakeStartTimer)/1000.0f)/5.0f)%2; if( temp == 0 ) { if( !m_ChangeCameraShakeAtDelayMode ) { _XPlaySoundEffect(ID_SR_INTERFACE_EARTHQUAKE_WAV, g_pLocalUser->m_Position ); } const FLOAT shakeadditionalfactor = 10.0f; FLOAT fshakefactor = _XLinearGraph( 0.05f,0.025f, 0.25f,0.0f ).GetValueAt( g_fElapsedFrameMilisecondTime ); m_CameraShakeFactor.x = fshakefactor * sinf(rand()); m_CameraShakeFactor.y = fshakefactor * sinf(rand()); m_CameraShakeFactor.z = fshakefactor * sinf(rand()); D3DXMATRIX matOrientation; D3DXMatrixInverse( &matOrientation, NULL, &mp_view_matrix ); D3DXVec3TransformNormal( &m_CameraShakeFactor, &m_CameraShakeFactor, &matOrientation ); changedcamerastatus = TRUE; m_ChangeCameraShakeAtDelayMode = TRUE; } else { if( m_ChangeCameraShakeAtDelayMode ) { _XPlaySoundEffect(ID_SR_INTERFACE_EARTHQUAKE01_WAV, g_pLocalUser->m_Position ); } m_ChangeCameraShakeAtDelayMode = FALSE; } } else { m_CameraShakeMode = FALSE; m_CameraShakeFactor = D3DXVECTOR3( 0.0f,0.0f,0.0f ); } } } if( changedcamerastatus ) { UpdateViewMatrix( &g_LodTerrain, TRUE ); g_LodTerrain.m_ObjectQuadTree.UpdateCamera(g_LodTerrain.m_3PCamera); g_LodTerrain.RebuildLevel(); } }
void IK::solve() { //don't solve anything if this chain is simulated if (checkSimulated()) return; //set up local variables used in solving the IK chain AMBone* destBone = _info.DestinationBone; AMBone* endEffBone = _info.EndEffectorBone; AMBone* curBone = NULL; D3DXVECTOR3 dest = D3DXVECTOR3(destBone->getCombinedTrans()(3,0), destBone->getCombinedTrans()(3,1), destBone->getCombinedTrans()(3,2)); //lol I still have no clue how this crazy shit works //algorithm is pretty much taken directly from MMD IKLink *cl; BoneInfo *ci; for (int i=0;i<(int)_info.IterationCount;i++) { for (int b=0;b<(int)_info.NumberOfLinks;b++) { cl = &_info.BoneLinkList[b]; curBone = cl->LinkBone; ci = curBone->getInfo(); D3DXVECTOR3 left = curBone->getPosWorld()-endEffBone->getPosWorld(); D3DXVECTOR3 right = curBone->getPosWorld()-destBone->getPosWorld(); D3DXVECTOR3 axis; D3DXVECTOR3 vec = left - right; if (D3DXVec3Length(&vec)*D3DXVec3Length(&vec) < 1E-04f) { i = _info.IterationCount; break; } D3DXVec3Normalize(&left, &left); D3DXVec3Normalize(&right, &right); D3DXVec3Cross(&axis, &left, &right); if (D3DXVec3Length(&axis)*D3DXVec3Length(&axis) < 1E-7 && i > 0) continue; D3DXVec3Normalize(&axis, &axis); /*if (cl->AngleLimit && i < _info.IterationCount/2) { if (cl->LowerLimit.y == 0.0f && cl->UpperLimit.y == 0.0f && cl->LowerLimit.z == 0.0f && cl->UpperLimit.z == 0.0f) { float n = (axis.x*ci->Parent->getCombinedTrans()._11) + (axis.y*ci->Parent->getCombinedTrans()._12) + (axis.z*ci->Parent->getCombinedTrans()._13); if (n >= 0.0f) axis.x = 1.0f; else axis.x = -1.0f; axis.y = 0.0f; axis.z = 0.0f; } else { if (cl->LowerLimit.x == 0.0f && cl->UpperLimit.x == 0.0f && cl->LowerLimit.z == 0.0f && cl->UpperLimit.z == 0.0f) { float n = (axis.x*ci->Parent->getCombinedTrans()._21) + (axis.y*ci->Parent->getCombinedTrans()._22) + (axis.z*ci->Parent->getCombinedTrans()._23); if (n >= 0.0f) axis.y = 1.0f; else axis.y = -1.0f; axis.x = 0.0f; axis.z = 0.0f; } else { if (cl->LowerLimit.x == 0.0f && cl->UpperLimit.x == 0.0f && cl->LowerLimit.y == 0.0f && cl->UpperLimit.y == 0.0f) { float n = (axis.x*ci->Parent->getCombinedTrans()._31) + (axis.y*ci->Parent->getCombinedTrans()._32) + (axis.z*ci->Parent->getCombinedTrans()._33); if (n >= 0.0f) axis.z = 1.0f; else axis.z = -1.0f; axis.x = 0.0f; axis.y = 0.0f; } else { D3DXVECTOR3 v; v.x = (axis.x*curBone->getCombinedTrans()._11)+(axis.y*curBone->getCombinedTrans()._12)+(axis.z*curBone->getCombinedTrans()._13); v.y = (axis.x*curBone->getCombinedTrans()._21)+(axis.y*curBone->getCombinedTrans()._22)+(axis.z*curBone->getCombinedTrans()._23); v.z = (axis.x*curBone->getCombinedTrans()._31)+(axis.y*curBone->getCombinedTrans()._32)+(axis.z*curBone->getCombinedTrans()._33); D3DXVec3Normalize(&axis, &v); } } } } else*/ { D3DXVECTOR3 v; v.x = (axis.x*curBone->getCombinedTrans()._11)+(axis.y*curBone->getCombinedTrans()._12)+(axis.z*curBone->getCombinedTrans()._13); v.y = (axis.x*curBone->getCombinedTrans()._21)+(axis.y*curBone->getCombinedTrans()._22)+(axis.z*curBone->getCombinedTrans()._23); v.z = (axis.x*curBone->getCombinedTrans()._31)+(axis.y*curBone->getCombinedTrans()._32)+(axis.z*curBone->getCombinedTrans()._33); D3DXVec3Normalize(&axis, &v); } float dot = D3DXVec3Dot(&left, &right); if (dot > 1.0f) dot = 1.0f; else if (dot < -1.0f) dot = -1.0f; float angle = acosf(dot); if (angle > (_info.AngleConstraint * (b+1)*2)) { angle = (_info.AngleConstraint * (b+1)*2); } D3DXQUATERNION newIkRot; D3DXQuaternionRotationAxis(&newIkRot, &axis, angle); D3DXQuaternionMultiply(&cl->IKQuat, &newIkRot, &cl->IKQuat); if (i == 0) //on first loop, apply rotation taken from the motion data D3DXQuaternionMultiply(&cl->IKQuat, &cl->IKQuat, &curBone->getRot()); D3DXMATRIX matrix; D3DXMatrixRotationQuaternion(&matrix, &cl->IKQuat); if (cl->AngleLimit) { if ((double)cl->LowerLimit.x > -1.5707963267948966 && (double)cl->UpperLimit.x < 1.5707963267948966) { float num5 = -matrix._32; float num6 = asinf(num5); if (abs(num6) > 1.535889f) { if (num6 < 0.0f) num6 = -1.535889f; else num6 = 1.535889f; } float num7 = cosf(num6); float num8 = matrix._31/num7; float num9 = matrix._33/num7; float num10 = atan2f(num8, num9); float num11 = matrix._12/num7; float num12 = matrix._22/num7; float num13 = atan2f(num11, num12); bool loopFlag = i<(int)_info.IterationCount/2; num6 = GetUpperLowerRadian(num6, cl->LowerLimit.x, cl->UpperLimit.x, loopFlag); num10 = GetUpperLowerRadian(num10, cl->LowerLimit.y, cl->UpperLimit.y, loopFlag); num13 = GetUpperLowerRadian(num13, cl->LowerLimit.z, cl->UpperLimit.z, loopFlag); D3DXMATRIX nx, ny, nz; D3DXMatrixRotationX(&nx, num6); D3DXMatrixRotationY(&ny, num10); D3DXMatrixRotationZ(&nz, num13); matrix = nz*nx*ny; } else { if ((double)cl->LowerLimit.y > -1.5707963267948966 && (double)cl->UpperLimit.y < 1.5707963267948966) { float num14 = -matrix._13; float num15 = asinf(num14); if (abs(num15) > 1.535889f) { if (num15 < 0.0f) { num15 = -1.535889f; } else { num15 = 1.535889f; } } float num16 = cosf(num15); float num17 = matrix._23 / num16; float num18 = matrix._33 / num16; float num19 = atan2f(num17, num18); float num20 = matrix._12 / num16; float num21 = matrix._11 / num16; float num22 = atan2f(num20, num21); bool loopFlag = i<(int)_info.IterationCount/2; num19 = GetUpperLowerRadian(num19, cl->LowerLimit.x, cl->UpperLimit.x, loopFlag); num15 = GetUpperLowerRadian(num15, cl->LowerLimit.y, cl->UpperLimit.y, loopFlag); num22 = GetUpperLowerRadian(num22, cl->LowerLimit.z, cl->UpperLimit.z, loopFlag); D3DXMATRIX nx, ny, nz; D3DXMatrixRotationX(&nx, num19); D3DXMatrixRotationY(&ny, num15); D3DXMatrixRotationZ(&nz, num22); matrix = nx*ny*nz; } else { float num23 = -matrix._21; float num24 = asinf(num23); if (abs(num24) > 1.535889f) { if (num24 < 0.0f) { num24 = -1.535889f; } else { num24 = 1.535889f; } } float num25 = cosf(num24); float num26 = matrix._23 / num25; float num27 = matrix._22 / num25; float num28 = atan2f(num26, num27); float num29 = matrix._31 / num25; float num30 = matrix._11 / num25; float num31 = atan2f(num29, num30); bool loopFlag = i<(int)_info.IterationCount/2; num28 = GetUpperLowerRadian(num28, cl->LowerLimit.x, cl->UpperLimit.x, loopFlag); num31 = GetUpperLowerRadian(num31, cl->LowerLimit.y, cl->UpperLimit.y, loopFlag); num24 = GetUpperLowerRadian(num24, cl->LowerLimit.z, cl->UpperLimit.z, loopFlag); D3DXMATRIX nx, ny, nz; D3DXMatrixRotationX(&nx, num28); D3DXMatrixRotationY(&ny, num31); D3DXMatrixRotationZ(&nz, num24); matrix = ny*nz*nx; } } D3DXQuaternionRotationMatrix(&cl->IKQuat, &matrix); } curBone->setRot(cl->IKQuat); //curBone->setCombTrans(matrix); for (int j=b;j>=0;j--) { _info.BoneLinkList[j].LinkBone->UpdateFromIK(); } endEffBone->UpdateFromIK(); } } for (int i=0;i<(int)_info.NumberOfLinks;i++) { _info.BoneLinkList[i].IKQuat = D3DXQUATERNION(0,0,0,1); } }
bool CPythonItem::TGroundItemInstance::Update() { if (bAnimEnded) return false; if (dwEndTime < CTimer::Instance().GetCurrentMillisecond()) { ThingInstance.SetRotationQuaternion(qEnd); /*D3DXVECTOR3 v3Adjust = -v3Center; D3DXMATRIX mat; D3DXMatrixRotationYawPitchRoll(&mat, D3DXToRadian(rEnd.y), D3DXToRadian(rEnd.x), D3DXToRadian(rEnd.z)); D3DXVec3TransformCoord(&v3Adjust,&v3Adjust,&mat);*/ D3DXQUATERNION qAdjust(-v3Center.x, -v3Center.y, -v3Center.z, 0.0f); D3DXQUATERNION qc; D3DXQuaternionConjugate(&qc, &qEnd); D3DXQuaternionMultiply(&qAdjust,&qAdjust,&qEnd); D3DXQuaternionMultiply(&qAdjust,&qc,&qAdjust); ThingInstance.SetPosition(v3EndPosition.x+qAdjust.x, v3EndPosition.y+qAdjust.y, v3EndPosition.z+qAdjust.z); //ThingInstance.Update(); bAnimEnded = true; __PlayDropSound(eDropSoundType, v3EndPosition); } else { DWORD time = CTimer::Instance().GetCurrentMillisecond() - dwStartTime; DWORD etime = dwEndTime - CTimer::Instance().GetCurrentMillisecond(); float rate = time * 1.0f / (dwEndTime - dwStartTime); D3DXVECTOR3 v3NewPosition=v3EndPosition;// = rate*(v3EndPosition - v3StartPosition) + v3StartPosition; v3NewPosition.z += 100-100*rate*(3*rate-2);//-100*(rate-1)*(3*rate+2); D3DXQUATERNION q; D3DXQuaternionRotationAxis(&q, &v3RotationAxis, etime * 0.03f *(-1+rate*(3*rate-2))); //ThingInstance.SetRotation(rEnd.y + etime*rStart.y, rEnd.x + etime*rStart.x, rEnd.z + etime*rStart.z); D3DXQuaternionMultiply(&q,&qEnd,&q); ThingInstance.SetRotationQuaternion(q); D3DXQUATERNION qAdjust(-v3Center.x, -v3Center.y, -v3Center.z, 0.0f); D3DXQUATERNION qc; D3DXQuaternionConjugate(&qc, &q); D3DXQuaternionMultiply(&qAdjust,&qAdjust,&q); D3DXQuaternionMultiply(&qAdjust,&qc,&qAdjust); ThingInstance.SetPosition(v3NewPosition.x+qAdjust.x, v3NewPosition.y+qAdjust.y, v3NewPosition.z+qAdjust.z); /*D3DXVECTOR3 v3Adjust = -v3Center; D3DXMATRIX mat; D3DXMatrixRotationYawPitchRoll(&mat, D3DXToRadian(rEnd.y + etime*rStart.y), D3DXToRadian(rEnd.x + etime*rStart.x), D3DXToRadian(rEnd.z + etime*rStart.z)); D3DXVec3TransformCoord(&v3Adjust,&v3Adjust,&mat); //Tracef("%f %f %f\n",v3Adjust.x,v3Adjust.y,v3Adjust.z); v3NewPosition += v3Adjust; ThingInstance.SetPosition(v3NewPosition.x, v3NewPosition.y, v3NewPosition.z);*/ } ThingInstance.Transform(); ThingInstance.Deform(); return !bAnimEnded; }
void CPythonItem::CreateItem(DWORD dwVirtualID, DWORD dwVirtualNumber, float x, float y, float z, bool bDrop) { //CItemManager& rkItemMgr=CItemManager::Instance(); CItemData * pItemData; if (!CItemManager::Instance().GetItemDataPointer(dwVirtualNumber, &pItemData)) return; CGraphicThing* pItemModel = pItemData->GetDropModelThing(); TGroundItemInstance * pGroundItemInstance = m_GroundItemInstancePool.Alloc(); pGroundItemInstance->dwVirtualNumber = dwVirtualNumber; bool bStabGround = false; if (bDrop) { z = CPythonBackground::Instance().GetHeight(x, y) + 10.0f; if (pItemData->GetType()==CItemData::ITEM_TYPE_WEAPON && (pItemData->GetWeaponType() == CItemData::WEAPON_SWORD || pItemData->GetWeaponType() == CItemData::WEAPON_ARROW)) bStabGround = true; bStabGround = false; pGroundItemInstance->bAnimEnded = false; } else { pGroundItemInstance->bAnimEnded = true; } { // attaching effect CEffectManager & rem =CEffectManager::Instance(); pGroundItemInstance->dwEffectInstanceIndex = rem.CreateEffect(m_dwDropItemEffectID, D3DXVECTOR3(x, -y, z), D3DXVECTOR3(0,0,0)); pGroundItemInstance->eDropSoundType=__GetDropSoundType(*pItemData); } D3DXVECTOR3 normal; if (!CPythonBackground::Instance().GetNormal(int(x),int(y),&normal)) normal = D3DXVECTOR3(0.0f,0.0f,1.0f); pGroundItemInstance->ThingInstance.Clear(); pGroundItemInstance->ThingInstance.ReserveModelThing(1); pGroundItemInstance->ThingInstance.ReserveModelInstance(1); pGroundItemInstance->ThingInstance.RegisterModelThing(0, pItemModel); pGroundItemInstance->ThingInstance.SetModelInstance(0, 0, 0); if (bDrop) { pGroundItemInstance->v3EndPosition = D3DXVECTOR3(x,-y,z); pGroundItemInstance->ThingInstance.SetPosition(0,0,0); } else pGroundItemInstance->ThingInstance.SetPosition(x, -y, z); pGroundItemInstance->ThingInstance.Update(); pGroundItemInstance->ThingInstance.Transform(); pGroundItemInstance->ThingInstance.Deform(); if (bDrop) { D3DXVECTOR3 vMin, vMax; pGroundItemInstance->ThingInstance.GetBoundBox(&vMin,&vMax); pGroundItemInstance->v3Center = (vMin + vMax) * 0.5f; std::pair<float,int> f[3] = { make_pair(vMax.x - vMin.x,0), make_pair(vMax.y - vMin.y,1), make_pair(vMax.z - vMin.z,2) }; std::sort(f,f+3); //int no_rotation_axis=-1; D3DXVECTOR3 rEnd; if (/*f[1].first-f[0].first < (f[2].first-f[0].first)*0.30f*/ bStabGround) { // 뾰족 if (f[2].second == 0) // axis x { rEnd.y = 90.0f + frandom(-15.0f, 15.0f); rEnd.x = frandom(0.0f, 360.0f); rEnd.z = frandom(-15.0f, 15.0f); } else if (f[2].second == 1) // axis y { rEnd.y = frandom(0.0f, 360.0f); rEnd.x = frandom(-15.0f, 15.0f); rEnd.z = 180.0f + frandom(-15.0f, 15.0f); } else // axis z { rEnd.y = 180.0f + frandom(-15.0f, 15.0f); rEnd.x = 0.0f+frandom(-15.0f, 15.0f); rEnd.z = frandom(0.0f, 360.0f); } } else { // 넓적 // 땅의 노말의 영향을 받을 것 if (f[0].second == 0) { // y,z = by normal pGroundItemInstance->qEnd = RotationArc( D3DXVECTOR3( ((float)(random()%2))*2-1+frandom(-0.1f,0.1f), 0+frandom(-0.1f,0.1f), 0+frandom(-0.1f,0.1f)), D3DXVECTOR3(0,0,1)/*normal*/); } else if (f[0].second == 1) { pGroundItemInstance->qEnd = RotationArc( D3DXVECTOR3( 0+frandom(-0.1f,0.1f), ((float)(random()%2))*2-1+frandom(-0.1f,0.1f), 0+frandom(-0.1f,0.1f)), D3DXVECTOR3(0,0,1)/*normal*/); } else { pGroundItemInstance->qEnd = RotationArc( D3DXVECTOR3( 0+frandom(-0.1f,0.1f), 0+frandom(-0.1f,0.1f), ((float)(random()%2))*2-1+frandom(-0.1f,0.1f)), D3DXVECTOR3(0,0,1)/*normal*/); } } //D3DXQuaternionRotationYawPitchRoll(&pGroundItemInstance->qEnd, rEnd.y, rEnd.x, rEnd.z ); float rot = frandom(0, 2*3.1415926535f); D3DXQUATERNION q(0,0,cosf(rot),sinf(rot)); D3DXQuaternionMultiply(&pGroundItemInstance->qEnd, &pGroundItemInstance->qEnd, &q); q = RotationArc(D3DXVECTOR3(0,0,1),normal); D3DXQuaternionMultiply(&pGroundItemInstance->qEnd, &pGroundItemInstance->qEnd, &q); pGroundItemInstance->dwStartTime = CTimer::Instance().GetCurrentMillisecond(); pGroundItemInstance->dwEndTime = pGroundItemInstance->dwStartTime+300; pGroundItemInstance->v3RotationAxis.x = sinf(rot+0);//frandom(0.4f,0.7f) * (2*(int)(random()%2) - 1); pGroundItemInstance->v3RotationAxis.y = cosf(rot+0);//frandom(0.4f,0.7f) * (2*(int)(random()%2) - 1); pGroundItemInstance->v3RotationAxis.z = 0;//frandom(0.4f,0.7f) * (2*(int)(random()%2) - 1); /* switch (no_rotation_axis) { case 0: pGroundItemInstance->rStart.x = 0; break; case 1: pGroundItemInstance->rStart.y = 0; break; case 2: pGroundItemInstance->rStart.z = 0; break; }*/ D3DXVECTOR3 v3Adjust = -pGroundItemInstance->v3Center; D3DXMATRIX mat; D3DXMatrixRotationQuaternion(&mat, &pGroundItemInstance->qEnd); /*D3DXMatrixRotationYawPitchRoll(&mat, D3DXToRadian(pGroundItemInstance->rEnd.y), D3DXToRadian(pGroundItemInstance->rEnd.x), D3DXToRadian(pGroundItemInstance->rEnd.z));*/ D3DXVec3TransformCoord(&v3Adjust,&v3Adjust,&mat); //Tracef("%f %f %f\n",v3Adjust.x,v3Adjust.y,v3Adjust.z); //pGroundItemInstance->v3EndPosition += v3Adjust; //pGroundItemInstance->rEnd.z += pGroundItemInstance->v3Center.z; } pGroundItemInstance->ThingInstance.Show(); m_GroundItemInstanceMap.insert(TGroundItemInstanceMap::value_type(dwVirtualID, pGroundItemInstance)); CPythonTextTail& rkTextTail=CPythonTextTail::Instance(); rkTextTail.RegisterItemTextTail( dwVirtualID, pItemData->GetName(), &pGroundItemInstance->ThingInstance); }
bool bgParserASE::ReadTMAnimation(int iNumObj) { bool hr = true; TCHAR szWordArray[2][MAX_PATH * 4]; TCHAR szWordTrack[4][MAX_PATH * 4]; AnimTrackInfo animData; bool bAnimEnd, bTrackEnd; m_pModel->m_ObjectList[iNumObj].Anim.PosTrack.clear(); m_pModel->m_ObjectList[iNumObj].Anim.RotTrack.clear(); m_pModel->m_ObjectList[iNumObj].Anim.SclTrack.clear(); _tcscpy(szWordTrack[0], _T("*CONTROL_POS_TRACK")); _tcscpy(szWordTrack[1], _T("*CONTROL_ROT_TRACK")); _tcscpy(szWordTrack[2], _T("*CONTROL_SCALE_TRACK")); _tcscpy(szWordTrack[3], _T("}")); bAnimEnd = false; while (bAnimEnd == false) { switch (FindWordArray(szWordTrack, 4)) { case 0: // *CONTROL_POS_TRACK ========================================== { _tcscpy(szWordArray[0], _T("*CONTROL_POS_SAMPLE")); _tcscpy(szWordArray[1], _T("}")); animData.Init(); bTrackEnd = false; while (bTrackEnd == false) { switch (FindWordArray(szWordArray, 2)) { case 0: // *CONTROL_POS_SAMPLE ---------------------------- { // 트랙 추가 _stscanf(m_szLine, _T("%s %d %f%f%f"), m_szWord, &animData.iTick, &animData.vVector.x, &animData.vVector.z, &animData.vVector.y); m_pModel->m_ObjectList[iNumObj].Anim.PosTrack.push_back(animData); continue; } break; case 1: // } ---------------------------- { // 트랙 종료 처리 bTrackEnd = true; } break; case -1: // 찾는 단어 없음 ----------------------------------- default: // 나머지 (배열 요소가 2개이므로 나올 수 없음) return false; break; } } } break; case 1: // *CONTROL_ROT_TRACK ========================================== { _tcscpy(szWordArray[0], _T("*CONTROL_ROT_SAMPLE")); _tcscpy(szWordArray[1], _T("}")); animData.Init(); bTrackEnd = false; while (bTrackEnd == false) { switch (FindWordArray(szWordArray, 2)) { case 0: // *CONTROL_ROT_SAMPLE ---------------------------- { // 트랙 추가 _stscanf(m_szLine, _T("%s %d %f%f%f %f"), m_szWord, &animData.iTick, &animData.qRotate.x, &animData.qRotate.z, &animData.qRotate.y, &animData.qRotate.w); D3DXQuaternionRotationAxis(&animData.qRotate, &D3DXVECTOR3(animData.qRotate.x, animData.qRotate.y, animData.qRotate.z), animData.qRotate.w); int iRotTrackSize = m_pModel->m_ObjectList[iNumObj].Anim.RotTrack.size(); if (iRotTrackSize) { D3DXQuaternionMultiply(&animData.qRotate, &m_pModel->m_ObjectList[iNumObj].Anim.RotTrack[iRotTrackSize - 1].qRotate, &animData.qRotate); } m_pModel->m_ObjectList[iNumObj].Anim.RotTrack.push_back(animData); continue; } break; case 1: // } ---------------------------- { // 트랙 종료 처리 bTrackEnd = true; } break; case -1: // 찾는 단어 없음 ----------------------------------- default: // 나머지 (배열 요소가 2개이므로 나올 수 없음) return false; break; } } } break; case 2: // *CONTROL_SCALE_TRACK ======================================== { _tcscpy(szWordArray[0], _T("*CONTROL_SCALE_SAMPLE")); _tcscpy(szWordArray[1], _T("}")); animData.Init(); bTrackEnd = false; while (bTrackEnd == false) { switch (FindWordArray(szWordArray, 2)) { case 0: // *CONTROL_SCALE_SAMPLE ------------------------ { // 트랙 추가 _stscanf(m_szLine, _T("%s %d %f%f%f %f%f%f%f"), m_szWord, &animData.iTick, &animData.vVector.x, &animData.vVector.z, &animData.vVector.y, &animData.qRotate.x, &animData.qRotate.z, &animData.qRotate.y, &animData.qRotate.w); D3DXQuaternionRotationAxis(&animData.qRotate, &D3DXVECTOR3(animData.qRotate.x, animData.qRotate.y, animData.qRotate.z), animData.qRotate.w); m_pModel->m_ObjectList[iNumObj].Anim.SclTrack.push_back(animData); continue; } break; case 1: // } ---------------------------- { // 트랙 종료 처리 bTrackEnd = true; } break; case -1: // 찾는 단어 없음 ----------------------------------- default: // 나머지 (배열 요소가 2개이므로 나올 수 없음) return false; break; } } } break; case 3: // } ======================================================== { // 애니메이션 종료 처리 bAnimEnd = true; } break; case -1: // 찾는 단어 없음 =============================================== default: // 나머지 (배열 요소가 4개이므로 나올 수 없음) return false; break; } } return hr; }