1 | /**************************************************************************/ |
2 | /* godot_body_direct_state_3d.cpp */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #include "godot_body_direct_state_3d.h" |
32 | |
33 | #include "godot_body_3d.h" |
34 | #include "godot_space_3d.h" |
35 | |
36 | Vector3 GodotPhysicsDirectBodyState3D::get_total_gravity() const { |
37 | return body->gravity; |
38 | } |
39 | |
40 | real_t GodotPhysicsDirectBodyState3D::get_total_angular_damp() const { |
41 | return body->total_angular_damp; |
42 | } |
43 | |
44 | real_t GodotPhysicsDirectBodyState3D::get_total_linear_damp() const { |
45 | return body->total_linear_damp; |
46 | } |
47 | |
48 | Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass() const { |
49 | return body->get_center_of_mass(); |
50 | } |
51 | |
52 | Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass_local() const { |
53 | return body->get_center_of_mass_local(); |
54 | } |
55 | |
56 | Basis GodotPhysicsDirectBodyState3D::get_principal_inertia_axes() const { |
57 | return body->get_principal_inertia_axes(); |
58 | } |
59 | |
60 | real_t GodotPhysicsDirectBodyState3D::get_inverse_mass() const { |
61 | return body->get_inv_mass(); |
62 | } |
63 | |
64 | Vector3 GodotPhysicsDirectBodyState3D::get_inverse_inertia() const { |
65 | return body->get_inv_inertia(); |
66 | } |
67 | |
68 | Basis GodotPhysicsDirectBodyState3D::get_inverse_inertia_tensor() const { |
69 | return body->get_inv_inertia_tensor(); |
70 | } |
71 | |
72 | void GodotPhysicsDirectBodyState3D::set_linear_velocity(const Vector3 &p_velocity) { |
73 | body->wakeup(); |
74 | body->set_linear_velocity(p_velocity); |
75 | } |
76 | |
77 | Vector3 GodotPhysicsDirectBodyState3D::get_linear_velocity() const { |
78 | return body->get_linear_velocity(); |
79 | } |
80 | |
81 | void GodotPhysicsDirectBodyState3D::set_angular_velocity(const Vector3 &p_velocity) { |
82 | body->wakeup(); |
83 | body->set_angular_velocity(p_velocity); |
84 | } |
85 | |
86 | Vector3 GodotPhysicsDirectBodyState3D::get_angular_velocity() const { |
87 | return body->get_angular_velocity(); |
88 | } |
89 | |
90 | void GodotPhysicsDirectBodyState3D::set_transform(const Transform3D &p_transform) { |
91 | body->set_state(PhysicsServer3D::BODY_STATE_TRANSFORM, p_transform); |
92 | } |
93 | |
94 | Transform3D GodotPhysicsDirectBodyState3D::get_transform() const { |
95 | return body->get_transform(); |
96 | } |
97 | |
98 | Vector3 GodotPhysicsDirectBodyState3D::get_velocity_at_local_position(const Vector3 &p_position) const { |
99 | return body->get_velocity_in_local_point(p_position); |
100 | } |
101 | |
102 | void GodotPhysicsDirectBodyState3D::apply_central_impulse(const Vector3 &p_impulse) { |
103 | body->wakeup(); |
104 | body->apply_central_impulse(p_impulse); |
105 | } |
106 | |
107 | void GodotPhysicsDirectBodyState3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) { |
108 | body->wakeup(); |
109 | body->apply_impulse(p_impulse, p_position); |
110 | } |
111 | |
112 | void GodotPhysicsDirectBodyState3D::apply_torque_impulse(const Vector3 &p_impulse) { |
113 | body->wakeup(); |
114 | body->apply_torque_impulse(p_impulse); |
115 | } |
116 | |
117 | void GodotPhysicsDirectBodyState3D::apply_central_force(const Vector3 &p_force) { |
118 | body->wakeup(); |
119 | body->apply_central_force(p_force); |
120 | } |
121 | |
122 | void GodotPhysicsDirectBodyState3D::apply_force(const Vector3 &p_force, const Vector3 &p_position) { |
123 | body->wakeup(); |
124 | body->apply_force(p_force, p_position); |
125 | } |
126 | |
127 | void GodotPhysicsDirectBodyState3D::apply_torque(const Vector3 &p_torque) { |
128 | body->wakeup(); |
129 | body->apply_torque(p_torque); |
130 | } |
131 | |
132 | void GodotPhysicsDirectBodyState3D::add_constant_central_force(const Vector3 &p_force) { |
133 | body->wakeup(); |
134 | body->add_constant_central_force(p_force); |
135 | } |
136 | |
137 | void GodotPhysicsDirectBodyState3D::add_constant_force(const Vector3 &p_force, const Vector3 &p_position) { |
138 | body->wakeup(); |
139 | body->add_constant_force(p_force, p_position); |
140 | } |
141 | |
142 | void GodotPhysicsDirectBodyState3D::add_constant_torque(const Vector3 &p_torque) { |
143 | body->wakeup(); |
144 | body->add_constant_torque(p_torque); |
145 | } |
146 | |
147 | void GodotPhysicsDirectBodyState3D::set_constant_force(const Vector3 &p_force) { |
148 | if (!p_force.is_zero_approx()) { |
149 | body->wakeup(); |
150 | } |
151 | body->set_constant_force(p_force); |
152 | } |
153 | |
154 | Vector3 GodotPhysicsDirectBodyState3D::get_constant_force() const { |
155 | return body->get_constant_force(); |
156 | } |
157 | |
158 | void GodotPhysicsDirectBodyState3D::set_constant_torque(const Vector3 &p_torque) { |
159 | if (!p_torque.is_zero_approx()) { |
160 | body->wakeup(); |
161 | } |
162 | body->set_constant_torque(p_torque); |
163 | } |
164 | |
165 | Vector3 GodotPhysicsDirectBodyState3D::get_constant_torque() const { |
166 | return body->get_constant_torque(); |
167 | } |
168 | |
169 | void GodotPhysicsDirectBodyState3D::set_sleep_state(bool p_sleep) { |
170 | body->set_active(!p_sleep); |
171 | } |
172 | |
173 | bool GodotPhysicsDirectBodyState3D::is_sleeping() const { |
174 | return !body->is_active(); |
175 | } |
176 | |
177 | int GodotPhysicsDirectBodyState3D::get_contact_count() const { |
178 | return body->contact_count; |
179 | } |
180 | |
181 | Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_position(int p_contact_idx) const { |
182 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); |
183 | return body->contacts[p_contact_idx].local_pos; |
184 | } |
185 | |
186 | Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_normal(int p_contact_idx) const { |
187 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); |
188 | return body->contacts[p_contact_idx].local_normal; |
189 | } |
190 | |
191 | Vector3 GodotPhysicsDirectBodyState3D::get_contact_impulse(int p_contact_idx) const { |
192 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); |
193 | return body->contacts[p_contact_idx].impulse; |
194 | } |
195 | |
196 | Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_velocity_at_position(int p_contact_idx) const { |
197 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); |
198 | return body->contacts[p_contact_idx].local_velocity_at_pos; |
199 | } |
200 | |
201 | int GodotPhysicsDirectBodyState3D::get_contact_local_shape(int p_contact_idx) const { |
202 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, -1); |
203 | return body->contacts[p_contact_idx].local_shape; |
204 | } |
205 | |
206 | RID GodotPhysicsDirectBodyState3D::get_contact_collider(int p_contact_idx) const { |
207 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, RID()); |
208 | return body->contacts[p_contact_idx].collider; |
209 | } |
210 | |
211 | Vector3 GodotPhysicsDirectBodyState3D::get_contact_collider_position(int p_contact_idx) const { |
212 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); |
213 | return body->contacts[p_contact_idx].collider_pos; |
214 | } |
215 | |
216 | ObjectID GodotPhysicsDirectBodyState3D::get_contact_collider_id(int p_contact_idx) const { |
217 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, ObjectID()); |
218 | return body->contacts[p_contact_idx].collider_instance_id; |
219 | } |
220 | |
221 | int GodotPhysicsDirectBodyState3D::get_contact_collider_shape(int p_contact_idx) const { |
222 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0); |
223 | return body->contacts[p_contact_idx].collider_shape; |
224 | } |
225 | |
226 | Vector3 GodotPhysicsDirectBodyState3D::get_contact_collider_velocity_at_position(int p_contact_idx) const { |
227 | ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); |
228 | return body->contacts[p_contact_idx].collider_velocity_at_pos; |
229 | } |
230 | |
231 | PhysicsDirectSpaceState3D *GodotPhysicsDirectBodyState3D::get_space_state() { |
232 | return body->get_space()->get_direct_state(); |
233 | } |
234 | |
235 | real_t GodotPhysicsDirectBodyState3D::get_step() const { |
236 | return body->get_space()->get_last_step(); |
237 | } |
238 | |