spring between 2 rigid bodies

Please don't post Bullet support questions here, use the above forums instead.
Michel Sanner
Posts: 1
Joined: Thu Aug 12, 2010 6:41 pm

spring between 2 rigid bodies

Post by Michel Sanner »

Hello

I am new to Bullet and might be missing something trivial here.
I create a world with no gravity and add a static rigid body sphere at (0,0,0) and
a moving rigid body sphere at (5.,0,0). I connect them with a spring which pulls
the moving sphere toward (0,0,0). As I run the simulation, the moving sphere
penetrates the static sphere as if there was no collision detection between them.

I wonder what I am missing here!

Here is pseudo code of what I do

// I create a DiscreteDynamicsWorld and set the gravity to (0,0,0)

collConfig = btDefaultCollisionConfiguration()
dispatcher = btCollisionDispatcher(ccf)
solver = btSequentialImpulseConstraintSolver()
broadphase = btDbvtBroadphase()
world = btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collConfig)

// create fixed anchor sphere
sphereShape = btSphereShape(1.0)
transform = btTransform()
transform.setIdentity()
transform.setOrigin(btVector3(0, 0, 0.))
motionState = btDefaultMotionState(transform)
body1 = btRigidBody( 0.0 , motionState, shape, localInertia)
world.addRigidBody(body1)

// create moving sphere
transform = btTransform()
transform.setIdentity()
transform.setOrigin(btVector3(0, 0, 0.))
motionState = btDefaultMotionState(transform)
body2 = btRigidBody( 5.0 , motionState, shape, localInertia)
world.addRigidBody(body2)

// create a spring
frameInA = libbullet.btTransform()
frameInA.setIdentity()
frameInA.setOrigin(btVector3(0., 0., 0.))

frameInB = libbullet.btTransform()
frameInB.setIdentity()
frameInB.setOrigin(btVector3( 0., 0, 0))

spring = libbullet.btGeneric6DofSpringConstraint(
body1, body2, frameInA, frameInB, True)
world.addConstraint(spring, True)
spring.enableSpring(0, True)

Thanks for any suggestions
priest_wd
Posts: 10
Joined: Wed Sep 22, 2010 3:33 pm

Re: spring between 2 rigid bodies

Post by priest_wd »

Hi Michel

I think you have to set the transform of your moving sphere like this

transform.setOrigin(btVector3(5., 0, 0.))

looks like both objects were in the same coordinates

Greetings