Skip to content

Commit

Permalink
[enh] added more versatile camera movement [wasdzx+space]
Browse files Browse the repository at this point in the history
  • Loading branch information
stef committed Sep 3, 2010
1 parent cc04906 commit e65ecbb
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions swram-opengl.py
Expand Up @@ -15,6 +15,10 @@


class Camera: class Camera:
zoom = 1.0 zoom = 1.0
pos = [20, 20, 20]
up = [0, 1, 0 ]
center = [0, 0, 0]
rotation = [0, 0, 0]


class SwarmEntity: class SwarmEntity:
def __init__(self, line): def __init__(self, line):
Expand All @@ -28,9 +32,12 @@ class Reader(Thread):
lock = Lock() lock = Lock()
changed = Event() changed = Event()
swarm_entities = [] swarm_entities = []
paused=False
def run(self): def run(self):
print 'Waithing for data on stdin' print 'Waithing for data on stdin'
while True: while True:
while Reader.paused:
sleep(0.1)
try: try:
self.read_entities() self.read_entities()
except: except:
Expand Down Expand Up @@ -69,7 +76,12 @@ def idle():
def display(): def display():
glLoadIdentity() glLoadIdentity()
dist = 20.0 / Camera.zoom dist = 20.0 / Camera.zoom
gluLookAt(dist, dist, dist, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0) gluLookAt(Camera.pos[0], Camera.pos[1], Camera.pos[2],
Camera.center[0], Camera.center[1], Camera.center[2],
Camera.up[0], Camera.up[1], Camera.up[2])
glRotatef(Camera.rotation[0], 1, 0, 0);
glRotatef(Camera.rotation[1], 0, 1, 0);
glRotatef(Camera.rotation[2], 0, 0, 1);
axis() axis()
mySphere = gluNewQuadric() mySphere = gluNewQuadric()
gluQuadricDrawStyle(mySphere, GLU_LINE) gluQuadricDrawStyle(mySphere, GLU_LINE)
Expand Down Expand Up @@ -115,47 +127,47 @@ def axis():
# x axis positive # x axis positive
glRasterPos3f(i, 0.0, 0.0) glRasterPos3f(i, 0.0, 0.0)
glColor3f(0.3, 0.3, 0.3) glColor3f(0.3, 0.3, 0.3)
#if i == biggest: if i == biggest:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, x) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, x)
#else: else:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii)
# x axis negative # x axis negative
glRasterPos3f(-i, 0.0, 0.0) glRasterPos3f(-i, 0.0, 0.0)
glColor3f(0.5, 0.0, 0.0) glColor3f(0.5, 0.0, 0.0)
#if i == biggest: if i == biggest:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, x) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, x)
#else: else:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii)


# y axis positive # y axis positive
glRasterPos3f(0.0, i, 0.0) glRasterPos3f(0.0, i, 0.0)
glColor3f(0.3, 0.3, 0.3) glColor3f(0.3, 0.3, 0.3)
#if i == biggest: if i == biggest:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, y) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, y)
#else: else:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii)
# x axis negative # x axis negative
glRasterPos3f(0.0, -i, 0.0) glRasterPos3f(0.0, -i, 0.0)
glColor3f(0.5, 0.0, 0.0) glColor3f(0.5, 0.0, 0.0)
#if i == biggest: if i == biggest:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, y) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, y)
#else: else:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii)


# z axis positive # z axis positive
glRasterPos3f(0.0, 0.0, i) glRasterPos3f(0.0, 0.0, i)
glColor3f(0.3, 0.3, 0.3) glColor3f(0.3, 0.3, 0.3)
#if i == biggest: if i == biggest:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, z) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, z)
#else: else:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii)
# z axis negative # z axis negative
glRasterPos3f(0.0, 0.0, -i) glRasterPos3f(0.0, 0.0, -i)
glColor3f(0.5, 0.0, 0.0) glColor3f(0.5, 0.0, 0.0)
#if i == biggest: if i == biggest:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, z) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, z)
#else: else:
# glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii) glutBitmapCharacter(GLUT_BITMAP_8_BY_13, ascii)


glFlush() glFlush()


Expand All @@ -172,9 +184,28 @@ def mykeyb(key, x, y):
Camera.zoom *= 1.2 Camera.zoom *= 1.2
elif key == '-': elif key == '-':
Camera.zoom /= 1.2 Camera.zoom /= 1.2
elif key== 'q':
sys.exit(0);
elif key=='w':
Camera.pos[0] -= 0.5
Camera.pos[1] -= 0.5
Camera.pos[2] -= 0.5
elif key=='s':
Camera.pos[0] += 0.5
Camera.pos[1] += 0.5
Camera.pos[2] += 0.5
elif key=='a':
Camera.rotation[1] -= 1
elif key=='d':
Camera.rotation[1] += 1
elif key=='z':
Camera.rotation[2] -= 1
elif key=='x':
Camera.rotation[2] += 1
elif key==' ':
Reader.paused=not Reader.paused
else: else:
return return
print 'Zoom is now', Camera.zoom
glutPostRedisplay() glutPostRedisplay()


def mymouse(but, stat, x, y): def mymouse(but, stat, x, y):
Expand All @@ -196,9 +227,8 @@ def mymouse(but, stat, x, y):


init() init()


print sys.argv
if '--dumpFrames' in sys.argv: if '--dumpFrames' in sys.argv:
dumpFrames=True dumpFrames=True


rdr = Reader() rdr = Reader()
rdr.start() rdr.start()
Expand Down

0 comments on commit e65ecbb

Please sign in to comment.