2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* godot_body_direct_state_3d.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2021-06-05 01:09:41 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
#include "godot_body_direct_state_3d.h"
|
2021-06-05 01:09:41 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
#include "godot_body_3d.h"
|
|
|
|
#include "godot_space_3d.h"
|
2021-06-05 01:09:41 +02:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_total_gravity() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->gravity;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
real_t GodotPhysicsDirectBodyState3D::get_total_angular_damp() const {
|
2020-04-14 19:59:53 +02:00
|
|
|
return body->total_angular_damp;
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
real_t GodotPhysicsDirectBodyState3D::get_total_linear_damp() const {
|
2020-04-14 19:59:53 +02:00
|
|
|
return body->total_linear_damp;
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_center_of_mass();
|
|
|
|
}
|
|
|
|
|
2021-10-22 20:56:00 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_center_of_mass_local() const {
|
|
|
|
return body->get_center_of_mass_local();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Basis GodotPhysicsDirectBodyState3D::get_principal_inertia_axes() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_principal_inertia_axes();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
real_t GodotPhysicsDirectBodyState3D::get_inverse_mass() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_inv_mass();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_inverse_inertia() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_inv_inertia();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Basis GodotPhysicsDirectBodyState3D::get_inverse_inertia_tensor() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_inv_inertia_tensor();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
void GodotPhysicsDirectBodyState3D::set_linear_velocity(const Vector3 &p_velocity) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-06-05 01:09:41 +02:00
|
|
|
body->set_linear_velocity(p_velocity);
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_linear_velocity() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_linear_velocity();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
void GodotPhysicsDirectBodyState3D::set_angular_velocity(const Vector3 &p_velocity) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-06-05 01:09:41 +02:00
|
|
|
body->set_angular_velocity(p_velocity);
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_angular_velocity() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_angular_velocity();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
void GodotPhysicsDirectBodyState3D::set_transform(const Transform3D &p_transform) {
|
2021-06-05 01:09:41 +02:00
|
|
|
body->set_state(PhysicsServer3D::BODY_STATE_TRANSFORM, p_transform);
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Transform3D GodotPhysicsDirectBodyState3D::get_transform() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_transform();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_velocity_at_local_position(const Vector3 &p_position) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_velocity_in_local_point(p_position);
|
|
|
|
}
|
|
|
|
|
2021-12-08 02:09:54 +01:00
|
|
|
void GodotPhysicsDirectBodyState3D::apply_central_impulse(const Vector3 &p_impulse) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-12-08 02:09:54 +01:00
|
|
|
body->apply_central_impulse(p_impulse);
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-08 02:09:54 +01:00
|
|
|
void GodotPhysicsDirectBodyState3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-12-08 02:09:54 +01:00
|
|
|
body->apply_impulse(p_impulse, p_position);
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-08 02:09:54 +01:00
|
|
|
void GodotPhysicsDirectBodyState3D::apply_torque_impulse(const Vector3 &p_impulse) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-12-08 02:09:54 +01:00
|
|
|
body->apply_torque_impulse(p_impulse);
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-08 02:09:54 +01:00
|
|
|
void GodotPhysicsDirectBodyState3D::apply_central_force(const Vector3 &p_force) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-12-08 02:09:54 +01:00
|
|
|
body->apply_central_force(p_force);
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-08 02:09:54 +01:00
|
|
|
void GodotPhysicsDirectBodyState3D::apply_force(const Vector3 &p_force, const Vector3 &p_position) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-12-08 02:09:54 +01:00
|
|
|
body->apply_force(p_force, p_position);
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-08 02:09:54 +01:00
|
|
|
void GodotPhysicsDirectBodyState3D::apply_torque(const Vector3 &p_torque) {
|
2021-10-03 20:57:26 +02:00
|
|
|
body->wakeup();
|
2021-12-08 02:09:54 +01:00
|
|
|
body->apply_torque(p_torque);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotPhysicsDirectBodyState3D::add_constant_central_force(const Vector3 &p_force) {
|
|
|
|
body->wakeup();
|
|
|
|
body->add_constant_central_force(p_force);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotPhysicsDirectBodyState3D::add_constant_force(const Vector3 &p_force, const Vector3 &p_position) {
|
|
|
|
body->wakeup();
|
|
|
|
body->add_constant_force(p_force, p_position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotPhysicsDirectBodyState3D::add_constant_torque(const Vector3 &p_torque) {
|
|
|
|
body->wakeup();
|
|
|
|
body->add_constant_torque(p_torque);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotPhysicsDirectBodyState3D::set_constant_force(const Vector3 &p_force) {
|
2022-09-02 02:32:33 +02:00
|
|
|
if (!p_force.is_zero_approx()) {
|
2021-12-08 02:09:54 +01:00
|
|
|
body->wakeup();
|
|
|
|
}
|
|
|
|
body->set_constant_force(p_force);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_constant_force() const {
|
|
|
|
return body->get_constant_force();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotPhysicsDirectBodyState3D::set_constant_torque(const Vector3 &p_torque) {
|
2022-09-02 02:32:33 +02:00
|
|
|
if (!p_torque.is_zero_approx()) {
|
2021-12-08 02:09:54 +01:00
|
|
|
body->wakeup();
|
|
|
|
}
|
|
|
|
body->set_constant_torque(p_torque);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_constant_torque() const {
|
|
|
|
return body->get_constant_torque();
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
void GodotPhysicsDirectBodyState3D::set_sleep_state(bool p_sleep) {
|
2021-06-05 01:09:41 +02:00
|
|
|
body->set_active(!p_sleep);
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
bool GodotPhysicsDirectBodyState3D::is_sleeping() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return !body->is_active();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
int GodotPhysicsDirectBodyState3D::get_contact_count() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->contact_count;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_position(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
|
|
|
|
return body->contacts[p_contact_idx].local_pos;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_normal(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
|
|
|
|
return body->contacts[p_contact_idx].local_normal;
|
|
|
|
}
|
|
|
|
|
2023-01-08 04:34:28 +01:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_contact_impulse(int p_contact_idx) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
|
|
|
|
return body->contacts[p_contact_idx].impulse;
|
2021-06-05 01:09:41 +02:00
|
|
|
}
|
|
|
|
|
2022-03-07 19:07:46 +01:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_contact_local_velocity_at_position(int p_contact_idx) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
|
|
|
|
return body->contacts[p_contact_idx].local_velocity_at_pos;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
int GodotPhysicsDirectBodyState3D::get_contact_local_shape(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, -1);
|
|
|
|
return body->contacts[p_contact_idx].local_shape;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
RID GodotPhysicsDirectBodyState3D::get_contact_collider(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, RID());
|
|
|
|
return body->contacts[p_contact_idx].collider;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_contact_collider_position(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
|
|
|
|
return body->contacts[p_contact_idx].collider_pos;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
ObjectID GodotPhysicsDirectBodyState3D::get_contact_collider_id(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, ObjectID());
|
|
|
|
return body->contacts[p_contact_idx].collider_instance_id;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
int GodotPhysicsDirectBodyState3D::get_contact_collider_shape(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0);
|
|
|
|
return body->contacts[p_contact_idx].collider_shape;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
Vector3 GodotPhysicsDirectBodyState3D::get_contact_collider_velocity_at_position(int p_contact_idx) const {
|
2021-06-05 01:09:41 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3());
|
|
|
|
return body->contacts[p_contact_idx].collider_velocity_at_pos;
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
PhysicsDirectSpaceState3D *GodotPhysicsDirectBodyState3D::get_space_state() {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_space()->get_direct_state();
|
|
|
|
}
|
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
real_t GodotPhysicsDirectBodyState3D::get_step() const {
|
2021-06-05 01:09:41 +02:00
|
|
|
return body->get_space()->get_last_step();
|
|
|
|
}
|