Quark Physics  1.0
2D Rigid and Soft Body Physics Engine
qspring.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 QSPRING_H
29 #define QSPRING_H
30 #include "qparticle.h"
31 
32 class QMesh;
38 class QSpring
39 {
40  float rigidity=1.0f;
41  QParticle *pA;
42  QParticle *pB;
43  float length;
44  bool isInternal=false;
45  bool enableDistanceLimit=false;
46  float minimumDistanceFactor=0.25f;
47  float maximumDistanceFactor=4.0f;
48  bool enabled=true;
49 public:
56  QSpring(QParticle *particleA,QParticle *particleB,bool internal=false);
64  QSpring(QParticle *particleA,QParticle *particleB,float length,bool internal=false);
65 
66 
67 
74  virtual void Update(float rigidity,bool internalsException,bool isWorldSpring=false);
75 
76  //Get Methods
79  return pA;
80  }
83  return pB;
84  }
86  float GetLength(){
87  return length;
88  }
90  bool GetIsInternal(){
91  return isInternal;
92  }
94  float GetRigidity(){
95  return rigidity;
96  }
97 
103  return enableDistanceLimit;
104  }
107  return minimumDistanceFactor;
108  }
111  return minimumDistanceFactor;
112  }
113 
115  bool GetEnabled(){
116  return enabled;
117  }
118 
119 
120 
121  //Set Methods
127  pA=particle;
128  return this;
129  }
135  pB=particle;
136  return this;
137  }
142  QSpring *SetLength(float length){
143  this->length=length;
144  return this;
145  }
150  QSpring *SetIsInternal(bool value){
151  isInternal=value;
152  return this;
153  }
158  QSpring *SetRigidity(float rigidity){
159  this->rigidity=rigidity;
160  return this;
161  }
162 
168  enableDistanceLimit=value;
169  return this;
170  }
173  minimumDistanceFactor=value;
174  return this;
175  }
178  maximumDistanceFactor=value;
179  return this;
180  }
181 
186  QSpring *SetEnabled(bool value){
187  enabled=value;
188  return this;
189  }
190 
194  bool manualDeletion=false;
195 
196 
197 
198 
199 
200 };
201 
202 #endif // QSPRING_H
QParticle objects form the network structures of QMesh objects defined for all body object types....
Definition: qparticle.h:40
You can apply distance constraints between 2 particles using the QSpring. The physics engine uses QSp...
Definition: qspring.h:39
virtual void Update(float rigidity, bool internalsException, bool isWorldSpring=false)
Definition: qspring.cpp:50
float GetMinimumDistanceFactor()
Definition: qspring.h:106
QSpring * SetMinimumDistanceFactor(float value)
Definition: qspring.h:172
QParticle * GetParticleA()
Definition: qspring.h:78
QSpring * SetIsInternal(bool value)
Definition: qspring.h:150
QSpring(QParticle *particleA, QParticle *particleB, bool internal=false)
Definition: qspring.cpp:33
bool GetDistanceLimitEnabled()
Definition: qspring.h:102
QSpring * SetLength(float length)
Definition: qspring.h:142
QSpring * SetDistanceLimitEnabled(bool value)
Definition: qspring.h:167
float GetLength()
Definition: qspring.h:86
QSpring * SetRigidity(float rigidity)
Definition: qspring.h:158
QParticle * GetParticleB()
Definition: qspring.h:82
bool GetIsInternal()
Definition: qspring.h:90
float GetRigidity()
Definition: qspring.h:94
QSpring * SetParticleA(QParticle *particle)
Definition: qspring.h:126
QSpring * SetParticleB(QParticle *particle)
Definition: qspring.h:134
bool manualDeletion
Definition: qspring.h:194
QSpring * SetMaximumDistanceFactor(float value)
Definition: qspring.h:177
bool GetEnabled()
Definition: qspring.h:115
QSpring * SetEnabled(bool value)
Definition: qspring.h:186
float GetMaximumDistanceFactor()
Definition: qspring.h:110
Every QBody object requires meshes. In other traditional physics engines, the term 'shape' is used in...
Definition: qmesh.h:49