示例#1
0
    def __init__(self, filename, view, mass, position=eVector3()):
        super(CueBall, self).__init__(filename, view)
        self.radius = self.model.dimension.z / 2.0
        self.mass = mass
        # Update z pos from radius
        position.z = self.radius

        # Init Transform
        transform = Transform()
        self.position = position
        self.do_transformation_matrix()
        self.mnumpy = array(self.m, 'f')
        transform.setFromOpenGLMatrix(self.mnumpy)

        # The Rigid Body
        mass = self.mass * SCALE_FACTOR
        shape = SphereShape(self.radius)
        i = shape.getLocalInertia(mass) * 0.65
        self.motion = DefaultMotionState()
        self.motion.setWorldTransform(transform)
        self.body = RigidBody.fromConstructionInfo(self.motion,         #  MotionState motion
                                                   shape,               #  CollisionShape shape
                                                   mass,                	#  btScalar mass
                                                   bVector3(i.x, i.y, i.z), #  Vector3 inertia
                                                   transform,           #  Transform worldTransform
                                                   0.2,              	#  btScalar linearDamping
                                                   0.65,              	#  btScalar angularDamping
                                                   0.25,                #  btScalar friction
                                                   0.7,          		#  btScalar restitution
                                                   1.5,                 #  btScalar linearSleepingThreshold
                                                   1.5)                 #  btScalar angularSleepingThreshold

        self.body.setContactProcessingThreshold(0)
        self.body.setCcdMotionThreshold(0)
        self.body.setHitFraction(0.1 * SCALE_FACTOR)
示例#2
0
    def __init__(self, filename, view):
        Model.__init__(self, filename, view)
        TriangleMesh.__init__(self, filename)

        # Create rigid body
        tvia = TriangleIndexVertexArray()
        tvia.addIndexedMesh(self.mesh)
        shape = BvhTriangleMeshShape(tvia)
        shape.buildOptimizedBvh()
        transform = Transform()
        transform.setIdentity()
        transform.setOrigin(bVector3(0, 0, 0))
        motion = DefaultMotionState()
        motion.setWorldTransform(transform)

        self.body = RigidBody.fromConstructionInfo(motion,              #  MotionState motion
                                                   shape,               #  CollisionShape shape
                                                   0.0,                 #  btScalar mass
                                                   bVector3(0, 0, 0),   #  Vector3 inertia
                                                   transform,           #  Transform worldTransform
                                                   0.0,               	#  btScalar linearDamping
                                                   0.0,               	#  btScalar angularDamping
                                                   0.75,                #  btScalar friction
                                                   0.95,                #  btScalar restitution
                                                   0.0,                 #  btScalar linearSleepingThreshold
                                                   0.0)                 #  btScalar angularSleepingThreshold
        self.motion = motion
        self.body.setContactProcessingThreshold(0)
示例#3
0
    def __init__(self, filename, view, cball_radius):
        super(CueStick, self).__init__(filename, view)
        self.half = self.model.dimension / 2.0
        self.tip_radius = self.half.x
        self.pivot = eVector3(0, 0, self.half.z + cball_radius)
        self.org_pivot = eVector3(*self.pivot)
        shape = CapsuleShapeZ(self.tip_radius, self.model.dimension.z - self.tip_radius * 2)
        #shape = CylinderShapeZ(bVector3(*self.half))
        transform = Transform()
        transform.setIdentity()
        self.motion = CSMotionState()
        self.motion.cue = self
        self.delta = 0.
        self.dx = 0.
        self.dy = 0.
        self.motion.setWorldTransform(transform)
        self.body = RigidBody.fromConstructionInfo(self.motion,         #  MotionState motion
                                                   shape,               #  CollisionShape shape
                                                   0.0,                 #  btScalar mass
                                                   bVector3(0, 0, 0),   #  Vector3 inertia
                                                   transform,           #  Transform worldTransform
                                                   0.0,                 #  btScalar linearDamping
                                                   0.0,                 #  btScalar angularDamping
                                                   0.0,                 #  btScalar friction
                                                   0.71,                #  btScalar restitution
                                                   0.0,                 #  btScalar linearSleepingThreshold
                                                   0.0)                 #  btScalar angularSleepingThreshold
        self.body.setContactProcessingThreshold(0)
        self.body.setCcdMotionThreshold(0)
        self.body.setHitFraction(0.1 * SCALE_FACTOR)
        self.body.setGravity(bVector3(0, 0, 0))

        # Make it kinematic body with collision contacts generation but no response impulses
        flags = self.body.getCollisionFlags() | CueStick.CF_KINEMATIC_OBJECT | CueStick.CF_NO_CONTACT_RESPONSE
        self.body.setCollisionFlags(flags)
        self.body.setActivationState(DISABLE_DEACTIVATION)