Munk2D Documentation  8.x.x
Loading...
Searching...
No Matches
cpBody.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
28
43
45typedef void (*cpBodyVelocityFunc)(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
47typedef void (*cpBodyPositionFunc)(cpBody *body, cpFloat dt);
48
50CP_EXPORT cpBody* cpBodyAlloc(void);
52CP_EXPORT cpBody* cpBodyInit(cpBody *body, cpFloat mass, cpFloat moment);
54CP_EXPORT cpBody* cpBodyNew(cpFloat mass, cpFloat moment);
55
57CP_EXPORT cpBody* cpBodyNewKinematic(void);
59CP_EXPORT cpBody* cpBodyNewStatic(void);
60
62CP_EXPORT void cpBodyDestroy(cpBody *body);
64CP_EXPORT void cpBodyFree(cpBody *body);
65
66// Defined in cpSpace.c
68CP_EXPORT void cpBodyActivate(cpBody *body);
70CP_EXPORT void cpBodyActivateStatic(cpBody *body, cpShape *filter);
71
73CP_EXPORT void cpBodySleep(cpBody *body);
75CP_EXPORT void cpBodySleepWithGroup(cpBody *body, cpBody *group);
76
78CP_EXPORT cpBool cpBodyIsSleeping(const cpBody *body);
79
83CP_EXPORT void cpBodySetType(cpBody *body, cpBodyType type);
84
86CP_EXPORT cpSpace* cpBodyGetSpace(const cpBody *body);
87
89CP_EXPORT cpFloat cpBodyGetMass(const cpBody *body);
91CP_EXPORT void cpBodySetMass(cpBody *body, cpFloat m);
92
94CP_EXPORT cpFloat cpBodyGetMoment(const cpBody *body);
96CP_EXPORT void cpBodySetMoment(cpBody *body, cpFloat i);
97
99CP_EXPORT cpVect cpBodyGetPosition(const cpBody *body);
101CP_EXPORT void cpBodySetPosition(cpBody *body, cpVect pos);
102
106CP_EXPORT void cpBodySetCenterOfGravity(cpBody *body, cpVect cog);
107
109CP_EXPORT cpVect cpBodyGetVelocity(const cpBody *body);
111CP_EXPORT void cpBodySetVelocity(cpBody *body, cpVect velocity);
112
114CP_EXPORT cpVect cpBodyGetForce(const cpBody *body);
116CP_EXPORT void cpBodySetForce(cpBody *body, cpVect force);
117
119CP_EXPORT cpFloat cpBodyGetAngle(const cpBody *body);
121CP_EXPORT void cpBodySetAngle(cpBody *body, cpFloat a);
122
126CP_EXPORT void cpBodySetAngularVelocity(cpBody *body, cpFloat angularVelocity);
127
129CP_EXPORT cpFloat cpBodyGetTorque(const cpBody *body);
131CP_EXPORT void cpBodySetTorque(cpBody *body, cpFloat torque);
132
134CP_EXPORT cpVect cpBodyGetRotation(const cpBody *body);
135
139CP_EXPORT void cpBodySetUserData(cpBody *body, cpDataPointer userData);
140
142CP_EXPORT void cpBodySetVelocityUpdateFunc(cpBody *body, cpBodyVelocityFunc velocityFunc);
145CP_EXPORT void cpBodySetPositionUpdateFunc(cpBody *body, cpBodyPositionFunc positionFunc);
146
148CP_EXPORT void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
150CP_EXPORT void cpBodyUpdatePosition(cpBody *body, cpFloat dt);
151
153CP_EXPORT cpVect cpBodyLocalToWorld(const cpBody *body, const cpVect point);
155CP_EXPORT cpVect cpBodyWorldToLocal(const cpBody *body, const cpVect point);
156
158CP_EXPORT void cpBodyApplyForceAtWorldPoint(cpBody *body, cpVect force, cpVect point);
160CP_EXPORT void cpBodyApplyForceAtLocalPoint(cpBody *body, cpVect force, cpVect point);
161
163CP_EXPORT void cpBodyApplyImpulseAtWorldPoint(cpBody *body, cpVect impulse, cpVect point);
165CP_EXPORT void cpBodyApplyImpulseAtLocalPoint(cpBody *body, cpVect impulse, cpVect point);
166
168CP_EXPORT cpVect cpBodyGetVelocityAtWorldPoint(const cpBody *body, cpVect point);
170CP_EXPORT cpVect cpBodyGetVelocityAtLocalPoint(const cpBody *body, cpVect point);
171
173CP_EXPORT cpFloat cpBodyKineticEnergy(const cpBody *body);
174
176typedef void (*cpBodyShapeIteratorFunc)(cpBody *body, cpShape *shape, void *data);
178CP_EXPORT void cpBodyEachShape(cpBody *body, cpBodyShapeIteratorFunc func, void *data);
179
181typedef void (*cpBodyConstraintIteratorFunc)(cpBody *body, cpConstraint *constraint, void *data);
183CP_EXPORT void cpBodyEachConstraint(cpBody *body, cpBodyConstraintIteratorFunc func, void *data);
184
186typedef void (*cpBodyArbiterIteratorFunc)(cpBody *body, cpArbiter *arbiter, void *data);
188CP_EXPORT void cpBodyEachArbiter(cpBody *body, cpBodyArbiterIteratorFunc func, void *data);
189
void * cpDataPointer
Type used for user data pointers.
Definition chipmunk_types.h:196
unsigned char cpBool
Chipmunk's boolean type.
Definition chipmunk_types.h:179
double cpFloat
Chipmunk's floating point type.
Definition chipmunk_types.h:68
CP_EXPORT cpVect cpBodyGetRotation(const cpBody *body)
Get the rotation vector of the body. (The x basis vector of it's transform.)
CP_EXPORT void cpBodySetType(cpBody *body, cpBodyType type)
Set the type of the body.
CP_EXPORT void cpBodyApplyImpulseAtLocalPoint(cpBody *body, cpVect impulse, cpVect point)
Apply an impulse to a body. Both the impulse and point are expressed in body local coordinates.
CP_EXPORT void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
Default velocity integration function..
CP_EXPORT void cpBodyEachArbiter(cpBody *body, cpBodyArbiterIteratorFunc func, void *data)
Call func once for each arbiter that is currently active on the body.
CP_EXPORT cpVect cpBodyWorldToLocal(const cpBody *body, const cpVect point)
Convert body absolute/world coordinates to relative/local coordinates.
CP_EXPORT cpFloat cpBodyGetMass(const cpBody *body)
Get the mass of the body.
CP_EXPORT cpBool cpBodyIsSleeping(const cpBody *body)
Returns true if the body is sleeping.
CP_EXPORT void cpBodyUpdatePosition(cpBody *body, cpFloat dt)
Default position integration function.
CP_EXPORT cpBody * cpBodyNewKinematic(void)
Allocate and initialize a cpBody, and set it as a kinematic body.
CP_EXPORT void cpBodyActivate(cpBody *body)
Wake up a sleeping or idle body.
CP_EXPORT void cpBodyApplyImpulseAtWorldPoint(cpBody *body, cpVect impulse, cpVect point)
Apply an impulse to a body. Both the impulse and point are expressed in world coordinates.
CP_EXPORT cpVect cpBodyGetCenterOfGravity(const cpBody *body)
Get the offset of the center of gravity in body local coordinates.
void(* cpBodyPositionFunc)(cpBody *body, cpFloat dt)
Rigid body position update function type.
Definition cpBody.h:47
CP_EXPORT void cpBodyApplyForceAtLocalPoint(cpBody *body, cpVect force, cpVect point)
Apply a force to a body. Both the force and point are expressed in body local coordinates.
cpBodyType
Definition cpBody.h:29
CP_EXPORT cpVect cpBodyLocalToWorld(const cpBody *body, const cpVect point)
Convert body relative/local coordinates to absolute/world coordinates.
CP_EXPORT void cpBodySetForce(cpBody *body, cpVect force)
Set the force applied to the body for the next time step.
CP_EXPORT void cpBodyEachShape(cpBody *body, cpBodyShapeIteratorFunc func, void *data)
Call func once for each shape attached to body and added to the space.
CP_EXPORT cpVect cpBodyGetVelocityAtLocalPoint(const cpBody *body, cpVect point)
Get the velocity on a body (in world units) at a point on the body in local coordinates.
CP_EXPORT cpBody * cpBodyInit(cpBody *body, cpFloat mass, cpFloat moment)
Initialize a cpBody.
CP_EXPORT cpFloat cpBodyGetAngularVelocity(const cpBody *body)
Get the angular velocity of the body.
CP_EXPORT cpFloat cpBodyGetTorque(const cpBody *body)
Get the torque applied to the body for the next time step.
CP_EXPORT void cpBodySetCenterOfGravity(cpBody *body, cpVect cog)
Set the offset of the center of gravity in body local coordinates.
CP_EXPORT cpVect cpBodyGetForce(const cpBody *body)
Get the force applied to the body for the next time step.
void(* cpBodyConstraintIteratorFunc)(cpBody *body, cpConstraint *constraint, void *data)
Body/constraint iterator callback function type.
Definition cpBody.h:181
CP_EXPORT void cpBodyApplyForceAtWorldPoint(cpBody *body, cpVect force, cpVect point)
Apply a force to a body. Both the force and point are expressed in world coordinates.
CP_EXPORT void cpBodySetPosition(cpBody *body, cpVect pos)
Set the position of the body.
CP_EXPORT cpFloat cpBodyKineticEnergy(const cpBody *body)
Get the amount of kinetic energy contained by the body.
CP_EXPORT void cpBodySetPositionUpdateFunc(cpBody *body, cpBodyPositionFunc positionFunc)
Set the callback used to update a body's position.
void(* cpBodyVelocityFunc)(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
Rigid body velocity update function type.
Definition cpBody.h:45
CP_EXPORT void cpBodySleepWithGroup(cpBody *body, cpBody *group)
Force a body to fall asleep immediately along with other bodies in a group.
CP_EXPORT cpBodyType cpBodyGetType(cpBody *body)
Get the type of the body.
CP_EXPORT void cpBodySetUserData(cpBody *body, cpDataPointer userData)
Set the user data pointer assigned to the body.
CP_EXPORT void cpBodySetMoment(cpBody *body, cpFloat i)
Set the moment of inertia of the body.
CP_EXPORT void cpBodyActivateStatic(cpBody *body, cpShape *filter)
Wake up any sleeping or idle bodies touching a static body.
CP_EXPORT cpBody * cpBodyAlloc(void)
Allocate a cpBody.
CP_EXPORT cpVect cpBodyGetVelocityAtWorldPoint(const cpBody *body, cpVect point)
Get the velocity on a body (in world units) at a point on the body in world coordinates.
void(* cpBodyArbiterIteratorFunc)(cpBody *body, cpArbiter *arbiter, void *data)
Body/arbiter iterator callback function type.
Definition cpBody.h:186
CP_EXPORT void cpBodyFree(cpBody *body)
Destroy and free a cpBody.
CP_EXPORT void cpBodySetMass(cpBody *body, cpFloat m)
Set the mass of the body.
void(* cpBodyShapeIteratorFunc)(cpBody *body, cpShape *shape, void *data)
Body/shape iterator callback function type.
Definition cpBody.h:176
CP_EXPORT void cpBodySetAngularVelocity(cpBody *body, cpFloat angularVelocity)
Set the angular velocity of the body.
CP_EXPORT void cpBodySetAngle(cpBody *body, cpFloat a)
Set the angle of a body.
CP_EXPORT void cpBodySetVelocity(cpBody *body, cpVect velocity)
Set the velocity of the body.
CP_EXPORT void cpBodySleep(cpBody *body)
Force a body to fall asleep immediately.
CP_EXPORT void cpBodyDestroy(cpBody *body)
Destroy a cpBody.
CP_EXPORT cpBody * cpBodyNewStatic(void)
Allocate and initialize a cpBody, and set it as a static body.
CP_EXPORT cpVect cpBodyGetVelocity(const cpBody *body)
Get the velocity of the body.
CP_EXPORT cpBody * cpBodyNew(cpFloat mass, cpFloat moment)
Allocate and initialize a cpBody.
CP_EXPORT cpFloat cpBodyGetMoment(const cpBody *body)
Get the moment of inertia of the body.
CP_EXPORT void cpBodySetTorque(cpBody *body, cpFloat torque)
Set the torque applied to the body for the next time step.
CP_EXPORT void cpBodyEachConstraint(cpBody *body, cpBodyConstraintIteratorFunc func, void *data)
Call func once for each constraint attached to body and added to the space.
CP_EXPORT cpFloat cpBodyGetAngle(const cpBody *body)
Get the angle of the body.
CP_EXPORT cpDataPointer cpBodyGetUserData(const cpBody *body)
Get the user data pointer assigned to the body.
CP_EXPORT cpVect cpBodyGetPosition(const cpBody *body)
Set the position of a body.
CP_EXPORT void cpBodySetVelocityUpdateFunc(cpBody *body, cpBodyVelocityFunc velocityFunc)
Set the callback used to update a body's velocity.
CP_EXPORT cpSpace * cpBodyGetSpace(const cpBody *body)
Get the space this body is added to.
@ CP_BODY_TYPE_DYNAMIC
A dynamic body is one that is affected by gravity, forces, and collisions.
Definition cpBody.h:32
@ CP_BODY_TYPE_KINEMATIC
A kinematic body is an infinite mass, user controlled body that is not affected by gravity,...
Definition cpBody.h:37
@ CP_BODY_TYPE_STATIC
A static body is a body that never (or rarely) moves.
Definition cpBody.h:41
Definition chipmunk_structs.h:124
Definition chipmunk_structs.h:36
Definition chipmunk_structs.h:251
Definition chipmunk_structs.h:178
Definition chipmunk_structs.h:397
Definition chipmunk_types.h:251