void Canopy::growHexSegment(treeNode *rootOfTree, BranchBase *pCanopyBranch,aabb TreeBoundingBox, LevelDetail *grammar, V3 startHeading) { theOverseer = observer::Instance(); rootOfTree->tree->m_CanopyCount++; V3 root(rootOfTree->pbranch->segments[0].m_tipPointList[0]); V3 CanopySegmentRoot(pCanopyBranch->tipPoint);// canopySegmentRoot V3 CanopyTop(root); CanopyTop.y = root.y + TreeBoundingBox.yMax; V3 CanopyFulcrum(CanopyTop); CanopyFulcrum.y = CanopyFulcrum.y * 0.57f; // 4/7 if(pCanopyBranch->tipPoint.y < CanopyFulcrum.y){ CanopyFulcrum.y = pCanopyBranch->tipPoint.y * 0.714f;// 5/7 } V3 CanopyHeading = CanopySegmentRoot-CanopyFulcrum; CanopyHeading.Normalize(); V3 CanopyArbitrary(CanopySegmentRoot-root); CanopyArbitrary.Normalize(); V3 Left = CrossProduct(CanopyArbitrary,CanopyHeading); V3 Right = CrossProduct(CanopyHeading,CanopyArbitrary); Left.Normalize(); Right.Normalize(); V3 Down = CrossProduct(Left,CanopyHeading); V3 Up = CrossProduct(CanopyHeading,Left); V3 perturb = CanopyHeading; Down.Normalize(); Up.Normalize(); int shift = -((int)floor(m_width/2.0f)); float nudge =0.0f; growPatchSegment(rootOfTree, pCanopyBranch,TreeBoundingBox, grammar,startHeading); }
void FireBall::initParticle(ParticleEmitter::Particle& out) { // Time particle is created relative to the global running // time of the particle system. out.initialTime = mTime; out.age=mTime; // Flare lives for 2-4 seconds. // original values //out.lifeTime = GetRandomFloat(2.0f, 8.0f); out.lifeTime = GetRandomFloat(mMinLifeTime, mMaxLifeTime); // Initial size in pixels. // original values //out.initialSize = GetRandomFloat(10.0f, 15.0f); out.initialSize = GetRandomFloat(mMinSize, mMaxSize); // Give a very small initial velocity to give the flares // some randomness. GetRandomVec(out.initialVelocity); out.initialVelocity.x *= mAccelImpulse.x; out.initialVelocity.y *= mAccelImpulse.y; out.initialVelocity.z *= mAccelImpulse.z; out.initialVelocity.x += mAccelShift.x; out.initialVelocity.y += mAccelShift.y; out.initialVelocity.z += mAccelShift.z; // Scalar value used in vertex shader as an amplitude factor. out.mass = GetRandomFloat(1.0f, 2.0f); // Start color at 50-100% intensity when born for variation. out.initialColor = static_cast<DWORD>(GetRandomFloat(0.5f, 1.0f) * 1.0f);//white; V3 temp = mParticleRadius - mInitPos; float length = temp.Length(); V3 tempNormal = temp.Normalize(); //D3DXMATRIX outmtx; noMat3 outmtx; //D3DXMatrixRotationYawPitchRoll(&outmtx,GetRandomFloat(0.0f,2.0f)*noMath::PI,GetRandomFloat(0.0f,2.0f)*noMath::PI,0.0f); noAngles angle(RAD2DEG(GetRandomFloat(0.0f,2.0f)*noMath::PI), RAD2DEG(GetRandomFloat(0.0f,2.0f)*noMath::PI), 0.0f); outmtx = angle.ToMat3(); //D3DXVec3TransformCoord(&temp,&temp,&outmtx); temp = outmtx * temp; out.initialPos = mInitPos + (temp * length); }
// The patch segment is an array of points that will be used as a canopy patch at the end of a branch or where // a canopy is defined. To create the patch we need to know what the drop angle will be. This is calculated based on the established // grammar drop angle along with the fulcrum calculation for the tree. The patch will not be flat but will be perturbed from the plane in // a random way based on a given weight factor for perturbation. void Canopy::growPatchSegment(treeNode *rootOfTree, BranchBase *pCanopyBranch,aabb TreeBoundingBox, LevelDetail *grammar, V3 startHeading) { theOverseer = observer::Instance(); //int cwidth =9; //int cheight =9; //float m_widthStep =1; //float m_heightStep =1.25; rootOfTree->tree->m_CanopyCount++; V3 root(rootOfTree->pbranch->segments[0].m_tipPointList[0]); V3 CanopySegmentRoot(pCanopyBranch->tipPoint);// canopySegmentRoot V3 CanopyTop(root); CanopyTop.y = root.y + TreeBoundingBox.yMax; V3 CanopyFulcrum(CanopyTop); CanopyFulcrum.y = CanopyFulcrum.y * 0.57f; // 4/7 if(pCanopyBranch->tipPoint.y < CanopyFulcrum.y){ CanopyFulcrum.y = pCanopyBranch->tipPoint.y * 0.714f;// 5/7 } V3 CanopyHeading = CanopySegmentRoot-CanopyFulcrum; CanopyHeading.Normalize(); V3 CanopyArbitrary(CanopySegmentRoot-root); CanopyArbitrary.Normalize(); V3 Left = CrossProduct(CanopyArbitrary,CanopyHeading); V3 Right = CrossProduct(CanopyHeading,CanopyArbitrary); Left.Normalize(); Right.Normalize(); V3 Down = CrossProduct(Left,CanopyHeading); V3 Up = CrossProduct(CanopyHeading,Left); float perturbFactor = grammar->perturbFactor; V3 perturb = CanopyHeading; Down.Normalize(); Up.Normalize(); Basis.iAxis = Right * (((float)m_width)/2) * m_widthStep; Basis.jAxis = CanopyHeading; Basis.kAxis = Down * (((float)m_height)/2) * m_heightStep; int shift = -((int)floor(m_width/2.0f)); float nudge =0.0f; for(int j=0;j<m_height;j++){ for(int i=0;i<m_width;i++){ nudge = theOverseer->randf(-(perturbFactor),(perturbFactor)); perturb = perturb * nudge; V3 tcb = pCanopyBranch->tipPoint + ((i+shift)*m_widthStep)* Left + (j*m_heightStep)*Down; V3 *cb; if(!(j==0&&i==(m_width/2))){ tcb = tcb + perturb; cb = new V3(tcb); }else{ cb = new V3(tcb); } m_Canopy.push_back(cb); perturb = CanopyHeading; } } theOverseer = observer::Instance(); m_startIndex = theOverseer->DXRS->CurrentIndex; m_startVertex = theOverseer->DXRS->CurrentVIndex; m_AABB = setAABB(); theOverseer->DXRS->CurrentIndex = theOverseer->DXRS->CurrentIndex + ((m_height-1)*(m_width-1)*12); // 6 per quad per side = 12 theOverseer->DXRS->CurrentVIndex = theOverseer->DXRS->CurrentVIndex + ( m_height*m_width*2); // two sides = 2 m_burning = false; }