Munk2D Documentation  8.x.x
Loading...
Searching...
No Matches
cpShape.h
1/* Copyright (c) 2025 Victor Blomqvist
2 * Copyright (c) 2007-2024 Scott Lembcke and Howling Moon Software
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21*/
22
26
39
51
64
68static const cpShapeFilter CP_SHAPE_FILTER_NONE = {CP_NO_GROUP, ~CP_ALL_CATEGORIES, ~CP_ALL_CATEGORIES};
69
71static inline cpShapeFilter
73{
74 cpShapeFilter filter = {group, categories, mask};
75 return filter;
76}
77
79CP_EXPORT void cpShapeDestroy(cpShape *shape);
81CP_EXPORT void cpShapeFree(cpShape *shape);
82
84CP_EXPORT cpBB cpShapeCacheBB(cpShape *shape);
86CP_EXPORT cpBB cpShapeUpdate(cpShape *shape, cpTransform transform);
87
90CP_EXPORT cpFloat cpShapePointQuery(const cpShape *shape, cpVect p, cpPointQueryInfo *out);
91
93CP_EXPORT cpBool cpShapeSegmentQuery(const cpShape *shape, cpVect a, cpVect b, cpFloat radius, cpSegmentQueryInfo *info);
94
96CP_EXPORT cpContactPointSet cpShapesCollide(const cpShape *a, const cpShape *b);
97
99CP_EXPORT cpSpace* cpShapeGetSpace(const cpShape *shape);
100
102CP_EXPORT cpBody* cpShapeGetBody(const cpShape *shape);
105CP_EXPORT void cpShapeSetBody(cpShape *shape, cpBody *body);
106
110CP_EXPORT void cpShapeSetMass(cpShape *shape, cpFloat mass);
111
115CP_EXPORT void cpShapeSetDensity(cpShape *shape, cpFloat density);
116
123
125CP_EXPORT cpBB cpShapeGetBB(const cpShape *shape);
126
128CP_EXPORT cpBool cpShapeGetSensor(const cpShape *shape);
130CP_EXPORT void cpShapeSetSensor(cpShape *shape, cpBool sensor);
131
133CP_EXPORT cpFloat cpShapeGetElasticity(const cpShape *shape);
135CP_EXPORT void cpShapeSetElasticity(cpShape *shape, cpFloat elasticity);
136
138CP_EXPORT cpFloat cpShapeGetFriction(const cpShape *shape);
140CP_EXPORT void cpShapeSetFriction(cpShape *shape, cpFloat friction);
141
145CP_EXPORT void cpShapeSetSurfaceVelocity(cpShape *shape, cpVect surfaceVelocity);
146
150CP_EXPORT void cpShapeSetUserData(cpShape *shape, cpDataPointer userData);
151
155CP_EXPORT void cpShapeSetCollisionType(cpShape *shape, cpCollisionType collisionType);
156
158CP_EXPORT cpShapeFilter cpShapeGetFilter(const cpShape *shape);
160CP_EXPORT void cpShapeSetFilter(cpShape *shape, cpShapeFilter filter);
161
163
166
170CP_EXPORT cpCircleShape* cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
172CP_EXPORT cpShape* cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
173
175CP_EXPORT cpVect cpCircleShapeGetOffset(const cpShape *shape);
177CP_EXPORT cpFloat cpCircleShapeGetRadius(const cpShape *shape);
178
180
183
189CP_EXPORT cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
190
192CP_EXPORT void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next);
193
195CP_EXPORT cpVect cpSegmentShapeGetA(const cpShape *shape);
197CP_EXPORT cpVect cpSegmentShapeGetB(const cpShape *shape);
199CP_EXPORT cpVect cpSegmentShapeGetNormal(const cpShape *shape);
202
void * cpDataPointer
Type used for user data pointers.
Definition chipmunk_types.h:196
#define CP_ALL_CATEGORIES
Value for cpShape.layers signifying that a shape is in every layer.
Definition chipmunk_types.h:234
unsigned char cpBool
Chipmunk's boolean type.
Definition chipmunk_types.h:179
#define CP_NO_GROUP
Value for cpShape.group signifying that a shape is in no group.
Definition chipmunk_types.h:229
double cpFloat
Chipmunk's floating point type.
Definition chipmunk_types.h:68
uintptr_t cpGroup
Type used for cpShape.group.
Definition chipmunk_types.h:210
unsigned int cpBitmask
Type used for cpShapeFilter category and mask.
Definition chipmunk_types.h:217
uintptr_t cpCollisionType
Type used for cpSpace.collision_type.
Definition chipmunk_types.h:203
CP_EXPORT cpShape * cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset)
Allocate and initialize a circle shape.
CP_EXPORT cpFloat cpCircleShapeGetRadius(const cpShape *shape)
Get the radius of a circle shape.
CP_EXPORT cpVect cpCircleShapeGetOffset(const cpShape *shape)
Get the offset of a circle shape.
CP_EXPORT cpCircleShape * cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset)
Initialize a circle shape.
CP_EXPORT cpCircleShape * cpCircleShapeAlloc(void)
Allocate a circle shape.
CP_EXPORT cpFloat cpSegmentShapeGetRadius(const cpShape *shape)
Get the first endpoint of a segment shape.
CP_EXPORT cpShape * cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius)
Allocate and initialize a segment shape.
CP_EXPORT void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next)
Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.
CP_EXPORT cpSegmentShape * cpSegmentShapeAlloc(void)
Allocate a segment shape.
CP_EXPORT cpVect cpSegmentShapeGetB(const cpShape *shape)
Get the second endpoint of a segment shape.
CP_EXPORT cpSegmentShape * cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius)
Initialize a segment shape.
CP_EXPORT cpVect cpSegmentShapeGetA(const cpShape *shape)
Get the first endpoint of a segment shape.
CP_EXPORT cpVect cpSegmentShapeGetNormal(const cpShape *shape)
Get the normal of a segment shape.
CP_EXPORT cpBool cpShapeGetSensor(const cpShape *shape)
Get if the shape is set to be a sensor or not.
CP_EXPORT void cpShapeFree(cpShape *shape)
Destroy and Free a shape.
CP_EXPORT cpContactPointSet cpShapesCollide(const cpShape *a, const cpShape *b)
Return contact information about two shapes.
CP_EXPORT void cpShapeDestroy(cpShape *shape)
Destroy a shape.
CP_EXPORT cpVect cpShapeGetCenterOfGravity(cpShape *shape)
Get the centroid of this shape.
CP_EXPORT void cpShapeSetUserData(cpShape *shape, cpDataPointer userData)
Set the user definable data pointer of this shape.
CP_EXPORT void cpShapeSetBody(cpShape *shape, cpBody *body)
Set the cpBody this shape is connected to.
CP_EXPORT cpFloat cpShapeGetElasticity(const cpShape *shape)
Get the elasticity of this shape.
CP_EXPORT cpBB cpShapeGetBB(const cpShape *shape)
Get the bounding box that contains the shape given it's current position and angle.
CP_EXPORT void cpShapeSetFriction(cpShape *shape, cpFloat friction)
Set the friction of this shape.
CP_EXPORT cpFloat cpShapePointQuery(const cpShape *shape, cpVect p, cpPointQueryInfo *out)
Perform a nearest point query.
CP_EXPORT cpFloat cpShapeGetMoment(cpShape *shape)
Get the calculated moment of inertia for this shape.
CP_EXPORT void cpShapeSetSurfaceVelocity(cpShape *shape, cpVect surfaceVelocity)
Set the surface velocity of this shape.
CP_EXPORT void cpShapeSetDensity(cpShape *shape, cpFloat density)
Set the density of this shape to have Chipmunk calculate mass properties for you.
CP_EXPORT void cpShapeSetElasticity(cpShape *shape, cpFloat elasticity)
Set the elasticity of this shape.
CP_EXPORT cpSpace * cpShapeGetSpace(const cpShape *shape)
The cpSpace this body is added to.
CP_EXPORT void cpShapeSetMass(cpShape *shape, cpFloat mass)
Set the mass of this shape to have Chipmunk calculate mass properties for you.
static cpShapeFilter cpShapeFilterNew(cpGroup group, cpBitmask categories, cpBitmask mask)
Create a new collision filter.
Definition cpShape.h:72
CP_EXPORT cpBB cpShapeCacheBB(cpShape *shape)
Update, cache and return the bounding box of a shape based on the body it's attached to.
CP_EXPORT cpFloat cpShapeGetMass(cpShape *shape)
Get the mass of the shape if you are having Chipmunk calculate mass properties for you.
static const cpShapeFilter CP_SHAPE_FILTER_NONE
Collision filter value for a shape that does not collide with anything.
Definition cpShape.h:68
CP_EXPORT void cpShapeSetCollisionType(cpShape *shape, cpCollisionType collisionType)
Get the collision type of this shape.
CP_EXPORT cpShapeFilter cpShapeGetFilter(const cpShape *shape)
Get the collision filtering parameters of this shape.
CP_EXPORT cpBody * cpShapeGetBody(const cpShape *shape)
The cpBody this shape is connected to.
CP_EXPORT cpVect cpShapeGetSurfaceVelocity(const cpShape *shape)
Get the surface velocity of this shape.
CP_EXPORT cpBB cpShapeUpdate(cpShape *shape, cpTransform transform)
Update, cache and return the bounding box of a shape with an explicit transformation.
CP_EXPORT cpDataPointer cpShapeGetUserData(const cpShape *shape)
Get the user definable data pointer of this shape.
CP_EXPORT cpFloat cpShapeGetArea(cpShape *shape)
Get the calculated area of this shape.
CP_EXPORT void cpShapeSetSensor(cpShape *shape, cpBool sensor)
Set if the shape is a sensor or not.
CP_EXPORT cpFloat cpShapeGetFriction(const cpShape *shape)
Get the friction of this shape.
CP_EXPORT cpCollisionType cpShapeGetCollisionType(const cpShape *shape)
Set the collision type of this shape.
CP_EXPORT cpFloat cpShapeGetDensity(cpShape *shape)
Get the density of the shape if you are having Chipmunk calculate mass properties for you.
static const cpShapeFilter CP_SHAPE_FILTER_ALL
Collision filter value for a shape that will collide with anything except CP_SHAPE_FILTER_NONE.
Definition cpShape.h:66
CP_EXPORT cpBool cpShapeSegmentQuery(const cpShape *shape, cpVect a, cpVect b, cpFloat radius, cpSegmentQueryInfo *info)
Perform a segment query against a shape. info must be a pointer to a valid cpSegmentQueryInfo structu...
CP_EXPORT void cpShapeSetFilter(cpShape *shape, cpShapeFilter filter)
Set the collision filtering parameters of this shape.
Chipmunk's axis-aligned 2D bounding box type. (left, bottom, right, top)
Definition cpBB.h:34
Definition chipmunk_structs.h:36
Definition chipmunk_structs.h:203
A struct that wraps up the important collision data for an arbiter.
Definition cpArbiter.h:88
Point query info struct.
Definition cpShape.h:28
cpVect gradient
The gradient of the signed distance function.
Definition cpShape.h:37
cpVect point
The closest point on the shape's surface. (in world space coordinates)
Definition cpShape.h:32
cpFloat distance
The distance to the point. The distance is negative if the point is inside the shape.
Definition cpShape.h:34
const cpShape * shape
The nearest shape, NULL if no shape was within range.
Definition cpShape.h:30
Segment query info struct.
Definition cpShape.h:41
const cpShape * shape
The shape that was hit, or NULL if no collision occured.
Definition cpShape.h:43
cpVect normal
The normal of the surface hit.
Definition cpShape.h:47
cpVect point
The point of impact.
Definition cpShape.h:45
cpFloat alpha
The normalized distance along the query segment in the range [0, 1].
Definition cpShape.h:49
Definition chipmunk_structs.h:210
Fast collision filtering type that is used to determine if two objects collide before calling collisi...
Definition cpShape.h:53
cpBitmask mask
A bitmask of user definable category types that this object object collides with.
Definition cpShape.h:62
cpGroup group
Two objects with the same non-zero group value do not collide.
Definition cpShape.h:56
cpBitmask categories
A bitmask of user definable categories that this object belongs to.
Definition cpShape.h:59
Definition chipmunk_structs.h:178
Definition chipmunk_structs.h:397
Column major affine transform.
Definition chipmunk_types.h:258
Definition chipmunk_types.h:251