shapeCollisionComponent.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #pragma once
  23. #ifndef SHAPE_COLLISION_COMPONENT_H
  24. #define SHAPE_COLLISION_COMPONENT_H
  25. #ifndef __RESOURCE_H__
  26. #include "core/resource.h"
  27. #endif
  28. #ifndef _TSSHAPE_H_
  29. #include "ts/tsShape.h"
  30. #endif
  31. #ifndef _SCENERENDERSTATE_H_
  32. #include "scene/sceneRenderState.h"
  33. #endif
  34. #ifndef _MBOX_H_
  35. #include "math/mBox.h"
  36. #endif
  37. #ifndef ENTITY_H
  38. #include "T3D/entity.h"
  39. #endif
  40. #ifndef CORE_INTERFACES_H
  41. #include "T3D/components/coreInterfaces.h"
  42. #endif
  43. #ifndef COLLISION_COMPONENT_H
  44. #include "T3D/components/collision/collisionComponent.h"
  45. #endif
  46. #ifndef RENDER_COMPONENT_INTERFACE_H
  47. #include "T3D/components/render/renderComponentInterface.h"
  48. #endif
  49. class TSShapeInstance;
  50. class SceneRenderState;
  51. class ShapeCollisionComponent;
  52. class PhysicsBody;
  53. class PhysicsWorld;
  54. class ShapeCollisionComponent : public CollisionComponent
  55. {
  56. typedef Component Parent;
  57. public:
  58. enum MeshType
  59. {
  60. None = 0, ///< No mesh
  61. Bounds = 1, ///< Bounding box of the shape
  62. CollisionMesh = 2, ///< Specifically designated collision meshes
  63. VisibleMesh = 3 ///< Rendered mesh polygons
  64. };
  65. protected:
  66. MeshType mCollisionType;
  67. MeshType mDecalType;
  68. MeshType mLOSType;
  69. Vector<S32> mCollisionDetails;
  70. Vector<S32> mLOSDetails;
  71. StringTableEntry colisionMeshPrefix;
  72. RenderComponentInterface* mOwnerRenderInterface;
  73. PhysicsComponent* mOwnerPhysicsComp;
  74. //only really relevent for the collision mesh type
  75. //if we note an animation component is added, we flag as being animated.
  76. //This way, if we're using collision meshes, we can set it up to update their transforms
  77. //as needed
  78. bool mAnimated;
  79. enum
  80. {
  81. ColliderMask = Parent::NextFreeMask,
  82. };
  83. public:
  84. ShapeCollisionComponent();
  85. virtual ~ShapeCollisionComponent();
  86. DECLARE_CONOBJECT(ShapeCollisionComponent);
  87. virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
  88. virtual void unpackUpdate(NetConnection *con, BitStream *stream);
  89. virtual void componentAddedToOwner(Component *comp);
  90. virtual void componentRemovedFromOwner(Component *comp);
  91. virtual void ownerTransformSet(MatrixF *mat);
  92. void targetShapeChanged(RenderComponentInterface* instanceInterface);
  93. virtual void onComponentRemove();
  94. virtual void onComponentAdd();
  95. virtual void checkDependencies();
  96. static void initPersistFields();
  97. void inspectPostApply();
  98. //Setup
  99. virtual void prepCollision();
  100. //Updates
  101. virtual void processTick();
  102. PhysicsCollision* buildColShapes();
  103. void updatePhysics();
  104. virtual bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
  105. virtual bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF &sphere){ return false; }
  106. virtual PhysicsCollision* getCollisionData();
  107. };
  108. typedef ShapeCollisionComponent::MeshType CollisionMeshMeshType;
  109. DefineEnumType(CollisionMeshMeshType);
  110. #endif // COLLISION_COMPONENT_H