+ weird racist test : the primitives only collide with their same type.legacy
@@ -26,6 +26,7 @@ public: | |||
{ | |||
m_mesh.Compile("[sc#ddd afcb60 1 60 -.1]"); | |||
vec3 BoxSize = vec3(60.f, 1.f, 60.f); | |||
m_physics.SetCollisionChannel(0, 0xFF); | |||
m_physics.SetShapeToBox(BoxSize); | |||
m_physics.SetMass(.0f); | |||
m_physics.SetTransform(base_location, base_rotation); | |||
@@ -85,17 +86,34 @@ public: | |||
m_mesh.Compile(MeshRand[RandValue]); | |||
vec3 BoxSize = vec3(2.0f); | |||
int ColGroup = 1; | |||
if (RandValue < SphereLimit) | |||
{ | |||
m_physics.SetShapeToBox(BoxSize); | |||
ColGroup += 0; | |||
} | |||
else if (RandValue < ConeLimit) | |||
{ | |||
m_physics.SetShapeToSphere(BoxSize.x * 2.f); | |||
ColGroup += 1; | |||
} | |||
else if (RandValue < CylLimit) | |||
{ | |||
m_physics.SetShapeToCone(BoxSize.x, BoxSize.y); | |||
ColGroup += 2; | |||
} | |||
else if (RandValue < CapsLimit) | |||
{ | |||
m_physics.SetShapeToCylinder(BoxSize); | |||
ColGroup += 3; | |||
} | |||
else | |||
{ | |||
m_physics.SetShapeToCapsule(BoxSize.x, BoxSize.y); | |||
ColGroup += 4; | |||
} | |||
m_physics.SetCollisionChannel(ColGroup, (1<<ColGroup)|(1)); | |||
m_physics.SetMass(base_mass); | |||
m_physics.SetTransform(base_location); | |||
m_physics.InitBodyToRigid(); | |||
@@ -36,7 +36,9 @@ EasyPhysics::EasyPhysics() : | |||
m_collision_shape(NULL), | |||
m_motion_state(NULL), | |||
m_mass(.0f), | |||
m_local_inertia(btVector3(.0f, .0f, .0f)) | |||
m_local_inertia(btVector3(.0f, .0f, .0f)), | |||
m_collision_group(1), | |||
m_collision_mask(1) | |||
{ | |||
} | |||
@@ -100,6 +102,15 @@ void EasyPhysics::SetShapeToCapsule(float radius, float height) | |||
height * LOL2BT_UNIT * LOL2BT_SIZE)); | |||
} | |||
//------------------------------------------------------------------------- | |||
//Bullet collision channel setup | |||
//-- | |||
void EasyPhysics::CustomSetCollisionChannel(int NewGroup, int NewMask) | |||
{ | |||
if (m_rigid_body) | |||
m_rigid_body->setCollisionFlags(m_collision_mask); | |||
} | |||
//------------------------------------------------------------------------- | |||
//Base Location/Rotation setup | |||
//-- | |||
@@ -157,14 +168,14 @@ void EasyPhysics::AddToSimulation(class Simulation* current_simulation) | |||
btDiscreteDynamicsWorld* dynamics_world = current_simulation->GetWorld(); | |||
if (m_rigid_body) | |||
{ | |||
dynamics_world->addRigidBody(m_rigid_body); | |||
dynamics_world->addRigidBody(m_rigid_body, m_collision_group, m_collision_mask); | |||
if (m_mass != .0f) | |||
current_simulation->AddToDynamic(this); | |||
else | |||
current_simulation->AddToStatic(this); | |||
} | |||
else | |||
dynamics_world->addCollisionObject(m_collision_object); | |||
dynamics_world->addCollisionObject(m_collision_object, m_collision_group, m_collision_mask); | |||
} | |||
//------------------------------------------------------------------------- | |||
@@ -42,6 +42,7 @@ public: | |||
void SetShapeToCylinder(lol::vec3& cyl_size); | |||
void SetShapeToCapsule(float radius, float height); | |||
void CustomSetCollisionChannel(int NewGroup, int NewMask); | |||
void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))); | |||
void SetMass(float mass); | |||
void InitBodyToRigid(); | |||
@@ -55,13 +56,10 @@ protected: | |||
btCollisionObject* m_collision_object; | |||
btRigidBody* m_rigid_body; | |||
btScalar m_mass; | |||
btVector3 m_local_inertia; | |||
btCollisionShape* m_collision_shape; | |||
btMotionState* m_motion_state; | |||
lol::mat4 m_local_to_world; | |||
#else | |||
public: | |||
EasyPhysics() { } | |||
@@ -72,12 +70,31 @@ public: | |||
void SetShapeToCylinder(lol::vec3& cyl_size) { } | |||
void SetShapeToCapsule(float radius, float height) { } | |||
void CustomSetCollisionChannel(int NewGroup, int NewMask) { } | |||
void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { } | |||
void SetMass(float mass) { } | |||
void InitBodyToRigid() { } | |||
void AddToSimulation(class Simulation* current_simulation) { } | |||
mat4 GetTransform() { return mat4(1.0f); } | |||
#endif | |||
public: | |||
//Sets the collision Group & Mask. | |||
//Mask can change at runtime, not group ! | |||
void SetCollisionChannel(int NewGroup, int NewMask) | |||
{ | |||
m_collision_group = (1<<NewGroup); | |||
m_collision_mask = NewMask; | |||
CustomSetCollisionChannel(NewGroup, NewMask); | |||
} | |||
int GetCollisionGroup() { return m_collision_group; } | |||
int GetCollisionMask() { return m_collision_mask; } | |||
protected: | |||
lol::mat4 m_local_to_world; | |||
float m_mass; | |||
int m_collision_group; | |||
int m_collision_mask; | |||
}; | |||
} /* namespace phys */ | |||
@@ -95,7 +95,7 @@ private: | |||
void CustomSetGravity(vec3 &NewGravity) | |||
{ | |||
if (m_dynamics_world) | |||
m_dynamics_world->setGravity(LOL2BT_VEC3(NewGravity)); | |||
m_dynamics_world->setGravity(LOL2BT_VEC3(NewGravity * LOL2BT_UNIT)); | |||
} | |||
void CustomSetTimestep(float NewTimestep) { } | |||