Exemplo n.º 1
0
    def update(self):
        # clamp
        while (self.m_azi < -180.0):
            self.m_azi+= 360.0
        while (self.m_azi > 180.0):
            self.m_azi-= 360.0

        if (self.m_ele < -89.0):
            self.m_ele = -89.0
        if (self.m_ele > 89.0):
            self.m_ele = 89.0

        if (self.m_cameraDistance < 0.1):
            self.m_cameraDistance = 0.1

        # calc camera position
        razi = self.m_azi * 0.01745329251994329547 # rads per deg
        head=bullet.btQuaternion(self.m_view.up, razi)

        eyePos=Vector3(0.0, 0.0, -self.m_cameraDistance)
        forward=Vector3(*eyePos[:])
        if (forward.length2() < bullet.SIMD_EPSILON):
            forward=Vector3(1.0, 0.0, 0.0)
        right=self.m_view.up.cross(forward)
        rele = self.m_ele * 0.01745329251994329547 # rads per deg
        pitch=bullet.btQuaternion(right, -rele)

        self.m_view.position=self.m_view.target+(
                bullet.btMatrix3x3(head)*bullet.btMatrix3x3(pitch)).apply(eyePos);
Exemplo n.º 2
0
    def	shootBox(self, destination):
        if not self.m_dynamicsWorld:
            return
        print 'shootBox'
        mass = 1.0;
        startTransform=bullet.btTransform();
        startTransform.setIdentity();
        camPos = self.getCameraPosition();
        startTransform.setOrigin(camPos);

        self.setShootBoxShape ();

        body = self.localCreateRigidBody(mass, startTransform, self.m_shootBoxShape);
        body.setLinearFactor((1,1,1));

        linVel= vector3.normalize(
                (destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]));
        linVel=vector3.mul(linVel, self.m_ShootBoxInitialSpeed);

        body.getWorldTransform().setOrigin(camPos);
        body.getWorldTransform().setRotation(bullet.btQuaternion(0,0,0,1));
        body.setLinearVelocity(linVel);
        body.setAngularVelocity((0,0,0));
        body.setCcdMotionThreshold(0.5);
        body.setCcdSweptSphereRadius(0.9);
Exemplo n.º 3
0
    def updateCamera(self):
        rele = self.m_ele * 0.01745329251994329547;# rads per deg
        razi = self.m_azi * 0.01745329251994329547;# rads per deg

        rot=bullet.btQuaternion(self.m_cameraUp, razi);

        eyePos=[0, 0, 0];
        eyePos[self.m_forwardAxis] = -self.m_cameraDistance;
        eyePos=tuple(eyePos)

        forward=(eyePos[0], eyePos[1], eyePos[2]);
        if (vector3.length2(forward) < bullet.SIMD_EPSILON):
            forward=(1.0, 0.0, 0.0);

        right = vector3.cross(self.m_cameraUp, forward);
        roll=bullet.btQuaternion(right,-rele);

        m=bullet.btMatrix3x3(rot) * bullet.btMatrix3x3(roll)
        eyePos =m.apply(eyePos);

        self.m_cameraPosition=vector3.add(eyePos, self.m_cameraTargetPosition);

        if (self.m_glutScreenWidth == 0 and self.m_glutScreenHeight == 0):
            return;

        aspect = float(self.m_glutScreenWidth) / float(self.m_glutScreenHeight);
        assert(aspect!=0.0)

        extents=(aspect * 1.0, 1.0, 0.0);


        if (self.m_ortho):
            # reset matrix

            extents *= self.m_cameraDistance;
            lower = self.m_cameraTargetPosition - extents;
            upper = self.m_cameraTargetPosition + extents;

        else:
            pass
Exemplo n.º 4
0
    def shootBox(self, world, camPos, destination):
        startTransform=bullet.btTransform()
        startTransform.setIdentity()

        body = world.localCreateRigidBody(1.0, startTransform, self.m_shootBoxShape)

        body.setLinearFactor((1.0,1.0,1.0))

        body.getWorldTransform().setOrigin(camPos);
        body.getWorldTransform().setRotation(bullet.btQuaternion(0,0,0,1));
        linVel=Vector3(
                destination[0]-camPos[0],
                destination[1]-camPos[1],
                destination[2]-camPos[2]).normalize()*self.m_ShootBoxInitialSpeed
        body.setLinearVelocity(linVel)
        body.setAngularVelocity((0.0, 0.0, 0.0))
        body.setCcdMotionThreshold(0.5)
        body.setCcdSweptSphereRadius(0.9)
