Element(const Vec2 x[3]) { Vec2 e1 = x[1]-x[0]; Vec2 e2 = x[2]-x[0]; Vec2 e3 = x[2]-x[1]; Matrix22 m(e1, e2); float det; mInvDm = Inverse(m, det); assert(det > 0.0f); mB[0] = PerpCCW(e3); mB[1] = PerpCW(e2); mB[2] = PerpCCW(e1); printf("mInvDm:\n"); Print(mInvDm); printf("mB:\n"); printf("%f, %f\n", mB[0].x, mB[0].y); printf("%f, %f\n", mB[1].x, mB[1].y); printf("%f, %f\n", mB[2].x, mB[2].y); }
void EnemyShip::changeVelocity(const float& dt, Engine::ParticleSystem& system) { if (target != nullptr) { Vector2 toTarget = target->getPosition() - shipPosition; if (LengthSquared(toTarget) != 0) { Vector2 normalizedtoTarget = PerpCCW(Normalized(toTarget)); shipRotation = atan2f(normalizedtoTarget.getY(), normalizedtoTarget.getX()); if (LengthSquared(toTarget) >= 0) { velocity = velocity + (Engine::Matrix2::rotation(shipRotation) * Engine::Vector2(0, -(acceleration * dt) * dt)); system.AddParticle(new THRUSTPARTICLEUP); } else { velocity = velocity + (Engine::Matrix2::rotation(shipRotation) * Engine::Vector2(0, (acceleration * dt) * dt)); system.AddParticle(new THRUSTPARTICLEDOWN); } } } }