Beispiel #1
0
def draw_full_car():
    anim_time = get_time()
    glPushMatrix()
    glTranslated(car_x_position + anim_time, 0, car_z_position)
    drawCar()
    draw_tires()
    glPopMatrix()
def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    if projection_mode == "ortho":
        width_ratio = DISPLAY_WIDTH / DISPLAY_HEIGHT
        zoom = -cam_z
        if zoom > 0:
            glOrtho(-zoom * width_ratio, zoom * width_ratio, -zoom, zoom, .5,
                    100)
            glMatrixMode(GL_MODELVIEW)
            glLoadIdentity()
            glRotated(rot_deg, 0, 1, 0)
            glTranslated(cam_x, cam_y, cam_z)

    else:
        gluPerspective(55, (DISPLAY_WIDTH / DISPLAY_HEIGHT), 0.1, 100.0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glRotated(rot_deg, 0, 1, 0)
        glTranslated(cam_x, cam_y, cam_z)

    drawTestShape()

    drawAxisOfRotation()

    if transform:
        shape_offset = [30, 0, 40]
        # problem 1
        transform_shape(shape_offset, 40)

    glFlush()
def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    if cam.projection_mode == "ortho":
        width_ratio = DISPLAY_WIDTH / DISPLAY_HEIGHT
        zoom = -cam.cur_position.z
        if zoom > 0:
            glOrtho(-zoom * width_ratio, zoom * width_ratio, -zoom, zoom, .5, 100)
            glMatrixMode(GL_MODELVIEW)
            glLoadIdentity()
            glRotated(cam.cur_rotation, 0, 1, 0)
            glTranslated(cam.cur_position.x, cam.cur_position.y, cam.cur_position.z)

    else:
        gluPerspective(60, (DISPLAY_WIDTH / DISPLAY_HEIGHT), 0.1, 100.0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glRotated(cam.cur_rotation, 0, 1, 0)
        glTranslated(cam.cur_position.x, cam.cur_position.y, cam.cur_position.z)

    draw_neighborhood()
    animate_car()

    glFlush()
Beispiel #4
0
    def render(self):
        """ The render pass for the scene """
        self.init_view()

        # Enable lighting and color
        glEnable(GL_LIGHTING)

        glClearColor(0.4, 0.4, 0.4, 0.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Load the modelview matrix from the current state of the trackball
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        loc = self.interaction.translation
        glTranslated(-loc[0], -loc[1], -loc[2])
        glMultMatrixf(self.interaction.trackball.matrix)

        # store the inverse of the current modelview.
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        # render the scene. This will call the render function for each object in the scene
        self.scene.render()

        # draw the grid
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        # flush the buffers so that the scene can be drawn
        glFlush()
Beispiel #5
0
    def render(self):
        """ The render pass for the scene """
        self.init_view()

        # Enable lighting and color
        glEnable(GL_LIGHTING)

        glClearColor(0.4, 0.4, 0.4, 0.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Load the modelview matrix from the current state of the trackball
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        loc = self.interaction.translation
        glTranslated(-loc[0], -loc[1], -loc[2])
        glMultMatrixf(self.interaction.trackball.matrix)

        # store the inverse of the current modelview.
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        # render the scene. This will call the render function for each object in the scene
        self.scene.render()

        # draw the grid
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        # flush the buffers so that the scene can be drawn
        glFlush()
Beispiel #6
0
 def render(self):
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
Beispiel #7
0
 def paintGL(self):
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glLoadIdentity()
     glTranslated(0.0, 0.0, -10.0)
     glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
     glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
     glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
     glCallList(self.object)
Beispiel #8
0
 def render(self):
     """ render the AABB. This can be useful for debugging purposes """
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
 def translate(self, trans):
     # translate the object
     self.makeCurrent()
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
     glTranslated(trans[0], trans[1], trans[2])
     glMultMatrixd(self._modelview_matrix)
     # update _modelview_matrix
     self._modelview_matrix = glGetDoublev(GL_MODELVIEW_MATRIX)
Beispiel #10
0
 def render(self):
     """ 渲染显示包围盒,可在调试的时候使用 """
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
Beispiel #11
0
def drawCarTurned():
    global seconds
    print(seconds)
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glTranslated(0, 0, -10 + seconds)
    glRotated(90, 0, 1, 0)
    drawCar()
    glPopMatrix()
Beispiel #12
0
def draw_house_row(mirror=False):
    for i in range(3):
        glPushMatrix()
        z_placement = 30 if mirror else 0
        rotation = 180 if mirror else 0
        glTranslated(-i * 15, 0, z_placement)
        glRotated(rotation, 0, 1, 0)
        drawHouse()
        glPopMatrix()
Beispiel #13
0
 def translate(self, trans):
     # translate the object
     self.makeCurrent()
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
     glTranslated(trans[0], trans[1], trans[2])
     glMultMatrixd(self._modelview_matrix)
     # update _modelview_matrix
     self._modelview_matrix = glGetDoublev(GL_MODELVIEW_MATRIX)
Beispiel #14
0
def init():
    glClearColor(0.0, 0.0, 0.0, 0.0)
    glShadeModel(GL_FLAT)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    # glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 100.0);
    gluPerspective(60, 1, 0, 100)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glTranslated(0, -5, -20)
Beispiel #15
0
    def init_view(self):
        """ initialize the projection matrix """
        xSize, ySize = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)
        aspect_ratio = float(xSize) / float(ySize)

        # load the projection matrix. Always the same
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        glViewport(0, 0, xSize, ySize)
        gluPerspective(70, aspect_ratio, 0.1, 1000.0)
        glTranslated(0, 0, -15)
Beispiel #16
0
    def init_view(self):
        """ initialize the projection matrix """
        xSize, ySize = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)
        aspect_ratio = float(xSize) / float(ySize)

        # load the projection matrix. Always the same
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        glViewport(0, 0, xSize, ySize)
        gluPerspective(70, aspect_ratio, 0.1, 1000.0)
        glTranslated(0, 0, -15)
Beispiel #17
0
 def draw(self, line_width=2):
     glEnable(GL_DEPTH_TEST)
     glShadeModel(GL_FLAT)
     glPushMatrix()
     glTranslated(self.x, self.y, self.z)
     glLineWidth(line_width)
     glColor3f(1.0, 1.0, 1.0)
     glBegin(GL_LINES)
     glVertex3f(0.0, 0.0, 0.0)
     glVertex3f(0.0, 0.0, self.length)
     glEnd()
     glPopMatrix()
Beispiel #18
0
 def draw_lines(self, line_width=1):
     glEnable(GL_DEPTH_TEST)
     glShadeModel(GL_FLAT)
     for position in self.line_positions:
         glPushMatrix()
         glTranslated(position[0], position[1], 0)
         glLineWidth(line_width)
         glBegin(GL_LINES)
         glVertex3f(0.0, 0.0, self.z_min)
         glVertex3f(0.0, 0.0, self.z_max)
         glEnd()
         glPopMatrix()
Beispiel #19
0
def init(): 
    glClearColor (0.0, 0.0, 0.0, 0.0)
    glShadeModel (GL_FLAT)
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    # glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 100.0);
    gluPerspective(60,1,0,100)
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity()
    glTranslated(0, Y_OFF, Z_OFF)
    global totDepth
    totDepth += Z_OFF
Beispiel #20
0
def draw_tires():
    anim_time = get_time()
    x_car_offset = 2.0
    z_car_offset = 1.5
    for i in range(2):
        for j in range(2):
            glPushMatrix()
            x_placement = x_car_offset if i == 1 else -x_car_offset
            z_placement = z_car_offset if j == 1 else -z_car_offset
            glTranslated(x_placement, 0, z_placement)
            glRotated(-50 * anim_time, 0, 0, 1)
            drawTire()
            glPopMatrix()
Beispiel #21
0
def drawWheels():
    global seconds
    wheelXOff = 2
    wheelZOff = 2
    wheelSpreed = 10
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glTranslated(-wheelXOff, 0, wheelZOff + seconds - 10)
    glRotated(seconds * wheelSpreed, 1, 0, 0)
    glRotated(90, 0, 1, 0)
    drawTire()
    glPopMatrix()
    glPushMatrix()
    glTranslated(wheelXOff, 0, wheelZOff + seconds - 10)
    glRotated(seconds * wheelSpreed, 1, 0, 0)
    glRotated(90, 0, 1, 0)
    drawTire()
    glPopMatrix()
    glPushMatrix()
    glTranslated(-wheelXOff, 0, -wheelZOff + seconds - 10)
    glRotated(seconds * wheelSpreed, 1, 0, 0)
    glRotated(90, 0, 1, 0)
    drawTire()
    glPopMatrix()
    glPushMatrix()
    glTranslated(wheelXOff, 0, -wheelZOff + seconds - 10)
    glRotated(seconds * wheelSpreed, 1, 0, 0)
    glRotated(90, 0, 1, 0)
    drawTire()
    glPopMatrix()
Beispiel #22
0
    def draw(self, time, line_width=None):
        if self.hidden:
            return
        time = time * 1e-9
        if time <= self.time:
            return

        pos_start = self.pos + (self.speed * (-self.time) * self.dir)
        path = self.speed * (time - self.time) * self.dir
        if self.length:
            max_path = self.length * self.dir
            if np.linalg.norm(max_path) <= np.linalg.norm(path):
                path = max_path
        pos_end = self.pos + path

        glPushMatrix()
        if line_width:
            glLineWidth(line_width)
        else:
            glLineWidth(self.line_width)
        glColor3f(*self.color)
        glBegin(GL_LINES)
        glVertex3f(*pos_start)
        glVertex3f(*pos_end)
        glEnd()
        glPopMatrix()

        if self.cherenkov_cone_enabled and self.colourist.cherenkov_cone_enabled:

            height = np.linalg.norm(pos_end - pos_start)
            position = pos_end - self.dir * height

            glEnable(GL_LIGHTING)
            glEnable(GL_DEPTH_TEST)
            glShadeModel(GL_FLAT)
            glColor4f(0.0, 0.0, 0.8, 0.3)

            glPushMatrix()
            glTranslated(*position)
            glPushMatrix()

            v = np.array(self.dir)
            glMultMatrixf(transform(v))

            glutSolidCone(0.6691 * height, height, 128, 64)
            glPopMatrix()
            glPopMatrix()

            glDisable(GL_LIGHTING)
Beispiel #23
0
 def init_view(self):
     """ 初始化投影矩阵 """
     xSize, ySize = glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT)
     # 屏幕宽高比
     aspect_ratio = float(xSize) / float(ySize)
     # 设置投影矩阵
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     #设置视口,应该与窗口重合
     glViewport(0, 0, xSize, ySize)
     # 设置透视,摄像机上下视野幅度70
     # 视野范围到距离摄像机1000个单位为止
     gluPerspective(70, aspect_ratio, 0.1, 1000.0)
     # 摄像机镜头从原点后退15个单位
     glTranslated(0, 0, -15)
Beispiel #24
0
def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)
    # viewing transformation
    global chHor
    global chVert
    global home
    global ortho
    global chDepth
    global pers
    global chRot
    global totHor
    global totVert
    global totRot
    #Your Code Here
    glMatrixMode(GL_MODELVIEW)
    glRotated(-totRot, 0, 10, 0)
    glRotated(chRot, 0, 10, 0)

    glTranslated(chHor, chVert, chDepth)
    glRotated(totRot, 0, 10, 0)
    totHor += chHor
    totVert += chVert
    totRot += chRot

    if home == True:
        init()
        totRot = 0
        totVert = 0
        totHor = 0
    if ortho == True:
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(-20.0, 20.0, -20.0, 20.0, -100.0, 100.0)
    if pers == True:
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60, 1, 0, 100)
    chHor = 0
    chVert = 0
    home = False
    chDepth = 0
    ortho = False
    pers = False
    chRot = 0

    drawHouse()
    glFlush()
