00001 00007 #include "Particle.h" 00008 #include "ParticleSystem.h" 00009 00010 Vec3 p_gravity(0.0f, -9.82f, 0.0f); 00011 00012 Particle::Particle() { 00013 m_parent = NULL; 00014 m_age = 0.0f; 00015 m_size = 1.0f; 00016 m_color.x = 1.0f; 00017 m_color.y = 0.0f; 00018 m_color.z = 0.0f; 00019 m_color.w = 0.5f; 00020 } 00021 00022 Particle::~Particle() { 00023 00024 } 00025 00026 bool Particle::update(float dTime) { 00027 if (m_age + dTime >= m_lifetime) { 00028 m_age = -1.0f; 00029 return false; 00030 } 00031 else { 00032 m_age += dTime; 00033 00034 m_prevLocation = m_location; 00035 m_location += m_velocity*dTime; 00036 00037 // some collision detection maby? 00038 00039 m_velocity += p_gravity*m_gravity*dTime; 00040 00041 if (m_parent && m_parent->isAttractive()) { 00042 Vec3 attractLocation; 00043 m_parent->getLocation(attractLocation); 00044 00045 Vec3 attractDir = attractLocation - m_location; 00046 00047 m_velocity += attractDir.normalize()*25.0f*dTime*0.01f; 00048 } 00049 00050 m_color.x += m_dColor.x * dTime; 00051 m_color.y += m_dColor.y * dTime; 00052 m_color.z += m_dColor.z * dTime; 00053 00054 m_alpha += m_dAlpha * dTime; 00055 00056 m_size += m_dSize * dTime; 00057 00058 m_gravity += m_dGravity * dTime; 00059 } 00060 00061 return true; 00062 } 00063 00064 void Particle::setParent(ParticleSystem *parent) { 00065 m_parent = parent; 00066 }