Quark Physics  1.0
2D Rigid and Soft Body Physics Engine
qareabody.h
1 
2 /************************************************************************************
3  * MIT License
4  *
5  * Copyright (c) 2023 Eray Zesen
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * https://github.com/erayzesen/QuarkPhysics
25  *
26 **************************************************************************************/
27 #ifndef QAREABODY_H
28 #define QAREABODY_H
29 #include "qbody.h"
30 #include "qworld.h"
31 #include <functional>
32 #include <unordered_set>
33 
34 class QManifold;
38 class QAreaBody : public QBody{
39  unordered_set<QBody*> bodies;
40  void AddCollidedBody(QBody *body);
41  void CheckBodies();
42  bool gravityFree=false;
43  QVector linearForceToApply=QVector::Zero();
44 public:
45  QAreaBody();
49  virtual void OnCollisionEnter(QBody *collidedBody){};
53  virtual void OnCollisionExit(QBody *collidedBody){};
58  std::function<void(QAreaBody *areaBody,QBody* collidedBody)> CollisionEnterEventListener;
63  std::function<void(QAreaBody *areaBody,QBody* collidedBody)> CollisionExitEventListener;
64 
68  std::function<QVector(QBody *body)> ComputeLinearForceListener;
69 
74  return gravityFree;
75  }
80  return linearForceToApply;
81  }
82 
89  gravityFree=value;
90  for (auto body : bodies){
91  body->ignoreGravity=gravityFree;
92  }
93  return this;
94  }
101  linearForceToApply=value;
102  return this;
103  }
104 
109  vector<QBody*> GetBodies() const{
110  return vector<QBody*>(bodies.begin(),bodies.end() );
111  }
112 
118 
119  if(ComputeLinearForceListener!=nullptr) {
120  return ComputeLinearForceListener(body);
121  }
122  return linearForceToApply;
123  }
127  bool HasBody(QBody* body){
128  return bodies.find(body) != bodies.end();
129  }
130 
131 
132  friend class QManifold;
133  friend class QWorld;
134 
135 };
136 
137 
138 #endif //QAREABODY_H
QAreaBody objects are objects that don't respond to collisions or receive any response from them,...
Definition: qareabody.h:38
QAreaBody * SetLinearForceToApply(QVector value)
Definition: qareabody.h:100
virtual void OnCollisionEnter(QBody *collidedBody)
Definition: qareabody.h:49
std::function< void(QAreaBody *areaBody, QBody *collidedBody)> CollisionExitEventListener
Definition: qareabody.h:63
virtual void OnCollisionExit(QBody *collidedBody)
Definition: qareabody.h:53
virtual QVector ComputeLinearForce(QBody *body)
Definition: qareabody.h:117
QAreaBody * SetGravityFreeEnabled(bool value)
Definition: qareabody.h:88
std::function< void(QAreaBody *areaBody, QBody *collidedBody)> CollisionEnterEventListener
Definition: qareabody.h:53
std::function< QVector(QBody *body)> ComputeLinearForceListener
Definition: qareabody.h:68
bool HasBody(QBody *body)
Definition: qareabody.h:127
QVector GetLinearForceToApply()
Definition: qareabody.h:79
bool GetGravityFreeEnabled()
Definition: qareabody.h:73
vector< QBody * > GetBodies() const
Definition: qareabody.h:109
QBody objects are the base class for all types of bodies. Any class derived from QBody shares these m...
Definition: qbody.h:43
QManifold retrieves collision data from collision tests between two QBody objects using QCollision me...
Definition: qmanifold.h:36
A QWorld object is required to create a physics simulation. The QWorld class manages the entire physi...
Definition: qworld.h:51
Definition: qvector.h:44