Skip to content

Instantly share code, notes, and snippets.

@oprypin
Created June 1, 2015 18:31
Show Gist options
  • Save oprypin/1157d351185dae0cab46 to your computer and use it in GitHub Desktop.
Save oprypin/1157d351185dae0cab46 to your computer and use it in GitHub Desktop.
crystalize.py Chipmunk
lib CP
fun message = "cpMessage"(condition : UInt8*, file : UInt8*, line : Int32, is_error : Int32, is_hard_error : Int32, message : UInt8*, ...) : Void
alias Float = Float64
alias HashValue = LibC::SizeT
alias CollisionID = UInt32
alias Bool = UInt8
alias DataPointer = Void*
alias CollisionType = LibC::SizeT
alias Group = LibC::SizeT
alias Bitmask = UInt32
alias Timestamp = UInt32
struct Vect
x : Float
y : Float
end
struct Transform
a : Float
b : Float
c : Float
d : Float
tx : Float
ty : Float
end
struct Mat2x2
a : Float
b : Float
c : Float
d : Float
end
type Array = Void*
type HashSet = Void*
type Body = Void*
type Shape = Void*
type CircleShape = Void*
type SegmentShape = Void*
type PolyShape = Void*
type Constraint = Void*
type PinJoint = Void*
type SlideJoint = Void*
type PivotJoint = Void*
type GrooveJoint = Void*
type DampedSpring = Void*
type DampedRotarySpring = Void*
type RotaryLimitJoint = Void*
type RatchetJoint = Void*
type GearJoint = Void*
type SimpleMotorJoint = Void*
type CollisionHandler = Void*
type ContactPointSet = Void*
type Arbiter = Void*
type Space = Void*
struct BB
l : Float
b : Float
r : Float
t : Float
end
alias SpatialIndexBBFunc = (Void*) -> BB
alias SpatialIndexIteratorFunc = (Void*, Void*) -> Void
alias SpatialIndexQueryFunc = (Void*, Void*, CollisionID, Void*) -> CollisionID
alias SpatialIndexSegmentQueryFunc = (Void*, Void*, Void*) -> Float
type SpatialIndexClass = Void*
type SpatialIndex = Void*
struct SpatialIndex
klass : SpatialIndexClass
bbfunc : SpatialIndexBBFunc
static_index : SpatialIndex
dynamic_index : SpatialIndex
end
type SpaceHash = Void*
fun space_hash_alloc = "cpSpaceHashAlloc"() : SpaceHash
fun space_hash_init = "cpSpaceHashInit"(hash : SpaceHash, celldim : Float, numcells : Int32, bbfunc : SpatialIndexBBFunc, static_index : SpatialIndex) : SpatialIndex
fun space_hash_new = "cpSpaceHashNew"(celldim : Float, cells : Int32, bbfunc : SpatialIndexBBFunc, static_index : SpatialIndex) : SpatialIndex
fun space_hash_resize = "cpSpaceHashResize"(hash : SpaceHash, celldim : Float, numcells : Int32) : Void
type BBTree = Void*
fun bb_tree_alloc = "cpBBTreeAlloc"() : BBTree
fun bb_tree_init = "cpBBTreeInit"(tree : BBTree, bbfunc : SpatialIndexBBFunc, static_index : SpatialIndex) : SpatialIndex
fun bb_tree_new = "cpBBTreeNew"(bbfunc : SpatialIndexBBFunc, static_index : SpatialIndex) : SpatialIndex
fun bb_tree_optimize = "cpBBTreeOptimize"(index : SpatialIndex) : Void
alias BBTreeVelocityFunc = (Void*) -> Vect
fun bb_tree_set_velocity_func = "cpBBTreeSetVelocityFunc"(index : SpatialIndex, func : BBTreeVelocityFunc) : Void
type Sweep1D = Void*
fun sweep1_d_alloc = "cpSweep1DAlloc"() : Sweep1D
fun sweep1_d_init = "cpSweep1DInit"(sweep : Sweep1D, bbfunc : SpatialIndexBBFunc, static_index : SpatialIndex) : SpatialIndex
fun sweep1_d_new = "cpSweep1DNew"(bbfunc : SpatialIndexBBFunc, static_index : SpatialIndex) : SpatialIndex
alias SpatialIndexDestroyImpl = (SpatialIndex) -> Void
alias SpatialIndexCountImpl = (SpatialIndex) -> Int32
alias SpatialIndexEachImpl = (SpatialIndex, SpatialIndexIteratorFunc, Void*) -> Void
alias SpatialIndexContainsImpl = (SpatialIndex, Void*, HashValue) -> Bool
alias SpatialIndexInsertImpl = (SpatialIndex, Void*, HashValue) -> Void
alias SpatialIndexRemoveImpl = (SpatialIndex, Void*, HashValue) -> Void
alias SpatialIndexReindexImpl = (SpatialIndex) -> Void
alias SpatialIndexReindexObjectImpl = (SpatialIndex, Void*, HashValue) -> Void
alias SpatialIndexReindexQueryImpl = (SpatialIndex, SpatialIndexQueryFunc, Void*) -> Void
alias SpatialIndexQueryImpl = (SpatialIndex, Void*, BB, SpatialIndexQueryFunc, Void*) -> Void
alias SpatialIndexSegmentQueryImpl = (SpatialIndex, Void*, Vect, Vect, Float, SpatialIndexSegmentQueryFunc, Void*) -> Void
struct SpatialIndexClass
destroy : SpatialIndexDestroyImpl
count : SpatialIndexCountImpl
each : SpatialIndexEachImpl
contains : SpatialIndexContainsImpl
insert : SpatialIndexInsertImpl
remove : SpatialIndexRemoveImpl
reindex : SpatialIndexReindexImpl
reindex_object : SpatialIndexReindexObjectImpl
reindex_query : SpatialIndexReindexQueryImpl
query : SpatialIndexQueryImpl
segment_query : SpatialIndexSegmentQueryImpl
end
fun spatial_index_free = "cpSpatialIndexFree"(index : SpatialIndex) : Void
fun spatial_index_collide_static = "cpSpatialIndexCollideStatic"(dynamic_index : SpatialIndex, static_index : SpatialIndex, func : SpatialIndexQueryFunc, data : Void*) : Void
fun arbiter_get_restitution = "cpArbiterGetRestitution"(arb : Arbiter) : Float
fun arbiter_set_restitution = "cpArbiterSetRestitution"(arb : Arbiter, restitution : Float) : Void
fun arbiter_get_friction = "cpArbiterGetFriction"(arb : Arbiter) : Float
fun arbiter_set_friction = "cpArbiterSetFriction"(arb : Arbiter, friction : Float) : Void
fun arbiter_get_surface_velocity = "cpArbiterGetSurfaceVelocity"(arb : Arbiter) : Vect
fun arbiter_set_surface_velocity = "cpArbiterSetSurfaceVelocity"(arb : Arbiter, vr : Vect) : Void
fun arbiter_get_user_data = "cpArbiterGetUserData"(arb : Arbiter) : DataPointer
fun arbiter_set_user_data = "cpArbiterSetUserData"(arb : Arbiter, user_data : DataPointer) : Void
fun arbiter_total_impulse = "cpArbiterTotalImpulse"(arb : Arbiter) : Vect
fun arbiter_total_ke = "cpArbiterTotalKE"(arb : Arbiter) : Float
fun arbiter_ignore = "cpArbiterIgnore"(arb : Arbiter) : Bool
fun arbiter_get_shapes = "cpArbiterGetShapes"(arb : Arbiter, a : Shape, b : Shape) : Void
fun arbiter_get_bodies = "cpArbiterGetBodies"(arb : Arbiter, a : Body, b : Body) : Void
struct Anonymous1
point_a : Vect
point_b : Vect
distance : Float
end
struct ContactPointSet
count : Int32
normal : Vect
points : Anonymous1[2]
end
fun arbiter_get_contact_point_set = "cpArbiterGetContactPointSet"(arb : Arbiter) : ContactPointSet
fun arbiter_set_contact_point_set = "cpArbiterSetContactPointSet"(arb : Arbiter, set : ContactPointSet) : Void
fun arbiter_is_first_contact = "cpArbiterIsFirstContact"(arb : Arbiter) : Bool
fun arbiter_is_removal = "cpArbiterIsRemoval"(arb : Arbiter) : Bool
fun arbiter_get_count = "cpArbiterGetCount"(arb : Arbiter) : Int32
fun arbiter_get_normal = "cpArbiterGetNormal"(arb : Arbiter) : Vect
fun arbiter_get_point_a = "cpArbiterGetPointA"(arb : Arbiter, i : Int32) : Vect
fun arbiter_get_point_b = "cpArbiterGetPointB"(arb : Arbiter, i : Int32) : Vect
fun arbiter_get_depth = "cpArbiterGetDepth"(arb : Arbiter, i : Int32) : Float
fun arbiter_call_wildcard_begin_a = "cpArbiterCallWildcardBeginA"(arb : Arbiter, space : Space) : Bool
fun arbiter_call_wildcard_begin_b = "cpArbiterCallWildcardBeginB"(arb : Arbiter, space : Space) : Bool
fun arbiter_call_wildcard_pre_solve_a = "cpArbiterCallWildcardPreSolveA"(arb : Arbiter, space : Space) : Bool
fun arbiter_call_wildcard_pre_solve_b = "cpArbiterCallWildcardPreSolveB"(arb : Arbiter, space : Space) : Bool
fun arbiter_call_wildcard_post_solve_a = "cpArbiterCallWildcardPostSolveA"(arb : Arbiter, space : Space) : Void
fun arbiter_call_wildcard_post_solve_b = "cpArbiterCallWildcardPostSolveB"(arb : Arbiter, space : Space) : Void
fun arbiter_call_wildcard_separate_a = "cpArbiterCallWildcardSeparateA"(arb : Arbiter, space : Space) : Void
fun arbiter_call_wildcard_separate_b = "cpArbiterCallWildcardSeparateB"(arb : Arbiter, space : Space) : Void
enum BodyType
BODY_TYPE_DYNAMIC
BODY_TYPE_KINEMATIC
BODY_TYPE_STATIC
end
alias BodyVelocityFunc = (Body, Vect, Float, Float) -> Void
alias BodyPositionFunc = (Body, Float) -> Void
fun body_alloc = "cpBodyAlloc"() : Body
fun body_init = "cpBodyInit"(body : Body, mass : Float, moment : Float) : Body
fun body_new = "cpBodyNew"(mass : Float, moment : Float) : Body
fun body_new_kinematic = "cpBodyNewKinematic"() : Body
fun body_new_static = "cpBodyNewStatic"() : Body
fun body_destroy = "cpBodyDestroy"(body : Body) : Void
fun body_free = "cpBodyFree"(body : Body) : Void
fun body_activate = "cpBodyActivate"(body : Body) : Void
fun body_activate_static = "cpBodyActivateStatic"(body : Body, filter : Shape) : Void
fun body_sleep = "cpBodySleep"(body : Body) : Void
fun body_sleep_with_group = "cpBodySleepWithGroup"(body : Body, group : Body) : Void
fun body_is_sleeping = "cpBodyIsSleeping"(body : Body) : Bool
fun body_get_type = "cpBodyGetType"(body : Body) : BodyType
fun body_set_type = "cpBodySetType"(body : Body, type : BodyType) : Void
fun body_get_space = "cpBodyGetSpace"(body : Body) : Space
fun body_get_mass = "cpBodyGetMass"(body : Body) : Float
fun body_set_mass = "cpBodySetMass"(body : Body, m : Float) : Void
fun body_get_moment = "cpBodyGetMoment"(body : Body) : Float
fun body_set_moment = "cpBodySetMoment"(body : Body, i : Float) : Void
fun body_get_position = "cpBodyGetPosition"(body : Body) : Vect
fun body_set_position = "cpBodySetPosition"(body : Body, pos : Vect) : Void
fun body_get_center_of_gravity = "cpBodyGetCenterOfGravity"(body : Body) : Vect
fun body_set_center_of_gravity = "cpBodySetCenterOfGravity"(body : Body, cog : Vect) : Void
fun body_get_velocity = "cpBodyGetVelocity"(body : Body) : Vect
fun body_set_velocity = "cpBodySetVelocity"(body : Body, velocity : Vect) : Void
fun body_get_force = "cpBodyGetForce"(body : Body) : Vect
fun body_set_force = "cpBodySetForce"(body : Body, force : Vect) : Void
fun body_get_angle = "cpBodyGetAngle"(body : Body) : Float
fun body_set_angle = "cpBodySetAngle"(body : Body, a : Float) : Void
fun body_get_angular_velocity = "cpBodyGetAngularVelocity"(body : Body) : Float
fun body_set_angular_velocity = "cpBodySetAngularVelocity"(body : Body, angular_velocity : Float) : Void
fun body_get_torque = "cpBodyGetTorque"(body : Body) : Float
fun body_set_torque = "cpBodySetTorque"(body : Body, torque : Float) : Void
fun body_get_rotation = "cpBodyGetRotation"(body : Body) : Vect
fun body_get_user_data = "cpBodyGetUserData"(body : Body) : DataPointer
fun body_set_user_data = "cpBodySetUserData"(body : Body, user_data : DataPointer) : Void
fun body_set_velocity_update_func = "cpBodySetVelocityUpdateFunc"(body : Body, velocity_func : BodyVelocityFunc) : Void
fun body_set_position_update_func = "cpBodySetPositionUpdateFunc"(body : Body, position_func : BodyPositionFunc) : Void
fun body_update_velocity = "cpBodyUpdateVelocity"(body : Body, gravity : Vect, damping : Float, dt : Float) : Void
fun body_update_position = "cpBodyUpdatePosition"(body : Body, dt : Float) : Void
fun body_local_to_world = "cpBodyLocalToWorld"(body : Body, point : Vect) : Vect
fun body_world_to_local = "cpBodyWorldToLocal"(body : Body, point : Vect) : Vect
fun body_apply_force_at_world_point = "cpBodyApplyForceAtWorldPoint"(body : Body, force : Vect, point : Vect) : Void
fun body_apply_force_at_local_point = "cpBodyApplyForceAtLocalPoint"(body : Body, force : Vect, point : Vect) : Void
fun body_apply_impulse_at_world_point = "cpBodyApplyImpulseAtWorldPoint"(body : Body, impulse : Vect, point : Vect) : Void
fun body_apply_impulse_at_local_point = "cpBodyApplyImpulseAtLocalPoint"(body : Body, impulse : Vect, point : Vect) : Void
fun body_get_velocity_at_world_point = "cpBodyGetVelocityAtWorldPoint"(body : Body, point : Vect) : Vect
fun body_get_velocity_at_local_point = "cpBodyGetVelocityAtLocalPoint"(body : Body, point : Vect) : Vect
fun body_kinetic_energy = "cpBodyKineticEnergy"(body : Body) : Float
alias BodyShapeIteratorFunc = (Body, Shape, Void*) -> Void
fun body_each_shape = "cpBodyEachShape"(body : Body, func : BodyShapeIteratorFunc, data : Void*) : Void
alias BodyConstraintIteratorFunc = (Body, Constraint, Void*) -> Void
fun body_each_constraint = "cpBodyEachConstraint"(body : Body, func : BodyConstraintIteratorFunc, data : Void*) : Void
alias BodyArbiterIteratorFunc = (Body, Arbiter, Void*) -> Void
fun body_each_arbiter = "cpBodyEachArbiter"(body : Body, func : BodyArbiterIteratorFunc, data : Void*) : Void
struct PointQueryInfo
shape : Shape
point : Vect
distance : Float
gradient : Vect
end
struct SegmentQueryInfo
shape : Shape
point : Vect
normal : Vect
alpha : Float
end
struct ShapeFilter
group : Group
categories : Bitmask
mask : Bitmask
end
fun shape_destroy = "cpShapeDestroy"(shape : Shape) : Void
fun shape_free = "cpShapeFree"(shape : Shape) : Void
fun shape_cache_bb = "cpShapeCacheBB"(shape : Shape) : BB
fun shape_update = "cpShapeUpdate"(shape : Shape, transform : Transform) : BB
fun shape_point_query = "cpShapePointQuery"(shape : Shape, p : Vect, out : PointQueryInfo*) : Float
fun shape_segment_query = "cpShapeSegmentQuery"(shape : Shape, a : Vect, b : Vect, radius : Float, info : SegmentQueryInfo*) : Bool
fun shapes_collide = "cpShapesCollide"(a : Shape, b : Shape) : ContactPointSet
fun shape_get_space = "cpShapeGetSpace"(shape : Shape) : Space
fun shape_get_body = "cpShapeGetBody"(shape : Shape) : Body
fun shape_set_body = "cpShapeSetBody"(shape : Shape, body : Body) : Void
fun shape_get_mass = "cpShapeGetMass"(shape : Shape) : Float
fun shape_set_mass = "cpShapeSetMass"(shape : Shape, mass : Float) : Void
fun shape_get_density = "cpShapeGetDensity"(shape : Shape) : Float
fun shape_set_density = "cpShapeSetDensity"(shape : Shape, density : Float) : Void
fun shape_get_moment = "cpShapeGetMoment"(shape : Shape) : Float
fun shape_get_area = "cpShapeGetArea"(shape : Shape) : Float
fun shape_get_center_of_gravity = "cpShapeGetCenterOfGravity"(shape : Shape) : Vect
fun shape_get_bb = "cpShapeGetBB"(shape : Shape) : BB
fun shape_get_sensor = "cpShapeGetSensor"(shape : Shape) : Bool
fun shape_set_sensor = "cpShapeSetSensor"(shape : Shape, sensor : Bool) : Void
fun shape_get_elasticity = "cpShapeGetElasticity"(shape : Shape) : Float
fun shape_set_elasticity = "cpShapeSetElasticity"(shape : Shape, elasticity : Float) : Void
fun shape_get_friction = "cpShapeGetFriction"(shape : Shape) : Float
fun shape_set_friction = "cpShapeSetFriction"(shape : Shape, friction : Float) : Void
fun shape_get_surface_velocity = "cpShapeGetSurfaceVelocity"(shape : Shape) : Vect
fun shape_set_surface_velocity = "cpShapeSetSurfaceVelocity"(shape : Shape, surface_velocity : Vect) : Void
fun shape_get_user_data = "cpShapeGetUserData"(shape : Shape) : DataPointer
fun shape_set_user_data = "cpShapeSetUserData"(shape : Shape, user_data : DataPointer) : Void
fun shape_get_collision_type = "cpShapeGetCollisionType"(shape : Shape) : CollisionType
fun shape_set_collision_type = "cpShapeSetCollisionType"(shape : Shape, collision_type : CollisionType) : Void
fun shape_get_filter = "cpShapeGetFilter"(shape : Shape) : ShapeFilter
fun shape_set_filter = "cpShapeSetFilter"(shape : Shape, filter : ShapeFilter) : Void
fun circle_shape_alloc = "cpCircleShapeAlloc"() : CircleShape
fun circle_shape_init = "cpCircleShapeInit"(circle : CircleShape, body : Body, radius : Float, offset : Vect) : CircleShape
fun circle_shape_new = "cpCircleShapeNew"(body : Body, radius : Float, offset : Vect) : Shape
fun circle_shape_get_offset = "cpCircleShapeGetOffset"(shape : Shape) : Vect
fun circle_shape_get_radius = "cpCircleShapeGetRadius"(shape : Shape) : Float
fun segment_shape_alloc = "cpSegmentShapeAlloc"() : SegmentShape
fun segment_shape_init = "cpSegmentShapeInit"(seg : SegmentShape, body : Body, a : Vect, b : Vect, radius : Float) : SegmentShape
fun segment_shape_new = "cpSegmentShapeNew"(body : Body, a : Vect, b : Vect, radius : Float) : Shape
fun segment_shape_set_neighbors = "cpSegmentShapeSetNeighbors"(shape : Shape, prev : Vect, next_ : Vect) : Void
fun segment_shape_get_a = "cpSegmentShapeGetA"(shape : Shape) : Vect
fun segment_shape_get_b = "cpSegmentShapeGetB"(shape : Shape) : Vect
fun segment_shape_get_normal = "cpSegmentShapeGetNormal"(shape : Shape) : Vect
fun segment_shape_get_radius = "cpSegmentShapeGetRadius"(shape : Shape) : Float
fun poly_shape_alloc = "cpPolyShapeAlloc"() : PolyShape
fun poly_shape_init = "cpPolyShapeInit"(poly : PolyShape, body : Body, count : Int32, verts : Vect*, transform : Transform, radius : Float) : PolyShape
fun poly_shape_init_raw = "cpPolyShapeInitRaw"(poly : PolyShape, body : Body, count : Int32, verts : Vect*, radius : Float) : PolyShape
fun poly_shape_new = "cpPolyShapeNew"(body : Body, count : Int32, verts : Vect*, transform : Transform, radius : Float) : Shape
fun poly_shape_new_raw = "cpPolyShapeNewRaw"(body : Body, count : Int32, verts : Vect*, radius : Float) : Shape
fun box_shape_init = "cpBoxShapeInit"(poly : PolyShape, body : Body, width : Float, height : Float, radius : Float) : PolyShape
fun box_shape_init2 = "cpBoxShapeInit2"(poly : PolyShape, body : Body, box : BB, radius : Float) : PolyShape
fun box_shape_new = "cpBoxShapeNew"(body : Body, width : Float, height : Float, radius : Float) : Shape
fun box_shape_new2 = "cpBoxShapeNew2"(body : Body, box : BB, radius : Float) : Shape
fun poly_shape_get_count = "cpPolyShapeGetCount"(shape : Shape) : Int32
fun poly_shape_get_vert = "cpPolyShapeGetVert"(shape : Shape, index : Int32) : Vect
fun poly_shape_get_radius = "cpPolyShapeGetRadius"(shape : Shape) : Float
alias ConstraintPreSolveFunc = (Constraint, Space) -> Void
alias ConstraintPostSolveFunc = (Constraint, Space) -> Void
fun constraint_destroy = "cpConstraintDestroy"(constraint : Constraint) : Void
fun constraint_free = "cpConstraintFree"(constraint : Constraint) : Void
fun constraint_get_space = "cpConstraintGetSpace"(constraint : Constraint) : Space
fun constraint_get_body_a = "cpConstraintGetBodyA"(constraint : Constraint) : Body
fun constraint_get_body_b = "cpConstraintGetBodyB"(constraint : Constraint) : Body
fun constraint_get_max_force = "cpConstraintGetMaxForce"(constraint : Constraint) : Float
fun constraint_set_max_force = "cpConstraintSetMaxForce"(constraint : Constraint, max_force : Float) : Void
fun constraint_get_error_bias = "cpConstraintGetErrorBias"(constraint : Constraint) : Float
fun constraint_set_error_bias = "cpConstraintSetErrorBias"(constraint : Constraint, error_bias : Float) : Void
fun constraint_get_max_bias = "cpConstraintGetMaxBias"(constraint : Constraint) : Float
fun constraint_set_max_bias = "cpConstraintSetMaxBias"(constraint : Constraint, max_bias : Float) : Void
fun constraint_get_collide_bodies = "cpConstraintGetCollideBodies"(constraint : Constraint) : Bool
fun constraint_set_collide_bodies = "cpConstraintSetCollideBodies"(constraint : Constraint, collide_bodies : Bool) : Void
fun constraint_get_pre_solve_func = "cpConstraintGetPreSolveFunc"(constraint : Constraint) : ConstraintPreSolveFunc
fun constraint_set_pre_solve_func = "cpConstraintSetPreSolveFunc"(constraint : Constraint, pre_solve_func : ConstraintPreSolveFunc) : Void
fun constraint_get_post_solve_func = "cpConstraintGetPostSolveFunc"(constraint : Constraint) : ConstraintPostSolveFunc
fun constraint_set_post_solve_func = "cpConstraintSetPostSolveFunc"(constraint : Constraint, post_solve_func : ConstraintPostSolveFunc) : Void
fun constraint_get_user_data = "cpConstraintGetUserData"(constraint : Constraint) : DataPointer
fun constraint_set_user_data = "cpConstraintSetUserData"(constraint : Constraint, user_data : DataPointer) : Void
fun constraint_get_impulse = "cpConstraintGetImpulse"(constraint : Constraint) : Float
fun constraint_is_pin_joint = "cpConstraintIsPinJoint"(constraint : Constraint) : Bool
fun pin_joint_alloc = "cpPinJointAlloc"() : PinJoint
fun pin_joint_init = "cpPinJointInit"(joint : PinJoint, a : Body, b : Body, anchor_a : Vect, anchor_b : Vect) : PinJoint
fun pin_joint_new = "cpPinJointNew"(a : Body, b : Body, anchor_a : Vect, anchor_b : Vect) : Constraint
fun pin_joint_get_anchor_a = "cpPinJointGetAnchorA"(constraint : Constraint) : Vect
fun pin_joint_set_anchor_a = "cpPinJointSetAnchorA"(constraint : Constraint, anchor_a : Vect) : Void
fun pin_joint_get_anchor_b = "cpPinJointGetAnchorB"(constraint : Constraint) : Vect
fun pin_joint_set_anchor_b = "cpPinJointSetAnchorB"(constraint : Constraint, anchor_b : Vect) : Void
fun pin_joint_get_dist = "cpPinJointGetDist"(constraint : Constraint) : Float
fun pin_joint_set_dist = "cpPinJointSetDist"(constraint : Constraint, dist : Float) : Void
fun constraint_is_slide_joint = "cpConstraintIsSlideJoint"(constraint : Constraint) : Bool
fun slide_joint_alloc = "cpSlideJointAlloc"() : SlideJoint
fun slide_joint_init = "cpSlideJointInit"(joint : SlideJoint, a : Body, b : Body, anchor_a : Vect, anchor_b : Vect, min : Float, max : Float) : SlideJoint
fun slide_joint_new = "cpSlideJointNew"(a : Body, b : Body, anchor_a : Vect, anchor_b : Vect, min : Float, max : Float) : Constraint
fun slide_joint_get_anchor_a = "cpSlideJointGetAnchorA"(constraint : Constraint) : Vect
fun slide_joint_set_anchor_a = "cpSlideJointSetAnchorA"(constraint : Constraint, anchor_a : Vect) : Void
fun slide_joint_get_anchor_b = "cpSlideJointGetAnchorB"(constraint : Constraint) : Vect
fun slide_joint_set_anchor_b = "cpSlideJointSetAnchorB"(constraint : Constraint, anchor_b : Vect) : Void
fun slide_joint_get_min = "cpSlideJointGetMin"(constraint : Constraint) : Float
fun slide_joint_set_min = "cpSlideJointSetMin"(constraint : Constraint, min : Float) : Void
fun slide_joint_get_max = "cpSlideJointGetMax"(constraint : Constraint) : Float
fun slide_joint_set_max = "cpSlideJointSetMax"(constraint : Constraint, max : Float) : Void
fun constraint_is_pivot_joint = "cpConstraintIsPivotJoint"(constraint : Constraint) : Bool
fun pivot_joint_alloc = "cpPivotJointAlloc"() : PivotJoint
fun pivot_joint_init = "cpPivotJointInit"(joint : PivotJoint, a : Body, b : Body, anchor_a : Vect, anchor_b : Vect) : PivotJoint
fun pivot_joint_new = "cpPivotJointNew"(a : Body, b : Body, pivot : Vect) : Constraint
fun pivot_joint_new2 = "cpPivotJointNew2"(a : Body, b : Body, anchor_a : Vect, anchor_b : Vect) : Constraint
fun pivot_joint_get_anchor_a = "cpPivotJointGetAnchorA"(constraint : Constraint) : Vect
fun pivot_joint_set_anchor_a = "cpPivotJointSetAnchorA"(constraint : Constraint, anchor_a : Vect) : Void
fun pivot_joint_get_anchor_b = "cpPivotJointGetAnchorB"(constraint : Constraint) : Vect
fun pivot_joint_set_anchor_b = "cpPivotJointSetAnchorB"(constraint : Constraint, anchor_b : Vect) : Void
fun constraint_is_groove_joint = "cpConstraintIsGrooveJoint"(constraint : Constraint) : Bool
fun groove_joint_alloc = "cpGrooveJointAlloc"() : GrooveJoint
fun groove_joint_init = "cpGrooveJointInit"(joint : GrooveJoint, a : Body, b : Body, groove_a : Vect, groove_b : Vect, anchor_b : Vect) : GrooveJoint
fun groove_joint_new = "cpGrooveJointNew"(a : Body, b : Body, groove_a : Vect, groove_b : Vect, anchor_b : Vect) : Constraint
fun groove_joint_get_groove_a = "cpGrooveJointGetGrooveA"(constraint : Constraint) : Vect
fun groove_joint_set_groove_a = "cpGrooveJointSetGrooveA"(constraint : Constraint, groove_a : Vect) : Void
fun groove_joint_get_groove_b = "cpGrooveJointGetGrooveB"(constraint : Constraint) : Vect
fun groove_joint_set_groove_b = "cpGrooveJointSetGrooveB"(constraint : Constraint, groove_b : Vect) : Void
fun groove_joint_get_anchor_b = "cpGrooveJointGetAnchorB"(constraint : Constraint) : Vect
fun groove_joint_set_anchor_b = "cpGrooveJointSetAnchorB"(constraint : Constraint, anchor_b : Vect) : Void
fun constraint_is_damped_spring = "cpConstraintIsDampedSpring"(constraint : Constraint) : Bool
alias DampedSpringForceFunc = (Constraint, Float) -> Float
fun damped_spring_alloc = "cpDampedSpringAlloc"() : DampedSpring
fun damped_spring_init = "cpDampedSpringInit"(joint : DampedSpring, a : Body, b : Body, anchor_a : Vect, anchor_b : Vect, rest_length : Float, stiffness : Float, damping : Float) : DampedSpring
fun damped_spring_new = "cpDampedSpringNew"(a : Body, b : Body, anchor_a : Vect, anchor_b : Vect, rest_length : Float, stiffness : Float, damping : Float) : Constraint
fun damped_spring_get_anchor_a = "cpDampedSpringGetAnchorA"(constraint : Constraint) : Vect
fun damped_spring_set_anchor_a = "cpDampedSpringSetAnchorA"(constraint : Constraint, anchor_a : Vect) : Void
fun damped_spring_get_anchor_b = "cpDampedSpringGetAnchorB"(constraint : Constraint) : Vect
fun damped_spring_set_anchor_b = "cpDampedSpringSetAnchorB"(constraint : Constraint, anchor_b : Vect) : Void
fun damped_spring_get_rest_length = "cpDampedSpringGetRestLength"(constraint : Constraint) : Float
fun damped_spring_set_rest_length = "cpDampedSpringSetRestLength"(constraint : Constraint, rest_length : Float) : Void
fun damped_spring_get_stiffness = "cpDampedSpringGetStiffness"(constraint : Constraint) : Float
fun damped_spring_set_stiffness = "cpDampedSpringSetStiffness"(constraint : Constraint, stiffness : Float) : Void
fun damped_spring_get_damping = "cpDampedSpringGetDamping"(constraint : Constraint) : Float
fun damped_spring_set_damping = "cpDampedSpringSetDamping"(constraint : Constraint, damping : Float) : Void
fun damped_spring_get_spring_force_func = "cpDampedSpringGetSpringForceFunc"(constraint : Constraint) : DampedSpringForceFunc
fun damped_spring_set_spring_force_func = "cpDampedSpringSetSpringForceFunc"(constraint : Constraint, spring_force_func : DampedSpringForceFunc) : Void
fun constraint_is_damped_rotary_spring = "cpConstraintIsDampedRotarySpring"(constraint : Constraint) : Bool
alias DampedRotarySpringTorqueFunc = (Constraint, Float) -> Float
fun damped_rotary_spring_alloc = "cpDampedRotarySpringAlloc"() : DampedRotarySpring
fun damped_rotary_spring_init = "cpDampedRotarySpringInit"(joint : DampedRotarySpring, a : Body, b : Body, rest_angle : Float, stiffness : Float, damping : Float) : DampedRotarySpring
fun damped_rotary_spring_new = "cpDampedRotarySpringNew"(a : Body, b : Body, rest_angle : Float, stiffness : Float, damping : Float) : Constraint
fun damped_rotary_spring_get_rest_angle = "cpDampedRotarySpringGetRestAngle"(constraint : Constraint) : Float
fun damped_rotary_spring_set_rest_angle = "cpDampedRotarySpringSetRestAngle"(constraint : Constraint, rest_angle : Float) : Void
fun damped_rotary_spring_get_stiffness = "cpDampedRotarySpringGetStiffness"(constraint : Constraint) : Float
fun damped_rotary_spring_set_stiffness = "cpDampedRotarySpringSetStiffness"(constraint : Constraint, stiffness : Float) : Void
fun damped_rotary_spring_get_damping = "cpDampedRotarySpringGetDamping"(constraint : Constraint) : Float
fun damped_rotary_spring_set_damping = "cpDampedRotarySpringSetDamping"(constraint : Constraint, damping : Float) : Void
fun damped_rotary_spring_get_spring_torque_func = "cpDampedRotarySpringGetSpringTorqueFunc"(constraint : Constraint) : DampedRotarySpringTorqueFunc
fun damped_rotary_spring_set_spring_torque_func = "cpDampedRotarySpringSetSpringTorqueFunc"(constraint : Constraint, spring_torque_func : DampedRotarySpringTorqueFunc) : Void
fun constraint_is_rotary_limit_joint = "cpConstraintIsRotaryLimitJoint"(constraint : Constraint) : Bool
fun rotary_limit_joint_alloc = "cpRotaryLimitJointAlloc"() : RotaryLimitJoint
fun rotary_limit_joint_init = "cpRotaryLimitJointInit"(joint : RotaryLimitJoint, a : Body, b : Body, min : Float, max : Float) : RotaryLimitJoint
fun rotary_limit_joint_new = "cpRotaryLimitJointNew"(a : Body, b : Body, min : Float, max : Float) : Constraint
fun rotary_limit_joint_get_min = "cpRotaryLimitJointGetMin"(constraint : Constraint) : Float
fun rotary_limit_joint_set_min = "cpRotaryLimitJointSetMin"(constraint : Constraint, min : Float) : Void
fun rotary_limit_joint_get_max = "cpRotaryLimitJointGetMax"(constraint : Constraint) : Float
fun rotary_limit_joint_set_max = "cpRotaryLimitJointSetMax"(constraint : Constraint, max : Float) : Void
fun constraint_is_ratchet_joint = "cpConstraintIsRatchetJoint"(constraint : Constraint) : Bool
fun ratchet_joint_alloc = "cpRatchetJointAlloc"() : RatchetJoint
fun ratchet_joint_init = "cpRatchetJointInit"(joint : RatchetJoint, a : Body, b : Body, phase : Float, ratchet : Float) : RatchetJoint
fun ratchet_joint_new = "cpRatchetJointNew"(a : Body, b : Body, phase : Float, ratchet : Float) : Constraint
fun ratchet_joint_get_angle = "cpRatchetJointGetAngle"(constraint : Constraint) : Float
fun ratchet_joint_set_angle = "cpRatchetJointSetAngle"(constraint : Constraint, angle : Float) : Void
fun ratchet_joint_get_phase = "cpRatchetJointGetPhase"(constraint : Constraint) : Float
fun ratchet_joint_set_phase = "cpRatchetJointSetPhase"(constraint : Constraint, phase : Float) : Void
fun ratchet_joint_get_ratchet = "cpRatchetJointGetRatchet"(constraint : Constraint) : Float
fun ratchet_joint_set_ratchet = "cpRatchetJointSetRatchet"(constraint : Constraint, ratchet : Float) : Void
fun constraint_is_gear_joint = "cpConstraintIsGearJoint"(constraint : Constraint) : Bool
fun gear_joint_alloc = "cpGearJointAlloc"() : GearJoint
fun gear_joint_init = "cpGearJointInit"(joint : GearJoint, a : Body, b : Body, phase : Float, ratio : Float) : GearJoint
fun gear_joint_new = "cpGearJointNew"(a : Body, b : Body, phase : Float, ratio : Float) : Constraint
fun gear_joint_get_phase = "cpGearJointGetPhase"(constraint : Constraint) : Float
fun gear_joint_set_phase = "cpGearJointSetPhase"(constraint : Constraint, phase : Float) : Void
fun gear_joint_get_ratio = "cpGearJointGetRatio"(constraint : Constraint) : Float
fun gear_joint_set_ratio = "cpGearJointSetRatio"(constraint : Constraint, ratio : Float) : Void
type SimpleMotor = Void*
fun constraint_is_simple_motor = "cpConstraintIsSimpleMotor"(constraint : Constraint) : Bool
fun simple_motor_alloc = "cpSimpleMotorAlloc"() : SimpleMotor
fun simple_motor_init = "cpSimpleMotorInit"(joint : SimpleMotor, a : Body, b : Body, rate : Float) : SimpleMotor
fun simple_motor_new = "cpSimpleMotorNew"(a : Body, b : Body, rate : Float) : Constraint
fun simple_motor_get_rate = "cpSimpleMotorGetRate"(constraint : Constraint) : Float
fun simple_motor_set_rate = "cpSimpleMotorSetRate"(constraint : Constraint, rate : Float) : Void
alias CollisionBeginFunc = (Arbiter, Space, DataPointer) -> Bool
alias CollisionPreSolveFunc = (Arbiter, Space, DataPointer) -> Bool
alias CollisionPostSolveFunc = (Arbiter, Space, DataPointer) -> Void
alias CollisionSeparateFunc = (Arbiter, Space, DataPointer) -> Void
struct CollisionHandler
type_a : CollisionType
type_b : CollisionType
begin_func : CollisionBeginFunc
pre_solve_func : CollisionPreSolveFunc
post_solve_func : CollisionPostSolveFunc
separate_func : CollisionSeparateFunc
user_data : DataPointer
end
fun space_alloc = "cpSpaceAlloc"() : Space
fun space_init = "cpSpaceInit"(space : Space) : Space
fun space_new = "cpSpaceNew"() : Space
fun space_destroy = "cpSpaceDestroy"(space : Space) : Void
fun space_free = "cpSpaceFree"(space : Space) : Void
fun space_get_iterations = "cpSpaceGetIterations"(space : Space) : Int32
fun space_set_iterations = "cpSpaceSetIterations"(space : Space, iterations : Int32) : Void
fun space_get_gravity = "cpSpaceGetGravity"(space : Space) : Vect
fun space_set_gravity = "cpSpaceSetGravity"(space : Space, gravity : Vect) : Void
fun space_get_damping = "cpSpaceGetDamping"(space : Space) : Float
fun space_set_damping = "cpSpaceSetDamping"(space : Space, damping : Float) : Void
fun space_get_idle_speed_threshold = "cpSpaceGetIdleSpeedThreshold"(space : Space) : Float
fun space_set_idle_speed_threshold = "cpSpaceSetIdleSpeedThreshold"(space : Space, idle_speed_threshold : Float) : Void
fun space_get_sleep_time_threshold = "cpSpaceGetSleepTimeThreshold"(space : Space) : Float
fun space_set_sleep_time_threshold = "cpSpaceSetSleepTimeThreshold"(space : Space, sleep_time_threshold : Float) : Void
fun space_get_collision_slop = "cpSpaceGetCollisionSlop"(space : Space) : Float
fun space_set_collision_slop = "cpSpaceSetCollisionSlop"(space : Space, collision_slop : Float) : Void
fun space_get_collision_bias = "cpSpaceGetCollisionBias"(space : Space) : Float
fun space_set_collision_bias = "cpSpaceSetCollisionBias"(space : Space, collision_bias : Float) : Void
fun space_get_collision_persistence = "cpSpaceGetCollisionPersistence"(space : Space) : Timestamp
fun space_set_collision_persistence = "cpSpaceSetCollisionPersistence"(space : Space, collision_persistence : Timestamp) : Void
fun space_get_user_data = "cpSpaceGetUserData"(space : Space) : DataPointer
fun space_set_user_data = "cpSpaceSetUserData"(space : Space, user_data : DataPointer) : Void
fun space_get_static_body = "cpSpaceGetStaticBody"(space : Space) : Body
fun space_get_current_time_step = "cpSpaceGetCurrentTimeStep"(space : Space) : Float
fun space_is_locked = "cpSpaceIsLocked"(space : Space) : Bool
fun space_add_default_collision_handler = "cpSpaceAddDefaultCollisionHandler"(space : Space) : CollisionHandler
fun space_add_collision_handler = "cpSpaceAddCollisionHandler"(space : Space, a : CollisionType, b : CollisionType) : CollisionHandler
fun space_add_wildcard_handler = "cpSpaceAddWildcardHandler"(space : Space, type : CollisionType) : CollisionHandler
fun space_add_shape = "cpSpaceAddShape"(space : Space, shape : Shape) : Shape
fun space_add_body = "cpSpaceAddBody"(space : Space, body : Body) : Body
fun space_add_constraint = "cpSpaceAddConstraint"(space : Space, constraint : Constraint) : Constraint
fun space_remove_shape = "cpSpaceRemoveShape"(space : Space, shape : Shape) : Void
fun space_remove_body = "cpSpaceRemoveBody"(space : Space, body : Body) : Void
fun space_remove_constraint = "cpSpaceRemoveConstraint"(space : Space, constraint : Constraint) : Void
fun space_contains_shape = "cpSpaceContainsShape"(space : Space, shape : Shape) : Bool
fun space_contains_body = "cpSpaceContainsBody"(space : Space, body : Body) : Bool
fun space_contains_constraint = "cpSpaceContainsConstraint"(space : Space, constraint : Constraint) : Bool
alias PostStepFunc = (Space, Void*, Void*) -> Void
fun space_add_post_step_callback = "cpSpaceAddPostStepCallback"(space : Space, func : PostStepFunc, key : Void*, data : Void*) : Bool
alias SpacePointQueryFunc = (Shape, Vect, Float, Vect, Void*) -> Void
fun space_point_query = "cpSpacePointQuery"(space : Space, point : Vect, max_distance : Float, filter : ShapeFilter, func : SpacePointQueryFunc, data : Void*) : Void
fun space_point_query_nearest = "cpSpacePointQueryNearest"(space : Space, point : Vect, max_distance : Float, filter : ShapeFilter, out : PointQueryInfo*) : Shape
alias SpaceSegmentQueryFunc = (Shape, Vect, Vect, Float, Void*) -> Void
fun space_segment_query = "cpSpaceSegmentQuery"(space : Space, start : Vect, end_ : Vect, radius : Float, filter : ShapeFilter, func : SpaceSegmentQueryFunc, data : Void*) : Void
fun space_segment_query_first = "cpSpaceSegmentQueryFirst"(space : Space, start : Vect, end_ : Vect, radius : Float, filter : ShapeFilter, out : SegmentQueryInfo*) : Shape
alias SpaceBBQueryFunc = (Shape, Void*) -> Void
fun space_bb_query = "cpSpaceBBQuery"(space : Space, bb : BB, filter : ShapeFilter, func : SpaceBBQueryFunc, data : Void*) : Void
alias SpaceShapeQueryFunc = (Shape, ContactPointSet, Void*) -> Void
fun space_shape_query = "cpSpaceShapeQuery"(space : Space, shape : Shape, func : SpaceShapeQueryFunc, data : Void*) : Bool
alias SpaceBodyIteratorFunc = (Body, Void*) -> Void
fun space_each_body = "cpSpaceEachBody"(space : Space, func : SpaceBodyIteratorFunc, data : Void*) : Void
alias SpaceShapeIteratorFunc = (Shape, Void*) -> Void
fun space_each_shape = "cpSpaceEachShape"(space : Space, func : SpaceShapeIteratorFunc, data : Void*) : Void
alias SpaceConstraintIteratorFunc = (Constraint, Void*) -> Void
fun space_each_constraint = "cpSpaceEachConstraint"(space : Space, func : SpaceConstraintIteratorFunc, data : Void*) : Void
fun space_reindex_static = "cpSpaceReindexStatic"(space : Space) : Void
fun space_reindex_shape = "cpSpaceReindexShape"(space : Space, shape : Shape) : Void
fun space_reindex_shapes_for_body = "cpSpaceReindexShapesForBody"(space : Space, body : Body) : Void
fun space_use_spatial_hash = "cpSpaceUseSpatialHash"(space : Space, dim : Float, count : Int32) : Void
fun space_step = "cpSpaceStep"(space : Space, dt : Float) : Void
struct SpaceDebugColor
r : Float32
g : Float32
b : Float32
a : Float32
end
alias SpaceDebugDrawCircleImpl = (Vect, Float, Float, SpaceDebugColor, SpaceDebugColor, DataPointer) -> Void
alias SpaceDebugDrawSegmentImpl = (Vect, Vect, SpaceDebugColor, DataPointer) -> Void
alias SpaceDebugDrawFatSegmentImpl = (Vect, Vect, Float, SpaceDebugColor, SpaceDebugColor, DataPointer) -> Void
alias SpaceDebugDrawPolygonImpl = (Int32, Vect*, Float, SpaceDebugColor, SpaceDebugColor, DataPointer) -> Void
alias SpaceDebugDrawDotImpl = (Float, Vect, SpaceDebugColor, DataPointer) -> Void
alias SpaceDebugDrawColorForShapeImpl = (Shape, DataPointer) -> SpaceDebugColor
enum SpaceDebugDrawFlags
SPACE_DEBUG_DRAW_SHAPES = 1 << 0
SPACE_DEBUG_DRAW_CONSTRAINTS = 1 << 1
SPACE_DEBUG_DRAW_COLLISION_POINTS = 1 << 2
end
struct SpaceDebugDrawOptions
draw_circle : SpaceDebugDrawCircleImpl
draw_segment : SpaceDebugDrawSegmentImpl
draw_fat_segment : SpaceDebugDrawFatSegmentImpl
draw_polygon : SpaceDebugDrawPolygonImpl
draw_dot : SpaceDebugDrawDotImpl
flags : SpaceDebugDrawFlags
shape_outline_color : SpaceDebugColor
color_for_shape : SpaceDebugDrawColorForShapeImpl
constraint_color : SpaceDebugColor
collision_point_color : SpaceDebugColor
data : DataPointer
end
fun space_debug_draw = "cpSpaceDebugDraw"(space : Space, options : SpaceDebugDrawOptions*) : Void
VERSION_MAJOR = 7
VERSION_MINOR = 0
VERSION_RELEASE = 0
fun moment_for_circle = "cpMomentForCircle"(m : Float, r1 : Float, r2 : Float, offset : Vect) : Float
fun area_for_circle = "cpAreaForCircle"(r1 : Float, r2 : Float) : Float
fun moment_for_segment = "cpMomentForSegment"(m : Float, a : Vect, b : Vect, radius : Float) : Float
fun area_for_segment = "cpAreaForSegment"(a : Vect, b : Vect, radius : Float) : Float
fun moment_for_poly = "cpMomentForPoly"(m : Float, count : Int32, verts : Vect*, offset : Vect, radius : Float) : Float
fun area_for_poly = "cpAreaForPoly"(count : Int32, verts : Vect*, radius : Float) : Float
fun centroid_for_poly = "cpCentroidForPoly"(count : Int32, verts : Vect*) : Vect
fun moment_for_box = "cpMomentForBox"(m : Float, width : Float, height : Float) : Float
fun moment_for_box2 = "cpMomentForBox2"(m : Float, box : BB) : Float
fun convex_hull = "cpConvexHull"(count : Int32, verts : Vect*, result : Vect*, first : Int32*, tol : Float) : Int32
end
def fmax(a : CP::Float, b : CP::Float) : Float
# return a > b ? a : b;
end
def fmin(a : CP::Float, b : CP::Float) : Float
# return a < b ? a : b;
end
def fabs(f : CP::Float) : Float
# return f < 0 ? -f : f;
end
def fclamp(f : CP::Float, min : CP::Float, max : CP::Float) : Float
# return cpfmin(cpfmax(f, min), max);
end
def fclamp01(f : CP::Float) : Float
# return cpfmax(0.0f, cpfmin(f, 1.0f));
end
def flerp(f1 : CP::Float, f2 : CP::Float, t : CP::Float) : Float
# return (f1 * (1.0f - t)) + (f2 * t);
end
def flerpconst(f1 : CP::Float, f2 : CP::Float, d : CP::Float) : Float
# return f1 + cpfclamp(f2 - f1, -d, d);
end
def v(x : CP::Float, y : CP::Float) : Vect
# cpVect v = {x, y};
# return v;
end
def veql(v1 : CP::Vect, v2 : CP::Vect) : Bool
# return (v1.x == v2.x) && (v1.y == v2.y);
end
def vadd(v1 : CP::Vect, v2 : CP::Vect) : Vect
# return cpv(v1.x + v2.x, v1.y + v2.y);
end
def vsub(v1 : CP::Vect, v2 : CP::Vect) : Vect
# return cpv(v1.x - v2.x, v1.y - v2.y);
end
def vneg(v : CP::Vect) : Vect
# return cpv(-v.x, -v.y);
end
def vmult(v : CP::Vect, s : CP::Float) : Vect
# return cpv(v.x * s, v.y * s);
end
def vdot(v1 : CP::Vect, v2 : CP::Vect) : Float
# return (v1.x * v2.x) + (v1.y * v2.y);
end
def vcross(v1 : CP::Vect, v2 : CP::Vect) : Float
# return (v1.x * v2.y) - (v1.y * v2.x);
end
def vperp(v : CP::Vect) : Vect
# return cpv(-v.y, v.x);
end
def vrperp(v : CP::Vect) : Vect
# return cpv(v.y, -v.x);
end
def vproject(v1 : CP::Vect, v2 : CP::Vect) : Vect
# return cpvmult(v2, cpvdot(v1, v2) / cpvdot(v2, v2));
end
def vforangle(a : CP::Float) : Vect
# return cpv(cos(a), sin(a));
end
def vtoangle(v : CP::Vect) : Float
# return atan2(v.y, v.x);
end
def vrotate(v1 : CP::Vect, v2 : CP::Vect) : Vect
# return cpv((v1.x * v2.x) - (v1.y * v2.y), (v1.x * v2.y) + (v1.y * v2.x));
end
def vunrotate(v1 : CP::Vect, v2 : CP::Vect) : Vect
# return cpv((v1.x * v2.x) + (v1.y * v2.y), (v1.y * v2.x) - (v1.x * v2.y));
end
def vlengthsq(v : CP::Vect) : Float
# return cpvdot(v, v);
end
def vlength(v : CP::Vect) : Float
# return sqrt(cpvdot(v, v));
end
def vlerp(v1 : CP::Vect, v2 : CP::Vect, t : CP::Float) : Vect
# return cpvadd(cpvmult(v1, 1.0f - t), cpvmult(v2, t));
end
def vnormalize(v : CP::Vect) : Vect
# return cpvmult(v, 1.0f / (cpvlength(v) + DBL_MIN));
end
def vslerp(v1 : CP::Vect, v2 : CP::Vect, t : CP::Float) : Vect
# cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2));
# cpFloat omega = acos(cpfclamp(dot, -1.0f, 1.0f));
# if (omega < 1e-3)
# {
# return cpvlerp(v1, v2, t);
# }
# else
# {
# cpFloat denom = 1.0f / sin(omega);
# return cpvadd(cpvmult(v1, sin((1.0f - t) * omega) * denom), cpvmult(v2, sin(t * omega) * denom));
# }
end
def vslerpconst(v1 : CP::Vect, v2 : CP::Vect, a : CP::Float) : Vect
# cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2));
# cpFloat omega = acos(cpfclamp(dot, -1.0f, 1.0f));
# return cpvslerp(v1, v2, cpfmin(a, omega) / omega);
end
def vclamp(v : CP::Vect, len : CP::Float) : Vect
# return cpvdot(v, v) > (len * len) ? cpvmult(cpvnormalize(v), len) : v;
end
def vlerpconst(v1 : CP::Vect, v2 : CP::Vect, d : CP::Float) : Vect
# return cpvadd(v1, cpvclamp(cpvsub(v2, v1), d));
end
def vdist(v1 : CP::Vect, v2 : CP::Vect) : Float
# return cpvlength(cpvsub(v1, v2));
end
def vdistsq(v1 : CP::Vect, v2 : CP::Vect) : Float
# return cpvlengthsq(cpvsub(v1, v2));
end
def vnear(v1 : CP::Vect, v2 : CP::Vect, dist : CP::Float) : Bool
# return cpvdistsq(v1, v2) < (dist * dist);
end
def mat2x2_new(a : CP::Float, b : CP::Float, c : CP::Float, d : CP::Float) : Mat2x2
# cpMat2x2 m = {a, b, c, d};
# return m;
end
def mat2x2_transform(m : CP::Mat2x2, v : CP::Vect) : Vect
# return cpv((v.x * m.a) + (v.y * m.b), (v.x * m.c) + (v.y * m.d));
end
def bb_new(l : CP::Float, b : CP::Float, r : CP::Float, t : CP::Float) : BB
# cpBB bb = {l, b, r, t};
# return bb;
end
def bb_new_for_extents(c : CP::Vect, hw : CP::Float, hh : CP::Float) : BB
# return cpBBNew(c.x - hw, c.y - hh, c.x + hw, c.y + hh);
end
def bb_new_for_circle(p : CP::Vect, r : CP::Float) : BB
# return cpBBNewForExtents(p, r, r);
end
def bb_intersects(a : CP::BB, b : CP::BB) : Bool
# return (((a.l <= b.r) && (b.l <= a.r)) && (a.b <= b.t)) && (b.b <= a.t);
end
def bb_contains_bb(bb : CP::BB, other : CP::BB) : Bool
# return (((bb.l <= other.l) && (bb.r >= other.r)) && (bb.b <= other.b)) && (bb.t >= other.t);
end
def bb_contains_vect(bb : CP::BB, v : CP::Vect) : Bool
# return (((bb.l <= v.x) && (bb.r >= v.x)) && (bb.b <= v.y)) && (bb.t >= v.y);
end
def bb_merge(a : CP::BB, b : CP::BB) : BB
# return cpBBNew(cpfmin(a.l, b.l), cpfmin(a.b, b.b), cpfmax(a.r, b.r), cpfmax(a.t, b.t));
end
def bb_expand(bb : CP::BB, v : CP::Vect) : BB
# return cpBBNew(cpfmin(bb.l, v.x), cpfmin(bb.b, v.y), cpfmax(bb.r, v.x), cpfmax(bb.t, v.y));
end
def bb_center(bb : CP::BB) : Vect
# return cpvlerp(cpv(bb.l, bb.b), cpv(bb.r, bb.t), 0.5f);
end
def bb_area(bb : CP::BB) : Float
# return (bb.r - bb.l) * (bb.t - bb.b);
end
def bb_merged_area(a : CP::BB, b : CP::BB) : Float
# return (cpfmax(a.r, b.r) - cpfmin(a.l, b.l)) * (cpfmax(a.t, b.t) - cpfmin(a.b, b.b));
end
def bb_segment_query(bb : CP::BB, a : CP::Vect, b : CP::Vect) : Float
# cpFloat idx = 1.0f / (b.x - a.x);
# cpFloat tx1 = bb.l == a.x ? -1e1000 : (bb.l - a.x) * idx;
# cpFloat tx2 = bb.r == a.x ? 1e1000 : (bb.r - a.x) * idx;
# cpFloat txmin = cpfmin(tx1, tx2);
# cpFloat txmax = cpfmax(tx1, tx2);
# cpFloat idy = 1.0f / (b.y - a.y);
# cpFloat ty1 = bb.b == a.y ? -1e1000 : (bb.b - a.y) * idy;
# cpFloat ty2 = bb.t == a.y ? 1e1000 : (bb.t - a.y) * idy;
# cpFloat tymin = cpfmin(ty1, ty2);
# cpFloat tymax = cpfmax(ty1, ty2);
# if ((tymin <= txmax) && (txmin <= tymax))
# {
# cpFloat min = cpfmax(txmin, tymin);
# cpFloat max = cpfmin(txmax, tymax);
# if ((0.0 <= max) && (min <= 1.0))
# return cpfmax(min, 0.0);
# }
# return 1e1000;
end
def bb_intersects_segment(bb : CP::BB, a : CP::Vect, b : CP::Vect) : Bool
# return cpBBSegmentQuery(bb, a, b) != 1e1000;
end
def bb_clamp_vect(bb : CP::BB, v : CP::Vect) : Vect
# return cpv(cpfclamp(v.x, bb.l, bb.r), cpfclamp(v.y, bb.b, bb.t));
end
def bb_wrap_vect(bb : CP::BB, v : CP::Vect) : Vect
# cpFloat dx = cpfabs(bb.r - bb.l);
# cpFloat modx = fmod(v.x - bb.l, dx);
# cpFloat x = modx > 0.0f ? modx : modx + dx;
# cpFloat dy = cpfabs(bb.t - bb.b);
# cpFloat mody = fmod(v.y - bb.b, dy);
# cpFloat y = mody > 0.0f ? mody : mody + dy;
# return cpv(x + bb.l, y + bb.b);
end
def bb_offset(bb : CP::BB, v : CP::Vect) : BB
# return cpBBNew(bb.l + v.x, bb.b + v.y, bb.r + v.x, bb.t + v.y);
end
def transform_new(a : CP::Float, b : CP::Float, c : CP::Float, d : CP::Float, tx : CP::Float, ty : CP::Float) : Transform
# cpTransform t = {a, b, c, d, tx, ty};
# return t;
end
def transform_new_transpose(a : CP::Float, c : CP::Float, tx : CP::Float, b : CP::Float, d : CP::Float, ty : CP::Float) : Transform
# cpTransform t = {a, b, c, d, tx, ty};
# return t;
end
def transform_inverse(t : CP::Transform) : Transform
# cpFloat inv_det = 1.0 / ((t.a * t.d) - (t.c * t.b));
# return cpTransformNewTranspose(t.d * inv_det, (-t.c) * inv_det, ((t.c * t.ty) - (t.tx * t.d)) * inv_det, (-t.b) * inv_det, t.a * inv_det, ((t.tx * t.b) - (t.a * t.ty)) * inv_det);
end
def transform_mult(t1 : CP::Transform, t2 : CP::Transform) : Transform
# return cpTransformNewTranspose((t1.a * t2.a) + (t1.c * t2.b), (t1.a * t2.c) + (t1.c * t2.d), ((t1.a * t2.tx) + (t1.c * t2.ty)) + t1.tx, (t1.b * t2.a) + (t1.d * t2.b), (t1.b * t2.c) + (t1.d * t2.d), ((t1.b * t2.tx) + (t1.d * t2.ty)) + t1.ty);
end
def transform_point(t : CP::Transform, p : CP::Vect) : Vect
# return cpv(((t.a * p.x) + (t.c * p.y)) + t.tx, ((t.b * p.x) + (t.d * p.y)) + t.ty);
end
def transform_vect(t : CP::Transform, v : CP::Vect) : Vect
# return cpv((t.a * v.x) + (t.c * v.y), (t.b * v.x) + (t.d * v.y));
end
def transformb_bb(t : CP::Transform, bb : CP::BB) : BB
# cpVect center = cpBBCenter(bb);
# cpFloat hw = (bb.r - bb.l) * 0.5;
# cpFloat hh = (bb.t - bb.b) * 0.5;
# cpFloat a = t.a * hw;
# cpFloat b = t.c * hh;
# cpFloat d = t.b * hw;
# cpFloat e = t.d * hh;
# cpFloat hw_max = cpfmax(cpfabs(a + b), cpfabs(a - b));
# cpFloat hh_max = cpfmax(cpfabs(d + e), cpfabs(d - e));
# return cpBBNewForExtents(cpTransformPoint(t, center), hw_max, hh_max);
end
def transform_translate(translate : CP::Vect) : Transform
# return cpTransformNewTranspose(1.0, 0.0, translate.x, 0.0, 1.0, translate.y);
end
def transform_scale(scale_x : CP::Float, scale_y : CP::Float) : Transform
# return cpTransformNewTranspose(scaleX, 0.0, 0.0, 0.0, scaleY, 0.0);
end
def transform_rotate(radians : CP::Float) : Transform
# cpVect rot = cpvforangle(radians);
# return cpTransformNewTranspose(rot.x, -rot.y, 0.0, rot.y, rot.x, 0.0);
end
def transform_rigid(translate : CP::Vect, radians : CP::Float) : Transform
# cpVect rot = cpvforangle(radians);
# return cpTransformNewTranspose(rot.x, -rot.y, translate.x, rot.y, rot.x, translate.y);
end
def transform_rigid_inverse(t : CP::Transform) : Transform
# return cpTransformNewTranspose(t.d, -t.c, (t.c * t.ty) - (t.tx * t.d), -t.b, t.a, (t.tx * t.b) - (t.a * t.ty));
end
def transform_wrap(outer : CP::Transform, inner : CP::Transform) : Transform
# return cpTransformMult(cpTransformInverse(outer), cpTransformMult(inner, outer));
end
def transform_wrap_inverse(outer : CP::Transform, inner : CP::Transform) : Transform
# return cpTransformMult(outer, cpTransformMult(inner, cpTransformInverse(outer)));
end
def transform_ortho(bb : CP::BB) : Transform
# return cpTransformNewTranspose(2.0 / (bb.r - bb.l), 0.0, (-(bb.r + bb.l)) / (bb.r - bb.l), 0.0, 2.0 / (bb.t - bb.b), (-(bb.t + bb.b)) / (bb.t - bb.b));
end
def transform_bone_scale(v0 : CP::Vect, v1 : CP::Vect) : Transform
# cpVect d = cpvsub(v1, v0);
# return cpTransformNewTranspose(d.x, -d.y, v0.x, d.y, d.x, v0.y);
end
def transform_axial_scale(axis : CP::Vect, pivot : CP::Vect, scale : CP::Float) : Transform
# cpFloat A = (axis.x * axis.y) * (scale - 1.0);
# cpFloat B = cpvdot(axis, pivot) * (1.0 - scale);
# return cpTransformNewTranspose(((scale * axis.x) * axis.x) + (axis.y * axis.y), A, axis.x * B, A, (axis.x * axis.x) + ((scale * axis.y) * axis.y), axis.y * B);
end
def spatial_index_destroy(index : CP::SpatialIndex) : Void
# if (index->klass)
# index->klass->destroy(index);
end
def spatial_index_count(index : CP::SpatialIndex) : Int32
# return index->klass->count(index);
end
def spatial_index_each(index : CP::SpatialIndex, func : CP::SpatialIndexIteratorFunc, data : CP::Void*) : Void
# index->klass->each(index, func, data);
end
def spatial_index_contains(index : CP::SpatialIndex, obj : CP::Void*, hashid : CP::HashValue) : Bool
# return index->klass->contains(index, obj, hashid);
end
def spatial_index_insert(index : CP::SpatialIndex, obj : CP::Void*, hashid : CP::HashValue) : Void
# index->klass->insert(index, obj, hashid);
end
def spatial_index_remove(index : CP::SpatialIndex, obj : CP::Void*, hashid : CP::HashValue) : Void
# index->klass->remove(index, obj, hashid);
end
def spatial_index_reindex(index : CP::SpatialIndex) : Void
# index->klass->reindex(index);
end
def spatial_index_reindex_object(index : CP::SpatialIndex, obj : CP::Void*, hashid : CP::HashValue) : Void
# index->klass->reindexObject(index, obj, hashid);
end
def spatial_index_query(index : CP::SpatialIndex, obj : CP::Void*, bb : CP::BB, func : CP::SpatialIndexQueryFunc, data : CP::Void*) : Void
# index->klass->query(index, obj, bb, func, data);
end
def spatial_index_segment_query(index : CP::SpatialIndex, obj : CP::Void*, a : CP::Vect, b : CP::Vect, t_exit : CP::Float, func : CP::SpatialIndexSegmentQueryFunc, data : CP::Void*) : Void
# index->klass->segmentQuery(index, obj, a, b, t_exit, func, data);
end
def spatial_index_reindex_query(index : CP::SpatialIndex, func : CP::SpatialIndexQueryFunc, data : CP::Void*) : Void
# index->klass->reindexQuery(index, func, data);
end
def shape_filter_new(group : CP::Group, categories : CP::Bitmask, mask : CP::Bitmask) : ShapeFilter
# cpShapeFilter filter = {group, categories, mask};
# return filter;
end
def closet_point_on_segment(p : CP::Vect, a : CP::Vect, b : CP::Vect) : Vect
# cpVect delta = cpvsub(a, b);
# cpFloat t = cpfclamp01(cpvdot(delta, cpvsub(p, b)) / cpvlengthsq(delta));
# return cpvadd(b, cpvmult(delta, t));
end
diff --git a/crystalize.py b/crystalize.py
index 8f85408..d922ba5 100755
--- a/crystalize.py
+++ b/crystalize.py
@@ -76,7 +76,14 @@ code = []
keywords = 'alias and begin break case class def defined do else elsif end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield BEGIN END'.split()
-lib_name = 'Lib'
+lib_name = 'CP'
+
+def remove_cp(s):
+ if s.startswith('cp'):
+ s = s[2:]
+ elif s.startswith('CP_'):
+ s = s[3:]
+ return s
def rename_identifier(name):
name = re.sub('[A-Z](?![A-Z0-9_]|$)', lambda m: '_' + m.group(0).lower(), name)
@@ -87,10 +94,10 @@ def rename_identifier(name):
return name
def rename_const(name):
- return rename_identifier(name).upper()
+ return rename_identifier(remove_cp(name)).upper()
def rename_func(name):
- return rename_identifier(name)
+ return rename_identifier(remove_cp(name))
def native_type(type):
for match, repl in {
@@ -121,6 +128,7 @@ def rename_type(type, lib=None):
r = native_type(type)
if r:
return r
+ type = remove_cp(type)
type = re.sub(r'_([a-zA-Z])', lambda m: m.group(1).upper(), type)
return type[0].upper() + type[1:]
@@ -292,6 +300,8 @@ for top in ast.ext:
output.append('alias {} = {}'.format(rename_type(top.name), make_type(top.type)))
elif isinstance(top, Decl) and top.quals == ['const']:
+ if not top.name.startswith('CP_VERSION'):
+ continue
val = generate_c(top.init)
if top.init:
output.append('{} = {}'.format(rename_const(top.name), val.strip('"')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment