Blender V2.61 - r43446

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 GENERIC_6DOF_SPRING_CONSTRAINT_H
00017 #define 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 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 internalUpdateSprings(btConstraintInfo2* info);
00043 public: 
00044     btGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA);
00045     void enableSpring(int index, bool onOff);
00046     void setStiffness(int index, btScalar stiffness);
00047     void setDamping(int index, btScalar damping);
00048     void setEquilibriumPoint(); // set the current constraint position/orientation as an equilibrium point for all DOF
00049     void setEquilibriumPoint(int index);  // set the current constraint position/orientation as an equilibrium point for given DOF
00050     void setEquilibriumPoint(int index, btScalar val);
00051 
00052     virtual void setAxis( const btVector3& axis1, const btVector3& axis2);
00053 
00054     virtual void getInfo2 (btConstraintInfo2* info);
00055 
00056     virtual int calculateSerializeBufferSize() const;
00058     virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
00059 
00060 };
00061 
00062 
00064 struct btGeneric6DofSpringConstraintData
00065 {
00066     btGeneric6DofConstraintData m_6dofData;
00067     
00068     int         m_springEnabled[6];
00069     float       m_equilibriumPoint[6];
00070     float       m_springStiffness[6];
00071     float       m_springDamping[6];
00072 };
00073 
00074 SIMD_FORCE_INLINE   int btGeneric6DofSpringConstraint::calculateSerializeBufferSize() const
00075 {
00076     return sizeof(btGeneric6DofSpringConstraintData);
00077 }
00078 
00080 SIMD_FORCE_INLINE   const char* btGeneric6DofSpringConstraint::serialize(void* dataBuffer, btSerializer* serializer) const
00081 {
00082     btGeneric6DofSpringConstraintData* dof = (btGeneric6DofSpringConstraintData*)dataBuffer;
00083     btGeneric6DofConstraint::serialize(&dof->m_6dofData,serializer);
00084 
00085     int i;
00086     for (i=0;i<6;i++)
00087     {
00088         dof->m_equilibriumPoint[i] = m_equilibriumPoint[i];
00089         dof->m_springDamping[i] = m_springDamping[i];
00090         dof->m_springEnabled[i] = m_springEnabled[i]? 1 : 0;
00091         dof->m_springStiffness[i] = m_springStiffness[i];
00092     }
00093     return "btGeneric6DofConstraintData";
00094 }
00095 
00096 #endif // GENERIC_6DOF_SPRING_CONSTRAINT_H
00097