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 
69  return gravityFree;
70  }
75  return linearForceToApply;
76  }
77 
84  gravityFree=value;
85  for (auto body : bodies){
86  body->ignoreGravity=gravityFree;
87  }
88  return this;
89  }
96  linearForceToApply=value;
97  return this;
98  }
99 
100 
101 
102 
103 
104 
105  friend class QManifold;
106  friend class QWorld;
107 
108 };
109 
110 
111 #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:95
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
QAreaBody * SetGravityFreeEnabled(bool value)
Definition: qareabody.h:83
std::function< void(QAreaBody *areaBody, QBody *collidedBody)> CollisionEnterEventListener
Definition: qareabody.h:53
QVector GetLinearForceToApply()
Definition: qareabody.h:74
bool GetGravityFreeEnabled()
Definition: qareabody.h:68
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