Skip to content

Instantly share code, notes, and snippets.

@BonsaiDen
Last active February 16, 2022 20:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BonsaiDen/6344844 to your computer and use it in GitHub Desktop.
Save BonsaiDen/6344844 to your computer and use it in GitHub Desktop.
Doc Markdown

Box.round( Float v ) ⇢ Integer

Rounds the given float to a integer, this function is intended for rendering purposes and tries to reduce jitter.

Box.World( Vec2 gravity = Vec2(0.0, 50.0), Integer steps = 10, Integer iterations = 10 )

  • Vec2 gravity ⬞ The gravity applied to all bodies contained by the world.

  • Integer steps ⬞ Number of simulation steps to perform on each world update.

  • Integer iterations ⬞ Number of iterations to perform for each collision contact.

Statics
  • Double EPSILON ⬞ Value used as a threshold for friction and resting of bodies.
Members
  • Integer contactCount ⬞ Number of contacts between the two bodies in the manifold.

  • Manifold[] contacts ⬞ List of contacts manifold that resulted from the last world update.

  • Vec2 gravity ⬞ The gravity applied to all bodies contained by the world.

  • addBody( Body body ) ⇢ Boolean

    Adds a body to the world.

    • Body body ⬞ Body to add.
  • containsBody( Body body ) ⇢ Boolean

    Checks whether a body is part of the world.

    • Body body ⬞ Body.
  • removeBody( Body body ) ⇢ Boolean

    Removes a body from the world.

    • Body body ⬞ Body to remove.
  • update( Double dt )

    Advances the simulation by the given number of seconds.

Box.AABB( Vec2 position, Vec2 extend, Double mass = 0.0, Double inertia = 0.0 ) extends Body

  • Vec2 position ⬞ Initial position of the AABB.

  • Vec2 extend ⬞ Extends of the AABB, the AABB will extend from its center in all directions based on the components of the vector.

  • Double mass ⬞ Mass of the AABB.

  • Double inertia ⬞ Inertia of the AABB.

Statics
  • Integer ShapeID ⬞ Unique ID identifying the collision shape.
Members
  • Vec2 extend ⬞ Extends of the object, each half.

  • computeMass( Double density )

    Computes the mass and inertia of the AABB based on its area and the given density.

Box.Circle( Vec2 position, Double radius, Double mass = 0.0, Double inertia = 0.0 ) extends Body

  • Vec2 position ⬞ Initial position of the Circle.

  • Double radius ⬞ Radius of the Cirlce.

  • Double mass ⬞ Mass of the Circle.

  • Double inertia ⬞ Inertia of the Circle.

Statics
  • Integer ShapeID ⬞ Unique ID identifying the collision shape.
Members
  • Double radius ⬞ Radius of the circle.

  • computeMass( Double density )

    Computes the mass and inertia of the circle based on its radius and the given density.

Box.Vec2( Double x, Double y )

  • Double x ⬞ x component of the vector.

  • Double y ⬞ y component of the vector.

Members
  • Double x ⬞ x component of the vector.

  • Double y ⬞ y component of the vector.

  • add( Vec2 v ) ⇢ Vec2

    Returns the result of the adding the second vector.

    • Vec2 v ⬞ Vector to be added.
  • angle( ) ⇢ Double

    Returns the direction in which the vector is pointing in radians.

  • cross( Vec2 v ) ⇢ Double

    Calculates the dot product between the two vectors.

    • Vec2 v ⬞ The second vector.
  • div( Double s ) ⇢ Vec2

    Divides the vector in-place.

  • dot( Vec2 v ) ⇢ Double

    Calculates the dot product of the two vectors.

    • Vec2 v ⬞ The second vector.
  • length( ) ⇢ Double

    Returns the length of the vector by using the square root of its length.

  • lengthSqr( ) ⇢ Double

    Returns the length of the vector by simply squaring its components.

  • mul( Double s ) ⇢ Vec2

    Multiplies the vector in-place.

  • normalize( ) ⇢ Vec2

    Returns a unit vector with length 1.

  • sub( Vec2 v ) ⇢ Vec2

    Returns a the result of the substraction of the second vector.

    • Vec2 v ⬞ Vector to be subtracted.
  • zero( )

    Sets both components of the vector to 0.

Body( Integer shapeId, Vec2 position, Double mass = 0.0, Double inertia = 0.0 )

  • Integer shapeId ⬞ Unique ID used identifying the bodies type.

  • Vec2 position ⬞ Initial position of the body.

  • Double mass ⬞ Mass of the body.

  • Double inertia ⬞ Inertia of the body.

Statics
  • Integer id ⬞ Unique ID counter identifying each {Body}.
Members
  • Double angularVelocity ⬞ Angular velocity in radians.

  • Double iI ⬞ Inverse inertia of the body. A value of 0 specifies infinite inertia.

  • Integer id ⬞ Unique ID of this body.

  • Double im ⬞ Inverse mass of the body. A value of 0 specifies infinite mass.

  • Double kineticFriction ⬞ Friction when the body is in motion.

  • Double orientation ⬞ Orientation in radians.

  • Vec2 pixelPosition ⬞ Position, rounded to the nearest full pixel value.

  • Vec2 position ⬞ Position.

  • Double restitution ⬞ "Bounciness" of the object's surface.

  • Double staticFriction ⬞ Friction when the body is at rest.

  • Double torque ⬞ Torque in radians.

  • Any user ⬞ Reference to custom user data attached to the body.

  • Vec2 velocity ⬞ Velocity of the body.

  • applyImpulse( Vec2 velocity, Vec2 angularVelocity )

    Applies the specified impulse to the body.

    • Vec2 velocity ⬞ Velocity to apply.

    • Vec2 angularVelocity ⬞ Angular velocity to apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment