Untitled Game engine no.5
1.0
|
6 #include "PhysicsParam.hpp"
41 [[nodiscard]]
virtual glm::vec3 furthestInDir(
const Ref<PhysicsEntity> &pe,
const glm::vec3 &norm)
const {
return {0, 0, 0};}
71 bool itmatUpdated =
true;
106 mat = (glm::translate(
x) * glm::toMat4(
q));
111 imat = glm::affineInverse(
getMat());
112 itmatUpdated =
false;
125 [[nodiscard]] glm::vec3 furthestInDir(
const glm::vec3 &norm)
const {
126 return pe->c->furthestInDir(pe, norm);
140 Support &operator=(glm::vec3 support) {
151 supportA = support.supportA;
152 supportB = support.supportB;
178 std::vector<Support> supports = std::vector<Support>(SIMPLEX_COUNT);
181 Simplex &operator=(std::initializer_list<Support> ilist) {
183 for (
auto item : ilist) {
187 index = ilist.size();
192 Support &operator[](
const int &i) {
196 void operator+=(
const Support &support) {
197 supports[
index] = support;
201 void add(glm::vec3 p, glm::vec3 a, glm::vec3 b) {
203 supports[
index].supportA = a;
204 supports[
index].supportB = b;
208 void set(
int i, glm::vec3 p, glm::vec3 a, glm::vec3 b) {
210 supports[i].supportA = a;
211 supports[i].supportB = b;
214 void push(Support p) {
215 for (
size_t i =
index; i >= 1; i--) {
216 supports[i] = supports[i - 1];
223 void push(glm::vec3 p, glm::vec3 a, glm::vec3 b) {
224 for (
int i = SIMPLEX_COUNT - 1; i >= 1; i--) {
225 supports[i] = supports[i - 1];
229 supports[0].supportA = a;
230 supports[0].supportB = b;
241 std::vector<Support> verts = std::vector<Support>(FACE_VERTS);
244 Support &operator[](
const int &i) {
249 for (
int i = 0; i < FACE_VERTS; ++i) {
250 verts[i] = support[i];
252 normal = support.normal;
256 FacePoint &operator=(std::initializer_list<Support> list) {
271 glm::vec3 positionA = {0,0,0}, positionB{};
275 float springConstant = 0;
284 connectedRigidBody = otherRigidBody;
285 this->maxLength = maxLength;
293 Joint(glm::vec3 selfPosition, glm::vec3 globalPosition) {
294 positionA = selfPosition;
295 positionB = globalPosition;
303 explicit Joint(glm::vec3 globalPosition,
float maxLength = 0) {
304 positionA = {0, 0, 0};
305 positionB = globalPosition;
306 this->maxLength = maxLength;
340 auto positionM = glm::translate(t,
position);
341 auto rotationM = glm::toMat4(
rotation);
342 auto scaleM = glm::scale(t,
scale);
344 return positionM * rotationM * scaleM;
359 TOP_LEFT, TOP, TOP_RIGHT,
361 BOTTOM_LEFT, BOTTOM, BOTTOM_RIGHT
378 RigidBody(
float height,
float width,
float depth,
float m) {
385 glm::vec3
force = glm::vec3(0, 0, 0);
401 glm::vec3
w = glm::vec3(0, 0, 0);
403 glm::vec3
t = glm::vec3(0, 0.f, 0);
422 moment = {{I12 * ((height * height) + (depth * depth)), 0, 0},
423 {0, I12 * ((width * width) + (depth * depth)), 0},
424 {0, 0, I12 * ((width * width) + (height * height))}};
444 explicit VertexCollider(std::vector<glm::vec3> verts) : verts(std::move(verts)) {}
445 std::vector<glm::vec3> verts;
447 [[nodiscard]] glm::vec3 furthestInDir(
const Ref<PhysicsEntity>& pe,
const glm::vec3 &norm)
const override {
449 glm::mat4 mat = pe->getMat();
455 for (glm::vec3 v : verts) {
456 v = glm::vec3{mat * glm::vec4{v, 1.0f}};
457 o = glm::dot(norm, v);
458 if (!found || o > f) {
478 float back = depth / 2.0f;
479 float front = depth / 2.0f;
480 float up = height / 2.0f;
481 float down = height / 2.0f;
482 float left = width / 2.0f;
483 float right = width / 2.0f;
484 vertexCollider->verts = std::vector<glm::vec3> {{-left, -down, back}, {-left, up, back},
485 {right, up, back}, {right, -down, back},
486 {-left, -down, -front}, {-left, up, -front},
487 {right, up, -front}, {right, -down, -front}};
488 return vertexCollider;
Generic type storage for a GJK enabled collider.
Definition: Components.hpp:32
glm::vec3 force
force to apply
Definition: Components.hpp:354
glm::qua< float > qPrev
rotation quat
Definition: Components.hpp:66
Wrapper for 2D collisions. Tells the physics system that you want to process a 2D collision and not a...
Definition: Components.hpp:496
float PenetrationDepth
delta x of the contact
Definition: Components.hpp:166
glm::qua< float > q
previous position (needed for XPBD)
Definition: Components.hpp:65
Storage wrapper for support points.
Definition: Components.hpp:177
glm::vec3 xPrev
position
Definition: Components.hpp:62
Ref< Entity > entity
Entitiy reference.
Definition: Components.hpp:47
float drag
drag co-efficient
Definition: Components.hpp:434
glm::mat4 getIMat()
Get the inverse matrix transformation.
Definition: Components.hpp:89
Ref< CollisionHook > hook
does the collider physically interact with other objects (def not stolen from unity)
Definition: Components.hpp:34
VertexCollider but in 2D. by default, all 2D colliders are non-kinematic triggers.
Definition: Components.hpp:503
Definition: Components.hpp:122
static Ref< VertexCollider > boxCollider(float width=64, float height=64, float depth=64)
Generate a box collider with given dimensions. centered at 0,0,0.
Definition: Components.hpp:476
size_t index
support point list (max 4)
Definition: Components.hpp:179
Generates a force.
Definition: Components.hpp:366
bool grounded
grounded flag
Definition: Components.hpp:436
std::shared_ptr< T > Ref
Has stuff for making references a lot more easily shared smart pointer.
Definition: Base.hpp:21
Applies a force! to a colliding body or connected object.
Definition: Components.hpp:351
glm::vec3 w
velocity
Definition: Components.hpp:60
glm::mat4 getMat()
Get the matrix transformation made up of q and x.
Definition: Components.hpp:78
void setMomentCube(float height, float width, float depth, float m)
Set the moment of inertia of this rigidbody to that of a solid cube.
Definition: Components.hpp:417
Wrapper for processing collisions between physics entities.
Definition: Components.hpp:23
Ref< Transform > tf
transform reference
Definition: Components.hpp:52
glm::vec3 force
force vector
Definition: Components.hpp:385
GJK support point structure. stores the resulting support point and the components that made it up....
Definition: Components.hpp:136
Allignment
enumeration representing alignment of text in a string of text.
Definition: Components.hpp:358
bool HasCollision
does the point actually represent a collision
Definition: Components.hpp:168
glm::vec3 t
Torque.
Definition: Components.hpp:403
Joint(glm::vec3 globalPosition, float maxLength=0)
tether entity to a global coordinate
Definition: Components.hpp:303
void processCollision(const Ref< PhysicsEntity > &other)
collision hook storage
Definition: Components.hpp:40
float angularDrag
air drag co-efficient
Definition: Components.hpp:390
Ref< Collider > c
collider reference
Definition: Components.hpp:54
glm::vec3 x
angular momentum
Definition: Components.hpp:61
Storage for the expanding polytope algorithm.
Definition: Components.hpp:240
float iMass
inverse mass
Definition: Components.hpp:432
std::vector< glm::vec3 > contacts
contact points in global space
Definition: Components.hpp:164
A Collider represented by a set of (convex) vertices.
Definition: Components.hpp:442
glm::mat3 moment
moment of inertia
Definition: Components.hpp:396
bool matUpdated
storage for a delta quat
Definition: Components.hpp:70
glm::vec3 Normal
normal vector
Definition: Components.hpp:162
glm::vec3 velocity
velocity vector
Definition: Components.hpp:383
Definition: Animation.hpp:14
Physics Component that represents a joint between rigidbodies. Intended to be connected to a Entity a...
Definition: Components.hpp:270
void clearMat()
Clear the matrix flags when the position or rotation is updated.
Definition: Components.hpp:99
Joint(glm::vec3 selfPosition, glm::vec3 globalPosition)
tether local entity position to a global coordinate position
Definition: Components.hpp:293
bool kinematic
is the object affected by physics
Definition: Components.hpp:393
glm::vec3 w
Angular velocity.
Definition: Components.hpp:401
glm::mat3 invMoment
inverse moment of inertia
Definition: Components.hpp:398
Joint(Ref< RigidBody > &otherRigidBody, float maxLength)
Connect two rigid-bodies at their respective centers at a given distance apart.
Definition: Components.hpp:283
Physics rigidbody component. Stores the physical parameters of an object. Such as moment of inertia,...
Definition: Components.hpp:376
Definition: Components.hpp:160
Ref< PhysicsEntity > physicsEntity
Reference to an active physics entity.
Definition: Components.hpp:406
float airDrag
air drag co-efficient
Definition: Components.hpp:388
glm::qua< float > dQ
previous quat
Definition: Components.hpp:67
Ref< RigidBody > rb
rigidbody reference
Definition: Components.hpp:57
Links all the data necessary to compute physics calculations.
Definition: Components.hpp:45