From 7a1d50465ccbe7c32782037e4456b73f4f371753 Mon Sep 17 00:00:00 2001 From: Irlan <-> Date: Wed, 18 Jul 2018 16:58:21 -0300 Subject: [PATCH] remove function --- examples/testbed/tests/cloth_test.h | 2 -- examples/testbed/tests/tension_mapping.h | 8 +++---- include/bounce/controllers/cloth_dragger.h | 6 +++--- include/bounce/dynamics/cloth/cloth.h | 3 --- include/bounce/dynamics/cloth/particle.h | 6 +++--- src/bounce/dynamics/cloth/cloth.cpp | 25 +++++----------------- src/bounce/dynamics/cloth/cloth_solver.cpp | 14 +++++++----- src/bounce/dynamics/cloth/particle.cpp | 6 ++---- 8 files changed, 25 insertions(+), 45 deletions(-) diff --git a/examples/testbed/tests/cloth_test.h b/examples/testbed/tests/cloth_test.h index 946e755..3d737d8 100644 --- a/examples/testbed/tests/cloth_test.h +++ b/examples/testbed/tests/cloth_test.h @@ -32,8 +32,6 @@ public: { Test::Step(); - m_cloth->Apply(); - m_cloth->Draw(); extern u32 b3_clothSolverIterations; diff --git a/examples/testbed/tests/tension_mapping.h b/examples/testbed/tests/tension_mapping.h index 61530b0..fe61e7a 100644 --- a/examples/testbed/tests/tension_mapping.h +++ b/examples/testbed/tests/tension_mapping.h @@ -97,8 +97,6 @@ public: { Test::Step(); - m_cloth->Apply(); - b3ClothMesh* mesh = m_cloth->GetMesh(); b3StackArray tension; @@ -126,9 +124,9 @@ public: { b3ClothMeshTriangle* t = m_rectangleClothMesh.triangles + i; - b3Vec3 v1 = mesh->vertices[t->v1]; - b3Vec3 v2 = mesh->vertices[t->v2]; - b3Vec3 v3 = mesh->vertices[t->v3]; + b3Vec3 v1 = mesh->particles[t->v1]->GetPosition(); + b3Vec3 v2 = mesh->particles[t->v2]->GetPosition(); + b3Vec3 v3 = mesh->particles[t->v3]->GetPosition(); b3Draw_draw->DrawSegment(v1, v2, b3Color_black); b3Draw_draw->DrawSegment(v2, v3, b3Color_black); diff --git a/include/bounce/controllers/cloth_dragger.h b/include/bounce/controllers/cloth_dragger.h index 99fbf2d..9faaa73 100644 --- a/include/bounce/controllers/cloth_dragger.h +++ b/include/bounce/controllers/cloth_dragger.h @@ -192,9 +192,9 @@ public: { B3_ASSERT(IsDragging() == true); - b3Vec3 A = m_mesh->vertices[m_triangle->v1]; - b3Vec3 B = m_mesh->vertices[m_triangle->v2]; - b3Vec3 C = m_mesh->vertices[m_triangle->v3]; + b3Vec3 A = m_mesh->particles[m_triangle->v1]->GetPosition(); + b3Vec3 B = m_mesh->particles[m_triangle->v2]->GetPosition(); + b3Vec3 C = m_mesh->particles[m_triangle->v3]->GetPosition(); return m_u * A + m_v * B + (1.0f - m_u - m_v) * C; } diff --git a/include/bounce/dynamics/cloth/cloth.h b/include/bounce/dynamics/cloth/cloth.h index 1a7abaf..81fc4fb 100644 --- a/include/bounce/dynamics/cloth/cloth.h +++ b/include/bounce/dynamics/cloth/cloth.h @@ -123,9 +123,6 @@ public: // Get the next cloth in the world cloth list. b3Cloth* GetNext(); - // Set the positions of the mesh vertices to the positions of their associated particles. - void Apply() const; - // Debug draw the cloth using the associated cloth mesh. void Draw() const; private: diff --git a/include/bounce/dynamics/cloth/particle.h b/include/bounce/dynamics/cloth/particle.h index b4e4884..a089349 100644 --- a/include/bounce/dynamics/cloth/particle.h +++ b/include/bounce/dynamics/cloth/particle.h @@ -160,6 +160,9 @@ private: // Applied external force b3Vec3 m_force; + // Applied external translation + b3Vec3 m_translation; + // Mass float32 m_mass; @@ -175,9 +178,6 @@ private: // Cloth mesh vertex index. u32 m_vertex; - // Applied external translation - b3Vec3 m_translation; - // Contact b3BodyContact m_contact; diff --git a/src/bounce/dynamics/cloth/cloth.cpp b/src/bounce/dynamics/cloth/cloth.cpp index d13f65f..3eb397c 100644 --- a/src/bounce/dynamics/cloth/cloth.cpp +++ b/src/bounce/dynamics/cloth/cloth.cpp @@ -270,13 +270,9 @@ b3Particle* b3Cloth::CreateParticle(const b3ParticleDef& def) void b3Cloth::DestroyParticle(b3Particle* particle) { - for (u32 i = 0; i > m_mesh->vertexCount; ++i) + if (particle->m_vertex != ~0) { - if (m_mesh->particles[i] == particle) - { - m_mesh->particles[i] = NULL; - break; - } + m_mesh->particles[particle->m_vertex] = NULL; } m_particleList.Remove(particle); @@ -417,9 +413,9 @@ bool b3Cloth::RayCast(b3RayCastOutput* output, const b3RayCastInput* input, u32 B3_ASSERT(triangleIndex < m_mesh->triangleCount); b3ClothMeshTriangle* triangle = m_mesh->triangles + triangleIndex; - b3Vec3 v1 = m_mesh->vertices[triangle->v1]; - b3Vec3 v2 = m_mesh->vertices[triangle->v2]; - b3Vec3 v3 = m_mesh->vertices[triangle->v3]; + b3Vec3 v1 = m_mesh->particles[triangle->v1]->m_position; + b3Vec3 v2 = m_mesh->particles[triangle->v2]->m_position; + b3Vec3 v3 = m_mesh->particles[triangle->v3]->m_position; b3Vec3 p1 = input->p1; b3Vec3 p2 = input->p2; @@ -738,17 +734,6 @@ void b3Cloth::Step(float32 dt, const b3Vec3& gravity) } } -void b3Cloth::Apply() const -{ - for (b3Particle* p = m_particleList.m_head; p; p = p->m_next) - { - if (p->m_vertex != ~0) - { - m_mesh->vertices[p->m_vertex] = p->m_position; - } - } -} - void b3Cloth::Draw() const { for (b3Particle* p = m_particleList.m_head; p; p = p->m_next) diff --git a/src/bounce/dynamics/cloth/cloth_solver.cpp b/src/bounce/dynamics/cloth/cloth_solver.cpp index 60ef6e2..42e46c5 100644 --- a/src/bounce/dynamics/cloth/cloth_solver.cpp +++ b/src/bounce/dynamics/cloth/cloth_solver.cpp @@ -91,7 +91,10 @@ void b3ClothSolver::ApplyForces() void b3AccelerationConstraint::Apply(const b3ClothSolverData* data) { - (*data->z)[i1] = z; + b3DiagMat33& sS = *data->S; + b3DenseVec3& sz = *data->z; + + sz[i1] = z; b3Mat33 I; I.SetIdentity(); @@ -99,22 +102,22 @@ void b3AccelerationConstraint::Apply(const b3ClothSolverData* data) { case 3: { - (*data->S)[i1] = I; + sS[i1] = I; break; } case 2: { - (*data->S)[i1] = I - b3Outer(p, p); + sS[i1] = I - b3Outer(p, p); break; } case 1: { - (*data->S)[i1] = I - b3Outer(p, p) - b3Outer(q, q); + sS[i1] = I - b3Outer(p, p) - b3Outer(q, q); break; } case 0: { - (*data->S)[i1].SetZero(); + sS[i1].SetZero(); break; } default: @@ -129,6 +132,7 @@ void b3ClothSolver::ApplyConstraints() { b3DiagMat33& S = *m_solverData.S; b3DenseVec3& z = *m_solverData.z; + float32 h = m_solverData.dt; S.SetIdentity(); z.SetZero(); diff --git a/src/bounce/dynamics/cloth/particle.cpp b/src/bounce/dynamics/cloth/particle.cpp index 234293e..5e5e741 100644 --- a/src/bounce/dynamics/cloth/particle.cpp +++ b/src/bounce/dynamics/cloth/particle.cpp @@ -31,6 +31,7 @@ b3Particle::b3Particle(const b3ParticleDef& def, b3Cloth* cloth) { m_cloth = cloth; m_type = def.type; + m_position = def.position; m_velocity = def.velocity; m_force = def.force; @@ -42,13 +43,10 @@ b3Particle::b3Particle(const b3ParticleDef& def, b3Cloth* cloth) m_x.SetZero(); m_vertex = ~0; - m_contact.f_active = false; m_contact.n_active = false; m_contact.t1_active = false; m_contact.t2_active = false; - m_contact.Fn = 0.0f; - m_contact.Ft1 = 0.0f; - m_contact.Ft2 = 0.0f; + m_contact.f_active = false; } b3Particle::~b3Particle()