Small optimizations
This commit is contained in:
parent
d4be363e7c
commit
85103f7027
|
@ -217,17 +217,15 @@ RP3D_FORCE_INLINE HalfEdgeStructure::Vertex BoxShape::getVertex(uint vertexIndex
|
||||||
RP3D_FORCE_INLINE Vector3 BoxShape::getVertexPosition(uint vertexIndex) const {
|
RP3D_FORCE_INLINE Vector3 BoxShape::getVertexPosition(uint vertexIndex) const {
|
||||||
assert(vertexIndex < getNbVertices());
|
assert(vertexIndex < getNbVertices());
|
||||||
|
|
||||||
Vector3 extent = getHalfExtents();
|
|
||||||
|
|
||||||
switch(vertexIndex) {
|
switch(vertexIndex) {
|
||||||
case 0: return Vector3(-extent.x, -extent.y, extent.z);
|
case 0: return Vector3(-mHalfExtents.x, -mHalfExtents.y, mHalfExtents.z);
|
||||||
case 1: return Vector3(extent.x, -extent.y, extent.z);
|
case 1: return Vector3(mHalfExtents.x, -mHalfExtents.y, mHalfExtents.z);
|
||||||
case 2: return Vector3(extent.x, extent.y, extent.z);
|
case 2: return Vector3(mHalfExtents.x, mHalfExtents.y, mHalfExtents.z);
|
||||||
case 3: return Vector3(-extent.x, extent.y, extent.z);
|
case 3: return Vector3(-mHalfExtents.x, mHalfExtents.y, mHalfExtents.z);
|
||||||
case 4: return Vector3(-extent.x, -extent.y, -extent.z);
|
case 4: return Vector3(-mHalfExtents.x, -mHalfExtents.y, -mHalfExtents.z);
|
||||||
case 5: return Vector3(extent.x, -extent.y, -extent.z);
|
case 5: return Vector3(mHalfExtents.x, -mHalfExtents.y, -mHalfExtents.z);
|
||||||
case 6: return Vector3(extent.x, extent.y, -extent.z);
|
case 6: return Vector3(mHalfExtents.x, mHalfExtents.y, -mHalfExtents.z);
|
||||||
case 7: return Vector3(-extent.x, extent.y, -extent.z);
|
case 7: return Vector3(-mHalfExtents.x, mHalfExtents.y, -mHalfExtents.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
|
@ -99,6 +99,29 @@ RP3D_FORCE_INLINE bool ConvexPolyhedronShape::isPolyhedron() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Find and return the index of the polyhedron face with the most anti-parallel face
|
||||||
|
// normal given a direction vector. This is used to find the incident face on
|
||||||
|
// a polyhedron of a given reference face of another polyhedron
|
||||||
|
RP3D_FORCE_INLINE uint ConvexPolyhedronShape::findMostAntiParallelFace(const Vector3& direction) const {
|
||||||
|
|
||||||
|
decimal minDotProduct = DECIMAL_LARGEST;
|
||||||
|
uint mostAntiParallelFace = 0;
|
||||||
|
|
||||||
|
// For each face of the polyhedron
|
||||||
|
const uint32 nbFaces = getNbFaces();
|
||||||
|
for (uint32 i=0; i < nbFaces; i++) {
|
||||||
|
|
||||||
|
// Get the face normal
|
||||||
|
const decimal dotProduct = getFaceNormal(i).dot(direction);
|
||||||
|
if (dotProduct < minDotProduct) {
|
||||||
|
minDotProduct = dotProduct;
|
||||||
|
mostAntiParallelFace = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mostAntiParallelFace;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,26 +35,3 @@ ConvexPolyhedronShape::ConvexPolyhedronShape(CollisionShapeName name, MemoryAllo
|
||||||
: ConvexShape(name, CollisionShapeType::CONVEX_POLYHEDRON, allocator) {
|
: ConvexShape(name, CollisionShapeType::CONVEX_POLYHEDRON, allocator) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find and return the index of the polyhedron face with the most anti-parallel face
|
|
||||||
// normal given a direction vector. This is used to find the incident face on
|
|
||||||
// a polyhedron of a given reference face of another polyhedron
|
|
||||||
uint ConvexPolyhedronShape::findMostAntiParallelFace(const Vector3& direction) const {
|
|
||||||
|
|
||||||
decimal minDotProduct = DECIMAL_LARGEST;
|
|
||||||
uint mostAntiParallelFace = 0;
|
|
||||||
|
|
||||||
// For each face of the polyhedron
|
|
||||||
uint32 nbFaces = getNbFaces();
|
|
||||||
for (uint32 i=0; i < nbFaces; i++) {
|
|
||||||
|
|
||||||
// Get the face normal
|
|
||||||
const decimal dotProduct = getFaceNormal(i).dot(direction);
|
|
||||||
if (dotProduct < minDotProduct) {
|
|
||||||
minDotProduct = dotProduct;
|
|
||||||
mostAntiParallelFace = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mostAntiParallelFace;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user