Exemplo n.º 1
0
def getRB(pos=Vec3(0, 0, 0), cshape=SphereShape(1)):
    """
    Return a Rigid Body plus auxiliary information (do *not* delete; see
    note below).

    .. note:: Do not delete the tuple until the end of the test
    because it may lead to memory access violations. The reason is that a
    rigid body requires several indepenent structures that need to remain
    in memory.
    """
    t = Transform(Quaternion(0, 0, 0, 1), pos)
    ms = DefaultMotionState(t)
    mass = 1

    # Build construction info and instantiate the rigid body.
    ci = RigidBodyConstructionInfo(mass, ms, cshape)
    return RigidBody(ci)
Exemplo n.º 2
0
inertia, principal = cs.calculatePrincipalAxisTransform(masses)
print('\nCenter of Mass: ', principal.getOrigin().topy())
print('Inertia Values: ', inertia)
print('Inertia Principal Axis: ', principal.getRotation().topy())
del t1, t2, csSphere

# Construct the rigid body for the compound shape based on the just computed
# inertia tensor.
print('\nTotal Mass: {}'.format(sum(masses)))
ci = azBullet.RigidBodyConstructionInfo(
    sum(masses),
    azBullet.DefaultMotionState(principal),
    cs,
    inertia,
)
body = RigidBody(ci)

# Add the body with its compound shape to the simulation.
sim.addRigidBody(body)
del masses, ci

# Apply an initial force and torque (only valid for the first simulation step
# because Bullet will clear all the forces afterwards).
body.clearForces()
body.applyCentralForce(Vec3(*(0, 1, 0)))
# body.applyTorque(Vec3(*(0, 1, 0)))

# Step the simulation and print the position of the Ball.
for ii in range(10):
    wt = body.getMotionState().getWorldTransform()
    pos = wt.getOrigin().topy()
Exemplo n.º 3
0
# Instantiate the Bullet simulation.
sim = azBullet.BulletBase()
sim.setGravity(Vec3(0, -10, 0))

# Create the collision shape for Ball and Ground.
ballShape = SphereShape(1)
groundShape = StaticPlaneShape(Vec3(0, 1, 0), 1)

# Create the rigid body for the Ground. Since it is a static body its mass must
# be zero.
mass = 0
groundRigidBodyState = DefaultMotionState(
    Transform(Quaternion(0, 0, 0, 1), Vec3(0, -1, 0)))
ci = RigidBodyConstructionInfo(mass, groundRigidBodyState, groundShape)
groundRigidBody = RigidBody(ci)
groundRigidBody.setRestitution(1.0)
sim.addRigidBody(groundRigidBody)
del mass, ci

# Create the rigid body for the Ball. Since it is a dynamic body we need to
# specify mass and inertia. The former we need to do ourselves but Bullet can
# do the heavy lifting for the Inertia and compute it for us.
fallRigidBodyState = DefaultMotionState(
    Transform(Quaternion(0, 0, 0, 1), Vec3(0, 20, 0)))
mass = 1
fallInertia = ballShape.calculateLocalInertia(mass)
ci = RigidBodyConstructionInfo(mass, fallRigidBodyState, ballShape,
                               fallInertia)
fallRigidBody = RigidBody(ci)
fallRigidBody.setRestitution(0.5)