Add Bullet and Chipmunk to dali-toolkit
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / chipmunk2d / include / chipmunk / cpShape.h
1 /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
2  * 
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  * 
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  * 
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19  * SOFTWARE.
20  */
21
22 /// @defgroup cpShape cpShape
23 /// The cpShape struct defines the shape of a rigid body.
24 /// @{
25
26 /// Point query info struct.
27 typedef struct cpPointQueryInfo {
28         /// The nearest shape, NULL if no shape was within range.
29         const cpShape *shape;
30         /// The closest point on the shape's surface. (in world space coordinates)
31         cpVect point;
32         /// The distance to the point. The distance is negative if the point is inside the shape.
33         cpFloat distance;
34         /// The gradient of the signed distance function.
35         /// The value should be similar to info.p/info.d, but accurate even for very small values of info.d.
36         cpVect gradient;
37 } cpPointQueryInfo;
38
39 /// Segment query info struct.
40 typedef struct cpSegmentQueryInfo {
41         /// The shape that was hit, or NULL if no collision occured.
42         const cpShape *shape;
43         /// The point of impact.
44         cpVect point;
45         /// The normal of the surface hit.
46         cpVect normal;
47         /// The normalized distance along the query segment in the range [0, 1].
48         cpFloat alpha;
49 } cpSegmentQueryInfo;
50
51 /// Fast collision filtering type that is used to determine if two objects collide before calling collision or query callbacks.
52 typedef struct cpShapeFilter {
53         /// Two objects with the same non-zero group value do not collide.
54         /// This is generally used to group objects in a composite object together to disable self collisions.
55         cpGroup group;
56         /// A bitmask of user definable categories that this object belongs to.
57         /// The category/mask combinations of both objects in a collision must agree for a collision to occur.
58         cpBitmask categories;
59         /// A bitmask of user definable category types that this object object collides with.
60         /// The category/mask combinations of both objects in a collision must agree for a collision to occur.
61         cpBitmask mask;
62 } cpShapeFilter;
63
64 /// Collision filter value for a shape that will collide with anything except CP_SHAPE_FILTER_NONE.
65 static const cpShapeFilter CP_SHAPE_FILTER_ALL = {CP_NO_GROUP, CP_ALL_CATEGORIES, CP_ALL_CATEGORIES};
66 /// Collision filter value for a shape that does not collide with anything.
67 static const cpShapeFilter CP_SHAPE_FILTER_NONE = {CP_NO_GROUP, ~CP_ALL_CATEGORIES, ~CP_ALL_CATEGORIES};
68
69 /// Create a new collision filter.
70 static inline cpShapeFilter
71 cpShapeFilterNew(cpGroup group, cpBitmask categories, cpBitmask mask)
72 {
73         cpShapeFilter filter = {group, categories, mask};
74         return filter;
75 }
76
77 /// Destroy a shape.
78 CP_EXPORT void cpShapeDestroy(cpShape *shape);
79 /// Destroy and Free a shape.
80 CP_EXPORT void cpShapeFree(cpShape *shape);
81
82 /// Update, cache and return the bounding box of a shape based on the body it's attached to.
83 CP_EXPORT cpBB cpShapeCacheBB(cpShape *shape);
84 /// Update, cache and return the bounding box of a shape with an explicit transformation.
85 CP_EXPORT cpBB cpShapeUpdate(cpShape *shape, cpTransform transform);
86
87 /// Perform a nearest point query. It finds the closest point on the surface of shape to a specific point.
88 /// The value returned is the distance between the points. A negative distance means the point is inside the shape.
89 CP_EXPORT cpFloat cpShapePointQuery(const cpShape *shape, cpVect p, cpPointQueryInfo *out);
90
91 /// Perform a segment query against a shape. @c info must be a pointer to a valid cpSegmentQueryInfo structure.
92 CP_EXPORT cpBool cpShapeSegmentQuery(const cpShape *shape, cpVect a, cpVect b, cpFloat radius, cpSegmentQueryInfo *info);
93
94 /// Return contact information about two shapes.
95 CP_EXPORT cpContactPointSet cpShapesCollide(const cpShape *a, const cpShape *b);
96
97 /// The cpSpace this body is added to.
98 CP_EXPORT cpSpace* cpShapeGetSpace(const cpShape *shape);
99
100 /// The cpBody this shape is connected to.
101 CP_EXPORT cpBody* cpShapeGetBody(const cpShape *shape);
102 /// Set the cpBody this shape is connected to.
103 /// Can only be used if the shape is not currently added to a space.
104 CP_EXPORT void cpShapeSetBody(cpShape *shape, cpBody *body);
105
106 /// Get the mass of the shape if you are having Chipmunk calculate mass properties for you.
107 CP_EXPORT cpFloat cpShapeGetMass(cpShape *shape);
108 /// Set the mass of this shape to have Chipmunk calculate mass properties for you.
109 CP_EXPORT void cpShapeSetMass(cpShape *shape, cpFloat mass);
110
111 /// Get the density of the shape if you are having Chipmunk calculate mass properties for you.
112 CP_EXPORT cpFloat cpShapeGetDensity(cpShape *shape);
113 /// Set the density  of this shape to have Chipmunk calculate mass properties for you.
114 CP_EXPORT void cpShapeSetDensity(cpShape *shape, cpFloat density);
115
116 /// Get the calculated moment of inertia for this shape.
117 CP_EXPORT cpFloat cpShapeGetMoment(cpShape *shape);
118 /// Get the calculated area of this shape.
119 CP_EXPORT cpFloat cpShapeGetArea(cpShape *shape);
120 /// Get the centroid of this shape.
121 CP_EXPORT cpVect cpShapeGetCenterOfGravity(cpShape *shape);
122
123 /// Get the bounding box that contains the shape given it's current position and angle.
124 CP_EXPORT cpBB cpShapeGetBB(const cpShape *shape);
125
126 /// Get if the shape is set to be a sensor or not.
127 CP_EXPORT cpBool cpShapeGetSensor(const cpShape *shape);
128 /// Set if the shape is a sensor or not.
129 CP_EXPORT void cpShapeSetSensor(cpShape *shape, cpBool sensor);
130
131 /// Get the elasticity of this shape.
132 CP_EXPORT cpFloat cpShapeGetElasticity(const cpShape *shape);
133 /// Set the elasticity of this shape.
134 CP_EXPORT void cpShapeSetElasticity(cpShape *shape, cpFloat elasticity);
135
136 /// Get the friction of this shape.
137 CP_EXPORT cpFloat cpShapeGetFriction(const cpShape *shape);
138 /// Set the friction of this shape.
139 CP_EXPORT void cpShapeSetFriction(cpShape *shape, cpFloat friction);
140
141 /// Get the surface velocity of this shape.
142 CP_EXPORT cpVect cpShapeGetSurfaceVelocity(const cpShape *shape);
143 /// Set the surface velocity of this shape.
144 CP_EXPORT void cpShapeSetSurfaceVelocity(cpShape *shape, cpVect surfaceVelocity);
145
146 /// Get the user definable data pointer of this shape.
147 CP_EXPORT cpDataPointer cpShapeGetUserData(const cpShape *shape);
148 /// Set the user definable data pointer of this shape.
149 CP_EXPORT void cpShapeSetUserData(cpShape *shape, cpDataPointer userData);
150
151 /// Set the collision type of this shape.
152 CP_EXPORT cpCollisionType cpShapeGetCollisionType(const cpShape *shape);
153 /// Get the collision type of this shape.
154 CP_EXPORT void cpShapeSetCollisionType(cpShape *shape, cpCollisionType collisionType);
155
156 /// Get the collision filtering parameters of this shape.
157 CP_EXPORT cpShapeFilter cpShapeGetFilter(const cpShape *shape);
158 /// Set the collision filtering parameters of this shape.
159 CP_EXPORT void cpShapeSetFilter(cpShape *shape, cpShapeFilter filter);
160
161
162 /// @}
163 /// @defgroup cpCircleShape cpCircleShape
164
165 /// Allocate a circle shape.
166 CP_EXPORT cpCircleShape* cpCircleShapeAlloc(void);
167 /// Initialize a circle shape.
168 CP_EXPORT cpCircleShape* cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
169 /// Allocate and initialize a circle shape.
170 CP_EXPORT cpShape* cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
171
172 /// Get the offset of a circle shape.
173 CP_EXPORT cpVect cpCircleShapeGetOffset(const cpShape *shape);
174 /// Get the radius of a circle shape.
175 CP_EXPORT cpFloat cpCircleShapeGetRadius(const cpShape *shape);
176
177 /// @}
178 /// @defgroup cpSegmentShape cpSegmentShape
179
180 /// Allocate a segment shape.
181 CP_EXPORT cpSegmentShape* cpSegmentShapeAlloc(void);
182 /// Initialize a segment shape.
183 CP_EXPORT cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius);
184 /// Allocate and initialize a segment shape.
185 CP_EXPORT cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
186
187 /// Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.
188 CP_EXPORT void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next);
189
190 /// Get the first endpoint of a segment shape.
191 CP_EXPORT cpVect cpSegmentShapeGetA(const cpShape *shape);
192 /// Get the second endpoint of a segment shape.
193 CP_EXPORT cpVect cpSegmentShapeGetB(const cpShape *shape);
194 /// Get the normal of a segment shape.
195 CP_EXPORT cpVect cpSegmentShapeGetNormal(const cpShape *shape);
196 /// Get the first endpoint of a segment shape.
197 CP_EXPORT cpFloat cpSegmentShapeGetRadius(const cpShape *shape);
198
199 /// @}