Quark Physics  1.0
2D Rigid and Soft Body Physics Engine
QMesh Struct Reference

Every QBody object requires meshes. In other traditional physics engines, the term 'shape' is used instead. However, in Quark Physics, meshes do not only contain information about primitive shapes. A QMesh includes collision shapes, collision behaviors, internal and external spring connections, particle informations, and necessary collective information for rendering. In the QMesh class, there are methods to quickly create primitive types such as circles, rectangles, and polygons that are suitable for the types and needs of body objects. However, QMesh objects are created with a struct called MeshData. Therefore, it is also possible to create many complex mesh examples for body types. More...

#include <qmesh.h>

Collaboration diagram for QMesh:

Classes

struct  MeshData
 

Public Types

enum  CollisionBehaviors { CIRCLES , POLYGONS , POLYLINE }
 

Public Member Functions

 QMesh ()
 
QVector GetPosition ()
 
QVector GetGlobalPosition ()
 
float GetRotation ()
 
float GetGlobalRotation ()
 
float GetInitialArea ()
 
float GetInitialPolygonsArea ()
 
float GetArea ()
 
float GetPolygonsArea ()
 
float GetCircumference ()
 
QBodyGetOwnerBody ()
 
CollisionBehaviors GetCollisionBehavior ()
 
QMeshSetPosition (QVector value)
 
QMeshSetGlobalPosition (QVector value)
 
QMeshSetRotation (float value)
 
QMeshAddParticle (QParticle *particle)
 
QMeshRemoveParticleAt (int index)
 
QMeshRemoveParticle (QParticle *particle)
 
int GetParticleCount ()
 
QParticleGetParticleAt (int index)
 
int GetParticleIndex (QParticle *particle)
 
QMeshSetPolygon (vector< QParticle * > polygonParticles)
 
QMeshAddParticleToPolygon (QParticle *particle, int position=-1)
 
QMeshRemoveParticleFromPolygon (QParticle *particle)
 
QMeshRemoveParticleFromPolygonAt (int index)
 
QMeshRemovePolygon ()
 
int GetPolygonParticleCount ()
 
QParticleGetParticleFromPolygon (int index)
 
float GetMinAngleConstraintOfPolygon ()
 
QMeshSetMinAngleConstraintOfPolygon (float radian)
 
QMeshAddClosedPolygon (vector< QParticle * > polygon)
 
QMeshRemoveClosedPolygonAt (int index)
 
int GetSubConvexPolygonCount ()
 
vector< QParticle * > & GetSubConvexPolygonAt (int index)
 
QMeshAddSpring (QSpring *spring)
 
QMeshRemoveSpring (QSpring *spring)
 
QMeshRemoveSpringAt (int index)
 
QMeshRemoveMatchingSprings (QParticle *particle)
 
int GetSpringCount ()
 
QSpringGetSpringAt (int index)
 
int GetSpringIndex (QSpring *spring)
 
int GetUVMapCount ()
 
vector< int > GetUVMapAt (int index)
 
QMeshAddUVMap (vector< int > map)
 
QMeshRemoveUVMapAt (int index)
 
QMeshClearUVMaps ()
 
QMeshRemoveMatchingUVMaps (int particleIndex)
 

Static Public Member Functions

static QMeshCreateWithCircle (float radius, QVector centerPosition=QVector::Zero())
 Creates a mesh with a circle shape. More...
 
static QMeshCreateWithPolygon (float radius, int sideCount, QVector centerPosition=QVector::Zero(), int polarGrid=-1, bool enableSprings=true, bool enablePolygons=true, float particleRadius=0.5f)
 Creates a mesh with a convex polygon shape. More...
 
static QMeshCreateWithRect (QVector size, QVector centerPosition=QVector::Zero(), QVector grid=QVector::Zero(), bool enableSprings=true, bool enablePolygons=true, float particleRadius=0.5f)
 Creates a mesh with a rectangle shape. More...
 
