Raxol.Animation.Physics.PhysicsEngine (Raxol v0.2.0)

View Source

Physics engine for Raxol animations.

Provides physics-based animation capabilities including:

  • Spring simulations
  • Gravity and bounce effects
  • Friction and damping
  • Collisions
  • Particle systems
  • Force fields

These can be used to create natural, organic animations that respond to user interactions in a physically plausible way.

Summary

Functions

Adds a force field to the physics world.

Adds an object to the physics world.

Applies an impulse force to an object.

Creates a particle system at the specified position.

Creates a new physics object with the given properties.

Creates a new physics world with default values.

Creates a new physics world with custom settings.

Removes an object from the physics world.

Sets the boundaries of the physics world.

Updates the physics world by one time step.

Types

physics_object()

@type physics_object() :: %{
  id: String.t(),
  position: Raxol.Animation.Physics.Vector.t(),
  velocity: Raxol.Animation.Physics.Vector.t(),
  acceleration: Raxol.Animation.Physics.Vector.t(),
  mass: float(),
  forces: [Raxol.Animation.Physics.Vector.t()],
  constraints: map(),
  properties: map()
}

world_state()

@type world_state() :: %{
  objects: %{required(String.t()) => physics_object()},
  gravity: Raxol.Animation.Physics.Vector.t(),
  time_scale: float(),
  iteration: non_neg_integer(),
  boundaries: map(),
  force_fields: [Raxol.Animation.Physics.ForceField.t()],
  last_update: integer()
}

Functions

add_force_field(world, force_field)

Adds a force field to the physics world.

add_object(world, object)

Adds an object to the physics world.

apply_impulse(world, object_id, impulse)

Applies an impulse force to an object.

create_particle_system(world, position, count, opts \\ [])

Creates a particle system at the specified position.

new_object(id, opts \\ [])

Creates a new physics object with the given properties.

new_world()

Creates a new physics world with default values.

new_world(opts)

Creates a new physics world with custom settings.

remove_object(world, object_id)

Removes an object from the physics world.

set_boundaries(world, boundaries)

Sets the boundaries of the physics world.

spring_force(world, object_id_1, object_id_2, spring_constant, rest_length)

Creates a spring force between two objects.

update(world, delta_time \\ nil)

Updates the physics world by one time step.