ConeShape.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "ConeShape.h"
  25. #include "Context.h"
  26. #include "Node.h"
  27. #include "PhysicsUtils.h"
  28. #include <BulletCollision/CollisionShapes/btConeShape.h>
  29. OBJECTTYPESTATIC(ConeShape);
  30. static const float DEFAULT_RADIUS = 0.5f;
  31. static const float DEFAULT_HEIGHT = 1.0f;
  32. ConeShape::ConeShape(Context* context) :
  33. CollisionShape(context),
  34. radius_(DEFAULT_RADIUS),
  35. height_(DEFAULT_HEIGHT)
  36. {
  37. }
  38. void ConeShape::RegisterObject(Context* context)
  39. {
  40. context->RegisterFactory<ConeShape>();
  41. ATTRIBUTE(ConeShape, VAR_VECTOR3, "Offset Position", position_, Vector3::ZERO, AM_DEFAULT);
  42. ATTRIBUTE(ConeShape, VAR_QUATERNION, "Offset Rotation", rotation_, Quaternion::IDENTITY, AM_DEFAULT);
  43. ATTRIBUTE(ConeShape, VAR_FLOAT, "Radius", radius_, DEFAULT_RADIUS, AM_DEFAULT);
  44. ATTRIBUTE(ConeShape, VAR_FLOAT, "Height", height_, DEFAULT_HEIGHT, AM_DEFAULT);
  45. }
  46. void ConeShape::SetRadius(float radius)
  47. {
  48. if (radius != radius_)
  49. {
  50. radius_ = radius;
  51. UpdateCollisionShape();
  52. NotifyRigidBody();
  53. }
  54. }
  55. void ConeShape::SetHeight(float height)
  56. {
  57. if (height != height_)
  58. {
  59. height_ = height;
  60. UpdateCollisionShape();
  61. NotifyRigidBody();
  62. }
  63. }
  64. void ConeShape::UpdateCollisionShape()
  65. {
  66. if (node_)
  67. {
  68. delete shape_;
  69. shape_ = 0;
  70. shape_ = new btConeShape(radius_, height_);
  71. shape_->setLocalScaling(ToBtVector3(node_->GetWorldScale()));
  72. }
  73. }