static QMeshCreateWithMeshData (QMesh::MeshData &data, bool enableSprings=true, bool enablePolygons=true)
 
static vector< QMesh::MeshDataGetMeshDatasFromFile (string filePath)
 
static vector< QMesh::MeshDataGetMeshDatasFromJsonData (std::string &jsonBasedData)
 
static float GetPolygonArea (vector< QParticle * > &polygonPoints, bool withLocalPositions=false)
 Returns the area of a polygon. More...
 
static bool CheckCollisionBehaviors (QMesh *meshA, QMesh *meshB, CollisionBehaviors firstBehavior, CollisionBehaviors secondBehavior)
 Checks collision behaviors between two bodies. If the specified body pair is the same as the specified collision behavior pair, returns true. More...
 
static MeshData GenerateRectangleMeshData (QVector size, QVector centerPosition=QVector::Zero(), QVector grid=QVector::Zero(), float particleRadius=0.5f)
 Generates rectangle mesh data with specified properties. More...
 
static MeshData GeneratePolygonMeshData (float radius, int sideCount, QVector centerPosition=QVector::Zero(), int polarGrid=-1, float particleRadius=0.5f)
 Generates a regular polygon mesh data with specified properties. More...
 
static pair< QVector, float > GetAveragePositionAndRotation (vector< QParticle * > particleCollection)
 
static vector< QVectorGetMatchingParticlePositions (vector< QParticle * > particleCollection, QVector targetPosition, float targetRotation)
 

Protected Member Functions

void UpdateCollisionBehavior ()
 
void UpdateSubConvexPolygons ()
 
void ApplyAngleConstraintsToPolygon ()
 
bool CheckIsPolygonConcave (vector< QParticle * > polygonParticles)
 

Static Protected Member Functions

static bool CheckIsReflex (QVector pA, QVector pB, QVector pC)
 
static bool CheckIsReflex (int indexA, int indexB, int indexC, vector< QParticle * > polygonParticles)
 
static void TriangulatePolygon (vector< QParticle * > &polygonParticles, vector< vector< int >> &triangles)
 
static void DecompositePolygon (vector< QParticle * > &polygonParticles, vector< vector< QParticle * >> &polygons)
 

Protected Attributes

vector< QParticle * > particles =vector<QParticle*>()
 
QVector position =QVector::Zero()
 
QVector globalPosition =QVector::Zero()
 
float rotation =0.0f
 
float globalRotation =0.0f
 
vector< QSpring * > springs =vector<QSpring*>()
 
vector< QParticle * > polygon =vector<QParticle*>()
 
vector< vector< QParticle * > > subConvexPolygons =vector<vector<QParticle*>>()
 
float circumference =0.0f
 
QBodyownerBody =nullptr
 
CollisionBehaviors collisionBehavior =CollisionBehaviors::CIRCLES
 
vector< vector< int > > UVMaps =vector<vector<int>>()
 
bool collisionBehaviorNeedsUpdate =false
 
vector< float > lastPolygonCornerAngles
 
float minAngleConstraintOfPolygon =M_PI*0.3
 
bool subConvexPolygonsNeedsUpdate =false
 

Friends

class QWorld
 
class QBody
 
class QRigidBody
 
class QSoftBody
 
class QRaycast
 
class QCollision
 

Detailed Description

Every QBody object requires meshes. In other traditional physics engines, the term 'shape' is used instead. However, in Quark Physics, meshes do not only contain information about primitive shapes. A QMesh includes collision shapes, collision behaviors, internal and external spring connections, particle informations, and necessary collective information for rendering. In the QMesh class, there are methods to quickly create primitive types such as circles, rectangles, and polygons that are suitable for the types and needs of body objects. However, QMesh objects are created with a struct called MeshData. Therefore, it is also possible to create many complex mesh examples for body types.

Constructor & Destructor Documentation

◆ QMesh()

QMesh::QMesh ( )

Creates a mesh.

Member Function Documentation

◆ AddClosedPolygon()

QMesh* QMesh::AddClosedPolygon ( vector< QParticle * >  polygon)

