Is it possible to create physics simulation without the render
object?
I tried but it prints the identity matrices:
from panda3d.bullet import BulletWorld
from panda3d.core import Vec3
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletRigidBodyNode
world = BulletWorld()
world.setGravity(Vec3(0, 0, -9.81))
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
node = BulletRigidBodyNode('Box')
node.setMass(1.0)
node.addShape(shape)
world.attachRigidBody(node)
for i in range(10):
world.doPhysics(0.016)
print(node.getShapeTransform(0))
Solution:
from panda3d.bullet import BulletWorld
from panda3d.core import TransformState, Vec3, Quat, Point3
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletRigidBodyNode
world = BulletWorld()
world.setGravity(Vec3(0, 0, -9.81))
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
node = BulletRigidBodyNode('Box')
node.setMass(1.0)
p = Point3(1, 0, 0)
q = Quat.identQuat()
s = Vec3(2, 2, 2)
transform = TransformState.make_pos_quat_scale(p, q, s)
node.setTransform(transform)
node.addShape(shape)
world.attachRigidBody(node)
for i in range(10):
world.doPhysics(0.016)
print(node.getTransform())
Output:
T:(pos 1 0 0 scale 2)
T:(pos 1 0 -0.002507 scale 2)
T:(pos 1 0 -0.007521 scale 2)
T:(pos 1 0 -0.015042 scale 2)
T:(pos 1 0 -0.02507 scale 2)
T:(pos 1 0 -0.037605 scale 2)
T:(pos 1 0 -0.052647 scale 2)
T:(pos 1 0 -0.070196 scale 2)
T:(pos 1 0 -0.090252 scale 2)
T:(pos 1 0 -0.112815 scale 2)