37 #include "qmath_utils.h"
45 float circumference=0.0f;
69 size_t operator()(
const std::pair<QBody*, QBody*>& p)
const {
70 std::size_t h1 = std::hash<QBody*>{}(p.first);
71 std::size_t h2 = std::hash<QBody*>{}(p.second);
72 return h1 ^ (h2 + 0x9e3779b9 + (h1 << 6) + (h1 >> 2));
77 bool operator()(
const std::pair<QBody*, QBody*>& p1,
const std::pair<QBody*, QBody*>& p2)
const {
78 return (p1.first == p2.first && p1.second == p2.second) ||
79 (p1.first == p2.second && p1.second == p2.first);
89 QVector prevPosition=QVector::Zero();
91 float prevRotation=0.0f;
93 Modes mode=QBody::Modes::DYNAMIC;
94 bool inertiaNeedsUpdate=
true;
95 bool circumferenceNeedsUpdate=
true;
96 bool enableBodySpecificTimeScale=
false;
97 float bodySpecificTimeScale=1.0f;
98 BodyTypes bodyType=BodyTypes::RIGID;
100 float velocityLimit=0.0f;
101 bool enableIntegratedVelocities=
true;
106 float staticFriction=0.5f;
107 float airFriction=0.01f;
109 float restitution=0.0f;
113 int collidableLayersBit=1;
114 bool isKinematic=
false;
115 bool allowKinematicCollisions=
false;
118 bool isSleeping=
false;
121 int fixedVelocityTick=0;
122 int fixedAngularTick=0;
127 void UpdateMeshTransforms();
132 virtual bool CanGiveCollisionResponseTo(
QBody *otherBody);
220 for(
auto mesh:_meshes){
221 res+=mesh->GetInitialArea();
228 for(
auto mesh:_meshes){
229 res+=mesh->GetInitialPolygonsArea();
236 for(
auto mesh:_meshes){
237 res+=mesh->GetArea();
244 for(
auto mesh:_meshes){
245 res+=mesh->GetPolygonsArea();
255 if(inertiaNeedsUpdate==
true){
257 inertia=inertia<500.0f ? 500.0f:inertia;
258 inertiaNeedsUpdate=
false;
268 return collidableLayersBit;
274 if( (layersBit & this->collidableLayersBit)==0 )
282 if( (layersBit & this->layersBit)==0 ){
297 return simulationModel;
306 return staticFriction;
325 if(circumferenceNeedsUpdate==
true){
327 for(
auto mesh:_meshes){
328 circumference+=mesh->GetCircumference();
330 circumferenceNeedsUpdate=
false;
333 return circumference;
338 return enableBodySpecificTimeScale;
343 return bodySpecificTimeScale;
370 if (withPreviousPosition) {
371 prevPosition=position;
375 UpdateMeshTransforms();
409 rotation=angleRadian;
410 if(withPreviousRotation)
411 prevRotation=angleRadian;
413 UpdateMeshTransforms();
422 return SetRotation( degree*(M_PI/180.0f),withPreviousRotation );
438 prevRotation=angleRadian;
466 collidableLayersBit=value;
491 simulationModel=model;
492 for(
auto mesh:_meshes){
493 mesh->UpdateCollisionBehavior();
495 UpdateMeshTransforms();
512 staticFriction=value;
531 inertiaNeedsUpdate=
true;
548 enableBodySpecificTimeScale=value;
557 bodySpecificTimeScale=value;
627 vector<QMesh*> _meshes=vector<QMesh*>();
630 static bool CanCollide(
QBody *bodyA,
QBody *bodyB,
bool checkBodiesAreEnabled=
true);
QBody objects are the base class for all types of bodies. Any class derived from QBody shares these m...
Definition: qbody.h:43
QVector GetPreviousPosition()
Definition: qbody.h:197
virtual void OnPreStep()
Definition: qbody.h:155
QBody * SetBodySpecificTimeScaleEnabled(bool value)
Definition: qbody.h:547
QBody * AddPreviousRotation(float angleRadian)
Definition: qbody.h:445
float GetTotalPolygonsInitialArea()
Definition: qbody.h:226
QBody * SetVelocityLimit(float value)
Definition: qbody.cpp:61
QBody * SetStaticFriction(float value)
Definition: qbody.h:511
QBody * SetIntegratedVelocitiesEnabled(bool value)
Definition: qbody.cpp:123
float GetFriction()
Definition: qbody.h:301
QBody * RemoveMeshAt(int index)
Definition: qbody.cpp:147
virtual void OnStep()
Definition: qbody.h:157
QBody * AddMesh(QMesh *mesh)
Definition: qbody.cpp:128
float GetAirFriction()
Definition: qbody.h:310
QBody * SetCollidableLayersBit(int value)
Definition: qbody.h:465
QBody * WakeUp()
Definition: qbody.h:607
virtual bool OnCollision(CollisionInfo)
Definition: qbody.h:162
QBody * AddRotation(float angleRadian, bool withPreviousRotation=true)
Definition: qbody.h:430
SimulationModels GetSimulationModel()
Definition: qbody.h:296
QBody * SetMass(float value)
Definition: qbody.h:529
QBody * SetLayersBit(int value)
Definition: qbody.h:457
int GetCollidableLayersBit()
Definition: qbody.h:267
QBody * SetRestitution(float value)
Definition: qbody.h:538
QAABB GetAABB() const
Definition: qbody.h:213
QBody * AddPosition(QVector value, bool withPreviousPosition=true)
Definition: qbody.h:385
float GetStaticFriction()
Definition: qbody.h:305
float GetTotalArea()
Definition: qbody.h:234
QWorld * GetWorld()
Definition: qbody.h:189
QBody * SetMode(QBody::Modes bodyMode)
Definition: qbody.h:481
float GetPreviousRotation()
Definition: qbody.h:209
float GetCircumference()
Definition: qbody.h:324
int GetMeshCount()
Definition: qbody.cpp:165
QBody * SetFriction(float value)
Definition: qbody.h:503
float GetRotation()
Definition: qbody.h:201
bool GetBodySpecificTimeScaleEnabled()
Definition: qbody.h:337
QBody * SetBodySpecificTimeScale(float value)
Definition: qbody.h:556
virtual float GetMass()
Definition: qbody.h:315
bool GetIsSleeping()
Definition: qbody.h:288
bool GetEnabled()
Definition: qbody.h:347
SimulationModels
Definition: qbody.h:63
QBody * SetRotationDegree(float degree, bool withPreviousRotation=true)
Definition: qbody.h:421
float GetVelocityLimit()
Definition: qbody.cpp:53
float GetInertia()
Definition: qbody.h:254
std::function< void(QBody *body)> PreStepEventListener
Definition: qbody.h:168
QVector GetPosition()
Definition: qbody.h:193
virtual void PostUpdate()
Definition: qbody.h:131
float GetTotalInitialArea()
Definition: qbody.h:218
QBody * AddMeshesFromFile(string filePath)
Definition: qbody.cpp:138
bool GetOverlapWithCollidableLayersBit(int layersBit)
Definition: qbody.h:273
BodyTypes GetBodyType()
Definition: qbody.h:185
bool GetIntegratedVelocitiesEnabled()
Definition: qbody.cpp:57
QBody * SetPreviousRotation(float angleRadian)
Definition: qbody.h:437
float GetRestitution()
Definition: qbody.h:319
QBody * AddPreviousPosition(QVector value)
Definition: qbody.h:400
std::function< bool(QBody *body, CollisionInfo)> CollisionEventListener
Definition: qbody.h:177
float GetRotationDegree()
Definition: qbody.h:205
QMesh * GetMeshAt(int index)
Definition: qbody.cpp:158
QBody * SetAirFriction(float value)
Definition: qbody.h:520
QBody * SetSimulationModel(SimulationModels model)
Definition: qbody.h:489
Modes GetMode()
Definition: qbody.h:250
float GetBodySpesificTimeScale()
Definition: qbody.h:342
QBody * SetEnabled(bool value)
Definition: qbody.h:564
std::function< void(QBody *body)> StepEventListener
Definition: qbody.h:172
virtual void Update()
Definition: qbody.h:129
float GetTotalPolygonsArea()
Definition: qbody.h:242
Modes
Definition: qbody.h:50
vector< QMesh * > * GetMeshes()
Definition: qbody.cpp:161
QBody * SetPosition(QVector value, bool withPreviousPosition=true)
Definition: qbody.h:368
QBody * SetPreviousPosition(QVector value)
Definition: qbody.h:392
QBody * SetRotation(float angleRadian, bool withPreviousRotation=true)
Definition: qbody.h:408
int GetLayersBit()
Definition: qbody.h:263
bool GetOverlapWithLayersBit(int layersBit)
Definition: qbody.h:281
QBody * SetCanSleep(bool value)
Definition: qbody.h:473
bool GetCanSleep()
Definition: qbody.h:292
Definition: qbroadphase.h:44
QJoint objects serves to apply various distance constraints between rigid bodies. Additionally,...
Definition: qjoint.h:37
QManifold retrieves collision data from collision tests between two QBody objects using QCollision me...
Definition: qmanifold.h:36
QParticle objects form the network structures of QMesh objects defined for all body object types....
Definition: qparticle.h:37
A QWorld object is required to create a physics simulation. The QWorld class manages the entire physi...
Definition: qworld.h:51
CollisionInfo structure contains collision information of a body object. This information is sent to ...
Definition: qbody.h:141
QVector position
Definition: qbody.h:143
QBody * body
Definition: qbody.h:145
QVector normal
Definition: qbody.h:147
float penetration
Definition: qbody.h:149
Every QBody object requires meshes. In other traditional physics engines, the term 'shape' is used in...
Definition: qmesh.h:48