mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 06:34:36 +00:00
initial commit jolt
This commit is contained in:
parent
0c2aa5328c
commit
8acf7da95b
1086 changed files with 214612 additions and 4 deletions
|
|
@ -0,0 +1,43 @@
|
|||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <Jolt/Jolt.h>
|
||||
|
||||
#include <Jolt/TriangleSplitter/TriangleSplitterMean.h>
|
||||
|
||||
JPH_NAMESPACE_BEGIN
|
||||
|
||||
TriangleSplitterMean::TriangleSplitterMean(const VertexList &inVertices, const IndexedTriangleList &inTriangles) :
|
||||
TriangleSplitter(inVertices, inTriangles)
|
||||
{
|
||||
}
|
||||
|
||||
bool TriangleSplitterMean::Split(const Range &inTriangles, Range &outLeft, Range &outRight)
|
||||
{
|
||||
const uint *begin = mSortedTriangleIdx.data() + inTriangles.mBegin;
|
||||
const uint *end = mSortedTriangleIdx.data() + inTriangles.mEnd;
|
||||
|
||||
// Calculate mean value for these triangles
|
||||
Vec3 mean = Vec3::sZero();
|
||||
for (const uint *t = begin; t < end; ++t)
|
||||
mean += Vec3::sLoadFloat3Unsafe(mCentroids[*t]);
|
||||
mean *= 1.0f / inTriangles.Count();
|
||||
|
||||
// Calculate deviation
|
||||
Vec3 deviation = Vec3::sZero();
|
||||
for (const uint *t = begin; t < end; ++t)
|
||||
{
|
||||
Vec3 delta = Vec3::sLoadFloat3Unsafe(mCentroids[*t]) - mean;
|
||||
deviation += delta * delta;
|
||||
}
|
||||
deviation *= 1.0f / inTriangles.Count();
|
||||
|
||||
// Calculate split plane
|
||||
uint dimension = deviation.GetHighestComponentIndex();
|
||||
float split = mean[dimension];
|
||||
|
||||
return SplitInternal(inTriangles, dimension, split, outLeft, outRight);
|
||||
}
|
||||
|
||||
JPH_NAMESPACE_END
|
||||
Loading…
Add table
Add a link
Reference in a new issue