Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/godot_physics_2d/godot_body_direct_state_2d.cpp
10277 views
1
/**************************************************************************/
2
/* godot_body_direct_state_2d.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_2d.h"
32
33
#include "godot_body_2d.h"
34
#include "godot_space_2d.h"
35
36
Vector2 GodotPhysicsDirectBodyState2D::get_total_gravity() const {
37
return body->gravity;
38
}
39
40
real_t GodotPhysicsDirectBodyState2D::get_total_angular_damp() const {
41
return body->total_angular_damp;
42
}
43
44
real_t GodotPhysicsDirectBodyState2D::get_total_linear_damp() const {
45
return body->total_linear_damp;
46
}
47
48
Vector2 GodotPhysicsDirectBodyState2D::get_center_of_mass() const {
49
return body->get_center_of_mass();
50
}
51
52
Vector2 GodotPhysicsDirectBodyState2D::get_center_of_mass_local() const {
53
return body->get_center_of_mass_local();
54
}
55
56
real_t GodotPhysicsDirectBodyState2D::get_inverse_mass() const {
57
return body->get_inv_mass();
58
}
59
60
real_t GodotPhysicsDirectBodyState2D::get_inverse_inertia() const {
61
return body->get_inv_inertia();
62
}
63
64
void GodotPhysicsDirectBodyState2D::set_linear_velocity(const Vector2 &p_velocity) {
65
body->wakeup();
66
body->set_linear_velocity(p_velocity);
67
}
68
69
Vector2 GodotPhysicsDirectBodyState2D::get_linear_velocity() const {
70
return body->get_linear_velocity();
71
}
72
73
void GodotPhysicsDirectBodyState2D::set_angular_velocity(real_t p_velocity) {
74
body->wakeup();
75
body->set_angular_velocity(p_velocity);
76
}
77
78
real_t GodotPhysicsDirectBodyState2D::get_angular_velocity() const {
79
return body->get_angular_velocity();
80
}
81
82
void GodotPhysicsDirectBodyState2D::set_transform(const Transform2D &p_transform) {
83
body->set_state(PhysicsServer2D::BODY_STATE_TRANSFORM, p_transform);
84
}
85
86
Transform2D GodotPhysicsDirectBodyState2D::get_transform() const {
87
return body->get_transform();
88
}
89
90
Vector2 GodotPhysicsDirectBodyState2D::get_velocity_at_local_position(const Vector2 &p_position) const {
91
return body->get_velocity_in_local_point(p_position);
92
}
93
94
void GodotPhysicsDirectBodyState2D::apply_central_impulse(const Vector2 &p_impulse) {
95
body->wakeup();
96
body->apply_central_impulse(p_impulse);
97
}
98
99
void GodotPhysicsDirectBodyState2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position) {
100
body->wakeup();
101
body->apply_impulse(p_impulse, p_position);
102
}
103
104
void GodotPhysicsDirectBodyState2D::apply_torque_impulse(real_t p_torque) {
105
body->wakeup();
106
body->apply_torque_impulse(p_torque);
107
}
108
109
void GodotPhysicsDirectBodyState2D::apply_central_force(const Vector2 &p_force) {
110
body->wakeup();
111
body->apply_central_force(p_force);
112
}
113
114
void GodotPhysicsDirectBodyState2D::apply_force(const Vector2 &p_force, const Vector2 &p_position) {
115
body->wakeup();
116
body->apply_force(p_force, p_position);
117
}
118
119
void GodotPhysicsDirectBodyState2D::apply_torque(real_t p_torque) {
120
body->wakeup();
121
body->apply_torque(p_torque);
122
}
123
124
void GodotPhysicsDirectBodyState2D::add_constant_central_force(const Vector2 &p_force) {
125
body->wakeup();
126
body->add_constant_central_force(p_force);
127
}
128
129
void GodotPhysicsDirectBodyState2D::add_constant_force(const Vector2 &p_force, const Vector2 &p_position) {
130
body->wakeup();
131
body->add_constant_force(p_force, p_position);
132
}
133
134
void GodotPhysicsDirectBodyState2D::add_constant_torque(real_t p_torque) {
135
body->wakeup();
136
body->add_constant_torque(p_torque);
137
}
138
139
void GodotPhysicsDirectBodyState2D::set_constant_force(const Vector2 &p_force) {
140
if (!p_force.is_zero_approx()) {
141
body->wakeup();
142
}
143
body->set_constant_force(p_force);
144
}
145
146
Vector2 GodotPhysicsDirectBodyState2D::get_constant_force() const {
147
return body->get_constant_force();
148
}
149
150
void GodotPhysicsDirectBodyState2D::set_constant_torque(real_t p_torque) {
151
if (!Math::is_zero_approx(p_torque)) {
152
body->wakeup();
153
}
154
body->set_constant_torque(p_torque);
155
}
156
157
real_t GodotPhysicsDirectBodyState2D::get_constant_torque() const {
158
return body->get_constant_torque();
159
}
160
161
void GodotPhysicsDirectBodyState2D::set_sleep_state(bool p_enable) {
162
body->set_active(!p_enable);
163
}
164
165
bool GodotPhysicsDirectBodyState2D::is_sleeping() const {
166
return !body->is_active();
167
}
168
169
void GodotPhysicsDirectBodyState2D::set_collision_layer(uint32_t p_layer) {
170
body->set_collision_layer(p_layer);
171
}
172
173
uint32_t GodotPhysicsDirectBodyState2D::get_collision_layer() const {
174
return body->get_collision_layer();
175
}
176
177
void GodotPhysicsDirectBodyState2D::set_collision_mask(uint32_t p_mask) {
178
body->set_collision_mask(p_mask);
179
}
180
181
uint32_t GodotPhysicsDirectBodyState2D::get_collision_mask() const {
182
return body->get_collision_mask();
183
}
184
185
int GodotPhysicsDirectBodyState2D::get_contact_count() const {
186
return body->contact_count;
187
}
188
189
Vector2 GodotPhysicsDirectBodyState2D::get_contact_local_position(int p_contact_idx) const {
190
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2());
191
return body->contacts[p_contact_idx].local_pos;
192
}
193
194
Vector2 GodotPhysicsDirectBodyState2D::get_contact_local_normal(int p_contact_idx) const {
195
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2());
196
return body->contacts[p_contact_idx].local_normal;
197
}
198
199
int GodotPhysicsDirectBodyState2D::get_contact_local_shape(int p_contact_idx) const {
200
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, -1);
201
return body->contacts[p_contact_idx].local_shape;
202
}
203
204
Vector2 GodotPhysicsDirectBodyState2D::get_contact_local_velocity_at_position(int p_contact_idx) const {
205
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2());
206
return body->contacts[p_contact_idx].local_velocity_at_pos;
207
}
208
209
RID GodotPhysicsDirectBodyState2D::get_contact_collider(int p_contact_idx) const {
210
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, RID());
211
return body->contacts[p_contact_idx].collider;
212
}
213
Vector2 GodotPhysicsDirectBodyState2D::get_contact_collider_position(int p_contact_idx) const {
214
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2());
215
return body->contacts[p_contact_idx].collider_pos;
216
}
217
218
ObjectID GodotPhysicsDirectBodyState2D::get_contact_collider_id(int p_contact_idx) const {
219
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, ObjectID());
220
return body->contacts[p_contact_idx].collider_instance_id;
221
}
222
223
int GodotPhysicsDirectBodyState2D::get_contact_collider_shape(int p_contact_idx) const {
224
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0);
225
return body->contacts[p_contact_idx].collider_shape;
226
}
227
228
Vector2 GodotPhysicsDirectBodyState2D::get_contact_collider_velocity_at_position(int p_contact_idx) const {
229
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2());
230
return body->contacts[p_contact_idx].collider_velocity_at_pos;
231
}
232
233
Vector2 GodotPhysicsDirectBodyState2D::get_contact_impulse(int p_contact_idx) const {
234
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2());
235
return body->contacts[p_contact_idx].impulse;
236
}
237
238
PhysicsDirectSpaceState2D *GodotPhysicsDirectBodyState2D::get_space_state() {
239
return body->get_space()->get_direct_state();
240
}
241
242
real_t GodotPhysicsDirectBodyState2D::get_step() const {
243
return body->get_space()->get_last_step();
244
}
245
246