-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split amorphous "Object" into "Collider" and "Rigidbody"
- Loading branch information
Showing
51 changed files
with
468 additions
and
463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "../../transform/transform.hpp" | ||
#include "../../serialisation/json.hpp" | ||
#include "../../renderer/renderable/renderable.hpp" | ||
#include "../../renderer/renderable/mesh/mesh.hpp" | ||
|
||
enum ShapeType {ST_CIRCLE, ST_RECT}; | ||
enum CollisionDirection {CD_TOP, CD_LEFT, CD_BOTTOM, CD_RIGHT}; | ||
|
||
class Collider : public Transform { | ||
public: | ||
explicit Collider(Transform *parent); | ||
explicit Collider(json j); | ||
|
||
void on_update() override; | ||
virtual void on_collision(Collider *other) {} | ||
void get_renderables(std::list<const Renderable *> &out) const override; | ||
|
||
void set_shape_rectangle(double w, double h); | ||
void set_shape_circle(double radius); | ||
void get_rect_half_extents(double &hw, double &hh) const; | ||
void get_circle_radius(double &r) const; | ||
[[nodiscard]] ShapeType get_shape_type() const; | ||
|
||
void set_interaction_mask(unsigned int mask); | ||
[[nodiscard]] bool can_interact() const; | ||
[[nodiscard]] unsigned int get_interaction_mask() const; | ||
[[nodiscard]] bool does_interact_with(const Collider *other) const; | ||
[[nodiscard]] bool does_interact_with(unsigned int mask) const; | ||
|
||
void set_touching(CollisionDirection dir); | ||
void set_not_touching(CollisionDirection dir); | ||
void set_not_touching_anything(); | ||
[[nodiscard]] bool is_touching(CollisionDirection dir) const; | ||
[[nodiscard]] bool is_touching_top() const; | ||
[[nodiscard]] bool is_touching_left() const; | ||
[[nodiscard]] bool is_touching_bottom() const; | ||
[[nodiscard]] bool is_touching_right() const; | ||
|
||
json serialise() override; | ||
|
||
protected: | ||
double _hw, _hh; | ||
ShapeType _shape_type; | ||
unsigned int _touching_flags; | ||
unsigned int _interaction_mask; | ||
MeshRenderable *_renderable_collider; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
#pragma once | ||
|
||
#include "../rigidbody/rigidbody.hpp" | ||
#include "../../transform/transform.hpp" | ||
#include "../../object/object.hpp" | ||
|
||
class ForceField: public Transform { | ||
public: | ||
virtual ~ForceField() = default; | ||
|
||
virtual arma::vec2 measure_at(Object *obj) const; | ||
virtual arma::vec2 f(Object *obj) const =0; | ||
virtual arma::vec2 measure_at(Rigidbody *obj) const; | ||
virtual arma::vec2 f(Rigidbody *obj) const =0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include "../collider/collider.hpp" | ||
#include "../material/material.hpp" | ||
|
||
class Rigidbody : public Collider { | ||
public: | ||
explicit Rigidbody(Transform *parent); | ||
explicit Rigidbody(json j); | ||
|
||
void timestep_force(double dt); | ||
void timestep_velocity(double dt); | ||
|
||
void set_mass(double mass); | ||
[[nodiscard]] double get_mass() const; | ||
|
||
[[nodiscard]] bool is_fixed() const; | ||
void set_fixed(bool value); | ||
|
||
void set_velocity(const arma::vec2 &velocity); | ||
[[nodiscard]] const arma::vec2 &get_velocity() const; | ||
|
||
void set_force(const arma::vec2 &force); | ||
void add_force(const arma::vec2 &force); | ||
[[nodiscard]] const arma::vec2 &get_force() const; | ||
|
||
[[nodiscard]] const PhysicsMaterial &get_material() const; | ||
void set_bounciness(double bounciness); | ||
void set_friction(double friction); | ||
|
||
virtual void on_physics_update() {} | ||
|
||
json serialise() override; | ||
|
||
protected: | ||
arma::vec2 _velocity, _previous_velocity, _force; | ||
double _mass, _inv_mass; | ||
PhysicsMaterial _material; | ||
bool _fixed; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#pragma once | ||
|
||
#include "../../../object/object.hpp" | ||
#include "../menu.hpp" | ||
|
||
class MenuItem; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.