Browse files

Almost got the Shoerical Coords Righ D:<

  • Loading branch information...
1 parent ed71a1e commit 98e0a0c31d5ff4d7e0ad158329e111f7ec17ce9a Fabián Heredia Montiel committed Apr 26, 2012
Showing with 40 additions and 35 deletions.
  1. +24 −18 Engine/__main__.py
  2. +14 −14 Engine/object.py
  3. +1 −2 resources/models/skybox.obj
  4. +1 −1 shaders/frag.glsl
View
42 Engine/__main__.py
@@ -56,7 +56,7 @@ def init():
glMatrixMode(GL_MODELVIEW)
# Habilitando
- # glEnable(GL_CULL_FACE)
+ # glEnable(GL_CULL_FACE) No se puede habilitar porque no pude invertir las normales del skybox.
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_LIGHTING)
@@ -68,20 +68,23 @@ def init():
# glsl.toggle()
# Add objects
- object.create("resources/models/skybox.obj", {"id": "skybox", "pos": [0, 0, 0, 100], "scale": 40})
- object.create("resources/models/Pejuang_Final.obj", {"id": "player", "pos": [0, 0, 0, 100]})
+ object.create("resources/models/skybox.obj", {"id": "skybox", "pos": [0, 0, 0, 000], "scale": 30})
+ object.create("resources/models/Pejuang_Final.obj", {"id": "player", "pos": [0, 0, 0, 100], "rot": [90,0,0]})
+ object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
+ object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
# Control de flujo
global nRun, nTime, tick
- nRun = time() + 3.0
+ nRun = time()
nTime = 1.0 / config.fps
tick = 0
#info
print "OpenGL: ", glGetString(GL_VERSION), ", GLSL: ", glGetString(GL_SHADING_LANGUAGE_VERSION)
# Main Loop
+ # glutFullScreen()
glutMainLoop()
# OpenGL Drawing
@@ -95,19 +98,17 @@ def display():
# Camara posicionada sobre el personaje
pos = object.objects["player"].getCart()
- gluLookAt(pos[0]*3, pos[1]*3, pos[2]*3, pos[0], pos[1], pos[2], 0, 1, 0)
+ gluLookAt(pos[0]*1, pos[1]*2, pos[2]*2, pos[0], pos[1], pos[2], 0, 1, 0)
- glLightfv(GL_LIGHT0, GL_POSITION, [pos[0]*3,pos[1]*3,pos[2]*3] + [1])
- glLightfv(GL_LIGHT0, GL_AMBIENT, [0,0,0,0])
- glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8,0.8,0.8,1])
- glLightfv(GL_LIGHT0, GL_SPECULAR, [1,1,1,1])
+ glLightfv(GL_LIGHT0, GL_POSITION, [pos[0]*3, pos[1]*3, pos[2]*3, 1])
+ glLightfv(GL_LIGHT0, GL_AMBIENT, [0, 0, 0, 0])
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.8, 0.8, 0.8, 1])
+ glLightfv(GL_LIGHT0, GL_SPECULAR, [1, 1, 1, 1])
for i in object.objects: object.objects[i].draw()
# Escena
glutSolidSphere(100,40, 40)
- glTranslatef(0,-100,0)
- glutSolidCube(100,100,1)
# Pasar a pantalla
glutSwapBuffers()
@@ -118,7 +119,7 @@ def idle():
# Scheduling
if nRun - time() < 0:
# En caso de que no se pueda mantener el tiempo
- if nRun - time() < -nTime and tick % config.fps == 0:
+ if nRun - time() < -nTime and (tick + 1) % config.fps == 0:
config.fps /= 2
nTime = 1.0 / config.fps
print config.fps
@@ -133,12 +134,17 @@ def idle():
# Key bindings
def keys(key, x, y):
- if key == "w": object.objects["player"].force([10,0,0,0])
- if key == "s": object.objects["player"].force([-10,0,0,0])
- if key == "a": object.objects["player"].force([0,-10,0,0])
- if key == "d": object.objects["player"].force([0,10,0,0])
- if key == "q": object.objects["player"].force([0,0,-10,0])
- if key == "e": object.objects["player"].force([0,0,10,0])
+ if key == "" : pass
+ elif key == "w": object.objects["player"].force([10,0,0,0])
+ elif key == "s": object.objects["player"].force([-10,0,0,0])
+ elif key == "a": object.objects["player"].force([0,10,0,0])
+ elif key == "d": object.objects["player"].force([0,-10,0,0])
+ elif key == "q": object.objects["player"].force([0,0,-10,0])
+ elif key == "e": object.objects["player"].force([0,0,10,0])
+ # ESC
+ elif key == chr(27): exit()
+ else: print "No reconocido: ", ord(key)
+
# Mouse bindings
def mouse(x, y):
View
28 Engine/object.py
@@ -73,28 +73,28 @@ def force(self, force = [0,0,0,0]):
def getCart(self):
'''
- pos.0 = phi
- pos.1 = theta
- pos.2 = gao
- pos.3 = rho
+ pos.0 = x phi
+ pos.1 = y theta
+ pos.2 = z gao
+ pos.3 = w rho
- x = rho * sin(phi) * cos(theta)
- y = rho * sin(phi) * sin(theta)
- z = rho * cos(phi)
+ x = rho * cos(theta)
+ z = rho * sin(theta)
+ y = rho * sin(phi)
'''
- x = self._prop["pos"][3] * sin(self._prop["pos"][0]) * cos(self._prop["pos"][1])
- y = self._prop["pos"][3] * sin(self._prop["pos"][0]) * sin(self._prop["pos"][1])
- z = self._prop["pos"][3] * cos(self._prop["pos"][0])
+ x = self._prop["pos"][3] * sin(radians(self._prop["pos"][1])) * cos(radians(self._prop["pos"][0]))
+ z = self._prop["pos"][3] * cos(radians(self._prop["pos"][1])) * cos(radians(self._prop["pos"][0]))
+ y = self._prop["pos"][3] * -sin(radians(self._prop["pos"][0]))
return [x, y, z]
def draw(self):
glPushMatrix()
# Posición
- glRotatef(self._prop["pos"][0], 1, 0, 0) # phi
- glRotatef(self._prop["pos"][1], 0, 0, 1) # theta
- glRotatef(self._prop["pos"][2], 0, 1, 0) # gao
- glTranslatef(0, self._prop["pos"][3], 0) # rho
+ glRotatef(self._prop["pos"][0], 1, 0, 0) # x phi
+ glRotatef(self._prop["pos"][1], 0, 1, 0) # y theta
+ glRotatef(self._prop["pos"][2], 0, 0, 1) # z gao
+ glTranslatef(0, 0, self._prop["pos"][3]) # w rho
# Rotación
glRotatef(self._prop["rot"][0], 1, 0, 0)
View
3 resources/models/skybox.obj
@@ -996,10 +996,9 @@ vt 0.506309 0.606227
vt 0.505247 0.668252
vt 0.503910 0.730152
vt 0.502011 0.791799
-usemtl skybox_duskcontrast.jpg
+usemtl skybox
s 1
f 207/1 208/2 217/3 218/4
-usemtl skybox
f 482/5 32/6 2/7
f 481/8 482/5 2/7 3/9
f 480/10 481/8 3/9 4/11
View
2 shaders/frag.glsl
@@ -6,5 +6,5 @@ void main()
gl_FragColor*= vec4(1.0,0.9,0.9,1.0);
// Eye
- gl_FragColor/= max(distance(gl_FragCoord.xy, vec2(640,360)), 1.0);
+ gl_FragColor/= max(log10(distance(gl_FragCoord.xy, vec2(640,360)))/2.0, 1.0);
}

0 comments on commit 98e0a0c

Please sign in to comment.