def render(self): pos = self.transform.position forward = self.transform.forward # print("pos: ", pos, "forward: ", forward, "rotation: ", self.transform.rotation) target = pos + forward gluLookAt(pos.x, pos.y, pos.z, target.x, target.y, target.z, 0, 1, 0)
def __init__(self, title='', fps=60, fullscreen=False, size=(800, 600), offset=(0, 0)): self.title = title self.fps = fps self.fullscreen = fullscreen self.size = size self.width, self.height = offset self.delta = 0 self.currentFrame = self.get_time() self.lastFrame = self.get_time() if self.fullscreen: self.surface = pygame.display.set_mode(self.size, FULLSCREEN | HWSURFACE | DOUBLEBUF | OPENGL) else: self.surface = pygame.display.set_mode(self.size, DOUBLEBUF | OPENGL) pygame.display.set_caption(self.title) ratio = (self.width ** 2 + self.height ** 2) / 325 glClearColor(0.83137254902, 0.83137254902, 0.83137254902, 1) gluPerspective(60, (size[0] / size[1]), 0.1, 1000.0) gluLookAt(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) gluLookAt(4 * ratio, 4 * ratio, 8 * ratio, 0, 0, 0, 0, 0, 1) glRotatef(135, 0, 0, 1) glRotatef(5, 0, 0, 1) glTranslatef(-self.width / 2, self.height / 2 + 1, 0) glEnable(GL_DEPTH_TEST) glEnable(GL_LINE_SMOOTH) glEnable(GL_POLYGON_SMOOTH) glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST) glEnable(GL_BLEND) glLineWidth(1) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
def setTransformLookAt(self, eye, lookat, up): glMatrixMode(GL_MODELVIEW) glLoadIdentity() gluLookAt(eye[0], eye[1], eye[2], lookat[0], lookat[1], lookat[2], up[0], up[1], up[2]) glLightfv(GL_LIGHT0, GL_AMBIENT, [0.8, 0.8, 0.8, 1.0]) glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0]) glLightfv(GL_LIGHT0, GL_POSITION, [0.0, 0.0, 1.0, 0.0])
def look_at(cls, eye_x: float, eye_y: float, eye_z: float, center_x: float, center_y: float, center_z: float, up_x: float = 0., up_y: float = 1., up_z: float = 0.): gluLookAt(eye_x, eye_y, eye_z, center_x, center_y, center_z, up_x, up_y, up_z)
def draw(): global step, delta, lid glClearColor(1, 1, 1, 0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() gluLookAt(0.0, 0.0, step, 0.0, 0.0, step-delta, 0.0, 1.0, 0.0) glCallList(lid) glEnable(GL_DEPTH_TEST) glutSwapBuffers() time.sleep(0.05)
def base_settings(self): glClearColor(1., 1., 1., 1.) # цвет фона glShadeModel(GL_SMOOTH) glEnable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glLightfv(GL_LIGHT0, GL_DIFFUSE, self.light_color) glLightfv(GL_LIGHT0, GL_POSITION, self.lightpos) # Источник света glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1) glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05) glEnable(GL_LIGHT0) glMatrixMode(GL_PROJECTION) gluPerspective(*self.perspective) glMatrixMode(GL_MODELVIEW) gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0)
def paintGL(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glPushMatrix() gluLookAt(0.0, 2.5, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) glRotatef(self.angle, 0.0, 1.0, 0.0) glBegin(GL_TRIANGLES) glColor3f(1.0, 1.0, 0.0) glVertex3f(0.0, 1.0, 0.0) glVertex3f(-1.0, -1.0, 0.0) glVertex3f(1.0, -1.0, 0.0) glEnd() glPopMatrix() glFlush()
def draw(self): glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, 1.65, 0.1, 500) gluLookAt(self.xizi, self.yizi - 50, 3.9, self.xizi, self.yizi, 0, 0, 1, 0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() glColor3f(1.0, 1.0, 1.0) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) # glRotate(20, 0, 0, 1) glPushMatrix() # glBindTexture(GL_TEXTURE_2D, self.casco) # # #Base da nave # glBegin(GL_TRIANGLE_FAN) # glTexCoord2f(0, 1) # glVertex3f(self.move_x + 0, self.move_y + 0, 1) # glTexCoord2f(1, 1) # glVertex3f(self.move_x + 0, self.move_y + 6, 1) # glTexCoord2f(1, 0) # glVertex3f(self.move_x + 1.5, self.move_y + 3, 1) # glTexCoord2f(0, 0) # glVertex3f(self.move_x + 2, self.move_y + 0, 1) # glTexCoord2f(0, 1) # glVertex3f(self.move_x + 5, self.move_y - 6, 1) # glTexCoord2f(1, 1) # glVertex3f(self.move_x + 2, self.move_y - 7, 1) # glTexCoord2f(1, 0) # glVertex3f(self.move_x + 1, self.move_y - 7, 1) # glTexCoord2f(1, 1) # glVertex3f(self.move_x + 0, self.move_y - 8, 1) # glTexCoord2f(1, 0) # glVertex3f(self.move_x - 1, self.move_y - 7, 1) # glTexCoord2f(0, 0) # glVertex3f(self.move_x - 2, self.move_y - 7, 1) # glTexCoord2f(0, 1) # glVertex3f(self.move_x - 5, self.move_y - 6, 1) # glTexCoord2f(1, 1) # glVertex3f(self.move_x - 2, self.move_y + 0, 1) # glTexCoord2f(1, 0) # glVertex3f(self.move_x - 1.5, self.move_y + 3, 1) # glTexCoord2f(0, 0) # glVertex3f(self.move_x + 0, self.move_y + 6, 1) # glEnd() # # #Casco da nave (fora) # glBegin(GL_QUAD_STRIP) # glTexCoord2f(0, 1) # glVertex3f(self.move_x + 0, self.move_y + 6, 1) # glVertex3f(self.move_x + 0, self.move_y + 3, 2) # glVertex3f(self.move_x + 1.5, self.move_y + 3, 1) # glVertex3f(self.move_x + 0.5, self.move_y + 2, 2) # glVertex3f(self.move_x + 2, self.move_y + 0, 1) # glVertex3f(self.move_x + 1, self.move_y + 0, 2) # glVertex3f(self.move_x + 5, self.move_y - 6, 1) # glVertex3f(self.move_x + 2, self.move_y - 4, 2) # glTexCoord2f(1, 1) # glVertex3f(self.move_x + 2, self.move_y - 7, 1) # glVertex3f(self.move_x + 1, self.move_y - 6, 2) # glVertex3f(self.move_x + 1, self.move_y - 7, 1) # glVertex3f(self.move_x + 0.5, self.move_y - 6, 2) # glVertex3f(self.move_x + 0, self.move_y - 8, 1) # glVertex3f(self.move_x + 0, self.move_y - 7, 2) # glVertex3f(self.move_x - 1, self.move_y - 7, 1) # glTexCoord2f(1, 0) # glVertex3f(self.move_x - 0.5, self.move_y - 6, 2) # glVertex3f(self.move_x - 2, self.move_y - 7, 1) # glVertex3f(self.move_x - 1, self.move_y - 6, 2) # glVertex3f(self.move_x - 5, self.move_y - 6, 1) # glVertex3f(self.move_x - 2, self.move_y - 4, 2) # glVertex3f(self.move_x - 2, self.move_y + 0, 1) # glTexCoord2f(0, 0) # glVertex3f(self.move_x - 1, self.move_y + 0, 2) # glVertex3f(self.move_x - 1.5, self.move_y + 3, 1) # glVertex3f(self.move_x - 0.5, self.move_y + 2, 2) # glVertex3f(self.move_x + 0, self.move_y + 6, 1) # glVertex3f(self.move_x + 0, self.move_y + 3, 2) # glEnd() # # glDisable(GL_TEXTURE_2D) # # glColor3f(1.0, 1.0, 1.0) # glDisable(GL_LIGHTING) # glEnable(GL_TEXTURE_2D) # # glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) # # glBindTexture(GL_TEXTURE_2D, self.metal) # # #Parte verde # glBegin(GL_QUAD_STRIP) # glTexCoord2f(0, 1) # glVertex3f(self.move_x + 0, self.move_y + 3, 2) # glVertex3f(self.move_x + 0, self.move_y + 2, 2.5) # glVertex3f(self.move_x + 0.5, self.move_y + 2, 2) # glVertex3f(self.move_x + 0.5, self.move_y + 1, 2.5) # glVertex3f(self.move_x + 1, self.move_y + 0, 2) # glVertex3f(self.move_x + 0.5, self.move_y + 0, 2.5) # glVertex3f(self.move_x + 2, self.move_y - 4, 2) # glTexCoord2f(1, 1) # glVertex3f(self.move_x + 1, self.move_y - 4, 2.5) # glVertex3f(self.move_x + 1, self.move_y - 6, 2) # glVertex3f(self.move_x + 1, self.move_y - 5, 2.5) # glVertex3f(self.move_x + 0.5, self.move_y - 6, 2) # glVertex3f(self.move_x + 0.5, self.move_y - 5, 2.5) # glVertex3f(self.move_x + 0, self.move_y - 7, 2) # glVertex3f(self.move_x + 0, self.move_y - 5, 2.5) # glVertex3f(self.move_x - 0.5, self.move_y - 6, 2) # glTexCoord2f(1, 0) # glVertex3f(self.move_x - 0.5, self.move_y - 5, 2.5) # glVertex3f(self.move_x - 1, self.move_y - 6, 2) # glVertex3f(self.move_x - 1, self.move_y - 5, 2.5) # glVertex3f(self.move_x - 2, self.move_y - 4, 2) # glVertex3f(self.move_x - 1, self.move_y - 4, 2.5) # glVertex3f(self.move_x - 1, self.move_y + 0, 2) # glTexCoord2f(0, 0) # glVertex3f(self.move_x - 0.5, self.move_y + 0, 2.5) # glVertex3f(self.move_x - 0.5, self.move_y + 2, 2) # glVertex3f(self.move_x - 0.5, self.move_y + 1, 2.5) # glVertex3f(self.move_x + 0, self.move_y + 3, 2) # glVertex3f(self.move_x + 0, self.move_y + 2, 2.5) # glEnd() # # glDisable(GL_TEXTURE_2D) # # glColor3f(1.0, 1.0, 1.0) # glEnable(GL_TEXTURE_2D) # # glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) # glBindTexture(GL_TEXTURE_2D, self.vidro) # # #Mira # # glDisable(GL_TEXTURE_2D) glColor3f(1, 0, 0) glBegin(GL_LINES) glVertex3f(self.move_x + 0, self.move_y + 70, 3) glVertex3f(self.move_x + 0, self.move_y + 70, -3) glEnd() glBegin(GL_LINES) glVertex3f(self.move_x + 3, self.move_y + 70, 0) glVertex3f(self.move_x + -3, self.move_y + 70, 0) glEnd() glPopMatrix() glColor3f(1.0, 1.0, 1.0) glEnable(GL_TEXTURE_2D) glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glBindTexture(GL_TEXTURE_2D, self.vidro) #Cookpit # glPushMatrix() glBegin(GL_QUADS) glTexCoord2f(0, 0) glVertex3f(self.move_x + -11, self.move_y + 6.9, 9.5) glTexCoord2f(1, 0) glVertex3f(self.move_x + 11, self.move_y + 6.9, 9.5) glTexCoord2f(1, 1) glVertex3f(self.move_x + 11, self.move_y + 6.9, -4) glTexCoord2f(0, 1) glVertex3f(self.move_x + -11, self.move_y + 6.9, -4) # glTexCoord2f(0, 1) # glVertex3f(self.move_x+ -50, self.move_y +50, 50) # glTexCoord2f(1, 1) # glVertex3f(self.move_x+ 50, self.move_y +50, 50) # glTexCoord2f(1, 0) # glVertex3f(self.move_x+ 50, self.move_y +-50, -50) # glTexCoord2f(0, 0) # glVertex3f(self.move_x+ -50, self.move_y +-50, -50) glEnd() glDisable(GL_TEXTURE_2D)
def initializeGL(self): glClearColor(0.0, 0.0, 0.0, 0.0) glShadeModel(GL_SMOOTH) glEnable(GL_DEPTH_TEST) glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_ALPHA_TEST) glAlphaFunc(GL_NOTEQUAL, 0.0) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, 1.65, 0.1, 500) gluLookAt(0, -100, 50, 0, 0, 0, 0, 1, 0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.myNave = Nave(self.animation_propellant_enemy, 0) self.in_scene.append(self.myNave) for i in range(EXPLOSION_FRAMES): self.animation_explosion[i] = self.loadImage("img/explosion/Comp" + str(i) + ".png") for i in range(PROPELLANT_FRAMES): self.animation_propellant_enemy[i] = self.loadImage( "img/fire/Comp" + str(i) + ".png") for i in range(10): self.img_planets[i] = self.loadImage("img/planets/planeta" + str(i) + ".png") self.img_nave_amarela = self.loadImage("img/nave4.png") self.img_nave_azul = self.loadImage("img/nave1.png") self.img_nave_preta = self.loadImage("img/nave3.png") self.img_tiro_amarelo = self.loadImage("img/nave4_pow.png") self.img_tiro_preto = self.loadImage("img/nave3_pow.png") self.img_tiro_azul = self.loadImage("img/nave1_pow.png") self.img_tiro = self.loadImage("img/nave2_pow.png") self.logo_init = self.loadImage("img/SpaceCute.png") self.logo_end = self.loadImage("img/YouDied.png") self.power_up_vida = self.loadImage("img/power_up_life.png") self.power_up_shoot = self.loadImage("img/power_up_shot.png") self.power_up_speed = self.loadImage("img/power_up_speed.png") self.myLogo_i.load("inicio", self.logo_init, self.logo_end) self.ornaments.append(self.myLogo_i) self.myLogo_i.inited = True self.myLogo_e.load("fim", self.logo_init, self.logo_end) self.init_queue() # Arrumando erros de frict fix_p = self.propellant_queue.pop() fix_p.load(self.animation_propellant_enemy, 1000, 1000, "fix") self.ornaments.append(fix_p) new_explosion = self.explosion_queue.pop() new_explosion.load(self.animation_explosion, 1000, 1000, "fix") self.ornaments.append(new_explosion) tx = 0 ambiente = [0.2, 0.2, 0.2, 1.0] difusa = [0.7, 0.7, 0.7, 1.0] especular = [1.0, 1.0, 1.0, 1.0] posicao = [0.0, 3.0, 2.0, 0.0] lmodelo_ambiente = [0.2, 0.2, 0.2, 1.0] glLightfv(GL_LIGHT0, GL_AMBIENT, ambiente) glLightfv(GL_LIGHT0, GL_DIFFUSE, difusa) glLightfv(GL_LIGHT0, GL_POSITION, posicao) glLightfv(GL_LIGHT0, GL_SPECULAR, especular) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodelo_ambiente) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_COLOR_MATERIAL)
def loadIdentity (self): gluLookAt(self.position[0], self.position[1], self.position[2], self.position[0] + self.direction.x, self.position[1] + self.direction.y, self.position[2] + self.direction.z, 0, 0, 1)
def apply(self): """Load the camera matrix.""" gluLookAt(self.origin[0], self.origin[1], self.origin[2], self.target[0], self.target[1], self.target[2], self.up[0], self.up[1], self.up[2])