btGeneric6DofSpringConstraint.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
00003 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc. 
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
00017 #define BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
00018 
00019 
00020 #include "LinearMath/btVector3.h"
00021 #include "btTypedConstraint.h"
00022 #include "btGeneric6DofConstraint.h"
00023 
00024 
00026 
00034 
00035 ATTRIBUTE_ALIGNED16(class) btGeneric6DofSpringConstraint : public btGeneric6DofConstraint
00036 {
00037 protected:
00038         bool            m_springEnabled[6];
00039         btScalar        m_equilibriumPoint[6];
00040         btScalar        m_springStiffness[6];
00041         btScalar        m_springDamping[6]; // between 0 and 1 (1 == no damping)
00042         void init();
00043         void internalUpdateSprings(btConstraintInfo2* info);
00044 public: 
00045         
00046         BT_DECLARE_ALIGNED_ALLOCATOR();
00047         
00048     btGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
00049     btGeneric6DofSpringConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB);
00050         void enableSpring(int index, bool onOff);
00051         void setStiffness(int index, btScalar stiffness);
00052         void setDamping(int index, btScalar damping);
00053         void setEquilibriumPoint(); // set the current constraint position/orientation as an equilibrium point for all DOF
00054         void setEquilibriumPoint(int index);  // set the current constraint position/orientation as an equilibrium point for given DOF
00055         void setEquilibriumPoint(int index, btScalar val);
00056 
00057         virtual void setAxis( const btVector3& axis1, const btVector3& axis2);
00058 
00059         virtual void getInfo2 (btConstraintInfo2* info);
00060 
00061         virtual int     calculateSerializeBufferSize() const;
00063         virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
00064 
00065 };
00066 
00067 
00069 struct btGeneric6DofSpringConstraintData
00070 {
00071         btGeneric6DofConstraintData     m_6dofData;
00072         
00073         int                     m_springEnabled[6];
00074         float           m_equilibriumPoint[6];
00075         float           m_springStiffness[6];
00076         float           m_springDamping[6];
00077 };
00078 
00079 SIMD_FORCE_INLINE       int     btGeneric6DofSpringConstraint::calculateSerializeBufferSize() const
00080 {
00081         return sizeof(btGeneric6DofSpringConstraintData);
00082 }
00083 
00085 SIMD_FORCE_INLINE       const char*     btGeneric6DofSpringConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
00086 {
00087         btGeneric6DofSpringConstraintData* dof = (btGeneric6DofSpringConstraintData*)dataBuffer;
00088         btGeneric6DofConstraint::serialize(&dof->m_6dofData,serializer);
00089 
00090         int i;
00091         for (i=0;i<6;i++)
00092         {
00093                 dof->m_equilibriumPoint[i] = (float)m_equilibriumPoint[i];
00094                 dof->m_springDamping[i] = (float)m_springDamping[i];
00095                 dof->m_springEnabled[i] = m_springEnabled[i]? 1 : 0;
00096                 dof->m_springStiffness[i] = (float)m_springStiffness[i];
00097         }
00098         return "btGeneric6DofSpringConstraintData";
00099 }
00100 
00101 #endif // BT_GENERIC_6DOF_SPRING_CONSTRAINT_H
00102