Beispiel #25
0
def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)
    # viewing transformation

    global chHor
    global chVert
    global home
    global ortho
    global chDepth
    global persz
    global chRot
    global totHor
    global totDepth
    global totRot
    global seconds
    #Your Code Here
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
    glTranslated(chHor, chVert, chDepth)
    glRotated(chRot, 0, 1, 0)

    if home == True:
        init()
        chRot = -45
        chDepth = 0
        chVert = 0
        chHor = -20
        seconds = 0
    if ortho == True:
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(-10.0, 10.0, -10.0, 10.0, -100.0, 100.0)
        seconds = 0
    if pers == True:
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60, 1, 0, 100)
    home = False
    ortho = False
    pers = False
    drawCarTurned()
    drawWheels()
    drawNeighboorhood()
    print(seconds)
    # drawWheels()
    glFlush()
    bob = 0
Beispiel #26
0
    def init_view(self):
        """init shadow matrix"""
        xSize, ySize = glutGet(GLUT_WINDOW_WIDTH), gluGet(GLUT_WINDOW_HEIGHT)
        #get screen's kuangaobi
        aspect_ratio = float(xSize) / float(ySize)

        #set shadow matrix
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        #set viewport, should be chonghe with window
        glViewport(0, 0, xSize, ySize)

        #set toushi, eyesight width 70 degree, 1000 distance fron camare
        gluPerspective(70, aspect_ratio, 0.1, 1000.0)

        #jinftou back 15 distances from o
        glTranslated(0, 0, -15)
