Quark Physics  1.0
2D Rigid and Soft Body Physics Engine
qjoint.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 
28 #ifndef QJOINT_H
29 #define QJOINT_H
30 #include "qrigidbody.h"
31 
32 
36 class QJoint
37 {
38  //Base Properties
39 
40  QRigidBody * bodyA=nullptr;
41  QRigidBody * bodyB=nullptr;
42 
43  QVector anchorA;
44  QVector anchorB;
45 
46  QVector anchorGlobalA;
47  QVector anchorGlobalB;
48 
49  bool collisionsEnabled=false;
50 
51  bool enabled=true;
52 
53  float rigidity=1.0f;
54 
55  float balance=0.5f;
56 
57  //Addinational Properties
58  float length=0.0f; //it makes distance joint
59  bool grooveEnabled=false; // it makes groove
60 
61  QWorld *world;
62 public:
71  QJoint(QRigidBody *bodyA,QVector anchorWorldPositionA,QVector anchorWorldPositionB,QRigidBody* bodyB=nullptr); // There are defined two achor points. Default distance value is the distance between the two points.
79  QJoint(QRigidBody *bodyA,QVector commonAnchorWorldPosition,QRigidBody* bodyB=nullptr) : QJoint(bodyA,commonAnchorWorldPosition,commonAnchorWorldPosition,bodyB){}; // There is a defined common anchor position, default distance is the zero.
80  ~QJoint();
81 
82  //Get Methods
84  inline QRigidBody * GetBodyA(){
85  return bodyA;
86  }
88  inline QRigidBody * GetBodyB(){
89  return bodyB;
90  }
93  return anchorA;
94  }
97  return anchorB;
98  }
101  return anchorGlobalA;
102  }
105  return anchorGlobalB;
106  }
108  inline bool GetCollisionEnabled(){
109  return collisionsEnabled;
110  }
112  inline float GetRigidity(){
113  return rigidity;
114  }
116  inline float GetLength(){
117  return length;
118  }
120  inline float GetBalance(){
121  return balance;
122  }
124  inline bool GetGrooveEnabled(){
125  return grooveEnabled;
126  }
127 
129  bool GetEnabled(){
130  return enabled;
131  }
132 
133  //Set Methods (It returns joint)
138  inline QJoint * SetBodyA(QRigidBody *body){
139  bodyA=body;
140  return this;
141  }
146  inline QJoint * SetBodyB(QRigidBody *body){
147  bodyB=body;
148  return this;
149  }
154  inline QJoint * SetAnchorAPosition(QVector worldPosition){
155  if(bodyA!=nullptr){
156  this->anchorA=(worldPosition-bodyA->GetPosition()).Rotated(-bodyA->GetRotation());
157  }else{
158  this->anchorA=worldPosition;
159  }
160  return this;
161  }
166  inline QJoint * SetAnchorBPosition(QVector worldPosition){
167  if(bodyB!=nullptr){
168  this->anchorB=(worldPosition-bodyB->GetPosition()).Rotated(-bodyB->GetRotation());
169  }else{
170  this->anchorB=worldPosition;
171  }
172  return this;
173  }
174 
179  inline QJoint* SetRigidity(float value){
180  rigidity=value;
181  return this;
182  }
187  inline QJoint* SetLength(float value){
188  length=value;
189  return this;
190  }
195  inline QJoint* SetBalance(float value){
196  balance=value;
197  return this;
198  }
199 
204  inline QJoint* SetGrooveEnabled(bool value){
205  grooveEnabled=value;
206  return this;
207  }
208 
213  QJoint* SetCollisionEnabled(bool value); //Added to cpp file because of that the function needs world object.
214 
215 
220  QJoint *SetEnabled(bool value){
221  enabled=value;
222  return this;
223  }
224 
225 
226 
228  virtual void Update();
229 
230  friend class QWorld;
231 
232 
233 
234 
235 };
236 
237 
238 
239 #endif // QJOINT_H
float GetRotation()
Definition: qbody.h:201
QVector GetPosition()
Definition: qbody.h:193
QJoint objects serves to apply various distance constraints between rigid bodies. Additionally,...
Definition: qjoint.h:37
float GetRigidity()
Definition: qjoint.h:112
QJoint * SetBalance(float value)
Definition: qjoint.h:195
QRigidBody * GetBodyB()
Definition: qjoint.h:88
QJoint * SetAnchorAPosition(QVector worldPosition)
Definition: qjoint.h:154
QVector GetAnchorBGlobalPosition()
Definition: qjoint.h:104
QJoint * SetGrooveEnabled(bool value)
Definition: qjoint.h:204
QJoint * SetBodyA(QRigidBody *body)
Definition: qjoint.h:138
float GetBalance()
Definition: qjoint.h:120
QJoint * SetEnabled(bool value)
Definition: qjoint.h:220
bool GetEnabled()
Definition: qjoint.h:129
QJoint * SetAnchorBPosition(QVector worldPosition)
Definition: qjoint.h:166
QVector GetAnchorBPosition()
Definition: qjoint.h:96
QJoint * SetCollisionEnabled(bool value)
Definition: qjoint.cpp:72
QJoint * SetBodyB(QRigidBody *body)
Definition: qjoint.h:146
bool GetGrooveEnabled()
Definition: qjoint.h:124
bool GetCollisionEnabled()
Definition: qjoint.h:108
QVector GetAnchorAGlobalPosition()
Definition: qjoint.h:100
QJoint(QRigidBody *bodyA, QVector anchorWorldPositionA, QVector anchorWorldPositionB, QRigidBody *bodyB=nullptr)
Definition: qjoint.cpp:32
QRigidBody * GetBodyA()
Definition: qjoint.h:84
QJoint * SetRigidity(float value)
Definition: qjoint.h:179
QJoint * SetLength(float value)
Definition: qjoint.h:187
QJoint(QRigidBody *bodyA, QVector commonAnchorWorldPosition, QRigidBody *bodyB=nullptr)
Definition: qjoint.h:79
virtual void Update()
Definition: qjoint.cpp:84
QVector GetAnchorAPosition()
Definition: qjoint.h:92
float GetLength()
Definition: qjoint.h:116
QRigidBody is a type of body that is simulated with the dynamics of Rigid body. A rigid body is a typ...
Definition: qrigidbody.h:40
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