Adds a polygon to the mesh

Parameters
polygonA particle pointers collection of the polygon.

◆ AddParticle()

QMesh * QMesh::AddParticle ( QParticle particle)

Adds a particle to the mesh

Parameters
particleA particle to be added.
Returns
QMesh* A pointer to mesh itself.

◆ AddParticleToPolygon()

QMesh * QMesh::AddParticleToPolygon ( QParticle particle,
int  position = -1 
)

Adds a particle of the mesh to the polygon. If you want to add a particle to the end of the polygon, set the position value as -1.

Parameters
particleA pointer to a particle
positionA position index. Default value is -1, indicating the end of the polygon.
Returns
QMesh* A pointer to mesh itself.

◆ AddSpring()

QMesh * QMesh::AddSpring ( QSpring spring)

Adds a spring to the mesh

Parameters
springA spring to be added.
Returns
QMesh* A pointer to mesh itself.

◆ AddUVMap()

QMesh * QMesh::AddUVMap ( vector< int >  map)

Adds a UV map to the mesh

Parameters
mapA particle index collection to be added.
Returns
QMesh* A pointer to mesh itself.

◆ CheckCollisionBehaviors()

bool QMesh::CheckCollisionBehaviors ( QMesh meshA,
QMesh meshB,
CollisionBehaviors  firstBehavior,
CollisionBehaviors  secondBehavior 
)
static

Checks collision behaviors between two bodies. If the specified body pair is the same as the specified collision behavior pair, returns true.

Parameters
meshAA mesh to check
meshBAnother mesh to check
firstBehaviorA behavior to check
secondBehaviorAnother behavior to check.

◆ ClearUVMaps()

QMesh * QMesh::ClearUVMaps ( )

Removes all UV maps of the mesh.

Returns
QMesh* A pointer to mesh itself.

◆ CreateWithCircle()

QMesh * QMesh::CreateWithCircle ( float  radius,
QVector  centerPosition = QVector::Zero() 
)
static

Creates a mesh with a circle shape.

Parameters
radiusThe radius of the circle
centerPositionThe center position of the circle in the mesh.
Returns
QMesh* A pointer to the created mesh.

◆ CreateWithMeshData()

QMesh * QMesh::CreateWithMeshData ( QMesh::MeshData data,
bool  enableSprings = true,
bool  enablePolygons = true 
)
static

Creates a mesh with a specified mesh data.

