Vector2 Gravity::forceDelta(const PhysicsEntity* e, float) const
{
- return Vector2(0, e->mass * forceGravity);
+ return Vector2(0, e->m_mass * forceGravity);
}
Vector2 GravityWell::forceDelta(const PhysicsEntity* e, float) const
{
const Vector2& pos = e->positionRaw();
- float mass = e->mass;
+ float mass = e->m_mass;
Vector2 delta = position - pos;
float sqrDist = delta.sqrLength();
Vector2 acc(0,0);
- float CoR = e->CoR;
+ float CoR = e->m_CoR;
float radius = 0;
const Ball* b = dynamic_cast<const Ball*>(e);
if( b != NULL )
/// ***** Constructors/Destructors *****
Ball::Ball(const Vector2& pos, float radius, const float* color)
- : PhysicsEntity(pos), radius(radius), color(color)
+ : PhysicsEntity(pos), m_radius(radius), m_color(color)
{
}
void Ball::draw() const
{
- graphics::drawCircle(radius, position, color);
+ graphics::drawCircle(m_radius, position, m_color);
}
float Ball::getRadius() const
{
- return radius;
+ return m_radius;
}
float getRadius() const;
//protected:
- float radius;
- const float* color;
+ float m_radius;
+ const float* m_color;
};
#endif // BALL_H
/// ***** Constructors/Destructors *****
Line::Line(const Vector2& org, const Vector2& dest, bool canDie)
- : Particle(org, canDie), dest(dest)
+ : Particle(org, canDie), m_dest(dest)
{
}
Line::Line(const Vector2& org, const Vector2& dest, float life_time)
- : Particle(org, life_time), dest(dest)
+ : Particle(org, life_time), m_dest(dest)
{
}
class Line: public Particle
{
public:
- Line(const Vector2&, const Vector2&, bool=true);
- Line(const Vector2&, const Vector2&, float);
+ Line(const Vector2& org, const Vector2& dest, bool canDie=true);
+ Line(const Vector2& org, const Vector2& dest, float life_time);
virtual ~Line();
virtual void draw();
protected:
- Vector2 dest;
+ Vector2 m_dest;
// triangle stuffs
// color
/// ***** Constructors/Destructors *****
Particle::Particle(const Vector2& pos, bool canDie)
- : Entity(pos), canDie(canDie)
+ : Entity(pos), m_canDie(canDie)
{
}
Particle::Particle(const Vector2& pos, float lifeTime)
- : Entity(pos), lifeTime(lifeTime)
+ : Entity(pos), m_lifeTime(lifeTime)
{
}
void Particle::update(float time_step)
{
- if(isDead)
+ if(m_isDead)
return;
- if (canDie)
+ if (m_canDie)
{
- lifeTime -= time_step;
- isDead = lifeTime <= 0;
+ m_lifeTime -= time_step;
+ m_isDead = m_lifeTime <= 0;
}
position += velocity * time_step;
}
virtual void update(float);
protected:
- float lifeTime;
+ float m_lifeTime;
- bool isDead;
- bool canDie;
+ bool m_isDead;
+ bool m_canDie;
};
#endif // PARTICLE_H
/// ***** Constructors/Destructors *****
PhysicsEntity::PhysicsEntity(const Vector2& pos)
- : Entity(pos), force(0,0), mass(1), CoR(0.8)
+ : Entity(pos), m_force(0,0), m_mass(1), m_CoR(0.8)
{
}
position = positionAt(time_step);
velocity = velocityAt(time_step);
- force *= 0;
+ m_force *= 0;
}
Vector2 PhysicsEntity::positionAt(float time_step) const
{
Vector2 newPosition = position;
Vector2 newVelocity = velocity;
- Vector2 newForce = force;
+ Vector2 newForce = m_force;
newPosition += effect::positionDelta(this, time_step);
newVelocity += effect::velocityDelta(this, time_step);
newForce += effect::forceDelta(this, time_step);
- return newForce/mass / 2 * time_step * time_step + newVelocity * time_step + newPosition;
+ return newForce/m_mass / 2 * time_step * time_step + newVelocity * time_step + newPosition;
}
Vector2 PhysicsEntity::velocityAt(float time_step) const
{
- Vector2 newForce = force;
+ Vector2 newForce = m_force;
Vector2 newVelocity = velocity;
newForce += effect::forceDelta(this, time_step);
newVelocity += effect::velocityDelta(this, time_step);
- return newForce/mass / 2 * time_step + newVelocity;
+ return newForce/m_mass / 2 * time_step + newVelocity;
}
void PhysicsEntity::applyForce(const Vector2& force)
}
void PhysicsEntity::applyForce(const Vector2& force, const Vector2& /*at*/)
{
- this->force += force;
+ this->m_force += force;
}
void PhysicsEntity::applyImpulse(const Vector2& impulse)
virtual void applyNudge(const Vector2& vecPush);
//protected:
- Vector2 force;
+ Vector2 m_force;
- float mass;
+ float m_mass;
// Coefficient of Restitution
- float CoR;
+ float m_CoR;
};
#endif // PHYSICS_H
/// ***** Constructors/Destructors *****
Polygon::Polygon(const vector<Vector2>& points, const float* color)
- : PhysicsEntity(Vector2(0,0)), points(points), color(color)
+ : PhysicsEntity(Vector2(0,0)), m_points(points), m_color(color)
{
DASSERT(0 < points.size());
void Polygon::draw() const
{
- graphics::drawPolygon(points, color);
+ graphics::drawPolygon(m_points, m_color);
}
/// ***** Private Class Methods *****
void Polygon::createBindingBox()
{
- DASSERT(0 < points.size());
+ DASSERT(0 < m_points.size());
- maxP = points.at(0);
- minP = points.at(0);
+ m_maxP = m_points.at(0);
+ m_minP = m_points.at(0);
- for(unsigned int i=1; i<points.size(); i++)
+ for(unsigned int i=1; i<m_points.size(); i++)
{
- if(points[i].m_fX < minP.m_fX) minP.m_fX = points[i].m_fX;
- else if(points[i].m_fX > maxP.m_fX) maxP.m_fX = points[i].m_fX;
+ if(m_points[i].m_fX < m_minP.m_fX) m_minP.m_fX = m_points[i].m_fX;
+ else if(m_points[i].m_fX > m_maxP.m_fX) m_maxP.m_fX = m_points[i].m_fX;
- if(points[i].m_fY < minP.m_fY) minP.m_fY = points[i].m_fY;
- else if(points[i].m_fY > maxP.m_fY) maxP.m_fY = points[i].m_fY;
+ if(m_points[i].m_fY < m_minP.m_fY) m_minP.m_fY = m_points[i].m_fY;
+ else if(m_points[i].m_fY > m_maxP.m_fY) m_maxP.m_fY = m_points[i].m_fY;
}
}
virtual void draw() const;
//protected:
- Vector2 maxP; // stores the max bounding box point
- Vector2 minP; // stores the min bounding box point
+ Vector2 m_maxP; // stores the max bounding box point
+ Vector2 m_minP; // stores the min bounding box point
- vector<Vector2> points;
+ vector<Vector2> m_points;
- const float* color;
+ const float* m_color;
+
private:
void createBindingBox();
void centerPosition();
{
const float& xb = pBall->positionRaw().m_fX;
const float& yb = pBall->positionRaw().m_fY;
- const float& rad = pBall->radius;
+ const float& rad = pBall->m_radius;
vecMin.m_fX = xb - rad;
vecMin.m_fY = yb - rad;
if( pPoly != NULL )
{
- vecMin = pPoly->minP;
- vecMax = pPoly->maxP;
+ vecMin = pPoly->m_minP;
+ vecMax = pPoly->m_maxP;
goto start;
}
const Vector2& vecNormal = cInfo.m_vecNormal;
const Vector2& vecPoint = cInfo.m_vecPoint;
- float m1 = pb1->mass;
- float m2 = pb2->mass;
+ float m1 = pb1->m_mass;
+ float m2 = pb2->m_mass;
- float e = (pb1->CoR + pb2->CoR) / 2;
+ float e = (pb1->m_CoR + pb2->m_CoR) / 2;
Vector2 v1 = pb1->velocityRaw();
Vector2 v2 = pb2->velocityRaw();
// a few values to simplify the equations
const Vector2& vecNorm = cInfo.m_vecNormal;
- float fCoR = pBall->CoR;
+ float fCoR = pBall->m_CoR;
Vector2 vecVelo = pBall->velocityRaw();
// impulse divided by mass
// CoR penetration fix, adds the polygon-ball jitters
// from center to point
- Vector2 vecCollP = vecNorm / vecNorm.length() * pBall->radius;
+ Vector2 vecCollP = vecNorm / vecNorm.length() * pBall->m_radius;
pBall->applyNudge(cInfo.m_vecPoint + vecCollP - pBall->positionRaw());
}
bool getInfo(const Ball* pb1, const Ball* pb2, CollisionInfo* pcInfo)
{
// a few values to simplify the equations
- float r1 = pb1->radius;
- float r2 = pb2->radius;
+ float r1 = pb1->m_radius;
+ float r2 = pb2->m_radius;
Vector2 p1 = pb1->positionRaw();
Vector2 p2 = pb2->positionRaw();
bool getInfo(const Polygon* pPoly, const Ball* pBall, CollisionInfo* pcInfo)
{
// a few values to simplify the equations
- float fRad = pBall->radius;
+ float fRad = pBall->m_radius;
Vector2 vecPos = pBall->positionRaw();
Vector2 vecVelo = pBall->velocityRaw();
- float fMaxX = pPoly->maxP.m_fX;
- float fMinX = pPoly->minP.m_fX;
- float fMaxY = pPoly->maxP.m_fY;
- float fMinY = pPoly->minP.m_fY;
+ float fMaxX = pPoly->m_maxP.m_fX;
+ float fMinX = pPoly->m_minP.m_fX;
+ float fMaxY = pPoly->m_maxP.m_fY;
+ float fMinY = pPoly->m_minP.m_fY;
// quick binding box check
if (vecPos.m_fX - fRad > fMaxX || vecPos.m_fX + fRad < fMinX ||
int iTot = 0;
{
- const vector<Vector2>& pts = pPoly->points;
+ const vector<Vector2>& pts = pPoly->m_points;
unsigned int num = pts.size();
for (unsigned int i = 0; i < num; i++)
s_startPolys.init();
pBall = addBall(Vector2(50, 50), 20, cWhite, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
pBall = addBall(Vector2(150, 50), 20, cGrey, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
pBall = addBall(Vector2(50, 100), 20, cRed, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
pBall = addBall(Vector2(100, 100), 20, cGreen, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
pBall = addBall(Vector2(150, 100), 20, cBlue, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
pBall = addBall(Vector2(50, 150), 20, cYellow, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
pBall = addBall(Vector2(100, 150), 20, cMagenta, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
pBall = addBall(Vector2(150, 150), 20, cCyan, s_startBalls);
- pBall->mass = fStartMass;
+ pBall->m_mass = fStartMass;
for( int i = 0; i < 50; i++)