Ejemplo n.º 1
0
    def add_sphere_at(self, x, y, z, radius, color, room):
        s = Primitives.getSphere(radius)

        colorname = 'added_sphere_%d' % id(s)
        TextureManager.getInstance().addTexture(
            colorname, Texture(1, 1, color))
        s.setTexture(colorname)
        s.build()
        if not hasattr(self, 'extra_shapes'):
            self.extra_shapes = []
        self.extra_shapes.append((s, x, y, z))
        room.world.addObject(s)
Ejemplo n.º 2
0
    def __init__(self, x, y, z, mass=1, scale=1, draw_as_cylinder=False,
                 color=Color.blue, overdraw_length=1, overdraw_radius=1,
                 flat_shading=False):

        if draw_as_cylinder:
            if y is max(x, y, z):
                radius = (x + z) / 4 * overdraw_radius
                self.shape = Primitives.getCylinder(
                    90, radius, y / (radius * 2) * overdraw_length)
            if z is max(x, y, z):
                radius = (x + y) / 4 * overdraw_radius
                self.shape = Primitives.getCylinder(
                    90, radius, z / (radius * 2) * overdraw_length)
                self.shape.rotateX(math.pi / 2)
                self.shape.rotateMesh()
        else:
            self.shape = createBox(x / 2.0 * scale,
                                   y / 2.0 * scale,
                                   z / 2.0 * scale)
        if flat_shading:
            self.shape.shadingMode = Object3D.SHADING_FAKED_FLAT

        colorname = 'box%d' % id(self)
        TextureManager.getInstance().addTexture(colorname, Texture(1, 1, color))
        self.shape.setTexture(colorname)
        self.shape.build()

        shape = BoxShape(Vector3f(x / 2.0, y / 2.0, z / 2.0))

        inertia = Vector3f(0, 0, 0)
        shape.calculateLocalInertia(mass, inertia)

        t = Transform()
        t.setIdentity()

        ms = DefaultMotionState(t)
        rb = RigidBodyConstructionInfo(mass, ms, shape, inertia)
        self.physics = RigidBody(rb)
Ejemplo n.º 3
0
    def __init__(self, r, mass=1, color=Color.red):
        colorname = 'sphere_%d' % id(self)
        self.shape = Primitives.getSphere(r)
        TextureManager.getInstance().addTexture(
            colorname, Texture(1, 1, color))
        self.shape.setTexture(colorname)
        self.shape.build()

        shape = BoxShape(Vector3f(r / 2.0, r / 2.0, r / 2.0))

        inertia = Vector3f(0, 0, 0)
        shape.calculateLocalInertia(mass, inertia)

        t = Transform()
        t.setIdentity()

        ms = DefaultMotionState(t)
        rb = RigidBodyConstructionInfo(mass, ms, shape, inertia)
        self.physics = RigidBody(rb)