2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* physics_server_sw.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "physics_server_sw.h"
|
|
|
|
#include "broad_phase_basic.h"
|
|
|
|
#include "broad_phase_octree.h"
|
2014-09-15 16:33:30 +02:00
|
|
|
#include "joints/cone_twist_joint_sw.h"
|
|
|
|
#include "joints/generic_6dof_joint_sw.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "joints/hinge_joint_sw.h"
|
|
|
|
#include "joints/pin_joint_sw.h"
|
|
|
|
#include "joints/slider_joint_sw.h"
|
2016-05-22 02:18:16 +02:00
|
|
|
#include "os/os.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "script_language.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
RID PhysicsServerSW::shape_create(ShapeType p_shape) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ShapeSW *shape = NULL;
|
|
|
|
switch (p_shape) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
case SHAPE_PLANE: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(PlaneShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_RAY: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(RayShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_SPHERE: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(SphereShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_BOX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(BoxShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_CAPSULE: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(CapsuleShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_CONVEX_POLYGON: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(ConvexPolygonShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_CONCAVE_POLYGON: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(ConcavePolygonShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_HEIGHTMAP: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shape = memnew(HeightMapShapeSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case SHAPE_CUSTOM: {
|
|
|
|
|
|
|
|
ERR_FAIL_V(RID());
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID id = shape_owner.make_rid(shape);
|
|
|
|
shape->set_self(id);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::shape_set_data(RID p_shape, const Variant &p_data) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ShapeSW *shape = shape_owner.get(p_shape);
|
|
|
|
ERR_FAIL_COND(!shape);
|
|
|
|
shape->set_data(p_data);
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::shape_set_custom_solver_bias(RID p_shape, real_t p_bias) {
|
|
|
|
|
|
|
|
ShapeSW *shape = shape_owner.get(p_shape);
|
|
|
|
ERR_FAIL_COND(!shape);
|
|
|
|
shape->set_custom_bias(p_bias);
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsServer::ShapeType PhysicsServerSW::shape_get_type(RID p_shape) const {
|
|
|
|
|
|
|
|
const ShapeSW *shape = shape_owner.get(p_shape);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!shape, SHAPE_CUSTOM);
|
2014-02-10 02:10:30 +01:00
|
|
|
return shape->get_type();
|
|
|
|
};
|
|
|
|
|
|
|
|
Variant PhysicsServerSW::shape_get_data(RID p_shape) const {
|
|
|
|
|
|
|
|
const ShapeSW *shape = shape_owner.get(p_shape);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!shape, Variant());
|
|
|
|
ERR_FAIL_COND_V(!shape->is_configured(), Variant());
|
2014-02-10 02:10:30 +01:00
|
|
|
return shape->get_data();
|
|
|
|
};
|
|
|
|
|
|
|
|
real_t PhysicsServerSW::shape_get_custom_solver_bias(RID p_shape) const {
|
|
|
|
|
|
|
|
const ShapeSW *shape = shape_owner.get(p_shape);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!shape, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
return shape->get_custom_bias();
|
|
|
|
}
|
|
|
|
|
|
|
|
RID PhysicsServerSW::space_create() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = memnew(SpaceSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
RID id = space_owner.make_rid(space);
|
|
|
|
space->set_self(id);
|
|
|
|
RID area_id = area_create();
|
|
|
|
AreaSW *area = area_owner.get(area_id);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
space->set_default_area(area);
|
|
|
|
area->set_space(space);
|
|
|
|
area->set_priority(-1);
|
2014-09-15 16:33:30 +02:00
|
|
|
RID sgb = body_create();
|
2017-03-05 16:44:50 +01:00
|
|
|
body_set_space(sgb, id);
|
|
|
|
body_set_mode(sgb, BODY_MODE_STATIC);
|
2014-09-15 16:33:30 +02:00
|
|
|
space->set_static_global_body(sgb);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return id;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::space_set_active(RID p_space, bool p_active) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
SpaceSW *space = space_owner.get(p_space);
|
|
|
|
ERR_FAIL_COND(!space);
|
|
|
|
if (p_active)
|
|
|
|
active_spaces.insert(space);
|
|
|
|
else
|
|
|
|
active_spaces.erase(space);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsServerSW::space_is_active(RID p_space) const {
|
|
|
|
|
|
|
|
const SpaceSW *space = space_owner.get(p_space);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!space, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return active_spaces.has(space);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
SpaceSW *space = space_owner.get(p_space);
|
|
|
|
ERR_FAIL_COND(!space);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
space->set_param(p_param, p_value);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t PhysicsServerSW::space_get_param(RID p_space, SpaceParameter p_param) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
const SpaceSW *space = space_owner.get(p_space);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!space, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
return space->get_param(p_param);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PhysicsDirectSpaceState *PhysicsServerSW::space_get_direct_state(RID p_space) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
SpaceSW *space = space_owner.get(p_space);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!space, NULL);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!doing_sync || space->is_locked()) {
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Space state is inaccesible right now, wait for iteration or fixed process notification.");
|
|
|
|
ERR_FAIL_V(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return space->get_direct_state();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::space_set_debug_contacts(RID p_space, int p_max_contacts) {
|
2015-09-20 18:03:46 +02:00
|
|
|
|
|
|
|
SpaceSW *space = space_owner.get(p_space);
|
|
|
|
ERR_FAIL_COND(!space);
|
|
|
|
space->set_debug_contacts(p_max_contacts);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Vector3> PhysicsServerSW::space_get_contacts(RID p_space) const {
|
|
|
|
|
|
|
|
SpaceSW *space = space_owner.get(p_space);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!space, Vector<Vector3>());
|
2015-09-20 18:03:46 +02:00
|
|
|
return space->get_debug_contacts();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PhysicsServerSW::space_get_contact_count(RID p_space) const {
|
|
|
|
|
|
|
|
SpaceSW *space = space_owner.get(p_space);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!space, 0);
|
2015-09-20 18:03:46 +02:00
|
|
|
return space->get_debug_contact_count();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
RID PhysicsServerSW::area_create() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
AreaSW *area = memnew(AreaSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
RID rid = area_owner.make_rid(area);
|
|
|
|
area->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::area_set_space(RID p_area, RID p_space) {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (p_space.is_valid()) {
|
|
|
|
space = space_owner.get(p_space);
|
|
|
|
ERR_FAIL_COND(!space);
|
|
|
|
}
|
|
|
|
|
|
|
|
area->set_space(space);
|
|
|
|
};
|
|
|
|
|
|
|
|
RID PhysicsServerSW::area_get_space(RID p_area) const {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
SpaceSW *space = area->get_space();
|
|
|
|
if (!space)
|
|
|
|
return RID();
|
|
|
|
return space->get_self();
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
area->set_space_override_mode(p_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsServer::AreaSpaceOverrideMode PhysicsServerSW::area_get_space_override_mode(RID p_area) const {
|
|
|
|
|
|
|
|
const AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, AREA_SPACE_OVERRIDE_DISABLED);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return area->get_space_override_mode();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_add_shape(RID p_area, RID p_shape, const Transform &p_transform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
ShapeSW *shape = shape_owner.get(p_shape);
|
|
|
|
ERR_FAIL_COND(!shape);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
area->add_shape(shape, p_transform);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_shape(RID p_area, int p_shape_idx, RID p_shape) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
ShapeSW *shape = shape_owner.get(p_shape);
|
|
|
|
ERR_FAIL_COND(!shape);
|
|
|
|
ERR_FAIL_COND(!shape->is_configured());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
area->set_shape(p_shape_idx, shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
area->set_shape_transform(p_shape_idx, p_transform);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int PhysicsServerSW::area_get_shape_count(RID p_area) const {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, -1);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return area->get_shape_count();
|
|
|
|
}
|
|
|
|
RID PhysicsServerSW::area_get_shape(RID p_area, int p_shape_idx) const {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ShapeSW *shape = area->get_shape(p_shape_idx);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!shape, RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return shape->get_self();
|
|
|
|
}
|
|
|
|
Transform PhysicsServerSW::area_get_shape_transform(RID p_area, int p_shape_idx) const {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, Transform());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return area->get_shape_transform(p_shape_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsServerSW::area_remove_shape(RID p_area, int p_shape_idx) {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
area->remove_shape(p_shape_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsServerSW::area_clear_shapes(RID p_area) {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (area->get_shape_count())
|
2014-02-10 02:10:30 +01:00
|
|
|
area->remove_shape(0);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_attach_object_instance_ID(RID p_area, ObjectID p_ID) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (space_owner.owns(p_area)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = space_owner.get(p_area);
|
|
|
|
p_area = space->get_default_area()->get_self();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
area->set_instance_id(p_ID);
|
|
|
|
}
|
|
|
|
ObjectID PhysicsServerSW::area_get_object_instance_ID(RID p_area) const {
|
|
|
|
|
|
|
|
if (space_owner.owns(p_area)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = space_owner.get(p_area);
|
|
|
|
p_area = space->get_default_area()->get_self();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
return area->get_instance_id();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (space_owner.owns(p_area)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = space_owner.get(p_area);
|
|
|
|
p_area = space->get_default_area()->get_self();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
2017-03-05 16:44:50 +01:00
|
|
|
area->set_param(p_param, p_value);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_transform(RID p_area, const Transform &p_transform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
area->set_transform(p_transform);
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant PhysicsServerSW::area_get_param(RID p_area, AreaParameter p_param) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (space_owner.owns(p_area)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = space_owner.get(p_area);
|
|
|
|
p_area = space->get_default_area()->get_self();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, Variant());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return area->get_param(p_param);
|
|
|
|
};
|
|
|
|
|
|
|
|
Transform PhysicsServerSW::area_get_transform(RID p_area) const {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, Transform());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return area->get_transform();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_layer_mask(RID p_area, uint32_t p_mask) {
|
2016-04-09 20:54:09 +02:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
area->set_layer_mask(p_mask);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_collision_mask(RID p_area, uint32_t p_mask) {
|
2016-04-09 20:54:09 +02:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
area->set_collision_mask(p_mask);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_monitorable(RID p_area, bool p_monitorable) {
|
2015-06-12 20:52:21 +02:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
area->set_monitorable(p_monitorable);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
area->set_monitor_callback(p_receiver ? p_receiver->get_instance_ID() : 0, p_method);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_ray_pickable(RID p_area, bool p_enable) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
|
|
|
area->set_ray_pickable(p_enable);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool PhysicsServerSW::area_is_ray_pickable(RID p_area) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!area, false);
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
return area->is_ray_pickable();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) {
|
2015-06-12 20:52:21 +02:00
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_area);
|
|
|
|
ERR_FAIL_COND(!area);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
area->set_area_monitor_callback(p_receiver ? p_receiver->get_instance_ID() : 0, p_method);
|
2015-06-12 20:52:21 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/* BODY API */
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID PhysicsServerSW::body_create(BodyMode p_mode, bool p_init_sleeping) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BodySW *body = memnew(BodySW);
|
|
|
|
if (p_mode != BODY_MODE_RIGID)
|
2014-02-10 02:10:30 +01:00
|
|
|
body->set_mode(p_mode);
|
|
|
|
if (p_init_sleeping)
|
2017-03-05 16:44:50 +01:00
|
|
|
body->set_state(BODY_STATE_SLEEPING, p_init_sleeping);
|
2014-02-10 02:10:30 +01:00
|
|
|
RID rid = body_owner.make_rid(body);
|
|
|
|
body->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_set_space(RID p_body, RID p_space) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (p_space.is_valid()) {
|
|
|
|
space = space_owner.get(p_space);
|
|
|
|
ERR_FAIL_COND(!space);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (body->get_space() == space)
|
2014-02-10 02:10:30 +01:00
|
|
|
return; //pointles
|
|
|
|
|
|
|
|
body->set_space(space);
|
|
|
|
};
|
|
|
|
|
|
|
|
RID PhysicsServerSW::body_get_space(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
SpaceSW *space = body->get_space();
|
|
|
|
if (!space)
|
|
|
|
return RID();
|
|
|
|
return space->get_self();
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_set_mode(RID p_body, BodyMode p_mode) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_mode(p_mode);
|
|
|
|
};
|
|
|
|
|
2015-12-28 01:32:12 +01:00
|
|
|
PhysicsServer::BodyMode PhysicsServerSW::body_get_mode(RID p_body) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, BODY_MODE_STATIC);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->get_mode();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
ShapeSW *shape = shape_owner.get(p_shape);
|
|
|
|
ERR_FAIL_COND(!shape);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
body->add_shape(shape, p_transform);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_shape(RID p_body, int p_shape_idx, RID p_shape) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
ShapeSW *shape = shape_owner.get(p_shape);
|
|
|
|
ERR_FAIL_COND(!shape);
|
|
|
|
ERR_FAIL_COND(!shape->is_configured());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
body->set_shape(p_shape_idx, shape);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
body->set_shape_transform(p_shape_idx, p_transform);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int PhysicsServerSW::body_get_shape_count(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, -1);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->get_shape_count();
|
|
|
|
}
|
|
|
|
RID PhysicsServerSW::body_get_shape(RID p_body, int p_shape_idx) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
ShapeSW *shape = body->get_shape(p_shape_idx);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!shape, RID());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return shape->get_self();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_shape_as_trigger(RID p_body, int p_shape_idx, bool p_enable) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count());
|
|
|
|
body->set_shape_as_trigger(p_shape_idx, p_enable);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool PhysicsServerSW::body_is_shape_set_as_trigger(RID p_body, int p_shape_idx) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, false);
|
|
|
|
ERR_FAIL_INDEX_V(p_shape_idx, body->get_shape_count(), false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-05-06 00:41:41 +02:00
|
|
|
return body->is_shape_set_as_trigger(p_shape_idx);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Transform PhysicsServerSW::body_get_shape_transform(RID p_body, int p_shape_idx) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, Transform());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->get_shape_transform(p_shape_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_remove_shape(RID p_body, int p_shape_idx) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->remove_shape(p_shape_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_clear_shapes(RID p_body) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (body->get_shape_count())
|
2014-02-10 02:10:30 +01:00
|
|
|
body->remove_shape(0);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_continuous_collision_detection(p_enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PhysicsServerSW::body_is_continuous_collision_detection_enabled(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->is_continuous_collision_detection_enabled();
|
|
|
|
}
|
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
void PhysicsServerSW::body_set_layer_mask(RID p_body, uint32_t p_mask) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_layer_mask(p_mask);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-09-03 04:13:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t PhysicsServerSW::body_get_layer_mask(RID p_body, uint32_t p_mask) const {
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
const BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, 0);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
return body->get_layer_mask();
|
|
|
|
}
|
|
|
|
|
2016-04-09 20:54:09 +02:00
|
|
|
void PhysicsServerSW::body_set_collision_mask(RID p_body, uint32_t p_mask) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_collision_mask(p_mask);
|
|
|
|
body->wakeup();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t PhysicsServerSW::body_get_collision_mask(RID p_body, uint32_t p_mask) const {
|
2016-04-09 20:54:09 +02:00
|
|
|
|
|
|
|
const BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, 0);
|
2016-04-09 20:54:09 +02:00
|
|
|
|
|
|
|
return body->get_collision_mask();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_attach_object_instance_ID(RID p_body, uint32_t p_ID) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_instance_id(p_ID);
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t PhysicsServerSW::body_get_object_instance_ID(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->get_instance_id();
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_set_user_flags(RID p_body, uint32_t p_flags) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t PhysicsServerSW::body_get_user_flags(RID p_body, uint32_t p_flags) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
void PhysicsServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
body->set_param(p_param, p_value);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t PhysicsServerSW::body_get_param(RID p_body, BodyParameter p_param) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->get_param(p_param);
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
body->set_state(p_state, p_variant);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Variant PhysicsServerSW::body_get_state(RID p_body, BodyState p_state) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, Variant());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->get_state(p_state);
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_applied_force(RID p_body, const Vector3 &p_force) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_applied_force(p_force);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector3 PhysicsServerSW::body_get_applied_force(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, Vector3());
|
2014-02-10 02:10:30 +01:00
|
|
|
return body->get_applied_force();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_applied_torque(RID p_body, const Vector3 &p_torque) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_applied_torque(p_torque);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector3 PhysicsServerSW::body_get_applied_torque(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, Vector3());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return body->get_applied_torque();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
body->apply_impulse(p_pos, p_impulse);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) {
|
2016-12-31 15:39:25 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->apply_torque_impulse(p_impulse);
|
|
|
|
body->wakeup();
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
Vector3 v = body->get_linear_velocity();
|
|
|
|
Vector3 axis = p_axis_velocity.normalized();
|
2017-03-05 16:44:50 +01:00
|
|
|
v -= axis * axis.dot(v);
|
|
|
|
v += p_axis_velocity;
|
2014-02-10 02:10:30 +01:00
|
|
|
body->set_linear_velocity(v);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_axis_lock(RID p_body, BodyAxisLock p_lock) {
|
2014-05-14 06:22:15 +02:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
body->set_axis_lock(p_lock);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-05-14 06:22:15 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PhysicsServerSW::BodyAxisLock PhysicsServerSW::body_get_axis_lock(RID p_body) const {
|
2014-05-14 06:22:15 +02:00
|
|
|
|
|
|
|
const BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, BODY_AXIS_LOCK_DISABLED);
|
2014-05-14 06:22:15 +02:00
|
|
|
return body->get_axis_lock();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void PhysicsServerSW::body_add_collision_exception(RID p_body, RID p_body_b) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->add_exception(p_body_b);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_remove_collision_exception(RID p_body, RID p_body_b) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
2015-01-05 01:16:40 +01:00
|
|
|
body->remove_exception(p_body_b);
|
2015-04-26 21:20:00 +02:00
|
|
|
body->wakeup();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < body->get_exceptions().size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
p_exceptions->push_back(body->get_exceptions()[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
void PhysicsServerSW::body_set_contacts_reported_depth_treshold(RID p_body, real_t p_treshold) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
};
|
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t PhysicsServerSW::body_get_contacts_reported_depth_treshold(RID p_body) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_omit_force_integration(RID p_body, bool p_omit) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
|
|
|
|
body->set_omit_force_integration(p_omit);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool PhysicsServerSW::body_is_omitting_force_integration(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, false);
|
2014-02-10 02:10:30 +01:00
|
|
|
return body->get_omit_force_integration();
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::body_set_max_contacts_reported(RID p_body, int p_contacts) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
body->set_max_contacts_reported(p_contacts);
|
|
|
|
}
|
|
|
|
|
|
|
|
int PhysicsServerSW::body_get_max_contacts_reported(RID p_body) const {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, -1);
|
2014-02-10 02:10:30 +01:00
|
|
|
return body->get_max_contacts_reported();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
2017-03-05 16:44:50 +01:00
|
|
|
body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_ID() : ObjectID(0), p_method, p_udata);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::body_set_ray_pickable(RID p_body, bool p_enable) {
|
2014-10-03 05:10:51 +02:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
|
|
|
ERR_FAIL_COND(!body);
|
|
|
|
body->set_ray_pickable(p_enable);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool PhysicsServerSW::body_is_ray_pickable(RID p_body) const {
|
2014-10-03 05:10:51 +02:00
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_body);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body, false);
|
2014-10-03 05:10:51 +02:00
|
|
|
return body->is_ray_pickable();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/* JOINT API */
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID PhysicsServerSW::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
BodySW *body_A = body_owner.get(p_body_A);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (!p_body_B.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A->get_space(), RID());
|
|
|
|
p_body_B = body_A->get_space()->get_static_global_body();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BodySW *body_B = body_owner.get(p_body_B);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(body_A == body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
JointSW *joint = memnew(PinJointSW(body_A, p_local_A, body_B, p_local_B));
|
2014-09-15 16:33:30 +02:00
|
|
|
RID rid = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
|
|
|
|
PinJointSW *pin_joint = static_cast<PinJointSW *>(joint);
|
|
|
|
pin_joint->set_param(p_param, p_value);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t PhysicsServerSW::pin_joint_get_param(RID p_joint, PinJointParam p_param) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, 0);
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, 0);
|
|
|
|
PinJointSW *pin_joint = static_cast<PinJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
return pin_joint->get_param(p_param);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::pin_joint_set_local_A(RID p_joint, const Vector3 &p_A) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
|
|
|
|
PinJointSW *pin_joint = static_cast<PinJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
pin_joint->set_pos_A(p_A);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 PhysicsServerSW::pin_joint_get_local_A(RID p_joint) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, Vector3());
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
|
|
|
|
PinJointSW *pin_joint = static_cast<PinJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
return pin_joint->get_pos_A();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::pin_joint_set_local_B(RID p_joint, const Vector3 &p_B) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_PIN);
|
|
|
|
PinJointSW *pin_joint = static_cast<PinJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
pin_joint->set_pos_B(p_B);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 PhysicsServerSW::pin_joint_get_local_B(RID p_joint) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, Vector3());
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3());
|
|
|
|
PinJointSW *pin_joint = static_cast<PinJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
return pin_joint->get_pos_B();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID PhysicsServerSW::joint_create_hinge(RID p_body_A, const Transform &p_frame_A, RID p_body_B, const Transform &p_frame_B) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
BodySW *body_A = body_owner.get(p_body_A);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (!p_body_B.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A->get_space(), RID());
|
|
|
|
p_body_B = body_A->get_space()->get_static_global_body();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BodySW *body_B = body_owner.get(p_body_B);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(body_A == body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
JointSW *joint = memnew(HingeJointSW(body_A, body_B, p_frame_A, p_frame_B));
|
2014-09-15 16:33:30 +02:00
|
|
|
RID rid = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID PhysicsServerSW::joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
BodySW *body_A = body_owner.get(p_body_A);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (!p_body_B.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A->get_space(), RID());
|
|
|
|
p_body_B = body_A->get_space()->get_static_global_body();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BodySW *body_B = body_owner.get(p_body_B);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(body_A == body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
JointSW *joint = memnew(HingeJointSW(body_A, body_B, p_pivot_A, p_pivot_B, p_axis_A, p_axis_B));
|
2014-09-15 16:33:30 +02:00
|
|
|
RID rid = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::hinge_joint_set_param(RID p_joint, HingeJointParam p_param, real_t p_value) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
|
|
|
|
HingeJointSW *hinge_joint = static_cast<HingeJointSW *>(joint);
|
|
|
|
hinge_joint->set_param(p_param, p_value);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t PhysicsServerSW::hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, 0);
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, 0);
|
|
|
|
HingeJointSW *hinge_joint = static_cast<HingeJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
return hinge_joint->get_param(p_param);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_HINGE);
|
|
|
|
HingeJointSW *hinge_joint = static_cast<HingeJointSW *>(joint);
|
|
|
|
hinge_joint->set_flag(p_flag, p_value);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
bool PhysicsServerSW::hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, false);
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_HINGE, false);
|
|
|
|
HingeJointSW *hinge_joint = static_cast<HingeJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
return hinge_joint->get_flag(p_flag);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::joint_set_solver_priority(RID p_joint, int p_priority) {
|
2014-10-03 05:10:51 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
|
|
|
joint->set_priority(p_priority);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int PhysicsServerSW::joint_get_solver_priority(RID p_joint) const {
|
2014-10-03 05:10:51 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, 0);
|
2014-10-03 05:10:51 +02:00
|
|
|
return joint->get_priority();
|
|
|
|
}
|
|
|
|
|
2014-09-15 16:33:30 +02:00
|
|
|
PhysicsServerSW::JointType PhysicsServerSW::joint_get_type(RID p_joint) const {
|
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, JOINT_PIN);
|
2014-09-15 16:33:30 +02:00
|
|
|
return joint->get_type();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID PhysicsServerSW::joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
BodySW *body_A = body_owner.get(p_body_A);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (!p_body_B.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A->get_space(), RID());
|
|
|
|
p_body_B = body_A->get_space()->get_static_global_body();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BodySW *body_B = body_owner.get(p_body_B);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(body_A == body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
JointSW *joint = memnew(SliderJointSW(body_A, body_B, p_local_frame_A, p_local_frame_B));
|
2014-09-15 16:33:30 +02:00
|
|
|
RID rid = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::slider_joint_set_param(RID p_joint, SliderJointParam p_param, real_t p_value) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_SLIDER);
|
|
|
|
SliderJointSW *slider_joint = static_cast<SliderJointSW *>(joint);
|
|
|
|
slider_joint->set_param(p_param, p_value);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t PhysicsServerSW::slider_joint_get_param(RID p_joint, SliderJointParam p_param) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, 0);
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0);
|
|
|
|
SliderJointSW *slider_joint = static_cast<SliderJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
return slider_joint->get_param(p_param);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID PhysicsServerSW::joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
BodySW *body_A = body_owner.get(p_body_A);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (!p_body_B.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A->get_space(), RID());
|
|
|
|
p_body_B = body_A->get_space()->get_static_global_body();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BodySW *body_B = body_owner.get(p_body_B);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(body_A == body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
JointSW *joint = memnew(ConeTwistJointSW(body_A, body_B, p_local_frame_A, p_local_frame_B));
|
2014-09-15 16:33:30 +02:00
|
|
|
RID rid = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, real_t p_value) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_CONE_TWIST);
|
|
|
|
ConeTwistJointSW *cone_twist_joint = static_cast<ConeTwistJointSW *>(joint);
|
|
|
|
cone_twist_joint->set_param(p_param, p_value);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t PhysicsServerSW::cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, 0);
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_CONE_TWIST, 0);
|
|
|
|
ConeTwistJointSW *cone_twist_joint = static_cast<ConeTwistJointSW *>(joint);
|
2014-09-15 16:33:30 +02:00
|
|
|
return cone_twist_joint->get_param(p_param);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
RID PhysicsServerSW::joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
BodySW *body_A = body_owner.get(p_body_A);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
if (!p_body_B.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_A->get_space(), RID());
|
|
|
|
p_body_B = body_A->get_space()->get_static_global_body();
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BodySW *body_B = body_owner.get(p_body_B);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(body_A == body_B, RID());
|
2014-09-15 16:33:30 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
JointSW *joint = memnew(Generic6DOFJointSW(body_A, body_B, p_local_frame_A, p_local_frame_B, true));
|
2014-09-15 16:33:30 +02:00
|
|
|
RID rid = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(rid);
|
|
|
|
return rid;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, real_t p_value) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
|
|
|
|
Generic6DOFJointSW *generic_6dof_joint = static_cast<Generic6DOFJointSW *>(joint);
|
|
|
|
generic_6dof_joint->set_param(p_axis, p_param, p_value);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t PhysicsServerSW::generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, 0);
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, 0);
|
|
|
|
Generic6DOFJointSW *generic_6dof_joint = static_cast<Generic6DOFJointSW *>(joint);
|
|
|
|
return generic_6dof_joint->get_param(p_axis, p_param);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(joint->get_type() != JOINT_6DOF);
|
|
|
|
Generic6DOFJointSW *generic_6dof_joint = static_cast<Generic6DOFJointSW *>(joint);
|
|
|
|
generic_6dof_joint->set_flag(p_axis, p_flag, p_enable);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
bool PhysicsServerSW::generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!joint, false);
|
|
|
|
ERR_FAIL_COND_V(joint->get_type() != JOINT_6DOF, false);
|
|
|
|
Generic6DOFJointSW *generic_6dof_joint = static_cast<Generic6DOFJointSW *>(joint);
|
|
|
|
return generic_6dof_joint->get_flag(p_axis, p_flag);
|
2014-09-15 16:33:30 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#if 0
|
|
|
|
void PhysicsServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) {
|
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!joint);
|
|
|
|
|
|
|
|
switch(p_param) {
|
|
|
|
case JOINT_PARAM_BIAS: joint->set_bias(p_value); break;
|
|
|
|
case JOINT_PARAM_MAX_BIAS: joint->set_max_bias(p_value); break;
|
|
|
|
case JOINT_PARAM_MAX_FORCE: joint->set_max_force(p_value); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t PhysicsServerSW::joint_get_param(RID p_joint,JointParam p_param) const {
|
|
|
|
|
|
|
|
const JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND_V(!joint,-1);
|
|
|
|
|
|
|
|
switch(p_param) {
|
|
|
|
case JOINT_PARAM_BIAS: return joint->get_bias(); break;
|
|
|
|
case JOINT_PARAM_MAX_BIAS: return joint->get_max_bias(); break;
|
|
|
|
case JOINT_PARAM_MAX_FORCE: return joint->get_max_force(); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RID PhysicsServerSW::pin_joint_create(const Vector3& p_pos,RID p_body_a,RID p_body_b) {
|
|
|
|
|
|
|
|
BodySW *A=body_owner.get(p_body_a);
|
|
|
|
ERR_FAIL_COND_V(!A,RID());
|
|
|
|
BodySW *B=NULL;
|
|
|
|
if (body_owner.owns(p_body_b)) {
|
|
|
|
B=body_owner.get(p_body_b);
|
|
|
|
ERR_FAIL_COND_V(!B,RID());
|
|
|
|
}
|
|
|
|
|
|
|
|
JointSW *joint = memnew( PinJointSW(p_pos,A,B) );
|
|
|
|
RID self = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(self);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID PhysicsServerSW::groove_joint_create(const Vector3& p_a_groove1,const Vector3& p_a_groove2, const Vector3& p_b_anchor, RID p_body_a,RID p_body_b) {
|
|
|
|
|
|
|
|
|
|
|
|
BodySW *A=body_owner.get(p_body_a);
|
|
|
|
ERR_FAIL_COND_V(!A,RID());
|
|
|
|
|
|
|
|
BodySW *B=body_owner.get(p_body_b);
|
|
|
|
ERR_FAIL_COND_V(!B,RID());
|
|
|
|
|
|
|
|
JointSW *joint = memnew( GrooveJointSW(p_a_groove1,p_a_groove2,p_b_anchor,A,B) );
|
|
|
|
RID self = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(self);
|
|
|
|
return self;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
RID PhysicsServerSW::damped_spring_joint_create(const Vector3& p_anchor_a,const Vector3& p_anchor_b,RID p_body_a,RID p_body_b) {
|
|
|
|
|
|
|
|
BodySW *A=body_owner.get(p_body_a);
|
|
|
|
ERR_FAIL_COND_V(!A,RID());
|
|
|
|
|
|
|
|
BodySW *B=body_owner.get(p_body_b);
|
|
|
|
ERR_FAIL_COND_V(!B,RID());
|
|
|
|
|
|
|
|
JointSW *joint = memnew( DampedSpringJointSW(p_anchor_a,p_anchor_b,A,B) );
|
|
|
|
RID self = joint_owner.make_rid(joint);
|
|
|
|
joint->set_self(self);
|
|
|
|
return self;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhysicsServerSW::damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value) {
|
|
|
|
|
|
|
|
|
|
|
|
JointSW *j = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND(!j);
|
|
|
|
ERR_FAIL_COND(j->get_type()!=JOINT_DAMPED_SPRING);
|
|
|
|
|
|
|
|
DampedSpringJointSW *dsj = static_cast<DampedSpringJointSW*>(j);
|
|
|
|
dsj->set_param(p_param,p_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
real_t PhysicsServerSW::damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const {
|
|
|
|
|
|
|
|
JointSW *j = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND_V(!j,0);
|
|
|
|
ERR_FAIL_COND_V(j->get_type()!=JOINT_DAMPED_SPRING,0);
|
|
|
|
|
|
|
|
DampedSpringJointSW *dsj = static_cast<DampedSpringJointSW*>(j);
|
|
|
|
return dsj->get_param(p_param);
|
|
|
|
}
|
|
|
|
|
|
|
|
PhysicsServer::JointType PhysicsServerSW::joint_get_type(RID p_joint) const {
|
|
|
|
|
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_joint);
|
|
|
|
ERR_FAIL_COND_V(!joint,JOINT_PIN);
|
|
|
|
|
|
|
|
return joint->get_type();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void PhysicsServerSW::free(RID p_rid) {
|
|
|
|
|
|
|
|
if (shape_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
ShapeSW *shape = shape_owner.get(p_rid);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (shape->get_owners().size()) {
|
|
|
|
ShapeOwnerSW *so = shape->get_owners().front()->key();
|
2014-02-10 02:10:30 +01:00
|
|
|
so->remove_shape(shape);
|
|
|
|
}
|
|
|
|
|
|
|
|
shape_owner.free(p_rid);
|
|
|
|
memdelete(shape);
|
|
|
|
} else if (body_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
BodySW *body = body_owner.get(p_rid);
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
/*
|
|
|
|
if (body->get_state_query())
|
|
|
|
_clear_query(body->get_state_query());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
if (body->get_direct_state_query())
|
|
|
|
_clear_query(body->get_direct_state_query());
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
body->set_space(NULL);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (body->get_shape_count()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
body->remove_shape(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (body->get_constraint_map().size()) {
|
|
|
|
RID self = body->get_constraint_map().front()->key()->get_self();
|
|
|
|
ERR_FAIL_COND(!self.is_valid());
|
|
|
|
free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
body_owner.free(p_rid);
|
|
|
|
memdelete(body);
|
|
|
|
|
|
|
|
} else if (area_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
AreaSW *area = area_owner.get(p_rid);
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
/*
|
|
|
|
if (area->get_monitor_query())
|
|
|
|
_clear_query(area->get_monitor_query());
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
area->set_space(NULL);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (area->get_shape_count()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
area->remove_shape(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
area_owner.free(p_rid);
|
|
|
|
memdelete(area);
|
|
|
|
} else if (space_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
SpaceSW *space = space_owner.get(p_rid);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (space->get_objects().size()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
CollisionObjectSW *co = (CollisionObjectSW *)space->get_objects().front()->get();
|
|
|
|
co->set_space(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
active_spaces.erase(space);
|
|
|
|
free(space->get_default_area()->get_self());
|
2014-09-15 16:33:30 +02:00
|
|
|
free(space->get_static_global_body());
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
space_owner.free(p_rid);
|
|
|
|
memdelete(space);
|
|
|
|
} else if (joint_owner.owns(p_rid)) {
|
|
|
|
|
|
|
|
JointSW *joint = joint_owner.get(p_rid);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < joint->get_body_count(); i++) {
|
2014-09-15 16:33:30 +02:00
|
|
|
|
|
|
|
joint->get_body_ptr()[i]->remove_constraint(joint);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
joint_owner.free(p_rid);
|
|
|
|
memdelete(joint);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ERR_EXPLAIN("Invalid ID");
|
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::set_active(bool p_active) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
active = p_active;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::init() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
doing_sync = true;
|
|
|
|
last_step = 0.001;
|
|
|
|
iterations = 8; // 8?
|
|
|
|
stepper = memnew(StepSW);
|
|
|
|
direct_state = memnew(PhysicsDirectBodyStateSW);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
void PhysicsServerSW::step(real_t p_step) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
doing_sync = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
last_step = p_step;
|
|
|
|
PhysicsDirectBodyStateSW::singleton->step = p_step;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
island_count = 0;
|
|
|
|
active_objects = 0;
|
|
|
|
collision_pairs = 0;
|
|
|
|
for (Set<const SpaceSW *>::Element *E = active_spaces.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
stepper->step((SpaceSW *)E->get(), p_step, iterations);
|
|
|
|
island_count += E->get()->get_island_count();
|
|
|
|
active_objects += E->get()->get_active_objects();
|
|
|
|
collision_pairs += E->get()->get_collision_pairs();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2014-09-03 04:13:40 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::sync(){
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::flush_queries() {
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
doing_sync = true;
|
2016-05-22 02:18:16 +02:00
|
|
|
|
|
|
|
uint64_t time_beg = OS::get_singleton()->get_ticks_usec();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<const SpaceSW *>::Element *E = active_spaces.front(); E; E = E->next()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
SpaceSW *space = (SpaceSW *)E->get();
|
2014-02-10 02:10:30 +01:00
|
|
|
space->call_queries();
|
|
|
|
}
|
|
|
|
|
2016-05-22 02:18:16 +02:00
|
|
|
if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_profiling()) {
|
|
|
|
|
|
|
|
uint64_t total_time[SpaceSW::ELAPSED_TIME_MAX];
|
2017-03-05 16:44:50 +01:00
|
|
|
static const char *time_name[SpaceSW::ELAPSED_TIME_MAX] = {
|
2016-05-22 02:18:16 +02:00
|
|
|
"integrate_forces",
|
|
|
|
"generate_islands",
|
|
|
|
"setup_constraints",
|
|
|
|
"solve_constraints",
|
|
|
|
"integrate_velocities"
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < SpaceSW::ELAPSED_TIME_MAX; i++) {
|
|
|
|
total_time[i] = 0;
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<const SpaceSW *>::Element *E = active_spaces.front(); E; E = E->next()) {
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < SpaceSW::ELAPSED_TIME_MAX; i++) {
|
|
|
|
total_time[i] += E->get()->get_elapsed_time(SpaceSW::ElapsedTime(i));
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Array values;
|
2017-03-05 16:44:50 +01:00
|
|
|
values.resize(SpaceSW::ELAPSED_TIME_MAX * 2);
|
|
|
|
for (int i = 0; i < SpaceSW::ELAPSED_TIME_MAX; i++) {
|
|
|
|
values[i * 2 + 0] = time_name[i];
|
|
|
|
values[i * 2 + 1] = USEC_TO_SEC(total_time[i]);
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
|
|
|
values.push_back("flush_queries");
|
2017-03-05 16:44:50 +01:00
|
|
|
values.push_back(USEC_TO_SEC(OS::get_singleton()->get_ticks_usec() - time_beg));
|
2016-05-22 02:18:16 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ScriptDebugger::get_singleton()->add_profiling_frame_data("physics", values);
|
2016-05-22 02:18:16 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void PhysicsServerSW::finish() {
|
|
|
|
|
|
|
|
memdelete(stepper);
|
|
|
|
memdelete(direct_state);
|
|
|
|
};
|
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
int PhysicsServerSW::get_process_info(ProcessInfo p_info) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_info) {
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
case INFO_ACTIVE_OBJECTS: {
|
|
|
|
|
|
|
|
return active_objects;
|
|
|
|
} break;
|
|
|
|
case INFO_COLLISION_PAIRS: {
|
|
|
|
return collision_pairs;
|
|
|
|
} break;
|
|
|
|
case INFO_ISLAND_COUNT: {
|
|
|
|
|
|
|
|
return island_count;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void PhysicsServerSW::_shape_col_cbk(const Vector3 &p_point_A, const Vector3 &p_point_B, void *p_userdata) {
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CollCbkData *cbk = (CollCbkData *)p_userdata;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cbk->max == 0)
|
2014-09-03 04:13:40 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (cbk->amount == cbk->max) {
|
|
|
|
//find least deep
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t min_depth = 1e20;
|
|
|
|
int min_depth_idx = 0;
|
|
|
|
for (int i = 0; i < cbk->amount; i++) {
|
|
|
|
|
|
|
|
real_t d = cbk->ptr[i * 2 + 0].distance_squared_to(cbk->ptr[i * 2 + 1]);
|
|
|
|
if (d < min_depth) {
|
|
|
|
min_depth = d;
|
|
|
|
min_depth_idx = i;
|
2014-09-03 04:13:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t d = p_point_A.distance_squared_to(p_point_B);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (d < min_depth)
|
2014-09-03 04:13:40 +02:00
|
|
|
return;
|
2017-03-05 16:44:50 +01:00
|
|
|
cbk->ptr[min_depth_idx * 2 + 0] = p_point_A;
|
|
|
|
cbk->ptr[min_depth_idx * 2 + 1] = p_point_B;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cbk->ptr[cbk->amount * 2 + 0] = p_point_A;
|
|
|
|
cbk->ptr[cbk->amount * 2 + 1] = p_point_B;
|
2014-09-03 04:13:40 +02:00
|
|
|
cbk->amount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
PhysicsServerSW::PhysicsServerSW() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BroadPhaseSW::create_func = BroadPhaseOctree::_create;
|
|
|
|
island_count = 0;
|
|
|
|
active_objects = 0;
|
|
|
|
collision_pairs = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
active = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PhysicsServerSW::~PhysicsServerSW(){
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
};
|