void PhysicalObj::ContactPointAngleOnGround(const Point2d& oldPos, Point2d& contactPos, Double& contactAngle) const { // Find the contact point and collision angle. // !!! ContactPoint(...) _can_ return false when CollisionTest(...) is true !!! // !!! WeaponProjectiles collide on objects, so computing the tangeante to the ground leads // !!! uninitialised values of cx and cy!! // if( ContactPoint(cx, cy) ){ int cx, cy; if (ContactPoint(cx, cy)) { contactAngle = GetWorld().ground.Tangent(cx, cy); if (!isNaN(contactAngle)) { contactPos.x = (Double)cx * METER_PER_PIXEL; contactPos.y = (Double)cy * METER_PER_PIXEL; } else { contactAngle = - GetSpeedAngle(); contactPos = oldPos; } } else { contactAngle = - GetSpeedAngle(); contactPos = oldPos; } }
void PhysicsSimulation::updateContacts() { PerformanceTimer perfTimer("contacts"); int numCollisions = _collisions.size(); for (int i = 0; i < numCollisions; ++i) { CollisionInfo* collision = _collisions.getCollision(i); quint64 key = collision->getShapePairKey(); if (key == 0) { continue; } QMap<quint64, ContactPoint>::iterator itr = _contacts.find(key); if (itr == _contacts.end()) { _contacts.insert(key, ContactPoint(*collision, _frameCount)); } else { itr.value().updateContact(*collision, _frameCount); } } }