diff options
Diffstat (limited to 'servers/physics/shape_sw.h')
-rw-r--r-- | servers/physics/shape_sw.h | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/servers/physics/shape_sw.h b/servers/physics/shape_sw.h index 39779bcda3..919c681105 100644 --- a/servers/physics/shape_sw.h +++ b/servers/physics/shape_sw.h @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2017 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 */ @@ -46,7 +46,7 @@ SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_creat class ShapeSW; -class ShapeOwnerSW { +class ShapeOwnerSW : public RID_Data { public: virtual void _shape_changed()=0; @@ -56,29 +56,31 @@ public: }; -class ShapeSW { +class ShapeSW : public RID_Data { RID self; - AABB aabb; + Rect3 aabb; bool configured; real_t custom_bias; Map<ShapeOwnerSW*,int> owners; protected: - void configure(const AABB& p_aabb); + void configure(const Rect3& p_aabb); public: enum { MAX_SUPPORTS=8 }; + virtual real_t get_area() const { return aabb.get_area();} + _FORCE_INLINE_ void set_self(const RID& p_self) { self=p_self; } _FORCE_INLINE_ RID get_self() const {return self; } virtual PhysicsServer::ShapeType get_type() const=0; - _FORCE_INLINE_ AABB get_aabb() const { return aabb; } + _FORCE_INLINE_ Rect3 get_aabb() const { return aabb; } _FORCE_INLINE_ bool is_configured() const { return configured; } virtual bool is_concave() const { return false; } @@ -114,7 +116,7 @@ public: typedef void (*Callback)(void* p_userdata,ShapeSW *p_convex); virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const { r_amount=0; } - virtual void cull(const AABB& p_local_aabb,Callback p_callback,void* p_userdata) const=0; + virtual void cull(const Rect3& p_local_aabb,Callback p_callback,void* p_userdata) const=0; ConcaveShapeSW() {} }; @@ -128,6 +130,7 @@ public: Plane get_plane() const; + virtual real_t get_area() const { return INFINITY; } virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_PLANE; } virtual void project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const; virtual Vector3 get_support(const Vector3& p_normal) const; @@ -152,6 +155,7 @@ public: float get_length() const; + virtual real_t get_area() const { return 0.0; } virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_RAY; } virtual void project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const; virtual Vector3 get_support(const Vector3& p_normal) const; @@ -176,6 +180,8 @@ public: real_t get_radius() const; + virtual real_t get_area() const { return 4.0/3.0 * Math_PI * radius * radius * radius; } + virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_SPHERE; } virtual void project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const; @@ -198,6 +204,7 @@ class BoxShapeSW : public ShapeSW { public: _FORCE_INLINE_ Vector3 get_half_extents() const { return half_extents; } + virtual real_t get_area() const { return 8 * half_extents.x * half_extents.y * half_extents.z; } virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_BOX; } @@ -226,6 +233,8 @@ public: _FORCE_INLINE_ real_t get_height() const { return height; } _FORCE_INLINE_ real_t get_radius() const { return radius; } + virtual real_t get_area() { return 4.0/3.0 * Math_PI * radius * radius * radius + height * Math_PI * radius * radius; } + virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_CAPSULE; } virtual void project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const; @@ -279,23 +288,23 @@ struct ConcavePolygonShapeSW : public ConcaveShapeSW { int indices[3]; }; - DVector<Face> faces; - DVector<Vector3> vertices; + PoolVector<Face> faces; + PoolVector<Vector3> vertices; struct BVH { - AABB aabb; + Rect3 aabb; int left; int right; int face_index; }; - DVector<BVH> bvh; + PoolVector<BVH> bvh; struct _CullParams { - AABB aabb; + Rect3 aabb; Callback callback; void *userdata; const Face *faces; @@ -326,10 +335,10 @@ struct ConcavePolygonShapeSW : public ConcaveShapeSW { void _fill_bvh(_VolumeSW_BVH* p_bvh_tree,BVH* p_bvh_array,int& p_idx); - void _setup(DVector<Vector3> p_faces); + void _setup(PoolVector<Vector3> p_faces); public: - DVector<Vector3> get_faces() const; + PoolVector<Vector3> get_faces() const; virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_CONCAVE_POLYGON; } @@ -338,7 +347,7 @@ public: virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual void cull(const AABB& p_local_aabb,Callback p_callback,void* p_userdata) const; + virtual void cull(const Rect3& p_local_aabb,Callback p_callback,void* p_userdata) const; virtual Vector3 get_moment_of_inertia(float p_mass) const; @@ -352,18 +361,18 @@ public: struct HeightMapShapeSW : public ConcaveShapeSW { - DVector<real_t> heights; + PoolVector<real_t> heights; int width; int depth; float cell_size; -// void _cull_segment(int p_idx,_SegmentCullParams *p_params) const; -// void _cull(int p_idx,_CullParams *p_params) const; + //void _cull_segment(int p_idx,_SegmentCullParams *p_params) const; + //void _cull(int p_idx,_CullParams *p_params) const; - void _setup(DVector<float> p_heights,int p_width,int p_depth,float p_cell_size); + void _setup(PoolVector<float> p_heights,int p_width,int p_depth,float p_cell_size); public: - DVector<real_t> get_heights() const; + PoolVector<real_t> get_heights() const; int get_width() const; int get_depth() const; float get_cell_size() const; @@ -374,7 +383,7 @@ public: virtual Vector3 get_support(const Vector3& p_normal) const; virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual void cull(const AABB& p_local_aabb,Callback p_callback,void* p_userdata) const; + virtual void cull(const Rect3& p_local_aabb,Callback p_callback,void* p_userdata) const; virtual Vector3 get_moment_of_inertia(float p_mass) const; @@ -446,7 +455,7 @@ struct MotionShapeSW : public ShapeSW { virtual void set_data(const Variant& p_data) {} virtual Variant get_data() const { return Variant(); } - MotionShapeSW() { configure(AABB()); } + MotionShapeSW() { configure(Rect3()); } }; |