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

Verlet point. More...

Inheritance diagram for VerletPhysics.VerletPoint:
Drawing.SimpleCircleSprite

Public Member Functions

 VerletPoint ()
 Create an uninitialized verlet point. More...
 
 VerletPoint (VerletWorld world)
 Create a verlet point. More...
 
void MoveToPosition (Vector2 position)
 Move point to position. More...
 
void ApplyForce (Vector2 force)
 Apply force on point. More...
 
void AddLink (VerletLink link)
 Associate verlet link with current point. More...
 
void RemoveLink (VerletLink link)
 Deassociate verlet link from current point. More...
 
void UpdateMovement (float delta)
 Update movement using current forces and gravity. More...
 
void Constraint (Vector2 worldSize)
 Apply constraints on point. More...
 
void PinToCurrentPosition ()
 Pin point to its current position. More...
 
void PinToPosition (Vector2 position)
 Pin point to a target position. More...
 
void Unpin ()
 Unpin point from its position. More...
 
- Public Member Functions inherited from Drawing.SimpleCircleSprite
 SimpleCircleSprite ()
 Create a light blue circle with radius 10. More...
 
 SimpleCircleSprite (Texture texture)
 Create a circle with a custom texture. More...
 

Public Attributes

float Mass = 1
 Point mass More...
 
float Bounce = 0.9f
 Bounce coefficient More...
 
float Friction = 0.99f
 Friction coefficient More...
 
float GravityScale = 1
 Gravity scale More...
 
Vector2 Acceleration
 Current acceleration More...
 

Properties

bool Touched [get]
 Point touched? More...
 
- Properties inherited from Drawing.SimpleCircleSprite
float Radius [get, set]
 Circle radius. More...
 

Detailed Description

Verlet point.

Definition at line 10 of file VerletPoint.cs.

Constructor & Destructor Documentation

◆ VerletPoint() [1/2]

VerletPhysics.VerletPoint.VerletPoint ( )
inline

Create an uninitialized verlet point.

Definition at line 45 of file VerletPoint.cs.

45 { }

◆ VerletPoint() [2/2]

VerletPhysics.VerletPoint.VerletPoint ( VerletWorld  world)
inline

Create a verlet point.

Parameters
worldVerlet world

Definition at line 51 of file VerletPoint.cs.

52  {
53  Radius = 15f;
54  Modulate = Colors.LightBlue;
55 
56  links = new List<VerletLink>();
57  }
float Radius
Circle radius.

Member Function Documentation

◆ AddLink()

void VerletPhysics.VerletPoint.AddLink ( VerletLink  link)
inline

Associate verlet link with current point.

Parameters
linkVerlet link

Definition at line 82 of file VerletPoint.cs.

83  {
84  links.Add(link);
85  }

◆ ApplyForce()

void VerletPhysics.VerletPoint.ApplyForce ( Vector2  force)
inline

Apply force on point.

Parameters
forceForce

Definition at line 73 of file VerletPoint.cs.

74  {
75  Acceleration += force / Mass;
76  }
float Mass
Point mass
Definition: VerletPoint.cs:13
Vector2 Acceleration
Current acceleration
Definition: VerletPoint.cs:25

◆ Constraint()

void VerletPhysics.VerletPoint.Constraint ( Vector2  worldSize)
inline

Apply constraints on point.

Parameters
worldSizeWorld size

Definition at line 115 of file VerletPoint.cs.

116  {
117  foreach (VerletLink link in links)
118  {
119  link.Constraint();
120  }
121 
122  ConstraintPositionInSize(worldSize);
123  ConstraintPinning();
124  }

◆ MoveToPosition()

void VerletPhysics.VerletPoint.MoveToPosition ( Vector2  position)
inline

Move point to position.

Parameters
positionTarget position

Definition at line 63 of file VerletPoint.cs.

64  {
65  GlobalPosition = position;
66  prevPosition = GlobalPosition;
67  }

◆ PinToCurrentPosition()

void VerletPhysics.VerletPoint.PinToCurrentPosition ( )
inline

Pin point to its current position.

Definition at line 129 of file VerletPoint.cs.

130  {
131  pinned = true;
132  pinPosition = GlobalPosition;
133  }

◆ PinToPosition()

void VerletPhysics.VerletPoint.PinToPosition ( Vector2  position)
inline

Pin point to a target position.

Parameters
positionTarget position

Definition at line 139 of file VerletPoint.cs.

140  {
141  pinned = true;
142  pinPosition = position;
143  }

◆ RemoveLink()

void VerletPhysics.VerletPoint.RemoveLink ( VerletLink  link)
inline

Deassociate verlet link from current point.

Parameters
linkVerlet link

Definition at line 91 of file VerletPoint.cs.

92  {
93  links.Remove(link);
94  }

◆ Unpin()

void VerletPhysics.VerletPoint.Unpin ( )
inline

Unpin point from its position.

Definition at line 148 of file VerletPoint.cs.

149  {
150  pinned = false;
151  }

◆ UpdateMovement()

void VerletPhysics.VerletPoint.UpdateMovement ( float  delta)
inline

Update movement using current forces and gravity.

Parameters
deltaDelta time

Definition at line 100 of file VerletPoint.cs.

101  {
102  var velocity = ComputeVelocity() * Friction;
103  var nextPosition = GlobalPosition + velocity + (Acceleration * delta);
104 
105  prevPosition = GlobalPosition;
106  GlobalPosition = nextPosition;
107 
108  Acceleration = Vector2.Zero;
109  }
float Friction
Friction coefficient
Definition: VerletPoint.cs:19

Member Data Documentation

◆ Acceleration

Vector2 VerletPhysics.VerletPoint.Acceleration

Current acceleration

Definition at line 25 of file VerletPoint.cs.

◆ Bounce

float VerletPhysics.VerletPoint.Bounce = 0.9f

Bounce coefficient

Definition at line 16 of file VerletPoint.cs.

◆ Friction

float VerletPhysics.VerletPoint.Friction = 0.99f

Friction coefficient

Definition at line 19 of file VerletPoint.cs.

◆ GravityScale

float VerletPhysics.VerletPoint.GravityScale = 1

Gravity scale

Definition at line 22 of file VerletPoint.cs.

◆ Mass

float VerletPhysics.VerletPoint.Mass = 1

Point mass

Definition at line 13 of file VerletPoint.cs.

Property Documentation

◆ Touched

bool VerletPhysics.VerletPoint.Touched
get

Point touched?

Definition at line 28 of file VerletPoint.cs.

29  {
30  get => touched;
31  }

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