diff --git a/CMakeLists.txt b/CMakeLists.txt index d40f9629..05357e62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,12 +34,14 @@ if(ANDROID) option(BUILD_SHARED "Build and install the shared library" ON) option(BUILD_STATIC "Build as static library" ON) option(INSTALL_STATIC "Install the static library" OFF) + option(FUNCTION_POINTERS "Generate function pointers for backwards FFI compatibility" ON) else() option(BUILD_DEMOS "Build the demo applications" ON) option(INSTALL_DEMOS "Install the demo applications" OFF) option(BUILD_SHARED "Build and install the shared library" ON) option(BUILD_STATIC "Build as static library" ON) option(INSTALL_STATIC "Install the static library" ON) + option(FUNCTION_POINTERS "Generate function pointers for backwards FFI compatibility" ON) endif() if(CMAKE_C_COMPILER_ID STREQUAL "Clang") diff --git a/include/chipmunk/chipmunk.h b/include/chipmunk/chipmunk.h index b504932b..049d0771 100644 --- a/include/chipmunk/chipmunk.h +++ b/include/chipmunk/chipmunk.h @@ -179,7 +179,7 @@ cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \ int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \ /// Returns the closest point on the line segment ab, to the point p. -static inline cpVect +inline cpVect cpClosetPointOnSegment(const cpVect p, const cpVect a, const cpVect b) { cpVect delta = cpvsub(a, b); @@ -222,11 +222,11 @@ cpBool cpSpaceShapeQuery_b(cpSpace *space, cpShape *shape, cpSpaceShapeQueryBloc #ifdef __cplusplus } -static inline cpVect operator *(const cpVect v, const cpFloat s){return cpvmult(v, s);} -static inline cpVect operator +(const cpVect v1, const cpVect v2){return cpvadd(v1, v2);} -static inline cpVect operator -(const cpVect v1, const cpVect v2){return cpvsub(v1, v2);} -static inline cpBool operator ==(const cpVect v1, const cpVect v2){return cpveql(v1, v2);} -static inline cpVect operator -(const cpVect v){return cpvneg(v);} +inline cpVect operator *(const cpVect v, const cpFloat s){return cpvmult(v, s);} +inline cpVect operator +(const cpVect v1, const cpVect v2){return cpvadd(v1, v2);} +inline cpVect operator -(const cpVect v1, const cpVect v2){return cpvsub(v1, v2);} +inline cpBool operator ==(const cpVect v1, const cpVect v2){return cpveql(v1, v2);} +inline cpVect operator -(const cpVect v){return cpvneg(v);} #endif #endif diff --git a/include/chipmunk/chipmunk_private.h b/include/chipmunk/chipmunk_private.h index a27fdec5..819f614a 100644 --- a/include/chipmunk/chipmunk_private.h +++ b/include/chipmunk/chipmunk_private.h @@ -88,7 +88,7 @@ cpSpatialIndex *cpSpatialIndexInit(cpSpatialIndex *index, cpSpatialIndexClass *k cpArbiter* cpArbiterInit(cpArbiter *arb, cpShape *a, cpShape *b); -static inline struct cpArbiterThread * +inline struct cpArbiterThread * cpArbiterThreadForBody(cpArbiter *arb, cpBody *body) { return (arb->body_a == body ? &arb->thread_a : &arb->thread_b); @@ -106,7 +106,7 @@ void cpArbiterApplyImpulse(cpArbiter *arb); cpShape *cpShapeInit(cpShape *shape, const cpShapeClass *klass, cpBody *body, struct cpShapeMassInfo massInfo); -static inline cpBool +inline cpBool cpShapeActive(cpShape *shape) { // checks if the shape is added to a shape list. @@ -117,7 +117,7 @@ cpShapeActive(cpShape *shape) // Note: This function returns contact points with r1/r2 in absolute coordinates, not body relative. struct cpCollisionInfo cpCollide(const cpShape *a, const cpShape *b, cpCollisionID id, struct cpContact *contacts); -static inline void +inline void CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r1, cpVect a, cpVect b, cpFloat r2, cpSegmentQueryInfo *info) { cpVect da = cpvsub(a, center); @@ -141,7 +141,7 @@ CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r1, cpVect a, cpVect b } } -static inline cpBool +inline cpBool cpShapeFilterReject(cpShapeFilter a, cpShapeFilter b) { // Reject the collision if: @@ -162,14 +162,14 @@ void cpLoopIndexes(const cpVect *verts, int count, int *start, int *end); void cpConstraintInit(cpConstraint *constraint, const struct cpConstraintClass *klass, cpBody *a, cpBody *b); -static inline void +inline void cpConstraintActivateBodies(cpConstraint *constraint) { cpBody *a = constraint->a; cpBodyActivate(a); cpBody *b = constraint->b; cpBodyActivate(b); } -static inline cpVect +inline cpVect relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2){ cpVect v1_sum = cpvadd(a->v, cpvmult(cpvperp(r1), a->w)); cpVect v2_sum = cpvadd(b->v, cpvmult(cpvperp(r2), b->w)); @@ -177,46 +177,46 @@ relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2){ return cpvsub(v2_sum, v1_sum); } -static inline cpFloat +inline cpFloat normal_relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n){ return cpvdot(relative_velocity(a, b, r1, r2), n); } -static inline void +inline void apply_impulse(cpBody *body, cpVect j, cpVect r){ body->v = cpvadd(body->v, cpvmult(j, body->m_inv)); body->w += body->i_inv*cpvcross(r, j); } -static inline void +inline void apply_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j) { apply_impulse(a, cpvneg(j), r1); apply_impulse(b, j, r2); } -static inline void +inline void apply_bias_impulse(cpBody *body, cpVect j, cpVect r) { body->v_bias = cpvadd(body->v_bias, cpvmult(j, body->m_inv)); body->w_bias += body->i_inv*cpvcross(r, j); } -static inline void +inline void apply_bias_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j) { apply_bias_impulse(a, cpvneg(j), r1); apply_bias_impulse(b, j, r2); } -static inline cpFloat +inline cpFloat k_scalar_body(cpBody *body, cpVect r, cpVect n) { cpFloat rcn = cpvcross(r, n); return body->m_inv + body->i_inv*rcn*rcn; } -static inline cpFloat +inline cpFloat k_scalar(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n) { cpFloat value = k_scalar_body(a, r1, n) + k_scalar_body(b, r2, n); @@ -225,7 +225,7 @@ k_scalar(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n) return value; } -static inline cpMat2x2 +inline cpMat2x2 k_tensor(cpBody *a, cpBody *b, cpVect r1, cpVect r2) { cpFloat m_sum = a->m_inv + b->m_inv; @@ -261,7 +261,7 @@ k_tensor(cpBody *a, cpBody *b, cpVect r1, cpVect r2) ); } -static inline cpFloat +inline cpFloat bias_coef(cpFloat errorBias, cpFloat dt) { return 1.0f - cpfpow(errorBias, dt); @@ -295,7 +295,7 @@ void cpSpaceActivateBody(cpSpace *space, cpBody *body); void cpSpaceLock(cpSpace *space); void cpSpaceUnlock(cpSpace *space, cpBool runPostStep); -static inline void +inline void cpSpaceUncacheArbiter(cpSpace *space, cpArbiter *arb) { const cpShape *a = arb->a, *b = arb->b; @@ -305,7 +305,7 @@ cpSpaceUncacheArbiter(cpSpace *space, cpArbiter *arb) cpArrayDeleteObj(space->arbiters, arb); } -static inline cpArray * +inline cpArray * cpSpaceArrayForBodyType(cpSpace *space, cpBodyType type) { return (type == CP_BODY_TYPE_STATIC ? space->staticBodies : space->dynamicBodies); @@ -317,7 +317,7 @@ cpCollisionID cpSpaceCollideShapes(cpShape *a, cpShape *b, cpCollisionID id, cpS //MARK: Foreach loops -static inline cpConstraint * +inline cpConstraint * cpConstraintNext(cpConstraint *node, cpBody *body) { return (node->a == body ? node->next_a : node->next_b); @@ -326,7 +326,7 @@ cpConstraintNext(cpConstraint *node, cpBody *body) #define CP_BODY_FOREACH_CONSTRAINT(bdy, var)\ for(cpConstraint *var = bdy->constraintList; var; var = cpConstraintNext(var, bdy)) -static inline cpArbiter * +inline cpArbiter * cpArbiterNext(cpArbiter *node, cpBody *body) { return (node->body_a == body ? node->thread_a.next : node->thread_b.next); diff --git a/include/chipmunk/chipmunk_types.h b/include/chipmunk/chipmunk_types.h index 9544da89..a6490375 100644 --- a/include/chipmunk/chipmunk_types.h +++ b/include/chipmunk/chipmunk_types.h @@ -98,7 +98,7 @@ unsigned __int8 Bytes[4]; float Value; }; - static union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}}; + union MSVC_EVIL_FLOAT_HACK INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}}; #define INFINITY (INFINITY_HACK.Value) #endif @@ -116,31 +116,31 @@ /// Return the max of two cpFloats. -static inline cpFloat cpfmax(cpFloat a, cpFloat b) +inline cpFloat cpfmax(cpFloat a, cpFloat b) { return (a > b) ? a : b; } /// Return the min of two cpFloats. -static inline cpFloat cpfmin(cpFloat a, cpFloat b) +inline cpFloat cpfmin(cpFloat a, cpFloat b) { return (a < b) ? a : b; } /// Return the absolute value of a cpFloat. -static inline cpFloat cpfabs(cpFloat f) +inline cpFloat cpfabs(cpFloat f) { return (f < 0) ? -f : f; } /// Clamp @c f to be between @c min and @c max. -static inline cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max) +inline cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max) { return cpfmin(cpfmax(f, min), max); } /// Clamp @c f to be between 0 and 1. -static inline cpFloat cpfclamp01(cpFloat f) +inline cpFloat cpfclamp01(cpFloat f) { return cpfmax(0.0f, cpfmin(f, 1.0f)); } @@ -148,13 +148,13 @@ static inline cpFloat cpfclamp01(cpFloat f) /// Linearly interpolate (or extrapolate) between @c f1 and @c f2 by @c t percent. -static inline cpFloat cpflerp(cpFloat f1, cpFloat f2, cpFloat t) +inline cpFloat cpflerp(cpFloat f1, cpFloat f2, cpFloat t) { return f1*(1.0f - t) + f2*t; } /// Linearly interpolate from @c f1 to @c f2 by no more than @c d. -static inline cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d) +inline cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d) { return f1 + cpfclamp(f2 - f1, -d, d); } diff --git a/include/chipmunk/cpBB.h b/include/chipmunk/cpBB.h index 8fc87049..54326fa0 100644 --- a/include/chipmunk/cpBB.h +++ b/include/chipmunk/cpBB.h @@ -35,45 +35,45 @@ typedef struct cpBB{ } cpBB; /// Convenience constructor for cpBB structs. -static inline cpBB cpBBNew(const cpFloat l, const cpFloat b, const cpFloat r, const cpFloat t) +inline cpBB cpBBNew(const cpFloat l, const cpFloat b, const cpFloat r, const cpFloat t) { cpBB bb = {l, b, r, t}; return bb; } /// Constructs a cpBB centered on a point with the given extents (half sizes). -static inline cpBB +inline cpBB cpBBNewForExtents(const cpVect c, const cpFloat hw, const cpFloat hh) { return cpBBNew(c.x - hw, c.y - hh, c.x + hw, c.y + hh); } /// Constructs a cpBB for a circle with the given position and radius. -static inline cpBB cpBBNewForCircle(const cpVect p, const cpFloat r) +inline cpBB cpBBNewForCircle(const cpVect p, const cpFloat r) { return cpBBNewForExtents(p, r, r); } /// Returns true if @c a and @c b intersect. -static inline cpBool cpBBIntersects(const cpBB a, const cpBB b) +inline cpBool cpBBIntersects(const cpBB a, const cpBB b) { return (a.l <= b.r && b.l <= a.r && a.b <= b.t && b.b <= a.t); } /// Returns true if @c other lies completely within @c bb. -static inline cpBool cpBBContainsBB(const cpBB bb, const cpBB other) +inline cpBool cpBBContainsBB(const cpBB bb, const cpBB other) { return (bb.l <= other.l && bb.r >= other.r && bb.b <= other.b && bb.t >= other.t); } /// Returns true if @c bb contains @c v. -static inline cpBool cpBBContainsVect(const cpBB bb, const cpVect v) +inline cpBool cpBBContainsVect(const cpBB bb, const cpVect v) { return (bb.l <= v.x && bb.r >= v.x && bb.b <= v.y && bb.t >= v.y); } /// Returns a bounding box that holds both bounding boxes. -static inline cpBB cpBBMerge(const cpBB a, const cpBB b){ +inline cpBB cpBBMerge(const cpBB a, const cpBB b){ return cpBBNew( cpfmin(a.l, b.l), cpfmin(a.b, b.b), @@ -83,7 +83,7 @@ static inline cpBB cpBBMerge(const cpBB a, const cpBB b){ } /// Returns a bounding box that holds both @c bb and @c v. -static inline cpBB cpBBExpand(const cpBB bb, const cpVect v){ +inline cpBB cpBBExpand(const cpBB bb, const cpVect v){ return cpBBNew( cpfmin(bb.l, v.x), cpfmin(bb.b, v.y), @@ -93,26 +93,26 @@ static inline cpBB cpBBExpand(const cpBB bb, const cpVect v){ } /// Returns the center of a bounding box. -static inline cpVect +inline cpVect cpBBCenter(cpBB bb) { return cpvlerp(cpv(bb.l, bb.b), cpv(bb.r, bb.t), 0.5f); } /// Returns the area of the bounding box. -static inline cpFloat cpBBArea(cpBB bb) +inline cpFloat cpBBArea(cpBB bb) { return (bb.r - bb.l)*(bb.t - bb.b); } /// Merges @c a and @c b and returns the area of the merged bounding box. -static inline cpFloat cpBBMergedArea(cpBB a, cpBB b) +inline cpFloat cpBBMergedArea(cpBB a, cpBB b) { return (cpfmax(a.r, b.r) - cpfmin(a.l, b.l))*(cpfmax(a.t, b.t) - cpfmin(a.b, b.b)); } /// Returns the fraction along the segment query the cpBB is hit. Returns INFINITY if it doesn't hit. -static inline cpFloat cpBBSegmentQuery(cpBB bb, cpVect a, cpVect b) +inline cpFloat cpBBSegmentQuery(cpBB bb, cpVect a, cpVect b) { cpVect delta = cpvsub(b, a); cpFloat tmin = -INFINITY, tmax = INFINITY; @@ -143,20 +143,20 @@ static inline cpFloat cpBBSegmentQuery(cpBB bb, cpVect a, cpVect b) } /// Return true if the bounding box intersects the line segment with ends @c a and @c b. -static inline cpBool cpBBIntersectsSegment(cpBB bb, cpVect a, cpVect b) +inline cpBool cpBBIntersectsSegment(cpBB bb, cpVect a, cpVect b) { return (cpBBSegmentQuery(bb, a, b) != INFINITY); } /// Clamp a vector to a bounding box. -static inline cpVect +inline cpVect cpBBClampVect(const cpBB bb, const cpVect v) { return cpv(cpfclamp(v.x, bb.l, bb.r), cpfclamp(v.y, bb.b, bb.t)); } /// Wrap a vector to a bounding box. -static inline cpVect +inline cpVect cpBBWrapVect(const cpBB bb, const cpVect v) { cpFloat dx = cpfabs(bb.r - bb.l); @@ -171,7 +171,7 @@ cpBBWrapVect(const cpBB bb, const cpVect v) } /// Returns a bounding box offseted by @c v. -static inline cpBB +inline cpBB cpBBOffset(const cpBB bb, const cpVect v) { return cpBBNew( diff --git a/include/chipmunk/cpBody.h b/include/chipmunk/cpBody.h index 7e6943d1..4cf50a89 100644 --- a/include/chipmunk/cpBody.h +++ b/include/chipmunk/cpBody.h @@ -32,11 +32,11 @@ typedef enum cpBodyType { /// A kinematic body is an infinite mass, user controlled body that is not affected by gravity, forces or collisions. /// Instead the body only moves based on it's velocity. /// Dynamic bodies collide normally with kinematic bodies, though the kinematic body will be unaffected. - /// Collisions between two kinematic bodies, or a kinematic body and a static body produce collision callbacks, but no collision response. + /// Collisions between two kinematic bodies, or a kinematic body and a body produce collision callbacks, but no collision response. CP_BODY_TYPE_KINEMATIC, - /// A static body is a body that never (or rarely) moves. If you move a static body, you must call one of the cpSpaceReindex*() functions. + /// A body is a body that never (or rarely) moves. If you move a body, you must call one of the cpSpaceReindex*() functions. /// Chipmunk uses this information to optimize the collision detection. - /// Static bodies do not produce collision callbacks when colliding with other static bodies. + /// Static bodies do not produce collision callbacks when colliding with other bodies. CP_BODY_TYPE_STATIC, } cpBodyType; @@ -54,7 +54,7 @@ CP_EXPORT cpBody* cpBodyNew(cpFloat mass, cpFloat moment); /// Allocate and initialize a cpBody, and set it as a kinematic body. CP_EXPORT cpBody* cpBodyNewKinematic(void); -/// Allocate and initialize a cpBody, and set it as a static body. +/// Allocate and initialize a cpBody, and set it as a body. CP_EXPORT cpBody* cpBodyNewStatic(void); /// Destroy a cpBody. @@ -65,7 +65,7 @@ CP_EXPORT void cpBodyFree(cpBody *body); // Defined in cpSpace.c /// Wake up a sleeping or idle body. CP_EXPORT void cpBodyActivate(cpBody *body); -/// Wake up any sleeping or idle bodies touching a static body. +/// Wake up any sleeping or idle bodies touching a body. CP_EXPORT void cpBodyActivateStatic(cpBody *body, cpShape *filter); /// Force a body to fall asleep immediately. diff --git a/include/chipmunk/cpShape.h b/include/chipmunk/cpShape.h index c78ed05d..8046dc22 100644 --- a/include/chipmunk/cpShape.h +++ b/include/chipmunk/cpShape.h @@ -67,7 +67,7 @@ static const cpShapeFilter CP_SHAPE_FILTER_ALL = {CP_NO_GROUP, CP_ALL_CATEGORIES static const cpShapeFilter CP_SHAPE_FILTER_NONE = {CP_NO_GROUP, ~CP_ALL_CATEGORIES, ~CP_ALL_CATEGORIES}; /// Create a new collision filter. -static inline cpShapeFilter +inline cpShapeFilter cpShapeFilterNew(cpGroup group, cpBitmask categories, cpBitmask mask) { cpShapeFilter filter = {group, categories, mask}; diff --git a/include/chipmunk/cpSpace.h b/include/chipmunk/cpSpace.h index 7bbabb85..104940e0 100644 --- a/include/chipmunk/cpSpace.h +++ b/include/chipmunk/cpSpace.h @@ -129,7 +129,7 @@ CP_EXPORT void cpSpaceSetCollisionPersistence(cpSpace *space, cpTimestamp collis CP_EXPORT cpDataPointer cpSpaceGetUserData(const cpSpace *space); CP_EXPORT void cpSpaceSetUserData(cpSpace *space, cpDataPointer userData); -/// The Space provided static body for a given cpSpace. +/// The Space provided body for a given cpSpace. /// This is merely provided for convenience and you are not required to use it. CP_EXPORT cpBody* cpSpaceGetStaticBody(const cpSpace *space); @@ -155,7 +155,7 @@ CP_EXPORT cpCollisionHandler *cpSpaceAddWildcardHandler(cpSpace *space, cpCollis //MARK: Add/Remove objects /// Add a collision shape to the simulation. -/// If the shape is attached to a static body, it will be added as a static shape. +/// If the shape is attached to a body, it will be added as a shape. CP_EXPORT cpShape* cpSpaceAddShape(cpSpace *space, cpShape *shape); /// Add a rigid body to the simulation. CP_EXPORT cpBody* cpSpaceAddBody(cpSpace *space, cpBody *body); @@ -238,7 +238,7 @@ CP_EXPORT void cpSpaceEachConstraint(cpSpace *space, cpSpaceConstraintIteratorFu //MARK: Indexing -/// Update the collision detection info for the static shapes in the space. +/// Update the collision detection info for the shapes in the space. CP_EXPORT void cpSpaceReindexStatic(cpSpace *space); /// Update the collision detection data for a specific shape in the space. CP_EXPORT void cpSpaceReindexShape(cpSpace *space, cpShape *shape); diff --git a/include/chipmunk/cpSpatialIndex.h b/include/chipmunk/cpSpatialIndex.h index 1f7c68ca..9398c0c5 100644 --- a/include/chipmunk/cpSpatialIndex.h +++ b/include/chipmunk/cpSpatialIndex.h @@ -92,7 +92,7 @@ CP_EXPORT cpSpatialIndex* cpBBTreeInit(cpBBTree *tree, cpSpatialIndexBBFunc bbfu /// Allocate and initialize a bounding box tree. CP_EXPORT cpSpatialIndex* cpBBTreeNew(cpSpatialIndexBBFunc bbfunc, cpSpatialIndex *staticIndex); -/// Perform a static top down optimization of the tree. +/// Perform a top down optimization of the tree. CP_EXPORT void cpBBTreeOptimize(cpSpatialIndex *index); /// Bounding box tree velocity callback function. @@ -154,72 +154,72 @@ CP_EXPORT void cpSpatialIndexFree(cpSpatialIndex *index); CP_EXPORT void cpSpatialIndexCollideStatic(cpSpatialIndex *dynamicIndex, cpSpatialIndex *staticIndex, cpSpatialIndexQueryFunc func, void *data); /// Destroy a spatial index. -static inline void cpSpatialIndexDestroy(cpSpatialIndex *index) +inline void cpSpatialIndexDestroy(cpSpatialIndex *index) { if(index->klass) index->klass->destroy(index); } /// Get the number of objects in the spatial index. -static inline int cpSpatialIndexCount(cpSpatialIndex *index) +inline int cpSpatialIndexCount(cpSpatialIndex *index) { return index->klass->count(index); } /// Iterate the objects in the spatial index. @c func will be called once for each object. -static inline void cpSpatialIndexEach(cpSpatialIndex *index, cpSpatialIndexIteratorFunc func, void *data) +inline void cpSpatialIndexEach(cpSpatialIndex *index, cpSpatialIndexIteratorFunc func, void *data) { index->klass->each(index, func, data); } /// Returns true if the spatial index contains the given object. /// Most spatial indexes use hashed storage, so you must provide a hash value too. -static inline cpBool cpSpatialIndexContains(cpSpatialIndex *index, void *obj, cpHashValue hashid) +inline cpBool cpSpatialIndexContains(cpSpatialIndex *index, void *obj, cpHashValue hashid) { return index->klass->contains(index, obj, hashid); } /// Add an object to a spatial index. /// Most spatial indexes use hashed storage, so you must provide a hash value too. -static inline void cpSpatialIndexInsert(cpSpatialIndex *index, void *obj, cpHashValue hashid) +inline void cpSpatialIndexInsert(cpSpatialIndex *index, void *obj, cpHashValue hashid) { index->klass->insert(index, obj, hashid); } /// Remove an object from a spatial index. /// Most spatial indexes use hashed storage, so you must provide a hash value too. -static inline void cpSpatialIndexRemove(cpSpatialIndex *index, void *obj, cpHashValue hashid) +inline void cpSpatialIndexRemove(cpSpatialIndex *index, void *obj, cpHashValue hashid) { index->klass->remove(index, obj, hashid); } /// Perform a full reindex of a spatial index. -static inline void cpSpatialIndexReindex(cpSpatialIndex *index) +inline void cpSpatialIndexReindex(cpSpatialIndex *index) { index->klass->reindex(index); } /// Reindex a single object in the spatial index. -static inline void cpSpatialIndexReindexObject(cpSpatialIndex *index, void *obj, cpHashValue hashid) +inline void cpSpatialIndexReindexObject(cpSpatialIndex *index, void *obj, cpHashValue hashid) { index->klass->reindexObject(index, obj, hashid); } /// Perform a rectangle query against the spatial index, calling @c func for each potential match. -static inline void cpSpatialIndexQuery(cpSpatialIndex *index, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, void *data) +inline void cpSpatialIndexQuery(cpSpatialIndex *index, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, void *data) { index->klass->query(index, obj, bb, func, data); } /// Perform a segment query against the spatial index, calling @c func for each potential match. -static inline void cpSpatialIndexSegmentQuery(cpSpatialIndex *index, void *obj, cpVect a, cpVect b, cpFloat t_exit, cpSpatialIndexSegmentQueryFunc func, void *data) +inline void cpSpatialIndexSegmentQuery(cpSpatialIndex *index, void *obj, cpVect a, cpVect b, cpFloat t_exit, cpSpatialIndexSegmentQueryFunc func, void *data) { index->klass->segmentQuery(index, obj, a, b, t_exit, func, data); } /// Simultaneously reindex and find all colliding objects. /// @c func will be called once for each potentially overlapping pair of objects found. -/// If the spatial index was initialized with a static index, it will collide it's objects against that as well. -static inline void cpSpatialIndexReindexQuery(cpSpatialIndex *index, cpSpatialIndexQueryFunc func, void *data) +/// If the spatial index was initialized with a index, it will collide it's objects against that as well. +inline void cpSpatialIndexReindexQuery(cpSpatialIndex *index, cpSpatialIndexQueryFunc func, void *data) { index->klass->reindexQuery(index, func, data); } diff --git a/include/chipmunk/cpTransform.h b/include/chipmunk/cpTransform.h index 4a6256b9..fdb185ee 100644 --- a/include/chipmunk/cpTransform.h +++ b/include/chipmunk/cpTransform.h @@ -33,7 +33,7 @@ static const cpTransform cpTransformIdentity = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0. /// (a, b) is the x basis vector. /// (c, d) is the y basis vector. /// (tx, ty) is the translation. -static inline cpTransform +inline cpTransform cpTransformNew(cpFloat a, cpFloat b, cpFloat c, cpFloat d, cpFloat tx, cpFloat ty) { cpTransform t = {a, b, c, d, tx, ty}; @@ -41,7 +41,7 @@ cpTransformNew(cpFloat a, cpFloat b, cpFloat c, cpFloat d, cpFloat tx, cpFloat t } /// Construct a new transform matrix in transposed order. -static inline cpTransform +inline cpTransform cpTransformNewTranspose(cpFloat a, cpFloat c, cpFloat tx, cpFloat b, cpFloat d, cpFloat ty) { cpTransform t = {a, b, c, d, tx, ty}; @@ -49,7 +49,7 @@ cpTransformNewTranspose(cpFloat a, cpFloat c, cpFloat tx, cpFloat b, cpFloat d, } /// Get the inverse of a transform matrix. -static inline cpTransform +inline cpTransform cpTransformInverse(cpTransform t) { cpFloat inv_det = 1.0/(t.a*t.d - t.c*t.b); @@ -60,7 +60,7 @@ cpTransformInverse(cpTransform t) } /// Multiply two transformation matrices. -static inline cpTransform +inline cpTransform cpTransformMult(cpTransform t1, cpTransform t2) { return cpTransformNewTranspose( @@ -70,21 +70,21 @@ cpTransformMult(cpTransform t1, cpTransform t2) } /// Transform an absolute point. (i.e. a vertex) -static inline cpVect +inline cpVect cpTransformPoint(cpTransform t, cpVect p) { return cpv(t.a*p.x + t.c*p.y + t.tx, t.b*p.x + t.d*p.y + t.ty); } /// Transform a vector (i.e. a normal) -static inline cpVect +inline cpVect cpTransformVect(cpTransform t, cpVect v) { return cpv(t.a*v.x + t.c*v.y, t.b*v.x + t.d*v.y); } /// Transform a cpBB. -static inline cpBB +inline cpBB cpTransformbBB(cpTransform t, cpBB bb) { cpVect center = cpBBCenter(bb); @@ -98,7 +98,7 @@ cpTransformbBB(cpTransform t, cpBB bb) } /// Create a transation matrix. -static inline cpTransform +inline cpTransform cpTransformTranslate(cpVect translate) { return cpTransformNewTranspose( @@ -108,7 +108,7 @@ cpTransformTranslate(cpVect translate) } /// Create a scale matrix. -static inline cpTransform +inline cpTransform cpTransformScale(cpFloat scaleX, cpFloat scaleY) { return cpTransformNewTranspose( @@ -118,7 +118,7 @@ cpTransformScale(cpFloat scaleX, cpFloat scaleY) } /// Create a rotation matrix. -static inline cpTransform +inline cpTransform cpTransformRotate(cpFloat radians) { cpVect rot = cpvforangle(radians); @@ -129,7 +129,7 @@ cpTransformRotate(cpFloat radians) } /// Create a rigid transformation matrix. (transation + rotation) -static inline cpTransform +inline cpTransform cpTransformRigid(cpVect translate, cpFloat radians) { cpVect rot = cpvforangle(radians); @@ -140,7 +140,7 @@ cpTransformRigid(cpVect translate, cpFloat radians) } /// Fast inverse of a rigid transformation matrix. -static inline cpTransform +inline cpTransform cpTransformRigidInverse(cpTransform t) { return cpTransformNewTranspose( @@ -152,19 +152,19 @@ cpTransformRigidInverse(cpTransform t) //MARK: Miscellaneous (but useful) transformation matrices. // See source for documentation... -static inline cpTransform +inline cpTransform cpTransformWrap(cpTransform outer, cpTransform inner) { return cpTransformMult(cpTransformInverse(outer), cpTransformMult(inner, outer)); } -static inline cpTransform +inline cpTransform cpTransformWrapInverse(cpTransform outer, cpTransform inner) { return cpTransformMult(outer, cpTransformMult(inner, cpTransformInverse(outer))); } -static inline cpTransform +inline cpTransform cpTransformOrtho(cpBB bb) { return cpTransformNewTranspose( @@ -173,7 +173,7 @@ cpTransformOrtho(cpBB bb) ); } -static inline cpTransform +inline cpTransform cpTransformBoneScale(cpVect v0, cpVect v1) { cpVect d = cpvsub(v1, v0); @@ -183,7 +183,7 @@ cpTransformBoneScale(cpVect v0, cpVect v1) ); } -static inline cpTransform +inline cpTransform cpTransformAxialScale(cpVect axis, cpVect pivot, cpFloat scale) { cpFloat A = axis.x*axis.y*(scale - 1.0); diff --git a/include/chipmunk/cpVect.h b/include/chipmunk/cpVect.h index 8ec02bdc..6e26fef9 100644 --- a/include/chipmunk/cpVect.h +++ b/include/chipmunk/cpVect.h @@ -32,44 +32,44 @@ static const cpVect cpvzero = {0.0f,0.0f}; /// Convenience constructor for cpVect structs. -static inline cpVect cpv(const cpFloat x, const cpFloat y) +inline cpVect cpv(const cpFloat x, const cpFloat y) { cpVect v = {x, y}; return v; } /// Check if two vectors are equal. (Be careful when comparing floating point numbers!) -static inline cpBool cpveql(const cpVect v1, const cpVect v2) +inline cpBool cpveql(const cpVect v1, const cpVect v2) { return (v1.x == v2.x && v1.y == v2.y); } /// Add two vectors -static inline cpVect cpvadd(const cpVect v1, const cpVect v2) +inline cpVect cpvadd(const cpVect v1, const cpVect v2) { return cpv(v1.x + v2.x, v1.y + v2.y); } /// Subtract two vectors. -static inline cpVect cpvsub(const cpVect v1, const cpVect v2) +inline cpVect cpvsub(const cpVect v1, const cpVect v2) { return cpv(v1.x - v2.x, v1.y - v2.y); } /// Negate a vector. -static inline cpVect cpvneg(const cpVect v) +inline cpVect cpvneg(const cpVect v) { return cpv(-v.x, -v.y); } /// Scalar multiplication. -static inline cpVect cpvmult(const cpVect v, const cpFloat s) +inline cpVect cpvmult(const cpVect v, const cpFloat s) { return cpv(v.x*s, v.y*s); } /// Vector dot product. -static inline cpFloat cpvdot(const cpVect v1, const cpVect v2) +inline cpFloat cpvdot(const cpVect v1, const cpVect v2) { return v1.x*v2.x + v1.y*v2.y; } @@ -77,80 +77,80 @@ static inline cpFloat cpvdot(const cpVect v1, const cpVect v2) /// 2D vector cross product analog. /// The cross product of 2D vectors results in a 3D vector with only a z component. /// This function returns the magnitude of the z value. -static inline cpFloat cpvcross(const cpVect v1, const cpVect v2) +inline cpFloat cpvcross(const cpVect v1, const cpVect v2) { return v1.x*v2.y - v1.y*v2.x; } /// Returns a perpendicular vector. (90 degree rotation) -static inline cpVect cpvperp(const cpVect v) +inline cpVect cpvperp(const cpVect v) { return cpv(-v.y, v.x); } /// Returns a perpendicular vector. (-90 degree rotation) -static inline cpVect cpvrperp(const cpVect v) +inline cpVect cpvrperp(const cpVect v) { return cpv(v.y, -v.x); } /// Returns the vector projection of v1 onto v2. -static inline cpVect cpvproject(const cpVect v1, const cpVect v2) +inline cpVect cpvproject(const cpVect v1, const cpVect v2) { return cpvmult(v2, cpvdot(v1, v2)/cpvdot(v2, v2)); } /// Returns the unit length vector for the given angle (in radians). -static inline cpVect cpvforangle(const cpFloat a) +inline cpVect cpvforangle(const cpFloat a) { return cpv(cpfcos(a), cpfsin(a)); } /// Returns the angular direction v is pointing in (in radians). -static inline cpFloat cpvtoangle(const cpVect v) +inline cpFloat cpvtoangle(const cpVect v) { return cpfatan2(v.y, v.x); } /// Uses complex number multiplication to rotate v1 by v2. Scaling will occur if v1 is not a unit vector. -static inline cpVect cpvrotate(const cpVect v1, const cpVect v2) +inline cpVect cpvrotate(const cpVect v1, const cpVect v2) { return cpv(v1.x*v2.x - v1.y*v2.y, v1.x*v2.y + v1.y*v2.x); } /// Inverse of cpvrotate(). -static inline cpVect cpvunrotate(const cpVect v1, const cpVect v2) +inline cpVect cpvunrotate(const cpVect v1, const cpVect v2) { return cpv(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y); } /// Returns the squared length of v. Faster than cpvlength() when you only need to compare lengths. -static inline cpFloat cpvlengthsq(const cpVect v) +inline cpFloat cpvlengthsq(const cpVect v) { return cpvdot(v, v); } /// Returns the length of v. -static inline cpFloat cpvlength(const cpVect v) +inline cpFloat cpvlength(const cpVect v) { return cpfsqrt(cpvdot(v, v)); } /// Linearly interpolate between v1 and v2. -static inline cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t) +inline cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t) { return cpvadd(cpvmult(v1, 1.0f - t), cpvmult(v2, t)); } /// Returns a normalized copy of v. -static inline cpVect cpvnormalize(const cpVect v) +inline cpVect cpvnormalize(const cpVect v) { // Neat trick I saw somewhere to avoid div/0. return cpvmult(v, 1.0f/(cpvlength(v) + CPFLOAT_MIN)); } /// Spherical linearly interpolate between v1 and v2. -static inline cpVect +inline cpVect cpvslerp(const cpVect v1, const cpVect v2, const cpFloat t) { cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2)); @@ -166,7 +166,7 @@ cpvslerp(const cpVect v1, const cpVect v2, const cpFloat t) } /// Spherical linearly interpolate between v1 towards v2 by no more than angle a radians -static inline cpVect +inline cpVect cpvslerpconst(const cpVect v1, const cpVect v2, const cpFloat a) { cpFloat dot = cpvdot(cpvnormalize(v1), cpvnormalize(v2)); @@ -176,31 +176,31 @@ cpvslerpconst(const cpVect v1, const cpVect v2, const cpFloat a) } /// Clamp v to length len. -static inline cpVect cpvclamp(const cpVect v, const cpFloat len) +inline cpVect cpvclamp(const cpVect v, const cpFloat len) { return (cpvdot(v,v) > len*len) ? cpvmult(cpvnormalize(v), len) : v; } /// Linearly interpolate between v1 towards v2 by distance d. -static inline cpVect cpvlerpconst(cpVect v1, cpVect v2, cpFloat d) +inline cpVect cpvlerpconst(cpVect v1, cpVect v2, cpFloat d) { return cpvadd(v1, cpvclamp(cpvsub(v2, v1), d)); } /// Returns the distance between v1 and v2. -static inline cpFloat cpvdist(const cpVect v1, const cpVect v2) +inline cpFloat cpvdist(const cpVect v1, const cpVect v2) { return cpvlength(cpvsub(v1, v2)); } /// Returns the squared distance between v1 and v2. Faster than cpvdist() when you only need to compare distances. -static inline cpFloat cpvdistsq(const cpVect v1, const cpVect v2) +inline cpFloat cpvdistsq(const cpVect v1, const cpVect v2) { return cpvlengthsq(cpvsub(v1, v2)); } /// Returns true if the distance between v1 and v2 is less than dist. -static inline cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dist) +inline cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dist) { return cpvdistsq(v1, v2) < dist*dist; } @@ -212,14 +212,14 @@ static inline cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dis /// @{ // NUKE -static inline cpMat2x2 +inline cpMat2x2 cpMat2x2New(cpFloat a, cpFloat b, cpFloat c, cpFloat d) { cpMat2x2 m = {a, b, c, d}; return m; } -static inline cpVect +inline cpVect cpMat2x2Transform(cpMat2x2 m, cpVect v) { return cpv(v.x*m.a + v.y*m.b, v.x*m.c + v.y*m.d); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef6706d7..e50f26d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,9 +11,13 @@ message("Configuring Chipmunk2D version ${CHIPMUNK_VERSION}") if(BUILD_SHARED) - add_library(chipmunk SHARED - ${chipmunk_source_files} - ) + if (FUNCTION_POINTERS) + message("Building shared library with function pointers.") + add_library(chipmunk SHARED ${chipmunk_source_files} "opt/chipmunk_fptrs.c") + else() + message("Building shared library without function pointers.") + add_library(chipmunk SHARED ${chipmunk_source_files}) + endif() # Tell MSVC to compile the code as C++. if(MSVC) set_source_files_properties(${chipmunk_source_files} PROPERTIES LANGUAGE CXX) diff --git a/src/chipmunk.c b/src/chipmunk.c index c6477e10..95563516 100644 --- a/src/chipmunk.c +++ b/src/chipmunk.c @@ -325,7 +325,50 @@ cpBool cpSpaceShapeQuery_b(cpSpace *space, cpShape *shape, cpSpaceShapeQueryBloc return cpSpaceShapeQuery(space, shape, (cpSpaceShapeQueryFunc)ShapeQueryIteratorFunc, block); } +// declarations of inline functions in chipmunk_types.h + +cpFloat cpfmax(cpFloat a, cpFloat b); +cpFloat cpfmin(cpFloat a, cpFloat b); +cpFloat cpfabs(cpFloat f); +cpFloat cpfclamp(cpFloat f, cpFloat min, cpFloat max); +cpFloat cpfclamp01(cpFloat f); +cpFloat cpflerp(cpFloat f1, cpFloat f2, cpFloat t); +cpFloat cpflerpconst(cpFloat f1, cpFloat f2, cpFloat d); + +// declarations of inline functions in chipmunk_private.h + +void CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r1, cpVect a, cpVect b, cpFloat r2, cpSegmentQueryInfo *info); + +cpArbiter * cpArbiterNext(cpArbiter *node, cpBody *body); + +cpVect cpClosetPointOnSegment(const cpVect p, const cpVect a, const cpVect b); +struct cpArbiterThread * cpArbiterThreadForBody(cpArbiter *arb, cpBody *body); +cpBool cpShapeActive(cpShape *shape); +void CircleSegmentQuery(cpShape *shape, cpVect center, cpFloat r1, cpVect a, cpVect b, cpFloat r2, cpSegmentQueryInfo *info); +cpBool cpShapeFilterReject(cpShapeFilter a, cpShapeFilter b); +void cpConstraintActivateBodies(cpConstraint *constraint); + +void cpSpaceUncacheArbiter(cpSpace *space, cpArbiter *arb); +cpArray * cpSpaceArrayForBodyType(cpSpace *space, cpBodyType type); +cpConstraint * cpConstraintNext(cpConstraint *node, cpBody *body); +cpArbiter * cpArbiterNext(cpArbiter *node, cpBody *body); +cpShapeFilter cpShapeFilterNew(cpGroup group, cpBitmask categories, cpBitmask mask); + +void cpConstraintActivateBodies(cpConstraint *constraint); +cpVect relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2); +cpFloat normal_relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n); +void apply_impulse(cpBody *body, cpVect j, cpVect r); +void apply_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j); +void apply_bias_impulse(cpBody *body, cpVect j, cpVect r); +void apply_bias_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j); +cpFloat k_scalar_body(cpBody *body, cpVect r, cpVect n); +cpFloat k_scalar(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n); +cpMat2x2 k_tensor(cpBody *a, cpBody *b, cpVect r1, cpVect r2); +cpFloat bias_coef(cpFloat errorBias, cpFloat dt); + +cpMat2x2 cpMat2x2New(cpFloat a, cpFloat b, cpFloat c, cpFloat d); +cpVect cpMat2x2Transform(cpMat2x2 m, cpVect v); + #endif #endif -#include "chipmunk/chipmunk_ffi.h" diff --git a/src/cpBB.c b/src/cpBB.c new file mode 100644 index 00000000..967872d9 --- /dev/null +++ b/src/cpBB.c @@ -0,0 +1,23 @@ + +#include "chipmunk/cpBB.h" + +// inline functions are redeclared in this translation unit so they are properly exported; +// FIXME: this might not really be necessary + +cpBB cpBBNew(const cpFloat l, const cpFloat b, const cpFloat r, const cpFloat t); +cpBB cpBBNewForExtents(const cpVect c, const cpFloat hw, const cpFloat hh); +cpBB cpBBNewForCircle(const cpVect p, const cpFloat r); +cpBool cpBBIntersects(const cpBB a, const cpBB b); +cpBool cpBBContainsBB(const cpBB bb, const cpBB other); +cpBool cpBBContainsVect(const cpBB bb, const cpVect v); +cpBB cpBBMerge(const cpBB a, const cpBB b); +cpBB cpBBExpand(const cpBB bb, const cpVect v); +cpVect cpBBCenter(cpBB bb); +cpFloat cpBBArea(cpBB bb); +cpFloat cpBBMergedArea(cpBB a, cpBB b); +cpFloat cpBBSegmentQuery(cpBB bb, cpVect a, cpVect b); +cpBool cpBBIntersectsSegment(cpBB bb, cpVect a, cpVect b); +cpVect cpBBClampVect(const cpBB bb, const cpVect v); +cpVect cpBBWrapVect(const cpBB bb, const cpVect v); +cpBB cpBBOffset(const cpBB bb, const cpVect v); + diff --git a/src/cpSpatialIndex.c b/src/cpSpatialIndex.c index 3fb7cb5d..c118747e 100644 --- a/src/cpSpatialIndex.c +++ b/src/cpSpatialIndex.c @@ -67,3 +67,17 @@ cpSpatialIndexCollideStatic(cpSpatialIndex *dynamicIndex, cpSpatialIndex *static } } +// declarations of inline functions in "cpSpatialIndex.h" + +void cpSpatialIndexDestroy(cpSpatialIndex *index); +int cpSpatialIndexCount(cpSpatialIndex *index); +void cpSpatialIndexEach(cpSpatialIndex *index, cpSpatialIndexIteratorFunc func, void *data); +cpBool cpSpatialIndexContains(cpSpatialIndex *index, void *obj, cpHashValue hashid); +void cpSpatialIndexInsert(cpSpatialIndex *index, void *obj, cpHashValue hashid); +void cpSpatialIndexRemove(cpSpatialIndex *index, void *obj, cpHashValue hashid); +void cpSpatialIndexReindex(cpSpatialIndex *index); +void cpSpatialIndexReindexObject(cpSpatialIndex *index, void *obj, cpHashValue hashid); +void cpSpatialIndexQuery(cpSpatialIndex *index, void *obj, cpBB bb, cpSpatialIndexQueryFunc func, void *data); +void cpSpatialIndexSegmentQuery(cpSpatialIndex *index, void *obj, cpVect a, cpVect b, cpFloat t_exit, cpSpatialIndexSegmentQueryFunc func, void *data); +void cpSpatialIndexReindexQuery(cpSpatialIndex *index, cpSpatialIndexQueryFunc func, void *data); + diff --git a/src/cpTransform.c b/src/cpTransform.c new file mode 100644 index 00000000..1e44e324 --- /dev/null +++ b/src/cpTransform.c @@ -0,0 +1,22 @@ + +#include "chipmunk/cpTransform.h" + +// declarations of inline functions in cpTransform.h + +cpTransform cpTransformNew(cpFloat a, cpFloat b, cpFloat c, cpFloat d, cpFloat tx, cpFloat ty); +cpTransform cpTransformNewTranspose(cpFloat a, cpFloat c, cpFloat tx, cpFloat b, cpFloat d, cpFloat ty); +cpTransform cpTransformInverse(cpTransform t); +cpTransform cpTransformMult(cpTransform t1, cpTransform t2); +cpVect cpTransformPoint(cpTransform t, cpVect p); +cpVect cpTransformVect(cpTransform t, cpVect v); +cpBB cpTransformbBB(cpTransform t, cpBB bb); +cpTransform cpTransformTranslate(cpVect translate); +cpTransform cpTransformScale(cpFloat scaleX, cpFloat scaleY); +cpTransform cpTransformRotate(cpFloat radians); +cpTransform cpTransformRigid(cpVect translate, cpFloat radians); +cpTransform cpTransformRigidInverse(cpTransform t); +cpTransform cpTransformWrap(cpTransform outer, cpTransform inner); +cpTransform cpTransformWrapInverse(cpTransform outer, cpTransform inner); +cpTransform cpTransformOrtho(cpBB bb); +cpTransform cpTransformBoneScale(cpVect v0, cpVect v1); +cpTransform cpTransformAxialScale(cpVect axis, cpVect pivot, cpFloat scale); diff --git a/src/cpVect.c b/src/cpVect.c new file mode 100644 index 00000000..62408812 --- /dev/null +++ b/src/cpVect.c @@ -0,0 +1,30 @@ + +#include "chipmunk/cpVect.h" + +cpVect cpv(const cpFloat x, const cpFloat y); +cpBool cpveql(const cpVect v1, const cpVect v2); +cpVect cpvadd(const cpVect v1, const cpVect v2); +cpVect cpvsub(const cpVect v1, const cpVect v2); +cpVect cpvneg(const cpVect v); +cpVect cpvmult(const cpVect v, const cpFloat s); +cpFloat cpvdot(const cpVect v1, const cpVect v2); +cpFloat cpvcross(const cpVect v1, const cpVect v2); +cpVect cpvperp(const cpVect v); +cpVect cpvrperp(const cpVect v); +cpVect cpvproject(const cpVect v1, const cpVect v2); +cpVect cpvforangle(const cpFloat a); +cpFloat cpvtoangle(const cpVect v); +cpVect cpvrotate(const cpVect v1, const cpVect v2); +cpVect cpvunrotate(const cpVect v1, const cpVect v2); +cpFloat cpvlengthsq(const cpVect v); +cpFloat cpvlength(const cpVect v); +cpVect cpvlerp(const cpVect v1, const cpVect v2, const cpFloat t); +cpVect cpvnormalize(const cpVect v); +cpVect cpvslerp(const cpVect v1, const cpVect v2, const cpFloat t); +cpVect cpvslerpconst(const cpVect v1, const cpVect v2, const cpFloat a); +cpVect cpvclamp(const cpVect v, const cpFloat len); +cpVect cpvlerpconst(cpVect v1, cpVect v2, cpFloat d); +cpFloat cpvdist(const cpVect v1, const cpVect v2); +cpFloat cpvdistsq(const cpVect v1, const cpVect v2); +cpBool cpvnear(const cpVect v1, const cpVect v2, const cpFloat dist); + diff --git a/include/chipmunk/chipmunk_ffi.h b/src/opt/chipmunk_fptrs.c similarity index 99% rename from include/chipmunk/chipmunk_ffi.h rename to src/opt/chipmunk_fptrs.c index 86e3d9fc..3e8ca09e 100644 --- a/include/chipmunk/chipmunk_ffi.h +++ b/src/opt/chipmunk_fptrs.c @@ -19,7 +19,7 @@ * SOFTWARE. */ -#ifdef CHIPMUNK_FFI +#include "chipmunk/chipmunk.h" // Create non static inlined copies of Chipmunk functions, useful for working with dynamic FFIs // For many languages, it may be faster to reimplement these functions natively instead. @@ -102,4 +102,3 @@ MAKE_REF(cpSpatialIndexReindexQuery); } #endif -#endif