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

Verlet breakable link. More...

Inheritance diagram for VerletPhysics.VerletLink:
Drawing.SimpleLineSprite

Public Member Functions

 VerletLink ()
 Create an uninitialized verlet link. More...
 
 VerletLink (VerletWorld world, VerletPoint a, VerletPoint b)
 Create a simple verlet link. More...
 
void Constraint ()
 Apply link constraint on the two verlet points. More...
 
- Public Member Functions inherited from Drawing.SimpleLineSprite
 SimpleLineSprite ()
 Create a grey line sprite. More...
 

Public Attributes

float RestingDistance
 Resting distance More...
 
float MinimalDistance = -1
 Minimal distance. Use -1 to disable. More...
 
float MaximalDistance = -1
 Maximal distance. Use -1 to disable. More...
 
float Stiffness = 1
 Stiffness of the link, between 0 and 1. More...
 
float TearSensitivity = -1
 Distance required to break the link. Use -1 to create an unbreakable link. More...
 
VerletPoint A
 First verlet point More...
 
VerletPoint B
 Second verlet point More...
 

Additional Inherited Members

- Properties inherited from Drawing.SimpleLineSprite
Vector2 PositionA [get, set]
 Point Position A. More...
 
Vector2 PositionB [get, set]
 Point Position B. More...
 
float Width [get, set]
 Line Width. More...
 

Detailed Description

Verlet breakable link.

Definition at line 9 of file VerletLink.cs.

Constructor & Destructor Documentation

◆ VerletLink() [1/2]

VerletPhysics.VerletLink.VerletLink ( )
inline

Create an uninitialized verlet link.

Definition at line 37 of file VerletLink.cs.

38  {
39  this.world = null;
40  }

◆ VerletLink() [2/2]

VerletPhysics.VerletLink.VerletLink ( VerletWorld  world,
VerletPoint  a,
VerletPoint  b 
)
inline

Create a simple verlet link.

Parameters
worldWorld
aPoint A
bPoint B

Definition at line 48 of file VerletLink.cs.

49  {
50  A = a;
51  B = b;
52  this.world = world;
53 
54  PositionA = A.GlobalPosition;
55  PositionB = B.GlobalPosition;
56 
57  if (RestingDistance == 0)
58  {
59  // Calculate resting distance from points position
60  RestingDistance = (PositionB - PositionA).Length();
61  }
62  }
Vector2 PositionB
Point Position B.
Vector2 PositionA
Point Position A.

Member Function Documentation

◆ Constraint()

void VerletPhysics.VerletLink.Constraint ( )
inline

Apply link constraint on the two verlet points.

Definition at line 67 of file VerletLink.cs.

68  {
69  var diff = A.GlobalPosition - B.GlobalPosition;
70  var d = diff.Length();
71  var difference = (RestingDistance - d) / d;
72 
73  // Check for tear
74  if (TearSensitivity > 0 && d > TearSensitivity)
75  {
76  world.QueueLinkRemoval(this);
77  }
78 
79  // Check for min value
80  if (MinimalDistance > 0 && d >= MinimalDistance)
81  {
82  // Do nothing
83  return;
84  }
85 
86  var imA = 1 / A.Mass;
87  var imB = 1 / B.Mass;
88  var scalarA = (imA / (imA + imB)) * Stiffness;
89  var scalarB = Stiffness - scalarA;
90 
91  Vector2 computeMovement(float scalar)
92  {
93  var movement = diff * difference * scalar;
94  if (MaximalDistance > 0)
95  {
96  return movement.Clamped(MaximalDistance);
97  }
98  else
99  {
100  return movement;
101  }
102  }
103 
104  A.GlobalPosition += computeMovement(scalarA);
105  B.GlobalPosition -= computeMovement(scalarB);
106 
107  PositionA = A.GlobalPosition;
108  PositionB = B.GlobalPosition;
109  }
float Mass
Point mass
Definition: VerletPoint.cs:13
void QueueLinkRemoval(VerletLink link)
Mark a link to be removed next frame.
Definition: VerletWorld.cs:111

Member Data Documentation

◆ A

VerletPoint VerletPhysics.VerletLink.A

First verlet point

Definition at line 27 of file VerletLink.cs.

◆ B

VerletPoint VerletPhysics.VerletLink.B

Second verlet point

Definition at line 30 of file VerletLink.cs.

◆ MaximalDistance

float VerletPhysics.VerletLink.MaximalDistance = -1

Maximal distance. Use -1 to disable.

Definition at line 18 of file VerletLink.cs.

◆ MinimalDistance

float VerletPhysics.VerletLink.MinimalDistance = -1

Minimal distance. Use -1 to disable.

Definition at line 15 of file VerletLink.cs.

◆ RestingDistance

float VerletPhysics.VerletLink.RestingDistance

Resting distance

Definition at line 12 of file VerletLink.cs.

◆ Stiffness

float VerletPhysics.VerletLink.Stiffness = 1

Stiffness of the link, between 0 and 1.

Definition at line 21 of file VerletLink.cs.

◆ TearSensitivity

float VerletPhysics.VerletLink.TearSensitivity = -1

Distance required to break the link. Use -1 to create an unbreakable link.

Definition at line 24 of file VerletLink.cs.


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