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
36Vector3 GodotPhysicsDirectBodyState3D::get_total_gravity() const {
37 return body->gravity;
38}
39
40real_t GodotPhysicsDirectBodyState3D::get_total_angular_damp() const {
41 return body->total_angular_damp;
42}
43
44real_t GodotPhysicsDirectBodyState3D::get_total_linear_damp() const {
45 return body->total_linear_damp;
46}
47
48Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass() const {
49 return body->get_center_of_mass();
50}
51
52Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass_local() const {
53 return body->get_center_of_mass_local();
54}
55
56Basis GodotPhysicsDirectBodyState3D::get_principal_inertia_axes() const {
57 return body->get_principal_inertia_axes();
58}
59
60real_t GodotPhysicsDirectBodyState3D::get_inverse_mass() const {
61 return body->get_inv_mass();
62}
63
64Vector3 GodotPhysicsDirectBodyState3D::get_inverse_inertia() const {
65 return body->get_inv_inertia();
66}
67
68Basis GodotPhysicsDirectBodyState3D::get_inverse_inertia_tensor() const {
69 return body->get_inv_inertia_tensor();
70}
71
72void GodotPhysicsDirectBodyState3D::set_linear_velocity(const Vector3 &p_velocity) {
73 body->wakeup();
74 body->set_linear_velocity(p_velocity);
75}
76
77Vector3 GodotPhysicsDirectBodyState3D::get_linear_velocity() const {
78 return body->get_linear_velocity();
79}
80
81void GodotPhysicsDirectBodyState3D::set_angular_velocity(const Vector3 &p_velocity) {
82 body->wakeup();
83 body->set_angular_velocity(p_velocity);
84}
85
86Vector3 GodotPhysicsDirectBodyState3D::get_angular_velocity() const {
87 return body->get_angular_velocity();
88}
89
90void GodotPhysicsDirectBodyState3D::set_transform(const Transform3D &p_transform) {
91 body->set_state(PhysicsServer3D::BODY_STATE_TRANSFORM, p_transform);
92}
93
94Transform3D GodotPhysicsDirectBodyState3D::get_transform() const {
95 return body->get_transform();
96}
97
98Vector3 GodotPhysicsDirectBodyState3D::get_velocity_at_local_position(const Vector3 &p_position) const {
99 return body->get_velocity_in_local_point(p_position);
100}
101
102void GodotPhysicsDirectBodyState3D::apply_central_impulse(const Vector3 &p_impulse) {
103 body->wakeup();
104 body->apply_central_impulse(p_impulse);
105}
106
107void GodotPhysicsDirectBodyState3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
108 body->wakeup();
109 body->apply_impulse(p_impulse, p_position);
110}
111
112void GodotPhysicsDirectBodyState3D::apply_torque_impulse(const Vector3 &p_impulse) {
113 body->wakeup();
114 body->apply_torque_impulse(p_impulse);
115}
116
117void GodotPhysicsDirectBodyState3D::apply_central_force(const Vector3 &p_force) {
118 body->wakeup();
119 body->apply_central_force(p_force);
120}
121
122void GodotPhysicsDirectBodyState3D::apply_force(const Vector3 &p_force, const Vector3 &p_position) {
123 body->wakeup();
124 body->apply_force(p_force, p_position);
125}
126
127void GodotPhysicsDirectBodyState3D::apply_torque(const Vector3 &p_torque) {
128 body->wakeup();
129 body->apply_torque(p_torque);
130}
131
132void GodotPhysicsDirectBodyState3D::add_constant_central_force(const Vector3 &p_force) {
133 body->wakeup();
134 body->add_constant_central_force(p_force);
135}
136
137void 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
142void GodotPhysicsDirectBodyState3D::add_constant_torque(const Vector3 &p_torque) {
143 body->wakeup();
144 body->add_constant_torque(p_torque);
145}
146
147void 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
154Vector3 GodotPhysicsDirectBodyState3D::get_constant_force() const {
155 return body->get_constant_force();
156}
157
158void 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
165Vector3 GodotPhysicsDirectBodyState3D::get_constant_torque() const {
166 return body->get_constant_torque();
167}
168
169void GodotPhysicsDirectBodyState3D::set_sleep_state(bool p_sleep) {
170 body->set_active(!p_sleep);
171}
172
173bool GodotPhysicsDirectBodyState3D::is_sleeping() const {
174 return !body->is_active();
175}
176
177int GodotPhysicsDirectBodyState3D::get_contact_count() const {
178 return body->contact_count;
179}
180
181Vector3 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
186Vector3 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
191Vector3 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
196Vector3 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
201int 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
206RID 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
211Vector3 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
216ObjectID 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
221int 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
226Vector3 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
231PhysicsDirectSpaceState3D *GodotPhysicsDirectBodyState3D::get_space_state() {
232 return body->get_space()->get_direct_state();
233}
234
235real_t GodotPhysicsDirectBodyState3D::get_step() const {
236 return body->get_space()->get_last_step();
237}
238