Parameters
dataMesh data.
enableSpringsAllow springs to the mesh.(It's unnecessary for rigid bodies)
enablePolygonsAllow polygon colliders to the mesh. Set to false for PBD type soft body needs.
Returns
QMesh* A pointer to the created mesh.

◆ CreateWithPolygon()

QMesh * QMesh::CreateWithPolygon ( float  radius,
int  sideCount,
QVector  centerPosition = QVector::Zero(),
int  polarGrid = -1,
bool  enableSprings = true,
bool  enablePolygons = true,
float  particleRadius = 0.5f 
)
static

Creates a mesh with a convex polygon shape.

Parameters
radiusThe radius of the regular polygon
sideCountThe number of sides of the polygon
centerPositionThe center position of the polygon in the mesh.
polarGridApplies a polar grid to the polygon with the specified layer count.(It's unnecessary for rigid bodies)
enableSpringsAllow springs to the polygon.(It's unnecessary for rigid bodies)
enablePolygonsAllow polygon colliders to the mesh. Set to false for PBD type soft body needs.
particleRadiusThe radius of the particles
Returns
QMesh* A pointer to the created mesh.

◆ CreateWithRect()

QMesh * QMesh::CreateWithRect ( QVector  size,
QVector  centerPosition = QVector::Zero(),
QVector  grid = QVector::Zero(),
bool  enableSprings = true,
bool  enablePolygons = true,
float  particleRadius = 0.5f 
)
static

Creates a mesh with a rectangle shape.

Parameters
sizeThe size of the rectangle
centerPositionThe center position of the rectangle in the mesh.
gridThe grid property of the rectangle. Applies a grid to the rectangle.(It's unnecessary for rigid bodies)
enableSpringsAllow springs to the rectangle.(It's unnecessary for rigid bodies)
enablePolygonsAllows polygon colliders to the mesh. Set to false for PBD type soft body needs.
particleRadiusThe radius of the particles.
Returns
QMesh* A pointer to the created mesh.

◆ GeneratePolygonMeshData()

QMesh::MeshData QMesh::GeneratePolygonMeshData ( float  radius,
int  sideCount,
QVector  centerPosition = QVector::Zero(),
int  polarGrid = -1,
float  particleRadius = 0.5f 
)
static

Generates a regular polygon mesh data with specified properties.

Parameters
radiusThe radius of the regular polygon.
sideCountThe number of sides of the polygon.
centerPositionThe center position of the polygon.
polarGridApplies a polar grid to the polygon with the specified layer count.(It's unnecessary for rigid bodies)
particleRadiusThe radius of the particles.
Returns
MeshData The data needed to create a mesh.

◆ GenerateRectangleMeshData()

QMesh::MeshData QMesh::GenerateRectangleMeshData ( QVector  size,
QVector  centerPosition = QVector::Zero(),
QVector  grid = QVector::Zero(),
float  particleRadius = 0.5f 
)
static

Generates rectangle mesh data with specified properties.

Parameters
sizeSize of the rectangle.
centerPositionThe center position of the rectangle.
gridThe grid property of the rectangle. Applies a grid to the rectangle.(It's unnecessary for rigid bodies)
particleRadiusThe radius of the particles.
Returns
MeshData The data needed to create a mesh.

◆ GetArea()

float QMesh::GetArea ( )
inline

Returns total area of the mesh with global positions of particles

◆ GetAveragePositionAndRotation()

pair< QVector, float > QMesh::GetAveragePositionAndRotation ( vector< QParticle * >  particleCollection)
static

Calculates the average position and rotation values of the specified particles.

Parameters
particleCollectionA Particles collection
Returns
Returns a position-rotation pair.

◆ GetCircumference()

float QMesh::GetCircumference ( )
inline

Returns total circumference of all polygons of the mesh (Calculates with local positions of particles)

◆ GetCollisionBehavior()

CollisionBehaviors QMesh::GetCollisionBehavior ( )
inline

Returns collision behaviors of the mesh. Collision behaviors can be circles, polygons, polylines.
The behaviors feature is important to determine collision methods for the mesh in the runtime.

◆ GetGlobalPosition()

QVector QMesh::GetGlobalPosition ( )
inline

Returns the global position of the mesh.

◆ GetGlobalRotation()

float QMesh::GetGlobalRotation ( )
inline

Returns the global rotation of the mesh.

◆ GetInitialArea()

float QMesh::GetInitialArea ( )
inline

Returns the total area of the mesh with local positions of particles

◆ GetInitialPolygonsArea()

float QMesh::GetInitialPolygonsArea ( )
inline

Returns the total polygon area of the mesh with local positions of particles

◆ GetMatchingParticlePositions()

vector< QVector > QMesh::GetMatchingParticlePositions ( vector< QParticle * >  particleCollection,
QVector  targetPosition,
float  targetRotation 
)
static

Returns the non-deformed particle positions based on the target position and rotation. This method is also used for shape matching operations.

Parameters
particleCollectionA collection of particles
targetPositionTarget center position to transformation.
targetRotationTarget center rotation to transformation.
Returns
Returns A list of positions.

◆ GetMeshDatasFromFile()

vector< QMesh::MeshData > QMesh::GetMeshDatasFromFile ( string  filePath)
static

Returns mesh data list from a json based *.qmesh file.You can use the returned mesh data of the collection with the QWorld::CreateWithMeshData method.

Parameters
filePathThe filePath to load
Returns
vector<QMesh::MeshData> A Mesh data list.

◆ GetMeshDatasFromJsonData()

vector< QMesh::MeshData > QMesh::GetMeshDatasFromJsonData ( std::string &  jsonBasedData)
static

Returns mesh data list from a json based data.You can use the returned mesh data of the collection with the QWorld::CreateWithMeshData method.

Parameters
jsonBasedDataThe json data to parse.
Returns
vector<QMesh::MeshData> A Mesh data list.

◆ GetMinAngleConstraintOfPolygon()

float QMesh::GetMinAngleConstraintOfPolygon ( )
inline

Returns the minimum angle for the angle constraints of the polygon. If the constraints are disabled, the value will be 0. The default value is pi * 0.1.

Returns
The minimum angle value in radians of the angle constraints of the polygon.

◆ GetOwnerBody()

QBody* QMesh::GetOwnerBody ( )
inline

Returns owner body of the mesh. Owner body is the body in which the mesh is appointed.

◆ GetParticleAt()

QParticle * QMesh::GetParticleAt ( int  index)

Returns a particle at the specified index

Parameters
particleThe index of particle to get.

◆ GetParticleCount()

int QMesh::GetParticleCount ( )

Returns the total particle count in the mesh.

◆ GetParticleFromPolygon()

QParticle * QMesh::GetParticleFromPolygon ( int  index)

Returns a particle of the polygon at the specified index

Parameters
indexAn index value
Returns
QParticle* A pointer to the particle.

◆ GetParticleIndex()

int QMesh::GetParticleIndex ( QParticle particle)
inline

Returns the index of the specified particle.

Parameters
particleA particle in the mesh.
Returns
If the particle is found, it returns the index value, otherwise it returns -1.

◆ GetPolygonArea()

float QMesh::GetPolygonArea ( vector< QParticle * > &  polygonPoints,
bool  withLocalPositions = false 
)
static

Returns the area of a polygon.

Parameters
polygonPointsA collection of particle pointers of the polygon
withLocalPositionsDefines whether the calculations will be done with local positions.

◆ GetPolygonParticleCount()

int QMesh::GetPolygonParticleCount ( )

Returns the total particle count of the polygon

◆ GetPolygonsArea()

float QMesh::GetPolygonsArea ( )
inline

Returns total polygon area of the mesh with global positions of particles

◆ GetPosition()

QVector QMesh::GetPosition ( )
inline

Returns the local position of the mesh.

◆ GetRotation()

float QMesh::GetRotation ( )
inline

Returns the local rotation of the mesh.

◆ GetSpringAt()

QSpring* QMesh::GetSpringAt ( int  index)
inline

Returns the spring at the specified index.

Parameters
indexThe index of the spring to be get.

◆ GetSpringCount()

int QMesh::GetSpringCount ( )
inline

Returns the total spring count in the mesh.

◆ GetSpringIndex()

int QMesh::GetSpringIndex ( QSpring spring)
inline

Returns the index of the specified spring.

Parameters
springA spring in the mesh.
Returns
If the spring is found, it returns the index value, otherwise it returns -1.

◆ GetSubConvexPolygonAt()

vector<QParticle*>& QMesh::GetSubConvexPolygonAt ( int  index)
inline

Returns polygon at the specified index

Parameters
indexThe index of the polygon to get.

◆ GetSubConvexPolygonCount()

int QMesh::GetSubConvexPolygonCount ( )
inline

Returns the total polygon count in the mesh.

◆ GetUVMapAt()

vector<int> QMesh::GetUVMapAt ( int  index)
inline

Returns the UV map at the specified index.

Parameters
indexThe index of the UV map to be get.

◆ GetUVMapCount()

int QMesh::GetUVMapCount ( )
inline

Returns the count of the UV maps .

◆ RemoveClosedPolygonAt()

QMesh* QMesh::RemoveClosedPolygonAt ( int  index)

Removes a polygon from the mesh at the specified index.

Parameters
indexThe index of the polygon.
Returns
QMesh* A pointer to mesh itself.

◆ RemoveMatchingSprings()

QMesh * QMesh::RemoveMatchingSprings ( QParticle particle)

Removes the springs that contain the specified particle.

Parameters
particleA particle to be matched.
Returns
QMesh* A pointer to mesh itself.

◆ RemoveMatchingUVMaps()

QMesh * QMesh::RemoveMatchingUVMaps ( int  particleIndex)

Removes the UV maps or UV map particle reference that contain the specified particle index.

Parameters
particleIndexA particle index to be matched.
Returns
QMesh* A pointer to mesh itself.

◆ RemoveParticle()

QMesh * QMesh::RemoveParticle ( QParticle particle)

Removes a particle from the mesh

Parameters
particleA particle to be removed.
Returns
QMesh* A pointer to mesh itself.

◆ RemoveParticleAt()

QMesh * QMesh::RemoveParticleAt ( int  index)

Removes the particle from the mesh at the specified index.

Parameters
particleThe index of particle to be removed.
Returns
QMesh* A pointer to mesh itself.

◆ RemoveParticleFromPolygon()

QMesh * QMesh::RemoveParticleFromPolygon ( QParticle particle)

Removes a particle from to the polygon.

Parameters
particleA pointer to a particle
Returns
QMesh* A pointer to mesh itself.
Note
A polygon requires at least 3 particles. Please check the number of particles in the polygon before removing any particle from it.

◆ RemoveParticleFromPolygonAt()

QMesh * QMesh::RemoveParticleFromPolygonAt ( int  index)

Removes a particle from to the polygon at the specified index.

Parameters
indexAn index value
Returns
QMesh* A pointer to mesh itself.
Note
A polygon requires at least 3 particles. Please check the number of particles in the polygon before removing any particle from it.

◆ RemovePolygon()

QMesh * QMesh::RemovePolygon ( )

Removes the polygon from the mesh.

Returns
QMesh* A pointer to mesh itself.

◆ RemoveSpring()

QMesh * QMesh::RemoveSpring ( QSpring spring)

Removes a spring to the mesh

Parameters
springA spring to be removed.
Returns
QMesh* A pointer to mesh itself.

◆ RemoveSpringAt()

QMesh * QMesh::RemoveSpringAt ( int  index)

Removes a spring to the mesh at the specified index.

Parameters
indexThe index of the spring to be removed.
Returns
QMesh* A pointer to mesh itself.

◆ RemoveUVMapAt()

QMesh * QMesh::RemoveUVMapAt ( int  index)

Removes the springs that contain the specified particle.

Parameters
indexThe index of the UV map to be removed.
Returns
QMesh* A pointer to mesh itself.

◆ SetGlobalPosition()

QMesh* QMesh::SetGlobalPosition ( QVector  value)
inline

Sets the global position of the mesh

Parameters
valueThe global position value to set.
Returns
QMesh* A pointer to mesh itself.

◆ SetMinAngleConstraintOfPolygon()

QMesh* QMesh::SetMinAngleConstraintOfPolygon ( float  radian)
inline

Sets the minimum angle for the angle constraints of the polygon. If the value is 0, it means constraints are disabled. The default value is pi * 0.1.

Parameters
radianThe minimum angle value in radians.
Returns
QMesh* A pointer to mesh itself.

◆ SetPolygon()

QMesh * QMesh::SetPolygon ( vector< QParticle * >  polygonParticles)

Sets a polygon to the mesh

Parameters
polygonParticlesA particle pointers collection of the polygon.
Returns
QMesh* A pointer to mesh itself.

◆ SetPosition()

QMesh* QMesh::SetPosition ( QVector  value)
inline

Sets the local position of the mesh

Parameters
valueThe local position value to set.
Returns
QMesh* A pointer to mesh itself.

◆ SetRotation()

QMesh* QMesh::SetRotation ( float  value)
inline

Sets the rotation of the mesh

Parameters
valueThe rotation value to set.
Returns
QMesh* A pointer to mesh itself.

The documentation for this struct was generated from the following files: