Small refactor
This commit is contained in:
@ -19,11 +19,9 @@
|
||||
#ifndef B3_SOFT_BODY_H
|
||||
#define B3_SOFT_BODY_H
|
||||
|
||||
#include <bounce/common/math/transform.h>
|
||||
#include <bounce/softbody/softbody_contact_manager.h>
|
||||
#include <bounce/common/memory/stack_allocator.h>
|
||||
|
||||
#include <bounce/collision/broad_phase.h>
|
||||
|
||||
class b3World;
|
||||
|
||||
struct b3SoftBodyMesh;
|
||||
@ -141,16 +139,14 @@ public:
|
||||
// Debug draw the body using the associated mesh.
|
||||
void Draw() const;
|
||||
private:
|
||||
friend struct b3SoftBodyNode;
|
||||
friend class b3SoftBodyContactManager;
|
||||
friend class b3SoftBodySolver;
|
||||
friend class b3SoftBodyForceSolver;
|
||||
friend struct b3SoftBodyNode;
|
||||
|
||||
// Compute mass of each node.
|
||||
void ComputeMass();
|
||||
|
||||
// Update contacts.
|
||||
void UpdateContacts();
|
||||
|
||||
// Solve
|
||||
void Solve(float32 dt, const b3Vec3& gravity, u32 velocityIterations, u32 positionIterations);
|
||||
|
||||
@ -190,8 +186,8 @@ private:
|
||||
// Soft body triangles
|
||||
b3SoftBodyTriangle* m_triangles;
|
||||
|
||||
// Broadphase
|
||||
b3BroadPhase m_broadPhase;
|
||||
// Contact manager
|
||||
b3SoftBodyContactManager m_contactManager;
|
||||
|
||||
// Attached world
|
||||
b3World* m_world;
|
||||
@ -207,11 +203,6 @@ inline b3Vec3 b3SoftBody::GetGravity() const
|
||||
return m_gravity;
|
||||
}
|
||||
|
||||
inline void b3SoftBody::SetWorld(b3World* world)
|
||||
{
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
inline const b3World* b3SoftBody::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
|
48
include/bounce/softbody/softbody_contact_manager.h
Normal file
48
include/bounce/softbody/softbody_contact_manager.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_SOFTBODY_CONTACT_MANAGER_H
|
||||
#define B3_SOFTBODY_CONTACT_MANAGER_H
|
||||
|
||||
#include <bounce/softbody/softbody_node_body_contact.h>
|
||||
#include <bounce/collision/broad_phase.h>
|
||||
#include <bounce/common/memory/block_pool.h>
|
||||
#include <bounce/common/template/list.h>
|
||||
|
||||
class b3SoftBody;
|
||||
|
||||
// Contact delegator for b3SoftBody.
|
||||
class b3SoftBodyContactManager
|
||||
{
|
||||
public:
|
||||
b3SoftBodyContactManager();
|
||||
|
||||
void FindNewBodyContacts();
|
||||
void AddNSPair(b3SoftBodyNode* n1, b3Shape* s2);
|
||||
void UpdateBodyContacts();
|
||||
|
||||
b3NodeBodyContact* CreateNodeBodyContact();
|
||||
void Destroy(b3NodeBodyContact* c);
|
||||
|
||||
b3BlockPool m_nodeBodyContactBlocks;
|
||||
b3SoftBody* m_body;
|
||||
b3BroadPhase m_broadPhase;
|
||||
b3List2<b3NodeBodyContact> m_nodeBodyContactList;
|
||||
};
|
||||
|
||||
#endif
|
@ -23,37 +23,7 @@
|
||||
#include <bounce/common/math/vec3.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
|
||||
class b3Shape;
|
||||
class b3SoftBody;
|
||||
struct b3SoftBodyNode;
|
||||
|
||||
// A contact between a node and a body
|
||||
struct b3NodeBodyContact
|
||||
{
|
||||
b3SoftBodyNode* n1;
|
||||
b3Shape* s2;
|
||||
|
||||
// Contact constraint
|
||||
b3Vec3 normal1;
|
||||
b3Vec3 localPoint1;
|
||||
b3Vec3 localPoint2;
|
||||
float32 normalImpulse;
|
||||
|
||||
// Friction constraint
|
||||
b3Vec3 t1, t2;
|
||||
b3Vec2 tangentImpulse;
|
||||
|
||||
bool active;
|
||||
};
|
||||
|
||||
struct b3NodeBodyContactWorldPoint
|
||||
{
|
||||
void Initialize(const b3NodeBodyContact* c, float32 rA, const b3Transform& xfA, float32 rB, const b3Transform& xfB);
|
||||
|
||||
b3Vec3 point;
|
||||
b3Vec3 normal;
|
||||
float32 separation;
|
||||
};
|
||||
|
||||
// Static node: Can be moved manually.
|
||||
// Kinematic node: Non-zero velocity, can be moved by the solver.
|
||||
@ -117,9 +87,11 @@ public:
|
||||
void ApplyForce(const b3Vec3& force);
|
||||
private:
|
||||
friend class b3SoftBody;
|
||||
friend class b3SoftBodyContactManager;
|
||||
friend class b3SoftBodySolver;
|
||||
friend class b3SoftBodyForceSolver;
|
||||
friend class b3SoftBodyContactSolver;
|
||||
friend class b3NodeBodyContact;
|
||||
|
||||
b3SoftBodyNode() { }
|
||||
|
||||
@ -128,6 +100,9 @@ private:
|
||||
// Synchronize node
|
||||
void Synchronize(const b3Vec3& displacement);
|
||||
|
||||
// Destroy associated contacts
|
||||
void DestroyContacts();
|
||||
|
||||
// Type
|
||||
b3SoftBodyNodeType m_type;
|
||||
|
||||
@ -161,9 +136,6 @@ private:
|
||||
// Soft body mesh vertex index.
|
||||
u32 m_vertex;
|
||||
|
||||
// Node and body contact
|
||||
b3NodeBodyContact m_bodyContact;
|
||||
|
||||
// Broadphase proxy
|
||||
u32 m_broadPhaseId;
|
||||
|
||||
@ -187,7 +159,7 @@ inline void b3SoftBodyNode::SetType(b3SoftBodyNodeType type)
|
||||
Synchronize(b3Vec3_zero);
|
||||
}
|
||||
|
||||
m_bodyContact.active = false;
|
||||
DestroyContacts();
|
||||
}
|
||||
|
||||
inline b3SoftBodyNodeType b3SoftBodyNode::GetType() const
|
||||
|
78
include/bounce/softbody/softbody_node_body_contact.h
Normal file
78
include/bounce/softbody/softbody_node_body_contact.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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_SOFT_BODY_NODE_BODY_CONTACT_H
|
||||
#define B3_SOFT_BODY_NODE_BODY_CONTACT_H
|
||||
|
||||
#include <bounce/common/template/list.h>
|
||||
#include <bounce/common/math/vec2.h>
|
||||
#include <bounce/common/math/vec3.h>
|
||||
#include <bounce/common/math/transform.h>
|
||||
|
||||
struct b3SoftBodyNode;
|
||||
class b3Shape;
|
||||
|
||||
// A contact between a node and a body
|
||||
class b3NodeBodyContact
|
||||
{
|
||||
public:
|
||||
private:
|
||||
friend class b3List2<b3NodeBodyContact>;
|
||||
friend class b3SoftBody;
|
||||
friend class b3SoftBodyContactManager;
|
||||
friend struct b3SoftBodyNode;
|
||||
friend class b3SoftBodySolver;
|
||||
friend class b3SoftBodyContactSolver;
|
||||
friend struct b3NodeBodyContactWorldPoint;
|
||||
|
||||
b3NodeBodyContact() { }
|
||||
~b3NodeBodyContact() { }
|
||||
|
||||
void Update();
|
||||
|
||||
b3SoftBodyNode* m_n1;
|
||||
b3Shape* m_s2;
|
||||
|
||||
// Is the contact active?
|
||||
bool m_active;
|
||||
|
||||
// Contact constraint
|
||||
b3Vec3 m_normal1;
|
||||
b3Vec3 m_localPoint1;
|
||||
b3Vec3 m_localPoint2;
|
||||
float32 m_normalImpulse;
|
||||
|
||||
// Friction constraint
|
||||
b3Vec3 m_tangent1, m_tangent2;
|
||||
b3Vec2 m_tangentImpulse;
|
||||
|
||||
// List pointers into the soft body
|
||||
b3NodeBodyContact* m_prev;
|
||||
b3NodeBodyContact* m_next;
|
||||
};
|
||||
|
||||
struct b3NodeBodyContactWorldPoint
|
||||
{
|
||||
void Initialize(const b3NodeBodyContact* c, float32 rA, const b3Transform& xfA, float32 rB, const b3Transform& xfB);
|
||||
|
||||
b3Vec3 point;
|
||||
b3Vec3 normal;
|
||||
float32 separation;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user