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 constexpr IndexedTriangleNoMaterial(uint32 inI1, uint32 inI2, uint32 inI3) : mIdx { inI1, inI2, 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 VertexList &inVertices) const
45 {
46 Vec3 v0(inVertices[mIdx[0]]);
47 Vec3 v1(inVertices[mIdx[1]]);
48 Vec3 v2(inVertices[mIdx[2]]);
49
50 return (v1 - v0).Cross(v2 - v0).IsNearZero();
51 }
52
54 void Rotate()
55 {
56 uint32 tmp = mIdx[0];
57 mIdx[0] = mIdx[1];
58 mIdx[1] = mIdx[2];
59 mIdx[2] = tmp;
60 }
61
63 Vec3 GetCentroid(const VertexList &inVertices) const
64 {
65 return (Vec3(inVertices[mIdx[0]]) + Vec3(inVertices[mIdx[1]]) + Vec3(inVertices[mIdx[2]])) / 3.0f;
66 }
67
69};
70
73{
74public:
76
78 constexpr IndexedTriangle(uint32 inI1, uint32 inI2, uint32 inI3, uint32 inMaterialIndex, uint inUserData = 0) : IndexedTriangleNoMaterial(inI1, inI2, inI3), mMaterialIndex(inMaterialIndex), mUserData(inUserData) { }
79
81 bool operator == (const IndexedTriangle &inRHS) const
82 {
84 }
85
88 {
89 if (mIdx[0] < mIdx[1])
90 {
91 if (mIdx[0] < mIdx[2])
92 return IndexedTriangle(mIdx[0], mIdx[1], mIdx[2], mMaterialIndex, mUserData); // 0 is smallest
93 else
94 return IndexedTriangle(mIdx[2], mIdx[0], mIdx[1], mMaterialIndex, mUserData); // 2 is smallest
95 }
96 else
97 {
98 if (mIdx[1] < mIdx[2])
99 return IndexedTriangle(mIdx[1], mIdx[2], mIdx[0], mMaterialIndex, mUserData); // 1 is smallest
100 else
101 return IndexedTriangle(mIdx[2], mIdx[0], mIdx[1], mMaterialIndex, mUserData); // 2 is smallest
102 }
103 }
104
107};
108
111
113
114// Create a std::hash/JPH::Hash for IndexedTriangleNoMaterial and IndexedTriangle
115JPH_MAKE_HASHABLE(JPH::IndexedTriangleNoMaterial, t.mIdx[0], t.mIdx[1], t.mIdx[2])
116JPH_MAKE_HASHABLE(JPH::IndexedTriangle, t.mIdx[0], t.mIdx[1], t.mIdx[2], t.mMaterialIndex, t.mUserData)
unsigned int uint
Definition Core.h:446
#define JPH_NAMESPACE_END
Definition Core.h:379
std::uint32_t uint32
Definition Core.h:449
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_MAKE_HASHABLE(type,...)
Definition HashCombine.h:191
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
Triangle with 32-bit indices and material index.
Definition IndexedTriangle.h:73
uint32 mUserData
User data that can be used for anything by the application, e.g. for tracking the original index of t...
Definition IndexedTriangle.h:106
uint32 mMaterialIndex
Definition IndexedTriangle.h:105
bool operator==(const IndexedTriangle &inRHS) const
Check if two triangles are identical.
Definition IndexedTriangle.h:81
IndexedTriangle GetLowestIndexFirst() const
Rotate the vertices so that the lowest vertex becomes the first. This does not change the represented...
Definition IndexedTriangle.h:87
constexpr IndexedTriangle(uint32 inI1, uint32 inI2, uint32 inI3, uint32 inMaterialIndex, uint inUserData=0)
Constructor.
Definition IndexedTriangle.h:78
Triangle with 32-bit indices.
Definition IndexedTriangle.h:13
JPH_OVERRIDE_NEW_DELETE IndexedTriangleNoMaterial()=default
Constructor.
Vec3 GetCentroid(const VertexList &inVertices) const
Get center of triangle.
Definition IndexedTriangle.h:63
uint32 mIdx[3]
Definition IndexedTriangle.h:68
bool IsDegenerate(const VertexList &inVertices) const
Check if triangle is degenerate.
Definition IndexedTriangle.h:44
void Rotate()
Rotate the vertices so that the second vertex becomes first etc. This does not change the represented...
Definition IndexedTriangle.h:54
constexpr IndexedTriangleNoMaterial(uint32 inI1, uint32 inI2, uint32 inI3)
Definition IndexedTriangle.h:19
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
bool operator==(const IndexedTriangleNoMaterial &inRHS) const
Check if two triangles are identical.
Definition IndexedTriangle.h:22
Definition Vec3.h:17