True Axis Physics SDK 1.2.0.1 Beta Documentation
www.trueaxis.com

BallAndSocketJointExample.cpp

Example of setting up a ball and socket joint.

//---------------------------------------------------------------------------------
// Ball and socket joint example
//---------------------------------------------------------------------------------

TA::Physics& physics = TA::Physics::GetInstance();

// Create 2 boxes
TA::DynamicObject* pObjectA = TA::DynamicObject::CreateNew();
TA::DynamicObject* pObjectB = TA::DynamicObject::CreateNew();
TA::AABB aabb(
    TA::Vec3(0.0f, 0.0f, 0.0f),  // center
    TA::Vec3(0.5f, 0.5f, 0.5f)); // extent
pObjectA->InitialiseAsABox(aabb);
pObjectB->InitialiseAsABox(aabb);

// Position the 2 boxes.
pObjectA->SetPosition(TA::Vec3(2.0f, 3.0f, 0.0f));
pObjectB->SetPosition(TA::Vec3(4.0f, 3.0f, 0.0f));

// Add the joint
TA::Vec3 v3JointWorldPos(3.0f, 3.0f, 0.0f);
pObjectA->AddJointTypeSocket(
    pObjectB,                                   // The object to join too.
    v3JointWorldPos / pObjectA->GetFrame(),     // local position on pObjectA (the divide opperator does an inverse trasform)
    v3JointWorldPos / pObjectB->GetFrame(),     // local position on pObjectB
    TA::Vec3(-1.0f, 0.0f, 0.0f),                // normalA
    TA::Vec3(1.0f, 0.0f, 0.0f),                 // normalB
    0.5f);                                      // The maximu angle between normalA and -normalB.

// Add the objects to the simulation
physics.AddDynamicObject(pObjectA);
physics.AddDynamicObject(pObjectB);


© Copyright 2004-2006 TRUE AXIS PTY LTD Australia. All rights reserved.