Esempio n. 1
0
 def __make_inner_squares_right(squares):
     rot_tfm = lu.make_rotation_y(math.pi / 2)
     translation = lambda i: lu.make_translation(-2 + i, 0, 0)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      RIGHT_TRANS)
     translation = lambda i: lu.make_translation(-2 + 2 * SPACING + i, 0, 0)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      RIGHT_TRANS)
Esempio n. 2
0
 def __make_inner_squares_up(squares):
     rot_tfm = lu.make_rotation_x(-math.pi / 2)
     translation = lambda i: lu.make_translation(0, -2 + i, 0)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      TOP_TRANS)
     translation = lambda i: lu.make_translation(0, -2 + 2 * SPACING + i, 0)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      TOP_TRANS)
Esempio n. 3
0
 def __make_inner_squares_front(squares):
     rot_tfm = lu.Mat4()
     translation = lambda i: lu.make_translation(0, 0, -1 - i)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      FRONT_TRANS)
     translation = lambda i: lu.make_translation(0, 0, -1 + 2 * SPACING - i)
     CubeRenderer.__add_inner_squares(squares, rot_tfm, translation,
                                      FRONT_TRANS)
Esempio n. 4
0
def make_lookFrom(eye, direction, up):
    f = normalize(direction)
    U = np.array(up[:3])
    s = normalize(np.cross(f, U))
    u = np.cross(s, f)
    M = np.matrix(np.identity(4))
    M[:3, :3] = np.vstack([s, u, -f])
    T = make_translation(-eye[0], -eye[1], -eye[2])
    return Mat4(M) * T
Esempio n. 5
0
 def render(self, view, renderingSystem):
     # TODO 1.3: This is a good place to draw the racer model instead of the sphere
     modelToWorldTransform = lu.make_translation(
         self.position[0], self.position[1],
         self.position[2]) * lu.make_scale(2, 2, 2)
     # self.translation = self.position*self.heading
     # modelToWorldTransform = lu.make_mat4_from_zAxis([self.position[0],self.position[1],self.position[2]],self.heading,vec3(0,0,1))\
     #                         *lu.make_scale(1, 1, 1);
     renderingSystem.drawObjModel(self.model, modelToWorldTransform, view)
Esempio n. 6
0
 def __add_left_squares(self, squares):
     translation = lambda row, col: lu.make_translation(
         SPACING, 2 - row + SPACING, -SPACING - 2 + col)
     rot_tfm = lu.make_rotation_y(math.pi / 2)
     CubeRenderer.__add_squares(self.cube.right.squares, squares, rot_tfm,
                                translation)
Esempio n. 7
0
 def __add_bottom_squares(self, squares):
     translation = lambda row, col: lu.make_translation(
         SPACING + col, SPACING, -SPACING - row)
     rot_tfm = lu.make_rotation_x(-math.pi / 2)
     CubeRenderer.__add_squares(self.cube.top.squares, squares, rot_tfm,
                                translation)
Esempio n. 8
0
 def __add_back_squares(self, squares):
     translation = lambda row, col: lu.make_translation(
         SPACING + 2 - col, SPACING + (2 - row), -3 + SPACING)
     CubeRenderer.__add_squares(self.cube.front.squares, squares, lu.Mat4(),
                                translation)
Esempio n. 9
0
""" Takes cube objects and formats them for rendering """
import math
import lab_utils as lu
from cube import SquareColor

SPACING = 0.05
FRONT_TRANS = lambda row, col: lu.make_translation(SPACING + col, SPACING +
                                                   (2 - row), -SPACING)
TOP_TRANS = lambda row, col: lu.make_translation(SPACING + col, 3 - SPACING,
                                                 -SPACING - 2 + row)
RIGHT_TRANS = lambda row, col: lu.make_translation(3 - SPACING, 2 - row +
                                                   SPACING, -SPACING - col)


class CubeRenderer:
    """ Breaks the Cube down into squares and colours to be drawn """
    def __init__(self, cube):
        self.cube = cube

    def get_colors(self):
        """ Gets the list of square colors """
        colors = []
        colors.extend([square.value for square in self.cube.front.squares])
        colors.extend([square.value for square in self.cube.top.squares])
        colors.extend([square.value for square in self.cube.right.squares])
        colors.extend([square.value for square in self.cube.back.squares])
        colors.extend([square.value for square in self.cube.bottom.squares])
        colors.extend([square.value for square in self.cube.left.squares])
        colors.extend([SquareColor.BLACK.value for i in range(4 * 3 * 9)])
        return colors