예제 #1
0
    def __init__(self, model, shape, element, level):
        Object.__init__(self, model, shape, element)

        cfg = Config('physics', 'Ship')

        self.move_force_sz = cfg.get('move_force')
        self.spin_velocity = cfg.get('spin_velocity')
        self.strafe_force = cfg.get('strafe_force')
        self.shape.forces_res.append(cfg.get('vacuum_resistance'))
        self.breake_rate = cfg.get('breake_rate')

        self.mouse_sensivity = Config('game', 'Mouse').get('sensivity')

        self.level = level

        self.rotation = Quaternion.from_axis_rotations(0., 0., 0.)

        self.ship_dir = None
        self.up_dir = None

        self.spinning = {
            'up': False,
            'down': False,
            'left': False,
            'right': False
        }

        self.vectors = {
            'up': (Vector3d.x_axis(), 1.),
            'down': (Vector3d.x_axis(), -1.),
            'left': (Vector3d.y_axis(), 1.),
            'right': (Vector3d.y_axis(), -1.)
        }

        self.strafe = {
            'forward': False,
            'left': False,
            'right': False,
            'breake': False
        }

        self.strafe_vectors = {
            'forward': Vector3d(0., 0., -0.7),
            'left': Vector3d(-0.9, 0., 0.),
            'right': Vector3d(0.9, 0., 0.),
            'breake': Vector3d(0., 0., 1.)
        }

        self.angles = [0., 0.]
        self.mouse_target = [0., 0.]

        self.collision_set = set()
        self.keep_colliding = set()
예제 #2
0
    def update_spinning(self, time_elapsed):
        for dir in self.spinning:
            if (self.spinning[dir]):
                axis, sign = self.vectors[dir]
                angle = self.spin_velocity * time_elapsed * sign

                r = Quaternion.from_axis_angle(axis, angle)

                self.rotation = self.rotation * r

        self.ship_dir = self.rotation * Vector3d(0., 0., -1.)
        self.up_dir = self.rotation * Vector3d(0., 1., 0.)
예제 #3
0
 def __init__(self, model, shape, element, level):
     Object.__init__(self, model, shape, element)
     
     cfg = Config('physics','Ship')
     
     self.move_force_sz = cfg.get('move_force')
     self.spin_velocity = cfg.get('spin_velocity')
     self.strafe_force = cfg.get('strafe_force')
     self.shape.forces_res.append(cfg.get('vacuum_resistance'))
     self.breake_rate = cfg.get('breake_rate')
     
     self.mouse_sensivity = Config('game','Mouse').get('sensivity')
     
     self.level = level
     
     self.rotation = Quaternion.from_axis_rotations(0.,0.,0.)
     
     self.ship_dir = None
     self.up_dir = None
     
     self.spinning = {
         'up'    : False,
         'down'  : False,
         'left'  : False,
         'right' : False
     }
             
     self.vectors = {
         'up'    : (Vector3d.x_axis(), 1.),
         'down'  : (Vector3d.x_axis(), -1.),
         'left'  : (Vector3d.y_axis(), 1.),
         'right' : (Vector3d.y_axis(), -1.)
     }
     
     self.strafe = {
         'forward': False,
         'left'  : False,
         'right' : False,
         'breake' : False
     }
     
     self.strafe_vectors = {
         'forward':Vector3d(0.,0.,-0.7),
         'left'  : Vector3d(-0.9,0.,0.),
         'right' : Vector3d(0.9,0.,0.),
         'breake' : Vector3d(0.,0.,1.)
     }
     
     self.angles = [0.,0.]
     self.mouse_target = [0.,0.]
     
     self.collision_set = set()
     self.keep_colliding = set()
예제 #4
0
    def update_spinning(self, time_elapsed):
        for dir in self.spinning:
            if (self.spinning[dir]):
                axis, sign = self.vectors[dir]
                angle = self.spin_velocity * time_elapsed * sign
                
                r = Quaternion.from_axis_angle(axis, angle)
                
                self.rotation = self.rotation * r

        self.ship_dir = self.rotation * Vector3d(0.,0.,-1.)
        self.up_dir = self.rotation * Vector3d(0.,1.,0.)
예제 #5
0
    def update_mouse_track(self, time_elapsed):
        eps = 0.1
        ax, ay = self.angles
        tx, ty = self.mouse_target

        if (fabs(ax - tx) <= eps):
            self.angles[0] = 0.0
            self.mouse_target[0] = 0.0
        else:
            before = sign(tx - ax)
            d = self.spin_velocity * time_elapsed * sign(tx - ax)
            self.angles[0] += d
            after = sign(tx - self.angles[0])

            if (before != after):
                self.angles[0] = 0.0
                self.mouse_target[0] = 0.0

            r = Quaternion.from_axis_angle(Vector3d(0., 1., 0.), d)
            self.rotation = self.rotation * r

        if (fabs(ay - ty) <= eps):
            self.angles[1] = 0.0
            self.mouse_target[1] = 0.0
        else:
            before = sign(ty - ay)
            d = self.spin_velocity * time_elapsed * sign(ty - ay)
            self.angles[1] += d
            after = sign(ty - self.angles[1])

            if (before != after):
                self.angles[1] = 0.0
                self.mouse_target[1] = 0.0

            r = Quaternion.from_axis_angle(Vector3d(1., 0., 0.), d)
            self.rotation = self.rotation * r
예제 #6
0
 def update_mouse_track(self, time_elapsed):
     eps = 0.1
     ax, ay = self.angles
     tx, ty = self.mouse_target
     
     if (fabs(ax - tx) <= eps):
         self.angles[0] = 0.0
         self.mouse_target[0] = 0.0
     else:
         before = sign(tx - ax)
         d = self.spin_velocity * time_elapsed * sign(tx - ax)
         self.angles[0] += d
         after = sign(tx - self.angles[0])
         
         if (before != after):
             self.angles[0] = 0.0
             self.mouse_target[0] = 0.0
         
         r = Quaternion.from_axis_angle(Vector3d(0.,1.,0.), d)
         self.rotation = self.rotation * r
         
     if (fabs(ay - ty) <= eps):
         self.angles[1] = 0.0
         self.mouse_target[1] = 0.0
     else:
         before = sign(ty - ay)
         d = self.spin_velocity * time_elapsed * sign(ty - ay)
         self.angles[1] += d
         after = sign(ty - self.angles[1])
         
         if (before != after):
             self.angles[1] = 0.0
             self.mouse_target[1] = 0.0
         
         r = Quaternion.from_axis_angle(Vector3d(1.,0.,0.), d)
         self.rotation = self.rotation * r