Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
IndexedTriangle.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
10
13{
14public:
16
19 IndexedTriangleNoMaterial(uint32 inI1, uint32 inI2, uint32 inI3) { mIdx[0] = inI1; mIdx[1] = inI2; mIdx[2] = inI3; }
20
22 bool operator == (const IndexedTriangleNoMaterial &inRHS) const
23 {
24 return mIdx[0] == inRHS.mIdx[0] && mIdx[1] == inRHS.mIdx[1] && mIdx[2] == inRHS.mIdx[2];
25 }
26
28 bool IsEquivalent(const IndexedTriangleNoMaterial &inRHS) const
29 {
30 return (mIdx[0] == inRHS.mIdx[0] && mIdx[1] == inRHS.mIdx[1] && mIdx[2] == inRHS.mIdx[2])
31 || (mIdx[0] == inRHS.mIdx[1] && mIdx[1] == inRHS.mIdx[2] && mIdx[2] == inRHS.mIdx[0])
32 || (mIdx[0] == inRHS.mIdx[2] && mIdx[1] == inRHS.mIdx[0] && mIdx[2] == inRHS.mIdx[1]);
33 }
34
36 bool IsOpposite(const IndexedTriangleNoMaterial &inRHS) const
37 {
38 return (mIdx[0] == inRHS.mIdx[0] && mIdx[1] == inRHS.mIdx[2] && mIdx[2] == inRHS.mIdx[1])
39 || (mIdx[0] == inRHS.mIdx[1] && mIdx[1] == inRHS.mIdx[0] && mIdx[2] == inRHS.mIdx[2])
40 || (mIdx[0] == inRHS.mIdx[2] && mIdx[1] == inRHS.mIdx[1] && mIdx[2] == inRHS.mIdx[0]);
41 }
42
44 bool IsDegenerate() const
45 {
46 return mIdx[0] == mIdx[1] || mIdx[1] == mIdx[2] || mIdx[2] == mIdx[0];
47 }
48
50 void Rotate()
51 {
52 uint32 tmp = mIdx[0];
53 mIdx[0] = mIdx[1];
54 mIdx[1] = mIdx[2];
55 mIdx[2] = tmp;
56 }
57
59 Vec3 GetCentroid(const VertexList &inVertices) const
60 {
61 return (Vec3(inVertices[mIdx[0]]) + Vec3(inVertices[mIdx[1]]) + Vec3(inVertices[mIdx[2]])) / 3.0f;
62 }
63
65};
66
69{
70public:
72
74 IndexedTriangle(uint32 inI1, uint32 inI2, uint32 inI3, uint32 inMaterialIndex) : IndexedTriangleNoMaterial(inI1, inI2, inI3), mMaterialIndex(inMaterialIndex) { }
75
77 bool operator == (const IndexedTriangle &inRHS) const
78 {
80 }
81
84 {
85 if (mIdx[0] < mIdx[1])
86 {
87 if (mIdx[0] < mIdx[2])
88 return IndexedTriangle(mIdx[0], mIdx[1], mIdx[2], mMaterialIndex); // 0 is smallest
89 else
90 return IndexedTriangle(mIdx[2], mIdx[0], mIdx[1], mMaterialIndex); // 2 is smallest
91 }
92 else
93 {
94 if (mIdx[1] < mIdx[2])
95 return IndexedTriangle(mIdx[1], mIdx[2], mIdx[0], mMaterialIndex); // 1 is smallest
96 else
97 return IndexedTriangle(mIdx[2], mIdx[0], mIdx[1], mMaterialIndex); // 2 is smallest
98 }
99 }
100
102};
103
106
108
109// Create a std::hash for IndexedTriangleNoMaterial and IndexedTriangle
110JPH_MAKE_HASHABLE(JPH::IndexedTriangleNoMaterial, t.mIdx[0], t.mIdx[1], t.mIdx[2])
111JPH_MAKE_HASHABLE(JPH::IndexedTriangle, t.mIdx[0], t.mIdx[1], t.mIdx[2], t.mMaterialIndex)
uint32_t uint32
Definition: Core.h:312
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
Array< Float3 > VertexList
Definition: Float3.h:42
#define JPH_MAKE_HASHABLE(type,...)
Definition: HashCombine.h:87
Array< IndexedTriangleNoMaterial > IndexedTriangleNoMaterialList
Definition: IndexedTriangle.h:104
Array< IndexedTriangle > IndexedTriangleList
Definition: IndexedTriangle.h:105
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
Triangle with 32-bit indices and material index.
Definition: IndexedTriangle.h:69
uint32 mMaterialIndex
Definition: IndexedTriangle.h:101
IndexedTriangle(uint32 inI1, uint32 inI2, uint32 inI3, uint32 inMaterialIndex)
Constructor.
Definition: IndexedTriangle.h:74
bool operator==(const IndexedTriangle &inRHS) const
Check if two triangles are identical.
Definition: IndexedTriangle.h:77
IndexedTriangle GetLowestIndexFirst() const
Rotate the vertices so that the lowest vertex becomes the first. This does not change the represented...
Definition: IndexedTriangle.h:83
Triangle with 32-bit indices.
Definition: IndexedTriangle.h:13
bool IsDegenerate() const
Check if triangle is degenerate.
Definition: IndexedTriangle.h:44
JPH_OVERRIDE_NEW_DELETE IndexedTriangleNoMaterial()=default
Constructor.
Vec3 GetCentroid(const VertexList &inVertices) const
Get center of triangle.
Definition: IndexedTriangle.h:59
uint32 mIdx[3]
Definition: IndexedTriangle.h:64
void Rotate()
Rotate the vertices so that the second vertex becomes first etc. This does not change the represented...
Definition: IndexedTriangle.h:50
bool IsEquivalent(const IndexedTriangleNoMaterial &inRHS) const
Check if two triangles are equivalent (using the same vertices)
Definition: IndexedTriangle.h:28
bool IsOpposite(const IndexedTriangleNoMaterial &inRHS) const
Check if two triangles are opposite (using the same vertices but in opposing order)
Definition: IndexedTriangle.h:36
IndexedTriangleNoMaterial(uint32 inI1, uint32 inI2, uint32 inI3)
Definition: IndexedTriangle.h:19
bool operator==(const IndexedTriangleNoMaterial &inRHS) const
Check if two triangles are identical.
Definition: IndexedTriangle.h:22
Definition: Vec3.h:16