def makeBox(pos=position_init, vel=velocity_init):
    if (True):
        box = btConvexHullShape()
        box.addPoint(btVector3(-1.0, 1.0, -1.0))
        box.addPoint(btVector3(-1.0, -1.0, -1.0))
        box.addPoint(btVector3(-1.0, -1.0, 1.0))
        box.addPoint(btVector3(-1.0, 1.0, 1.0))
        box.addPoint(btVector3(1.0, 1.0, 1.0))
        box.addPoint(btVector3(1.0, 1.0, -1.0))
        box.addPoint(btVector3(1.0, -1.0, -1.0))
        box.addPoint(btVector3(1.0, -1.0, 1.0))
    else:
        box = btBoxShape(btVector3(1.0, 1.0, 1.0))

    # a bullet shape with a mass (1.0)
    box1 = BulletWeightedShape(box, 1.0)

    # A Bullet Dynamical System : a shape + a mass + position and velocity
    body = BulletDS(box1,
                    [0, 0, pos, 1., 0, 0, 0],
                    [0, 0, vel, 0., 0., 0.])
    
    # set external forces
    weight = [0, 0, - box1.mass() * g]
    body.setFExtPtr(weight)

    return body
예제 #2
0
    def importObject(self, name, translation, orientation,
                     velocity, contactors, mass, inertia, body_class, shape_class):

        if body_class is None:
            body_class = BulletDS

        if self._broadphase is not None and 'input' in self._data:
            if mass == 0.:
                # a static object
                rbase = btQuaternion(orientation[1],
                                     orientation[2],
                                     orientation[3],
                                     orientation[0])

                for c in contactors:
                    (w, x, y, z) = c.orientation
                    c_orientation = btQuaternion(x, y, z, w)
                    rc_orientation = mul(rbase, c_orientation)

                    c_origin = btVector3(c.translation[0],
                                         c.translation[1],
                                         c.translation[2])

                    rc_origin = quatRotate(rbase, c_origin)

                    rc_sorigin = btVector3(rc_origin.x() + translation[0],
                                           rc_origin.y() + translation[1],
                                           rc_origin.z() + translation[2])

                    static_cobj = btCollisionObject()
                    static_cobj.setCollisionFlags(
                        btCollisionObject.CF_STATIC_OBJECT)

                    self._static_origins.append(rc_sorigin)

                    self._static_orientations.append(rc_orientation)
                    transform = btTransform(rc_orientation)
                    transform.setOrigin(rc_sorigin)
                    self._static_transforms.append(transform)
                    static_cobj.setWorldTransform(transform)

                    static_cobj.setCollisionShape(
                        self._shape.get(c.name))
                    self._static_cobjs.append(static_cobj)
                    self._broadphase.addStaticObject(static_cobj,
                                                     int(c.group))

            else:
                # a moving object

                bws = BulletWeightedShape(
                    self._shape.get(contactors[0].name), mass)

                if inertia is not None:
                    bws.setInertia(inertia[0], inertia[1], inertia[2])

                body = body_class(bws,
                                  translation + orientation,
                                  velocity,
                                  contactors[0].translation,
                                  contactors[0].orientation,
                                  contactors[0].group)

                for contactor in contactors[1:]:
                    shape_id = self._shapeid[contactor.name]

                    body.addCollisionShape(self._shape.get(contactor.name),
                                           contactor.translation,
                                           contactor.orientation,
                                           contactor.group)

                # set external forces
                self._set_external_forces(body)

                # add the dynamical system to the non smooth
                # dynamical system
                nsds = self._broadphase.model().nonSmoothDynamicalSystem()
                nsds.insertDynamicalSystem(body)
                nsds.setOSI(body, self._osi)
                nsds.setName(body, str(name))
예제 #3
0
if (True):
    box = btConvexHullShape()
    box.addPoint(btVector3(-1.0, 1.0, -1.0))
    box.addPoint(btVector3(-1.0, -1.0, -1.0))
    box.addPoint(btVector3(-1.0, -1.0, 1.0))
    box.addPoint(btVector3(-1.0, 1.0, 1.0))
    box.addPoint(btVector3(1.0, 1.0, 1.0))
    box.addPoint(btVector3(1.0, 1.0, -1.0))
    box.addPoint(btVector3(1.0, -1.0, -1.0))
    box.addPoint(btVector3(1.0, -1.0, 1.0))
else:
    box = btBoxShape(btVector3(1.0, 1.0, 1.0))

# a bullet shape with a mass (1.0)
box1 = BulletWeightedShape(box, 1.0)

# A Bullet Dynamical System : a shape + a mass + position and velocity
body = BulletDS(box1, [0, 0, position_init, 1., 0, 0, 0],
                [0, 0, velocity_init, 0., 0., 0.])

# set external forces
weight = [0, 0, -box1.mass() * g]
body.setFExtPtr(weight)

#
# Model
#
bouncingBox = Model(t0, T)

# add the dynamical system to the non smooth dynamical system
예제 #4
0
if (True):
    box = btConvexHullShape()
    box.addPoint(btVector3(-1.0, 1.0, -1.0))
    box.addPoint(btVector3(-1.0, -1.0, -1.0))
    box.addPoint(btVector3(-1.0, -1.0, 1.0))
    box.addPoint(btVector3(-1.0, 1.0, 1.0))
    box.addPoint(btVector3(1.0, 1.0, 1.0))
    box.addPoint(btVector3(1.0, 1.0, -1.0))
    box.addPoint(btVector3(1.0, -1.0, -1.0))
    box.addPoint(btVector3(1.0, -1.0, 1.0))
else:
    box = btBoxShape(btVector3(1.0, 1.0, 1.0))

# a bullet shape with a mass (1.0)
box1 = BulletWeightedShape(box, 1.0)

# A Bullet Dynamical System : a shape + a mass + position and velocity
body = BulletDS(box1,
                [0, 0, position_init, 1., 0, 0, 0],
                [0, 0, velocity_init, 0., 0., 0.])

# set external forces
weight = [0, 0, - box1.mass() * g]
body.setFExtPtr(weight)

#
# Model
#
bouncingBox = Model(t0, T)