Quark Physics  1.0
2D Rigid and Soft Body Physics Engine
qraycast.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 QRAYCAST_H
29 #define QRAYCAST_H
30 #include "qvector.h"
31 #include "qbody.h"
32 
33 class QWorld;
37 class QRaycast
38 {
39 
40 protected:
41  void UpdateContacts();
42 
43  int collidableLayersBit=1;
44 
45 public:
51  QRaycast(QVector position, QVector rayVector,bool enableContainingBodies=false);
55  struct Contact{
56  public:
64  float distance;
66 
67  };
68 
77  static vector<QRaycast::Contact> RaycastTo(QWorld *world, QVector rayPosition,QVector rayVector, int collidableLayers=1,bool enableContainingBodies=false );
78 
79 
80 
81 
82 
83  //Get Methods
85  vector<QRaycast::Contact> *GetContacts();
89  float GetRotation();
96 
97  //Set Methods
101  QRaycast *SetPosition(QVector value);
105  QRaycast *SetRotation(float value);
109  QRaycast *SetRayVector(QVector value);
114 
118  QRaycast *SetCollidableLayersBit(int value);
119 
120 
121  friend class QWorld;
122 
123 private:
124  QVector position=QVector::Zero();
125  float rotation=0.0f;
126  QVector ray=QVector::Zero();
127  QVector rayOriginal=QVector::Zero();
128 
129  bool enabledContainingBodies=false;
130 
131  vector<QRaycast::Contact> contacts;
132 
133  QWorld *world;
134 
135 
136 
137  static vector<QBody*> GetPotentialBodies(QWorld *whichWorld,QVector rayPosition,QVector rayVector,int collidableLayers);
138  static void RaycastToParticles(QBody *body, QMesh *mesh, QVector rayPosition, QVector rayVector, QVector rayUnit,QVector rayNormal, bool enableContainingBodies,vector<QRaycast::Contact> *contacts);
139  static void RaycastToPolygon(QBody *body, QMesh *mesh, QVector rayPosition, QVector rayVector, QVector rayUnit,QVector rayNormal, bool enableContainingBodies,vector<QRaycast::Contact> *contacts);
140 
141  static bool SortContacts(const QRaycast::Contact contactA,const QRaycast::Contact contactB);
142 
143 };
144 
145 #endif // QRAYCAST_H
QBody objects are the base class for all types of bodies. Any class derived from QBody shares these m...
Definition: qbody.h:43
QRaycast objects send a ray into the world and return collision results with body objects....
Definition: qraycast.h:38
QRaycast * SetRayVector(QVector value)
Definition: qraycast.cpp:162
QRaycast * SetRotation(float value)
Definition: qraycast.cpp:155
vector< QRaycast::Contact > * GetContacts()
Definition: qraycast.cpp:118
QVector GetPosition()
Definition: qraycast.cpp:123
QRaycast * SetEnabledContainingBodies(bool value)
Definition: qraycast.cpp:169
bool GetEnabledContainingBodies()
Definition: qraycast.cpp:133
int GetCollidableLayersBit()
Definition: qraycast.cpp:138
float GetRotation()
Definition: qraycast.cpp:144
QRaycast * SetCollidableLayersBit(int value)
Definition: qraycast.cpp:175
QRaycast(QVector position, QVector rayVector, bool enableContainingBodies=false)
Definition: qraycast.cpp:33
static vector< QRaycast::Contact > RaycastTo(QWorld *world, QVector rayPosition, QVector rayVector, int collidableLayers=1, bool enableContainingBodies=false)
Definition: qraycast.cpp:94
QRaycast * SetPosition(QVector value)
Definition: qraycast.cpp:149
QVector GetRayVector()
Definition: qraycast.cpp:128
A QWorld object is required to create a physics simulation. The QWorld class manages the entire physi...
Definition: qworld.h:51
Every QBody object requires meshes. In other traditional physics engines, the term 'shape' is used in...
Definition: qmesh.h:48
Definition: qraycast.h:55
QVector normal
Definition: qraycast.h:62
QBody * body
Definition: qraycast.h:58
float distance
Definition: qraycast.h:64
QVector position
Definition: qraycast.h:60
Definition: qvector.h:44