Plasma Engine  2.0
Loading...
Searching...
No Matches
ClothSheetSimulator.h
1#pragma once
2
3#include <Foundation/Containers/DynamicArray.h>
4#include <Foundation/Math/Vec3.h>
5#include <Foundation/SimdMath/SimdFloat.h>
6#include <Foundation/SimdMath/SimdVec4f.h>
7#include <Foundation/Time/Time.h>
8#include <GameEngine/GameEngineDLL.h>
9
15class PL_GAMEENGINE_DLL plClothSimulator
16{
17public:
18 struct Node
19 {
21 bool m_bFixed = false;
22 plSimdVec4f m_vPosition = plSimdVec4f::MakeZero();
23 plSimdVec4f m_vPreviousPosition = plSimdVec4f::MakeZero();
24 };
25
27 plUInt8 m_uiWidth = 32;
28
30 plUInt8 m_uiHeight = 32;
31
34
36 float m_fDampingFactor = 0.995f;
37
39 plVec2 m_vSegmentLength = plVec2(0.1f);
40
43
44 void SimulateCloth(const plTime& diff);
45 void SimulateStep(const plSimdFloat fDiffSqr, plUInt32 uiMaxIterations, plSimdFloat fAllowedError);
46 bool HasEquilibrium(plSimdFloat fAllowedMovement) const;
47
48private:
49 plSimdFloat EnforceDistanceConstraint();
50 void UpdateNodePositions(const plSimdFloat tDiffSqr);
51 plSimdVec4f MoveTowards(const plSimdVec4f posThis, const plSimdVec4f posNext, plSimdFloat factor, const plSimdVec4f fallbackDir, plSimdFloat& inout_fError, plSimdFloat fSegLen);
52
53 plTime m_LeftOverTimeStep;
54};
A simple simulator for swinging and hanging cloth.
Definition ClothSheetSimulator.h:16
plDynamicArray< Node, plAlignedAllocatorWrapper > m_Nodes
All cloth nodes.
Definition ClothSheetSimulator.h:42
plVec3 m_vAcceleration
Overall force acting equally upon all cloth nodes.
Definition ClothSheetSimulator.h:33
Definition DynamicArray.h:81
Definition SimdFloat.h:7
A 4-component SIMD vector class.
Definition SimdVec4f.h:8
static plSimdVec4f MakeZero()
Creates an plSimdVec4f that is initialized to zero.
Definition SimdVec4f_inl.h:8
Definition ClothSheetSimulator.h:19
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12