btRayShape.cpp 4.2 KB

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