Put forces into a folder. Added soft b3MouseForce
This commit is contained in:
@ -20,10 +20,12 @@
|
||||
|
||||
b3ClothDragger::b3ClothDragger(b3Ray3* ray, b3Cloth* cloth)
|
||||
{
|
||||
m_spring = false;
|
||||
m_staticDrag = true;
|
||||
m_ray = ray;
|
||||
m_cloth = cloth;
|
||||
m_triangle = nullptr;
|
||||
m_km = 10000.0f;
|
||||
m_kd = 0.0f;
|
||||
}
|
||||
|
||||
b3ClothDragger::~b3ClothDragger()
|
||||
@ -42,7 +44,8 @@ bool b3ClothDragger::StartDragging()
|
||||
}
|
||||
|
||||
m_mesh = m_cloth->GetMesh();
|
||||
m_triangle = m_mesh->triangles + rayOut.triangle;
|
||||
m_triangleIndex = rayOut.triangle;
|
||||
m_triangle = m_mesh->triangles + m_triangleIndex;
|
||||
m_x = rayOut.fraction;
|
||||
|
||||
b3Particle* p1 = m_cloth->GetParticle(m_triangle->v1);
|
||||
@ -68,42 +71,7 @@ bool b3ClothDragger::StartDragging()
|
||||
m_u = m_v = 0.0f;
|
||||
}
|
||||
|
||||
if (m_spring)
|
||||
{
|
||||
b3ParticleDef pd;
|
||||
pd.type = e_staticParticle;
|
||||
pd.position = B;
|
||||
|
||||
m_particle = m_cloth->CreateParticle(pd);
|
||||
|
||||
{
|
||||
b3SpringForceDef sfd;
|
||||
sfd.p1 = m_particle;
|
||||
sfd.p2 = p1;
|
||||
sfd.restLength = 0.0f;
|
||||
sfd.structural = 10000.0f;
|
||||
m_s1 = (b3SpringForce*)m_cloth->CreateForce(sfd);
|
||||
}
|
||||
|
||||
{
|
||||
b3SpringForceDef sfd;
|
||||
sfd.p1 = m_particle;
|
||||
sfd.p2 = p2;
|
||||
sfd.restLength = 0.0f;
|
||||
sfd.structural = 10000.0f;
|
||||
m_s2 = (b3SpringForce*)m_cloth->CreateForce(sfd);
|
||||
}
|
||||
|
||||
{
|
||||
b3SpringForceDef sfd;
|
||||
sfd.p1 = m_particle;
|
||||
sfd.p2 = p3;
|
||||
sfd.restLength = 0.0f;
|
||||
sfd.structural = 10000.0f;
|
||||
m_s3 = (b3SpringForce*)m_cloth->CreateForce(sfd);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (m_staticDrag)
|
||||
{
|
||||
m_t1 = p1->GetType();
|
||||
p1->SetType(e_staticParticle);
|
||||
@ -114,6 +82,27 @@ bool b3ClothDragger::StartDragging()
|
||||
m_t3 = p3->GetType();
|
||||
p3->SetType(e_staticParticle);
|
||||
}
|
||||
else
|
||||
{
|
||||
b3ParticleDef pd;
|
||||
pd.type = e_staticParticle;
|
||||
pd.position = GetPointA();
|
||||
|
||||
m_particle = m_cloth->CreateParticle(pd);
|
||||
|
||||
b3ClothTriangle* triangle = m_cloth->GetTriangle(m_triangleIndex);
|
||||
|
||||
b3MouseForceDef def;
|
||||
def.particle = m_particle;
|
||||
def.triangle = triangle;
|
||||
def.w2 = m_u;
|
||||
def.w3 = m_v;
|
||||
def.w4 = (1.0f - m_u - m_v);
|
||||
def.mouse = m_km;
|
||||
def.damping = m_kd;
|
||||
|
||||
m_mf = (b3MouseForce*)m_cloth->CreateForce(def);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -127,11 +116,7 @@ void b3ClothDragger::Drag()
|
||||
|
||||
b3Vec3 dx = B - A;
|
||||
|
||||
if (m_spring)
|
||||
{
|
||||
m_particle->SetPosition(B);
|
||||
}
|
||||
else
|
||||
if (m_staticDrag)
|
||||
{
|
||||
b3Particle* p1 = m_cloth->GetParticle(m_triangle->v1);
|
||||
p1->ApplyTranslation(dx);
|
||||
@ -142,11 +127,15 @@ void b3ClothDragger::Drag()
|
||||
b3Particle* p3 = m_cloth->GetParticle(m_triangle->v3);
|
||||
p3->ApplyTranslation(dx);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_particle->SetPosition(B);
|
||||
}
|
||||
}
|
||||
|
||||
void b3ClothDragger::SetSpring(bool bit)
|
||||
void b3ClothDragger::SetStaticDrag(bool bit)
|
||||
{
|
||||
if (bit == m_spring)
|
||||
if (bit == m_staticDrag)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -156,26 +145,24 @@ void b3ClothDragger::SetSpring(bool bit)
|
||||
StopDragging();
|
||||
}
|
||||
|
||||
m_spring = bit;
|
||||
m_staticDrag = bit;
|
||||
}
|
||||
|
||||
void b3ClothDragger::StopDragging()
|
||||
{
|
||||
B3_ASSERT(IsDragging() == true);
|
||||
|
||||
if (m_spring)
|
||||
{
|
||||
m_cloth->DestroyForce(m_s1);
|
||||
m_cloth->DestroyForce(m_s2);
|
||||
m_cloth->DestroyForce(m_s3);
|
||||
m_cloth->DestroyParticle(m_particle);
|
||||
}
|
||||
else
|
||||
if (m_staticDrag)
|
||||
{
|
||||
m_cloth->GetParticle(m_triangle->v1)->SetType(m_t1);
|
||||
m_cloth->GetParticle(m_triangle->v2)->SetType(m_t2);
|
||||
m_cloth->GetParticle(m_triangle->v3)->SetType(m_t3);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_cloth->DestroyForce(m_mf);
|
||||
m_cloth->DestroyParticle(m_particle);
|
||||
}
|
||||
|
||||
m_triangle = nullptr;
|
||||
}
|
||||
|
@ -23,7 +23,8 @@
|
||||
#include <bounce/cloth/cloth.h>
|
||||
#include <bounce/cloth/cloth_mesh.h>
|
||||
#include <bounce/cloth/particle.h>
|
||||
#include <bounce/cloth/spring_force.h>
|
||||
#include <bounce/cloth/cloth_triangle.h>
|
||||
#include <bounce/cloth/forces/mouse_force.h>
|
||||
|
||||
// A cloth triangle dragger.
|
||||
class b3ClothDragger
|
||||
@ -32,10 +33,18 @@ public:
|
||||
b3ClothDragger(b3Ray3* ray, b3Cloth* cloth);
|
||||
~b3ClothDragger();
|
||||
|
||||
void SetSpring(bool bit);
|
||||
void SetStaticDrag(bool bit);
|
||||
|
||||
bool GetSpring() const;
|
||||
bool GetStaticDrag() const;
|
||||
|
||||
void SetMouseStiffness(float32 k);
|
||||
|
||||
float32 GetMouseStiffness();
|
||||
|
||||
void SetMouseDamping(float32 k);
|
||||
|
||||
float32 GetMouseDamping();
|
||||
|
||||
bool IsDragging() const;
|
||||
|
||||
bool StartDragging();
|
||||
@ -53,22 +62,42 @@ private:
|
||||
|
||||
b3Cloth* m_cloth;
|
||||
const b3ClothMesh* m_mesh;
|
||||
u32 m_triangleIndex;
|
||||
b3ClothMeshTriangle* m_triangle;
|
||||
float32 m_u, m_v;
|
||||
|
||||
bool m_spring;
|
||||
|
||||
float32 m_km;
|
||||
float32 m_kd;
|
||||
b3Particle* m_particle;
|
||||
b3SpringForce* m_s1;
|
||||
b3SpringForce* m_s2;
|
||||
b3SpringForce* m_s3;
|
||||
b3MouseForce* m_mf;
|
||||
|
||||
bool m_staticDrag;
|
||||
b3ParticleType m_t1, m_t2, m_t3;
|
||||
};
|
||||
|
||||
inline bool b3ClothDragger::GetSpring() const
|
||||
inline bool b3ClothDragger::GetStaticDrag() const
|
||||
{
|
||||
return m_spring;
|
||||
return m_staticDrag;
|
||||
}
|
||||
|
||||
inline void b3ClothDragger::SetMouseStiffness(float32 k)
|
||||
{
|
||||
m_km = k;
|
||||
}
|
||||
|
||||
inline float32 b3ClothDragger::GetMouseStiffness()
|
||||
{
|
||||
return m_km;
|
||||
}
|
||||
|
||||
inline void b3ClothDragger::SetMouseDamping(float32 k)
|
||||
{
|
||||
m_kd = k;
|
||||
}
|
||||
|
||||
inline float32 b3ClothDragger::GetMouseDamping()
|
||||
{
|
||||
return m_kd;
|
||||
}
|
||||
|
||||
inline bool b3ClothDragger::IsDragging() const
|
||||
|
Reference in New Issue
Block a user