~codeforger/pypal/docs

« back to all changes in this revision

Viewing changes to pypal/sandbox/gltest.py

  • Committer: Michael Rochester
  • Date: 2014-07-15 11:58:20 UTC
  • Revision ID: m.rochester93@googlemail.com-20140715115820-qhxcg847lmz3q0le
cleaned up the project abit and fixed the built in examples

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import pygame 
2
 
from pygame.locals import *
3
 
 
4
 
from OpenGL.GL import (
5
 
    GL_DEPTH_TEST, glEnable, glTranslate)
6
 
from OpenGL.GLU import gluPerspective, gluLookAt
7
 
 
8
 
import glhelp as glh
9
 
 
10
 
import pypal as pal
11
 
 
12
 
pygame.init()
13
 
pygame.display.set_mode(
14
 
    (1024, 768), pygame.locals.OPENGL | pygame.locals.DOUBLEBUF)
15
 
 
16
 
glEnable(GL_DEPTH_TEST)
17
 
gluPerspective(60.0, 640.0 / 480.0, 0.5, 1000.0)
18
 
glTranslate(0, -15, -60)
19
 
 
20
 
objects = []
21
 
 
22
 
terrain =  pal.body.StaticBox((0,0,0,60,1,60))
23
 
sbox = pal.body.StaticBox((0,10,0,1.,1.,1.))
24
 
sbox1 = pal.body.StaticBox((10,10,0,1.,1.,1.))
25
 
box1 = pal.body.Box((-10,5,0,1,1,1),mass=10)
26
 
ssphere = pal.body.StaticSphere((-10,10,0,1))
27
 
sphere = pal.body.Sphere((5,10,0,1),mass=1)
28
 
 
29
 
objects.append(glh.Box(terrain,(0,0,255)))
30
 
objects.append(glh.Box(sbox, (255, 0, 0)))
31
 
objects.append(glh.Box(sbox1, (0, 255, 0)))
32
 
objects.append(glh.Ball(sphere, (0, 255, 255)))
33
 
objects.append(glh.Box(box1, (255, 255, 0)))
34
 
objects.append(glh.Ball(ssphere, (255, 0, 255)))
35
 
 
36
 
#prismatic = pal.link.Prismatic(sbox,sphere,sbox.get_position(),(1,0,0),False)
37
 
#prismatic.set_limits(0,20)
38
 
#revolute = pal.link.Spherical(sbox1,box,sbox1.get_position(),False)
39
 
 
40
 
#rigid = pal.link.Rigid(box,sphere.body,False)
41
 
 
42
 
control = box1
43
 
 
44
 
gluLookAt(5,5,5,0,0,0,0,1,0)
45
 
running = True
46
 
while running:
47
 
    pal.update(1./50.)
48
 
    glh.render(objects)
49
 
    events = pygame.event.get()
50
 
    for event in events:
51
 
        if event.type == QUIT:
52
 
            running = not running
53
 
        elif event.type == KEYDOWN:
54
 
            if event.key == K_SPACE:
55
 
                pass
56
 
            elif event.key == K_RIGHT:
57
 
                control.set_active(True)
58
 
                control.apply_impulse((75,0,0))
59
 
            elif event.key == K_LEFT:
60
 
                control.set_active(True)
61
 
                control.apply_impulse((-75,0,0))
62
 
            elif event.key == K_UP:
63
 
                control.set_active(True)
64
 
                control.apply_impulse((0,75,0))
65
 
            elif event.key == K_DOWN:
66
 
                control.set_active(True)
67
 
                control.apply_impulse((0,-75,0))
68
 
            elif event.key == K_d:
69
 
                control.set_active(True)
70
 
                control.apply_impulse((75,0,0))
71
 
            elif event.key == K_a:
72
 
                control.set_active(True)
73
 
                control.apply_impulse((-75,0,0))
74
 
            elif event.key == K_s:
75
 
                control.set_active(True)
76
 
                control.apply_impulse((0,0,75))
77
 
            elif event.key == K_w:
78
 
                control.set_active(True)
79
 
                control.apply_impulse((0,0,-75))