/usr/include/chipmunk/cpShape.h is in chipmunk-dev 5.3.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | /* Copyright (c) 2007 Scott Lembcke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
// Forward declarations required for defining other structs.
struct cpShape;
struct cpShapeClass;
typedef struct cpSegmentQueryInfo {
struct cpShape *shape; // shape that was hit, NULL if no collision
cpFloat t; // Distance along query segment, will always be in the range [0, 1].
cpVect n; // normal of hit surface
} cpSegmentQueryInfo;
// Enumeration of shape types.
typedef enum cpShapeType{
CP_CIRCLE_SHAPE,
CP_SEGMENT_SHAPE,
CP_POLY_SHAPE,
CP_NUM_SHAPES
} cpShapeType;
// Shape class. Holds function pointers and type data.
typedef struct cpShapeClass {
cpShapeType type;
// Called by cpShapeCacheBB().
cpBB (*cacheData)(struct cpShape *shape, cpVect p, cpVect rot);
// Called to by cpShapeDestroy().
void (*destroy)(struct cpShape *shape);
// called by cpShapePointQuery().
cpBool (*pointQuery)(struct cpShape *shape, cpVect p);
// called by cpShapeSegmentQuery()
void (*segmentQuery)(struct cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info);
} cpShapeClass;
// Basic shape struct that the others inherit from.
typedef struct cpShape{
// The "class" of a shape as defined above
CP_PRIVATE(const cpShapeClass *klass);
// cpBody that the shape is attached to.
cpBody *body;
// Cached BBox for the shape.
cpBB bb;
// Sensors invoke callbacks, but do not generate collisions
cpBool sensor;
// *** Surface properties.
// Coefficient of restitution. (elasticity)
cpFloat e;
// Coefficient of friction.
cpFloat u;
// Surface velocity used when solving for friction.
cpVect surface_v;
// *** User Definable Fields
// User defined data pointer for the shape.
cpDataPointer data;
// User defined collision type for the shape.
cpCollisionType collision_type;
// User defined collision group for the shape.
cpGroup group;
// User defined layer bitmask for the shape.
cpLayers layers;
// *** Internally Used Fields
// Shapes form a linked list when added to space on a non-NULL body
CP_PRIVATE(struct cpShape *next);
// Unique id used as the hash value.
CP_PRIVATE(cpHashValue hashid);
} cpShape;
// Low level shape initialization func.
cpShape* cpShapeInit(cpShape *shape, const struct cpShapeClass *klass, cpBody *body);
// Basic destructor functions. (allocation functions are not shared)
void cpShapeDestroy(cpShape *shape);
void cpShapeFree(cpShape *shape);
// Cache the BBox of the shape.
cpBB cpShapeCacheBB(cpShape *shape);
// Test if a point lies within a shape.
cpBool cpShapePointQuery(cpShape *shape, cpVect p);
#define CP_DeclareShapeGetter(struct, type, name) type struct##Get##name(cpShape *shape)
// Circle shape structure.
typedef struct cpCircleShape{
CP_PRIVATE(cpShape shape);
// Center in body space coordinates
CP_PRIVATE(cpVect c);
// Radius.
CP_PRIVATE(cpFloat r);
// Transformed center. (world space coordinates)
CP_PRIVATE(cpVect tc);
} cpCircleShape;
// Basic allocation functions for cpCircleShape.
cpCircleShape *cpCircleShapeAlloc(void);
cpCircleShape *cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
cpShape *cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
CP_DeclareShapeGetter(cpCircleShape, cpVect, Offset);
CP_DeclareShapeGetter(cpCircleShape, cpFloat, Radius);
// Segment shape structure.
typedef struct cpSegmentShape{
CP_PRIVATE(cpShape shape);
// Endpoints and normal of the segment. (body space coordinates)
cpVect CP_PRIVATE(a), CP_PRIVATE(b), CP_PRIVATE(n);
// Radius of the segment. (Thickness)
cpFloat CP_PRIVATE(r);
// Transformed endpoints and normal. (world space coordinates)
cpVect CP_PRIVATE(ta), CP_PRIVATE(tb), CP_PRIVATE(tn);
} cpSegmentShape;
// Basic allocation functions for cpSegmentShape.
cpSegmentShape* cpSegmentShapeAlloc(void);
cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius);
cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
CP_DeclareShapeGetter(cpSegmentShape, cpVect, A);
CP_DeclareShapeGetter(cpSegmentShape, cpVect, B);
CP_DeclareShapeGetter(cpSegmentShape, cpVect, Normal);
CP_DeclareShapeGetter(cpSegmentShape, cpFloat, Radius);
// For determinism, you can reset the shape id counter.
void cpResetShapeIdCounter(void);
// Directed segment queries against individual shapes.
void cpSegmentQueryInfoPrint(cpSegmentQueryInfo *info);
cpBool cpShapeSegmentQuery(cpShape *shape, cpVect a, cpVect b, cpSegmentQueryInfo *info);
static inline cpVect
cpSegmentQueryHitPoint(const cpVect start, const cpVect end, const cpSegmentQueryInfo info)
{
return cpvlerp(start, end, info.t);
}
static inline cpFloat
cpSegmentQueryHitDist(const cpVect start, const cpVect end, const cpSegmentQueryInfo info)
{
return cpvdist(start, end)*info.t;
}
|