12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include <qmath.h>
- #include "qparticle.h"
- float Q_rsqrt( float number )
- {
- long i;
- float x2, y;
- const float threehalfs = 1.5F;
- x2 = number * 0.5F;
- y = number;
- i = * ( long * ) &y; // evil floating point bit level hacking
- i = 0x5f3759df - ( i >> 1 ); // what the fuck?
- y = * ( float * ) &i;
- y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
- // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
- return y;
- }
- QParticle::QParticle(const QVector2D & position, qreal aMass) :
- Force(0.0, 0.0), Position(position)
- {
- setMass(aMass);
- }
- QParticle::QParticle(qreal aMass) :
- Force(0.0, 0.0), Position(0.0, 0.0)
- {
- setMass(aMass);
- }
- void QParticle::setMass(qreal massInKg)
- {
- if (massInKg == 0)
- {
- InvertMass = 0;
- }
- else
- {
- InvertMass = 1.0f / massInKg;
- }
- }
- bool QParticle::zeroVelocity(bool dontNull)
- {
- if(Velocity.isNull())
- {
- return true;
- }
- if((qAbs(Velocity.x()) < KZEROVELOCITY) &&
- (qAbs(Velocity.y()) < KZEROVELOCITY))
- {
- if(!dontNull)
- {
- Velocity.setX(0.0);
- Velocity.setY(0.0);
- }
- return true;
- }
- return false;
- }
- float QParticle::FastVelocityLength() const
- {
- return qSqrt((Velocity.x()*Velocity.x()) + (Velocity.y()*Velocity.y()));
- }
|