Organize cloth contacts

This commit is contained in:
Irlan
2019-06-13 10:13:15 -03:00
parent 6b92664c1e
commit f7becc7ee7
5 changed files with 264 additions and 214 deletions

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2016-2019 Irlan Robson https://irlanrobson.github.io
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#ifndef B3_CLOTH_CONTACT_H
#define B3_CLOTH_CONTACT_H
#include <bounce/common/template/list.h>
class b3Particle;
struct b3ClothMeshTriangle;
struct b3ClothAABBProxy;
// Contact between particle and a triangle
class b3ParticleTriangleContact
{
public:
private:
friend class b3Cloth;
friend class b3Particle;
friend class b3ClothContactManager;
friend class b3List2<b3ParticleTriangleContact>;
friend class b3ClothContactSolver;
b3ParticleTriangleContact() { }
~b3ParticleTriangleContact() { }
void Update();
// Particle
b3Particle* m_p1;
// Triangle
b3ClothMeshTriangle* m_triangle;
b3ClothAABBProxy* m_triangleProxy;
b3Particle* m_p2;
b3Particle* m_p3;
b3Particle* m_p4;
float32 m_normalImpulse;
bool m_front;
bool m_active;
b3ParticleTriangleContact* m_prev;
b3ParticleTriangleContact* m_next;
};
#endif

View File

@ -19,36 +19,12 @@
#ifndef B3_CLOTH_CONTACT_MANAGER_H
#define B3_CLOTH_CONTACT_MANAGER_H
#include <bounce/cloth/cloth_contact.h>
#include <bounce/collision/broad_phase.h>
#include <bounce/common/memory/block_pool.h>
#include <bounce/common/template/list.h>
#include <bounce/collision/broad_phase.h>
class b3Cloth;
class b3Particle;
struct b3ClothMeshTriangle;
struct b3ClothAABBProxy;
// Contact between particle and a triangle
class b3ParticleTriangleContact
{
public:
b3Particle* m_p1;
b3ClothMeshTriangle* m_triangle;
b3ClothAABBProxy* m_triangleProxy;
b3Particle* m_p2;
b3Particle* m_p3;
b3Particle* m_p4;
bool m_front;
bool m_active;
float32 m_normalImpulse;
b3ParticleTriangleContact* m_prev;
b3ParticleTriangleContact* m_next;
};
// Contact delegator for b3Cloth.
class b3ClothContactManager
@ -62,19 +38,14 @@ public:
void FindNewContacts();
void UpdateContacts();
b3ParticleTriangleContact* Create();
b3ParticleTriangleContact* CreateParticleTriangleContact();
void Destroy(b3ParticleTriangleContact* c);
void Update(b3ParticleTriangleContact* c);
b3Cloth* m_cloth;
b3BlockPool m_particleTriangleContactBlocks;
b3Cloth* m_cloth;
b3BroadPhase m_broadPhase;
b3List2<b3ParticleTriangleContact> m_particleTriangleContactList;
};

View File

@ -19,10 +19,10 @@
#ifndef B3_PARTICLE_H
#define B3_PARTICLE_H
#include <bounce/cloth/force.h>
#include <bounce/common/math/transform.h>
#include <bounce/common/math/vec2.h>
#include <bounce/common/template/list.h>
#include <bounce/cloth/force.h>
class b3Shape;
class b3Cloth;
@ -91,12 +91,14 @@ struct b3ParticleBodyContactWorldPoint
float32 separation;
};
// Cloth primitive type
enum b3ClothAABBProxyType
{
e_particleProxy,
e_triangleProxy
};
// Cloth primitive broadphase proxy
struct b3ClothAABBProxy
{
b3ClothAABBProxyType type;
@ -160,6 +162,7 @@ private:
friend class b3Cloth;
friend class b3ClothSolver;
friend class b3ClothContactManager;
friend class b3ParticleTriangleContact;
friend class b3ClothContactSolver;
friend class b3Force;
friend class b3SpringForce;
@ -226,10 +229,8 @@ private:
// AABB Proxy
b3ClothAABBProxy m_aabbProxy;
//
// Links to the cloth particle list.
b3Particle* m_prev;
//
b3Particle* m_next;
};