void CView::ProcessShakeSmooth_DoShaking( SShake* pShake, float frameTime) { if (pShake->nextShake <= 0.0f) { pShake->nextShake = pShake->frequency; pShake->startShake = pShake->goalShake; pShake->startShakeSpeed = pShake->goalShakeSpeed; pShake->startShakeVector = pShake->goalShakeVector; pShake->startShakeVectorSpeed = pShake->goalShakeVectorSpeed; GetRandomQuat(pShake->goalShake, pShake); GetRandomQuat(pShake->goalShakeSpeed, pShake); GetRandomVector(pShake->goalShakeVector, pShake); GetRandomVector(pShake->goalShakeVectorSpeed, pShake); if (pShake->flip) { pShake->goalShake.Invert(); pShake->goalShakeSpeed.Invert(); pShake->goalShakeVector = -pShake->goalShakeVector; pShake->goalShakeVectorSpeed = -pShake->goalShakeVectorSpeed; } if (pShake->doFlip) pShake->flip = !pShake->flip; } pShake->nextShake -= frameTime; float t = (pShake->frequency - pShake->nextShake) / pShake->frequency; CubeInterpolateQuat(t, pShake); CubeInterpolateVector(t, pShake); }
/* 1. 将粒子复活并将其置入粒子源处 2. 获取任意方向,大小在规定范围内的速度,并将其规范化,以便绘制出球形区域 3. 设置粒子的颜色为随机颜色 4. 设置粒子的生命周期为2s */ void FIRE::reset_particle(ATTRIBUTE *attribute) { attribute->_alive = true; attribute->_position = _origin; D3DXVECTOR3 min = D3DXVECTOR3(-1.0f, -1.0f, -1.0f); D3DXVECTOR3 max = D3DXVECTOR3( 1.0f, 1.0f, 1.0f); //获取任意方向的速度 GetRandomVector( &attribute->_velocity, &min, &max); //将速度规范化才能绘制出球形 D3DXVec3Normalize( &attribute->_velocity, &attribute->_velocity); attribute->_velocity *= 100.0f; //将粒子设置为一个随机的颜色 attribute->_color = D3DXCOLOR( GetRandomFloat(0.0f, 1.0f), GetRandomFloat(0.0f, 1.0f), GetRandomFloat(0.0f, 1.0f), 1.0f); attribute->_age = 0.0f; attribute->_life_time = 2.0f; // lives for 2 seconds }
//本函数没错 //设置粒子属性 P245 //在指定的外界体内创建了具有随机xz坐标的雪花粒子,并将粒子的y坐标设为 //外接体高度值,赋予雪花一定向左下飘的速度 void SNOW::reset_particle(ATTRIBUTE *attribute) { attribute->_alive = true; GetRandomVector(&attribute->_position, //设置雪花飘落的速度大小以及方向 &_box._min, &_box._max); attribute->_position.y = _box._max.y; attribute->_velocity.x = GetRandomFloat(0.0f,1.0f) * (-3.0f); attribute->_velocity.y = GetRandomFloat(0.0f,1.0f) * (-10.0f); attribute->_velocity.z = 0.0f; attribute->_color = WHITE; //设定雪花的颜色(实际上雪花的颜色是纹理的颜色) }
void Balls::ResetParticle(Particle* particle, D3DXVECTOR3* pos) { particle->isLive = true ; particle->age = 0.0f ; particle->lifeTime = 5.0f ; /*GetRandomFloat(0.1f, 1.0f) ;*/ particle->position = *pos ; D3DXVECTOR3 min = D3DXVECTOR3(-1.0f, -1.0f, -1.0f); D3DXVECTOR3 max = D3DXVECTOR3( 1.0f, 1.0f, 1.0f); GetRandomVector(&particle->velocity, &min, &max); // normalize to make spherical D3DXVec3Normalize(&particle->velocity, &particle->velocity); particle->velocity.z = 0.0f; // Normalize gravity D3DXVec3Normalize(&particle->gravity, &particle->gravity); }
//初始化粒子 void SnowParticle::ResetParticle(Particle* particle) { particle->age = 0.0f; particle->isLive = true; particle->lifeTime = GetRandomFloat(2.0f, 10.0f); particle->color = D3DCOLOR_RGBA(rand() % 255, rand() % 255, rand() % 255, rand() % 255); particle->colorFade = D3DXCOLOR(D3DCOLOR_RGBA(0, 0, 0, 0)); D3DXVECTOR3 minVec(0, 50, 0); D3DXVECTOR3 maxVec(50, 70, 50); D3DXVECTOR3 pos; GetRandomVector(&pos, &minVec, &maxVec); particle->position = pos; particle->initVelocity = D3DXVECTOR3(GetRandomFloat(0, 1.0f), GetRandomFloat(-1.0f, 0.0f), GetRandomFloat(0.0f, 1.0f)); particle->velocity = D3DXVECTOR3(GetRandomFloat(-1.0f, 1.0f), GetRandomFloat(-1.0f, 0.0f), GetRandomFloat(-1.0f, 1.0f)); }