Quark Physics  1.0
2D Rigid and Soft Body Physics Engine
qparticle.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 QPARTICLE_H
29 #define QPARTICLE_H
30 #include "qvector.h"
31 #include <vector>
32 
33 class QMesh;
36 class QParticle
37 {
38  float r=0.5f;
39 
40  QVector globalPosition;
41  QVector prevGlobalPosition;
42 
43  QVector position;
44 
45  float mass=1.0f;
46 
47  QMesh *ownerMesh=nullptr;
48 
49  bool isInternal=false;
50 
51  QVector force=QVector::Zero();
52 
53  std::vector<QVector> accumulatedForces;
54 public:
55  QParticle();
56  QParticle(float posX,float posY,float radius=0.5f);
57  QParticle(QVector pos,float radius=0.5f);
58 
59 
60 
61  //Get Methods
64  return globalPosition;
65  }
68  return prevGlobalPosition;
69  }
72  return position;
73  }
75  float GetMass(){
76  return mass;
77  }
82  return ownerMesh;
83  }
85  float GetRadius(){
86  return r;
87  }
89  bool GetIsInternal(){
90  return isInternal;
91  }
94  return force;
95  }
96 
97  //Set Methods
118  QParticle *SetPosition(QVector value);
123  QParticle *AddPosition(QVector value);
124 
129  QParticle *SetMass(float value);
134  QParticle *SetOwnerMesh(QMesh *mesh);
139  QParticle *SetRadius(float radius);
144  QParticle *SetIsInternal(bool value);
145 
146  //
150  QParticle *ApplyForce(QVector value);
155  QParticle *SetForce(QVector value);
160  QParticle *AddForce(QVector value);
161 
162 
163  //Accumulated Forces
173 
174 
175  //Static Methods
182  static void ApplyForceToParticleSegment(QParticle *pA,QParticle *pB,QVector force,QVector fromPosition);
183 
184 };
185 
186 #endif // QPARTICLE_H
QParticle objects form the network structures of QMesh objects defined for all body object types....
Definition: qparticle.h:37
QParticle * AddGlobalPosition(QVector value)
Definition: qparticle.cpp:66
static void ApplyForceToParticleSegment(QParticle *pA, QParticle *pB, QVector force, QVector fromPosition)
Definition: qparticle.cpp:173
QVector GetForce()
Definition: qparticle.h:93
QParticle * SetForce(QVector value)
Definition: qparticle.cpp:134
QParticle * AddAccumulatedForce(QVector value)
Definition: qparticle.cpp:147
QParticle * SetOwnerMesh(QMesh *mesh)
Definition: qparticle.cpp:103
float GetMass()
Definition: qparticle.h:75
QParticle * SetMass(float value)
Definition: qparticle.cpp:98
QParticle * ApplyForce(QVector value)
Definition: qparticle.cpp:126
QVector GetGlobalPosition()
Definition: qparticle.h:63
QParticle * ApplyAccumulatedForces()
Definition: qparticle.cpp:159
QVector GetPreviousGlobalPosition()
Definition: qparticle.h:67
bool GetIsInternal()
Definition: qparticle.h:89
QVector GetPosition()
Definition: qparticle.h:71
QParticle * ClearAccumulatedForces()
Definition: qparticle.cpp:153
float GetRadius()
Definition: qparticle.h:85
QParticle * SetGlobalPosition(QVector value)
Definition: qparticle.cpp:53
QParticle * AddForce(QVector value)
Definition: qparticle.cpp:143
QParticle * SetPreviousGlobalPosition(QVector value)
Definition: qparticle.cpp:69
QParticle * SetRadius(float radius)
Definition: qparticle.cpp:108
QParticle * SetIsInternal(bool value)
Definition: qparticle.cpp:119
QParticle * AddPreviousGlobalPosition(QVector value)
Definition: qparticle.cpp:74
QParticle * AddPosition(QVector value)
Definition: qparticle.cpp:94
QMesh * GetOwnerMesh()
Definition: qparticle.h:81
Every QBody object requires meshes. In other traditional physics engines, the term 'shape' is used in...
Definition: qmesh.h:48
Definition: qvector.h:44