Hi all,
I am struggling with the hinge angle in BulletHingeConstraint. In detail, I am wondering why a hinge constraint along the y-axis between two boxes, of which one is rotated by 180 degrees around the z-axis, has an initial hinge_angle of 180 degrees. To make this clear, here is an example:
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Vec3, Point3
from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletRigidBodyNode
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletHingeConstraint
from panda3d.bullet import BulletDebugNode
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
base.cam.setPos(0, -10, 0)
base.cam.lookAt(0, 0, 0)
# create a debug node to get debug view
self.debugNode = BulletDebugNode('Debug')
debugNP = self.render.attachNewNode(self.debugNode)
debugNP.show()
# create the world
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNode)
# create a box
box = BulletRigidBodyNode('Box')
box.setMass(0.0)
box.addShape(BulletBoxShape(Vec3(0.5, 0.5, 0.5)))
box.setDeactivationEnabled(False)
self.world.attachRigidBody(box)
np = self.render.attachNewNode(box)
model = self.loader.loadModel('box.egg')
model.flattenLight()
model.reparentTo(np)
np.setPos(0, 0, 0)
#create a second box
box2 = BulletRigidBodyNode('Box2')
box2.setMass(1.0)
box2.addShape(BulletBoxShape(Vec3(0.5, 0.5, 0.5)))
box2.setDeactivationEnabled(False)Joints
np = self.render.attachNewNode(box2)
self.world.attachRigidBody(box2)
model = self.loader.loadModel('box.egg')
model.flattenLight()
model.reparentTo(np)
np.setPos(2.0, 0, 0.0)
np.setHpr(180, 0, 0)
# create a joint between the boxes
self.joint = BulletHingeConstraint(
box,
box2,
Point3(1.0, 0, 0.0),
Point3(1.0, 0, 0.0),
Vec3(0, 1, 0),
Vec3(0, -1, 0))
self.world.attachConstraint(self.joint)
self.taskMgr.add(self.update, 'update')
# update function
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt)
print self.joint.get_hinge_angle()
return task.cont
app = MyApp()
app.run()
The given out hinge angles starts with 180 degree! In contrast, I would have expected it to start with zero degrees in the initial position. While it may seem stupid here to rotate the box around the z-axis, this may be perfectly justified when dealing with more complex objects. The problem when starting with 180 degrees is that the angle limits of the constraint cannot be used any longer as they have to be between -180 and 180 degrees.
To sum up, I wonder what I have to do with the HingeConstraint to obtain a zero degrees hinge angle in the initial condition even if one of the objects is rotated.
Thanks for your help!
Best
Timo