Beispiel #27
0
    def draw(self):
        glPushMatrix()
        glTranslated(self.pos.x, self.pos.y, self.pos.z)

        glEnable(GL_LIGHTING)
        color_r = 0.5
        color_g = 0.0
        color_b = 0.0
        glColor3f(color_r, color_g, color_b)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_DIFFUSE)
        #glDisable(GL_TEXTURE_2D)
        glutSolidSphere(self.radius, 64, 64)
        glDisable(GL_COLOR_MATERIAL)

        glDisable(GL_LIGHTING)

        glPopMatrix()
    def render(self):
        """ The render pass for the scene """
        self.init_view()

        glEnable(GL_LIGHTING)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Load the modelview matrix from the current state of the trackball
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        tar = self.interaction.LookAttarget;
        self.Camera.target = (tar[0],tar[1],tar[2])
        if self.Camera.CameraMode == 'Trackball':
            loc = self.Camera.position;
            #Camera.position
            glTranslated(-loc[0], -loc[1], -loc[2])
            glMultMatrixf(self.interaction.trackball.matrix)
        elif self.Camera.CameraMode == 'LookAt':
            # embed()
            self.Camera.point()
        elif self.Camera.CameraMode == 'LookAtFollow':
            self.Camera.follow()
            self.Camera.point()
        else:
            glMultMatrixf(self.interaction.trackball.matrix) # by default revert to trackball if mode is set incorrectly

        # store the inverse of the current modelview.
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        # render the scene. This will call the render function for each object in the scene
        self.scene.render()

        # draw the grid
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        # flush the buffers so that the scene can be drawn
        glFlush()
Beispiel #29
0
def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)
    # viewing transformation

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    if camera['perspective']:
        gluPerspective(50, DISPLAY_WIDTH / DISPLAY_HEIGHT, camera['near'],
                       camera['far'])
    else:
        glOrtho(-10, 10, -10, 10, camera['near'], camera['far'])

    glRotated(camera['rotate'], 0, 1, 0)
    glTranslated(camera['x'], camera['y'], camera['z'])

    drawHouse()

    glFlush()
Beispiel #30
0
def display():
    global zoom
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    width_ratio = DISPLAY_WIDTH / DISPLAY_HEIGHT

    if zoom > 0:
        glOrtho(-zoom * width_ratio, zoom * width_ratio, -zoom, zoom, .5, 100)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glTranslated(cam_x, cam_y, cam_z)

    # DO NOT CHANGE -- THIS SETS THE CAMERA!!!!

    drawHouse()

    glFlush()
Beispiel #31
0
    def draw(self, time, spectrum):
        if self.hidden:
            return
        if time < self.time:
            self._show_replaced_hits()
            return

        self._hide_replaced_hits()

        # color = (1.0, 1.0-self.time/2000.0, self.time/2000.0)
        color = spectrum(self.time, self)
        glPushMatrix()
        glTranslated(self.x, self.y, self.z)

        glColor3f(*color)
        # glEnable(GL_COLOR_MATERIAL)
        # glColorMaterial(GL_FRONT, GL_DIFFUSE)
        glutSolidSphere(int(1 + np.sqrt(self.tot) * 1.5), 16, 16)
        # glDisable(GL_COLOR_MATERIAL)

        glPopMatrix()
