def glLoadModel_texture(self, filename, translate = V3(0,0,0), scale = V3(1,1,1), texture = None): model = Obj(filename) light = V3(0,0,1) for face in model.faces: vertCount = len(face) v0 = model.vertices[ face[0][0] - 1 ] v1 = model.vertices[ face[1][0] - 1 ] v2 = model.vertices[ face[2][0] - 1 ] if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v0 = self.transform_original(v0,translate, scale) v1 = self.transform_original(v1,translate, scale) v2 = self.transform_original(v2,translate, scale) if vertCount > 3: v3 = self.transform_original(v3,translate, scale) if texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0,0) vt1 = V2(0,0) vt2 = V2(0,0) vt3 = V2(0,0) s1 = V3((v1.x - v0.x), (v1.y - v0.y), (v1.z - v0.z)) s2 = V3((v2.x - v0.x), (v2.y - v0.y), (v2.z - v0.z)) normal = V3(((s1.y * s2.z)- (s2.y * s1.z)), -((s1.x * s2.z)- (s2.x * s1.z)), ((s1.x * s2.y)- (s2.x * s1.y))) try: norm_normal = ( abs(normal.x)**2 + abs(normal.y)**2 + abs(normal.z)**2 )**(1/2) normal = V3((normal.x / norm_normal), (normal.y / norm_normal), (normal.z / norm_normal)) intensity = (normal.x * light.x) + (normal.y * light.y) + (normal.z * light.z) if intensity >=0: self.triangle_bc_texture(v0,v1,v2, texture = texture, texcoords = (vt0,vt1,vt2), intensity = intensity ) if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v3 = self.transform_original(v3,translate, scale) self.triangle_bc_texture(v0,v2,v3, texture = texture, texcoords = (vt0,vt2,vt3), intensity = intensity) except: pass
def loadModel(self, filename, translate=V3(0, 0, 0), scale=V3(1, 1, 1), rotate=V3(0, 0, 0), isWireframe=False): model = Obj(filename) modelMatrix = self.createObjectMatrix(translate, scale, rotate) rotationMatrix = self.createRotationMatrix(rotate) for face in model.faces: vertCount = len(face) v0 = model.vertices[face[0][0] - 1] v1 = model.vertices[face[1][0] - 1] v2 = model.vertices[face[2][0] - 1] if vertCount > 3: v3 = model.vertices[face[3][0] - 1] v0 = self.transform(v0, modelMatrix) v1 = self.transform(v1, modelMatrix) v2 = self.transform(v2, modelMatrix) if vertCount > 3: v3 = self.transform(v3, modelMatrix) if self.active_texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0, 0) vt1 = V2(0, 0) vt2 = V2(0, 0) vt3 = V2(0, 0) vn0 = model.normals[face[0][2] - 1] vn1 = model.normals[face[1][2] - 1] vn2 = model.normals[face[2][2] - 1] vn0 = self.dirTransform(vn0, rotationMatrix) vn1 = self.dirTransform(vn1, rotationMatrix) vn2 = self.dirTransform(vn2, rotationMatrix) if vertCount > 3: vn3 = model.normals[face[3][2] - 1] vn3 = self.dirTransform(vn3, rotationMatrix) self.triangle_bc(v0, v1, v2, texcoords=( vt0, vt1, vt2), normals=(vn0, vn1, vn2)) if vertCount > 3: # asumamos que 4, un cuadrado self.triangle_bc(v0, v2, v3, texcoords=( vt0, vt2, vt3), normals=(vn1, vn2, vn3))
def glLoadModel(self, filename, translate = V3(0,0,0), scale = V3(1,1,1), rotate=V3(0,0,0)): model = Obj(filename) mMatrix = modelMatrix(translate, scale, rotate) rMatrix = rotationMatrix(rotate) for face in model.faces: vertCount = len(face) v0 = model.vertices[ face[0][0] - 1 ] v1 = model.vertices[ face[1][0] - 1 ] v2 = model.vertices[ face[2][0] - 1 ] if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v0 = self.transform(v0, mMatrix) v1 = self.transform(v1, mMatrix) v2 = self.transform(v2, mMatrix) if vertCount > 3: v3 = self.transform(v3, mMatrix) if self.active_texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0,0) vt1 = V2(0,0) vt2 = V2(0,0) vt3 = V2(0,0) vn0 = model.normals[face[0][2] - 1] vn1 = model.normals[face[1][2] - 1] vn2 = model.normals[face[2][2] - 1] vn0 = self.dirTransform(vn0, rMatrix) vn1 = self.dirTransform(vn1, rMatrix) vn2 = self.dirTransform(vn2, rMatrix) if vertCount > 3: vn3 = model.normals[face[3][2] - 1] vn3 = self.dirTransform(vn3, rMatrix) try: self.triangle_bc(v0,v1,v2, texcoords = (vt0,vt1,vt2), normals = (vn0,vn1,vn2)) if vertCount > 3: self.triangle_bc(v0,v2,v3, texcoords = (vt0,vt2,vt3), normals = (vn0,vn2,vn3)) except: pass
def detect_bounce(msg): analysis = lamson.bounce.detect(Obj(base=lamson.encoding.from_message(msg))) print('Lamson bounce analysis: {}'.format(analysis.__dict__)) if analysis.is_hard(): print('Hard bounce.') return ResponseType.hard if analysis.is_soft(): print('Soft bounce.') return ResponseType.soft # TODO: detect complaints return ResponseType.unknown
def __init__(self, filename, texture_name, scale): self.model = Obj(filename) self.createVertBuffer() self.texture_surface = pygame.image.load(texture_name) self.texture_data = pygame.image.tostring(self.texture_surface, "RGB", 1) self.texture = glGenTextures(1) self.position = glm.vec3(0, 0, 0) self.rotation = glm.vec3(0, 0, 0) self.scale = scale
def generateFood(self): row = None col = None while True: row = random.randint(0, util.Constants.GAME_WINDOW_HEIGHT) col = random.randint(0, util.Constants.GAME_WINDOW_WIDTH) if self.board[row][col] == None: self.food = Obj(row, col, util.Constants.FOOD_COLOR) self.placeObj(self.food) return self.food
def __init__(self): self.bg = Obj("assets/bg.png", 0, 0) self.bg2 = Obj("assets/bg.png", 0, -640) self.spider = Obj("assets/spider1.png", random.randrange(0, 320), -50) self.flower = Obj("assets/florwer1.png", random.randrange(0, 320), 200) self.bee = Bee("assets/bee1.png", 150, 600) self.change_scene = False self.score = Text(120, "0") self.lifes = Text(60, "3")
def init_grid(dimension): grid = [] for row in range(dimension): grid.append([]) for col in range(dimension): piece = Obj(row, col) grid[row].append(piece) return grid
def draw(self): temp_objects = [] if (self.score_window): self.draw_score() else: if (self.run): for i in self.sector[0].enemies: for j in i.laser: if (j.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(j) if (i.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(i) for i in self.sector[0].obstacles: if (i.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(i) for i in self.sector[0].powerups: if (i.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(i) temp_objects.append(self.player) for i in self.player.laser: temp_objects.append(i) hud = [ Obj(Vector2D(self.view.pos.x + 1, 2), Graphics.draw_hline(148, 1)), Obj(Vector2D(self.view.pos.x + 1, 1), "HP:[" + "â–ˆ" * (self.player.hp * 2) + " " * (10 - self.player.hp * 2) + "]", fore_color=colorama.Fore.RED, bg_color=colorama.Back.BLACK, style=colorama.Style.BRIGHT), Obj( Vector2D(self.view.pos.x + 135, 1), "Score:[" + " " * (6 - len(str(self.score))) + str(self.score) + "]") ] self.last_matrix = Graphics.draw(temp_objects, self.view, matrix=self.last_matrix, hud=hud)
def load(self, filename, translate, scale, texture=None): model = Obj(filename) light = V3(0, 0, 1) for face in model.faces: vcount = len(face) vertices = [] tvertices = [] for j in range(vcount): f1 = face[j][0] - 1 v1 = model.vertices[f1] x1 = round((v1[0] + translate[0]) * scale[0]) y1 = round((v1[1] + translate[1]) * scale[1]) z1 = round((v1[2] + translate[2]) * scale[2]) # self.glLine(V2(x1, y1), V2(x2, y2), glColor(random.randint(0,255),random.randint(0,255),random.randint(0,255))) vertices.append(V3(x1, y1, z1)) f1t = face[j][1] - 1 v1t = model.tvertices[f1t] tvertices.append(V2(v1t[0], v1t[1])) randomColor = glColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) A = vertices[0] B = vertices[1] C = vertices[2] normal = norm(cross(sub(B, A), sub(C, A))) intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue # intensityColor = glColor(grey,grey,grey) tA = vertices[0] tB = vertices[1] tC = vertices[2] self.triangle(vertices=(A, B, C), tvertices=(tA, tB, tC), texture=texture # intensityColor )
def push_the_objects(self): tmi_values = tmi.values() for i in range(config['height'] // 8): for j in range(config['width'] // 8): data = pyxel.tilemap(self.current_tm).get( j + self.tm_offsetX, i + self.tm_offsetY) if data in tmi_values: self.world.push( Obj(j * 8, i * 8, 8, 8, get_key(tmi, data)[0]))
def draw(objects, view, **kwargs): last_matrix = kwargs.get("matrix", []) #last matrix matrix = [[["", "", "", ""] for i in range(151)] for i in range(51)] #matrix of the Gamefield if no matrix background = kwargs.get("background", [ Obj(Vector2D(view.pos.x, 0), Graphics.draw_rect(150, 50, 1, " "), transparent=False) ]) hud = kwargs.get("hud", []) matrix = Graphics.create_Matrix(matrix, background, view) #Background gets added to Matrix matrix = Graphics.create_Matrix(matrix, objects, view) #All Objects get added to Matrix matrix = Graphics.create_Matrix(matrix, hud, view) #Hud if visible gets added to Matrix if (last_matrix != []): last_style = "" last_font_color = "" last_background_color = "" for y in range(0, len(last_matrix)): for x in range(1, len(last_matrix[y]) - 2): if (last_matrix[y][x][3] != matrix[y][x][3] or last_matrix[y][x][2] != matrix[y][x][2] or last_matrix[y][x][1] != matrix[y][x][1]): if (matrix[y][x][0] != last_style): sys.stdout.write("\033[" + str(y + 1) + ";" + str(x + 1) + "H" + matrix[y][x][0]) last_style = matrix[y][x][0] if (matrix[y][x][1] != last_font_color): sys.stdout.write("\033[" + str(y + 1) + ";" + str(x + 1) + "H" + matrix[y][x][1]) last_font_color = matrix[y][x][1] if (matrix[y][x][2] != last_background_color): sys.stdout.write("\033[" + str(y + 1) + ";" + str(x + 1) + "H" + matrix[y][x][2]) last_background_color = matrix[y][x][2] sys.stdout.write("\033[" + str(y + 1) + ";" + str(x + 1) + "H" + matrix[y][x][3]) else: sys.stdout.write("\033[1;1H" + Graphics.convert_Matrix(matrix)) sys.stdout.flush() return matrix
def Model(self, filename, translate, scale): modelo = Obj(filename) for face in modelo.faces: vertCount = len(face) for vert in range(vertCount): v0 = modelo.vertices[face[vert][0] - 1] v1 = modelo.vertices[face[(vert + 1) % vertCount][0] - 1] x0 = int(v0[0] * scale[0] + translate[0]) y0 = int(v0[1] * scale[1] + translate[1]) x1 = int(v1[0] * scale[0] + translate[0]) y1 = int(v1[1] * scale[1] + translate[1]) self.glLine(x0, y0, x1, y1)
def load(self, filename, translate, scale): model = Obj(filename) light = V3(0, 0, 1) for face in model.faces: vcount = len(face) if vcount == 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 a = self.transform(model.vertices[f1], translate, scale) b = self.transform(model.vertices[f2], translate, scale) c = self.transform(model.vertices[f3], translate, scale) normal = norm(cross(sub(b, a), sub(c, a))) intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue self.triangle(a, b, c, intensity) else: # assuming 4 f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f4 = face[3][0] - 1 vertices = [ self.transform(model.vertices[f1], translate, scale), self.transform(model.vertices[f2], translate, scale), self.transform(model.vertices[f3], translate, scale), self.transform(model.vertices[f4], translate, scale) ] normal = norm( cross(sub(vertices[0], vertices[1]), sub(vertices[1], vertices[2]))) # no necesitamos dos normales!! intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue # dont paint this face # vertices are ordered, no need to sort! # vertices.sort(key=lambda v: v.x + v.y) A, B, C, D = vertices self.triangle(A, B, C, intensity) self.triangle(A, C, D, intensity)
def loadModel(self, filename, translate = V3(0,0,0), scale = V3(1,1,1), isWireframe = False): model = Obj(filename) for face in model.faces: vertCount = len(face) if isWireframe: for vert in range(vertCount): v0 = model.vertices[ face[vert][0] - 1 ] v1 = model.vertices[ face[(vert + 1) % vertCount][0] - 1] v0 = V2(round(v0[0] * scale.x + translate.x), round(v0[1] * scale.y + translate.y)) v1 = V2(round(v1[0] * scale.x + translate.x), round(v1[1] * scale.y + translate.y)) self.glLine_coord(v0, v1) else: v0 = model.vertices[ face[0][0] - 1 ] v1 = model.vertices[ face[1][0] - 1 ] v2 = model.vertices[ face[2][0] - 1 ] if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v0 = self.transform(v0,translate, scale) v1 = self.transform(v1,translate, scale) v2 = self.transform(v2,translate, scale) if vertCount > 3: v3 = self.transform(v3,translate, scale) if self.active_texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0,0) vt1 = V2(0,0) vt2 = V2(0,0) vt3 = V2(0,0) vn0 = model.normals[face[0][2] - 1] vn1 = model.normals[face[1][2] - 1] vn2 = model.normals[face[2][2] - 1] if vertCount > 3: vn3 = model.normals[face[3][2] - 1] self.triangle_bc(v0,v1,v2, texcoords = (vt0,vt1,vt2), normals = (vn0,vn1,vn2)) if vertCount > 3: #asumamos que 4, un cuadrado self.triangle_bc(v0,v2,v3, texcoords = (vt0,vt2,vt3), normals = (vn0,vn2,vn3))
def loadRoom(self, gameName, roomName): roomPath = './saved_games/' + gameName + '/rooms/' + roomName + '.txt' if os.path.exists(roomPath) == False: return -1 else: inputRoom = open(roomPath, 'r') for line in inputRoom: roomData = '' if 'features' in line: words = re.split("[:,]+", line) words = [x.strip() for x in words] roomData = [] if len(words) > 1: for x in words[1:]: if x != '': myFeature = Feature() myFeature.loadFeature(gameName, x) roomData.append(myFeature) elif 'pickupObjects' in line: words = re.split("[:,]+", line) words = [x.strip() for x in words] roomData = [] if len(words) > 1: for x in words[1:]: if x != '': myObject = Obj() myObject.loadObject(gameName, x) roomData.append(myObject) else: words = re.split("[:]+", line) words = [x.strip() for x in words] if words[0] == 'visited': if(words[1] == 'True'): roomData = True else: roomData = False elif len(words) > 1: roomData = fixColor(words[1]) setattr(self, words[0], roomData)
def glLoadModel_poli(self, filename, translate, scale): model = Obj(filename) for face in model.faces: vc = len(face) for i in range(vc): v0 = model.vertices[ face[i][0] - 1 ] v1 = model.vertices[ face[(i + 1) % vc][0] - 1] lv0 = V2(round(v0[0] * scale[0] + translate[0]), round(v0[1] * scale[1] + translate[1])) lv1 = V2(round(v1[0] * scale[0] + translate[0]), round(v1[1] * scale[1] + translate[1])) self.line(lv0 , lv1)
def __init__(self): self.all_sprites = pygame.sprite.Group() self.coin_group = pygame.sprite.Group() self.pipes_group = pygame.sprite.Group() self.bg = Obj("assets/sky.png", 0, 0, self.all_sprites) self.bg2 = Obj("assets/sky.png", 360, 0, self.all_sprites) self.ground = Obj("assets/ground.png", 0, 480, self.all_sprites) self.ground2 = Obj("assets/ground.png", 0, 480, self.all_sprites) self.score = Text(100, "0") self.bird = Bird("assets/bird1.png", 50, 320, self.all_sprites) self.change_scence = False self.ticks = 0 self.timer = 0 self.max_score = 0 self.check_score()
def load(self, filename, translate, scale): model = Obj(filename) light = self.light for face in model.faces: vcount = len(face) if vcount == 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 a = self.transform(model.vertices[f1], translate, scale) b = self.transform(model.vertices[f2], translate, scale) c = self.transform(model.vertices[f3], translate, scale) normal = norm(cross(sub(b, a), sub(c, a))) intensity = dot(normal, light) grey = round(255 * intensity) # if intensity < 0: # return # if grey < 0: # continue self.triangle(a, b, c, intensity) else: # assuming 4 f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f4 = face[3][0] - 1 vertices = [ self.transform(model.vertices[f1], translate, scale), self.transform(model.vertices[f2], translate, scale), self.transform(model.vertices[f3], translate, scale), self.transform(model.vertices[f4], translate, scale) ] normal = norm( cross(sub(vertices[0], vertices[1]), sub(vertices[1], vertices[2]))) # no necesitamos dos normales!! intensity = dot(normal, light) grey = round(255) # if grey < 0: # continue A, B, C, D = vertices self.triangle(A, B, C, intensity) self.triangle(A, C, D, intensity)
def load(self, filename, translate=(0, 0, 0), scale=(1, 1, 1)): """ Loads an obj file in the screen wireframe only Input: filename: the full path of the obj file translate: (translateX, translateY) how much the model will be translated during render scale: (scaleX, scaleY) how much the model should be scaled """ model = Obj(filename) for face in model.vfaces: vcount = len(face) if vcount == 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 a = self.transform(model.vertices[f1], translate, scale) b = self.transform(model.vertices[f2], translate, scale) c = self.transform(model.vertices[f3], translate, scale) self.triangle( a, b, c, glColor(random.randint(0, 1), random.randint(0, 1), random.randint(0, 1))) else: # assuming 4 f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f4 = face[3][0] - 1 vertices = [ self.transform(model.vertices[f1], translate, scale), self.transform(model.vertices[f2], translate, scale), self.transform(model.vertices[f3], translate, scale), self.transform(model.vertices[f4], translate, scale) ] A, B, C, D = vertices self.triangle( A, B, C, glColor(random.randint(0, 1), random.randint(0, 1), random.randint(0, 1))) self.triangle( A, C, D, glColor(random.randint(0, 1), random.randint(0, 1), random.randint(0, 1)))
def __init__(self): self.todos_sprites = pygame.sprite.Group() self.bg1 = Obj("assets/idéia.png", 0, 0, self.todos_sprites) # self.ground = Obj("imagem", 0, 480, self.todos_sprites) # self.ground2 = Obj("imagem", 360, 480, self.todos_sprites) # self.get_ready = Obj("imagem", 60, 100, self.todos_sprites) # self.table_score = Obj("imagem", 20, 200, self.todos_sprites) # self.button_go = Obj("imagem", 100, 420, self.todos_sprites) self.mudar_cenario = False
def load(self, filename, scale=(1, 1, 1), translate=(0, 0, 0)): model = Obj(filename) light = V3(0, 0, 1) for face in model.vfaces: vcount = len(face) if vcount == 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 a = self.transform(model.vertices[f1], translate, scale) b = self.transform(model.vertices[f2], translate, scale) c = self.transform(model.vertices[f3], translate, scale) normal = norm(cross(sub(b, a), sub(c, a))) intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue self.triangle(a, b, c, color(grey, grey, grey)) else: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f4 = face[3][0] - 1 vertices = [ self.transform(model.vertices[f1], translate, scale), self.transform(model.vertices[f2], translate, scale), self.transform(model.vertices[f3], translate, scale), self.transform(model.vertices[f4], translate, scale) ] normal = norm( cross(sub(vertices[0], vertices[1]), sub(vertices[1], vertices[2]))) intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue A, B, C, D = vertices self.triangle(A, B, C, color(grey, grey, grey)) self.triangle(A, C, D, color(grey, grey, grey))
def __init__(self): self.room_objects = [ Obj(Vector2D(self.view.pos.x+5,1),load_texture("other",0),style = colorama.Style.BRIGHT), Obj(Vector2D(self.view.pos.x+5,10),load_texture("other",4)), Obj(Vector2D(self.view.pos.x+5,15),load_texture("other",4)), Obj(Vector2D(self.view.pos.x+5+3,12),"Start Game"), Obj(Vector2D(self.view.pos.x+5+3,17),"Exit"), Obj(Vector2D(self.view.pos.x+50, 12), "How to play:\n W,A,S,D = Bewegen(ohne schiessen)\n Pfeil Tasten = Bewegen(mit schiessen)\n Alle Tasten ausser W,A,S,D,Enter,Esc = Schiessen") ];
def glLoadModel_shaders(self, filename, translate = V3(0,0,0), scale = V3(1,1,1)): model = Obj(filename) #light = V3(0,0,1) for face in model.faces: vertCount = len(face) v0 = model.vertices[ face[0][0] - 1 ] v1 = model.vertices[ face[1][0] - 1 ] v2 = model.vertices[ face[2][0] - 1 ] if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v0 = self.transform_original(v0,translate, scale) v1 = self.transform_original(v1,translate, scale) v2 = self.transform_original(v2,translate, scale) if vertCount > 3: v3 = self.transform_original(v3,translate, scale) if self.active_texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0,0) vt1 = V2(0,0) vt2 = V2(0,0) vt3 = V2(0,0) vn0 = model.normals[face[0][2] - 1] vn1 = model.normals[face[1][2] - 1] vn2 = model.normals[face[2][2] - 1] if vertCount > 3: vn3 = model.normals[face[3][2] - 1] try: self.triangle_bc(v0,v1,v2, texcoords = (vt0,vt1,vt2), normals = (vn0,vn1,vn2)) if vertCount > 3: self.triangle_bc(v0,v2,v3, texcoords = (vt0,vt2,vt3), normals = (vn0,vn2,vn3)) except: pass
def load_model_2D(self, filename, translate, scale): model = Obj(filename) posX, posY = self.ndp_to_pixels(translate['x'], translate['y']) for face in model.faces: vertex_count = len(face) for vertex in range(vertex_count): v0 = model.vertices[face[vertex][0] - 1] v1 = model.vertices[face[(vertex + 1) % vertex_count][0] - 1] x0, y0 = round(v0[0] * scale['x'] + posX), round(v0[1] * scale['y'] + posY) x1, y1 = round(v1[0] * scale['x'] + posX), round(v1[1] * scale['y'] + posY) self.glLine_coords(x0, y0, x1, y1)
def load(self, filename, translate, scale): model = Obj(filename) light = V3(0,0,1) for face in model.faces: vcount = len(face) vertices = [] for j in range(vcount): f1 = face[j][0] - 1 f2 = face[(j + 1) % vcount][0] - 1 v1 = model.vertices[f1] v2 = model.vertices[f2] x1 = round((v1[0] + translate[0]) * scale[0]) y1 = round((v1[1] + translate[1]) * scale[1]) z1 = round((v1[2] + translate[2]) * scale[2]) x2 = round((v2[0] + translate[0]) * scale[0]) y2 = round((v2[1] + translate[1]) * scale[1]) z2 = round((v2[2] + translate[2]) * scale[2]) # self.glLine(V2(x1, y1), V2(x2, y2), glColor(random.randint(0,255),random.randint(0,255),random.randint(0,255))) vertices.append(V3(x1, y1, z1)) randomColor = glColor(random.randint(0,255),random.randint(0,255),random.randint(0,255)) A = vertices[0] B = vertices[1] C = vertices[2] normal = norm(cross(sub(B, A), sub(C, A))) intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue intensityColor = glColor(grey,grey,grey) self.triangle(A,B,C, intensityColor) if vcount == 4: D = vertices[3] self.triangle(A,C,D, intensityColor)
def __init__(self): self.all_sprites = pygame.sprite.Group() self.bg = Obj("assets/sky.png", 0, 0, self.all_sprites) self.bg2 = Obj("assets/sky.png", 360, 0, self.all_sprites) self.ground = Obj("assets/ground.png", 0, 480, self.all_sprites) self.ground2 = Obj("assets/ground.png", 0, 480, self.all_sprites) self.get_ready = Obj("assets/getready.png", 60, 100, self.all_sprites) self.table_score = Obj("assets/score.png", 25, 200, self.all_sprites) self.buttom_go = Obj("assets/go.png", 100, 410, self.all_sprites) self.change_scene = False self.text_score = Text(100, "0")
def loadModel(self, filename, translate=V3(0, 0, 0), scale=V3(1, 1, 1), isWireframe=False): model = Obj(filename) light = V3(0, 0, 1) for face in model.faces: vertCount = len(face) if isWireframe: for vert in range(vertCount): v0 = model.vertices[face[vert][0] - 1] v1 = model.vertices[face[(vert + 1) % vertCount][0] - 1] v0 = V2(round(v0[0] * scale.x + translate.x), round(v0[1] * scale.y + translate.y)) v1 = V2(round(v1[0] * scale.x + translate.x), round(v1[1] * scale.y + translate.y)) self.glLine_coord(v0, v1) else: v0 = model.vertices[face[0][0] - 1] v1 = model.vertices[face[1][0] - 1] v2 = model.vertices[face[2][0] - 1] v0 = self.transform(v0, translate, scale) v1 = self.transform(v1, translate, scale) v2 = self.transform(v2, translate, scale) normal = cross(substract(v1, v0), substract(v2, v0)) intensity = dot(norm(normal), norm(light)) if intensity >= 0: self.triangle_bc(v0, v1, v2, color(intensity, intensity, intensity)) # Manage square rendering if vertCount > 3: v3 = model.vertices[face[3][0] - 1] v3 = self.transform(v3, translate, scale) if intensity >= 0: self.triangle_bc( v0, v2, v3, color(intensity, intensity, intensity))
def load(self, filename, translate, scale): model = Obj(filename) for face in model.faces: vcount = len(face) for j in range(vcount): vi1 = face[j][0] - 1 vi2 = face[(j + 1) % vcount][0] - 1 v1 = model.vertices[vi1] v2 = model.vertices[vi2] x1 = round((v1[0] + scale[0]) * translate[0]) y1 = round((v1[1] + scale[1]) * translate[1]) x2 = round((v2[0] + scale[0]) * translate[0]) y2 = round((v2[1] + scale[1]) * translate[1]) self.Line(x1, y1, x2, y2)
def load(self, filename, translate, scale): model = Obj(filename) for face in model.faces: vcount = len(face) for j in range(vcount): vi1 = face[j][0] - 1 vi2 = face[(j + 1) % vcount][0] - 1 v1 = model.vertices[vi1] v2 = model.vertices[vi2] x1 = round(v1[0] * scale[0]) + translate[0] y1 = round(v1[1] * scale[1]) + translate[1] x2 = round(v2[0] * scale[0]) + translate[0] y2 = round(v2[1] * scale[1]) + translate[1] self.line(V2(x1, y1), V2(x2, y2))
monster_list = deque() # init rendering update_queue = deque() # Queue of rects specifying areas of display to update background = Background(WINDOW_WIDTH, WINDOW_HEIGHT, GREY) background.render(screen, update_queue) # draw a bunch of garbage cans (debug) gbg_can_size = IMG_SIZES["garbage_can"] x_coord = TILE_SIZE * 3 while x_coord < TILE_SIZE * 10: y_coord = TILE_SIZE * 3 while y_coord < WINDOW_HEIGHT: gbg_can = Obj(x_coord, y_coord, gbg_can_size[0], gbg_can_size[1]) gbg_can.img = load_img(GBG_CAN_N) gbg_can.render(screen, update_queue) env_obj_list.append(gbg_can) y_coord += TILE_SIZE * 2 x_coord += TILE_SIZE * 2 # Draw player (debug) player_size = IMG_SIZES["man_standing"] player = Player(WINDOW_WIDTH, WINDOW_HEIGHT, player_size[0], player_size[1]) player.img = load_img(MAN_STAND_N) player.render(screen, update_queue)