aboutsummaryrefslogtreecommitdiff
path: root/NvCloth/samples/SampleBase/utils
diff options
context:
space:
mode:
authorMarijn Tamis <[email protected]>2017-10-20 14:30:56 +0200
committerMarijn Tamis <[email protected]>2017-10-20 14:36:12 +0200
commitfabb251458f4a2d6d4f87dd36038fac2774b378c (patch)
tree68a4a0ecd940dc949e0477d521d8c159968cfcd5 /NvCloth/samples/SampleBase/utils
parentNvCloth 1.1.2 Release. (22576033) (diff)
downloadnvcloth-1.1.3.tar.xz
nvcloth-1.1.3.zip
NvCloth 1.1.3 Release. (23014067)v1.1.3
Diffstat (limited to 'NvCloth/samples/SampleBase/utils')
-rw-r--r--NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp1
-rw-r--r--NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h4
-rw-r--r--NvCloth/samples/SampleBase/utils/JobManager.cpp5
-rw-r--r--NvCloth/samples/SampleBase/utils/MeshGenerator.cpp81
4 files changed, 66 insertions, 25 deletions
diff --git a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp
index 49f9ada..495ba15 100644
--- a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp
+++ b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.cpp
@@ -72,6 +72,7 @@ GeneratePlaneCloth(x,y,2,2) generates:
pos = physx::PxVec3(((float)x / (float)segmentsX) * width,
((float)(y&2) / (float)segmentsY) * height,
((float)((y+1)&~1) / (float)segmentsY) * height);
+ break;
default:
pos = physx::PxVec3(((float)x / (float)segmentsX) * width,
0.f,
diff --git a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h
index d6cf0fd..1db4115 100644
--- a/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h
+++ b/NvCloth/samples/SampleBase/utils/ClothMeshGenerator.h
@@ -25,7 +25,7 @@ struct ClothMeshData
a(_a), b(_b), c(_c){}
uint32_t a, b, c;
- Triangle operator+(uint32_t offset)const { return Triangle(a + offset, b + offset, c + offset); };
+ Triangle operator+(uint32_t offset)const { return Triangle(a + offset, b + offset, c + offset); }
};
struct Quad
{
@@ -34,7 +34,7 @@ struct ClothMeshData
a(_a), b(_b), c(_c), d(_d){}
uint32_t a, b, c, d;
- Quad operator+(uint32_t offset)const { return Quad(a + offset, b + offset, c + offset, d + offset); };
+ Quad operator+(uint32_t offset)const { return Quad(a + offset, b + offset, c + offset, d + offset); }
};
std::vector<physx::PxVec3> mVertices;
std::vector<physx::PxVec2> mUvs;
diff --git a/NvCloth/samples/SampleBase/utils/JobManager.cpp b/NvCloth/samples/SampleBase/utils/JobManager.cpp
index 093db60..2a18d1c 100644
--- a/NvCloth/samples/SampleBase/utils/JobManager.cpp
+++ b/NvCloth/samples/SampleBase/utils/JobManager.cpp
@@ -124,13 +124,16 @@ void MultithreadedSolverHelper::StartSimulation(float dt)
for (int j = 0; j < mSolver->getSimulationChunkCount(); j++)
mSimulationChunkJobs[j].Reset();
}
+
mStartSimulationJob.Reset();
mEndSimulationJob.Reset(mSolver->getSimulationChunkCount());
mStartSimulationJob.RemoveReference();
-
}
void MultithreadedSolverHelper::WaitForSimulation()
{
+ if (mSolver->getSimulationChunkCount() == 0)
+ return;
+
mEndSimulationJob.Wait();
} \ No newline at end of file
diff --git a/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp b/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp
index 857daed..5541cc3 100644
--- a/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp
+++ b/NvCloth/samples/SampleBase/utils/MeshGenerator.cpp
@@ -348,6 +348,20 @@ Mesh generateIcosahedron(float radius, int subdivisions)
return mesh;
}
+namespace
+{
+ physx::PxVec3 IntersectSpheres(float* circleRadius, physx::PxVec3 aCenter, float aRadius, physx::PxVec3 bCenter, float bRadius)
+ {
+ //Intersect spheres in 2d (http://paulbourke.net/geometry/circlesphere/ Intersection of two circles)
+ float d = (aCenter - bCenter).magnitude();
+ float a = (aRadius*aRadius - bRadius*bRadius + d*d) / (2.0f*d);
+ float h = sqrtf(aRadius*aRadius - a*a);
+ physx::PxVec3 P3 = aCenter + a * (bCenter - aCenter) / d;
+ if(circleRadius) *circleRadius = h;
+ return P3;
+ }
+};
+
Mesh generateCone(physx::PxVec4 a, physx::PxVec4 b, int segments, float grow, bool correctCone)
{
Mesh mesh;
@@ -365,41 +379,64 @@ Mesh generateCone(physx::PxVec4 a, physx::PxVec4 b, int segments, float grow, bo
basis[2].normalize();
computeBasis(basis[2], &basis[0], &basis[1]);
- physx::PxVec3 pa = aCenter + aRadius*basis[0];
- physx::PxVec3 pb = bCenter + bRadius*basis[0];
- physx::PxVec3 dir = pb - pa;
-
- physx::PxVec3 n = basis[2].cross(dir);
- physx::PxVec3 n2 = dir.cross(n);
- physx::PxVec3 focusPoint = aCenter + ((pa - aCenter).dot(n2)) / basis[2].dot(n2) * basis[2];
-
if(correctCone)
{
+ //make the cone connect seamlessly to the spheres
+ {
+ //http://jwilson.coe.uga.edu/emt669/Student.Folders/Kertscher.Jeff/Essay.3/Tangents.html
+
+ //sphere a with smaller radius
+ float cRadius = aRadius - bRadius;
+ physx::PxVec3 cCenter = aCenter;
+
+ //sphere in between the a and b
+ physx::PxVec3 dCenter = (aCenter+bCenter)*0.5f;
+ float dRadius = (aCenter - bCenter).magnitude()*0.5f;
+
+ //intersection between c and d to get tangent point
+ float iRadius;
+ physx::PxVec3 iCenter = IntersectSpheres(&iRadius, dCenter, dRadius, cCenter, cRadius);
+ physx::PxVec3 iPoint = iCenter + basis[0] * iRadius; //tangent point on c
+ physx::PxVec3 offset = (iPoint - aCenter).getNormalized(); //offset direction
+
+ physx::PxVec3 aPoint = aCenter + offset*aRadius;
+ aCenter = (aPoint - aCenter).dot(basis[2])*basis[2] + aCenter;
+ aRadius = (aPoint - aCenter).magnitude();
+ physx::PxVec3 bPoint = bCenter + offset*bRadius;
+ bCenter = (bPoint - aCenter).dot(basis[2])*basis[2] + aCenter;
+ bRadius = (bPoint - bCenter).magnitude();
+
+
+ }
+
+ //old code, probably wrong
+ /*
+ physx::PxVec3 pa = aCenter + aRadius*basis[0];
+ physx::PxVec3 pb = bCenter + bRadius*basis[0];
+ physx::PxVec3 dir = pb - pa;
+
+ //construct plane containing pa and pb, with normal perpendicular to basis[0]
+ physx::PxVec3 n = basis[2].cross(dir);
+ physx::PxVec3 n2 = dir.cross(n);
+
+ //line plane intersection
+ physx::PxVec3 focusPoint = aCenter + ((pa - aCenter).dot(n2)) / basis[2].dot(n2) * basis[2];
+
{
float focusDistance = (focusPoint - aCenter).magnitude();
+ //make circle with center in mid point between focusPoint and aCenter
physx::PxVec3 cCenter = (focusPoint + aCenter)*0.5f;
float cRadius = focusDistance*0.5f;
- float d = (aCenter - cCenter).magnitude();
- float a = (aRadius*aRadius - cRadius*cRadius + d*d) / (2.0f*d);
- float h = sqrtf(aRadius*aRadius - a*a);
- physx::PxVec3 P3 = aCenter + a * (cCenter - aCenter) / d;
- aCenter = P3;
- aRadius = h;
+ aCenter = IntersectSpheres(&aRadius, aCenter, aRadius, cCenter, cRadius);
}
{
float focusDistance = (focusPoint - bCenter).magnitude();
physx::PxVec3 cCenter = (focusPoint + bCenter)*0.5f;
float cRadius = focusDistance*0.5f;
- float d = (bCenter - cCenter).magnitude();
- float a = (bRadius*bRadius - cRadius*cRadius + d*d) / (2.0f*d);
- float h = sqrtf(bRadius*bRadius - a*a);
- physx::PxVec3 P3 = bCenter + a * (cCenter - bCenter) / d;
-
- bCenter = P3;
- bRadius = h;
- }
+ bCenter = IntersectSpheres(&bRadius, bCenter, bRadius, cCenter, cRadius);
+ }*/
}