consistency
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <bounce/dynamics/cloth/spring_force.h>
|
||||
#include <bounce/dynamics/cloth/cloth_solver.h>
|
||||
#include <bounce/dynamics/world.h>
|
||||
#include <bounce/dynamics/world_listeners.h>
|
||||
#include <bounce/dynamics/body.h>
|
||||
#include <bounce/dynamics/shapes/shape.h>
|
||||
#include <bounce/collision/collision.h>
|
||||
@@ -347,15 +348,38 @@ void b3Cloth::ComputeMass()
|
||||
}
|
||||
}
|
||||
|
||||
bool b3Cloth::RayCast(b3ClothRayCastOutput* output, const b3RayCastInput* input) const
|
||||
void b3Cloth::RayCast(b3RayCastListener* listener, const b3RayCastInput* input) const
|
||||
{
|
||||
for (u32 i = 0; i < m_mesh->triangleCount; ++i)
|
||||
{
|
||||
b3ClothRayCastSingleOutput subOutput;
|
||||
if (RayCast(&subOutput, input, i))
|
||||
{
|
||||
float32 newFraction = listener->ReportCloth(subOutput.cloth, subOutput.point, subOutput.normal, subOutput.fraction, subOutput.triangle);
|
||||
|
||||
if (newFraction == 0.0f)
|
||||
{
|
||||
// The client has stopped the query.
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool b3Cloth::RayCastSingle(b3ClothRayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const
|
||||
{
|
||||
b3RayCastInput input;
|
||||
input.p1 = p1;
|
||||
input.p2 = p2;
|
||||
input.maxFraction = 1.0f;
|
||||
|
||||
output->triangle = ~0;
|
||||
output->fraction = input->maxFraction;
|
||||
output->fraction = B3_MAX_FLOAT;
|
||||
|
||||
for (u32 i = 0; i < m_mesh->triangleCount; ++i)
|
||||
{
|
||||
b3ClothRayCastOutput subOutput;
|
||||
if (RayCast(&subOutput, input, i))
|
||||
b3ClothRayCastSingleOutput subOutput;
|
||||
if (RayCast(&subOutput, &input, i))
|
||||
{
|
||||
if (subOutput.fraction < output->fraction)
|
||||
{
|
||||
@@ -372,7 +396,7 @@ bool b3Cloth::RayCast(b3ClothRayCastOutput* output, const b3RayCastInput* input)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool b3Cloth::RayCast(b3ClothRayCastOutput* output, const b3RayCastInput* input, u32 triangleIndex) const
|
||||
bool b3Cloth::RayCast(b3ClothRayCastSingleOutput* output, const b3RayCastInput* input, u32 triangleIndex) const
|
||||
{
|
||||
B3_ASSERT(triangleIndex < m_mesh->triangleCount);
|
||||
b3ClothMeshTriangle* triangle = m_mesh->triangles + triangleIndex;
|
||||
|
@@ -24,22 +24,7 @@
|
||||
|
||||
void b3FrictionForce::Apply(const b3ClothSolverData* data)
|
||||
{
|
||||
b3DenseVec3& v = *data->v;
|
||||
b3DenseVec3& f = *data->f;
|
||||
b3SparseSymMat33& dfdv = *data->dfdv;
|
||||
|
||||
u32 i = m_p->m_solverId;
|
||||
|
||||
if (m_kd > 0.0f)
|
||||
{
|
||||
f[i] += -m_kd * v[i];
|
||||
|
||||
b3Mat33 I; I.SetIdentity();
|
||||
|
||||
b3Mat33 Jv = -m_kd * I;
|
||||
|
||||
dfdv(i, i) += Jv;
|
||||
}
|
||||
// TODO
|
||||
}
|
||||
|
||||
b3Particle::b3Particle(const b3ParticleDef& def, b3Cloth* cloth)
|
||||
|
@@ -378,7 +378,7 @@ void b3World::StepCloth(float32 dt)
|
||||
}
|
||||
}
|
||||
|
||||
struct b3RayCastCallback
|
||||
struct b3ShapeRayCastCallback
|
||||
{
|
||||
float32 Report(const b3RayCastInput& input, u32 proxyId)
|
||||
{
|
||||
@@ -413,20 +413,20 @@ struct b3RayCastCallback
|
||||
const b3BroadPhase* broadPhase;
|
||||
};
|
||||
|
||||
void b3World::RayCast(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const
|
||||
void b3World::RayCastShape(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const
|
||||
{
|
||||
b3RayCastInput input;
|
||||
input.p1 = p1;
|
||||
input.p2 = p2;
|
||||
input.maxFraction = 1.0f;
|
||||
|
||||
b3RayCastCallback callback;
|
||||
b3ShapeRayCastCallback callback;
|
||||
callback.listener = listener;
|
||||
callback.broadPhase = &m_contactMan.m_broadPhase;
|
||||
m_contactMan.m_broadPhase.RayCast(&callback, input);
|
||||
}
|
||||
|
||||
struct b3RayCastSingleCallback
|
||||
struct b3ShapeRayCastSingleCallback
|
||||
{
|
||||
float32 Report(const b3RayCastInput& input, u32 proxyId)
|
||||
{
|
||||
@@ -458,14 +458,14 @@ struct b3RayCastSingleCallback
|
||||
const b3BroadPhase* broadPhase;
|
||||
};
|
||||
|
||||
bool b3World::RayCastSingle(b3RayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const
|
||||
bool b3World::RayCastSingleShape(b3ShapeRayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const
|
||||
{
|
||||
b3RayCastInput input;
|
||||
input.p1 = p1;
|
||||
input.p2 = p2;
|
||||
input.maxFraction = 1.0f;
|
||||
|
||||
b3RayCastSingleCallback callback;
|
||||
b3ShapeRayCastSingleCallback callback;
|
||||
callback.shape0 = NULL;
|
||||
callback.output0.fraction = B3_MAX_FLOAT;
|
||||
callback.broadPhase = &m_contactMan.m_broadPhase;
|
||||
@@ -491,6 +491,46 @@ bool b3World::RayCastSingle(b3RayCastSingleOutput* output, const b3Vec3& p1, con
|
||||
return false;
|
||||
}
|
||||
|
||||
void b3World::RayCastCloth(b3RayCastListener* listener, const b3Vec3& p1, const b3Vec3& p2) const
|
||||
{
|
||||
b3RayCastInput input;
|
||||
input.p1 = p1;
|
||||
input.p2 = p2;
|
||||
input.maxFraction = B3_MAX_FLOAT;
|
||||
|
||||
for (b3Cloth* c = m_clothList.m_head; c; c = c->m_next)
|
||||
{
|
||||
c->RayCast(listener, &input);
|
||||
}
|
||||
}
|
||||
|
||||
bool b3World::RayCastSingleCloth(b3ClothRayCastSingleOutput* output, const b3Vec3& p1, const b3Vec3& p2) const
|
||||
{
|
||||
output->cloth = NULL;
|
||||
output->triangle = ~0;
|
||||
output->fraction = B3_MAX_FLOAT;
|
||||
|
||||
for (b3Cloth* c = m_clothList.m_head; c; c = c->m_next)
|
||||
{
|
||||
b3ClothRayCastSingleOutput subOutput;
|
||||
if (c->RayCastSingle(&subOutput, p1, p2))
|
||||
{
|
||||
if (subOutput.fraction < output->fraction)
|
||||
{
|
||||
subOutput.cloth = c;
|
||||
*output = subOutput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (output->cloth != NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
struct b3QueryAABBCallback
|
||||
{
|
||||
bool Report(u32 proxyID)
|
||||
|
Reference in New Issue
Block a user