void NNParticle::Update( float dTime ) { m_NowLifeTime += dTime; m_Speed = m_StartSpeed + (m_EndSpeed-m_StartSpeed)*(m_NowLifeTime/m_LifeTime); m_RotationSpeed = m_StartRotationSpeed + (m_EndRotationSpeed-m_StartRotationSpeed)*(m_NowLifeTime/m_LifeTime); m_Position = m_Position + NNPoint( cos(NNDegreeToRadian(m_Direction)), sin(NNDegreeToRadian(m_Direction)) ) * m_Speed * dTime; m_Rotation += m_RotationSpeed * dTime; m_ScaleX = (m_StartScaleX + (m_EndScaleX-m_StartScaleX)*(m_NowLifeTime/m_LifeTime)); m_ScaleY = (m_StartScaleY + (m_EndScaleY-m_StartScaleY)*(m_NowLifeTime/m_LifeTime)); m_Color = (m_StartColor + (m_EndColor-m_StartColor)*(m_NowLifeTime/m_LifeTime)); }
void NNParticleSystem::CreateParticle() { NNParticle* pInstance = NNParticle::Create( mTexturePath ); pInstance->SetParentMatrix( this->mMatrix ); float tempDirection = NNDegreeToRadian(NNRandom::NextFloat(mDirection-mSpreadDegree/2.f,mDirection+mSpreadDegree/2.f)); pInstance->SetPosition( NNRandom::NextFloat(mMinStartRadiusX, mMaxStartRadiusX)*cos(tempDirection), NNRandom::NextFloat(mMinStartRadiusX, mMaxStartRadiusX)*sin(tempDirection) ); pInstance->SetStartSpeed( NNRandom::NextFloat(mMinStartSpeed, mMaxStartSpeed) ); pInstance->SetEndSpeed( NNRandom::NextFloat(mMinEndSpeed, mMaxEndSpeed) ); pInstance->SetStartScaleX( NNRandom::NextFloat(mMinStartScaleX, mMaxStartScaleX) ); pInstance->SetStartScaleY( NNRandom::NextFloat(mMinStartScaleY, mMaxStartScaleY) ); pInstance->SetEndScaleX( NNRandom::NextFloat(mMinEndScaleX, mMaxEndScaleX) ); pInstance->SetEndScaleY( NNRandom::NextFloat(mMinEndScaleY, mMaxEndScaleY) ); pInstance->SetStartRotationSpeed( NNRandom::NextFloat(mMinStartRotationSpeed, mMaxStartRotationSpeed) ); pInstance->SetEndRotationSpeed( NNRandom::NextFloat(mMinEndRotationSpeed, mMaxEndRotationSpeed) ); pInstance->SetDirection( NNRandom::NextFloat(mDirection-mSpreadDegree/2.f, mDirection+mSpreadDegree/2.f) ); pInstance->SetLifeTime( NNRandom::NextFloat(mMinLifeTime, mMaxLifeTime) ); pInstance->SetStartRGBA( NNRandom::NextInt(mMinStartColor.GetRed(), mMaxStartColor.GetRed()), NNRandom::NextInt(mMinStartColor.GetGreen(), mMaxStartColor.GetGreen()), NNRandom::NextInt(mMinStartColor.GetBlue(), mMaxStartColor.GetBlue()), NNRandom::NextInt(mMinStartColor.GetAlpha(), mMaxStartColor.GetAlpha()) ); pInstance->SetEndRGBA( NNRandom::NextInt(mMinEndColor.GetRed(), mMaxEndColor.GetRed()), NNRandom::NextInt(mMinEndColor.GetGreen(), mMaxEndColor.GetGreen()), NNRandom::NextInt(mMinEndColor.GetBlue(), mMaxEndColor.GetBlue()), NNRandom::NextInt(mMinEndColor.GetAlpha(), mMaxEndColor.GetAlpha()) ); mParticleList.push_back( pInstance ); }