PhysicsWorld class
Manages a world of physics objects and their interactions.
Constructors
-
PhysicsWorld({List<
PhysicsObject> ? objects, double gravity = PhysicsConstants.defaultGravity, bool isActive = true, double windX = 0.0, double windY = 0.0, bool windEnabled = false, double? leftBound, double? rightBound, double? topBound, double? bottomBound, void onBoundaryCollision(PhysicsObject, String)?}) - Creates a new physics world.
Properties
- activeObjectCount → int
-
Gets the number of active objects.
no setter
-
activeObjects
→ List<
PhysicsObject> -
Gets all active objects.
no setter
- altitudeBasedGravity ↔ bool
-
Whether to vary gravity with altitude (inverse-square, Earth-like)
getter/setter pair
- bottomBound ↔ double?
-
World boundaries (optional)
getter/setter pair
-
centerOfMass
→ List<
double> -
Gets the center of mass of all objects.
no setter
- collisionDetector ↔ CollisionDetector
-
Collision detector for handling object interactions
getter/setter pair
- gravity ↔ double
-
Gravitational acceleration for the world
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- isActive ↔ bool
-
Whether the physics world is active
getter/setter pair
- leftBound ↔ double?
-
World boundaries (optional)
getter/setter pair
- metersPerPixel ↔ double
-
World-to-meters scale: meters per one pixel in Y (and X) direction
Defaults to 0.001 m/px (1 px = 1 mm)
getter/setter pair
-
objects
→ List<
PhysicsObject> -
List of all physics objects in the world
final
- onBoundaryCollision ↔ void Function(PhysicsObject, String)?
-
Callback for when objects hit boundaries
getter/setter pair
- planetRadiusMeters ↔ double
-
Planetary radius used for altitude-based gravity (meters)
getter/setter pair
- rightBound ↔ double?
-
World boundaries (optional)
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- topBound ↔ double?
-
World boundaries (optional)
getter/setter pair
- totalEnergy → double
-
Gets the total mechanical energy in the world.
no setter
- totalKineticEnergy → double
-
Gets the total kinetic energy in the world.
no setter
- totalPotentialEnergy → double
-
Gets the total potential energy in the world.
Potential energy is calculated relative to the ground level (reference point).
When an object is at rest on the ground, its potential energy is 0.
no setter
- windEnabled ↔ bool
-
Whether wind simulation is enabled
getter/setter pair
- windX ↔ double
-
Wind velocity in X direction (m/s)
getter/setter pair
- windY ↔ double
-
Wind velocity in Y direction (m/s)
getter/setter pair
Methods
-
addObject(
PhysicsObject object) → void - Adds an object to the physics world.
-
applyForceToAll(
double fx, double fy) → void - Applies a force to all objects in the world.
-
clear(
) → void - Clears all objects from the physics world.
-
configureAltitudeBasedGravity(
{required bool enabled, double? metersPerPixelOverride, double? planetRadiusMetersOverride}) → void - Enables/disables altitude-based gravity and optionally updates scale/planet.
-
getExpectedSpeedFromHeight(
PhysicsObject obj, {double? cachedGroundLevel}) → double - Calculates expected speed from energy conservation (ignoring air resistance). Formula: v = √(2gh) where h is height above ground. This shows the theoretical speed if all PE converts to KE.
-
getObjectsInArea(
double x, double y, double width, double height) → List< PhysicsObject> - Gets objects within a certain area.
-
getObjectsNearPoint(
double x, double y, double radius) → List< PhysicsObject> - Gets objects near a specific point.
-
getPotentialEnergy(
PhysicsObject obj, {double? cachedGroundLevel}) → double - Calculates potential energy for a single object. Uses ground level as reference point (PE = 0 when object is on ground).
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pause(
) → void - Pauses all physics in the world.
-
removeObject(
PhysicsObject object) → void - Removes an object from the physics world.
-
reset(
) → void - Resets all objects to their initial positions.
-
resume(
) → void - Resumes all physics in the world.
-
setBoundaries(
{double? left, double? right, double? top, double? bottom}) → void - Sets the world boundaries.
-
setGravity(
double newGravity) → void - Sets the gravity for the world.
-
setWind(
double newWindX, double newWindY) → void - Sets the wind velocity for the world.
-
setWindEnabled(
bool enabled) → void - Enables or disables wind simulation.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
double dt) → void - Updates the physics world for a given time step.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited