Exemplo n.º 1
0
class Loading(object):
    def __init__(self, w, h, title):
        self.KeyInputState = {
            "reset": False,
            "space": False,
            "b": False,
            "v": False,
            "g": False,
            "h": False,
            "n": False
        }
        self.cam = Camera(60., 1.0, 0.1, 1000.0)
        #self.cam.setPos([0,10,1], [0,0,0])
        #self.cam.setPos([10,10,10], [0,0,0])
        #self.cam.setPos([10,5,10], [0,0,0])
        #self.cam.setPos([10,2,10], [0,0,0])
        self.cam.setPos([20, 10, 10], [0, 0, 0])
        self.timer = Timer()
        self.gridMode = False
        self.gridAngle = 0
        self.gridAxis = [1, 0, 0]
        self.graphics = Graphics()
        self.lighting = Lighting()
        self.scene = Scene()
        self.background = Background()

        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
        glutInitWindowSize(w, h)
        glutInitWindowPosition(100, 100)
        glutCreateWindow(title)
        glClearColor(0.25, 0.25, 0.25, 1.0)
        glEnable(GL_DEPTH_TEST)
        self.lighting.LightSet()

    def setBackground(self, filename):
        self.background.loadImage(filename)

    def reshape(self, w, h):
        self.cam.setAsp(w, h)
        glViewport(0, 0, w, h)

    def grid(self, option):
        self.gridMode = option

    def rotateGrid(self, angle, axis):
        self.gridAngle = angle
        self.gridAxis = axis

    def timerStart(self):
        self.timer.start()

    def timerStop(self):
        self.timer.stop()

    def timerReset(self):
        self.timer.reset()

    def getDt(self):
        return self.timer.getDt()

    def getEt(self):
        return self.timer.getEt()

    def frame(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        self.cam.applyCamera(self.background)

        self.lighting.LightPosition()
        if self.gridMode:
            self.graphics.drawGrid(100, self.gridAngle, self.gridAxis)

    def afterFrame(self):

        self.scene.draw()
        glFlush()

    def start(self, displayCallback, keyCallback):
        glutDisplayFunc(displayCallback)
        glutIdleFunc(displayCallback)
        glutKeyboardFunc(keyCallback)
        glutReshapeFunc(self.reshape)
        glutMainLoop()

    def drawBall(self, pos, radius=1.0):
        self.graphics.drawBall(pos, radius)

    def cameraAt(self, eye, target, up=[0, 1, 0]):
        self.cam.setPos(eye, target, up)

    def addObject(self, name, type):
        obj = VisualObj()
        obj.setNameAndType(name, type)
        self.scene.opaqueChildren.add(obj)
        return obj

    def addSphere(self, name):
        return self.addObject(name, 0)

    def addCube(self, name):
        return self.addObject(name, 1)

    def addTransparentObject(self, name, type):
        obj = VisualObj()
        obj.setNameAndType(name, type)
        self.scene.transChildren.add(obj)
        return obj

    def addTransparentSphere(self, name):
        return self.addTransparentObject(name, 0)

    def addTransparentCube(self, name):
        return self.addTransparentObject(name, 1)
Exemplo n.º 2
0
class Loading(object):
    def __init__(self, w, h, title):
        self.cam = Camera(90.0, 800/600,1, 100000.0)
        self.eye = [0.0, -2000.0, 3800.0]
        self.target = [0.0, 0.0, 2500.0]
        self.up = [0.0, 0.0, 1.0]
        self.cam.setPos(self.eye, self.target)
        self.timer = Timer()
        self.gridMode = False
        self.gridAngle = 0
        self.gridAxis = [1,0,0]

        self.graphics = Graphics()
        self.lighting = Lighting()
        self.scene = Scene()
        self.background = Background()
        self.obj_basic = OBJ('island_basic_1.obj', swapyz=True)
        self.obj_snow = OBJ('island_basic_snow.obj', swapyz=True)
        self.obj_rain = OBJ('island_basic_rain.obj', swapyz=True)
        self.obj = self.obj_basic
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
        glutInitWindowSize(w, h)
        glutInitWindowPosition(800, 600)


        glEnable(GL_DEPTH_TEST)
        glShadeModel(GL_SMOOTH)
        self.lighting.LightSet()

    def changeModel_basic(self):
        self.obj = self.obj_basic

    def changeModel_snow(self):
        self.obj = self.obj_snow
    def changeModel_rain(self):
        self.obj = self.obj_rain
    def setBackground(self, filename):
        self.background.loadImage(filename)


    def reshape(self, w, h):
        self.cam.setAsp(w,h)
        glViewport(0,0, w,h)

    def grid(self, option):
        self.gridMode = option

    def rotateGrid(self, angle, axis):
        self.gridAngle = angle
        self.gridAxis = axis


    def timerStart(self):
        self.timer.start()

    def timerStop(self):
        self.timer.stop()

    def timerReset(self):
        self.timer.reset()


    def getDt(self):
        return self.timer.getDt()

    def getEt(self):
        return self.timer.getEt()

    def frame(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        self.cam.applyCamera(self.background)

        self.lighting.LightPosition(cos(self.getEt()) * 2000, sin(self.getEt()) * 2000 + 2000)

        if self.gridMode :
            self.graphics.drawGrid(100, self.gridAngle, self.gridAxis)

        glCallList(self.obj.gl_list)

    def afterFrame(self):

        self.scene.draw()
        glFlush()

    def start(self, displayCallback, keyCallback):
        glutDisplayFunc(displayCallback)
        glutIdleFunc(displayCallback)
        glutKeyboardFunc(keyCallback)
        glutReshapeFunc(self.reshape)
        glEnableClientState(GL_NORMAL_ARRAY)

        #glutMainLoop()

    def drawBall(self, pos, radius=0.0):
        self.graphics.drawBall(pos, radius)

    def cameraAt(self, eye, target, up=[0,0,1]):
        self.cam.setPos(eye, target, up)

    def addObject(self, name, type):
        obj = VisualObj()
        obj.setNameAndType(name, type)
        self.scene.opaqueChildren.add(obj)
        return obj

    def addSphere(self, name):
        return self.addObject(name, 0)

    def addCube(self, name):
        return self.addObject(name, 1)

    def addTransparentObject(self, name, type):
        obj = VisualObj()
        obj.setNameAndType(name, type)
        self.scene.transChildren.add(obj)
        return obj

    def addTransparentSphere(self, name):
        return self.addTransparentObject(name, 0)


    def addTransparentCube(self, name):
        return self.addTransparentObject(name, 1)
Exemplo n.º 3
0
        print(self.vel[0])
        print("\n") 
        acc = self.gravity + self.force / self.mass
        self.vel = self.vel + acc*time
        self.loc = self.loc + self.vel*time

## initialize object ##
game = myGame(750, 750, "201724515 À±½ÂÈñ assigment02")
game.grid(True)
table = BillTable(billSize, [0, billSize[1]/2.0, 0])
ball1 = Ball(billSize, 5, [1, 0, 0, 1])
ball2 = Ball(billSize, -5, [0, 0, 1, 1]) 
clock = Timer()
clock.start()
light = Lighting([0, 100, 0, 0])
light.LightSet() 

## toggle setting ##
round = False;
lightON = True;

def draw():
    global angle 
    game.frame()
    drawBackGround()
    if(round is True) : 
        angle = angle + 0.02
    game.setCamera([cameraPos[0]*math.cos(angle) , cameraPos[1], cameraPos[2]*math.sin(angle)], cameraCen, [0, 1, 0])
    table.showing()
    ball1.simulate(clock.getDt())
    insideBillSize = [billSize[0]*0.8, billSize[1]*0.8, billSize[2]*0.8]