Exemplo n.º 5
0
    def updateCamera(self):
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        rele = self.m_ele * 0.01745329251994329547;# rads per deg
        razi = self.m_azi * 0.01745329251994329547;# rads per deg

        rot=bullet.btQuaternion(self.m_cameraUp, razi);

        eyePos=[0, 0, 0];
        eyePos[self.m_forwardAxis] = -self.m_cameraDistance;
        eyePos=tuple(eyePos)

        forward=(eyePos[0], eyePos[1], eyePos[2]);
        if (vector3.length2(forward) < bullet.SIMD_EPSILON):
            forward=(1.0, 0.0, 0.0);

        right = vector3.cross(self.m_cameraUp, forward);
        roll=bullet.btQuaternion(right,-rele);

        m=bullet.btMatrix3x3(rot) * bullet.btMatrix3x3(roll)
        eyePos =m.apply(eyePos);

        self.m_cameraPosition=vector3.add(eyePos, self.m_cameraTargetPosition);

        if (self.m_glutScreenWidth == 0 and self.m_glutScreenHeight == 0):
            return;

        aspect = float(self.m_glutScreenWidth) / float(self.m_glutScreenHeight);
        assert(aspect!=0.0)

        extents=(aspect * 1.0, 1.0, 0.0);


        if (self.m_ortho):
            # reset matrix
            glLoadIdentity();

            extents *= self.m_cameraDistance;
            lower = self.m_cameraTargetPosition - extents;
            upper = self.m_cameraTargetPosition + extents;
            # gluOrtho2D(lower.x, upper.x, lower.y, upper.y);
            glOrtho(lower.getX(), upper.getX(),
                    lower.getY(), upper.getY(),
                    -1000, 1000);

            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            # glTranslatef(100, 210, 0);
        else:
            # glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0);
            glFrustum (-aspect * self.m_frustumZNear, aspect * self.m_frustumZNear,
                    -self.m_frustumZNear, self.m_frustumZNear,
                    self.m_frustumZNear, self.m_frustumZFar);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();
            gluLookAt(
                    self.m_cameraPosition[0], self.m_cameraPosition[1], self.m_cameraPosition[2],
                    self.m_cameraTargetPosition[0],
                    self.m_cameraTargetPosition[1],
                    self.m_cameraTargetPosition[2],
                    self.m_cameraUp[0],self.m_cameraUp[1],self.m_cameraUp[2]);
Exemplo n.º 6
0
if __name__ == "__main__":
    broadphase = bullet.btDbvtBroadphase()
    collisionConfiguration = bullet.btDefaultCollisionConfiguration()
    dispatcher = bullet.btCollisionDispatcher(collisionConfiguration)

    solver = bullet.btSequentialImpulseConstraintSolver()
    dynamicsWorld = bullet.btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration)

    dynamicsWorld.setGravity((0, -10, 0))

    groundShape = bullet.btStaticPlaneShape((0, 1, 0), 1)

    fallShape = bullet.btSphereShape(1)

    groundMotionState = bullet.btDefaultMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), (0, -1, 0)))

    groundRigidBodyCI = bullet.btRigidBodyConstructionInfo(0, groundMotionState, groundShape, (0, 0, 0))
    groundRigidBody = bullet.btRigidBody(groundRigidBodyCI)
    dynamicsWorld.addRigidBody(groundRigidBody)

    fallMotionState = bullet.btDefaultMotionState(bullet.btTransform(bullet.btQuaternion(0, 0, 0, 1), (0, 50, 0)))

    mass = 1
    fallInertia = (0, 0, 0)
    fallShape.calculateLocalInertia(mass, fallInertia)
    fallRigidBodyCI = bullet.btRigidBodyConstructionInfo(mass, fallMotionState, fallShape, fallInertia)
    fallRigidBody = bullet.btRigidBody(fallRigidBodyCI)
    dynamicsWorld.addRigidBody(fallRigidBody)

    for i in range(300):