2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* collision_object_sw.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00: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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef COLLISION_OBJECT_SW_H
|
|
|
|
#define COLLISION_OBJECT_SW_H
|
|
|
|
|
|
|
|
#include "broad_phase_sw.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "self_list.h"
|
|
|
|
#include "servers/physics_server.h"
|
|
|
|
#include "shape_sw.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-05 22:56:59 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
#define MAX_OBJECT_DISTANCE 10000000.0
|
2017-03-05 15:44:50 +00:00
|
|
|
#define MAX_OBJECT_DISTANCE_X2 (MAX_OBJECT_DISTANCE * MAX_OBJECT_DISTANCE)
|
2015-05-05 22:56:59 +00:00
|
|
|
#endif
|
2014-09-19 21:39:50 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class SpaceSW;
|
|
|
|
|
|
|
|
class CollisionObjectSW : public ShapeOwnerSW {
|
|
|
|
public:
|
|
|
|
enum Type {
|
|
|
|
TYPE_AREA,
|
|
|
|
TYPE_BODY
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
private:
|
2014-02-10 01:10:30 +00:00
|
|
|
Type type;
|
|
|
|
RID self;
|
|
|
|
ObjectID instance_id;
|
2017-06-13 15:45:01 +00:00
|
|
|
uint32_t collision_layer;
|
2016-04-09 18:54:09 +00:00
|
|
|
uint32_t collision_mask;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
struct Shape {
|
|
|
|
|
|
|
|
Transform xform;
|
|
|
|
Transform xform_inv;
|
|
|
|
BroadPhaseSW::ID bpid;
|
2017-01-11 03:52:51 +00:00
|
|
|
Rect3 aabb_cache; //for rayqueries
|
2016-12-31 14:39:25 +00:00
|
|
|
real_t area_cache;
|
2014-02-10 01:10:30 +00:00
|
|
|
ShapeSW *shape;
|
2017-07-15 04:23:10 +00:00
|
|
|
bool disabled;
|
2014-10-03 11:58:41 +00:00
|
|
|
|
2017-07-15 04:23:10 +00:00
|
|
|
Shape() { disabled = false; }
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Shape> shapes;
|
|
|
|
SpaceSW *space;
|
|
|
|
Transform transform;
|
|
|
|
Transform inv_transform;
|
|
|
|
bool _static;
|
|
|
|
|
|
|
|
void _update_shapes();
|
|
|
|
|
|
|
|
protected:
|
2017-03-05 15:44:50 +00:00
|
|
|
void _update_shapes_with_motion(const Vector3 &p_motion);
|
2014-02-10 01:10:30 +00:00
|
|
|
void _unregister_shapes();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ void _set_transform(const Transform &p_transform, bool p_update_shapes = true) {
|
2014-09-19 21:39:50 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
|
|
|
|
if (p_transform.origin.length_squared() > MAX_OBJECT_DISTANCE_X2) {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_EXPLAIN("Object went too far away (more than " + itos(MAX_OBJECT_DISTANCE) + "mts from origin).");
|
2014-09-19 21:39:50 +00:00
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
transform = p_transform;
|
|
|
|
if (p_update_shapes) _update_shapes();
|
2014-09-19 21:39:50 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ void _set_inv_transform(const Transform &p_transform) { inv_transform = p_transform; }
|
2014-02-10 01:10:30 +00:00
|
|
|
void _set_static(bool p_static);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void _shapes_changed() = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _set_space(SpaceSW *space);
|
|
|
|
|
2014-10-03 03:10:51 +00:00
|
|
|
bool ray_pickable;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
CollisionObjectSW(Type p_type);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
|
|
|
_FORCE_INLINE_ void set_self(const RID &p_self) { self = p_self; }
|
2014-02-10 01:10:30 +00:00
|
|
|
_FORCE_INLINE_ RID get_self() const { return self; }
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ void set_instance_id(const ObjectID &p_instance_id) { instance_id = p_instance_id; }
|
2014-02-10 01:10:30 +00:00
|
|
|
_FORCE_INLINE_ ObjectID get_instance_id() const { return instance_id; }
|
|
|
|
|
|
|
|
void _shape_changed();
|
|
|
|
|
|
|
|
_FORCE_INLINE_ Type get_type() const { return type; }
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_shape(ShapeSW *p_shape, const Transform &p_transform = Transform());
|
|
|
|
void set_shape(int p_index, ShapeSW *p_shape);
|
|
|
|
void set_shape_transform(int p_index, const Transform &p_transform);
|
2014-02-10 01:10:30 +00:00
|
|
|
_FORCE_INLINE_ int get_shape_count() const { return shapes.size(); }
|
|
|
|
_FORCE_INLINE_ ShapeSW *get_shape(int p_index) const { return shapes[p_index].shape; }
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ const Transform &get_shape_transform(int p_index) const { return shapes[p_index].xform; }
|
|
|
|
_FORCE_INLINE_ const Transform &get_shape_inv_transform(int p_index) const { return shapes[p_index].xform_inv; }
|
|
|
|
_FORCE_INLINE_ const Rect3 &get_shape_aabb(int p_index) const { return shapes[p_index].aabb_cache; }
|
2016-12-31 14:39:25 +00:00
|
|
|
_FORCE_INLINE_ const real_t get_shape_area(int p_index) const { return shapes[p_index].area_cache; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_FORCE_INLINE_ Transform get_transform() const { return transform; }
|
|
|
|
_FORCE_INLINE_ Transform get_inv_transform() const { return inv_transform; }
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ SpaceSW *get_space() const { return space; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ void set_ray_pickable(bool p_enable) { ray_pickable = p_enable; }
|
2014-10-03 03:10:51 +00:00
|
|
|
_FORCE_INLINE_ bool is_ray_pickable() const { return ray_pickable; }
|
|
|
|
|
2017-07-15 04:23:10 +00:00
|
|
|
_FORCE_INLINE_ void set_shape_as_disabled(int p_idx, bool p_enable) { shapes[p_idx].disabled = p_enable; }
|
|
|
|
_FORCE_INLINE_ bool is_shape_set_as_disabled(int p_idx) const { return shapes[p_idx].disabled; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-06-13 15:45:01 +00:00
|
|
|
_FORCE_INLINE_ void set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; }
|
|
|
|
_FORCE_INLINE_ uint32_t get_collision_layer() const { return collision_layer; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ void set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; }
|
2016-04-09 18:54:09 +00:00
|
|
|
_FORCE_INLINE_ uint32_t get_collision_mask() const { return collision_mask; }
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ bool test_collision_mask(CollisionObjectSW *p_other) const {
|
2017-06-13 15:45:01 +00:00
|
|
|
return collision_layer & p_other->collision_mask || p_other->collision_layer & collision_mask;
|
2016-04-09 18:54:09 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void remove_shape(ShapeSW *p_shape);
|
|
|
|
void remove_shape(int p_index);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
virtual void set_space(SpaceSW *p_space) = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ bool is_static() const { return _static; }
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
virtual ~CollisionObjectSW() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // COLLISION_OBJECT_SW_H
|