1 | /** |
2 | * Copyright (c) 2006-2023 LOVE Development Team |
3 | * |
4 | * This software is provided 'as-is', without any express or implied |
5 | * warranty. In no event will the authors be held liable for any damages |
6 | * arising from the use of this software. |
7 | * |
8 | * Permission is granted to anyone to use this software for any purpose, |
9 | * including commercial applications, and to alter it and redistribute it |
10 | * freely, subject to the following restrictions: |
11 | * |
12 | * 1. The origin of this software must not be misrepresented; you must not |
13 | * claim that you wrote the original software. If you use this software |
14 | * in a product, an acknowledgment in the product documentation would be |
15 | * appreciated but is not required. |
16 | * 2. Altered source versions must be plainly marked as such, and must not be |
17 | * misrepresented as being the original software. |
18 | * 3. This notice may not be removed or altered from any source distribution. |
19 | **/ |
20 | |
21 | #ifndef LOVE_PHYSICS_BOX2D_CONTACT_H |
22 | #define LOVE_PHYSICS_BOX2D_CONTACT_H |
23 | |
24 | // LOVE |
25 | #include "common/Object.h" |
26 | #include "common/runtime.h" |
27 | #include "World.h" |
28 | |
29 | // Box2D |
30 | #include <Box2D/Box2D.h> |
31 | |
32 | namespace love |
33 | { |
34 | namespace physics |
35 | { |
36 | namespace box2d |
37 | { |
38 | |
39 | class World; |
40 | |
41 | /** |
42 | * A Contact represents a collision point between |
43 | * two shapes. |
44 | **/ |
45 | class Contact : public Object |
46 | { |
47 | public: |
48 | // Friends. |
49 | friend class World; |
50 | friend class World::ContactCallback; |
51 | |
52 | static love::Type type; |
53 | |
54 | /** |
55 | * Creates a new Contact by copying a Box2D contact |
56 | * point. It does not store the pointer, but copy the |
57 | * data pointed to. |
58 | * @param contact Pointer to the Box2D contact. |
59 | **/ |
60 | Contact(World *world, b2Contact *contact); |
61 | |
62 | virtual ~Contact(); |
63 | |
64 | /** |
65 | * Removes the b2Contact pointer from Memoizer and sets it |
66 | * to null on the Contact. |
67 | **/ |
68 | void invalidate(); |
69 | |
70 | /** |
71 | * Returns if the Contact still points to a valid b2Contact. |
72 | * @return True if the contact is still valid or false if it has been destroyed. |
73 | **/ |
74 | bool isValid(); |
75 | |
76 | /** |
77 | * Gets the position of each point of contact. |
78 | * @return The position along the x-axis. |
79 | * @return The position along the y-axis. |
80 | **/ |
81 | int getPositions(lua_State *L); |
82 | |
83 | /** |
84 | * Gets the collision normal. |
85 | * @return The x-component of the normal. |
86 | * @return The y-component of the normal. |
87 | **/ |
88 | int getNormal(lua_State *L); |
89 | |
90 | /** |
91 | * The mixed friction between the two fixtures at |
92 | * the point of impact. |
93 | **/ |
94 | float getFriction() const; |
95 | |
96 | /** |
97 | * The mixed restitution of the two fixtures |
98 | * at the point of impact. |
99 | **/ |
100 | float getRestitution() const; |
101 | |
102 | /** |
103 | * Check if the contact is enabled. |
104 | **/ |
105 | bool isEnabled() const; |
106 | |
107 | /** |
108 | * Check if the contact is touching. |
109 | **/ |
110 | bool isTouching() const; |
111 | |
112 | // Only call the setters in PreSolve |
113 | |
114 | /** |
115 | * Override the default friction mixture. |
116 | **/ |
117 | void setFriction(float friction); |
118 | |
119 | /** |
120 | * Override the default restitution mixture. |
121 | **/ |
122 | void setRestitution(float restitution); |
123 | |
124 | /** |
125 | * Enable/disable this contact. |
126 | **/ |
127 | void setEnabled(bool enabled); |
128 | |
129 | /** |
130 | * Reset the friction mixture to the default |
131 | * value. |
132 | **/ |
133 | void resetFriction(); |
134 | |
135 | /** |
136 | * Reset the restitution mixture to the default |
137 | * value. |
138 | **/ |
139 | void resetRestitution(); |
140 | |
141 | /** |
142 | * Set the desired tangent speed. |
143 | **/ |
144 | void setTangentSpeed(float speed); |
145 | |
146 | /** |
147 | * Get the desired tangent speed. |
148 | **/ |
149 | float getTangentSpeed() const; |
150 | |
151 | void getChildren(int &childA, int &childB); |
152 | |
153 | /** |
154 | * Gets the Fixtures associated with this Contact. |
155 | **/ |
156 | void getFixtures(Fixture *&fixtureA, Fixture *&fixtureB); |
157 | |
158 | private: |
159 | |
160 | // The Box2D contact. |
161 | b2Contact *contact; |
162 | |
163 | World *world; |
164 | }; |
165 | |
166 | } // box2d |
167 | } // physics |
168 | } // love |
169 | |
170 | #endif // LOVE_PHYSICS_BOX2D_CONTACT_H |
171 | |