Beispiel #1
0
    def keyEvent(self, key):
        homogeneous_light_vector = np.array([*self.light_vector, 0])
        #Your code here
        if key == pygame.K_w:
            self.light_vector = np.matmul(homogeneous_light_vector,
                                          wf.rotateXMatrix(np.radians(5)))[:3]

        if key == pygame.K_s:
            self.light_vector = np.matmul(homogeneous_light_vector,
                                          wf.rotateXMatrix(-np.radians(5)))[:3]

        if key == pygame.K_a:
            self.light_vector = np.matmul(homogeneous_light_vector,
                                          wf.rotateYMatrix(-np.radians(5)))[:3]

        if key == pygame.K_d:
            self.light_vector = np.matmul(homogeneous_light_vector,
                                          wf.rotateYMatrix(np.radians(5)))[:3]

        if key == pygame.K_q:
            self.light_vector = np.matmul(homogeneous_light_vector,
                                          wf.rotateZMatrix(np.radians(5)))[:3]

        if key == pygame.K_e:
            self.light_vector = np.matmul(homogeneous_light_vector,
                                          wf.rotateZMatrix(-np.radians(5)))[:3]

        return
Beispiel #2
0
 def keyEvent(self, key):
     if key == pygame.K_a:
         # print("a is pressed")
         temp = self.light_vector
         temp = np.insert(temp, 3, 1)
         self.light_vector = np.dot(temp, wf.rotateYMatrix(-pi / 16))[:-1]
     if key == pygame.K_d:
         # print("d is pressed")
         temp = self.light_vector
         temp = np.insert(temp, 3, 1)
         self.light_vector = np.dot(temp, wf.rotateYMatrix(pi / 16))[:-1]
     if key == pygame.K_w:
         # print("w is pressed")
         temp = self.light_vector
         temp = np.insert(temp, 3, 1)
         self.light_vector = np.dot(temp, wf.rotateXMatrix(pi / 16))[:-1]
     if key == pygame.K_s:
         # print("s is pressed")
         temp = self.light_vector
         temp = np.insert(temp, 3, 1)
         self.light_vector = np.dot(temp, wf.rotateXMatrix(-pi / 16))[:-1]
     if key == pygame.K_q:
         # print("q is pressed")
         temp = self.light_vector
         temp = np.insert(temp, 3, 1)
         self.light_vector = np.dot(temp, wf.rotateZMatrix(pi / 16))[:-1]
     if key == pygame.K_e:
         # print("e is pressed")
         temp = self.light_vector
         temp = np.insert(temp, 3, 1)
         self.light_vector = np.dot(temp, wf.rotateZMatrix(-pi / 16))[:-1]
     return
    def rotateAll(self, axis, theta):
        """ Rotates all wireframe objects in simulation. """

        global correction_matrix
        
        # Create rotation matrix, and update global correction matrix.
        if axis == 'X':
            rotateMatrix = wf.rotateXMatrix(theta)
            correction_matrix = np.dot(wf.rotateXMatrix(-theta),
             correction_matrix)

        elif axis == 'Y':
            rotateMatrix = wf.rotateYMatrix(theta)
            correction_matrix = np.dot(wf.rotateYMatrix(-theta),
             correction_matrix)

        elif axis == 'Z':
            rotateMatrix = wf.rotateZMatrix(theta)
            correction_matrix = np.dot(wf.rotateZMatrix(-theta),
             correction_matrix)

        for wireframe in [self.hat.base, self.hat.bill, self.hat.lightSensors]:
            center = hat.base.findCenter()
            wireframe.nodes = wireframe.nodes - center 
            wireframe.transform(rotateMatrix)
            wireframe.nodes = wireframe.nodes + center 
