Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Public Types | Public Member Functions | List of all members
VerletPhysics.VerletCloth Class Reference

Simple verlet cloth. More...

Public Types

enum class  PinModeEnum { None , TopCorners , Top , AllCorners }
 Pin mode enum. More...
 

Public Member Functions

 VerletCloth (VerletWorld world, Vector2 topLeftPosition, Vector2 pointCount, float separation, PinModeEnum pinMode=PinModeEnum.TopCorners, float tearSensitivityFactor=2, float stiffness=1, bool drawPoints=false, float pointRadius=10f)
 Create a verlet cloth. More...
 

Detailed Description

Simple verlet cloth.

Definition at line 9 of file VerletCloth.cs.

Member Enumeration Documentation

◆ PinModeEnum

Pin mode enum.

Enumerator
None 

No pin

TopCorners 

Pin top corners

Top 

Pin all top points

AllCorners 

Pin all corners

Definition at line 14 of file VerletCloth.cs.

15  {
17  None,
18 
20  TopCorners,
21 
23  Top,
24 
26  AllCorners
27  }

Constructor & Destructor Documentation

◆ VerletCloth()

VerletPhysics.VerletCloth.VerletCloth ( VerletWorld  world,
Vector2  topLeftPosition,
Vector2  pointCount,
float  separation,
PinModeEnum  pinMode = PinModeEnum.TopCorners,
float  tearSensitivityFactor = 2,
float  stiffness = 1,
bool  drawPoints = false,
float  pointRadius = 10f 
)
inline

Create a verlet cloth.

Parameters
worldVerlet world
topLeftPositionTop-left position
pointCountX/Y point count
separationSeparation
pinModePin mode
tearSensitivityFactorDistance factor required to break the cloth. Use -1 to create an unbreakable cloth.
stiffnessStiffness of the cloth
drawPointsDraw verlet points
pointRadiusVerlet point radius

Definition at line 43 of file VerletCloth.cs.

44  {
45  points = new List<VerletPoint>();
46 
47  for (int j = 0; j < pointCount.y; ++j)
48  {
49  for (int i = 0; i < pointCount.x; ++i)
50  {
51  var position = topLeftPosition + new Vector2(separation * i, separation * j);
52  var point = world.CreatePoint();
53  point.Radius = pointRadius;
54  point.Visible = drawPoints;
55  point.MoveToPosition(position);
56 
57  if (pinMode == PinModeEnum.AllCorners)
58  {
59  if ((j == 0 || j == pointCount.y - 1) && (i == 0 || i == pointCount.x - 1))
60  {
61  point.PinToCurrentPosition();
62  }
63  }
64  else if (pinMode == PinModeEnum.TopCorners)
65  {
66  if (j == 0 && (i == 0 || i == pointCount.x - 1))
67  {
68  point.PinToCurrentPosition();
69  }
70  }
71  else if (pinMode == PinModeEnum.Top)
72  {
73  if (j == 0)
74  {
75  point.PinToCurrentPosition();
76  }
77  }
78 
79  points.Add(point);
80  }
81  }
82 
83  if (points.Count == 0)
84  {
85  GD.PrintErr("Bad points length for cloth. Need to be > 0");
86  return;
87  }
88 
89  for (int j = 0; j < pointCount.y; ++j)
90  {
91  for (int i = 0; i < pointCount.x; ++i)
92  {
93  if (i > 0)
94  {
95  // Right to left
96  int pAIdx = i - 1 + (j * (int)pointCount.x);
97  int pBIdx = i + (j * (int)pointCount.x);
98 
99  var link = world.CreateLink(points[pAIdx], points[pBIdx]);
100  link.RestingDistance = separation;
101  link.TearSensitivity = separation * tearSensitivityFactor;
102  link.Stiffness = stiffness;
103  }
104 
105  if (j > 0)
106  {
107  // Bottom to top
108  int pAIdx = i + ((j - 1) * (int)pointCount.x);
109  int pBIdx = i + (j * (int)pointCount.x);
110 
111  var link = world.CreateLink(points[pAIdx], points[pBIdx]);
112  link.RestingDistance = separation;
113  link.TearSensitivity = separation * tearSensitivityFactor;
114  link.Stiffness = stiffness;
115  }
116  }
117  }
118  }
PinModeEnum
Pin mode enum.
Definition: VerletCloth.cs:15

The documentation for this class was generated from the following file: