deargui-vpl/ref/virtools/Samples/Behaviors/ParticlesSystem/behaviors src/ClothSystem.h

141 lines
2.8 KiB
C++

#pragma once
class ParticleManager;
class ClothSystem
{
public:
// Ctor
ClothSystem(CKContext* iCtx);
// Dtor
~ClothSystem();
///
// Attributes accessor
void SetPointMass(const float iPointMass)
{
m_PointInverseMass = 1.0f / iPointMass;
}
void SetDamping(const float iDamping)
{
m_DampingFactor = iDamping;
}
void SetTightness(const float iTightness)
{
float tight2 = iTightness*iTightness;
m_StrutLength2.x = m_StrutLength.x*m_StrutLength.x*tight2;
m_StrutLength2.y = m_StrutLength.y*m_StrutLength.y*tight2;
m_StrutLength2.z = m_StrutLength.z*m_StrutLength.z*tight2;
}
void SetGravity(const VxVector& iGravity)
{
m_Gravity = iGravity;
}
void SetIterations(int iIterations)
{
m_Iterations = iIterations;
}
// Update the cloth system
void Update(const float iDeltaTime);
// Tesselate the cloth mesh
void Tesselate(const Vx2DVector& iResolution, const Vx2DVector& iSize, const Vx2DVector& iMapping, CKMaterial* iMaterial, CKMaterial* iBackMaterial);
// Clear the hooks
void ClearHooks();
// set a hook
void SetHook(CK3dEntity* iHook, const Vx2DVector& iPosition)
{
if (!iHook) return;
int index = (int)(iPosition.x*(m_Width-1) + m_Width*(int)(iPosition.y*(m_Height-1)));
m_Nodes[index].hook = iHook;
}
// set the referential
void SetReferential(CK3dEntity* iReferential)
{
//if (m_Referential == iReferential)
// return;
if ((iReferential != m_Referential) && m_Referential) {
m_Referential->RemoveMesh(m_Mesh);
}
m_Referential = iReferential;
if (m_Referential)
m_Referential->SetCurrentMesh(m_Mesh);
}
void SetMaterial(CKMaterial* iFrontMaterial);
protected:
// Integrate
void _Integrate(const float iDeltaTime);
// Constraint Solving
void _SatisfyConstraints(const float iDeltaTime);
void _SatisfyConstraintsSIMD(const float iDeltaTime);
// Collision Response
void _SatisfyBoxDeflectors(const XObjectPointerArray& iBoxes);
void _SatisfySphereDeflectors(const XObjectPointerArray& iSpheres);
void _SatisfyInfinitePlaneDeflectors(const XObjectPointerArray& iPlanes);
void _SatisfyMeshDeflectors(const XObjectPointerArray& iMeshes);
// The mesh
CKMesh* m_Mesh;
// 3D Entity supporting the cloth
CK3dEntity* m_Referential;
// Back material
CKMaterial* m_BackMaterial;
// Particle Manager
ParticleManager* m_ParticleManager;
// X Resolution
int m_Width;
// Y Resolution
int m_Height;
// 1/ Point Mass
float m_PointInverseMass;
// Damping Factor
float m_DampingFactor;
// gravity force
VxVector m_Gravity;
// Solving iterations
int m_Iterations;
// Strut length
VxVector m_StrutLength;
VxVector m_StrutLength2;
struct Node {
VxVector4 position;
VxVector oldPosition;
CK3dEntity* hook;
};
// System
Node* m_Nodes;
// For Smoothing Purpose
float m_oldDeltaTime;
};