working on collision detection when entities get warped at world boundaries
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "PhysicsBase.h"
|
||||
#include "ModelBase.h"
|
||||
#include "EntityBase.h"
|
||||
#include "coll2d.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Engine;
|
||||
@@ -64,3 +65,54 @@ TEST_FIXTURE ( PhysicsFixture, PhysicsModuleActorActorCollision ) {
|
||||
|
||||
PhysicsModule.UnregisterEntity (actor_2_entity->mId);
|
||||
}
|
||||
|
||||
TEST_FIXTURE (PhysicsFixture, PhysicsTestWarpCollisionX ) {
|
||||
float world_size = 10;
|
||||
PhysicsModule.SetWorldBounds (
|
||||
vector3d (-world_size, -world_size, -world_size),
|
||||
vector3d (world_size, world_size, world_size)
|
||||
);
|
||||
|
||||
EntityPhysicState* actor_2_entity = CreateEntityPhysicState (EntityBaseTypeActor, 4);
|
||||
assert (actor_2_entity->mShape);
|
||||
assert (actor_entity->mShape);
|
||||
|
||||
PhysicsModule.RegisterEntity (actor_2_entity);
|
||||
|
||||
float actor_radius = dynamic_cast<coll2d::Sphere*>(actor_entity->mShape)->getRadius();
|
||||
// actor_entity->mPosition = vector3d (-world_size + actor_radius + 0.01 + 2 * world_size, 0., world_size - actor_radius);
|
||||
actor_entity->mPosition = vector3d (-world_size + actor_radius + 0.01, 0., world_size - actor_radius);
|
||||
actor_entity->mVelocity = vector3d (-1., 0., 0.);
|
||||
|
||||
actor_2_entity->mPosition = vector3d (world_size - actor_radius - 0.01, 0., world_size - actor_radius);
|
||||
actor_2_entity->mVelocity = vector3d (0., 0., 0.);
|
||||
|
||||
bool coll_res = false;
|
||||
coll2d::CollisionInfo info;
|
||||
|
||||
// with disabled world warp, there should not be a collision ...
|
||||
PhysicsModule.DisableWorldWarp(PhysicsBase::WorldWarpModeX);
|
||||
coll_res = PhysicsModule.CalcNextCollision (1., actor_entity->mId, actor_2_entity->mId, info);
|
||||
CHECK (!coll_res);
|
||||
|
||||
// ... however with WorldWarp enabled, there should be!
|
||||
PhysicsModule.EnableWorldWarp (PhysicsBase::WorldWarpModeX);
|
||||
coll_res = PhysicsModule.CalcNextCollision (1., actor_entity->mId, actor_2_entity->mId, info);
|
||||
CHECK (coll_res);
|
||||
|
||||
// Now we change the velocities and let actor_2 move out of the maximum x
|
||||
// direction
|
||||
actor_entity->mVelocity = vector3d (0., 0., 0.);
|
||||
actor_2_entity->mVelocity = vector3d (1., 0., 0.);
|
||||
|
||||
// with disabled world warp, there should not be a collision ...
|
||||
PhysicsModule.DisableWorldWarp(PhysicsBase::WorldWarpModeX);
|
||||
coll_res = PhysicsModule.CalcNextCollision (1., actor_entity->mId, actor_2_entity->mId, info);
|
||||
CHECK (!coll_res);
|
||||
|
||||
// ... however with WorldWarp enabled, there should be!
|
||||
PhysicsModule.EnableWorldWarp (PhysicsBase::WorldWarpModeX);
|
||||
coll_res = PhysicsModule.CalcNextCollision (1., actor_entity->mId, actor_2_entity->mId, info);
|
||||
CHECK (coll_res);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user