const ( // A static body does not move during simulation and behaves as if it has infinite mass. // Static bodies can be moved manually by setting the position of the body. // The velocity of a static body is always zero. // Static bodies do not collide with other static or kinematic bodies. Static = BodyType(iota) // A kinematic body moves under simulation according to its velocity. // They do not respond to forces. // They can be moved manually, but normally a kinematic body is moved by setting its velocity. // A kinematic body behaves as if it has infinite mass. // Kinematic bodies do not collide with other static or kinematic bodies. Kinematic // A dynamic body is fully simulated. // Can be moved manually by the user, but normally they move according to forces. // A dynamic body can collide with all body types. // A dynamic body always has finite, non-zero mass. Dynamic )
const ( SleepyEvent = "physics.SleepyEvent" // Dispatched after a body has gone in to the sleepy state. SleepEvent = "physics.SleepEvent" // Dispatched after a body has fallen asleep. WakeUpEvent = "physics.WakeUpEvent" // Dispatched after a sleeping body has woken up. CollideEvent = "physics.CollideEvent" // Dispatched after two bodies collide. This event is dispatched on each of the two bodies involved in the collision. )
Body represents a physics-driven body.
NewBody creates and returns a pointer to a new RigidBody. The igraphic's geometry *must* be convex.
Apply force to a world point. This could for example be a point on the Body surface. Applying force this way will add to Body.force and Body.torque. relativePoint: A point relative to the center of mass to apply the force on.
Forces from a force field need to be multiplied by mass.
Apply impulse to a world point. This could for example be a point on the Body surface. An impulse is a force added to a body during a short period of time (impulse = force * time). Impulses will be added to Body.velocity and Body.angularVelocity. impulse: The amount of impulse to add. relativePoint: A point relative to the center of mass to apply the force on.
Apply force to a local point in the body. force: The force vector to apply, defined locally in the body frame. localPoint: A local point in the body to apply the force on.
Apply locally-defined impulse to a local point in the body. force: The force vector to apply, defined locally in the body frame. localPoint: A local point in the body to apply the force on.
ApplyVelocityDeltas adds the specified deltas to the body's linear and angular velocities.
ClearForces clears all forces on the body.
CollidableWith returns whether the body can collide with the specified body.
Get world velocity of a point in the body.
Move the body forward in time. dt: Time step quatNormalize: Set to true to normalize the body quaternion quatNormalizeFast: If the quaternion should be normalized using "fast" quaternion normalization
PointToLocal converts a world point to local body frame. TODO maybe move to Node
PointToWorld converts a local point to world frame. TODO maybe move to Node
SetBodyType sets the body type.
SetFixedRotation specifies whether the body should rotate.
TODO future: modify this to be "AddShape" and keep track of list of shapes, their positions and orientations For now each body can only be a single shape or a single geometry
Sleep forces the body to sleep.
Called every timestep to update internal sleep timer and change sleep state if needed. time: The world time in seconds
If checkSleeping is true then returns false if both bodies are currently sleeping.
UpdateEffectiveMassProperties If the body is sleeping, it should be immovable and thus have infinite mass during solve. This is solved by having a separate "effective mass" and other "effective" properties
Update .inertiaWorld and .invRotInertiaWorld
UpdateMassProperties Should be called whenever you change the body shape or mass.
VectorToLocal converts a world vector to local body frame. TODO maybe move to Node
VectorToWorld converts a local vector to world frame. TODO maybe move to Node
WakeUp wakes the body up.
BodyType specifies how the body is affected during the simulation.