PageRenderTime 147ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llphysicsshapebuilderutil.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 138 lines | 78 code | 31 blank | 29 comment | 14 complexity | 7413b03bd72ee84eecf227e90e9d8f6d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llphysicsshapebuilder.h
  3. * @brief Generic system to convert LL(Physics)VolumeParams to physics shapes
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_PHYSICS_SHAPE_BUILDER_H
  27. #define LL_PHYSICS_SHAPE_BUILDER_H
  28. #include "indra_constants.h"
  29. #include "llvolume.h"
  30. #define USE_SHAPE_QUANTIZATION 0
  31. #define SHAPE_BUILDER_DEFAULT_VOLUME_DETAIL 1
  32. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_HOLLOW 0.10f
  33. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_HOLLOW_SPHERES 0.90f
  34. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_PATH_CUT 0.05f
  35. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_TAPER 0.05f
  36. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_TWIST 0.09f
  37. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_SHEAR 0.05f
  38. const F32 SHAPE_BUILDER_ENTRY_SNAP_SCALE_BIN_SIZE = 0.15f;
  39. const F32 SHAPE_BUILDER_ENTRY_SNAP_PARAMETER_BIN_SIZE = 0.010f;
  40. const F32 SHAPE_BUILDER_CONVEXIFICATION_SIZE = 2.f * COLLISION_TOLERANCE;
  41. const F32 SHAPE_BUILDER_MIN_GEOMETRY_SIZE = 0.5f * COLLISION_TOLERANCE;
  42. class LLPhysicsVolumeParams : public LLVolumeParams
  43. {
  44. public:
  45. LLPhysicsVolumeParams( const LLVolumeParams& params, bool forceConvex ) :
  46. LLVolumeParams( params ),
  47. mForceConvex(forceConvex) {}
  48. bool operator==(const LLPhysicsVolumeParams &params) const
  49. {
  50. return ( LLVolumeParams::operator==(params) && (mForceConvex == params.mForceConvex) );
  51. }
  52. bool operator!=(const LLPhysicsVolumeParams &params) const
  53. {
  54. return !operator==(params);
  55. }
  56. bool operator<(const LLPhysicsVolumeParams &params) const
  57. {
  58. if ( LLVolumeParams::operator!=(params) )
  59. {
  60. return LLVolumeParams::operator<(params);
  61. }
  62. return (params.mForceConvex == false) && (mForceConvex == true);
  63. }
  64. bool shouldForceConvex() const { return mForceConvex; }
  65. private:
  66. bool mForceConvex;
  67. };
  68. class LLPhysicsShapeBuilderUtil
  69. {
  70. public:
  71. class PhysicsShapeSpecification
  72. {
  73. public:
  74. enum ShapeType
  75. {
  76. // Primitive types
  77. BOX,
  78. SPHERE,
  79. CYLINDER,
  80. USER_CONVEX, // User specified they wanted the convex hull of the volume
  81. PRIM_CONVEX, // Either a volume that is inherently convex but not a primitive type, or a shape
  82. // with dimensions such that will convexify it anyway.
  83. SCULPT, // Special case for traditional sculpts--they are the convex hull of a single particular set of volume params
  84. USER_MESH, // A user mesh. May or may not contain a convex decomposition.
  85. PRIM_MESH, // A non-convex volume which we have to represent accurately
  86. INVALID
  87. };
  88. PhysicsShapeSpecification() :
  89. mType( INVALID ),
  90. mScale( 0.f, 0.f, 0.f ),
  91. mCenter( 0.f, 0.f, 0.f ) {}
  92. bool isConvex() { return (mType != USER_MESH && mType != PRIM_MESH && mType != INVALID); }
  93. bool isMesh() { return (mType == USER_MESH) || (mType == PRIM_MESH); }
  94. ShapeType getType() { return mType; }
  95. const LLVector3& getScale() { return mScale; }
  96. const LLVector3& getCenter() { return mCenter; }
  97. private:
  98. friend class LLPhysicsShapeBuilderUtil;
  99. ShapeType mType;
  100. // Dimensions of an AABB around the shape
  101. LLVector3 mScale;
  102. // Offset of shape from origin of primitive's reference frame
  103. LLVector3 mCenter;
  104. };
  105. static void determinePhysicsShape( const LLPhysicsVolumeParams& volume_params, const LLVector3& scale, PhysicsShapeSpecification& specOut );
  106. };
  107. #endif //LL_PHYSICS_SHAPE_BUILDER_H