Beispiel #4
0
    def keyEvent(self, key):

        #Your code here
        if key == pygame.K_a:
            print("a is pressed")

            self.light_vector = np.matmul(wf.rotateYMatrix(
                math.pi / 20), (np.append(self.light_vector, [1], axis=0)))
            self.light_vector = self.light_vector[0:3]
            self.light_vector = self.light_vector / np.sqrt(
                np.sum(self.light_vector**2))
        if key == pygame.K_d:
            print("d is pressed")
            #self.light_vector = wf.rotateYMatrix(-math.pi/20) * self.light_vector
            self.light_vector = np.matmul(wf.rotateYMatrix(
                -math.pi / 20), (np.append(self.light_vector, [1], axis=0)))
            self.light_vector = self.light_vector[0:3]
            self.light_vector = self.light_vector / np.sqrt(
                np.sum(self.light_vector**2))
        if key == pygame.K_w:
            print("w is pressed")
            #self.light_vector = wf.rotateXMatrix(math.pi/20) * self.light_vector
            self.light_vector = np.matmul(wf.rotateXMatrix(
                -math.pi / 20), (np.append(self.light_vector, [1], axis=0)))
            self.light_vector = self.light_vector[0:3]
            self.light_vector = self.light_vector / np.sqrt(
                np.sum(self.light_vector**2))
        if key == pygame.K_s:
            print("s is pressed")
            #self.light_vector = wf.rotateXMatrix(-math.pi/20) * self.light_vector
            self.light_vector = np.matmul(wf.rotateXMatrix(
                math.pi / 20), (np.append(self.light_vector, [1], axis=0)))
            self.light_vector = self.light_vector[0:3]
            self.light_vector = self.light_vector / np.sqrt(
                np.sum(self.light_vector**2))
        if key == pygame.K_q:
            print("q is pressed")
            #self.light_vector = wf.rotateZMatrix(math.pi/20) * self.light_vector
            self.light_vector = np.matmul(wf.rotateZMatrix(
                -math.pi / 20), (np.append(self.light_vector, [1], axis=0)))
            self.light_vector = self.light_vector[0:3]
            self.light_vector = self.light_vector / np.sqrt(
                np.sum(self.light_vector**2))
        if key == pygame.K_e:
            print("e is pressed")
            #self.light_vector = wf.rotateZMatrix(-math.pi/20) * self.light_vector
            self.light_vector = np.matmul(wf.rotateZMatrix(
                math.pi / 20), (np.append(self.light_vector, [1], axis=0)))
            self.light_vector = self.light_vector[0:3]
            self.light_vector = self.light_vector / np.sqrt(
                np.sum(self.light_vector**2))

        return
Beispiel #5
0
    def keyEvent(self, key):
        global Xdisp
        #Your code here
        if key == pygame.K_w:
            temp = self.light_vector
            temp = np.insert(temp, 3, 1)
            self.light_vector = np.dot(temp, wf.rotateXMatrix(math.pi/16))[:-1]
        if key == pygame.K_s:
            temp = self.light_vector
            temp = np.insert(temp, 3, 1)
            self.light_vector = np.dot(temp, wf.rotateXMatrix(-math.pi/16))[:-1]
        if key == pygame.K_a:
            temp = self.light_vector
            temp = np.insert(temp, 3, 1)
            self.light_vector = np.dot(temp, wf.rotateYMatrix(-math.pi/16))[:-1]
        if key == pygame.K_d:
            temp = self.light_vector
            temp = np.insert(temp, 3, 1)
            self.light_vector = np.dot(temp, wf.rotateYMatrix(math.pi/16))[:-1]
        if key == pygame.K_q:
            temp = self.light_vector
            temp = np.insert(temp, 3, 1)
            self.light_vector = np.dot(temp, wf.rotateZMatrix(math.pi/16))[:-1]
        if key == pygame.K_e:
            temp = self.light_vector
            temp = np.insert(temp, 3, 1)
            self.light_vector = np.dot(temp, wf.rotateZMatrix(-math.pi/16))[:-1]
        if key == pygame.K_p:
            Xdisp += .01
            print(Xdisp)
            if Xdisp > .7:
                Xdisp -= 1
        if key == pygame.K_l:
            Xdisp -= .01
            print(Xdisp)
            if Xdisp < 0:
                Xdisp += 1

        return
