btRayShape.cpp 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*************************************************************************/
  2. /* btRayShape.h */
  3. /* Author: AndreaCatania */
  4. /*************************************************************************/
  5. /* This file is part of: */
  6. /* GODOT ENGINE */
  7. /* http://www.godotengine.org */
  8. /*************************************************************************/
  9. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  10. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  11. /* */
  12. /* Permission is hereby granted, free of charge, to any person obtaining */
  13. /* a copy of this software and associated documentation files (the */
  14. /* "Software"), to deal in the Software without restriction, including */
  15. /* without limitation the rights to use, copy, modify, merge, publish, */
  16. /* distribute, sublicense, and/or sell copies of the Software, and to */
  17. /* permit persons to whom the Software is furnished to do so, subject to */
  18. /* the following conditions: */
  19. /* */
  20. /* The above copyright notice and this permission notice shall be */
  21. /* included in all copies or substantial portions of the Software. */
  22. /* */
  23. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  24. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  25. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  26. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  27. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  28. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  29. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  30. /*************************************************************************/
  31. #include "btRayShape.h"
  32. #include "LinearMath/btAabbUtil2.h"
  33. #include "math/math_funcs.h"
  34. btRayShape::btRayShape(btScalar length)
  35. : btConvexInternalShape(),
  36. m_shapeAxis(0, 0, 1) {
  37. m_shapeType = CUSTOM_CONVEX_SHAPE_TYPE;
  38. setLength(length);
  39. }
  40. btRayShape::~btRayShape() {
  41. }
  42. void btRayShape::setLength(btScalar p_length) {
  43. m_length = p_length;
  44. reload_cache();
  45. }
  46. btVector3 btRayShape::localGetSupportingVertex(const btVector3 &vec) const {
  47. return localGetSupportingVertexWithoutMargin(vec) + (m_shapeAxis * m_collisionMargin);
  48. }
  49. btVector3 btRayShape::localGetSupportingVertexWithoutMargin(const btVector3 &vec) const {
  50. if (vec.z() > 0)
  51. return m_shapeAxis * m_cacheScaledLength;
  52. else
  53. return btVector3(0, 0, 0);
  54. }
  55. void btRayShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const {
  56. for (int i = 0; i < numVectors; ++i) {
  57. supportVerticesOut[i] = localGetSupportingVertexWithoutMargin(vectors[i]);
  58. }
  59. }
  60. void btRayShape::getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const {
  61. #define MARGIN_BROADPHASE 0.1
  62. btVector3 localAabbMin(0, 0, 0);
  63. btVector3 localAabbMax(m_shapeAxis * m_length);
  64. btTransformAabb(localAabbMin, localAabbMax, MARGIN_BROADPHASE, t, aabbMin, aabbMax);
  65. }
  66. void btRayShape::calculateLocalInertia(btScalar mass, btVector3 &inertia) const {
  67. inertia.setZero();
  68. }
  69. int btRayShape::getNumPreferredPenetrationDirections() const {
  70. return 0;
  71. }
  72. void btRayShape::getPreferredPenetrationDirection(int index, btVector3 &penetrationVector) const {
  73. penetrationVector.setZero();
  74. }
  75. void btRayShape::reload_cache() {
  76. m_cacheScaledLength = m_length * m_localScaling[2] + m_collisionMargin;
  77. m_cacheSupportPoint.setIdentity();
  78. m_cacheSupportPoint.setOrigin(m_shapeAxis * m_cacheScaledLength);
  79. }