//----------------------------------------------------------------------------- // Name: D3DXQuaternionAxisToAxis // Desc: Axis to axis quaternion // Takes two points on unit sphere an angle THETA apart, returns // quaternion that represents a rotation around cross product by theta. //----------------------------------------------------------------------------- inline D3DXQUATERNION* WINAPI D3DXQuaternionAxisToAxis ( D3DXQUATERNION *pOut, const D3DXVECTOR3 *pvFrom, const D3DXVECTOR3 *pvTo) { D3DXVECTOR3 vA, vB; D3DXVec3Normalize(&vA, pvFrom); D3DXVec3Normalize(&vB, pvTo); D3DXVECTOR3 vHalf(vA + vB); D3DXVec3Normalize(&vHalf, &vHalf); return D3DXQuaternionUnitAxisToUnitAxis2(pOut, &vA, &vHalf); }
// `创建模型` int CGutParticle::BuildMesh(Matrix4x4 &camera_matrix) { Vector4 vHalf(0.5f); for ( int i=0; i<m_iNumParticles; i++ ) { int base = i*4; float size = m_pParticleArray[i].m_fSize; Vector4 vPos = m_pParticleArray[i].m_vPosition; Vector4 vVec0 = camera_matrix[0] * size; Vector4 vVec1 = camera_matrix[1] * size; Vector4 v0 = vPos - vVec0 * vHalf + vVec1 * vHalf; Vector4 v1 = v0 - vVec1; Vector4 v2 = v0 + vVec0; Vector4 v3 = v0 + vVec0 - vVec1; sParticleVertex *p = m_pVertexArray + base; float fFadeout = m_pParticleArray[i].m_fLife * 5; if ( fFadeout > 1.0f ) fFadeout = 1.0f; int intensity = fFadeout * 255; unsigned int color = intensity<<24 | intensity<<16 | intensity<<8 | intensity; p[0].m_Color = color; p[1].m_Color = color; p[2].m_Color = color; p[3].m_Color = color; v0.StoreXYZ(p[0].m_fPosition); v1.StoreXYZ(p[1].m_fPosition); v2.StoreXYZ(p[2].m_fPosition); v3.StoreXYZ(p[3].m_fPosition); } return m_iNumParticles * 4; }
void GrayScott::step() { // update step ++currStep_; // u and v at the half step std::vector<double> uHalf(Ntot_); std::vector<double> vHalf(Ntot_); // right hand sides for u and for v std::vector<double> uRhs(N_); std::vector<double> vRhs(N_); double uCoeff = Du_*dt_/(2.*dx_*dx_); double vCoeff = Dv_*dt_/(2.*dx_*dx_); /****************** DIFFUSION (ADI) ***************************************/ // perform the first half-step // loop over all rows // j=0 for (int i=0; i<N_; ++i) { uRhs[i] = U(i,0) + uCoeff * (U(i,1) - U(i,0)); vRhs[i] = V(i,0) + vCoeff * (V(i,1) - V(i,0)); } TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UHALF(0,0), 1); TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VHALF(0,0), 1); // inner grid points for (int j=1; j<N_-1; ++j) { // create right-hand side of the systems for (int i=0; i<N_; ++i) { uRhs[i] = U(i,j) + uCoeff * (U(i,j+1) - 2.*U(i,j) + U(i,j-1)); vRhs[i] = V(i,j) + vCoeff * (V(i,j+1) - 2.*V(i,j) + V(i,j-1)); } TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UHALF(0,j), 1); TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VHALF(0,j), 1); } // j=N_-1 for (int i=0; i<N_; ++i) { uRhs[i] = U(i,N_-1) + uCoeff * (- U(i,N_-1) + U(i,N_-2)); vRhs[i] = V(i,N_-1) + vCoeff * (- V(i,N_-1) + V(i,N_-2)); } TriDiagMatrixSolver::solve(N_, matU1_, uRhs, &UHALF(0,N_-1), 1); TriDiagMatrixSolver::solve(N_, matV1_, vRhs, &VHALF(0,N_-1), 1); // perform the second half-step // loop over all columns // i=0 for (int j=0; j<N_; ++j) { uRhs[j] = UHALF(0,j) + uCoeff * (UHALF(1,j) - UHALF(0,j)); vRhs[j] = VHALF(0,j) + vCoeff * (VHALF(1,j) - VHALF(0,j)); } TriDiagMatrixSolver::solve(N_, matU2_, uRhs, &U(0,0), N_); TriDiagMatrixSolver::solve(N_, matV2_, vRhs, &V(0,0), N_); // inner grid points for (int i=1; i<N_-1; ++i) { // create right-hand side of the systems for (int j=0; j<N_; ++j) { uRhs[j] = UHALF(i,j) + uCoeff * (UHALF(i+1,j) - 2.*UHALF(i,j) + UHALF(i-1,j)); vRhs[j] = VHALF(i,j) + vCoeff * (VHALF(i+1,j) - 2.*VHALF(i,j) + VHALF(i-1,j)); } TriDiagMatrixSolver::solve(N_, matU2_, uRhs, &U(i,0), N_); TriDiagMatrixSolver::solve(N_, matV2_, vRhs, &V(i,0), N_); } // i=N_-1 for (int j=0; j<N_; ++j) { uRhs[j] = UHALF(N_-1,j) + uCoeff * (- UHALF(N_-1,j) + UHALF(N_-2,j)); vRhs[j] = VHALF(N_-1,j) + vCoeff * (- VHALF(N_-1,j) + VHALF(N_-2,j)); } TriDiagMatrixSolver::solve(N_, matU2_, uRhs, &U(N_-1,0), N_); TriDiagMatrixSolver::solve(N_, matV2_, vRhs, &V(N_-1,0), N_); /****************** REACTION **********************************************/ double tmp; for (int i=0; i<N_; ++i) { for (int j=0; j<N_; ++j) { tmp = U(i,j); U(i,j) += dt_ * ( -U(i,j)*V(i,j)*V(i,j) + F_*(1.-U(i,j)) ); V(i,j) += dt_ * ( tmp*V(i,j)*V(i,j) - (F_+k_)*V(i,j) ); } } }