Beispiel #32
0
 def draw(self, line_width=1, color=(1.0, 0.0, 0.0)):
     glEnable(GL_DEPTH_TEST)
     glEnable(GL_LINE_SMOOTH)
     glShadeModel(GL_FLAT)
     glPushMatrix()
     glLineWidth(line_width)
     glColor3f(*color)
     glBegin(GL_LINES)
     glVertex3f(-1.0, 0.0, 0.0)
     glVertex3f(1.0, 0.0, 0.0)
     glEnd()
     glPushMatrix()
     glTranslated(1.0, 0.0, 0.0)
     glRotated(90, 0.0, 1.0, 0.0)
     glutSolidCone(0.05, 0.2, 16, 16)
     glPopMatrix()
     glBegin(GL_LINES)
     glVertex3f(0.0, -1.0, 0.0)
     glVertex3f(0.0, 1.0, 0.0)
     glEnd()
     glPushMatrix()
     glTranslated(0.0, 1.0, 0.0)
     glRotated(-90, 1.0, 0.0, 0.0)
     glutSolidCone(0.05, 0.2, 16, 16)
     glPopMatrix()
     glBegin(GL_LINES)
     glVertex3f(0.0, 0.0, -1.0)
     glVertex3f(0.0, 0.0, 1.0)
     glEnd()
     glPushMatrix()
     glTranslated(0.0, 0.0, 1.0)
     glutSolidCone(0.05, 0.2, 16, 16)
     glPopMatrix()
     glPopMatrix()
Beispiel #33
0
def display():
    glClear (GL_COLOR_BUFFER_BIT)
    glColor3f (1.0, 1.0, 1.0)
    # viewing transformation
    global chHor
    global chVert
    global home
    global ortho
    global chDepth
    global pers
    global chRot
    global totHor
    global totDepth
    global totRot
    #Your Code Here
    glMatrixMode(GL_MODELVIEW)


    glRotated(-totRot,0,10,0)

    glTranslated(-totHor,0,-totDepth)
    glRotated(chRot, 0, 1, 0)
    glTranslated(+totHor,0,+totDepth)
    glTranslated(chHor, chVert, chDepth)
    glRotated(totRot, 0, 10, 0)
    rad = math.radians(chRot)

    if(chRot  > 0 or chRot < 0):
        totHor = totHor * math.cos(rad) + totDepth * math.sin(rad)
        totHorTemp = totHor
        totDepth = -totHorTemp * math.sin(rad) + totDepth * math.cos(rad)


    totHor += chHor
    totDepth += chDepth
    totRot += chRot

    if home == True:
        init()
        totRot = 0
        totHor = 0
    if ortho == True:
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(-10.0,10.0,-10.0,10.0,-100.0, 100.0)
    if pers == True:
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60, 1, 0, 100)
    chHor = 0
    chVert = 0
    home = False
    chDepth = 0
    ortho = False
    pers = False
    chRot = 0

    drawHouse()
    glFlush()
def animate_car():
    """Use push so that you can apply some transformations at the same time?
       1. Push the matrix from stack
       2. Translate to position
       3. Rotate it
       4. Draw it
       5. Pop the matrix
       """
    # move car along
    glPushMatrix()
    glTranslated(car.position.x, car.position.y, car.position.z)
    drawCar()

    # translate and rotate tires
    for tire in car.tires:
        glPushMatrix()
        glTranslated(tire.x, tire.y, tire.z)
        car.tire_rotation -= .2
        glRotated(car.tire_rotation, 0, 0, 1)
        drawTire()
        glPopMatrix()

    glPopMatrix()
Beispiel #35
0
def display():
    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)
    # viewing transformation

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    if camera.perspective:
        gluPerspective(50, DISPLAY_WIDTH / DISPLAY_HEIGHT, camera.near,
                       camera.far)
    else:
        glOrtho(-10, 10, -10, 10, camera.near, camera.far)

    glRotated(camera.rotate, 0, 1, 0)
    glTranslated(camera.x, camera.y, camera.z)

    for house in houses:
        glPushMatrix()
        glTranslated(house.x, house.y, house.z)
        glRotated(house.rotate_y, 0, 1, 0)
        drawHouse()
        glPopMatrix()

    glPushMatrix()
    glTranslated(car.x, car.y, car.z)
    glRotated(car.rotate_y, 0, 1, 0)
    drawCar()
    for tire in tires:
        glPushMatrix()
        glTranslated(tire.x, tire.y, tire.z)
        glRotated(tire.rotate_y, 0, 1, 0)
        glRotated(tire.rotate_z, 0, 0, 1)
        drawTire()
        glPopMatrix()
    glPopMatrix()

    glFlush()
