BSConstraintSpring.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyrightD
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using OpenMetaverse;
  31. namespace OpenSim.Region.Physics.BulletSPlugin
  32. {
  33. public sealed class BSConstraintSpring : BSConstraint6Dof
  34. {
  35. public override ConstraintType Type { get { return ConstraintType.D6_SPRING_CONSTRAINT_TYPE; } }
  36. public BSConstraintSpring(BulletWorld world, BulletBody obj1, BulletBody obj2,
  37. Vector3 frame1Loc, Quaternion frame1Rot,
  38. Vector3 frame2Loc, Quaternion frame2Rot,
  39. bool useLinearReferenceFrameA, bool disableCollisionsBetweenLinkedBodies)
  40. :base(world, obj1, obj2)
  41. {
  42. m_constraint = PhysicsScene.PE.Create6DofSpringConstraint(world, obj1, obj2,
  43. frame1Loc, frame1Rot, frame2Loc, frame2Rot,
  44. useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
  45. m_enabled = true;
  46. PhysicsScene.DetailLog("{0},BSConstraintSpring,create,wID={1}, rID={2}, rBody={3}, cID={4}, cBody={5}",
  47. obj1.ID, world.worldID, obj1.ID, obj1.AddrString, obj2.ID, obj2.AddrString);
  48. PhysicsScene.DetailLog("{0},BSConstraintSpring,create, f1Loc={1},f1Rot={2},f2Loc={3},f2Rot={4},usefA={5},disCol={6}",
  49. m_body1.ID, frame1Loc, frame1Rot, frame2Loc, frame2Rot, useLinearReferenceFrameA, disableCollisionsBetweenLinkedBodies);
  50. }
  51. public bool SetAxisEnable(int pIndex, bool pAxisEnable)
  52. {
  53. PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEnable,obj1ID={1},obj2ID={2},indx={3},enable={4}",
  54. m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pAxisEnable);
  55. PhysicsScene.PE.SpringEnable(m_constraint, pIndex, BSParam.NumericBool(pAxisEnable));
  56. return true;
  57. }
  58. public bool SetStiffness(int pIndex, float pStiffness)
  59. {
  60. PhysicsScene.DetailLog("{0},BSConstraintSpring.SetStiffness,obj1ID={1},obj2ID={2},indx={3},stiff={4}",
  61. m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pStiffness);
  62. PhysicsScene.PE.SpringSetStiffness(m_constraint, pIndex, pStiffness);
  63. return true;
  64. }
  65. public bool SetDamping(int pIndex, float pDamping)
  66. {
  67. PhysicsScene.DetailLog("{0},BSConstraintSpring.SetDamping,obj1ID={1},obj2ID={2},indx={3},damp={4}",
  68. m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pDamping);
  69. PhysicsScene.PE.SpringSetDamping(m_constraint, pIndex, pDamping);
  70. return true;
  71. }
  72. public bool SetEquilibriumPoint(int pIndex, float pEqPoint)
  73. {
  74. PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEquilibriumPoint,obj1ID={1},obj2ID={2},indx={3},eqPoint={4}",
  75. m_body1.ID, m_body1.ID, m_body2.ID, pIndex, pEqPoint);
  76. PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, pIndex, pEqPoint);
  77. return true;
  78. }
  79. public bool SetEquilibriumPoint(Vector3 linearEq, Vector3 angularEq)
  80. {
  81. PhysicsScene.DetailLog("{0},BSConstraintSpring.SetEquilibriumPoint,obj1ID={1},obj2ID={2},linearEq={3},angularEq={4}",
  82. m_body1.ID, m_body1.ID, m_body2.ID, linearEq, angularEq);
  83. PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 0, linearEq.X);
  84. PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 1, linearEq.Y);
  85. PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 2, linearEq.Z);
  86. PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 3, angularEq.X);
  87. PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 4, angularEq.Y);
  88. PhysicsScene.PE.SpringSetEquilibriumPoint(m_constraint, 5, angularEq.Z);
  89. return true;
  90. }
  91. }
  92. }