Liking cljdoc? Tell your friends :D

org.nfrac.cljbox2d.core

cljbox2d, a 2D physics engine.

A clojure wrapper for JBox2D, which is a close Java port of Erin Catto's excellent C++ Box2D physics engine.

[cljbox2d](https://github.com/floybix/cljbox2d/), a 2D physics engine.

A clojure wrapper for [JBox2D](http://www.jbox2d.org/), which is a
close Java port of Erin Catto's excellent C++
[Box2D](http://www.box2d.org/) physics engine.
raw docstring

aabbclj

(aabb fixt)
(aabb [x0 y0] [x1 y1])

Axis-Aligned Bounding Box

Axis-Aligned Bounding Box
sourceraw docstring

all-current-contactsclj

(all-current-contacts world)

Lazy seq of current contacts in the world. Each contact is a map as defined by the contact-data function. Contacts without actual contact points (i.e. created only due to overlapping bounding boxes) are excluded.

Lazy seq of current contacts in the world. Each contact is a map as
defined by the `contact-data` function. Contacts without actual
contact points (i.e. created only due to overlapping bounding
boxes) are excluded.
sourceraw docstring

alljointseqclj

(alljointseq world)

Lazy seq of all joints in the world.

Lazy seq of all joints in the world.
sourceraw docstring

anchor-aclj

(anchor-a jt)

The anchor point on bodyA in world coordinates

The anchor point on bodyA in world coordinates
sourceraw docstring

anchor-bclj

(anchor-b jt)

The anchor point on bodyB in world coordinates

The anchor point on bodyB in world coordinates
sourceraw docstring

angleclj

(angle body)

Angle of a body in radians

Angle of a body in radians
sourceraw docstring

angular-velocityclj

(angular-velocity body)

Angular velocity of a body in radians/second.

Angular velocity of a body in radians/second.
sourceraw docstring

angular-velocity!clj

(angular-velocity! body a-vel)
source

apply-force!clj

(apply-force! body force pt)

Apply a force in Newtons to body at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body.

Apply a force in Newtons to body at a world point. If the force is
not applied at the center of mass, it will generate a torque and
affect the angular velocity. This wakes up the body.
sourceraw docstring

apply-impulse!clj

(apply-impulse! body impulse pt)

Apply an impulse in N-seconds or kg-m/s at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body.

Apply an impulse in N-seconds or kg-m/s at a point. This
immediately modifies the velocity. It also modifies the angular
velocity if the point of application is not at the center of mass.
This wakes up the body.
sourceraw docstring

apply-torque!clj

(apply-torque! body torque)

Apply a torque in N-m, i.e. about the z-axis (out of the screen). This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body.

Apply a torque in N-m, i.e. about the z-axis (out of the screen).
This affects the angular velocity without affecting the linear
velocity of the center of mass. This wakes up the body.
sourceraw docstring

awake?clj

(awake? body)
source

body!clj

(body! world body-spec & fixture-specs)

Creates a Body together with its Fixtures. The body-spec map is passed to the body-def function. Each of the fixture-specs are passed to the fixture-def function.

Creates a Body together with its Fixtures. The `body-spec` map is
passed to the `body-def` function. Each of the `fixture-specs` are
passed to the `fixture-def` function.
sourceraw docstring

body-aclj

(body-a jt)

Return bodyA for a joint

Return bodyA for a joint
sourceraw docstring

body-bclj

(body-b jt)

Return bodyB for a joint

Return bodyB for a joint
sourceraw docstring

body-defclj

(body-def {:keys [type position angle bullet fixed-rotation gravity-scale
                  angular-damping linear-damping angular-velocity
                  linear-velocity user-data]
           :or {angular-velocity 0
                linear-velocity [0 0]
                linear-damping 0
                gravity-scale 1.0
                bullet false
                type :dynamic
                angle 0
                angular-damping 0
                fixed-rotation false
                position [0 0]}})

A BodyDef, which holds properties but not shapes. Do not call this directly, instead use (body!).

A BodyDef, which holds properties but not shapes. Do not call this
directly, instead use `(body!)`.
sourceraw docstring

body-moving?clj

(body-moving? body)
source

body-ofclj

(body-of fixt)

Get the body to which a fixture belongs

Get the body to which a fixture belongs
sourceraw docstring

body-typeclj

(body-type body)

The body type as a keyword :dynamic :static or :kinematic.

The body type as a keyword `:dynamic` `:static` or `:kinematic`.
sourceraw docstring

bodyseqclj

(bodyseq world)
(bodyseq world body)

Lazy seq of all bodies in the world, or a body list

Lazy seq of all bodies in the world, or a body list
sourceraw docstring

boxclj

(box hx hy)
(box hx hy center)
(box hx hy center angle)

Create a box shape from half-width, half-height, by default centered at [0 0]

Create a box shape from half-width, half-height,
by default centered at [0 0]
sourceraw docstring

circleclj

(circle radius)
(circle radius center)

Create a circle shape, by default centered at [0 0]

Create a circle shape, by default centered at [0 0]
sourceraw docstring

contact-dataclj

(contact-data contact)
(contact-data contact impulses)

Returns a map with keys :fixture-a :fixture-b :points :normal :normal-impulses :tangent-impulses from a JBox2D Contact object and optional ContactImpulse object. Returns nil if no contact points exist.

Returns a map with keys :fixture-a :fixture-b :points :normal
:normal-impulses :tangent-impulses from a JBox2D Contact object and
optional ContactImpulse object. Returns nil if no contact points
exist.
sourceraw docstring

contactingclj

(contacting bod)

Set of other bodies that the given body is currently contacting.

Set of other bodies that the given body is currently contacting.
sourceraw docstring

current-contactsclj

(current-contacts bod)

Lazy seq of contacts on this body. Each contact is a map as defined by the contact-data function. Contacts without actual contact points (i.e. created only due to overlapping bounding boxes) are excluded.

Lazy seq of contacts on this body. Each contact is a map as defined
by the `contact-data` function. Contacts without actual contact
points (i.e. created only due to overlapping bounding boxes) are
excluded.
sourceraw docstring

Destroyablecljprotocol

Abstraction for JBox2D objects which can be destroyed.

Abstraction for JBox2D objects which can be destroyed.

destroy!clj

(destroy! this)

Remove object from the World permanantly. Destroying a body automatically deletes all associated shapes and joints.

Remove object from the World permanantly. Destroying a body
automatically deletes all associated shapes and joints.
sourceraw docstring

edgeclj

(edge pt1 pt2)

Create an edge shape, a line between two points.

Create an edge shape, a line between two points.
sourceraw docstring

edge-chainclj

(edge-chain vertices)

Creates a chain of edge shapes, assumed not self-intersecting, left open at the ends.

Creates a chain of edge shapes, assumed not self-intersecting, left
open at the ends.
sourceraw docstring

edge-loopclj

(edge-loop vertices)

Creates a loop of edge shapes, assumed not self-intersecting, where the last point joins back to the first point.

Creates a loop of edge shapes, assumed not self-intersecting, where
the last point joins back to the first point.
sourceraw docstring

fixture!clj

(fixture! body fixture-spec)

Creates a Fixture on an existing Body. The second argument is a fixture specification map to be passed to the fixture-def function.

Creates a Fixture on an existing Body. The second argument is a
fixture specification map to be passed to the `fixture-def`
function.
sourceraw docstring

fixture-defclj

(fixture-def {:keys [shape density friction restitution is-sensor group-index
                     category-bits mask-bits user-data]
              :or {density 1
                   friction 0.3
                   restitution 0.3
                   is-sensor false
                   group-index 0
                   category-bits 1
                   mask-bits 65535}})

A FixtureDef: a shape with some physical properties. Do not call this directly, instead use (body!) or (fixture!).

:group-index allows a certain group of objects to never collide (negative) or always collide (positive). Zero means no collision group.

A FixtureDef: a shape with some physical properties. Do not call
this directly, instead use `(body!)` or `(fixture!)`.

`:group-index` allows a certain group of objects to never
collide (negative) or always collide (positive). Zero means no
collision group.
sourceraw docstring

fixture-ofclj

(fixture-of body)

Often a body will only have one fixture. This is a convenience function to pull out the first fixture from a body.

Often a body will only have one fixture. This is a convenience
function to pull out the first fixture from a body.
sourceraw docstring

fixtureseqclj

(fixtureseq body)

Lazy seq of fixtures on a body.

Lazy seq of fixtures on a body.
sourceraw docstring

gravityclj

(gravity world)

Gets the gravity vector.

Gets the gravity vector.
sourceraw docstring

gravity!clj

(gravity! world gravity)

Sets the gravity vector.

Sets the gravity vector.
sourceraw docstring

gravity-scaleclj

(gravity-scale body)
source

gravity-scale!clj

(gravity-scale! body z)
source

initspeccljmultimethod

Augments the joint specification map to define body-local anchors, axes, etc. from given initial world values (e.g. :world-anchor).

Augments the joint specification map to define body-local anchors,
axes, etc. from given initial world values (e.g. `:world-anchor`).
sourceraw docstring

joint!clj

(joint! spec)

Creates a joint from a spec map according to its :type key. In most cases the map must contain :body-a and :body-b.

  • :revolute joint constrains two bodies to share a common point while they are free to rotate about the point. The relative rotation about the shared point is the joint angle. You can limit the relative rotation with a joint limit that specifies a lower and upper angle. You can use a motor to drive the relative rotation about the shared point. A maximum motor torque is provided so that infinite forces are not generated.

  • :prismatic joint. This requires defining a line of motion using an axis and an anchor point. The definition uses local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.

  • :distance joint. This requires defining an anchor point on both bodies and the non-zero length of the distance joint. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. This helps when saving and loading a game. Note however that this initialisation function uses world points. For :damping-ratio 0 = no damping; 1 = critical damping.`

  • :rope joint requires two body-local anchor points and a maximum length.

  • :constant-volume joint. Connects a group a bodies together so they maintain a constant volume within them. Uses Distance joints internally.

  • :mouse joint. By convention body-a is ground and body-b is the selection.

  • :weld joint. This requires defining a common anchor point on both bodies. This initialisation function takes a world point.

Creates a joint from a spec map according to its `:type` key. In
most cases the map must contain `:body-a` and `:body-b`.

* `:revolute` joint constrains two bodies to share a common point
  while they are free to rotate about the point. The relative
  rotation about the shared point is the joint angle. You can limit
  the relative rotation with a joint limit that specifies a lower
  and upper angle. You can use a motor to drive the relative
  rotation about the shared point. A maximum motor torque is
  provided so that infinite forces are not generated.

* `:prismatic` joint. This requires defining a line of motion using
  an axis and an anchor point. The definition uses local anchor
  points and a local axis so that the initial configuration can
  violate the constraint slightly. The joint translation is zero
  when the local anchor points coincide in world space. Using local
  anchors and a local axis helps when saving and loading a game.

* `:distance` joint. This requires defining an anchor point on both
  bodies and the non-zero length of the distance joint. The
  definition uses local anchor points so that the initial
  configuration can violate the constraint slightly. This helps
  when saving and loading a game. *Note* however that this
  initialisation function uses world points. For `:damping-ratio` 0
  = no damping; 1 = critical damping.`

* `:rope` joint requires two body-local anchor points and a maximum
  length.

* `:constant-volume` joint. Connects a group a bodies together so
  they maintain a constant volume within them. Uses Distance joints
  internally.

* `:mouse` joint. By convention `body-a` is ground and `body-b` is
  the selection.

* `:weld` joint. This requires defining a common anchor point on
  both bodies. This initialisation function takes a world point.
sourceraw docstring

joint!*cljmultimethod

source

joint-angleclj

(joint-angle jt)
source

joint-angular-velocityclj

(joint-angular-velocity jt)

Relative angular velocity of two attached bodies in radians/second.

Relative angular velocity of two attached bodies in radians/second.
sourceraw docstring

joint-typeclj

(joint-type joint)

The joint type as a keyword.

The joint type as a keyword.
sourceraw docstring

jointseqclj

(jointseq body)

Lazy seq of all joints connected to a body

Lazy seq of all joints connected to a body
sourceraw docstring

Limitablecljprotocol

Abstraction for JBox2D joints which can have limits

Abstraction for JBox2D joints which can have limits

enable-limit!clj

(enable-limit! this flag)

Set whether limits are in effect.

Set whether limits are in effect.

limit-enabled?clj

(limit-enabled? this)

Whether limits are in effect on a joint.

Whether limits are in effect on a joint.

limitsclj

(limits this)

Vector of limits on a joint.

Vector of limits on a joint.

limits!clj

(limits! this limits)

Set [lower upper] limits on a joint.

Set [lower upper] limits on a joint.
sourceraw docstring

linear-velocityclj

(linear-velocity body)
(linear-velocity body loc-pt)

Linear velocity of a point on the body in local coordinates, by default its center of mass. In m/s.

Linear velocity of a point on the body in local coordinates, by
default its center of mass. In m/s.
sourceraw docstring

linear-velocity!clj

(linear-velocity! body vel)
source

linear-velocity-worldclj

(linear-velocity-world body world-pt)

Linear velocity of a point on the body in world coordinates. In m/s.

Linear velocity of a point on the body in world coordinates. In m/s.
sourceraw docstring

local-coordsclj

(local-coords fixt)

Local coordinates of polygon vertices. Approximated for circles.

Local coordinates of polygon vertices. Approximated for circles.
sourceraw docstring

Motorisedcljprotocol

Abstraction for JBox2D joints which can have motors

Abstraction for JBox2D joints which can have motors

max-motor-force!clj

(max-motor-force! this force)

Set maximum motor force

Set maximum motor force

max-motor-forceclj

(max-motor-force this)

Maximum motor force

Maximum motor force

motor-speed!clj

(motor-speed! this speed)

Set motor (target) speed, may or may not be enabled.

Set motor (target) speed, may or may not be enabled.

enable-motor!clj

(enable-motor! this flag)

Set whether a motor is enabled.

Set whether a motor is enabled.

motor-torqueclj

(motor-torque this inv-dt)

Current motor torque.

Current motor torque.

max-motor-torque!clj

(max-motor-torque! this torque)

Set maximum motor torque

Set maximum motor torque

motor-speedclj

(motor-speed this)

Motor (target) speed, may or may not be enabled.

Motor (target) speed, may or may not be enabled.

motor-enabled?clj

(motor-enabled? this)

Whether a motor is enabled on a joint.

Whether a motor is enabled on a joint.

joint-speedclj

(joint-speed this)

Current joint speed, may be linear or angular.

Current joint speed, may be linear or angular.

motor-forceclj

(motor-force this inv-dt)

Current motor force.

Current motor force.

max-motor-torqueclj

(max-motor-torque this)

Maximum motor torque

Maximum motor torque
sourceraw docstring

new-worldclj

(new-world)
(new-world gravity)

Returns a new Box2D world. Gravity defaults to [0 -10] m/s^2.

Returns a new Box2D world. Gravity defaults to [0 -10] m/s^2.
sourceraw docstring

polygonclj

(polygon vertices)

Create a polygon shape. Must be convex! It is assumed that the exterior is the right of each edge. i.e. vertices go counter-clockwise.

Create a polygon shape. Must be convex!
It is assumed that the exterior is the right of each edge.
i.e. vertices go counter-clockwise.
sourceraw docstring

power-wattsclj

(power-watts jt)

Instantaneous rate of work done by a revolute joint in Watts. Multiply by the time step to get work in Joules.

Instantaneous rate of work done by a revolute joint in Watts.
Multiply by the time step to get work in Joules.
sourceraw docstring

query-aabbclj

(query-aabb world bb)
(query-aabb world bb max-take)

Return a vector of (up to a given number of) fixtures overlapping an Axis-Aligned Bounding Box

Return a vector of (up to a given number of) fixtures overlapping
an Axis-Aligned Bounding Box
sourceraw docstring

query-at-pointclj

(query-at-point world pt)
(query-at-point world [x y] max-take)

Return a vector of fixtures overlapping the given point. The point is tested to be inside each shape, not just within its bounding box.

Return a vector of fixtures overlapping the given point. The point
is tested to be inside each shape, not just within its bounding
box.
sourceraw docstring

radiusclj

(radius fixt)

Radius of a Fixture's shape.

Radius of a Fixture's shape.
sourceraw docstring

raycastclj

(raycast world
         start-pt
         end-pt
         mode
         &
         {:keys [ignore] :or {ignore (constantly false)}})

Raycast from start-pt to end-pt, returning a sequence of fixture intersections, each a map (record) with keys :fixture :point :normal :fraction. If mode is :all, all intersections are returned in no particular order. If mode is :closest, only the closest intersection is returned in a single-element list, or an empty list if none exist. If an :ignore function is given, fixtures returning logical true from it are ignored.

Raycast from start-pt to end-pt, returning a sequence of fixture
intersections, each a map (record) with keys `:fixture` `:point`
`:normal` `:fraction`. If `mode` is `:all`, all intersections are
returned in no particular order. If mode is `:closest`, only the
closest intersection is returned in a single-element list, or an
empty list if none exist. If an `:ignore` function is given,
fixtures returning logical true from it are ignored.
sourceraw docstring

reaction-forceclj

(reaction-force jt inv-dt)

The reaction force on bodyB at the joint anchor in Newtons. Give the inverse of the timestep.

The reaction force on bodyB at the joint anchor in Newtons.
Give the inverse of the timestep.
sourceraw docstring

reaction-torqueclj

(reaction-torque jt inv-dt)

The reaction torque on bodyB in N*m. Give the inverse of the timestep.

The reaction torque on bodyB in N*m.
Give the inverse of the timestep.
sourceraw docstring

rodclj

(rod from-pt angle length width)

Create a long thin (box) shape extending from a point to a given length and with a given angle.

Create a long thin (box) shape extending from a point to a given
length and with a given angle.
sourceraw docstring

set-buffering-contact-listener!clj

(set-buffering-contact-listener! world)

Sets a ContactListener on the world which stores contacts. Returns an atom which will be populated with a sequence of contact-data records. Consumer is responsible for emptying it.

Sets a ContactListener on the world which stores contacts. Returns
an atom which will be populated with a sequence of `contact-data`
records. Consumer is responsible for emptying it.
sourceraw docstring

shape-typeclj

(shape-type fixt)

The shape type of a Fixture as a keyword e.g. :circle or :polygon.

The shape type of a Fixture as a keyword e.g. `:circle` or `:polygon`.
sourceraw docstring

sleep!clj

(sleep! body)

Put a body to sleep.

Put a body to sleep.
sourceraw docstring

snapshot-bodyclj

(snapshot-body body motion-only?)
source

snapshot-fixtureclj

(snapshot-fixture fixt)
source

snapshot-jointclj

(snapshot-joint jt)
source

snapshot-sceneclj

(snapshot-scene world prev-scene well-behaved?)
(snapshot-scene world prev-scene well-behaved? identify)

Returns an immutable value representation of the world for drawing, with keys :bodies and :joints. Body snapshots and joint snapshots are stored in two-level nested maps, allowing bodies to be grouped together. identify returns a 2-tuple giving the group and (nested) body keys. The default case stores all bodies under a single key :all and keys them by object hash value.

If a non-nil prev-scene is given then it is used as a basis: only the differences are applied to form a new value, improving memory use via structural sharing.

Argument well-behaved? asserts that Fixtures will not change, and that static bodies will not move: they can then be ignored for efficiency.

Returns an immutable value representation of the world for drawing,
with keys :bodies and :joints. Body snapshots and joint snapshots
are stored in two-level nested maps, allowing bodies to be grouped
together. `identify` returns a 2-tuple giving the group
and (nested) body keys. The default case stores all bodies under a
single key `:all` and keys them by object hash value.

If a non-nil `prev-scene` is given then it is used as a basis: only
the differences are applied to form a new value, improving memory
use via structural sharing.

Argument `well-behaved?` asserts that Fixtures will not change, and
that static bodies will not move: they can then be ignored for
efficiency.
sourceraw docstring

step!clj

(step! world dt)
(step! world dt velocity-iterations position-iterations)

Simulate the world for a time step given in seconds. Note that Box2D objects are locked during simulation. Returns the world (although it remains a mutable object).

Simulate the world for a time step given in seconds.
Note that Box2D objects are locked during simulation.
Returns the world (although it remains a mutable object).
sourceraw docstring

TwoDeeObjectcljprotocol

General methods for 2D physical objects which may be aggregated

General methods for 2D physical objects which may be aggregated

centerclj

(center this)

Center of mass in world coordinates.

Center of mass in world coordinates.

loc-centerclj

(loc-center this)

Center of mass in local coordinates.

Center of mass in local coordinates.

massclj

(mass this)

Total mass in kg.

Total mass in kg.

positionclj

(position this)
(position this loc-pt)

World coordinates of a local point, default [0 0].

World coordinates of a local point, default [0 0].

to-localclj

(to-local this pt)

Local coordinates of a world point.

Local coordinates of a world point.

to-local-vectclj

(to-local-vect this vect)

Local vector of a world vector.

Local vector of a world vector.
sourceraw docstring

UserDatacljprotocol

set-user-data!clj

(set-user-data! this x)

user-dataclj

(user-data this)
source

v2xyclj

(v2xy v)

Makes a vector [x y] from a Vec2

Makes a vector [x y] from a Vec2
sourceraw docstring

vary-user-dataclj

(vary-user-data this f & args)

Alters the userdata attached to this by applying f to the existing value (or the empty map) with given args. Returns the object.

Alters the userdata attached to `this` by applying `f` to the
existing value (or the empty map) with given args. Returns the
object.
sourceraw docstring

vec2clj

(vec2 v)
(vec2 x y)

Make a JBox2D Vec2 object from given x, y.

Make a JBox2D `Vec2` object from given `x`, `y`.
sourceraw docstring

wake!clj

(wake! body)

Wake up a body.

Wake up a body.
sourceraw docstring

world-coordsclj

(world-coords fixt)

World coordinates of polygon vertices. Approximated for circles.

World coordinates of polygon vertices. Approximated for circles.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close