@@ -339,11 +339,45 @@ void PhysicsManager::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
339339 b2Fixture* fixtureMapSolidBlock = FilterFixture (fixtureA, fixtureB, PHYSICS_OBJCAT_MAP_SOLID_BLOCK);
340340 b2Fixture* fixturePed = FilterFixture (fixtureA, fixtureB, PHYSICS_OBJCAT_PED);
341341 b2Fixture* fixtureCar = FilterFixture (fixtureA, fixtureB, PHYSICS_OBJCAT_CAR);
342+ b2Fixture* fixtureProjectile = FilterFixture (fixtureA, fixtureB, PHYSICS_OBJCAT_PROJECTILE);
342343
343- if (fixturePed)
344+ if (fixtureProjectile)
345+ {
346+ hasCollision = false ; // projectiles doesnt collide
347+
348+ ProjectilePhysicsBody* projectileObject = CastBodyData<ProjectilePhysicsBody>(fixtureProjectile->GetBody ());
349+
350+ // projectile vs map solid block
351+ if (fixtureMapSolidBlock)
352+ {
353+ b2FixtureData_map fxdata = fixtureMapSolidBlock->GetUserData ();
354+ if (projectileObject->ShouldContactWith (PHYSICS_OBJCAT_MAP_SOLID_BLOCK))
355+ {
356+ ProcessProjectileVsMap (contact, projectileObject, fxdata.mX , fxdata.mZ );
357+ }
358+ }
359+ // projectile vs car
360+ else if (fixtureCar)
361+ {
362+ CarPhysicsBody* carPhysicsObject = CastBodyData<CarPhysicsBody>(fixtureCar->GetBody ());
363+ if (projectileObject->ShouldContactWith (PHYSICS_OBJCAT_CAR))
364+ {
365+ ProcessProjectileVsCar (contact, projectileObject, carPhysicsObject);
366+ }
367+ }
368+ // projectile vs ped
369+ else if (fixturePed)
370+ {
371+ PedPhysicsBody* pedPhysicsObject = CastBodyData<PedPhysicsBody>(fixturePed->GetBody ());
372+ if (projectileObject->ShouldContactWith (PHYSICS_OBJCAT_PED))
373+ {
374+ ProcessProjectileVsPed (contact, projectileObject, pedPhysicsObject);
375+ }
376+ }
377+ }
378+ else if (fixturePed)
344379 {
345380 PedPhysicsBody* pedPhysicsObject = CastBodyData<PedPhysicsBody>(fixturePed->GetBody ());
346- debug_assert (pedPhysicsObject);
347381
348382 // ped vs map solid block
349383 if (fixtureMapSolidBlock)
@@ -570,7 +604,6 @@ bool PhysicsManager::ProcessSensorContact(b2Contact* contact, bool onBegin)
570604
571605 b2Fixture* pedFixture = FilterFixture (contact->GetFixtureA (), contact->GetFixtureB (), PHYSICS_OBJCAT_PED | PHYSICS_OBJCAT_PED_SENSOR);
572606 b2Fixture* carFixture = FilterFixture (contact->GetFixtureA (), contact->GetFixtureB (), PHYSICS_OBJCAT_CAR);
573- b2Fixture* projectileFixture = FilterFixture (contact->GetFixtureA (), contact->GetFixtureB (), PHYSICS_OBJCAT_PROJECTILE_SENSOR);
574607 b2Fixture* mapSolidBlockFixture = FilterFixture (contact->GetFixtureA (), contact->GetFixtureB (), PHYSICS_OBJCAT_MAP_SOLID_BLOCK);
575608 if (pedFixture && carFixture)
576609 {
@@ -586,31 +619,6 @@ bool PhysicsManager::ProcessSensorContact(b2Contact* contact, bool onBegin)
586619 }
587620 return true ;
588621 }
589-
590- if (projectileFixture)
591- {
592- ProjectilePhysicsBody* projectileObject = CastBodyData<ProjectilePhysicsBody>(projectileFixture->GetBody ());
593- if (projectileObject->mReferenceProjectile ->mDead )
594- return false ;
595-
596- if (pedFixture)
597- {
598- PedPhysicsBody* pedObject = CastBodyData<PedPhysicsBody>(pedFixture->GetBody ());
599- return ProcessSensorProjectileVsPed (contact, projectileObject, pedObject);
600- }
601-
602- if (carFixture)
603- {
604- CarPhysicsBody* carObject = CastBodyData<CarPhysicsBody>(carFixture->GetBody ());
605- return ProcessSensorProjectileVsCar (contact, projectileObject, carObject);
606- }
607-
608- if (mapSolidBlockFixture)
609- {
610- b2FixtureData_map fxdata = mapSolidBlockFixture->GetUserData ();
611- return ProcessSensorProjectileVsMap (contact, projectileObject, fxdata.mX , fxdata.mZ );
612- }
613- }
614622 return false ;
615623}
616624
@@ -714,29 +722,82 @@ void PhysicsManager::HandleContactPedVsCar(b2Contact* contact, float impulse, Pe
714722 ped->mReferencePed ->ReceiveHitByCar (car->mReferenceCar , impulse);
715723}
716724
717- bool PhysicsManager::ProcessSensorProjectileVsMap (b2Contact* contact, ProjectilePhysicsBody* projectile, int mapx, int mapy) const
725+ bool PhysicsManager::ProcessProjectileVsMap (b2Contact* contact, ProjectilePhysicsBody* projectile, int mapx, int mapy) const
718726{
719727 // check same height
728+ int layer = (int ) (Convert::MetersToMapUnits (projectile->mHeight ) + 0 .5f );
729+
730+ BlockStyle* mapBlock = gGameMap .GetBlockClamp (mapx, mapy, layer);
731+ if (mapBlock->mGroundType != eGroundType_Building)
732+ return false ;
733+
734+ // get collision point
735+ b2WorldManifold wmanifold;
736+ contact->GetWorldManifold (&wmanifold);
720737
738+ int pointsCount = contact->GetManifold ()->pointCount ;
739+ if (pointsCount > 0 )
740+ {
741+ glm::vec3 contactPoint (
742+ wmanifold.points [0 ].x , projectile->mHeight ,
743+ wmanifold.points [0 ].y );
721744
745+ projectile->mReferenceProjectile ->SetContactDetected (contactPoint, nullptr );
746+ return true ;
747+ }
722748 return false ;
723749}
724750
725- bool PhysicsManager::ProcessSensorProjectileVsCar (b2Contact* contact, ProjectilePhysicsBody* projectile, CarPhysicsBody* car) const
751+ bool PhysicsManager::ProcessProjectileVsCar (b2Contact* contact, ProjectilePhysicsBody* projectile, CarPhysicsBody* car) const
726752{
753+ // check car bounds height
754+ // todo: get car height!
755+ bool hasContact = ((projectile->mHeight >= car->mHeight ) &&
756+ (projectile->mHeight <= (car->mHeight + 2 .0f )));
727757
758+ if (!hasContact)
759+ return false ;
728760
729- // check same height
761+ // get collision point
762+ b2WorldManifold wmanifold;
763+ contact->GetWorldManifold (&wmanifold);
730764
765+ int pointsCount = contact->GetManifold ()->pointCount ;
766+ if (pointsCount > 0 )
767+ {
768+ glm::vec3 contactPoint (
769+ wmanifold.points [0 ].x , projectile->mHeight ,
770+ wmanifold.points [0 ].y );
771+
772+ projectile->mReferenceProjectile ->SetContactDetected (contactPoint, car->mReferenceCar );
773+ return true ;
774+ }
731775 return false ;
732776}
733777
734- bool PhysicsManager::ProcessSensorProjectileVsPed (b2Contact* contact, ProjectilePhysicsBody* projectile, PedPhysicsBody* ped) const
778+ bool PhysicsManager::ProcessProjectileVsPed (b2Contact* contact, ProjectilePhysicsBody* projectile, PedPhysicsBody* ped) const
735779{
736- if (!ped->ShouldContactWith (PHYSICS_OBJCAT_PROJECTILE_SENSOR))
780+ // check ped bounds height
781+ // todo: get car height!
782+ bool hasContact = ((projectile->mHeight >= ped->mHeight ) &&
783+ (projectile->mHeight <= (ped->mHeight + 2 .0f )));
784+
785+ if (!hasContact)
737786 return false ;
738787
739- // check same height
788+ // get collision point
789+ b2WorldManifold wmanifold;
790+ contact->GetWorldManifold (&wmanifold);
791+
792+ int pointsCount = contact->GetManifold ()->pointCount ;
793+ if (pointsCount > 0 )
794+ {
795+ glm::vec3 contactPoint (
796+ wmanifold.points [0 ].x , projectile->mHeight ,
797+ wmanifold.points [0 ].y );
740798
799+ projectile->mReferenceProjectile ->SetContactDetected (contactPoint, ped->mReferencePed );
800+ return true ;
801+ }
741802 return false ;
742803}
0 commit comments