BOOL _XKeyframeController::LoadNode_TM( FILE* pFile, _XM_SUBNODE* pSubNode ) { D3DXMATRIX matScale, matWorld; D3DXMatrixIdentity(&pSubNode->matTM); D3DXVECTOR3 tmPos = D3DXVECTOR3(0, 0, 0), tmScale = D3DXVECTOR3(1, 1, 1); D3DXQUATERNION tmRot; D3DXQuaternionIdentity(&tmRot); fread(&tmPos, 1, sizeof(D3DXVECTOR3), pFile); fread(&tmRot, 1, sizeof(D3DXQUATERNION), pFile); fread(&tmScale, 1, sizeof(D3DXVECTOR3), pFile); tmRot.x = sinf(tmRot.w/2.0f)*tmRot.x; tmRot.y = sinf(tmRot.w/2.0f)*tmRot.y; tmRot.z = sinf(tmRot.w/2.0f)*tmRot.z; tmRot.w = cosf(tmRot.w/2.0f); D3DXMatrixRotationQuaternion(&matWorld, &tmRot); matWorld._41 = tmPos.x; matWorld._42 = tmPos.y; matWorld._43 = tmPos.z; D3DXMatrixScaling(&matScale, tmScale.x, tmScale.y, tmScale.z); D3DXMatrixMultiply(&pSubNode->matTM, &matScale, &matWorld); return TRUE; }
void cNormalGun::Shot(const D3DXVECTOR3& vDir, cObjBase* pObj) { if (m_IsCanShot) { _GETS(cSystemMgr)->CreateSound(L"Data/Sound/shot.wav", false); D3DXMATRIXA16 matRot; D3DXQUATERNION q; auto matWorld = pObj->GetWorldMatrix(); D3DXVECTOR3 vObjPos = D3DXVECTOR3(matWorld._41, matWorld._42, matWorld._43); D3DXVECTOR3 vPos; for (int n = 0; n < 1; ++n) { D3DXQuaternionRotationAxis(&q, &_GETSINGLE( cObjectMgr)->GetWorldUp(), (n * 2 - 1) * D3DX_PI * 0.25f); D3DXMatrixRotationQuaternion(&matRot, &q); // D3DXVec3TransformCoord(&vPos, &vDir, &matRot); vPos = vObjPos; auto pBullet = InstantiateBullet(vDir ,vPos); if (pBullet != NULL) { this->BulletTypeSetup(pBullet, pObj); } } this->SetCoolTime(); } }
void Sun::HandleMessage(const D3DXMATRIX *pViewMatrix) { render::Interface *pInterface = render::Interface::GetInstance(); int iW = pInterface->GetWndWidth(); int iH = pInterface->GetWndHeight(); ui::Manager::_tagINPUTINFO *pInputInfo = ui::Manager::GetInstance()->GetInputInfoBuffer(); switch(pInputInfo->eType) { case UIMT_MS_BTNDOWN: if (pInputInfo->dwData == MK_RBUTTON && (pInputInfo->byKeyBuffer[DIK_LALT] & 0x80)) { m_bDrag = TRUE; m_qOld = m_qNow; ScreenToVector(pInputInfo->ptMouse.x,pInputInfo->ptMouse.y,iW,iH,1.0f,&m_vOldVector); } break; case UIMT_MS_MOVE: if (m_bDrag) { ScreenToVector(pInputInfo->ptMouse.x,pInputInfo->ptMouse.y,iW,iH,1.0f,&m_vCurVector); m_qNow = m_qOld * QuatFromBallPoints( m_vOldVector, m_vCurVector ); D3DXMATRIX mInvView; D3DXMatrixInverse(&mInvView, NULL, pViewMatrix); mInvView._41 = mInvView._42 = mInvView._43 = 0; D3DXMATRIX mLastRotInv; D3DXMatrixInverse(&mLastRotInv, NULL, &m_mRotSnapshot); D3DXMATRIX mRot; D3DXMatrixRotationQuaternion(&mRot, &m_qNow); m_mRotSnapshot = mRot; // Accumulate the delta of the arcball's rotation in view space. // Note that per-frame delta rotations could be problematic over long periods of time. m_mRot *= *pViewMatrix * mLastRotInv * mRot * mInvView; // Since we're accumulating delta rotations, we need to orthonormalize // the matrix to prevent eventual matrix skew D3DXVECTOR3* pXBasis = (D3DXVECTOR3*) &m_mRot._11; D3DXVECTOR3* pYBasis = (D3DXVECTOR3*) &m_mRot._21; D3DXVECTOR3* pZBasis = (D3DXVECTOR3*) &m_mRot._31; D3DXVec3Normalize( pXBasis, pXBasis ); D3DXVec3Cross( pYBasis, pZBasis, pXBasis ); D3DXVec3Normalize( pYBasis, pYBasis ); D3DXVec3Cross( pZBasis, pXBasis, pYBasis ); //Transform the default direction vector by the light's rotation matrix D3DXVec3TransformNormal( &m_vCurDirection, &m_vDefDirection , &m_mRot ); } break; } if (!(pInputInfo->dwMouseButtonState & MK_RBUTTON)) { m_bDrag = FALSE; } }
Ray OBB::GetContactPoint(Ray &ray) { D3DXMATRIX p, r, world, invWorld; D3DXMatrixTranslation(&p, m_pos.x, m_pos.y, m_pos.z); D3DXMatrixRotationQuaternion(&r, &m_rot); D3DXMatrixMultiply(&world, &r, &p); D3DXMatrixInverse(&invWorld, NULL, &world); D3DXVECTOR3 org, dir; D3DXVec3TransformCoord(&org, &ray.m_org, &invWorld); D3DXVec3TransformNormal(&dir, &ray.m_dir, &invWorld); D3DXPLANE planes[] = {D3DXPLANE(0.0f, 0.0f, -1.0f, -m_size.z), D3DXPLANE(0.0f, 0.0f, 1.0f, -m_size.z), D3DXPLANE(0.0f, -1.0f, 0.0f, -m_size.y), D3DXPLANE(0.0f, 1.0f, 0.0f, -m_size.y), D3DXPLANE(-1.0f, 0.0f, 0.0f, -m_size.x), D3DXPLANE(1.0f, 0.0f, 0.0f, -m_size.x) }; D3DXVECTOR3 result, normal; int numPlanes = 0; int numIntersections = 0; for (int i=0; i<6; i++) { float d = org.x * planes[i].a + org.y * planes[i].b + org.z * planes[i].c; if (d > -planes[i].d) { D3DXVECTOR3 r; if (D3DXPlaneIntersectLine(&r, &planes[i], &org, &(org + dir * 1000.0f)) != NULL) { numPlanes++; if (abs(r.x) <= m_size.x && abs(r.y) <= m_size.y && abs(r.z) <= m_size.z) { D3DXVec3TransformCoord(&r, &r, &world); result = r; normal = D3DXVECTOR3(planes[i].a, planes[i].b, planes[i].c); numIntersections++; } } } } if (numIntersections == 0) { //Warning! OBB No Intersections! return Ray(ray.m_org, -ray.m_dir); } D3DXVec3Normalize(&normal, &normal); D3DXVec3TransformNormal(&normal, &normal, &world); return Ray(result, normal); }
Camera::Camera(Scene* parent, std::string name) : m_parentScene(parent), GameObject(name) { Vec3 up(0,1,0), position(0,0,-100), lookAt(0,0,1); Mat44 rotationMatrix; D3DXMatrixRotationQuaternion(&rotationMatrix, &m_rotation); lookAt = position + lookAt; D3DXMatrixLookAtLH(&this->m_GUIViewMatrix, &position, &lookAt, &up); }
void Mesh::RotateVectorByMeshesRotation( Vector3& vec ) { D3DXMATRIX QuatMat; D3DXMatrixRotationQuaternion(&QuatMat, &this->rotQuat); D3DXVECTOR4 o; D3DXVECTOR3 i = D3DXVECTOR3(vec.x, vec.y, vec.z); D3DXVec3Transform(&o, &i, &QuatMat); vec.x = o.x; vec.y = o.y; vec.z = o.z; }
D3DXMATRIX BT2DX_MATRIX(const btTransform &ms) { btQuaternion q = ms.getRotation(); btVector3 p = ms.getOrigin(); D3DXMATRIX pos, rot, world; D3DXMatrixTranslation(&pos, p.x(), p.y(), p.z()); D3DXMatrixRotationQuaternion(&rot, &BT2DX_QUATERNION(q)); D3DXMatrixMultiply(&world, &rot, &pos); return world; }
void SpaceShip::UpdateCamera() { // Update the camera D3DXMATRIX matrix; D3DXVECTOR4 vec = D3DXVECTOR4(0, 6, -16, 1); D3DXVec4Transform(&vec, &vec, D3DXMatrixRotationQuaternion(&matrix, &m_QuatY)); Vector3D eye = Vector3D(vec.x + m_Position.X, vec.y + m_Position.Y, vec.z + m_Position.Z); m_Camera->SetAllVectors(eye, m_Position, Vector3D(0, 1, 0)); }
void CN3Transform::ReCalcMatrix() { m_Matrix.Scale(m_vScale); if(m_qRot.w != 0) { static __Matrix44 mtxRot; D3DXMatrixRotationQuaternion(&mtxRot, &m_qRot); m_Matrix *= mtxRot; } m_Matrix.PosSet(m_vPos); }
/************************************************************************* * D3DXMatrixAffineTransformation2D */ D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D( D3DXMATRIX *pout, FLOAT scaling, CONST D3DXVECTOR2 *protationcenter, FLOAT rotation, CONST D3DXVECTOR2 *ptranslation) { D3DXMATRIX m1, m2, m3, m4, m5; D3DXQUATERNION rot; D3DXVECTOR3 rot_center, trans; rot.w=cos(rotation/2.0f); rot.x=0.0f; rot.y=0.0f; rot.z=sin(rotation/2.0f); if ( protationcenter ) { rot_center.x=protationcenter->x; rot_center.y=protationcenter->y; rot_center.z=0.0f; } else { rot_center.x=0.0f; rot_center.y=0.0f; rot_center.z=0.0f; } if ( ptranslation ) { trans.x=ptranslation->x; trans.y=ptranslation->y; trans.z=0.0f; } else { trans.x=0.0f; trans.y=0.0f; trans.z=0.0f; } D3DXMatrixScaling(&m1, scaling, scaling, 1.0f); D3DXMatrixTranslation(&m2, -rot_center.x, -rot_center.y, -rot_center.z); D3DXMatrixTranslation(&m4, rot_center.x, rot_center.y, rot_center.z); D3DXMatrixRotationQuaternion(&m3, &rot); D3DXMatrixTranslation(&m5, trans.x, trans.y, trans.z); D3DXMatrixMultiply(&m1, &m1, &m2); D3DXMatrixMultiply(&m1, &m1, &m3); D3DXMatrixMultiply(&m1, &m1, &m4); D3DXMatrixMultiply(pout, &m1, &m5); return pout; }
//============================================================================= // SceneModelの描画 //============================================================================= void SceneModel::Draw() { D3DXMATRIX mtxScl, mtxRot, mtxTranslate, mtxQuat; D3DMATERIAL9 matDef; // ワールドマトリックスの設定 D3DXMatrixIdentity(&m_MtxWorld); // 大きさを反映 D3DXMatrixScaling(&mtxScl, m_Scl.x, m_Scl.y, m_Scl.z); D3DXMatrixMultiply(&m_MtxWorld, &m_MtxWorld, &mtxScl); // 向きを反映 D3DXMatrixRotationYawPitchRoll(&mtxRot, m_Rot.y, m_Rot.x, m_Rot.z); D3DXMatrixMultiply(&m_MtxWorld, &m_MtxWorld, &mtxRot); // クオータニオン反映 D3DXMatrixRotationQuaternion(&mtxQuat, &m_Quaternion); D3DXMatrixMultiply(&m_MtxWorld, &m_MtxWorld, &mtxQuat); // 位置を反映 D3DXMatrixTranslation(&mtxTranslate, m_Pos.x, m_Pos.y, m_Pos.z); D3DXMatrixMultiply(&m_MtxWorld, &m_MtxWorld, &mtxTranslate); // 親モデルとの連結 if (m_pParent) { // 親モデルのワールドに反映 D3DXMatrixMultiply(&m_MtxWorld, &m_MtxWorld, &m_pParent->m_MtxWorld); m_pD3DDevice->SetTransform(D3DTS_WORLD, &m_MtxWorld); } else { m_pD3DDevice->SetTransform(D3DTS_WORLD, &m_MtxWorld); } m_pD3DDevice->GetMaterial(&matDef); // 現在のマテリアルを保存 for (size_t nCntMat = 0; nCntMat < (int)m_NumMat; nCntMat++) { m_pD3DDevice->SetMaterial(&m_pMaterial[nCntMat].MatD3D); // マテリアル設定 if (m_pMaterial[nCntMat].pTextureFilename) // テクスチャの設定 { m_pD3DDevice->SetTexture(0, m_pTextureBuff[nCntMat]); // テクスチャの設定 } else { m_pD3DDevice->SetTexture(0, NULL); // テクスチャの設定 } m_pMeshBuff->DrawSubset(nCntMat); // 各パーツの描画 } m_pD3DDevice->SetMaterial(&matDef); // マテリアルを元に戻す }
void TrackTube::SetWorldMatrix(Vector scale, Quaternion rotation, Vector translate){ D3DXMatrixIdentity(&worldMatrix); D3DXQUATERNION qat; qat.x = rotation.x; qat.y = rotation.y; qat.z = rotation.z; qat.w = rotation.w; D3DXMATRIX trans, rot, sc; D3DXMatrixTranslation(&trans, translate.x, translate.y, translate.z); D3DXMatrixRotationQuaternion(&rot, &qat); D3DXMatrixScaling(&sc, scale.x, scale.y, scale.z); worldMatrix = sc*rot*trans; }
void cObjBase::Translation() { D3DXMATRIXA16 matScale, matRot, matTrans; D3DXMatrixScaling(&matScale, m_vScale.x, m_vScale.y, m_vScale.z); { D3DXQUATERNION q; D3DXQuaternionRotationYawPitchRoll(&q, m_vRotation.y, m_vRotation.x, m_vRotation.z); D3DXMatrixRotationQuaternion(&matRot, &q); } D3DXMatrixTranslation(&matTrans, m_vPosition.x, m_vPosition.y, m_vPosition.z); m_matWorld = matScale * matRot * matTrans; }
bool OBB::Intersect(Ray &ray) { D3DXMATRIX p, r, world; D3DXMatrixTranslation(&p, m_pos.x, m_pos.y, m_pos.z); D3DXMatrixRotationQuaternion(&r, &m_rot); D3DXMatrixMultiply(&world, &r, &p); D3DXMatrixInverse(&world, NULL, &world); D3DXVECTOR3 org, dir; D3DXVec3TransformCoord(&org, &ray.m_org, &world); D3DXVec3TransformNormal(&dir, &ray.m_dir, &world); return D3DXBoxBoundProbe(&(-m_size), &m_size, &org, &dir) == TRUE; }
void CCamera::SetViewQuaternion(const D3DXVECTOR3& _krvec3Position, const D3DXQUATERNION& _krquatRotation) { m_vec3Position = _krvec3Position; D3DXMATRIX mat; D3DXMatrixRotationQuaternion(&mat, &_krquatRotation); D3DXVec3TransformCoord(&m_vec3Look, &g_atUpRightDirectionVecs[FACE_TOP].vec3Direction, &mat); D3DXVec3TransformCoord(&m_vec3Up, &g_atUpRightDirectionVecs[FACE_TOP].vec3Up, &mat); D3DXVec3TransformCoord(&m_vec3Right, &g_atUpRightDirectionVecs[FACE_TOP].vec3Right, &mat); D3DXMatrixTransformation(&m_matView, 0, 0, 0, 0, &_krquatRotation, &_krvec3Position); D3DXMatrixInverse(&m_matView, 0, &m_matView); }
bool OBB::Intersect(D3DXVECTOR3 &point) { D3DXMATRIX p, r, world; D3DXMatrixTranslation(&p, m_pos.x, m_pos.y, m_pos.z); D3DXMatrixRotationQuaternion(&r, &m_rot); D3DXMatrixMultiply(&world, &r, &p); D3DXMatrixInverse(&world, NULL, &world); D3DXVECTOR4 pnt; D3DXVec3Transform(&pnt, &point, &world); if (abs(pnt.x) > m_size.x)return false; if (abs(pnt.y) > m_size.y)return false; if (abs(pnt.z) > m_size.z)return false; return true; }
HRESULT CXFrameNode::UpdateMatrices(D3DXMATRIX* ParentMat) { if(m_TransUsed[0]) { D3DXVECTOR3 TransPos = m_TransPos[0]; D3DXVECTOR3 TransScale = m_TransScale[0]; D3DXQUATERNION TransRot = m_TransRot[0]; float LerpValue = m_LerpValue[0]; if(m_TransUsed[1]) { D3DXVec3Lerp(&TransScale, &TransScale, &m_TransScale[1], LerpValue); D3DXQuaternionSlerp(&TransRot, &TransRot, &m_TransRot[1], LerpValue); D3DXVec3Lerp(&TransPos, &TransPos, &m_TransPos[1], LerpValue); } // prepare local transformation matrix D3DXMatrixIdentity(&m_TransformationMatrix); D3DXMATRIX ScaleMat; D3DXMatrixScaling(&ScaleMat, TransScale.x, TransScale.y, TransScale.z); D3DXMatrixMultiply(&m_TransformationMatrix, &m_TransformationMatrix, &ScaleMat); D3DXMATRIX RotMat; D3DXMatrixRotationQuaternion(&RotMat, &TransRot); D3DXMatrixMultiply(&m_TransformationMatrix, &m_TransformationMatrix, &RotMat); D3DXMATRIX PosMat; D3DXMatrixTranslation(&PosMat, TransPos.x, TransPos.y, TransPos.z); D3DXMatrixMultiply(&m_TransformationMatrix, &m_TransformationMatrix, &PosMat); } m_TransUsed[0] = m_TransUsed[1] = false; // multiply by parent transformation D3DXMatrixMultiply(&m_CombinedMatrix, &m_TransformationMatrix, ParentMat); // update child frames for(int i=0; i<m_Frames.GetSize(); i++) { m_Frames[i]->UpdateMatrices(&m_CombinedMatrix); } return S_OK; }
void Camera::Render(ViewPort* viewPort, Mat44 worldMatrix, Mat44 projectionMatrix, Mat44 orthogonalMatrix) { Vec3 up(0,1,0), lookAt(0,0,1); Mat44 rotationMatrix; D3DXMatrixRotationQuaternion(&rotationMatrix, &m_rotation); D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix); D3DXVec3TransformCoord(&up, &up, &rotationMatrix); lookAt = position + lookAt; D3DXMatrixLookAtLH(&this->m_viewMatrix, &position, &lookAt, &up); m_parentScene->Render(viewPort, worldMatrix, m_viewMatrix, projectionMatrix); m_parentScene->RenderGUI(viewPort, worldMatrix, m_GUIViewMatrix, orthogonalMatrix); // Seems like a sloppy fix return; }
bool Application::OnUpdate() { lcTime::Get()->Update(); m_pKeyboard->Update(); m_pMouse->Update(); lcCamera::FreeLookCamera(m_pCamera,1.0f,1.0f); m_pCamera->Update(); if(lcKeyboard::IsKeyDown(KEY_ESCAPE)) return 0; D3DXMATRIX outMat; D3DXQUATERNION invQuat; m_pScene->SetTranslate(g_kRootPosition); D3DXQUATERNION tempq; D3DXVECTOR3 tempAxis; float tempAngle; D3DXQuaternionToAxisAngle(&g_kRootRotation, &tempAxis, &tempAngle); tempAxis = -tempAxis; D3DXQuaternionRotationAxis(&tempq, &tempAxis, tempAngle); D3DXMatrixRotationQuaternion(&outMat,&tempq); m_pScene->SetRotate(outMat); if(g_bWireframe) { g_pkBox->SetPrimativeTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); } else { g_pkBox->SetPrimativeTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); } lcRenderer::GetDeviceContext()->PSSetSamplers(0,1,&CubeSampleState); m_pScene->Update(); return m_pWindow->Tick(); }
void OBB::Render() { if (m_pMesh != NULL) { D3DXMATRIX p, r, world; D3DXMatrixTranslation(&p, m_pos.x, m_pos.y, m_pos.z); D3DXMatrixRotationQuaternion(&r, &m_rot); D3DXMatrixMultiply(&world, &r, &p); g_pEffect->SetMatrix("matW", &world); D3DXHANDLE hTech = g_pEffect->GetTechniqueByName("Lighting"); g_pEffect->SetTechnique(hTech); g_pEffect->Begin(NULL, NULL); g_pEffect->BeginPass(0); m_pMesh->DrawSubset(0); g_pEffect->EndPass(); g_pEffect->End(); } }
void GEMesh::render() { if(!bVisible) return; D3DXMatrixScaling(&mScale, vScale.x, vScale.y, vScale.z); D3DXMatrixRotationQuaternion(&mRotation, &qRotation); D3DXMatrixTranslation(&mTranslation, vPosition.x, vPosition.y, vPosition.z); mTransform = mScale * mRotation * mTranslation; d3ddev->SetTransform(D3DTS_WORLD, &mTransform); for(DWORD i = 0; i < iNumMaterials; i++) { d3ddev->SetMaterial(&mMaterials[i]); d3ddev->SetTexture(0, mTextures[i]); mMesh->DrawSubset(i); } }
void Racer::update() { if (drawable && body) { D3DXMATRIX transMat; (body->getTransform()).get4x4ColumnMajor(transMat); drawable->setTransform(&transMat); // Now update wheels (wheelRL->body->getTransform()).get4x4ColumnMajor(transMat); wheelRL->drawable->setTransform(&transMat); (wheelRR->body->getTransform()).get4x4ColumnMajor(transMat); wheelRR->drawable->setTransform(&transMat); (wheelFL->body->getTransform()).get4x4ColumnMajor(transMat); D3DXMATRIX rot1, rot2, trans1; D3DXVECTOR3 scale, trans; D3DXQUATERNION rot; D3DXMatrixDecompose(&scale, &rot, &trans, &transMat); D3DXMatrixRotationQuaternion(&rot1, &rot); D3DXMatrixRotationAxis(&rot2, &(drawable->getYVector()), currentSteering * 1.11f); D3DXMatrixTranslation(&trans1, trans.x, trans.y, trans.z); D3DXMatrixMultiply(&transMat, &rot1, &rot2); D3DXMatrixMultiply(&transMat, &transMat, &trans1); wheelFL->drawable->setTransform(&transMat); (wheelFR->body->getTransform()).get4x4ColumnMajor(transMat); D3DXMatrixTranslation(&trans1, transMat._41, transMat._42, transMat._43); D3DXMatrixMultiply(&transMat, &rot1, &rot2); D3DXMatrixMultiply(&transMat, &transMat, &trans1); wheelFR->drawable->setTransform(&transMat); } }
bool Maze::checkRespownConditions() { Vector3 pos = this->mPlatform->GetMesh()->GetPosition(); D3DXMATRIX quat; D3DXMatrixRotationQuaternion(&quat, &this->mPlatform->GetMesh()->GetRotation()); Matrix4 rotate(quat); rotate.TransposeThis(); Vector3 posBall = this->mBalls[0]->GetMesh()->GetPosition(); Vector3 newCoord = rotate.GetInverse() * (posBall - pos - Vector3(0,5.0f,0)); if(newCoord.y < -6.0f) return true; else return false; }
void* Tractor::getVehiclePose() { if(m_poseGiven) return (void*)m_vehiclePose; m_poseGiven = true; /*CHASSIS*/ Mat rot; worldMat(&m_vehiclePose->matChassis, Vec3(m_actor->getGlobalPosition().x, m_actor->getGlobalPosition().y, m_actor->getGlobalPosition().z), Vec3(0, 0, 0)); D3DXMatrixRotationQuaternion(&rot, &D3DXQUATERNION(m_actor->getGlobalOrientationQuat().x, m_actor->getGlobalOrientationQuat().y, m_actor->getGlobalOrientationQuat().z, m_actor->getGlobalOrientationQuat().w)); m_vehiclePose->matChassis = m_vehicleDimms->matChassisRotation * rot * m_vehiclePose->matChassis; D3DXVec3TransformNormal(&m_forward, &Vec3(1, 0, 0), &rot); ShapeUserData* sud; //Wheels //Front Left wheel sud = (ShapeUserData*)(m_wheelFrontLeft->userData); sud->wheelShapePose.getColumnMajor44((NxF32*)&m_vehiclePose->matFrontLeftWheel); m_vehiclePose->matFrontLeftWheel = m_vehicleDimms->matFrontLeftWheelRotation * m_vehiclePose->matFrontLeftWheel; //Front Right wheel sud = (ShapeUserData*)(m_wheelFrontRight->userData); sud->wheelShapePose.getColumnMajor44((NxF32*)&m_vehiclePose->matFrontRightWheel); m_vehiclePose->matFrontRightWheel = m_vehicleDimms->matFrontRightWheelRotation * m_vehiclePose->matFrontRightWheel; //Rear Left wheel sud = (ShapeUserData*)(m_wheelRearLeft->userData); sud->wheelShapePose.getColumnMajor44((NxF32*)&m_vehiclePose->matRearLeftWheel); m_vehiclePose->matRearLeftWheel = m_vehicleDimms->matRearLeftWheelRotation * m_vehiclePose->matRearLeftWheel; //Rear Right wheel sud = (ShapeUserData*)(m_wheelRearRight->userData); sud->wheelShapePose.getColumnMajor44((NxF32*)&m_vehiclePose->matRearRightWheel); m_vehiclePose->matRearRightWheel = m_vehicleDimms->matRearRightWheelRotation * m_vehiclePose->matRearRightWheel; return (void*)m_vehiclePose; }
void DisplayObject::MoveMesh(){ //D3DXMATRIX matRotateX; //D3DXMATRIX matRotateY; D3DXMATRIX matRotate; D3DXMATRIX matTrans; D3DXMATRIX matFinal; D3DXQuaternionNormalize(&_m_rotation, &_m_rotation); D3DXMatrixRotationQuaternion(&matRotate, &_m_rotation); //D3DXMatrixRotationX(&matRotateX, rotation.x); //D3DXMatrixRotationY(&matRotateY, rotation.y); //D3DXMatrixRotationZ(&matRotateZ, rotation.z); D3DXMatrixTranslation(&matTrans, _m_pos.x, _m_pos.y, _m_pos.z); D3DXMatrixMultiply(&matFinal, &matRotate, &matTrans); //matFinal = matRotate * matTrans; //matRotate = matRotateZ * matRotateY * matRotateX * matTrans; m_world = matFinal; //DXUTGetD3D9Device()->SetTransform(m_world, &(matRotate)); }
bool ActionBox::isPointInside(Vec3 *point) { /*if(!(point->y < m_currentMax.y && point->y > m_currentMin.y)) return false;*/ /*point->y = 100.0f; Vec3 p0 = m_min; Vec3 p1 = m_max; Vec3 p2 = Vec3(m_max.x, 0, m_min.z); Vec3 p2_2 = Vec3(m_min.x, 0, m_max.z); D3DXVec3TransformCoord(&p0, &p0, &m_world); D3DXVec3TransformCoord(&p1, &p1, &m_world); D3DXVec3TransformCoord(&p2, &p2, &m_world); D3DXVec3TransformCoord(&p2_2, &p2_2, &m_world); return D3DXIntersectTri(&p0, &p1, &p2, point, &Vec3(0, -1, 0), 0, 0, 0) || D3DXIntersectTri(&p0, &p1, &p2_2, point, &Vec3(0, -1, 0), 0, 0, 0);*/ Vec3 checkPoint = *point; checkPoint = (*point) - m_position; Mat temp; temp = m_world; D3DXQUATERNION quat; D3DXQuaternionRotationMatrix(&quat, &temp); D3DXQuaternionNormalize(&quat, &quat); D3DXQuaternionInverse(&quat, &quat); temp._41 = 0; temp._42 = 0; temp._43 = 0; D3DXMatrixRotationQuaternion(&temp, &quat); D3DXVec3TransformCoord(&checkPoint, &checkPoint, &temp); if(checkPoint.x > m_min.x && checkPoint.x < m_max.x && //checkPoint.y > m_min.y && checkPoint.y < m_max.y && checkPoint.z > m_min.z && checkPoint.z < m_max.z) return true; return false; }
/***************************************************************** * D3DXMATRIX Interpolate(D3DXMATRIX _d3dPrevFrame, D3DXMATRIX _d3dNextFrame, float _fLambda): * Interpolates between two Matrices based on Lambda time * * Ins: D3DXMATRIX _d3dPrevFrame * D3DXMATRIX _d3dNextFrame * float _fLambda * * Outs: void * * Returns: D3DXMATRIX * * Mod. Date: 02/20/2013 * Mod. Initials: SD *****************************************************************/ D3DXMATRIX Interpolate(D3DXMATRIX& d3dMatrixA, D3DXMATRIX& d3dMatrixB, float fLambda) { D3DXQUATERNION quatA, quatB, tempQuat; D3DXQuaternionRotationMatrix(&quatA, &d3dMatrixA); D3DXQuaternionRotationMatrix(&quatB, &d3dMatrixB); tempQuat = quatA; D3DXQuaternionNormalize(&quatA, &tempQuat); tempQuat = quatB; D3DXQuaternionNormalize(&quatB, &tempQuat); D3DXQuaternionSlerp(&tempQuat, &quatA, &quatB, fLambda); D3DXMATRIX result; D3DXMatrixRotationQuaternion(&result, &tempQuat); D3DXVec3Lerp((D3DXVECTOR3*)&result[12], (D3DXVECTOR3*)&d3dMatrixA[12], (D3DXVECTOR3*)&d3dMatrixB[12], fLambda); D3DXVECTOR3 scaleA = D3DXVECTOR3(d3dMatrixA[0],d3dMatrixA[5],d3dMatrixA[10]); D3DXVECTOR3 scaleB = D3DXVECTOR3(d3dMatrixB[0],d3dMatrixB[5],d3dMatrixB[10]); D3DXVECTOR3 finalScale; D3DXVec3Lerp(&finalScale, &scaleA, &scaleB, fLambda); result[0] = finalScale[0]; result[5] = finalScale[1]; result[10] = finalScale[2]; return result; }
//----------------------------------------------------------------------------- // Name: FrameMove() // Desc: Called once per frame, the call is the entry point for animating // the scene. //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::FrameMove() { // When the window has focus, let the mouse adjust the camera view if( m_bCapture ) { D3DXMATRIX matCursor; D3DXQUATERNION qCursor = D3DUtil_GetRotationFromCursor( m_hWnd ); D3DXMatrixRotationQuaternion( &matCursor, &qCursor ); D3DXMatrixMultiply( &m_matView, &m_matTrackBall, &matCursor ); D3DXMATRIX matTrans; D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, 3.0f ); D3DXMatrixMultiply( &m_matView, &m_matView, &matTrans ); } else { D3DXMATRIX matRotation; D3DXMatrixRotationY( &matRotation, -m_fElapsedTime ); D3DXMatrixMultiply( &m_matWorld, &m_matWorld, &matRotation ); } return S_OK; }
void CMotion::Animate(D3DXMATRIX* bones, float currentFrame_, int nextFrame) { TMAnimation* frame = null; TMAnimation* next = null; D3DXQUATERNION slerp; D3DXVECTOR3 lerp; D3DXMATRIX m1, m2; const int currentFrame = (int)currentFrame_; const float slp = currentFrame_ - (float)currentFrame; for (int i = 0; i < m_boneCount; i++) { if (m_frames[i].frames) { frame = &m_frames[i].frames[currentFrame]; next = &m_frames[i].frames[nextFrame]; D3DXQuaternionSlerp(&slerp, &frame->rot, &next->rot, slp); D3DXVec3Lerp(&lerp, &frame->pos, &next->pos, slp); D3DXMatrixTranslation(&m1, lerp.x, lerp.y, lerp.z); D3DXMatrixRotationQuaternion(&m2, &slerp); m2 *= m1; if (m_bones[i].parentID != -1) m2 *= bones[m_bones[i].parentID]; } else { m2 = m_frames[i].TM; if (m_bones[i].parentID != -1) m2 *= bones[m_bones[i].parentID]; } bones[i] = m2; } }
const D3DXMATRIX* Camera::getViewMatrix() { if(!m_viewCacheValid) { D3DXMATRIX rot; D3DXMatrixIdentity(&m_viewMatrix); D3DXVECTOR4 transl(m_translation,1); D3DXMatrixRotationQuaternion(&rot, &m_orientation); D3DXMatrixTranslation(&m_viewMatrix,transl.x, transl.y, transl.z); m_viewMatrix *= rot; if(m_reflected) { m_viewMatrix = m_reflMatrix * m_viewMatrix; } m_viewCacheValid = true; } return &m_viewMatrix; }