[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-physics / third-party / chipmunk2d / include / chipmunk / cpArbiter.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 cpArbiter cpArbiter
23 /// The cpArbiter struct tracks pairs of colliding shapes.
24 /// They are also used in conjuction with collision handler callbacks
25 /// allowing you to retrieve information on the collision or change it.
26 /// A unique arbiter value is used for each pair of colliding objects. It persists until the shapes separate.
27 /// @{
28
29 #define CP_MAX_CONTACTS_PER_ARBITER 2
30
31 /// Get the restitution (elasticity) that will be applied to the pair of colliding objects.
32 CP_EXPORT cpFloat cpArbiterGetRestitution(const cpArbiter *arb);
33 /// Override the restitution (elasticity) that will be applied to the pair of colliding objects.
34 CP_EXPORT void cpArbiterSetRestitution(cpArbiter *arb, cpFloat restitution);
35 /// Get the friction coefficient that will be applied to the pair of colliding objects.
36 CP_EXPORT cpFloat cpArbiterGetFriction(const cpArbiter *arb);
37 /// Override the friction coefficient that will be applied to the pair of colliding objects.
38 CP_EXPORT void cpArbiterSetFriction(cpArbiter *arb, cpFloat friction);
39
40 // Get the relative surface velocity of the two shapes in contact.
41 CP_EXPORT cpVect cpArbiterGetSurfaceVelocity(cpArbiter *arb);
42
43 // Override the relative surface velocity of the two shapes in contact.
44 // By default this is calculated to be the difference of the two surface velocities clamped to the tangent plane.
45 CP_EXPORT void cpArbiterSetSurfaceVelocity(cpArbiter *arb, cpVect vr);
46
47 /// Get the user data pointer associated with this pair of colliding objects.
48 CP_EXPORT cpDataPointer cpArbiterGetUserData(const cpArbiter *arb);
49 /// Set a user data point associated with this pair of colliding objects.
50 /// If you need to perform any cleanup for this pointer, you must do it yourself, in the separate callback for instance.
51 CP_EXPORT void cpArbiterSetUserData(cpArbiter *arb, cpDataPointer userData);
52
53 /// Calculate the total impulse including the friction that was applied by this arbiter.
54 /// This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
55 CP_EXPORT cpVect cpArbiterTotalImpulse(const cpArbiter *arb);
56 /// Calculate the amount of energy lost in a collision including static, but not dynamic friction.
57 /// This function should only be called from a post-solve, post-step or cpBodyEachArbiter callback.
58 CP_EXPORT cpFloat cpArbiterTotalKE(const cpArbiter *arb);
59
60 /// Mark a collision pair to be ignored until the two objects separate.
61 /// Pre-solve and post-solve callbacks will not be called, but the separate callback will be called.
62 CP_EXPORT cpBool cpArbiterIgnore(cpArbiter *arb);
63
64 /// Return the colliding shapes involved for this arbiter.
65 /// The order of their cpSpace.collision_type values will match
66 /// the order set when the collision handler was registered.
67 CP_EXPORT void cpArbiterGetShapes(const cpArbiter *arb, cpShape **a, cpShape **b);
68
69 /// A macro shortcut for defining and retrieving the shapes from an arbiter.
70 #define CP_ARBITER_GET_SHAPES(__arb__, __a__, __b__) cpShape *__a__, *__b__; cpArbiterGetShapes(__arb__, &__a__, &__b__);
71
72 /// Return the colliding bodies involved for this arbiter.
73 /// The order of the cpSpace.collision_type the bodies are associated with values will match
74 /// the order set when the collision handler was registered.
75 CP_EXPORT void cpArbiterGetBodies(const cpArbiter *arb, cpBody **a, cpBody **b);
76
77 /// A macro shortcut for defining and retrieving the bodies from an arbiter.
78 #define CP_ARBITER_GET_BODIES(__arb__, __a__, __b__) cpBody *__a__, *__b__; cpArbiterGetBodies(__arb__, &__a__, &__b__);
79
80 /// A struct that wraps up the important collision data for an arbiter.
81 struct cpContactPointSet {
82         /// The number of contact points in the set.
83         int count;
84         
85         /// The normal of the collision.
86         cpVect normal;
87         
88         /// The array of contact points.
89         struct {
90                 /// The position of the contact on the surface of each shape.
91                 cpVect pointA, pointB;
92                 /// Penetration distance of the two shapes. Overlapping means it will be negative.
93                 /// This value is calculated as cpvdot(cpvsub(point2, point1), normal) and is ignored by cpArbiterSetContactPointSet().
94                 cpFloat distance;
95         } points[CP_MAX_CONTACTS_PER_ARBITER];
96 };
97
98 /// Return a contact set from an arbiter.
99 CP_EXPORT cpContactPointSet cpArbiterGetContactPointSet(const cpArbiter *arb);
100
101 /// Replace the contact point set for an arbiter.
102 /// This can be a very powerful feature, but use it with caution!
103 CP_EXPORT void cpArbiterSetContactPointSet(cpArbiter *arb, cpContactPointSet *set);
104
105 /// Returns true if this is the first step a pair of objects started colliding.
106 CP_EXPORT cpBool cpArbiterIsFirstContact(const cpArbiter *arb);
107 /// Returns true if the separate callback is due to a shape being removed from the space.
108 CP_EXPORT cpBool cpArbiterIsRemoval(const cpArbiter *arb);
109
110 /// Get the number of contact points for this arbiter.
111 CP_EXPORT int cpArbiterGetCount(const cpArbiter *arb);
112 /// Get the normal of the collision.
113 CP_EXPORT cpVect cpArbiterGetNormal(const cpArbiter *arb);
114 /// Get the position of the @c ith contact point on the surface of the first shape.
115 CP_EXPORT cpVect cpArbiterGetPointA(const cpArbiter *arb, int i);
116 /// Get the position of the @c ith contact point on the surface of the second shape.
117 CP_EXPORT cpVect cpArbiterGetPointB(const cpArbiter *arb, int i);
118 /// Get the depth of the @c ith contact point.
119 CP_EXPORT cpFloat cpArbiterGetDepth(const cpArbiter *arb, int i);
120
121 /// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
122 /// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
123 CP_EXPORT cpBool cpArbiterCallWildcardBeginA(cpArbiter *arb, cpSpace *space);
124 /// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
125 /// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
126 CP_EXPORT cpBool cpArbiterCallWildcardBeginB(cpArbiter *arb, cpSpace *space);
127
128 /// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
129 /// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
130 CP_EXPORT cpBool cpArbiterCallWildcardPreSolveA(cpArbiter *arb, cpSpace *space);
131 /// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
132 /// You must decide how to handle the wildcard's return value since it may disagree with the other wildcard handler's return value or your own.
133 CP_EXPORT cpBool cpArbiterCallWildcardPreSolveB(cpArbiter *arb, cpSpace *space);
134
135 /// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
136 CP_EXPORT void cpArbiterCallWildcardPostSolveA(cpArbiter *arb, cpSpace *space);
137 /// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
138 CP_EXPORT void cpArbiterCallWildcardPostSolveB(cpArbiter *arb, cpSpace *space);
139
140 /// If you want a custom callback to invoke the wildcard callback for the first collision type, you must call this function explicitly.
141 CP_EXPORT void cpArbiterCallWildcardSeparateA(cpArbiter *arb, cpSpace *space);
142 /// If you want a custom callback to invoke the wildcard callback for the second collision type, you must call this function explicitly.
143 CP_EXPORT void cpArbiterCallWildcardSeparateB(cpArbiter *arb, cpSpace *space);
144
145 /// @}