#include "Generic6DofSpringConstraint.h"
#include "BulletCLIMath.h"

namespace BulletCLI 
{
    Generic6DofSpringConstraint::Generic6DofSpringConstraint(RigidBody^ rbA,RigidBody^ rbB,Matrix frameInA,Matrix frameInB)
    {
        btTransform* fA=BulletCLI::XMatrixToBTTransform(frameInA);
        btTransform* fB=BulletCLI::XMatrixToBTTransform(frameInB);
        this->m_p=new ::btGeneric6DofSpringConstraint(*(rbA->GetPtr()),*(rbB->GetPtr()),*fA,*fB,true);
        delete fA;
        delete fB;
    }
	Generic6DofSpringConstraint::~Generic6DofSpringConstraint()
    {
        this->!Generic6DofSpringConstraint();
    }
	Generic6DofSpringConstraint::!Generic6DofSpringConstraint()
    {
        delete this->m_p;
    }
    void Generic6DofSpringConstraint::SetAngularUpperLimit(Vector3 angularUpper)
    {
        btVector3* angUp=BulletCLI::XVectorToBTVector(angularUpper);
        this->m_p->setAngularUpperLimit(*angUp);
        delete angUp;
    }
    void Generic6DofSpringConstraint::SetAngularLowerLimit(Vector3 angularLower)
    {
        btVector3* angLw=BulletCLI::XVectorToBTVector(angularLower);
        this->m_p->setAngularLowerLimit(*angLw);
        delete angLw;
    }
    void Generic6DofSpringConstraint::SetLinearUpperLimit(Vector3 linearUpper)
    {
        btVector3* linUp=BulletCLI::XVectorToBTVector(linearUpper);
        this->m_p->setLinearUpperLimit(*linUp);
        delete linUp;
    }
    void Generic6DofSpringConstraint::SetLinearLowerLimit(Vector3 linearLower)
    {
        btVector3* linLw=BulletCLI::XVectorToBTVector(linearLower);
        this->m_p->setLinearLowerLimit(*linLw);
        delete linLw;
    }
    void Generic6DofSpringConstraint::SetStiffness(int index,float stiffness)
    {
        btScalar stif(stiffness);
        this->m_p->setStiffness(index,stif);
    }
}