def transform_shape(shape_offset, rotation):
    glPushMatrix()
    glTranslated(shape_offset[0], shape_offset[1], shape_offset[2])
    glRotated(rotation, 0, 1, 0)
    drawTestShape()
    glPopMatrix()
def transform_house(house_offset, rotation):
    glPushMatrix()
    glTranslated(house_offset[0], house_offset[1], house_offset[2])
    glRotated(rotation, 0, 1, 0)
    drawHouse()
    glPopMatrix()
Beispiel #38
0
def drawNeighboorhood():
    horOfset = 15
    glMatrixMode(GL_MODELVIEW)
    #left part of neighboorhood
    glPushMatrix()
    glTranslated(-horOfset, 0, 20)
    glRotated(90, 0, 1, 0)
    drawHouse()
    glPopMatrix()

    glPushMatrix()
    glTranslated(-horOfset, 0, 0)
    glRotated(90, 0, 1, 0)
    drawHouse()
    glPopMatrix()

    glPushMatrix()
    glTranslated(-horOfset, 0, -20)
    glRotated(90, 0, 1, 0)
    drawHouse()
    glPopMatrix()

    #right part of neighboorhood

    glPushMatrix()
    glTranslated(horOfset, 0, 20)
    glRotated(-90, 0, 1, 0)
    drawHouse()
    glPopMatrix()

    glPushMatrix()
    glTranslated(horOfset, 0, 0)
    glRotated(-90, 0, 1, 0)
    drawHouse()
    glPopMatrix()

    glPushMatrix()
    glTranslated(horOfset, 0, -20)
    glRotated(-90, 0, 1, 0)
    drawHouse()
    glPopMatrix()
Beispiel #39
0
def keyboard(key, x, y):

    global rot
    global xdisp
    global ydisp
    global zdisp
    global project
    glMatrixMode(GL_MODELVIEW)

    if key == chr(27):
        import sys
        sys.exit(0)

    if key == b'w':
        z = 1.0 * math.cos(math.radians(rot))
        x = 1.0 * math.sin(math.radians(rot))
        zdisp += z
        xdisp += x
        glTranslated(x, 0.0, z)

    if key == b's':
        z = -1.0 * math.cos(math.radians(rot))
        x = -1.0 * math.sin(math.radians(rot))
        zdisp += z
        xdisp += x
        glTranslated(x, 0.0, z)

    if key == b'a':
        z = -1.0 * math.sin(math.radians(rot))
        x = 1.0 * math.cos(math.radians(rot))
        zdisp += z
        xdisp += x
        glTranslated(x, 0.0, z)

    if key == b'd':
        z = 1.0 * math.sin(math.radians(rot))
        x = -1.0 * math.cos(math.radians(rot))
        zdisp += z
        xdisp += x
        glTranslated(x, 0.0, z)

    if key == b'r':
        ydisp += 1
        glTranslated(0.0, -1.0, 0.0)

    if key == b'f':
        ydisp -= 1
        glTranslated(0.0, 1.0, 0.0)

    if key == b'q':
        rot += 1
        if rot > 360:
            rot = 0
        glTranslated(-xdisp, -ydisp, -zdisp)
        glRotated(-1.0, 0.0, 1.0, 0.0)
        glTranslated(xdisp, ydisp, zdisp)

    if key == b'e':
        rot -= 1
        if rot < 0:
            rot = 360
        glTranslated(-xdisp, -ydisp, -zdisp)
        glRotated(1.0, 0.0, 1.0, 0.0)
        glTranslated(xdisp, ydisp, zdisp)

    if key == b'h':
        start()

    if key == b'o':
        project = 'o'

    if key == b'p':
        project = 'p'

    glutPostRedisplay()
Beispiel #40
0
def draw_edge_house():
    glPushMatrix()
    glTranslated(-40, 0, 15)
    glRotated(90, 0, 1, 0)
    drawHouse()
    glPopMatrix()
 def Render( self, mode = None):
     GLUTInteractiveContext.Render (self, mode)
     glTranslated ( 2,0,-4)
     drawCube()