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

Simple verlet world which handle simulation book-keeping. More...

Inherits Node2D.

Public Member Functions

 VerletWorld ()
 Create a default verlet world. More...
 
VerletPoint CreatePoint (Vector2? initialPosition=null, float? mass=null, float? gravityScale=null, float? radius=null, Color? color=null, bool? visible=null)
 Create a verlet point. More...
 
VerletLink CreateLink (VerletPoint a, VerletPoint b, float? restingDistance=null, float? minimalDistance=null, float? maximalDistance=null, float? tearSensitivity=null, float? tearSensitivityFactor=null, float? stiffness=null, float? width=null, Color? color=null, bool? visible=null)
 Create a verlet link. More...
 
void QueueLinkRemoval (VerletLink link)
 Mark a link to be removed next frame. More...
 
void AddBehavior (IBehavior behavior)
 Add a new behavior. More...
 
void RemoveBehavior (IBehavior behavior)
 Remove an existing behavior. More...
 

Public Attributes

int ConstraintAccuracy = 2
 Constraint resolution accuracy More...
 

Detailed Description

Simple verlet world which handle simulation book-keeping.

Definition at line 9 of file VerletWorld.cs.

Constructor & Destructor Documentation

◆ VerletWorld()

VerletPhysics.VerletWorld.VerletWorld ( )
inline

Create a default verlet world.

Definition at line 21 of file VerletWorld.cs.

22  {
23  points = new List<VerletPoint>();
24  linksToRemove = new List<VerletLink>();
25  behaviors = new List<IBehavior>();
26  }

Member Function Documentation

◆ AddBehavior()

void VerletPhysics.VerletWorld.AddBehavior ( IBehavior  behavior)
inline

Add a new behavior.

Parameters
behaviorBehavior

Definition at line 123 of file VerletWorld.cs.

124  {
125  behaviors.Add(behavior);
126  }

◆ CreateLink()

VerletLink VerletPhysics.VerletWorld.CreateLink ( VerletPoint  a,
VerletPoint  b,
float?  restingDistance = null,
float?  minimalDistance = null,
float?  maximalDistance = null,
float?  tearSensitivity = null,
float?  tearSensitivityFactor = null,
float?  stiffness = null,
float?  width = null,
Color?  color = null,
bool?  visible = null 
)
inline

Create a verlet link.

Parameters
aFirst verlet point
bFirst verlet point
restingDistanceResting distance
minimalDistanceMinimal link distance. Use -1 to disable.
maximalDistanceMaximal link distance. Use -1 to disable.
tearSensitivityDistance required to break the link. Use -1 to create an unbreakable link.
tearSensitivityFactorDistance factor required to break the link. Use -1 to create an unbreakable link.
stiffnessStiffness of the link
widthWidth of the link
colorLink color
visibleShow link
Returns
Verlet link

Definition at line 73 of file VerletWorld.cs.

85  {
86  var link = new VerletLink(this, a, b);
87  a.AddLink(link);
88  AddChild(link);
89 
90  link.Visible = visible ?? link.Visible;
91  link.RestingDistance = restingDistance ?? link.RestingDistance;
92  link.MinimalDistance = minimalDistance ?? link.MinimalDistance;
93  link.MaximalDistance = maximalDistance ?? link.MaximalDistance;
94  link.TearSensitivity = tearSensitivity ?? link.TearSensitivity;
95  link.Stiffness = stiffness ?? link.Stiffness;
96  link.Modulate = color ?? link.Modulate;
97  link.Width = width ?? link.Width;
98 
99  if (tearSensitivityFactor.HasValue)
100  {
101  link.TearSensitivity = link.RestingDistance * tearSensitivityFactor.Value;
102  }
103 
104  return link;
105  }

◆ CreatePoint()

VerletPoint VerletPhysics.VerletWorld.CreatePoint ( Vector2?  initialPosition = null,
float?  mass = null,
float?  gravityScale = null,
float?  radius = null,
Color?  color = null,
bool?  visible = null 
)
inline

Create a verlet point.

Parameters
initialPositionInitial position
massMass
gravityScaleGravity scale
radiusRadius
colorColor
visibleShow point
Returns
Verlet point

Definition at line 38 of file VerletWorld.cs.

39  {
40  var point = new VerletPoint(this);
41  points.Add(point);
42  AddChild(point);
43 
44  point.Mass = mass ?? point.Mass;
45  point.GravityScale = gravityScale ?? point.GravityScale;
46  point.Radius = radius ?? point.Radius;
47  point.Visible = visible ?? point.Visible;
48  point.Modulate = color ?? point.Modulate;
49 
50  if (initialPosition.HasValue)
51  {
52  point.MoveToPosition(initialPosition.Value);
53  }
54 
55  return point;
56  }

◆ QueueLinkRemoval()

void VerletPhysics.VerletWorld.QueueLinkRemoval ( VerletLink  link)
inline

Mark a link to be removed next frame.

Parameters
linkVerlet link

Definition at line 111 of file VerletWorld.cs.

112  {
113  if (!linksToRemove.Contains(link))
114  {
115  linksToRemove.Add(link);
116  }
117  }

◆ RemoveBehavior()

void VerletPhysics.VerletWorld.RemoveBehavior ( IBehavior  behavior)
inline

Remove an existing behavior.

Parameters
behaviorBehavior

Definition at line 132 of file VerletWorld.cs.

133  {
134  behaviors.Remove(behavior);
135  }

Member Data Documentation

◆ ConstraintAccuracy

int VerletPhysics.VerletWorld.ConstraintAccuracy = 2

Constraint resolution accuracy

Definition at line 12 of file VerletWorld.cs.


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