void SkinnedMesh::UpdateMatrices(Bone* bone, D3DXMATRIX *parentMatrix) { if (bone == NULL)return; D3DXMatrixMultiply(&bone->CombinedTransformationMatrix, &bone->TransformationMatrix, parentMatrix); if (bone->pFrameSibling)UpdateMatrices((Bone*)bone->pFrameSibling, parentMatrix); if (bone->pFrameFirstChild)UpdateMatrices((Bone*)bone->pFrameFirstChild, &bone->CombinedTransformationMatrix); }
void CXModel::UpdateMatrices(const D3DXFRAME *inFrame, const D3DXMATRIX *parentMatrix) { stD3DFrameEx *frame = (stD3DFrameEx*)inFrame; if(parentMatrix != NULL) D3DXMatrixMultiply(&frame->finalMatrix, &frame->TransformationMatrix, parentMatrix); else frame->finalMatrix = frame->TransformationMatrix; if(frame->pFrameSibling != NULL) UpdateMatrices(frame->pFrameSibling, parentMatrix); if(frame->pFrameFirstChild != NULL) UpdateMatrices(frame->pFrameFirstChild, &frame->finalMatrix); }
void CCLUDrawBase::SetPerspectiveAngle(GLfloat fAngle, bool bUpdateMatrices) { m_sPer.Set(fAngle, float(m_iSizeX) / float(m_iSizeY), m_sPer.fNear, m_sPer.fFar); if (bUpdateMatrices) UpdateMatrices(); }
void CCLUDrawBase::Enable2dView(bool bVal) { m_b2dView = bVal; if (m_b2dView) { // Reset original Ortho factor and update Ortho vars. m_fOrthoFac = 0.01f; m_sOrtho.fLeft = -float(m_iSizeX) * 0.5f * m_fOrthoFac; m_sOrtho.fRight = float(m_iSizeX) * 0.5f * m_fOrthoFac; m_sOrtho.fBottom = -float(m_iSizeY) * 0.5f * m_fOrthoFac; m_sOrtho.fTop = float(m_iSizeY) * 0.5f * m_fOrthoFac; m_sOrtho.fNear = -100.0f; m_sOrtho.fFar = 100.0f; } UpdateMatrices(); m_mTransform[0].Reset(); ResetTransformVars(); if (!m_b2dView) m_mTransform[0].pfTrans[2] = -5.0; m_vRMain = m_E3Base.vSC; m_vU = m_E3Base.vSC; m_vAxis = m_E3Base.vSC; m_vU = 0; m_vAxis = 0; //if (!m_bIsAnimated) // Display(); }
void XSkinnedMesh::LoadModel( const string& fileName ) { BoneHierarchyLoader boneHierarchy; BoneFrame* frame = nullptr; // .x 파일로부터 본 계층 구조를 로드한다. auto hr = D3DXLoadMeshHierarchyFromX( fileName.c_str(), D3DXMESH_MANAGED, D3D9_DEVICE, &boneHierarchy, NULL, &frame, &_animation ); if (FAILED( hr )) { SAFE_DELETE( frame ); // assert } _rootBone = static_cast<Bone*>(frame); // bone matrices update SetMatrices(); UpdateMatrices( _rootBone, &_world ); SetupBoneMatrixPtr( _rootBone ); // render sphere //D3DXCreateSphere( D3D9_DEVICE, 2.0f, 10, 10, &_sphereMesh, NULL ); //LoadTexture( DEFAULT_TEX ); }
void RagDoll::UpdateSkeleton(Bone* bone) { if (bone == NULL) return; if (bone->m_pObb != NULL) { //Calculate new position for the bone D3DXMATRIX pos; D3DXVECTOR3 pivot = bone->m_pObb->GetPivot(bone->m_pivot); D3DXMatrixTranslation(&pos, pivot.x, pivot.y, pivot.z); //Calculate new orientation for the bone D3DXMATRIX rot; D3DXMatrixRotationQuaternion(&rot, &bone->m_pObb->GetRotation(bone->m_originalRot)); //Combine to create new transformation matrix bone->CombinedTransformationMatrix = rot * pos; //Update children bones with our new transformation matrix if (bone->pFrameFirstChild != NULL) UpdateMatrices((Bone*)bone->pFrameFirstChild, &bone->CombinedTransformationMatrix); } //Traverse the rest of the bone hierarchy UpdateSkeleton((Bone*)bone->pFrameSibling); UpdateSkeleton((Bone*)bone->pFrameFirstChild); }
//////////////////////////////////////////////////////////////// // // CTileBatcher::OnDeviceCreate // // // //////////////////////////////////////////////////////////////// void CTileBatcher::OnDeviceCreate ( IDirect3DDevice9* pDevice, float fViewportSizeX, float fViewportSizeY ) { m_pDevice = pDevice; // Cache matrices UpdateMatrices ( fViewportSizeX, fViewportSizeY ); }
void DRender::DrawMesh( DSimpleMesh * simpleMesh ) { assert( simpleMesh ); assert( m_context ); UpdateMatrices(); DMaterialController::DMaterial *material = nullptr; simpleMesh->GetMaterial( &material ); assert( material ); SetMaterial( material ); auto vertexViewPtr = simpleMesh->GetVertices(); assert( vertexViewPtr ); auto indexViewPtr = simpleMesh->GetIndices(); assert( indexViewPtr ); SetVertexBufferView( vertexViewPtr.Get() ); SetIndexBufferView( indexViewPtr.Get() ); SetPrimitiveTopology( D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); m_context->DrawIndexed( simpleMesh->GetIndexCount(), simpleMesh->GetStartIndexLocation(), simpleMesh->GetStartVertexLocation() ); }
void CXModel::Update(float time, const D3DXMATRIX *matWorld) { time /= m_speed; m_currentTime += time; if(m_animControl) m_animControl->AdvanceTime(time, NULL); UpdateMatrices(m_root, matWorld); stD3DContainerEx *pMesh = m_currentContainer; if(pMesh && pMesh->pSkinInfo) { unsigned int numBones = pMesh->pSkinInfo->GetNumBones(); for(unsigned int i = 0; i < numBones; i++) D3DXMatrixMultiply(&m_boneMatrices[i], pMesh->pSkinInfo->GetBoneOffsetMatrix(i), pMesh->boneMatrices[i]); void *srcPtr; pMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&srcPtr); void *destPtr; pMesh->originalMesh->LockVertexBuffer(0, (void**)&destPtr); pMesh->pSkinInfo->UpdateSkinnedMesh(m_boneMatrices, NULL, srcPtr, destPtr); pMesh->originalMesh->UnlockVertexBuffer(); pMesh->MeshData.pMesh->UnlockVertexBuffer(); } }
void AACodonMutSelSBDPPhyloProcess::ReadPredictedOmega(string name, int burnin, int every, int until) { if (GetNprocs() > 1) { cerr << "error in read predicted omega: works only under non mpi\n"; exit(1); } double* meanomega = new double[GetNsite()]; for (int i=0; i<GetNsite(); i++) { meanomega[i] = 0; } ifstream is((name + ".chain").c_str()); if (!is) { cerr << "error: no .chain file found\n"; exit(1); } cerr << "burnin : " << burnin << "\n"; cerr << "until : " << until << '\n'; int i=0; while ((i < until) && (i < burnin)) { FromStream(is); i++; } int samplesize = 0; while (i < until) { cerr << "."; cerr.flush(); samplesize++; FromStream(is); i++; UpdateMatrices(); for (int i=0; i<GetNsite(); i++) { meanomega[i] += GetPredictedOmega(i); } int nrep = 1; while ((i<until) && (nrep < every)) { FromStream(is); i++; nrep++; } } cerr << '\n'; double mean = 0; ofstream os((name + ".predsiteomega").c_str()); os << "site\tomega\n"; for (int i=0; i<GetNsite(); i++) { meanomega[i] /= samplesize; mean += meanomega[i]; os << i+1 << '\t' << meanomega[i] << '\n'; } cerr << "mean site-specific predicted dN/dS in" << name << ".predsiteomega\n"; mean /= GetNsite(); cerr << "global mean predicted omega: " << mean << '\n'; cerr << '\n'; }
void CCLUDrawBase::SetPerspective(GLfloat fAngle, GLfloat fNear, GLfloat fFar) { m_sPer.Set(fAngle, float(m_iSizeX) / float(m_iSizeY), fNear, fFar); UpdateMatrices(); if (!m_bIsAnimated) Display(); }
void SKINNEDMESH::SetPose(D3DXMATRIX world, ID3DXAnimationController* animControl, float time) { if(animControl != NULL) animControl->AdvanceTime(time, NULL); else m_pAnimControl->AdvanceTime(time, NULL); UpdateMatrices((BONE*)m_pRootBone, &world); }
//////////////////////////////////////////////////////////////// // // CTileBatcher::OnRenderTargetChange // // // //////////////////////////////////////////////////////////////// void CTileBatcher::OnChangingRenderTarget ( uint uiNewViewportSizeX, uint uiNewViewportSizeY ) { // Flush dx draws Flush (); // Make new projection transform UpdateMatrices ( uiNewViewportSizeX, uiNewViewportSizeY ); }
void CCLUDrawBase::SetOrtho(GLfloat fLeft, GLfloat fRight, GLfloat fBottom, GLfloat fTop, GLfloat fNear, GLfloat fFar) { m_sOrtho.Set(fLeft, fRight, fBottom, fTop, fNear, fFar); UpdateMatrices(); if (!m_bIsAnimated) Display(); }
void XSkinnedMesh::SetPose( float time ) { if (_animation != NULL) { _animation->AdvanceTime( time, NULL ); } UpdateMatrices( _rootBone, &_world ); }
// MPI: these two functions are responsible for broadcasting/receiving the current state of the parameter vector // are model dependent // should be implemented in .cpp file void CodonMutSelSBDPPhyloProcess::SlaveUpdateParameters() { // SlaveBroadcastTree(); int i,j,L1,L2,ni,nd,nbranch = GetNbranch(),nnucrr = GetNnucrr(),nnucstat = 4; L1 = GetNmodeMax(); L2 = GetDim(); //nd = nbranch + nnucrr + nnucstat + L2 + L1*(L2+1); // check if these last terms are correct in this context... nd = nbranch + nnucrr + nnucstat + L1*L2 + GetDim() + 1; ni = 1 + ProfileProcess::GetNsite(); int* ivector = new int[ni]; double* dvector = new double[nd]; MPI_Bcast(ivector,ni,MPI_INT,0,MPI_COMM_WORLD); MPI_Bcast(dvector,nd,MPI_DOUBLE,0,MPI_COMM_WORLD); int index = 0; for(i=0; i<nbranch; ++i) { blarray[i] = dvector[index]; index++; } for(i=0; i<nnucrr; ++i) { nucrr[i] = dvector[index]; index++; } for(i=0; i<nnucstat; ++i) { nucstat[i] = dvector[index]; index++; } for(i=0; i<L1; ++i) { for(j=0; j<L2; ++j) { profile[i][j] = dvector[index]; index++; } } for (int i=0; i<GetDim(); i++) { dirweight[0][i] = dvector[index]; index++; } kappa = dvector[index]; index++; Ncomponent = ivector[0]; for(i=0; i<ProfileProcess::GetNsite(); ++i) { SBDPProfileProcess::alloc[i] = ivector[1+i]; } //GetBranchLengthsFromArray(); delete[] dvector; delete[] ivector; // this one is really important // in those cases where new components have appeared, or some old ones have disappeared // during allocation move on the master node. // // note that CreateMatrices() in fact creates only those that are not yet allocated // and also deletes those that are now obsolete // CreateMatrices(); UpdateMatrices(); }
Camera::Camera(ezAngle fov, float aspectRatio) : m_vPosition(0.0f, 200.0f, 0.0f), m_vUp(0.0f, 1.0f, 0.0f), m_ViewDir(1.0f, 0.0f, 0.0f) { const float nearPlane = 0.1f; const float farPlane = 1000.0f; m_ProjectionMatrix.SetPerspectiveProjectionMatrixFromFovY(fov, aspectRatio, nearPlane, farPlane, ezProjectionDepthRange::MinusOneToOne); UpdateMatrices(); }
void SKINNEDMESH::Load(char fileName[], IDirect3DDevice9 *Dev) { m_pDevice = Dev; BONE_HIERARCHY boneHierarchy; D3DXLoadMeshHierarchyFromX(fileName, D3DXMESH_MANAGED, m_pDevice, &boneHierarchy, NULL, &m_pRootBone, NULL); D3DXMATRIX i; UpdateMatrices((BONE*)m_pRootBone, D3DXMatrixIdentity(&i)); //Create Sphere D3DXCreateSphere(m_pDevice, 0.07f, 10, 10, &m_pSphereMesh, NULL); }
void XSkinnedMesh::UpdateMatrices( Bone* bone, D3DXMATRIX* parentMatrix ) { if (!bone) { assert( Util::ErrorMessage( "Bone is null" ) ); } // 부모 변환 행렬과 복합된 월드 변환 행렬을 계산 D3DXMatrixMultiply( &bone->_combinedTransMatrix, &bone->TransformationMatrix, parentMatrix ); // 동일한 계산을 형제 본에도 수행 if (bone->pFrameSibling) { UpdateMatrices( static_cast<Bone*>(bone->pFrameSibling), parentMatrix ); } // 동일한 계산을 자식 본에 수행 if (bone->pFrameFirstChild) { UpdateMatrices( static_cast<Bone*>(bone->pFrameFirstChild), &bone->_combinedTransMatrix ); } _world = *parentMatrix; }
void SkinnedMesh::Load(char fileName[]) { BoneHierarchyLoader boneHierarchy; D3DXLoadMeshHierarchyFromX(fileName, D3DXMESH_MANAGED, g_pDevice, &boneHierarchy, NULL, &m_pRootBone, NULL); SetupBoneMatrixPointers((Bone*)m_pRootBone); //Update all the bones D3DXMATRIX i; D3DXMatrixIdentity(&i); UpdateMatrices((Bone*)m_pRootBone, &i); //Create Sphere D3DXCreateSphere(g_pDevice, 0.02f, 10, 10, &m_pSphereMesh, NULL); }
//---------------------------------------------------------------------------- void PlaneMeshIntersectionWindow::OnIdle() { MeasureTime(); MoveCamera(); UpdateMatrices(); mEngine->Enable(mPSTarget); mEngine->ClearBuffers(); mEngine->Draw(mMesh); mEngine->Disable(mPSTarget); mEngine->Execute(mDrawIntersections, mXSize / 8, mYSize / 8, 1); mEngine->Draw(mOverlay); DrawFrameRate(8, mYSize - 8, mTextColor); mEngine->DisplayColorBuffer(0); UpdateFrameCount(); }
bool CCLUDrawBase::SetViewport(int iX, int iY, int iW, int iH) { if (iW <= 0 || iH <= 0) return false; glViewport(m_iPosX = iX, m_iPosY = iY, m_iSizeX = iW, m_iSizeY = iH); m_sPer.fAspect = float(m_iSizeX) / float(m_iSizeY); m_sOrtho.fLeft = -float(m_iSizeX) * 0.5f * m_fOrthoFac; m_sOrtho.fRight = float(m_iSizeX) * 0.5f * m_fOrthoFac; m_sOrtho.fBottom = -float(m_iSizeY) * 0.5f * m_fOrthoFac; m_sOrtho.fTop = float(m_iSizeY) * 0.5f * m_fOrthoFac; UpdateMatrices(); return true; }
Transformation(Fix _x, Fix _y, Fix _z, const ei::Quaternion& _rotation) : m_position(_x, _y, _z), m_rotation(_rotation) { UpdateMatrices(); }
//------------------------------------------------------------------------ int CGraphicsLayer::CreateShader() { HRESULT r=0; DWORD ShaderFlags=D3D10_SHADER_ENABLE_STRICTNESS; ID3D10Blob *pErrors = 0; // Compile shaders ID3D10Blob* pBlobVS = NULL; ID3D10Blob* pBlobHS = NULL; ID3D10Blob* pBlobDS = NULL; ID3D10Blob* pBlobPS = NULL; ID3D10Blob* pBlobGS = NULL; ID3D10Blob* pBlobGSFur = NULL; if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothVS", "vs_5_0", &pBlobVS )!=S_OK){return 1;} if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothHS", "hs_5_0", &pBlobHS )!=S_OK){return 1;} if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothDS", "ds_5_0", &pBlobDS )!=S_OK){return 1;} if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothGS", "gs_5_0", &pBlobGS )!=S_OK){return 1;} if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "FurGS", "gs_5_0", &pBlobGSFur )!=S_OK){return 1;} if(CompileShaderFromFile( L"D3D11SimpleFx.hlsl", "SmoothPS", "ps_5_0", &pBlobPS )!=S_OK){return 1;} if(m_pDevice->CreateVertexShader( pBlobVS->GetBufferPointer(), pBlobVS->GetBufferSize(), NULL, &m_pVSGouraud )!=S_OK){return 1;} if(m_pDevice->CreateHullShader( pBlobHS->GetBufferPointer(), pBlobHS->GetBufferSize(), NULL, &m_pHSSmooth )!=S_OK){return 1;} if(m_pDevice->CreateDomainShader( pBlobDS->GetBufferPointer(), pBlobDS->GetBufferSize(), NULL, &m_pDSSmooth )!=S_OK){return 1;} if(m_pDevice->CreateGeometryShader( pBlobGS->GetBufferPointer(), pBlobGS->GetBufferSize(), NULL, &m_pGSSmooth )!=S_OK){return 1;} if(m_pDevice->CreatePixelShader( pBlobPS->GetBufferPointer(), pBlobPS->GetBufferSize(), NULL, &m_pPSGouraud )!=S_OK){return 1;} if(m_pDevice->CreateGeometryShader( pBlobGSFur->GetBufferPointer(), pBlobGSFur->GetBufferSize(), NULL, &m_pGSFur )!=S_OK){return 1;} D3D11_INPUT_ELEMENT_DESC defaultLayout[] = { {"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT ,0, 0,D3D11_INPUT_PER_VERTEX_DATA,0}, }; if(m_pDevice->CreateInputLayout( defaultLayout, ARRAYSIZE( defaultLayout ), pBlobVS->GetBufferPointer(), pBlobVS->GetBufferSize(), &m_pVertexLayout )!=S_OK){return 1;} m_pDeviceContext->IASetInputLayout(m_pVertexLayout); if(CreateConstantsBuffer()!=S_OK){return 1;} D3DXMATRIX mtxWorld; D3DXMatrixIdentity(&mtxWorld); SetWorldMtx(mtxWorld); D3DXMATRIX mtxView; D3DXVECTOR3 vecEye(3.0f, 3.0f, 3.5f); D3DXVECTOR3 vecAt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vecUp(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&mtxView, &vecEye, &vecAt, &vecUp); SetViewMtx(mtxView); D3DXMatrixPerspectiveFovLH(&m_mProj, (float)D3DX_PI * 0.5f, m_rcScreenRect.right/(float)m_rcScreenRect.bottom, 0.1f, 50.0f); UpdateMatrices(); }
void Rotate( const ei::Vec3& _axis, float _angle ) { m_rotation = ei::Quaternion( _axis, _angle ) * m_rotation; UpdateMatrices(); }
void Rotate( float _yaw, float _pitch, float _roll ) { m_rotation = ei::Quaternion( _yaw, _pitch, _roll ) * m_rotation; UpdateMatrices(); }
void SkeletizedObj :: Update(float T_time) { Profile("Update skeletized object"); //RigidObj::Update(T_time); //////////////////////////////////////////////////////// Update Verlets for (int bi = 0; bi < I_bones; ++bi) if (!FL_stationary) { xFLOAT I_count = 0; if (Collisions.size()) { xVector3 NW_dump; NW_dump.zero(); std::vector<Physics::Colliders::CollisionPoint>::iterator iter_cur, iter_end = Collisions.end(); for (iter_cur = Collisions.begin(); iter_cur != iter_end; ++iter_cur) ApplyAcceleration(iter_cur->V_reaction, 1.f, *iter_cur); for (iter_cur = Collisions.begin(); iter_cur != iter_end; ++iter_cur) { bool supports = false; for (int ci = 0; ci < iter_cur->I_Bones && !supports; ++ci) supports = (iter_cur->W_Bones[ci].I_bone == bi); if (supports) { xVector3 N_fix = xVector3::Normalize(iter_cur->NW_fix); xFLOAT W_cos = xVector3::DotProduct(N_fix, NW_VerletVelocity_new[bi]); if (W_cos < 0.f) { NW_dump -= N_fix * W_cos; ++I_count; } } } if (I_count) { NW_VerletVelocity_new[bi] += NW_dump / I_count; verletSystem.FL_attached[bi] = true; } } if (!I_count) { //if (T_time != 0) //{ // //drag // xFLOAT V_vel = NW_VerletVelocity[i].length(); // xFLOAT W_air_drag = air_drag(S_radius, V_vel*V_vel) * T_time / M_mass; // if (V_vel > W_air_drag) // NW_VerletVelocity_new[i] += NW_VerletVelocity[i] * (1.f - W_air_drag / V_vel); //} //else NW_VerletVelocity_new[bi] += NW_VerletVelocity[bi]; } NW_VerletVelocity[bi] = NW_VerletVelocity_new[bi]; if (!NW_VerletVelocity[bi].isZero()) { if (T_time != 0) { verletSystem.P_previous[bi] = verletSystem.P_current[bi] + NW_VerletVelocity[bi] * T_time; Modify(); } else verletSystem.P_previous[bi] = verletSystem.P_current[bi]; NW_VerletVelocity_new[bi].zero(); } else verletSystem.P_previous[bi] = verletSystem.P_current[bi]; } verletSystem.SwapPositions(); xVector3 NW_translation; if (Collisions.size()) { NW_translation = MergeCollisions() * 0.9f; if (NW_translation.lengthSqr() < 0.0001f) NW_translation.zero(); } else NW_translation = verletSystem.P_current[0]-verletSystem.P_previous[0]; // Update Matrices MX_LocalToWorld_Set().postTranslateT(NW_translation); UpdateMatrices(); xSkeleton &spine = ModelGr->xModelP->Spine; verletSystem.C_constraints = spine.C_constraints; verletSystem.I_constraints = spine.I_constraints; verletSystem.C_lengthConst = spine.C_boneLength; verletSystem.Spine = &spine; verletSystem.MX_ModelToWorld = MX_LocalToWorld_Get(); verletSystem.MX_WorldToModel_T = MX_WorldToLocal; verletSystem.MX_WorldToModel_T.transpose(); verletSystem.T_step = T_time; VerletSolver engine; engine.Init(verletSystem); engine.I_passes = 5; //engine.Verlet(); engine.SatisfyConstraints(); if (T_time > EPSILON) { xFLOAT T_time_Inv = 1.f / T_time; for (int i = 0; i < I_bones; ++i) { xVector3 V_speed = (verletSystem.P_current[i] - verletSystem.P_previous[i]) * T_time_Inv; if (V_speed.x > 0.f && NW_VerletVelocity[i].x > 0.f) V_speed.x = min (V_speed.x, NW_VerletVelocity[i].x); else if (V_speed.x < 0.f && NW_VerletVelocity[i].x < 0.f) V_speed.x = max (V_speed.x, NW_VerletVelocity[i].x); else V_speed.x = 0.f; if (V_speed.y > 0.f && NW_VerletVelocity[i].y > 0.f) V_speed.y = min (V_speed.y, NW_VerletVelocity[i].y); else if (V_speed.y < 0.f && NW_VerletVelocity[i].y < 0.f) V_speed.y = max (V_speed.y, NW_VerletVelocity[i].y); else V_speed.y = 0.f; if (V_speed.z > 0.f && NW_VerletVelocity[i].z > 0.f) V_speed.z = min (V_speed.z, NW_VerletVelocity[i].z); else if (V_speed.z < 0.f && NW_VerletVelocity[i].z < 0.f) V_speed.z = max (V_speed.z, NW_VerletVelocity[i].z); else V_speed.z = 0.f; NW_VerletVelocity[i] = V_speed; } } else for (int i = 0; i < I_bones; ++i) NW_VerletVelocity[i].zero(); spine.CalcQuats(verletSystem.P_current, verletSystem.QT_boneSkew, 0, verletSystem.MX_WorldToModel_T); spine.QuatsToArray(QT_verlet); FL_verlet = false; bool FL_locked = false; for (int i = 0; i < I_bones; ++i) if (verletSystem.FL_attached[i]) { FL_locked = true; break; } xFLOAT T_mod = T_time; for (int i = 0; i < I_bones; ++i) if (T_Verlet[i] > T_time) { if (FL_locked) T_Verlet[i] -= T_time; verletSystem.W_boneMix[i] = 1.f; FL_verlet = true; } else if (T_Verlet[i] > 0.f) { T_Verlet[i] = 0.f; verletSystem.W_boneMix[i] = 1.f; FL_verlet = true; } else if (verletSystem.W_boneMix[i] > T_mod) { if (FL_locked) verletSystem.W_boneMix[i] -= T_mod; FL_verlet = true; } else verletSystem.W_boneMix[i] = 0.f; if (FL_verlet) comBoard.ID_action_cur = comBoard.StopAction.ID_action; spine.L_bones->QT_rotation.zeroQ(); QT_verlet[0].zeroQ(); //////////////////////////////////////////////////////// Track enemy movement if (FL_auto_movement && Tracker.Mode != Math::Tracking::ObjectTracker::TRACK_NOTHING && !FL_verlet && LifeEnergy > 0.f && T_time > 0.f) { xVector3 NW_aim = MX_LocalToWorld_Get().preTransformV( comBoard.GetActionRotation().preTransformV( xVector3::Create(0.f, -1.1f, 0.f))); NW_aim.z = 0.f; Tracker.P_destination = P_center_Trfm + NW_aim; Tracker.UpdateDestination(); xVector3 NW_dst = Tracker.P_destination - P_center_Trfm; NW_dst.z = 0.f; comBoard.AutoMovement(NW_aim, NW_dst, T_time); MX_LocalToWorld_Set().preMultiply(comBoard.MX_shift); } bool FL_auto_movement_needed = comBoard.AutoAction != ComBoard::AutoHint::HINT_NONE; //////////////////////////////////////////////////////// Update Animation xQuaternion *bones = NULL, *bones2 = NULL; if (LifeEnergy > 0.f) { if (actions.L_actions.size()) { xDWORD delta = (xDWORD)(T_time*1000); actions.Update(delta); bones = actions.GetTransformations(); if (actions.T_progress > 10000) actions.T_progress = 0; } if ((ControlType == Control_ComBoardInput || FL_auto_movement_needed) && comBoard.L_actions.size()) { if (!FL_verlet) { comBoard.Update(T_time * 1000, ControlType == Control_ComBoardInput); MX_LocalToWorld_Set().preMultiply(comBoard.MX_shift); } bones2 = comBoard.GetTransformations(); } else if (ControlType == Control_CaptureInput) bones2 = g_CaptureInput.GetTransformations(); else if (ControlType == Control_NetworkInput) bones2 = g_NetworkInput.GetTransformations(); else { //bones2 = new xQuaternion[ModelGr->instance.I_bones]; //for (int i = 0; i < ModelGr->instance.I_bones; ++i) // bones2[i].zeroQ(); } } if (!bones && bones2) bones = bones2; else if (bones2) { xAnimation::Average(bones2, bones, ModelGr->instance.I_bones, 0.5f, bones); delete[] bones2; } if (bones) if (FL_verlet) xAnimation::Average(bones, QT_verlet, ModelGr->instance.I_bones, verletSystem.W_boneMix, bones); else UpdateSkews(bones); if (bones) { ModelGr->xModelP->Spine.QuatsFromArray(bones); delete[] bones; CalculateSkeleton(); } else { ModelGr->xModelP->Spine.QuatsFromArray(QT_verlet); CalculateSkeleton(); } //////////////////////////////////////////////////////// Update Physical Representation UpdateMatrices(); UpdateVerletSystem(); P_center_Trfm = MX_LocalToWorld_Get().preTransformP(P_center); if (T_time > EPSILON) { xFLOAT T_time_Inv = 1.f / T_time; for (int i = 0; i < I_bones; ++i) NW_VerletVelocity_total[i] = (verletSystem.P_current[i] - verletSystem.P_previous[i]) * T_time_Inv; } else for (int i = 0; i < I_bones; ++i) NW_VerletVelocity_total[i].zero(); for (int i = 0; i < I_bones; ++i) if (NW_VerletVelocity_total[i].isZero()) F_VerletPower[i].zero(); else { xVector3 N_speed = xVector3::Normalize(NW_VerletVelocity_total[i]); xFLOAT W_power = xVector3::DotProduct(F_VerletPower[i], N_speed); F_VerletPower[i] = NW_VerletVelocity_total[i]; if (W_power > 0.f) F_VerletPower[i] += N_speed*W_power; } }
Transformation(const FixVec3& _position, const ei::Quaternion& _rotation) : m_position(_position), m_rotation(_rotation) { UpdateMatrices(); }
void Transform::Update(float dt) { UpdateMatrices(); }
void Rotate( const ei::Quaternion& _rotation ) { m_rotation = _rotation * m_rotation; UpdateMatrices(); }