[dali_2.3.21] Merge branch 'devel/master'
[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 /// Get the hash ID of the shape
83 CP_EXPORT cpHashValue cpShapeGetHashId(cpShape* shape);
84
85 /// Update, cache and return the bounding box of a shape based on the body it's attached to.
86 CP_EXPORT cpBB cpShapeCacheBB(cpShape *shape);
87 /// Update, cache and return the bounding box of a shape with an explicit transformation.
88 CP_EXPORT cpBB cpShapeUpdate(cpShape *shape, cpTransform transform);
89
90 /// Perform a nearest point query. It finds the closest point on the surface of shape to a specific point.
91 /// The value returned is the distance between the points. A negative distance means the point is inside the shape.
92 CP_EXPORT cpFloat cpShapePointQuery(const cpShape *shape, cpVect p, cpPointQueryInfo *out);
93
94 /// Perform a segment query against a shape. @c info must be a pointer to a valid cpSegmentQueryInfo structure.
95 CP_EXPORT cpBool cpShapeSegmentQuery(const cpShape *shape, cpVect a, cpVect b, cpFloat radius, cpSegmentQueryInfo *info);
96
97 /// Return contact information about two shapes.
98 CP_EXPORT cpContactPointSet cpShapesCollide(const cpShape *a, const cpShape *b);
99
100 /// The cpSpace this body is added to.
101 CP_EXPORT cpSpace* cpShapeGetSpace(const cpShape *shape);
102
103 /// The cpBody this shape is connected to.
104 CP_EXPORT cpBody* cpShapeGetBody(const cpShape *shape);
105 /// Set the cpBody this shape is connected to.
106 /// Can only be used if the shape is not currently added to a space.
107 CP_EXPORT void cpShapeSetBody(cpShape *shape, cpBody *body);
108
109 /// Get the mass of the shape if you are having Chipmunk calculate mass properties for you.
110 CP_EXPORT cpFloat cpShapeGetMass(cpShape *shape);
111 /// Set the mass of this shape to have Chipmunk calculate mass properties for you.
112 CP_EXPORT void cpShapeSetMass(cpShape *shape, cpFloat mass);
113
114 /// Get the density of the shape if you are having Chipmunk calculate mass properties for you.
115 CP_EXPORT cpFloat cpShapeGetDensity(cpShape *shape);
116 /// Set the density  of this shape to have Chipmunk calculate mass properties for you.
117 CP_EXPORT void cpShapeSetDensity(cpShape *shape, cpFloat density);
118
119 /// Get the calculated moment of inertia for this shape.
120 CP_EXPORT cpFloat cpShapeGetMoment(cpShape *shape);
121 /// Get the calculated area of this shape.
122 CP_EXPORT cpFloat cpShapeGetArea(cpShape *shape);
123 /// Get the centroid of this shape.
124 CP_EXPORT cpVect cpShapeGetCenterOfGravity(cpShape *shape);
125
126 /// Get the bounding box that contains the shape given it's current position and angle.
127 CP_EXPORT cpBB cpShapeGetBB(const cpShape *shape);
128
129 /// Get if the shape is set to be a sensor or not.
130 CP_EXPORT cpBool cpShapeGetSensor(const cpShape *shape);
131 /// Set if the shape is a sensor or not.
132 CP_EXPORT void cpShapeSetSensor(cpShape *shape, cpBool sensor);
133
134 /// Get the elasticity of this shape.
135 CP_EXPORT cpFloat cpShapeGetElasticity(const cpShape *shape);
136 /// Set the elasticity of this shape.
137 CP_EXPORT void cpShapeSetElasticity(cpShape *shape, cpFloat elasticity);
138
139 /// Get the friction of this shape.
140 CP_EXPORT cpFloat cpShapeGetFriction(const cpShape *shape);
141 /// Set the friction of this shape.
142 CP_EXPORT void cpShapeSetFriction(cpShape *shape, cpFloat friction);
143
144 /// Get the surface velocity of this shape.
145 CP_EXPORT cpVect cpShapeGetSurfaceVelocity(const cpShape *shape);
146 /// Set the surface velocity of this shape.
147 CP_EXPORT void cpShapeSetSurfaceVelocity(cpShape *shape, cpVect surfaceVelocity);
148
149 /// Get the user definable data pointer of this shape.
150 CP_EXPORT cpDataPointer cpShapeGetUserData(const cpShape *shape);
151 /// Set the user definable data pointer of this shape.
152 CP_EXPORT void cpShapeSetUserData(cpShape *shape, cpDataPointer userData);
153
154 /// Set the collision type of this shape.
155 CP_EXPORT cpCollisionType cpShapeGetCollisionType(const cpShape *shape);
156 /// Get the collision type of this shape.
157 CP_EXPORT void cpShapeSetCollisionType(cpShape *shape, cpCollisionType collisionType);
158
159 /// Get the collision filtering parameters of this shape.
160 CP_EXPORT cpShapeFilter cpShapeGetFilter(const cpShape *shape);
161 /// Set the collision filtering parameters of this shape.
162 CP_EXPORT void cpShapeSetFilter(cpShape *shape, cpShapeFilter filter);
163
164
165 /// @}
166 /// @defgroup cpCircleShape cpCircleShape
167
168 /// Allocate a circle shape.
169 CP_EXPORT cpCircleShape* cpCircleShapeAlloc(void);
170 /// Initialize a circle shape.
171 CP_EXPORT cpCircleShape* cpCircleShapeInit(cpCircleShape *circle, cpBody *body, cpFloat radius, cpVect offset);
172 /// Allocate and initialize a circle shape.
173 CP_EXPORT cpShape* cpCircleShapeNew(cpBody *body, cpFloat radius, cpVect offset);
174
175 /// Get the offset of a circle shape.
176 CP_EXPORT cpVect cpCircleShapeGetOffset(const cpShape *shape);
177 /// Get the radius of a circle shape.
178 CP_EXPORT cpFloat cpCircleShapeGetRadius(const cpShape *shape);
179
180 /// @}
181 /// @defgroup cpSegmentShape cpSegmentShape
182
183 /// Allocate a segment shape.
184 CP_EXPORT cpSegmentShape* cpSegmentShapeAlloc(void);
185 /// Initialize a segment shape.
186 CP_EXPORT cpSegmentShape* cpSegmentShapeInit(cpSegmentShape *seg, cpBody *body, cpVect a, cpVect b, cpFloat radius);
187 /// Allocate and initialize a segment shape.
188 CP_EXPORT cpShape* cpSegmentShapeNew(cpBody *body, cpVect a, cpVect b, cpFloat radius);
189
190 /// Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.
191 CP_EXPORT void cpSegmentShapeSetNeighbors(cpShape *shape, cpVect prev, cpVect next);
192
193 /// Get the first endpoint of a segment shape.
194 CP_EXPORT cpVect cpSegmentShapeGetA(const cpShape *shape);
195 /// Get the second endpoint of a segment shape.
196 CP_EXPORT cpVect cpSegmentShapeGetB(const cpShape *shape);
197 /// Get the normal of a segment shape.
198 CP_EXPORT cpVect cpSegmentShapeGetNormal(const cpShape *shape);
199 /// Get the first endpoint of a segment shape.
200 CP_EXPORT cpFloat cpSegmentShapeGetRadius(const cpShape *shape);
201
202 /// @}