Chipmunk class

Chipmunk class

Methods


Method new()

Initialize the simulation space

Usage

Chipmunk$new(gravity = cpv(0, -100), time_step = 0.01)

Arguments

gravity

vector object indication direction and strength of gravity. Default: cpv(0, -100)

time_step

simulation step size. smaller is more accurate. Default: 0.01 Add a shape of the given type


Method add_shape()

Usage

Chipmunk$add_shape(type, shape, friction, elasticity)

Arguments

type

one of segment, circle, box, polygon and static variants

shape

the cmShape ExternalPointer

friction

friction along segment. range [0, 1]

elasticity

Range [0, 1] Add a body of the given type


Method add_body()

Usage

Chipmunk$add_body(type, body, x, y, vx, vy, angle, angular_velocity)

Arguments

type

character name of type. must be a dynamic type

body

body to add. type = cpBody

x, y

initial body location

vx, vy

initial body velocity

angle

orientation angle in degrees

angular_velocity

default: 0 degrees/second Add a static segment


Method add_static_segment()

Usage

Chipmunk$add_static_segment(x1, y1, x2, y2, friction = 1, elasticity = 0)

Arguments

x1, y1, x2, y2

segment end points

friction

friction along segment. default 1. range [0, 1]

elasticity

default: 0 (no bounce). Range [0, 1]


Method get_static_segments()

Get the data.frame of all current segments Add a circular body to the space

Usage

Chipmunk$get_static_segments()


Method add_circle()

Usage

Chipmunk$add_circle(
  x,
  y,
  vx = 0,
  vy = 0,
  radius = 1,
  angular_velocity = 0,
  mass = 1,
  friction = 0.7,
  elasticity = 0
)

Arguments

x, y

initial body location

vx, vy

initial body velocity

radius

radius of body. default: 1

angular_velocity

default: 0 degrees/second

mass

mass of body. default: 1

friction

default: 0.7

elasticity

default: 0 (no bounce). Valid range [0, 1]


Method get_circles()

Get the location of all the circles Add a box body to the space

Usage

Chipmunk$get_circles()


Method add_box()

Usage

Chipmunk$add_box(
  x,
  y,
  vx = 0,
  vy = 0,
  width = 1.73,
  height = 1,
  angle = 0,
  radius = 0.05,
  angular_velocity = 0,
  mass = 1,
  friction = 0.7,
  elasticity = 0
)

Arguments

x, y

initial body location

vx, vy

initial body velocity

width, height

body width and height

angle

rotation angle in degrees. default 0

radius

radius of rounded corner

angular_velocity

default: 0 degrees/second

mass

mass of body. default: 1

friction

default: 0.7

elasticity

default: 0 (no bounce). Valid range [0, 1]


Method get_boxes()

Get the location of all the boxes

Usage

Chipmunk$get_boxes()

Returns

a data.frame with idx, width, height and rotation angle (radians)


Method get_boxes_as_polygons()

Get the location of all the boxes as a list of corner vertices Add a convex hull polygon to the space

Usage

Chipmunk$get_boxes_as_polygons()


Method add_polygon()

Usage

Chipmunk$add_polygon(
  xs,
  ys,
  angle = 0,
  x = 0,
  y = 0,
  vx = 0,
  vy = 0,
  radius = 0.05,
  angular_velocity = 0,
  mass = 1,
  friction = 0.7,
  elasticity = 0
)

Arguments

xs, ys

polygon vertices

angle

initial rotation angle in degrees. default 0

x, y

initial body location

vx, vy

initial body velocity

radius

radius of rounded corners

angular_velocity

default: 0 degrees/second

mass

mass of body. default: 1

friction

default: 0.7

elasticity

default: 0 (no bounce). Valid range [0, 1]


Method get_polygons()

Get the location of all the polygons

Usage

Chipmunk$get_polygons()


Method get_bodies()

Advanced: Get the list of Chipmunk cpBody objects

Usage

Chipmunk$get_bodies()


Method get_body_states()

Advanced: Get state of cpBody objects as data.frame

Usage

Chipmunk$get_body_states(type)

Arguments

type

cpbody type one of c('segment', 'circle', 'box', 'polygon') Advance the simulation by N timesteps


Method advance()

Usage

Chipmunk$advance(N = 1)

Arguments

N

number of time steps to advance


Method clone()

The objects of this class are cloneable with this method.

Usage

Chipmunk$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.