Beispiel #6
0
def setup_viewer(viewer):
    if scene == "shark":
        viewer.addEffect(fx.DrawSpeedTween(1, 45, 1, 20))
        viewer.addWireframe('spin', obj.loadOBJ("shark.obj"))
        viewer.wireframes['spin'].transform(wf.scaleMatrix(150))
    elif scene == "text":
        viewer.addEffect(fx.DrawSpeedTween(1, 150, 1, 50))
        viewer.addWireframe('spin', obj.loadOBJ("text_test.obj"))
        viewer.wireframes['spin'].transform(wf.scaleMatrix(3))
        viewer.wireframes['spin'].transform(wf.rotateZMatrix(-np.pi))
        viewer.wireframes['spin'].transform(wf.rotateYMatrix(-np.pi))
    elif scene == "watchdogs":
        viewer.addEffect(fx.DrawSpeedTween(1, 70, 1, 10))
        viewer.addWireframe('spin', obj.loadOBJ("watchdogs.obj"))
        viewer.wireframes['spin'].transform(wf.scaleMatrix(3))
        viewer.wireframes['spin'].transform(wf.rotateZMatrix(-np.pi))
        viewer.wireframes['spin'].transform(wf.rotateYMatrix(-np.pi))
    elif scene == "milkey":
        viewer.addEffect(fx.MIDIModulator("milkey.uss"))
        viewer.addWireframe('head', shape.Spheroid((0,)*3, (150,)*3, resolution=5))
        viewer.addWireframe('left_ear', shape.Spheroid((0,)*3, (75,)*3, resolution=3))
        viewer.addWireframe('right_ear', shape.Spheroid((0,)*3, (75,)*3, resolution=3))
    elif scene == "cube":
        viewer.addEffect(fx.DrawSpeedTween(1, 250, 2, 50))
        viewer.addWireframe('spin', shape.Cuboid((0,)*3, (150,)*3))
    elif scene == "sphere":
        viewer.addEffect(fx.DrawSpeedTween(0.25, 130, 0.25, 20))
        viewer.addWireframe('spin', shape.Spheroid((0,)*3, (150,)*3))
    if scene != "milkey":
        viewer.centerWireframe("spin")
    else:
        viewer.centerWireframe("head")
        viewer.centerWireframe("left_ear")
        viewer.wireframes["left_ear"].transform(wf.translationMatrix(150, -150, 0))
        viewer.centerWireframe("right_ear")
        viewer.wireframes["right_ear"].transform(wf.translationMatrix(-150, -150, 0))
    viewer.key_to_function = {}
    viewer.object_update = object_update
Beispiel #7
0
 def rotate(self, axis, amount):
     (x, y, z) = self.findCentre()
     translation_matrix1 = wf.translationMatrix(-x, -y, -z)
     translation_matrix2 = wf.translationMatrix(x, y, z)
     
     if axis == 'x':
         rotation_matrix = wf.rotateXMatrix(amount)
     elif axis == 'y':
         rotation_matrix = wf.rotateYMatrix(amount)
     elif axis == 'z':
         rotation_matrix = wf.rotateZMatrix(amount)
         
     rotation_matrix = np.dot(np.dot(translation_matrix1, rotation_matrix), translation_matrix2)
     self.transform(rotation_matrix)
 def rotate(self, axis, amount):
     (x, y, z) = self.findCentre()
     translation_matrix1 = wf.translationMatrix(-x, -y, -z)
     translation_matrix2 = wf.translationMatrix(x, y, z)
     
     if axis == 'x':
         rotation_matrix = wf.rotateXMatrix(amount)
     elif axis == 'y':
         rotation_matrix = wf.rotateYMatrix(amount)
     elif axis == 'z':
         rotation_matrix = wf.rotateZMatrix(amount)
         
     rotation_matrix = np.dot(np.dot(translation_matrix1, rotation_matrix), translation_matrix2)
     self.transform(rotation_matrix)
    def rotate(self, axis, amount):
        """Rotate the "camera" by rotating all other wireframes"""
        (x, y, z) = self.findCenter()
        translation_matrix1 = wf.translationMatrix(-x, -y, -z)
        translation_matrix2 = wf.translationMatrix(x, y, z)

        axis = axis.lower()

        if axis == 'x':
            rotation_matrix = wf.rotateXMatrix(amount)
        elif axis == 'y':
            rotation_matrix = wf.rotateYMatrix(amount)
        elif axis == 'z':
            rotation_matrix = wf.rotateZMatrix(amount)
        else:
            raise Exception("Invalid rotation axis. Valid axes are x, y, and z.")

        rotation_matrix = np.dot(np.dot(translation_matrix1, rotation_matrix), translation_matrix2)
        self.transform(rotation_matrix)
