Skip to content

Commit

Permalink
[#17] : Enhanced physics engine stability
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Jul 2, 2020
1 parent 4f450ce commit 9182d66
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 389 deletions.
6 changes: 3 additions & 3 deletions engines/basic/include/shader_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace dbasic {
};

struct ShaderObjectVariables {
ysMatrix Transform = ysMath::LoadIdentity();
ysMatrix Transform = ysMath::Constants::Identity;

float TexOffset[2] = { 0.0f, 0.0f };
float TexScale[2] = { 1.0f, 1.0f };
Expand All @@ -43,8 +43,8 @@ namespace dbasic {
};

struct ShaderScreenVariables {
ysMatrix CameraView = ysMath::LoadIdentity();
ysMatrix Projection = ysMath::LoadIdentity();
ysMatrix CameraView = ysMath::Constants::Identity;
ysMatrix Projection = ysMath::Constants::Identity;

ysVector4 Eye = { 0.0f, 0.0f, 0.0f };
};
Expand Down
2 changes: 1 addition & 1 deletion engines/basic/src/scene_object_asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dbasic::SceneObjectAsset::SceneObjectAsset() : ysObject("SceneObjectAsset") {
m_skeletonIndex = -1;
m_type = ysObjectData::ObjectType::Undefined;

m_localTransform = ysMath::LoadIdentity();
m_localTransform = ysMath::Constants::Identity;
m_localOrientation = ysMath::Constants::QuatIdentity;
m_localPosition = ysMath::Constants::Zero;

Expand Down
6 changes: 3 additions & 3 deletions include/yds_expanding_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ysExpandingArray {
ysExpandingArray() {
m_maxSize = START_SIZE;
m_nObjects = 0;
m_array = NULL;
m_array = nullptr;

Preallocate(m_maxSize);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ class ysExpandingArray {
}

bool IsActive() const {
return (m_array != NULL);
return (m_array != nullptr);
}

void Delete(int index, bool maintainOrder = false) {
Expand All @@ -149,7 +149,7 @@ class ysExpandingArray {
m_array[i] = m_array[i + 1];
}

m_array[m_nObjects - 1] = NULL;
m_array[m_nObjects - 1] = nullptr;
}
else {
m_array[index] = m_array[m_nObjects - 1];
Expand Down
6 changes: 6 additions & 0 deletions include/yds_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ namespace ysMath {
YS_MATH_CONST ysVector Half = { 0.5f, 0.5f, 0.5f, 0.5f };
YS_MATH_CONST ysVector Double = { 2.0f, 2.0f, 2.0f, 2.0f };

YS_MATH_CONST ysMatrix Identity = {
IdentityRow1,
IdentityRow2,
IdentityRow3,
IdentityRow4 };

// Numeral Constants
YS_MATH_CONST float PI = 3.141592654f;
YS_MATH_CONST float TWO_PI = 6.2831853071795864769252866f;
Expand Down
13 changes: 6 additions & 7 deletions physics/include/collision_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ namespace dphysics {
CollisionDetector();
~CollisionDetector();

bool BoxBoxCollision(Collision &collision, RigidBody *body1, RigidBody *body2, BoxPrimitive *box1, BoxPrimitive *box2);
bool CircleBoxCollision(Collision &collision, RigidBody *body1, RigidBody *body2, CirclePrimitive *circle, BoxPrimitive *box);
bool CircleCircleCollision(Collision &collision, RigidBody *body1, RigidBody *body2, CirclePrimitive *circle1, CirclePrimitive *circle2);
bool RayBoxCollision(Collision &collision, RigidBody *body1, RigidBody *body2, RayPrimitive *ray, BoxPrimitive *box);
bool RayCircleCollision(Collision &collision, RigidBody *body1, RigidBody *body2, RayPrimitive *ray, CirclePrimitive *circle);
int BoxBoxCollision(Collision *collisions, RigidBody *body1, RigidBody *body2, BoxPrimitive *box1, BoxPrimitive *box2);
int CircleBoxCollision(Collision *collisions, RigidBody *body1, RigidBody *body2, CirclePrimitive *circle, BoxPrimitive *box);
int CircleCircleCollision(Collision *collisions, RigidBody *body1, RigidBody *body2, CirclePrimitive *circle1, CirclePrimitive *circle2);
int RayBoxCollision(Collision *collisions, RigidBody *body1, RigidBody *body2, RayPrimitive *ray, BoxPrimitive *box);
int RayCircleCollision(Collision *collisions, RigidBody *body1, RigidBody *body2, RayPrimitive *ray, CirclePrimitive *circle);

bool CircleCircleIntersect(RigidBody *body1, RigidBody *body2, CirclePrimitive *circle1, CirclePrimitive *circle2);

protected:
bool _BoxBoxCollision(Collision *collision, BoxPrimitive *body1, BoxPrimitive *body2);
bool _BoxBoxEdgeDetect(Collision *collisions, BoxPrimitive *body1, BoxPrimitive *body2);
int _BoxBoxCollision(Collision *collisions, BoxPrimitive *body1, BoxPrimitive *body2);
};

} /* namesapce dbasic */
Expand Down
16 changes: 15 additions & 1 deletion physics/include/collision_primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,23 @@ namespace dphysics {
class Collision : public ysObject {
friend RigidBodySystem;

public:
enum class CollisionType {
PointFace,
EdgeEdge,
Generic,
Unknown
};

public:
Collision();
Collision(Collision &collision);
Collision(const Collision &collision);
~Collision();

CollisionType m_collisionType;
int m_feature1;
int m_feature2;

float m_penetration;
ysVector m_normal;
ysVector m_position;
Expand Down Expand Up @@ -80,6 +92,8 @@ namespace dphysics {
ysVector GetContactVelocity() const { return m_initialContactVelocity; }
ysVector GetContactVelocityWorld() const;

bool IsSameAs(Collision *other) const;

protected:
ysVector m_relativePosition[2];
ysMatrix m_contactSpace;
Expand Down
2 changes: 2 additions & 0 deletions physics/include/rigid_body.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ namespace dphysics {

bool CheckState();

Collision *FindMatchingCollision(Collision *collision);

protected:
// Properties
bool m_registered;
Expand Down
4 changes: 4 additions & 0 deletions physics/include/rigid_body_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ namespace dphysics {
void CloseReplayFile();

protected:
bool CollisionExists(Collision *collision);

void GenerateCollisions();
void InitializeCollisions();
void CleanCollisions();
void ClearCollisions();
void GenerateCollisions(RigidBody *body1, RigidBody *body2);

void ResolveCollisions(float dt);
Expand Down
Loading

0 comments on commit 9182d66

Please sign in to comment.