lua.wetgenes.chipmunk.space
space=chipmunk.space()
Create the space you will be simulating physics in.
lua.wetgenes.chipmunk.space.add
space:add(body)
space:add(shape)
space:add(constraint)
Add a body/shape/constraint to the space.
lua.wetgenes.chipmunk.space.add_handler
space:add_handler(handler,id1,id2)
space:add_handler(handler,id1)
space:add_handler(handler)
Add collision callback handler, for the given collision types.
The handler table will have other values inserted in it and will be used as an arbiter table in callbacks. So always pass in a new one to this function. There does not seem to be a way to free handlers so be careful what you add.
id1,id2 can be a string in which case it will be converted to a number via the space:type function.
lua.wetgenes.chipmunk.space.body
space:body(...)
Create and add this body to the space.
lua.wetgenes.chipmunk.space.collision_bias
v=space:collision_bias()
v=space:collision_bias(v)
Get and/or Set the colision bias for this space.
lua.wetgenes.chipmunk.space.collision_persistence
v=space:collision_persistence()
v=space:collision_persistence(v)
Get and/or Set the collision persistence for this space.
lua.wetgenes.chipmunk.space.collision_slop
v=space:collision_slop()
v=space:collision_slop(v)
Get and/or Set the colision slop for this space.
lua.wetgenes.chipmunk.space.constraint
space:constraint(...)
Create and add this constraint to the space.
lua.wetgenes.chipmunk.space.contains
space:contains(body)
space:contains(shape)
space:contains(constraint)
Does the space contain this body/shape/constraint, possibly superfluous as we can check our own records.
lua.wetgenes.chipmunk.space.current_time_step
v=space:current_time_step()
Get the current time step for this space.
lua.wetgenes.chipmunk.space.damping
v=space:damping()
v=space:damping(v)
Get and/or Set the damping for this space.
lua.wetgenes.chipmunk.space.gravity
vx,vy=space:gravity()
vx,vy=space:gravity(vx,vy)
Get and/or Set the gravity vector for this space.
lua.wetgenes.chipmunk.space.idle_speed_threshold
v=space:idle_speed_threshold()
v=space:idle_speed_threshold(v)
Get and/or Set the idle speed threshold for this space.
lua.wetgenes.chipmunk.space.iterations
v=space:iterations()
v=space:iterations(v)
Get and/or Set the iterations for this space.
lua.wetgenes.chipmunk.space.locked
v=space:locked()
Get the locked state for this space, if true we cannot change shapes.
lua.wetgenes.chipmunk.space.query_bounding_box
array = space:query_bounding_box(lx,ly,hx,hy,group,categories,mask)
Find the shapes that are within this bounding box (lx,ly) to (hx,hy). Use group,categories and mask to filter the results.
Returns an array of shapes.
lua.wetgenes.chipmunk.space.query_point
array = space:query_point(x,y,d,group,categories,mask)
Find the shapes that are within d distance from the point at x,y. Use group,categories and mask to filter the results.
Returns an array of hit data, with each item containing the following.
it.shape -- the shape
it.point_x -- the point of contact (x)
it.point_y -- the point of contact (y)
it.distance -- the distance to the point of contact
it.gradient_x -- the normalised vector to collision (x)
it.gradient_y -- the normalised vector to collision (y)
lua.wetgenes.chipmunk.space.query_point_nearest
item = space:query_point_nearest(x,y,d,group,categories,mask)
Find the nearest shape that is within d distance from the point at x,y. Use group,categories and mask to filter the results.
returns a table with the following info or nil for no hit
it.shape -- the shape
it.point_x -- the point of contact (x)
it.point_y -- the point of contact (y)
it.distance -- the distance to the point of contact
it.gradient_x -- the normalised vector to collision (x)
it.gradient_y -- the normalised vector to collision (y)
lua.wetgenes.chipmunk.space.query_segment
array = space:query_segment(sx,sy,ex,ey,r,group,categories,mask)
Find the shapes that are along this raycast segment, from (sx,sy) to (ex,ey) with a radius of r. Use group,categories and mask to filter the results.
Returns an array of hit data, with each item containing the following.
it.shape -- the shape
it.point_x -- the point of contact (x)
it.point_y -- the point of contact (y)
it.normal_x -- the normal at contact (x)
it.normal_y -- the normal at contact (y)
it.alpha -- how far along the segment the contact happened (0 to 1)
lua.wetgenes.chipmunk.space.query_segment_first
it = space:query_segment_first(sx,sy,ex,ey,r,group,categories,mask)
Find the shapes that are along this raycast segment, from (sx,sy) to (ex,ey) with a radius of r. Use group,categories and mask to filter the results.
Returns a table with the following info or nil for no hit
it.shape -- the shape
it.point_x -- the point of contact (x)
it.point_y -- the point of contact (y)
it.normal_x -- the normal at contact (x)
it.normal_y -- the normal at contact (y)
it.alpha -- how far along the segment the contact happened (0 to 1)
lua.wetgenes.chipmunk.space.query_shape
array = space:query_shape(shape)
Find the shapes that intersect with the given shape.
Returns an array of hit data, with each item containing the following.
it.shape -- the shape
it.normal_x -- the normal at contact (x)
it.normal_y -- the normal at contact (y)
it.contacts -- array of contact points -> {ax,ay,bx,by,distance,etc...}
lua.wetgenes.chipmunk.space.reindex
space:reindex(shape)
space:reindex(body)
space:reindex()
Reindex the shapes, either a specific shape, all the shapes in a body or just all the static shapes.
lua.wetgenes.chipmunk.space.remove
space:remove(body)
space:remove(shape)
space:remove(constraint)
Remove a body/shape/constraint from this space.
lua.wetgenes.chipmunk.space.sleep_time_threshold
v=space:sleep_time_threshold()
v=space:sleep_time_threshold(v)
Get and/or Set the sleep time threshold for this space.
lua.wetgenes.chipmunk.space.step
space:step(time)
Run the simulation for time in seconds. EG 1/60.
lua.wetgenes.chipmunk.space.type
number = space:type(name)
name = space:type(number)
Manage collision types, pass in a string and always get a number out. This number is consistent only for this space.
Alternatively pass in a number and get a string or nil as a result.