def main(): d = 0.00001 window_height = 10 window_width = 10 pixels_height = 300 pixels_width = 300 objects = [] cube = obj.Obj().import_obj('../objects/cube.obj') # s = mt.get_scale_matrix([3., 0.1, 4., 1]) # floor = copy.deepcopy(cube) # floor.apply_transformation(s) # objects.append(floor) # T = mt.get_translation_matrix([1, 0, 2]) # cube2 = copy.deepcopy(cube) # cube2.apply_material(obj.Material([0, 0, 0], [0, 0, 0], [0, 0, 0], 1)) # cube2.apply_transformation(T) objects.append(cube) # punctual_light = PunctualLightSource(intensity=[1., 1., 1.], position=[1.5, 1.2, 0.1]) po = [0.5, 0.5, 2.5, 1.0] look_at = [0.5, 0.5, 0.5, 1.0] a_vup = [0.5, 2, 0.5, 1.0] p = "PERSPECTIVE" ob = "OBLIQUE" cb = "CABINET" cv = "CAVALIER" ort = "ORTHOGRAPHIC" projection_type = ob scenario = Scenario(objects=objects, light_sources=[], po=po, look_at=look_at, a_vup=a_vup, background_color=[0., 0., 0.], ambient_light=[0.9, 0.9, 0.9]) window = Window(window_width, window_height, d, pixels_width, pixels_height) scenario.render(window, ray_mean=False, parallel=True, shadow=False, projection_type=projection_type, oblique_angle=45, oblique_factor=1)
def main(): d = 1 window_height = 1 window_width = 1 pixels_height = 200 pixels_width = 200 objects = [] cube = obj.Obj().import_obj('../objects/cube.obj') s = mt.get_scale_matrix([100., 0.1, 100., 1]) floor = copy.deepcopy(cube) floor.apply_transformation(s) objects.append(floor) rgb_red = [1, 0, 0] red_material = obj.Material(rgb_red, rgb_red, [1, 1, 1], 1) T = mt.get_translation_matrix([50, 0, 50]) S = mt.get_scale_matrix([1, 3, 1, 1]) M = mt.compose_matrices([T, S]) cube2 = copy.deepcopy(cube) cube2.apply_transformation(M) cube2.apply_material(red_material) objects.append(cube2) punctual_light = PunctualLightSource(intensity=[1., 1., 1.], position=[50.5, 5, 50.5]) po = [50.5, 4, 60.5, 1.0] look_at = [50.5, 0., 50.5, 1.0] a_vup = [50.5, 20, 50.5, 1.0] scenario = Scenario(objects=objects, light_sources=[punctual_light], po=po, look_at=look_at, a_vup=a_vup, background_color=[0., 0., 0.], ambient_light=[0.5, 0.5, 0.5]) window = Window(window_width, window_height, d, pixels_width, pixels_height) scenario.render(window, ray_mean=False, parallel=False, shadow=True, projection_type="PERSPECTIVE", oblique_angle=None, oblique_factor=None)
def three_vanishing_points(): objects = [] cube = obj.Obj().import_obj('../objects/cube.obj') color = np.array([254, 178, 76]) / 255 color_material = obj.Material(color, color, [0.8, 0.8, 0.8], 10) S = mt.get_scale_matrix([10, 10, 10., 1]) T = mt.get_translation_matrix([0.0, 0.0, 0.]) M = mt.compose_matrices([T, S]) cube.apply_transformation(M) cube.apply_material(color_material) objects.append(cube) punctual_light = PunctualLightSource(intensity=[0.5, 0.5, 0.5], position=[20., 20., 5.]) d = 1 window_height = 1 window_width = 1 pixels_height = 200 pixels_width = 200 window = Window(window_width, window_height, d, pixels_width, pixels_height) # THREE VANISHING POINTS po = [20., 20., 20., 1.0] look_at = [10., 10., 10, 1.0] a_vup = [10., 12, 10, 1.0] scenario = Scenario(objects=objects, light_sources=[punctual_light], po=po, look_at=look_at, a_vup=a_vup, background_color=[0., 0., 0.], ambient_light=[0.5, 0.5, 0.5]) scenario.render(window, ray_mean=False, parallel=True, shadow=True, projection_type="PERSPECTIVE", oblique_angle=None, oblique_factor=None)
def create_objects(): cube = obj.Obj().import_obj('../objects/cube.obj') objects = [] # MATERIALS specular_term = [1, 1, 1] m = 10 # WALLS MATERIAL rgb_wall_material = [44 / 255, 137 / 255, 142 / 255] wall_material = obj.Material(rgb_wall_material, rgb_wall_material, specular_term, m) # CEILING MATERIAL rgb_ceiling_material = [200 / 255, 203 / 255, 208 / 255] ceiling_material = obj.Material(rgb_ceiling_material, rgb_ceiling_material, specular_term, m) # FLOOR MATERIAL floor_material = obj.Material(rgb_ceiling_material, rgb_ceiling_material, specular_term, m) # BLACK MATERIAL rgb_black = [0, 0, 0] black_material = obj.Material(rgb_black, rgb_black, specular_term, m) # WOOD MATERIAL rgb_wood_dark = [89 / 255, 63 / 255, 44 / 255] rgb_wood_light = [144 / 255, 112 / 255, 100 / 255] wood_material_dark = obj.Material(rgb_wood_dark, rgb_wood_dark, specular_term, m) wood_material_light = obj.Material(rgb_wood_light, rgb_wood_light, specular_term, m) # SOFA MATERIAL rgb_sofa = [93 / 255, 83 / 255, 87 / 255] sofa_material = obj.Material(rgb_sofa, rgb_sofa, specular_term, m) rgb_gray_light = [144 / 255, 150 / 255, 169 / 255] gray_material_light = obj.Material(rgb_gray_light, rgb_gray_light, specular_term, m) # OBJECTS # CHÃO s = mt.get_scale_matrix([3., 0.1, 4., 1]) floor = copy.deepcopy(cube) floor.apply_transformation(s) floor.apply_material(floor_material) objects.append(floor) # TETO t = mt.get_translation_matrix([0, 3., 0]) roof = copy.deepcopy(floor) roof.apply_transformation(t) roof.apply_material(ceiling_material) objects.append(roof) # TETO: DETALHES s = mt.get_scale_matrix([3., 0.3, 0.8, 1]) t = mt.get_translation_matrix([0.1, 2.7, 0.1]) m = mt.compose_matrices([t, s]) roof_detail = copy.deepcopy(cube) roof_detail.apply_transformation(m) roof_detail.apply_material(ceiling_material) objects.append(roof_detail) s = mt.get_scale_matrix([0.5, 0.3, 4., 1]) t = mt.get_translation_matrix([0.1, 2.7, 0]) m = mt.compose_matrices([t, s]) roof_detail2 = copy.deepcopy(cube) roof_detail2.apply_transformation(m) roof_detail2.apply_material(ceiling_material) objects.append(roof_detail2) t = mt.get_translation_matrix([2.4, 0, 0]) roof_detail3 = copy.deepcopy(roof_detail2) roof_detail3.apply_transformation(t) roof_detail3.apply_material(ceiling_material) objects.append(roof_detail3) t = mt.get_translation_matrix([0, 0, 3.2]) roof_detail4 = copy.deepcopy(roof_detail) roof_detail4.apply_transformation(t) roof_detail4.apply_material(ceiling_material) objects.append(roof_detail4) # PAREDE ESQUERDA s = mt.get_scale_matrix([0.1, 3., 0.75, 1]) wall2 = copy.deepcopy(cube) wall2.apply_transformation(s) wall2.apply_material(wall_material) objects.append(wall2) s = mt.get_scale_matrix([0.1, 3., 0.5, 1]) t = mt.get_translation_matrix([0, 0, 1.75]) m = mt.compose_matrices([t, s]) wall2_1 = copy.deepcopy(cube) wall2_1.apply_transformation(m) wall2_1.apply_material(wall_material) objects.append(wall2_1) t = mt.get_translation_matrix([0, 0, 3.25]) wall2_2 = copy.deepcopy(wall2) wall2_2.apply_transformation(t) wall2_2.apply_material(wall_material) objects.append(wall2_2) s = mt.get_scale_matrix([0.1, 1., 4., 1]) wall2_3 = copy.deepcopy(cube) wall2_3.apply_transformation(s) wall2_3.apply_material(wall_material) objects.append(wall2_3) s = mt.get_scale_matrix([0.1, 0.6, 4., 1]) t = mt.get_translation_matrix([0, 2.4, 0]) m = mt.compose_matrices([t, s]) wall2_4 = copy.deepcopy(cube) wall2_4.apply_transformation(m) wall2_4.apply_material(wall_material) objects.append(wall2_4) # PERSIANAS s = mt.get_scale_matrix([0.03, 0.01, 1.05, 1]) sh = mt.get_shear_matrix('x', 'y', -45) t = mt.get_translation_matrix([0.15, 1.1, 0.77]) m = mt.compose_matrices([t, sh, s]) blind = copy.deepcopy(cube) blind.apply_transformation(m) objects.append(blind) t = mt.get_translation_matrix([0, 0, 1.38]) blind1 = copy.deepcopy(blind) blind1.apply_transformation(t) objects.append(blind1) for x in range(1, 16): t = mt.get_translation_matrix([0, (x * 0.08), 0]) blind2 = copy.deepcopy(blind) blind3 = copy.deepcopy(blind1) blind2.apply_transformation(t) blind3.apply_transformation(t) objects.append(blind2) objects.append(blind3) # PAREDE DIREITA s = mt.get_scale_matrix([0.1, 3., 4., 1]) t = mt.get_translation_matrix([2.9, 0, 0]) m = mt.compose_matrices([t, s]) wall3 = copy.deepcopy(cube) wall3.apply_transformation(m) wall3.apply_material(wall_material) objects.append(wall3) # PAREDE TRÁS s = mt.get_scale_matrix([3., 3., 0.1, 1]) wall = copy.deepcopy(cube) wall.apply_transformation(s) wall.apply_material(wall_material) objects.append(wall) # PAREDE FRENTE t = mt.get_translation_matrix([0, 0, 4.]) wall4 = copy.deepcopy(wall) wall4.apply_transformation(t) wall4.apply_material(wall_material) objects.append(wall4) # PAREDE TRÁS: DETALHES s = mt.get_scale_matrix([0.5, 2.7, 0.3, 1]) t = mt.get_translation_matrix([0, 0, 0.1]) m = mt.compose_matrices([t, s]) wall_detail = copy.deepcopy(cube) wall_detail.apply_transformation(m) wall_detail.apply_material(wood_material_dark) objects.append(wall_detail) t = mt.get_translation_matrix([2.5, 0, 0]) wall_detail2 = copy.deepcopy(wall_detail) wall_detail2.apply_transformation(t) wall_detail2.apply_material(wood_material_dark) objects.append(wall_detail2) s = mt.get_scale_matrix([0.5, 1., 0.3, 1]) t = mt.get_translation_matrix([0.5, 1.7, 0.1]) m = mt.compose_matrices([t, s]) wall_detail3 = copy.deepcopy(cube) wall_detail3.apply_transformation(m) wall_detail3.apply_material(wood_material_dark) objects.append(wall_detail3) t = mt.get_translation_matrix([1.5, 0, 0]) wall_detail4 = copy.deepcopy(wall_detail3) wall_detail4.apply_transformation(t) wall_detail4.apply_material(wood_material_dark) objects.append(wall_detail4) # PRATELEIRAS DA PAREDE DE TRÁS s = mt.get_scale_matrix([1., 0.06, 0.25, 1]) t = mt.get_translation_matrix([1., 1.9, 0.1]) m = mt.compose_matrices([t, s]) shelf = copy.deepcopy(cube) shelf.apply_transformation(m) shelf.apply_material(wood_material_dark) objects.append(shelf) t = mt.get_translation_matrix([0, 0.3, 0]) shelf2 = copy.deepcopy(shelf) shelf2.apply_transformation(t) shelf2.apply_material(wood_material_dark) objects.append(shelf2) t = mt.get_translation_matrix([0, 0.3, 0]) shelf3 = copy.deepcopy(shelf2) shelf3.apply_transformation(t) shelf3.apply_material(wood_material_dark) objects.append(shelf3) # TV s = mt.get_scale_matrix([1., 0.6, 0.05, 1]) t = mt.get_translation_matrix([1., 0.8, 0.1]) m = mt.compose_matrices([t, s]) tv = copy.deepcopy(cube) tv.apply_transformation(m) tv.apply_material(gray_material_light) objects.append(tv) s = mt.get_scale_matrix([0.06, 0.6, 0.08, 1]) t = mt.get_translation_matrix([0.94, 0.8, 0.1]) m = mt.compose_matrices([t, s]) tv_detail = copy.deepcopy(cube) tv_detail.apply_transformation(m) tv_detail.apply_material(black_material) objects.append(tv_detail) t = mt.get_translation_matrix([1.06, 0, 0]) tv_detail2 = copy.deepcopy(tv_detail) tv_detail2.apply_transformation(t) tv_detail2.apply_material(black_material) objects.append(tv_detail2) s = mt.get_scale_matrix([1.12, 0.06, 0.08, 1]) t = mt.get_translation_matrix([0.94, 0.74, 0.1]) m = mt.compose_matrices([t, s]) tv_detail3 = copy.deepcopy(cube) tv_detail3.apply_transformation(m) tv_detail3.apply_material(black_material) objects.append(tv_detail3) t = mt.get_translation_matrix([0, 0.66, 0]) tv_detail4 = copy.deepcopy(tv_detail3) tv_detail4.apply_transformation(t) tv_detail4.apply_material(black_material) objects.append(tv_detail4) # TV RACK s = mt.get_scale_matrix([1.2, 0.06, 0.4, 1]) t = mt.get_translation_matrix([0.9, 0.2, 0.1]) m = mt.compose_matrices([t, s]) tv_rack = copy.deepcopy(cube) tv_rack.apply_transformation(m) tv_rack.apply_material(wood_material_light) objects.append(tv_rack) t = mt.get_translation_matrix([0, 0.2, 0]) tv_rack2 = copy.deepcopy(tv_rack) tv_rack2.apply_transformation(t) tv_rack2.apply_material(wood_material_light) objects.append(tv_rack2) s = mt.get_scale_matrix([0.06, 0.4, 0.35, 1]) t = mt.get_translation_matrix([0.95, 0, 0.1]) m = mt.compose_matrices([t, s]) tv_rack3 = copy.deepcopy(cube) tv_rack3.apply_transformation(m) tv_rack3.apply_material(wood_material_light) objects.append(tv_rack3) t = mt.get_translation_matrix([1.04, 0, 0]) tv_rack4 = copy.deepcopy(tv_rack3) tv_rack4.apply_transformation(t) tv_rack4.apply_material(wood_material_light) objects.append(tv_rack4) # SPEAKERS s = mt.get_scale_matrix([0.2, 0.9, 0.3, 1]) t = mt.get_translation_matrix([0.6, 0, 0.1]) m = mt.compose_matrices([t, s]) speaker = copy.deepcopy(cube) speaker.apply_transformation(m) speaker.apply_material(black_material) objects.append(speaker) t = mt.get_translation_matrix([1.6, 0, 0]) speaker2 = copy.deepcopy(speaker) speaker2.apply_transformation(t) speaker2.apply_material(black_material) objects.append(speaker2) s = mt.get_scale_matrix([0.6, 0.2, 0.3, 1]) t = mt.get_translation_matrix([1.2, 0.46, 0.1]) m = mt.compose_matrices([t, s]) device = copy.deepcopy(cube) device.apply_transformation(m) device.apply_material(black_material) objects.append(device) # SOFA 1: COSTAS s = mt.get_scale_matrix([0.15, 0.8, 1.5, 1]) t = mt.get_translation_matrix([0.15, 0.1, 1.25]) m = mt.compose_matrices([t, s]) sofa1_1 = copy.deepcopy(cube) sofa1_1.apply_transformation(m) sofa1_1.apply_material(sofa_material) objects.append(sofa1_1) # SOFA 2: COSTAS t = mt.get_translation_matrix([2.55, 0, 0]) sofa2_1 = copy.deepcopy(sofa1_1) sofa2_1.apply_transformation(t) objects.append(sofa2_1) # SOFA 1: BRAÇO DIREITA s = mt.get_scale_matrix([0.6, 0.6, 0.15, 1]) t = mt.get_translation_matrix([0.3, 0.1, 1.25]) m = mt.compose_matrices([t, s]) sofa1_2 = copy.deepcopy(cube) sofa1_2.apply_transformation(m) sofa1_2.apply_material(sofa_material) objects.append(sofa1_2) # SOFA 2: BRAÇO DIREITA t = mt.get_translation_matrix([1.8, 0, 0]) sofa2_2 = copy.deepcopy(sofa1_2) sofa2_2.apply_transformation(t) objects.append(sofa2_2) # SOFA 1: BRAÇO ESQUERDA t = mt.get_translation_matrix([0, 0, 1.35]) sofa1_3 = copy.deepcopy(sofa1_2) sofa1_3.apply_transformation(t) objects.append(sofa1_3) # SOFA 2: BRAÇO ESQUERDA t = mt.get_translation_matrix([1.8, 0, 0]) sofa2_3 = copy.deepcopy(sofa1_3) sofa2_3.apply_transformation(t) objects.append(sofa2_3) # SOFA 1: BASE s = mt.get_scale_matrix([0.6, 0.3, 1.2, 1]) t = mt.get_translation_matrix([0.3, 0.05, 1.4]) m = mt.compose_matrices([t, s]) sofa1_4 = copy.deepcopy(cube) sofa1_4.apply_transformation(m) sofa1_4.apply_material(sofa_material) objects.append(sofa1_4) # SOFA 2: BASE t = mt.get_translation_matrix([1.8, 0, 0]) sofa2_4 = copy.deepcopy(sofa1_4) sofa2_4.apply_transformation(t) objects.append(sofa2_4) # SOFA 1: ASSENTO 1 s = mt.get_scale_matrix([0.6, 0.05, 0.60, 1]) t = mt.get_translation_matrix([0.3, 0.35, 1.37]) m = mt.compose_matrices([t, s]) sofa1_5 = copy.deepcopy(cube) sofa1_5.apply_transformation(m) sofa1_5.apply_material(sofa_material) objects.append(sofa1_5) # SOFA 2: ASSENTO 1 t = mt.get_translation_matrix([1.8, 0, 0]) sofa2_5 = copy.deepcopy(sofa1_5) sofa2_5.apply_transformation(t) objects.append(sofa2_5) # SOFA 1: ASSENTO 2 t = mt.get_translation_matrix([0, 0, 0.63]) sofa1_6 = copy.deepcopy(sofa1_5) sofa1_6.apply_transformation(t) objects.append(sofa1_6) # SOFA 2: ASSENTO 2 t = mt.get_translation_matrix([1.8, 0, 0]) sofa2_6 = copy.deepcopy(sofa1_6) sofa2_6.apply_transformation(t) objects.append(sofa2_6) # MESA DE CENTRO s = mt.get_scale_matrix([0.6, 0.1, 1, 1]) t = mt.get_translation_matrix([1.2, 0.3, 1.5]) m = mt.compose_matrices([t, s]) table1 = copy.deepcopy(cube) table1.apply_material(wood_material_light) table1.apply_transformation(m) objects.append(table1) s = mt.get_scale_matrix([0.5, 0.1, 0.2, 1]) t = mt.get_translation_matrix([1.25, 0.1, 1.6]) m = mt.compose_matrices([t, s]) table2 = copy.deepcopy(cube) table2.apply_material(wood_material_light) table2.apply_transformation(m) objects.append(table2) t = mt.get_translation_matrix([0, 0, 0.6]) table3 = copy.deepcopy(table2) table3.apply_transformation(t) objects.append(table3) # print total number of faces # size = 0 # for obje in objects: # size += len(obje.faces) # print(size) return objects
def draw_scenario_corrida(): ########### Definindo Cenario ########### # importando os objetos ja setados, talvez precise modificar depois path = os.path.normpath( os.path.join(__file__, '../../../objects/cube3.obj')) cube = obj.Obj().import_obj(path) # arquibancada path2 = os.path.normpath( os.path.join(__file__, '../../../objects/grandstand.obj')) grandstand = obj.Obj().import_obj(path2) grandstand.calculate_normals() # MATERIAIS # Cores dos Materiais & Componentes Especulares: specular_term = [1, 1, 1] specular_term2 = [0.3, 0.3, 0.3] rugose_term = [0.2, 0.2, 0.2] m = 10 # MATERIAL ASFALTO rgb_asfalto_material = [0.50196078, 0.50196078, 0.50196078] asfalto_material = obj.Material(rgb_asfalto_material, rgb_asfalto_material, specular_term2, m) asfalto_cube = copy.deepcopy(cube) asfalto_cube.apply_material(asfalto_material) # MATERIAL GRAMADO rgb_gramado_material = [50 / 255, 205 / 255, 50 / 255] gramado_material = obj.Material(rgb_gramado_material, rgb_gramado_material, specular_term, m) gramado_cube = copy.deepcopy(cube) gramado_cube.apply_material(gramado_material) # MATERIAL MADEIRA rgb_madeira_material = [92 / 255, 51 / 255, 23 / 255] madeira_material = obj.Material(rgb_madeira_material, rgb_madeira_material, specular_term, 2) madeira_cube = copy.deepcopy(cube) madeira_cube.apply_material(madeira_material) # MATERIAL LINHA DE CHEGADA 1 rgb_chegada1_material = [0, 0, 0] chegada1_material = obj.Material(rgb_chegada1_material, rgb_chegada1_material, specular_term, m) chegada1_cube = copy.deepcopy(cube) chegada1_cube.apply_material(chegada1_material) # MATERIAL LINHA DE CHEGADA 2 rgb_chegada2_material = [1, 1, 1] chegada2_material = obj.Material(rgb_chegada2_material, rgb_chegada2_material, specular_term, m) chegada2_cube = copy.deepcopy(cube) chegada2_cube.apply_material(chegada2_material) # MATERIAL POSTE 1 rgb_poste1_material = [140 / 255, 23 / 255, 23 / 255] poste1_material = obj.Material(rgb_poste1_material, rgb_poste1_material, specular_term, 2) poste1_cube = copy.deepcopy(cube) poste1_cube.apply_material(poste1_material) # MATERIAL POSTE 2 rgb_poste2_material = [207 / 255, 181 / 255, 59 / 255] poste2_material = obj.Material(rgb_poste2_material, rgb_poste2_material, specular_term, 2) poste2_cube = copy.deepcopy(cube) poste2_cube.apply_material(poste2_material) # MATERIAL ARQUIBANCADA 1 rgb_arquibancada1_material = [140 / 255, 23 / 255, 23 / 255] arquibancada1_material = obj.Material(rgb_arquibancada1_material, rgb_arquibancada1_material, specular_term, 2) arquibancada1_grandstand = copy.deepcopy(grandstand) arquibancada1_grandstand.apply_material(arquibancada1_material) # MATERIAL ARQUIBANCADA 2 rgb_arquibancada2_material = [207 / 255, 181 / 255, 59 / 255] arquibancada2_material = obj.Material(rgb_arquibancada2_material, rgb_arquibancada2_material, specular_term, 2) arquibancada2_grandstand = copy.deepcopy(grandstand) arquibancada2_grandstand.apply_material(arquibancada2_material) #################### # so teste ''' glPushMatrix() # glScalef(3., 0.1, 4.) #glScalef(150, 0.01, 150) glTranslatef(5, 0, 0) draw_polygon(arquibancada2_grandstand) glPopMatrix() ''' # GRAMADO glPushMatrix() #glScalef(3., 0.1, 4.) glScalef(150, 0.01, 150) draw_polygon(gramado_cube) glPopMatrix() # LINHA CHEGADA glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(50, 0, 50) #(51.25, 0, 50) draw_polygon(chegada1_cube) glPopMatrix() glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(44, 11, 45) #(51.25, 0, 51.25) draw_polygon(chegada2_cube) glPopMatrix() glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(50, 0, 52.5) #(51.25, 0, 52.5) draw_polygon(chegada1_cube) glPopMatrix() glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(50, 0, 53.75) #(51.25, 0, 53.75) draw_polygon(chegada2_cube) glPopMatrix() glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(51.25, 0, 53.75) #(52.5, 0, 53.75) draw_polygon(chegada2_cube) glPopMatrix() glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(51.25, 0, 52.5) #(52.5, 0, 52.5) draw_polygon(chegada1_cube) glPopMatrix() glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(51.25, 0, 52.5) #(52.5, 0, 51.25) draw_polygon(chegada2_cube) glPopMatrix() glPushMatrix() glScalef(1.25, 1.1, 1.25) glTranslatef(51.25, 0, 52.5) #(52.5, 0, 50) draw_polygon(chegada1_cube) glPopMatrix() # POSTE glPushMatrix() glScalef(3, 1, 3) glTranslatef(42, 1, 42) draw_polygon(poste1_cube) glPopMatrix() glPushMatrix() glScalef(1, 7, 1) glTranslatef(43, 2, 43) #(44, 2, 43) draw_polygon(poste2_cube) glPopMatrix() glPushMatrix() glScalef(1, 5, 1) glTranslatef(44, 11, 44) #(45, 11, 44) draw_polygon(poste1_cube) glPopMatrix() #TESTANDO A ARQUIBANCADA glPushMatrix() glScalef(30, 10, 10) glTranslatef(49, 0, 38) draw_polygon(arquibancada1_grandstand) glPopMatrix() glPushMatrix() #rotacao #glRotatef(90, 0, 1, 0) glRotate(90, 0, -50, 0) glTranslatef(0, 0, 1) glScalef(10, 10, 30) glTranslatef(11, 0, 55) draw_polygon(arquibancada2_grandstand) glPopMatrix()
def draw_scenario(): path = os.path.normpath( os.path.join(__file__, '../../../objects/cube2.obj')) cube = obj.Obj().import_obj(path) # MATERIALS specular_term = [0.3, 0.3, 0.3] m = 0.1 # WALLS MATERIAL rgb_wall_material = [44 / 255, 137 / 255, 142 / 255] wall_material = obj.Material(rgb_wall_material, rgb_wall_material, specular_term, m) wall_cube = copy.deepcopy(cube) wall_cube.apply_material(wall_material) # CEILING MATERIAL rgb_ceiling_material = [200 / 255, 203 / 255, 208 / 255] ceiling_material = obj.Material(rgb_ceiling_material, rgb_ceiling_material, specular_term, m) ceiling_cube = copy.deepcopy(cube) ceiling_cube.apply_material(ceiling_material) # FLOOR MATERIAL floor_material = obj.Material(rgb_ceiling_material, rgb_ceiling_material, specular_term, m) floor_cube = copy.deepcopy(cube) floor_cube.apply_material(floor_material) # BLACK MATERIAL rgb_black = [0, 0, 0] black_material = obj.Material(rgb_black, rgb_black, specular_term, 5) black_cube = copy.deepcopy(cube) black_cube.apply_material(black_material) # WOOD MATERIAL rgb_wood_dark = [89 / 255, 63 / 255, 44 / 255] rgb_wood_light = [144 / 255, 112 / 255, 100 / 255] wood_material_dark = obj.Material(rgb_wood_dark, rgb_wood_dark, specular_term, m) wood_material_light = obj.Material(rgb_wood_light, rgb_wood_light, specular_term, m) dark_wood_cube = copy.deepcopy(cube) dark_wood_cube.apply_material(wood_material_dark) light_wood_cube = copy.deepcopy(cube) light_wood_cube.apply_material(wood_material_light) # SOFA MATERIAL rgb_sofa = [93 / 255, 83 / 255, 87 / 255] sofa_material = obj.Material(rgb_sofa, rgb_sofa, specular_term, m) sofa_cube = copy.deepcopy(cube) sofa_cube.apply_material(sofa_material) rgb_gray_light = [144 / 255, 150 / 255, 169 / 255] gray_material_light = obj.Material(rgb_gray_light, rgb_gray_light, specular_term, m) gray_cube = copy.deepcopy(cube) gray_cube.apply_material(gray_material_light) # CHÃO glPushMatrix() glScalef(3., 0.1, 4.) draw_polygon(floor_cube) glPopMatrix() # TETO glPushMatrix() glTranslatef(0, 3., 0) glScalef(3., 0.1, 4.) draw_polygon(ceiling_cube) glPopMatrix() # TETO: DETALHES - TRÁS glPushMatrix() glTranslatef(0.1, 2.7, 0.1) glScalef(2.8, 0.3, 0.8) draw_polygon(ceiling_cube) glPopMatrix() # TETO: DETALHES - FRENTE glPushMatrix() glTranslatef(0.1, 2.7, 3.1) glScalef(2.8, 0.3, 0.8) draw_polygon(ceiling_cube) glPopMatrix() # TETO: DETALHES - ESQUERDA glPushMatrix() glTranslatef(0.1, 2.7, 0.9) glScalef(0.5, 0.3, 2.3) draw_polygon(ceiling_cube) glPopMatrix() # TETO: DETALHES - DIREITA glPushMatrix() glTranslatef(2.4, 2.7, 0.9) glScalef(0.5, 0.3, 2.3) draw_polygon(ceiling_cube) glPopMatrix() # PAREDE TRÁS glPushMatrix() glScalef(3., 3., 0.1) draw_polygon(wall_cube) glPopMatrix() # PAREDE TRÁS: DETALHES - ESQUERDA glPushMatrix() glTranslatef(0.1, 0.1, 0.1) glScalef(0.4, 2.6, 0.3) draw_polygon(dark_wood_cube) glPopMatrix() # PAREDE TRÁS: DETALHES - DIREITA glPushMatrix() glTranslatef(2.5, 0.1, 0.1) glScalef(0.4, 2.6, 0.3) draw_polygon(dark_wood_cube) glPopMatrix() # PAREDE TRÁS: DETALHES - ESQUERDA-CIMA glPushMatrix() glTranslatef(0.5, 1.7, 0.1) glScalef(0.5, 1.0, 0.3) draw_polygon(dark_wood_cube) glPopMatrix() # PAREDE TRÁS: DETALHES - DIREITA-CIMA glPushMatrix() glTranslatef(2.0, 1.7, 0.1) glScalef(0.5, 1.0, 0.3) draw_polygon(dark_wood_cube) glPopMatrix() # PRATELEIRAS DA PAREDE DE TRÁS - BAIXO glPushMatrix() glTranslatef(1.0, 1.9, 0.1) glScalef(1.0, 0.06, 0.25) draw_polygon(dark_wood_cube) glPopMatrix() # PRATELEIRAS DA PAREDE DE TRÁS - MEIO glPushMatrix() glTranslatef(1.0, 2.2, 0.1) glScalef(1.0, 0.06, 0.25) draw_polygon(dark_wood_cube) glPopMatrix() # PRATELEIRAS DA PAREDE DE TRÁS - CIMA glPushMatrix() glTranslatef(1.0, 2.5, 0.1) glScalef(1.0, 0.06, 0.25) draw_polygon(dark_wood_cube) glPopMatrix() # TV - CENTRO glPushMatrix() glTranslatef(1.0, 0.8, 0.1) glScalef(1.0, 0.6, 0.05) draw_polygon(gray_cube) glPopMatrix() # TV - BORDA ESQUERDA glPushMatrix() glTranslatef(0.94, 0.8, 0.1) glScalef(0.06, 0.6, 0.08) draw_polygon(black_cube) glPopMatrix() # TV - BORDA DIREITA glPushMatrix() glTranslatef(2.0, 0.8, 0.1) glScalef(0.06, 0.6, 0.08) draw_polygon(black_cube) glPopMatrix() # TV - BORDA BAIXO glPushMatrix() glTranslatef(0.94, 0.74, 0.1) glScalef(1.12, 0.06, 0.08) draw_polygon(black_cube) glPopMatrix() # TV - BORDA CIMA glPushMatrix() glTranslatef(0.94, 1.4, 0.1) glScalef(1.12, 0.06, 0.08) draw_polygon(black_cube) glPopMatrix() # TV RACK - BAIXO glPushMatrix() glTranslatef(0.9, 0.2, 0.1) glScalef(1.2, 0.06, 0.4) draw_polygon(light_wood_cube) glPopMatrix() # TV RACK - CIMA glPushMatrix() glTranslatef(0.9, 0.4, 0.1) glScalef(1.2, 0.06, 0.4) draw_polygon(light_wood_cube) glPopMatrix() # TV RACK - ESQUERDA glPushMatrix() glTranslatef(0.95, 0, 0.1) glScalef(0.06, 0.4, 0.35) draw_polygon(light_wood_cube) glPopMatrix() # TV RACK - DIREITA glPushMatrix() glTranslatef(1.99, 0, 0.1) glScalef(0.06, 0.4, 0.35) draw_polygon(light_wood_cube) glPopMatrix() # SPEAKER - ESQUERDA glPushMatrix() glTranslatef(0.6, 0, 0.1) glScalef(0.2, 0.9, 0.3) draw_polygon(black_cube) glPopMatrix() # SPEAKER - DIREITA glPushMatrix() glTranslatef(2.2, 0, 0.1) glScalef(0.2, 0.9, 0.3) draw_polygon(black_cube) glPopMatrix() # SPEAKER - APARELHO glPushMatrix() glTranslatef(1.2, 0.46, 0.1) glScalef(0.6, 0.2, 0.3) draw_polygon(black_cube) glPopMatrix() # SOFA 1 - COSTAS glPushMatrix() glTranslatef(0.15, 0.1, 1.25) glScalef(0.15, 0.8, 1.5) draw_polygon(sofa_cube) glPopMatrix() # SOFA 1 - BRAÇO DIREITA glPushMatrix() glTranslatef(0.3, 0.1, 1.25) glScalef(0.6, 0.6, 0.15) draw_polygon(sofa_cube) glPopMatrix() # SOFA 1 - BRAÇO ESQUERDA glPushMatrix() glTranslatef(0.3, 0.1, 2.6) glScalef(0.6, 0.6, 0.15) draw_polygon(sofa_cube) glPopMatrix() # SOFA 1 - BASE glPushMatrix() glTranslatef(0.3, 0.05, 1.4) glScalef(0.6, 0.3, 1.2) draw_polygon(sofa_cube) glPopMatrix() # SOFA 1 - ASSENTO 1 glPushMatrix() glTranslatef(0.3, 0.35, 1.38) glScalef(0.6, 0.05, 0.61) draw_polygon(sofa_cube) glPopMatrix() # SOFA 1 - ASSENTO 2 glPushMatrix() glTranslatef(0.3, 0.35, 2.0) glScalef(0.6, 0.05, 0.61) draw_polygon(sofa_cube) glPopMatrix() # SOFA 2 - COSTAS glPushMatrix() glTranslatef(2.7, 0.1, 1.25) glScalef(0.15, 0.8, 1.5) draw_polygon(sofa_cube) glPopMatrix() # SOFA 2 - BRAÇO DIREITA glPushMatrix() glTranslatef(2.1, 0.1, 1.25) glScalef(0.6, 0.6, 0.15) draw_polygon(sofa_cube) glPopMatrix() # SOFA 2 - BRAÇO ESQUERDA glPushMatrix() glTranslatef(2.1, 0.1, 2.6) glScalef(0.6, 0.6, 0.15) draw_polygon(sofa_cube) glPopMatrix() # SOFA 2 - BASE glPushMatrix() glTranslatef(2.1, 0.05, 1.4) glScalef(0.6, 0.3, 1.2) draw_polygon(sofa_cube) glPopMatrix() # SOFA 2 - ASSENTO 1 glPushMatrix() glTranslatef(2.1, 0.35, 1.38) glScalef(0.6, 0.05, 0.61) draw_polygon(sofa_cube) glPopMatrix() # SOFA 2 - ASSENTO 2 glPushMatrix() glTranslatef(2.1, 0.35, 2.0) glScalef(0.6, 0.05, 0.61) draw_polygon(sofa_cube) glPopMatrix() # MESA - CIMA glPushMatrix() glTranslatef(1.2, 0.3, 1.5) glScalef(0.6, 0.1, 1.0) draw_polygon(light_wood_cube) glPopMatrix() # MESA - APOIO TRÁS glPushMatrix() glTranslatef(1.25, 0.1, 1.6) glScalef(0.5, 0.2, 0.2) draw_polygon(light_wood_cube) glPopMatrix() # MESA - APOIO FRENTE glPushMatrix() glTranslatef(1.25, 0.1, 2.2) glScalef(0.5, 0.2, 0.2) draw_polygon(light_wood_cube) glPopMatrix() # PAREDE FRENTE glPushMatrix() glTranslatef(0, 0, 3.9) glScalef(3., 3., 0.1) draw_polygon(wall_cube) glPopMatrix() # PAREDE ESQUERDA - LATERAL glPushMatrix() glTranslatef(0, 1, 0) glScalef(0.1, 1.4, 0.75) draw_polygon(wall_cube) glPopMatrix() # PAREDE ESQUERDA - MEIO glPushMatrix() glTranslatef(0, 1, 1.75) glScalef(0.1, 1.4, 0.5) draw_polygon(wall_cube) glPopMatrix() # PAREDE ESQUERDA - LATERAL glPushMatrix() glTranslatef(0, 1, 3.25) glScalef(0.1, 1.4, 0.75) draw_polygon(wall_cube) glPopMatrix() # PAREDE ESQUERDA - BAIXO glPushMatrix() glScalef(0.1, 1., 4.) draw_polygon(wall_cube) glPopMatrix() # PAREDE ESQUERDA - CIMA glPushMatrix() glTranslatef(0, 2.4, 0) glScalef(0.1, 0.6, 4.) draw_polygon(wall_cube) glPopMatrix() # PERSIANAS sh = mt.get_shear_matrix('x', 'y', -45) for x in range(0, 17): glPushMatrix() glTranslatef(0.125, 1.05 + (x * 0.08), 0.75) glMultMatrixf(sh) glScalef(0.03, 0.01, 1.05) draw_polygon(cube) glPopMatrix() glPushMatrix() glTranslatef(0.125, 1.05 + (x * 0.08), 2.2) glMultMatrixf(sh) glScalef(0.03, 0.01, 1.05) draw_polygon(cube) glPopMatrix() # PAREDE DIREITA glPushMatrix() glTranslatef(2.9, 0., 0.) glScalef(0.1, 3., 4.) draw_polygon(wall_cube) glPopMatrix()
def one_vanishing_point(): objects = [] cube = obj.Obj().import_obj('../objects/cube.obj') color = np.array([254, 178, 76]) / 255 color_material = obj.Material(color, color, [0.8, 0.8, 0.8], 10) # BAIXO S = mt.get_scale_matrix([10, 0.1, 10., 1]) T = mt.get_translation_matrix([0.0, 0.0, 0.]) M = mt.compose_matrices([T, S]) floor = copy.deepcopy(cube) floor.apply_transformation(M) floor.apply_material(color_material) objects.append(floor) # DIREITA T = mt.get_translation_matrix([10, 0.1, 0.]) S = mt.get_scale_matrix([0.1, 10, 10, 1]) M = mt.compose_matrices([T, S]) cube2 = copy.deepcopy(cube) cube2.apply_transformation(M) cube2.apply_material(color_material) objects.append(cube2) # ESQUERDA T = mt.get_translation_matrix([-0.1, 0.1, 0.]) S = mt.get_scale_matrix([0.1, 10, 10, 1]) M = mt.compose_matrices([T, S]) cube3 = copy.deepcopy(cube) cube3.apply_transformation(M) cube3.apply_material(color_material) objects.append(cube3) # CIMA T = mt.get_translation_matrix([0, 10.1, 0]) S = mt.get_scale_matrix([10, 0.1, 10, 1]) M = mt.compose_matrices([T, S]) cube4 = copy.deepcopy(cube) cube4.apply_transformation(M) cube4.apply_material(color_material) objects.append(cube4) punctual_light = PunctualLightSource(intensity=[0.5, 0.5, 0.5], position=[5., 8., 20.]) punctual_light2 = PunctualLightSource(intensity=[0.5, 0.5, 0.5], position=[20., 20., 5.]) d = 1 window_height = 1 window_width = 1 pixels_height = 200 pixels_width = 200 window = Window(window_width, window_height, d, pixels_width, pixels_height) # # ONE VANISHING POINT po = [5., 5., 25, 1.0] look_at = [5., 5., 0, 1.0] a_vup = [5., 6, 0, 1.0] scenario = Scenario(objects=objects, light_sources=[punctual_light, punctual_light2], po=po, look_at=look_at, a_vup=a_vup, background_color=[0., 0., 0.], ambient_light=[0.5, 0.5, 0.5]) scenario.render(window, ray_mean=False, parallel=True, shadow=True, projection_type="PERSPECTIVE", oblique_angle=None, oblique_factor=None)