collision_object_sw.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*************************************************************************/
  2. /* collision_object_sw.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef COLLISION_OBJECT_SW_H
  30. #define COLLISION_OBJECT_SW_H
  31. #include "shape_sw.h"
  32. #include "servers/physics_server.h"
  33. #include "self_list.h"
  34. #include "broad_phase_sw.h"
  35. class SpaceSW;
  36. class CollisionObjectSW : public ShapeOwnerSW {
  37. public:
  38. enum Type {
  39. TYPE_AREA,
  40. TYPE_BODY
  41. };
  42. private:
  43. Type type;
  44. RID self;
  45. ObjectID instance_id;
  46. struct Shape {
  47. Transform xform;
  48. Transform xform_inv;
  49. BroadPhaseSW::ID bpid;
  50. AABB aabb_cache; //for rayqueries
  51. ShapeSW *shape;
  52. };
  53. Vector<Shape> shapes;
  54. SpaceSW *space;
  55. Transform transform;
  56. Transform inv_transform;
  57. bool _static;
  58. void _update_shapes();
  59. protected:
  60. void _update_shapes_with_motion(const Vector3& p_motion);
  61. void _unregister_shapes();
  62. _FORCE_INLINE_ void _set_transform(const Transform& p_transform) { transform=p_transform; _update_shapes(); }
  63. _FORCE_INLINE_ void _set_inv_transform(const Transform& p_transform) { inv_transform=p_transform; }
  64. void _set_static(bool p_static);
  65. virtual void _shapes_changed()=0;
  66. void _set_space(SpaceSW *space);
  67. CollisionObjectSW(Type p_type);
  68. public:
  69. _FORCE_INLINE_ void set_self(const RID& p_self) { self=p_self; }
  70. _FORCE_INLINE_ RID get_self() const { return self; }
  71. _FORCE_INLINE_ void set_instance_id(const ObjectID& p_instance_id) { instance_id=p_instance_id; }
  72. _FORCE_INLINE_ ObjectID get_instance_id() const { return instance_id; }
  73. void _shape_changed();
  74. _FORCE_INLINE_ Type get_type() const { return type; }
  75. void add_shape(ShapeSW *p_shape,const Transform& p_transform=Transform());
  76. void set_shape(int p_index,ShapeSW *p_shape);
  77. void set_shape_transform(int p_index,const Transform& p_transform);
  78. _FORCE_INLINE_ int get_shape_count() const { return shapes.size(); }
  79. _FORCE_INLINE_ ShapeSW *get_shape(int p_index) const { return shapes[p_index].shape; }
  80. _FORCE_INLINE_ const Transform& get_shape_transform(int p_index) const { return shapes[p_index].xform; }
  81. _FORCE_INLINE_ const Transform& get_shape_inv_transform(int p_index) const { return shapes[p_index].xform_inv; }
  82. _FORCE_INLINE_ const AABB& get_shape_aabb(int p_index) const { return shapes[p_index].aabb_cache; }
  83. _FORCE_INLINE_ Transform get_transform() const { return transform; }
  84. _FORCE_INLINE_ Transform get_inv_transform() const { return inv_transform; }
  85. _FORCE_INLINE_ SpaceSW* get_space() const { return space; }
  86. void remove_shape(ShapeSW *p_shape);
  87. void remove_shape(int p_index);
  88. virtual void set_space(SpaceSW *p_space)=0;
  89. _FORCE_INLINE_ bool is_static() const { return _static; }
  90. virtual ~CollisionObjectSW() {}
  91. };
  92. #endif // COLLISION_OBJECT_SW_H