Class: Particle
physics/fluid/particle.Particle
Hierarchy
โณ
Particle
Constructors
constructor
โข new Particle(radius
, mass
)
Creates a Particle.
Parameters
Name | Type | Description |
---|---|---|
radius | number | The radius of the particle |
mass | number | The mass of the particle |
Overrides
Defined in
src/physics/fluid/particle.ts:31
Properties
airFriction
โข airFriction: number
= 0
The damping applied to the object's linear velocity every physics update.
Inherited from
Defined in
src/physics/object.ts:68
angularDamping
โข angularDamping: number
= 0
The damping applied to the object's angular velocity every physics update.
Inherited from
Defined in
src/physics/object.ts:97
angularVelocity
โข angularVelocity: number
= 0
The object's angular velocity in radians per second.
Inherited from
Defined in
src/physics/object.ts:80
collider
โข collider: Collider
The object's collider.
Inherited from
Defined in
src/physics/collisionObject.ts:23
density
โข density: number
Defined in
src/physics/fluid/particle.ts:14
densityNear
โข densityNear: number
Defined in
src/physics/fluid/particle.ts:15
dx
โข dx: vec2
Defined in
src/physics/fluid/particle.ts:20
dynamicFriction
โข dynamicFriction: number
= 0.1
Coefficient of dynamic/kinetic friction.
This value should be between 0 and 1 for best results.
see
Static And Kinetic Friction
Inherited from
Defined in
src/physics/object.ts:51
filter
โข filter: CollisionFilter
The object's collision filter.
Inherited from
Defined in
src/physics/collisionObject.ts:18
force
โข force: vec2
The net force applied to the object in newtons.
Inherited from
Defined in
src/physics/object.ts:58
gravity
โข gravity: vec2
The gravitational froce applied to the object.
Inherited from
Defined in
src/physics/object.ts:12
isDynamic
โข isDynamic: boolean
= true
Wether the body has dynamics or not.
Inherited from
Defined in
src/physics/rigidbody.ts:15
isStatic
โข isStatic: boolean
= false
Wether or not the object is static, static objects do not move during collisions.
Inherited from
Defined in
src/physics/collisionObject.ts:38
isTrigger
โข isTrigger: boolean
= false
Wether or not the collision object should be a trigger.
When true the object will detect but not respond to collisions.
Inherited from
Defined in
src/physics/collisionObject.ts:45
listeners
โข Protected
listeners: Object
= {}
Index signature
โช [index: string
]: Listener
[]
Inherited from
Defined in
src/object2d.ts:32
lockRotation
โข lockRotation: boolean
= false
Wether or not the object can rotate.
When true the object's rotation will not be affected by collisions or dynamics.
Inherited from
Defined in
src/physics/object.ts:125
lockXAxis
โข lockXAxis: boolean
= false
Wether or not the object's x position is locked.
When true the object's x position will not be affected by collisions or dynamics.
Inherited from
Defined in
src/physics/object.ts:111
lockYAxis
โข lockYAxis: boolean
= false
Wether or not the object's y position is locked.
When true the object's y position will not be affected by collisions or dynamics.
Inherited from
Defined in
src/physics/object.ts:118
neighbours
โข neighbours: Particle
[]
Defined in
src/physics/fluid/particle.ts:23
posPrev
โข posPrev: vec2
Defined in
src/physics/fluid/particle.ts:21
pressure
โข pressure: number
Defined in
src/physics/fluid/particle.ts:17
pressureNear
โข pressureNear: number
Defined in
src/physics/fluid/particle.ts:18
radius
โข Private
radius: number
Defined in
src/physics/fluid/particle.ts:12
restitution
โข restitution: number
= 0
Elasticity/bounciness
This value should be between 0 and 1 for best results.
Inherited from
Defined in
src/physics/object.ts:33
staticFriction
โข staticFriction: number
= 0.1
Coefficient of static friction.
This value should be between 0 and 1 for best results.
see
Static And Kinetic Friction
Inherited from
Defined in
src/physics/object.ts:42
stickyCollider
โข stickyCollider: boolean
= true
Wether or not to clone the object's position and rotation to it's collider.
Inherited from
Defined in
src/physics/collisionObject.ts:33
takesGravity
โข takesGravity: boolean
= true
Wether or not the object should take gravity from the physics world.
Inherited from
Defined in
src/physics/object.ts:104
torque
โข torque: number
= 0
The object's torque in newtons, can be thought of as rotational force.
Inherited from
Defined in
src/physics/object.ts:75
totalContacts
โข totalContacts: number
= 0
The number of contact points the object is colliding at.
Inherited from
Defined in
src/physics/collisionObject.ts:28
velocity
โข velocity: vec2
The object's velocity in world space units (metres).
Inherited from
Defined in
src/physics/object.ts:63
Methods
addEventListener
โธ addEventListener(event
, listener
): boolean
Executes a function when an event is fired.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to listen for |
listener | Listener | The function to execute when the event fired |
Returns
boolean
Wether or not the listener was added
Inherited from
Defined in
src/object2d.ts:209
advancePosition
โธ advancePosition(delta
, smoothingRadius
): void
Advanced the particle's position.
Parameters
Name | Type | Description |
---|---|---|
delta | number | The time since the last update |
smoothingRadius | number | The smoothing radius of the fluid |
Returns
void
Defined in
src/physics/fluid/particle.ts:108
applyForce
โธ applyForce(force
, contact?
): void
Adds a force to the object's current total force vector.
If no contact point is provided then the force will be applied at the object's centre, generating 0 torque.
Parameters
Name | Type | Description |
---|---|---|
force | vec2 | The force vector to apply |
contact? | vec2 | The local position on the body to apply the force at |
Returns
void
Inherited from
Defined in
src/physics/object.ts:156
applyForceAtAngle
โธ applyForceAtAngle(force
, angle
, contact?
): void
Applies a force to the object at an angle.
The direction vector is calculated from the unit y+ vector.
If no contact point is provided then the force will be applied at the object's centre, generating 0 torque.
Parameters
Name | Type | Description |
---|---|---|
force | number | The force to apply in newtons |
angle | number | The angle at which to apply the force in radians (world space) |
contact? | vec2 | The local position on the body to apply the force at |
Returns
void
Inherited from
Defined in
src/physics/object.ts:178
applyImpulse
โธ applyImpulse(impulse
, contactVector
): void
Applies an impulse to the physics object.
This will apply an instantaneous change to the object's angular and linear velocity.
Parameters
Name | Type | Description |
---|---|---|
impulse | vec2 | The impulse to apply |
contactVector | vec2 | A vector from the object's center to the contact point |
Returns
void
Inherited from
Defined in
src/physics/object.ts:199
computeDoubleDensityRelaxation
โธ computeDoubleDensityRelaxation(smoothingRadius
): void
Computes the density and density near of the particle based on it's neighbours.
Parameters
Name | Type | Description |
---|---|---|
smoothingRadius | number | The smoothing radius of the fluid |
Returns
void
Defined in
src/physics/fluid/particle.ts:68
computeNewVelocity
โธ computeNewVelocity(delta
, gravity
): void
Comptues the particle's new velocity and performs the second force solving pass.
Parameters
Name | Type | Description |
---|---|---|
delta | number | The time since the last update |
gravity | vec2 | The physics world's gravity vector |
Returns
void
Defined in
src/physics/fluid/particle.ts:145
computePressure
โธ computePressure(stiffness
, stiffnessNear
, restDensity
): void
Calculate the pressure the particle based on it's neighbours.
Parameters
Name | Type | Description |
---|---|---|
stiffness | number | - |
stiffnessNear | number | - |
restDensity | number | The rest density of the fluid |
Returns
void
Defined in
src/physics/fluid/particle.ts:97
findNeighbours
โธ findNeighbours(kdTree
, smoothingRadius
, smoothingRadiusSqr
): void
Finds particles which are closer to this particle than the fluid's smoothing radius.
Particles which are closer than this distance are added to this particle's neighbours array.
Parameters
Name | Type | Description |
---|---|---|
kdTree | kdTree | The kdTree of the fluid |
smoothingRadius | number | The fluid's smoothing radius |
smoothingRadiusSqr | number | The fluid's smoothing radius squared |
Returns
void
Defined in
src/physics/fluid/particle.ts:59
fireEvent
โธ fireEvent(event
, ...e
): void
Executes all listeners attached to a given event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event to fire |
...e | any | The data to pass to each event listener |
Returns
void
Inherited from
Defined in
src/object2d.ts:185
getEventListeners
โธ getEventListeners(event
): Listener
[]
Gets the listeners attached to an event.
Parameters
Name | Type |
---|---|
event | string |
Returns
Listener
[]
An array of listeners attached to the given event
Inherited from
Defined in
src/object2d.ts:198
getEvents
โธ getEvents(): string
[]
Gets the events that can be listened to on the object.
Returns
string
[]
The events the object supports
Inherited from
Defined in
src/object2d.ts:175
getInertia
โธ getInertia(): number
Gets the moment of inertia of the object.
Returns
number
The inertia of the object
Inherited from
Defined in
src/physics/object.ts:257
getInverseInertia
โธ getInverseInertia(): number
Gets the inverse moment of inertia of the object (1 / inertia).
Returns
number
The inverse inertia of the object
Inherited from
Defined in
src/physics/object.ts:266
getInverseMass
โธ getInverseMass(): number
Gets the inverse mass of the object (1 / mass).
Returns
number
The inverse mass of the object
Inherited from
Defined in
src/physics/object.ts:234
getMass
โธ getMass(): number
Gets the mass of the object.
Returns
number
The mass of the object
Inherited from
Defined in
src/physics/object.ts:225
getPosition
โธ getPosition(): vec2
Gets the object's position.
Returns
vec2
The object's position as a vec2
Inherited from
Defined in
src/object2d.ts:82
getRadius
โธ getRadius(): number
Gets the radius of the particle.
Returns
number
The particle's radius
Defined in
src/physics/fluid/particle.ts:169
getRotation
โธ getRotation(): number
Gets the object's rotation as a number in radians relative to y+.
Returns
number
The object's rotation
Inherited from
Defined in
src/object2d.ts:139
moveRight
โธ moveRight(dist
): void
Moves the object's position right (x+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move right, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:100
moveUp
โธ moveUp(dist
): void
Moves the object's position up (y+) relative to it's rotation.
Parameters
Name | Type | Description |
---|---|---|
dist | number | The distance to move up, can be + or - |
Returns
void
Inherited from
Defined in
src/object2d.ts:114
removeEventListener
โธ removeEventListener(event
, listener
): boolean
Removes a listener from an event.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event the listener is attached to |
listener | Listener | The listener to remove |
Returns
boolean
Wether or not the listener was removed
Inherited from
Defined in
src/object2d.ts:223
rotate
โธ rotate(angle
): void
Increments the object's rotation by an angle in radians.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The angle to rotate by in radians |
Returns
void
Inherited from
Defined in
src/object2d.ts:148
setInertia
โธ setInertia(inertia
): void
Sets the moment of inertia of the object.
Also computes the inverse inertia.
NOTE: Setting the inertia to 0 will act as infinite inertia.
Parameters
Name | Type | Description |
---|---|---|
inertia | number | The objects new inertia |
Returns
void
Inherited from
Defined in
src/physics/object.ts:247
setMass
โธ setMass(mass
): void
Sets the mass of the object in kg.
Also computes the inverse mass.
NOTE: Setting the mass to 0 will act as infinite mass.
Parameters
Name | Type | Description |
---|---|---|
mass | number | The objects new mass |
Returns
void
Inherited from
Defined in
src/physics/object.ts:213
setPosition
โธ setPosition(pos
): void
Sets the object's position.
Also sets this.collider
's position, if this.stickyCollider
is true.
Parameters
Name | Type | Description |
---|---|---|
pos | vec2 | The object's new position |
Returns
void
Inherited from
Defined in
src/physics/collisionObject.ts:121
setPositionX
โธ setPositionX(x
): void
Sets the x component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
x | number | The object's new x coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:56
setPositionY
โธ setPositionY(y
): void
Sets the y component of the object's position.
Parameters
Name | Type | Description |
---|---|---|
y | number | The object's new y coordinate |
Returns
void
Inherited from
Defined in
src/object2d.ts:69
setRadius
โธ setRadius(radius
): void
Sets the particle's radius.
Parameters
Name | Type | Description |
---|---|---|
radius | number | The particle's new radius |
Returns
void
Defined in
src/physics/fluid/particle.ts:159
setRotation
โธ setRotation(angle
): void
Sets the object's rotation, in radians.
Also sets this.collider
's rotation, if this.stickyCollider
is true.
Parameters
Name | Type | Description |
---|---|---|
angle | number | The object's new rotation angle (in radians) |
Returns
void
Inherited from
Defined in
src/physics/collisionObject.ts:133
setupEvents
โธ Protected
setupEvents(): void
Sets all the events that can be used in listeners
.
Returns
void
Inherited from
Defined in
src/physics/rigidbody.ts:31
testCollision
โธ testCollision(B
): CollisionResult
Checks if this object's collider is colliding with another object's collider.
Parameters
Name | Type | Description |
---|---|---|
B | CollisionObject | CollisionObject to test collisions against |
Returns
CollisionResult with the results of the test
Inherited from
Defined in
src/physics/collisionObject.ts:75
translate
โธ translate(v
): void
Translates the object by the provided vector.
Parameters
Name | Type | Description |
---|---|---|
v | vec2 | The vector to translate by |
Returns
void
Inherited from
Defined in
src/object2d.ts:91