Beispiel #10
0
    pygame.K_EQUALS: (lambda x: x.scale(1.25)),
    pygame.K_MINUS:  (lambda x: x.scale(0.8)),
    pygame.K_q:      (lambda x: x.rotate('x', ROTATION_AMOUNT)),
    pygame.K_w:      (lambda x: x.rotate('x',-ROTATION_AMOUNT)),
    pygame.K_a:      (lambda x: x.rotate('y', ROTATION_AMOUNT)),
    pygame.K_s:      (lambda x: x.rotate('y',-ROTATION_AMOUNT)),
    pygame.K_z:      (lambda x: x.rotate('z', ROTATION_AMOUNT)),
    pygame.K_x:      (lambda x: x.rotate('z',-ROTATION_AMOUNT))
}

light_movement = {
    pygame.K_q:      (lambda x: x.transform(wf.rotateXMatrix(-ROTATION_AMOUNT))),
    pygame.K_w:      (lambda x: x.transform(wf.rotateXMatrix( ROTATION_AMOUNT))),
    pygame.K_a:      (lambda x: x.transform(wf.rotateYMatrix(-ROTATION_AMOUNT))),
    pygame.K_s:      (lambda x: x.transform(wf.rotateYMatrix( ROTATION_AMOUNT))),
    pygame.K_z:      (lambda x: x.transform(wf.rotateZMatrix(-ROTATION_AMOUNT))),
    pygame.K_x:      (lambda x: x.transform(wf.rotateZMatrix( ROTATION_AMOUNT)))
}

class WireframeViewer(wf.WireframeGroup):
    """ A group of wireframes which can be displayed on a Pygame screen """
    
    def __init__(self, width, height, name="Wireframe Viewer"):
        self.width = width
        self.height = height
        
        self.screen = pygame.display.set_mode((width, height))
        pygame.display.set_caption(name)
        
        self.wireframes = {}
        self.wireframe_colours = {}
    pygame.K_EQUALS: (lambda x: x.scale(1.25)),
    pygame.K_MINUS: (lambda x: x.scale(0.8)),
    pygame.K_q: (lambda x: x.rotate('x', ROTATION_AMOUNT)),
    pygame.K_w: (lambda x: x.rotate('x', -ROTATION_AMOUNT)),
    pygame.K_a: (lambda x: x.rotate('y', ROTATION_AMOUNT)),
    pygame.K_s: (lambda x: x.rotate('y', -ROTATION_AMOUNT)),
    pygame.K_z: (lambda x: x.rotate('z', ROTATION_AMOUNT)),
    pygame.K_x: (lambda x: x.rotate('z', -ROTATION_AMOUNT))
}

light_movement = {
    pygame.K_q: (lambda x: x.transform(wf.rotateXMatrix(-ROTATION_AMOUNT))),
    pygame.K_w: (lambda x: x.transform(wf.rotateXMatrix(ROTATION_AMOUNT))),
    pygame.K_a: (lambda x: x.transform(wf.rotateYMatrix(-ROTATION_AMOUNT))),
    pygame.K_s: (lambda x: x.transform(wf.rotateYMatrix(ROTATION_AMOUNT))),
    pygame.K_z: (lambda x: x.transform(wf.rotateZMatrix(-ROTATION_AMOUNT))),
    pygame.K_x: (lambda x: x.transform(wf.rotateZMatrix(ROTATION_AMOUNT)))
}


class WireframeViewer(wf.WireframeGroup):
    """ A group of wireframes which can be displayed on a Pygame screen """
    def __init__(self, width, height, name="Wireframe Viewer"):
        self.width = width
        self.height = height

        self.screen = pygame.display.set_mode((width, height))
        pygame.display.set_caption(name)

        self.wireframes = {}
        self.wireframe_colours = {}