コード例 #1
0
ファイル: painting.py プロジェクト: Page6/DeploySimulator
 def resizeGL(self, width, height):
     
     # To insure we don't have a zero height
 
     if height == 0:
         height = 1
         
     # Fill the entire graphics window!
     
     gl.glViewport(0, 0, width, height)
     
     # Set the projection matrix... our "view"
     
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     
     # Set how we view the world and position our eyeball
     
     glu.gluPerspective(45.0, 1.0, 1.0, 100.0)
 
     # Set the matrix for the object we are drawing
     
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     
     # Place the camera position, the direction of view
     # and which axis is up
     
     glu.gluLookAt(self.coordLength, self.coordLength, self.coordLength, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0)
コード例 #2
0
ファイル: molecular_vis.py プロジェクト: atrigent/smilesvis
    def display(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glLoadIdentity()

        # do zoom
        glu.gluLookAt(0.0, 0.0, self.zoom, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

        # do rotation
        for x_rot, y_rot in reversed(self.rotations):
            gl.glRotatef(math.sqrt(x_rot**2 + y_rot**2), y_rot, x_rot, 0)
        #gl.glRotate(x_rot, 0, 1, 0)
        #gl.glRotate(y_rot, 1, 0, 0)

        """
        one, two, three, four = (1, 1, 0), (1, -1, 0), (-1, -1, 0), (-1, 1, 0)
        draw_element(chemistry.elements[0], one)
        draw_single_bond(one, two)
        draw_element(chemistry.elements[0], two)
        draw_double_bond(two, three)
        draw_element(chemistry.elements[0], three)
        draw_triple_bond(three, four)
        draw_element(chemistry.elements[0], four)
        draw_quadruple_bond(four, one)
        """
        #self.draw_atoms(self.molecule)
        gl.glCallList(self.displist)

        #gl.glFlush()
        glut.glutSwapBuffers()
コード例 #3
0
    def paintGL(self):
        gl.glClear (gl.GL_COLOR_BUFFER_BIT|gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45.0, 4.0/3.0, 0.1, 100.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        glu.gluLookAt(4, 3, 3, 0, 0, 0, 0, 1, 0)

        self._texture_id = gl.glGenTextures(1)
        gl.glBindTexture(gl.GL_TEXTURE_2D, self._texture_id)
        gl.glTexImage2D(
            gl.GL_TEXTURE_2D, 0, gl.GL_RGB, self._width, self._height, 0,
            gl.GL_BGR, gl.GL_UNSIGNED_BYTE, self._texture_data)
        gl.glTexParameteri(
            gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
        gl.glTexParameteri(
            gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER,
            gl.GL_LINEAR_MIPMAP_LINEAR)
        gl.glGenerateMipmap(gl.GL_TEXTURE_2D)



        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo)
        gl.glVertexPointer(3, gl.GL_FLOAT, 0, None)
        gl.glEnableVertexAttribArray(1)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._uv_buffer)
        gl.glVertexAttribPointer(1, 2, gl.GL_FLOAT, gl.GL_FALSE, 0, None)
        gl.glBindAttribLocation(self._shader_program, 1, "vertex_uv")
        gl.glLinkProgram(self._shader_program)
        gl.glUseProgram(self._shader_program)
        print gl.glGetProgramiv(self._shader_program, gl.GL_LINK_STATUS)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 12*3)
コード例 #4
0
ファイル: main.py プロジェクト: eirvandelden/Bomb3D
  def DrawScreen(self):
    OGL.glClear(OGL.GL_COLOR_BUFFER_BIT | OGL.GL_DEPTH_BUFFER_BIT)	# Clear The Screen And The Depth Buffer
    OGL.glLoadIdentity() # Reset The matrix

    # To calculate our collision detection with the camera, it just takes one function
    # call from the client side.  We just pass in the vertices in the world that we
    # want to check, and then the vertex count.  
    objCamera.CheckCameraCollision(g_vWorld, g_NumberOfVerts)

    # Assign Values to Local Variables to Prevent Long Lines Of Code	
    pos.x, pos.y, pos.z = objCamera.mPos.x, objCamera.mPos.y, objCamera.mPos.z
    view.x, view.y, view.z = objCamera.mView.x, objCamera.mView.y, objCamera.mView.z
    up.x, up.y, up.z = objCamera.mUp.x, objCamera.mUp.y, objCamera.mUp.z

    # use this function for opengl target camera
    OGLU.gluLookAt(pos.x, pos.y, pos.z, view.x, view.y, view.z, up.x, up.y, up.z)

    # Since we have the vertices for the world in the correct order, let's create
    # a loop that goes through all of the vertices and passes them in to be rendered.

    OGL.glBegin(OGL.GL_TRIANGLES)
    # Go through all the vertices and draw them
    for i in range(0,g_NumberOfVerts,3):
      OGL.glColor3ub(i, 2*i, 3*i) # All different colors to see the structure while playing
      OGL.glVertex3f(g_vWorld[i].x, g_vWorld[i].y, g_vWorld[i].z)
      OGL.glVertex3f(g_vWorld[i+1].x, g_vWorld[i+1].y, g_vWorld[i+1].z)
      OGL.glVertex3f(g_vWorld[i+2].x, g_vWorld[i+2].y, g_vWorld[i+2].z)
				
    OGL.glEnd()
コード例 #5
0
ファイル: __init__.py プロジェクト: mulderg/physical-python
    def __drawstuff(self):
        gl.glPushMatrix()
        glu.gluLookAt(value(self.__camera.x), value(self.__camera.y), value(self.__camera.z),
                  value(self.__center.x), value(self.__center.y), value(self.__center.z),
                  value(self.__up.x), value(self.__up.y), value(self.__up.z))

        lightZeroPosition = [10.,4.,10.,1.]
        lightZeroColor = [1,1,1,1.0]
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, lightZeroPosition)
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, lightZeroColor)
        gl.glLightf(gl.GL_LIGHT0, gl.GL_CONSTANT_ATTENUATION, 0.1)
        gl.glLightf(gl.GL_LIGHT0, gl.GL_LINEAR_ATTENUATION, 0.05)
        gl.glEnable(gl.GL_LIGHT0)

        lightOnePosition = [6.,4.,10.,1.]
        lightOneColor = [0.2,0.2,0.4,1.0] # blue-tinged shadows
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, lightOnePosition)
        gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, lightOneColor)
        gl.glLightf(gl.GL_LIGHT1, gl.GL_CONSTANT_ATTENUATION, 0.1)
        gl.glLightf(gl.GL_LIGHT1, gl.GL_LINEAR_ATTENUATION, 0.05)
        gl.glEnable(gl.GL_LIGHT1)

        if self.__am_slow:
            gl.glClearColor(0.2,0.,0.,1.)
        else:
            gl.glClearColor(0.,0.,0.,1.)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT|gl.GL_DEPTH_BUFFER_BIT)

        for o in self.__objects:
            o._draw()

        gl.glPopMatrix()
コード例 #6
0
ファイル: hypercube.py プロジェクト: davidraythompson/hsifind
    def on_paint(self, event):
        """Process the drawing event."""
        import OpenGL.GL as gl
        import OpenGL.GLU as glu
        self.canvas.SetCurrent(self.canvas.context)

        if not self.gl_initialized:
            self.initgl()
            self.gl_initialized = True
            self.print_help()

        if self.light:
            gl.glEnable(gl.GL_LIGHTING)
        else:
            gl.glDisable(gl.GL_LIGHTING)

        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
                   # Clear The Screen And The Depth Buffer
        gl.glLoadIdentity(
        )                                     # Reset The View

        gl.glPushMatrix()
        glu.gluLookAt(*(list(rtp_to_xyz(
            *self.camera_pos_rtp)) + list(self.target_pos) + list(self.up)))

        self.draw_cube()

        gl.glPopMatrix()
        gl.glFlush()
        self.SwapBuffers()
        event.Skip()
コード例 #7
0
ファイル: camera.py プロジェクト: ulethHCI/GLuskap
 def use(self):
     """camera.use() -> void`
        Calls gluLookAt using the current camera settings."""
     GL.glMatrixMode(GL.GL_MODELVIEW)
     GL.glLoadIdentity()
     p, l, u = self.pos, self.lookAt, self.up
     GLU.gluLookAt(p[0], p[1], p[2], l[0], l[1], l[2], u[0], u[1], u[2])
コード例 #8
0
ファイル: viewer.py プロジェクト: bwesterb/py-sphere
    def display(self):
        """ Render the scene. """
        start = time.time()

        GL.glClear(GL.GL_COLOR_BUFFER_BIT |
                   GL.GL_DEPTH_BUFFER_BIT)
        GL.glPushMatrix()

        cam_x = self.zoom * math.sin(self.cam_lat) * math.cos(self.cam_long)
        cam_y = self.zoom * math.sin(self.cam_lat) * math.sin(self.cam_long)
        cam_z = self.zoom * math.cos(self.cam_lat)
        GLU.gluLookAt(cam_x, cam_y, cam_z, 0, 0, 0, 0, 0, 2)

        self.display_box()
        self.display_points()
        self.display_segments()
        self.display_circles()
        self.display_polygons()
        self.display_regions()
        self.display_sphere()

        GL.glPopMatrix()
        GLUT.glutSwapBuffers()

        render_time = time.time() - start
        GLUT.glutSetWindowTitle("%.3f" % render_time)
コード例 #9
0
ファイル: view.py プロジェクト: Joishi/Python
    def initOpenGLMatrix(self):
        # FROM http://code.activestate.com/recipes/325391-open-a-glut-window-and-draw-a-sphere-using-pythono/
        glut.glutInit(sys.argv)
        glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH)
        glut.glutInitWindowSize(400, 400)
        glut.glutCreateWindow(b'PyTowerDefense')

        gl.glClearColor(0., 0., 0., 1.)
        gl.glShadeModel(gl.GL_SMOOTH)
        gl.glEnable(gl.GL_CULL_FACE)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_LIGHTING)
        gl.lightZeroPosition = [100., 40., 100., 1.]
        gl.lightZeroColor = [0.8, 1.0, 0.8, 1.0] #green tinged
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, gl.lightZeroPosition)
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, gl.lightZeroColor)
        gl.glLightf(gl.GL_LIGHT0, gl.GL_CONSTANT_ATTENUATION, 0.01)
        gl.glLightf(gl.GL_LIGHT0, gl.GL_LINEAR_ATTENUATION, 0.005)
        gl.glEnable(gl.GL_LIGHT0)
        glut.glutDisplayFunc(self.paint)
        glut.glutIdleFunc(self.repaint)
        gl.glMatrixMode(gl.GL_PROJECTION)
        glu.gluPerspective(30., 1., 1., 1000.)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        self._eyePosition = Point3D("Camera Eye Location").translate(0, 0, 400)
        self._watchingPosition = Point3D("Camera Watching Position")
        self._upVector = Point3D("Camera Up Vector").translate(0, 1, 0)
        glu.gluLookAt(self._eyePosition.x, self._eyePosition.y, self._eyePosition.z,
                      self._watchingPosition.x, self._watchingPosition.y, self._watchingPosition.z,
                      self._upVector.x, self._upVector.y, self._upVector.z)
        gl.glPushMatrix()
        return
コード例 #10
0
    def paintGL(self):
        gl.glClear (gl.GL_COLOR_BUFFER_BIT|gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45.0, 4.0/3.0, 0.1, 100.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        glu.gluLookAt(4, 3, 10, 0, 0, 0, 0, 1, 0)

        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo)
        gl.glVertexPointer(3, gl.GL_FLOAT, 0, None)

        gl.glLinkProgram(self._shader_program)
        gl.glUseProgram(self._shader_program)

        model = math3d.Matrix44.translate(0, 0, 0)

        view = math3d.Matrix44.look_at_right_hand(
            math3d.Vector(4, 3, 10),
            math3d.Vector(0, 0, 0),
            math3d.Vector(0, 1, 0))

        projection = math3d.Matrix44.projection_right_hand(
            math.radians(45), 4.0/3.0, 0.1, 100.0)

        mvp = model*view*projection

        mvp_id = gl.glGetUniformLocation(self._shader_program, "mvp")
        gl.glUniformMatrix4fv(mvp_id, 1, gl.GL_FALSE, mvp.raw_data())

        gl.glDrawArrays(gl.GL_TRIANGLES, 0, self._vertices.size)
コード例 #11
0
ファイル: Testopengl.py プロジェクト: pluto16/python_cv
def main():
    glut.glutInit(sys.argv)
    glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH)
    glut.glutInitWindowSize(400,400)
    glut.glutCreateWindow("teapot")

    gl.glClearColor(0.,0.,0.,1.)
    gl.glShadeModel(gl.GL_SMOOTH)
    gl.glEnable(gl.GL_CULL_FACE)
    gl.glEnable(gl.GL_DEPTH_TEST)
    gl.glEnable(gl.GL_LIGHTING)
    lightZeroPosition = [10.,4.,10.,1.]
    lightZeroColor = [0.8,1.0,0.8,1.0] #green tinged
    gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, lightZeroPosition)
    gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, lightZeroColor)
    gl.glLightf(gl.GL_LIGHT0, gl.GL_CONSTANT_ATTENUATION, 0.1)
    gl.glLightf(gl.GL_LIGHT0, gl.GL_LINEAR_ATTENUATION, 0.05)
    gl.glEnable(gl.GL_LIGHT0)
    glut.glutDisplayFunc(display)
    gl.glMatrixMode(gl.GL_PROJECTION)
    glu.gluPerspective(40.,1.,1.,40.)
    gl.glMatrixMode(gl.GL_MODELVIEW)
    glu.gluLookAt(0,0,10,
                  0,0,0,
                  0,1,0)
    gl.glPushMatrix()
    glut.glutMainLoop()
    return
コード例 #12
0
ファイル: tileflow.py プロジェクト: jhu-interaction/wallframe
    def paintGL(self):
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
        GLU.gluLookAt(0, 0, 2, 0, 0, 0, 0, 1, 0)
        GL.glDisable(GL.GL_DEPTH_TEST)

        self.qglClearColor(self.clearColor)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        GL.glPushMatrix()
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glEnable(GL.GL_BLEND)
        GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA)

        offset = self.offset
        if offset <= 0:
            offset = 0
        if offset > len(self.res_list) - 1:
            offset = len(self.res_list) - 1
        mid = int(math.floor(offset + 0.5))
        start_pos = mid - TileflowWidget.VISIBLE_TILES
        if start_pos < 0:
            start_pos = 0
        end_pos = mid + TileflowWidget.VISIBLE_TILES
        if end_pos > len(self.res_list):
            end_pos = len(self.res_list)
        for i in range(start_pos, mid)[::TileflowWidget.DIRECTION]:
            self.drawTile(i, i - offset, self.tiles[i])
        for i in range(mid, end_pos)[::-TileflowWidget.DIRECTION]:
            self.drawTile(i, i - offset, self.tiles[i])

        GL.glPopMatrix()
コード例 #13
0
ファイル: picwall.py プロジェクト: drewp/picwall
    def draw(self):
        t1 = time.time()
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        glLoadIdentity ()
        horizonY = 1 * 2.2 - .6 + .5
        GLU.gluLookAt(self.eyeX.x, horizonY, 8.0,
                      self.lookX.x, horizonY, 0.0,
                      0.0, 1.0, 0.0)

        glEnable(GL.GL_TEXTURE_2D)

        if 0:
            with pushMatrix():
                glColor3f(1,0,0)
                glTranslatef(*self.ball)
                glScalef(.2, .2, 1)
                imageCard("sample.jpg")

        with pushMatrix():
            with mode(disable=[GL.GL_LIGHTING]):
                for card in self.cards:
                    card.draw(self.eyeX.x, horizonY, self.cardList)

        glFlush()
        pygame.display.flip()
コード例 #14
0
ファイル: blobview.py プロジェクト: rolodub/thesis
	def drawBackground(self, painter, rect) :

		super(BlobViewScene, self).drawBackground(painter,rect)
		height = float(painter.device().height())
		width = float(painter.device().width())

		painter.beginNativePainting()
		self.setStates()

		GL.glClearColor(0.0, 0.0, 0.0, 0.0)
		GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

		GL.glMatrixMode(GL.GL_PROJECTION)
		GLU.gluPerspective(60.0, width / height, 0.01, 450.0);
		GLU.gluLookAt(-self._distance,0,0,0,0,0,0,0,1);

		GL.glMatrixMode(GL.GL_MODELVIEW);

		view = QtGui.QMatrix4x4()
		view.rotate(self._trackballs[2].rotation())

#		view = np.array(list(view.data())).reshape((4,4))
#		view[2, 3] -= 2.0 * math.exp(self._distance / 1200.0)
#		view = QtGui.QMatrix4x4(*view.reshape((16,)))

		GL.glLoadMatrixf(view.data())
		self.drawAxis()
#		self.drawPoints()
		self.drawSphere()

		self.setDefaultState()
		painter.endNativePainting()
		self._frame+=1
コード例 #15
0
ファイル: camera.py プロジェクト: droidguy04/batma
 def locate(self):
     gl.glLoadIdentity()
     glu.gluLookAt(
         self.__eye_x, self.__eye_y, self.__eye_z,
         self.__center_x, self.__center_y, 0,
         self.__up_vector_x, self.__up_vector_y, self.__up_vector_z
     )
コード例 #16
0
ファイル: scene.py プロジェクト: arokem/Fos
    def reshape(self,w,h):        

        #px,py,w,h=self.viewport
        gl.glViewport (0,0,w,h)

        self.viewport=(0,0,w,h)
        
        gl.glMatrixMode (gl.GL_PROJECTION)
        
        gl.glLoadIdentity ()
                

        if self.isperspect:

            fovy,aspect,zNear,zFar=self.glu_perspect
        
            glu.gluPerspective(fovy,w/float(h),zNear,zFar)

        else:

            left,right,bottom,top,near,far=self.gl_orthog
            
            gl.glOrtho(left, right, bottom, top, near, far)

        gl.glMatrixMode (gl.GL_MODELVIEW) 

        gl.glLoadIdentity ()
        
        eyex,eyey,eyez,centx,centy,centz,upx,upy,upz=self.glu_lookat

        glu.gluLookAt(eyex,eyey,eyez,centx,centy,centz,upx,upy,upz)
コード例 #17
0
def main():
    global calib, cyl

    src_dir = os.path.split(os.path.abspath(__file__))[0]
    data_dir = os.path.join(src_dir,'..','data')
    pmat = np.loadtxt( os.path.join(data_dir, 'cameramatrix.txt') )
    calib = decompose(pmat)
    width = 752
    height = 480

    glut.glutInit()
    glut.glutInitWindowSize(width,height)
    glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_ACCUM | glut.GLUT_DOUBLE)
    glut.glutCreateWindow("calib_test_pyopengl");

    cyl = PointCylinder()
    if 1:
        # compose view matrix
        r = get_gluLookAt(pmat)
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        glu.gluLookAt( *r['all_args'] )
    gl.glDisable(gl.GL_DEPTH_TEST)
    glut.glutDisplayFunc(on_draw)
    on_resize(width,height)
    glut.glutMainLoop()
コード例 #18
0
ファイル: camera.py プロジェクト: Dominic001/MCEdit-Unified
 def setModelview(self):
     pos = self.cameraPosition
     look = numpy.array(self.cameraPosition)
     look += self.cameraVector
     up = (0, 1, 0)
     GLU.gluLookAt(pos[0], pos[1], pos[2],
                   look[0], look[1], look[2],
                   up[0], up[1], up[2])
コード例 #19
0
ファイル: graphics.py プロジェクト: BKhomutenko/SYMORO_python
 def CameraTransformation(self):
     gl.glLoadIdentity()
     glu.gluLookAt(
         self.cen_x-self.distance*cos(self.ver_angle)*sin(self.hor_angle),
         self.cen_y-self.distance*cos(self.ver_angle)*cos(self.hor_angle),
         self.cen_z+self.distance*sin(self.ver_angle),
         self.cen_x, self.cen_y, self.cen_z,
         0.0, 0.0, 1.0)
コード例 #20
0
ファイル: opengl_backend.py プロジェクト: ChrisBeaumont/mplgl
    def _set_projections(self):
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GL.glOrtho(0, self.width, 0, self.height, -10, 10)

        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
        GLU.gluLookAt(0, 0, 4, 0, 0, 0, 0, 1, 0)
コード例 #21
0
ファイル: glviewer.py プロジェクト: hobu/laspy
 def display(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glLoadIdentity()
     glu.gluLookAt(self.location[0], self.location[1], self.location[2], 
                   self.focus[0],self.focus[1], self.focus[2] ,
                   self.up[0], self.up[1], self.up[2])
     self.draw_points(self.N)
     glut.glutSwapBuffers()
コード例 #22
0
ファイル: deprecatedapp.py プロジェクト: showa-yojyo/notebook
    def set_modelview_matrix(self):
        """Set the modelview matrix with deprecated GL commands."""

        GL.glLoadIdentity()
        GLU.gluLookAt(
            self.camera_eye[0], self.camera_eye[1], self.camera_eye[2],
            self.camera_center[0], self.camera_center[1], self.camera_center[2],
            self.camera_up[0], self.camera_up[1], self.camera_up[2])
        GL.glMultMatrixf(self.rotation_matrix)
コード例 #23
0
ファイル: camera.py プロジェクト: rpwagner/tiled-display
 def draw(self, renderer):
     # print "drawing camera"
     glMatrixMode(GL_MODELVIEW)
     glLoadIdentity()
     GLU.gluLookAt(
         self.cameraPos[0],self.cameraPos[1],self.cameraPos[2],
         self.center[0],self.center[1],self.center[2],
         self.up[0],self.up[1],self.up[2]
     )
コード例 #24
0
ファイル: qt5_graphics.py プロジェクト: LinuxCNC/linuxcnc
    def redraw_perspective(self):

        w = self.winfo_width()
        h = self.winfo_height()
        GL.glViewport(0, 0, w, h)
        if self.use_gradient_background:
                GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
                GL.glMatrixMode(GL.GL_PROJECTION)
                GL.glMatrixMode(GL.GL_PROJECTION)

                GL.glPushMatrix()
                GL.glLoadIdentity()
    
                GL.glMatrixMode(GL.GL_MODELVIEW)
                GL.glLoadIdentity()
                GL.glDisable(GL.GL_DEPTH_TEST)
                GL.glBegin(GL.GL_QUADS)
                #//blue color
                GL.glColor3f(0.0, 0.0, 1)
                GL.glVertex3f(-1.0, -1.0, -1.0)
                GL.glVertex3f(1.0, -1.0, -1.0)
                #//black color
                GL.glColor3f(0.0, 0.0, 0.0)
                GL.glVertex3f(1.0, 1.0, -1.0)
                GL.glVertex3f(-1.0, 1.0, -1.0)
               
                GL.glEnd()
                GL.glEnable(GL.GL_DEPTH_TEST)
                GL.glMatrixMode(GL.GL_PROJECTION)
                GL.glPopMatrix()
                GL.glMatrixMode(GL.GL_MODELVIEW)
                GL.glLoadIdentity()
        else:
            pass
            # Clear the background and depth buffer.
            GL.glClearColor(*(self.colors['back'] + (0,)))
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluPerspective(self.fovy,               # The vertical Field of View, in radians: the amount of "zoom".
                                                    # Think "camera lens". Usually between 90 (extra wide) and 30 (quite zoomed in)
                        float(w)/float(h),          # Aspect Ratio. Notice that 4/3 == 800/600 screen resolution
                        self.near,                  # near clipping plane. Keep as big as possible, or you'll get precision issues.
                        self.far + self.distance)   # Far clipping plane. Keep as little as possible.

        GLU.gluLookAt(0, 0, self.distance,  # the position of your camera, in world space
            0, 0, 0,                        # where you want to look at, in world space
            0., 1., 0.)                     # probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        try:
            self.redraw()
        finally:
            GL.glFlush()                               # Tidy up
            GL.glPopMatrix()                   # Restore the matrix
コード例 #25
0
ファイル: modelview.py プロジェクト: g2xianxian/gloopy
 def set_world(self):
     """
     Set the OpenGL modelview matrix to account for the camera's position
     and orientation.
     """
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     position = self.camera.position
     look_at = position_or_gameitem(self.camera.look_at)
     glu.gluLookAt(position.x, position.y, position.z, look_at.x, look_at.y, look_at.z, 0, 1, 0)
コード例 #26
0
    def run(self, rate=100, looping=True):
        '''Run the viewer
        
        Parameters
        ----------
        rate : integer
            Sample rate for the display [Hz]. Lower numbers result in slower display.
        looping : boolean
            If set to "True", the display will loop until the window is closed.
        '''
            
        dt = int(1/rate*1000)  # [msec]

        # Camera properties, e.g. focal length etc
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        
        glu.gluPerspective(45, (self.display[0]/self.display[1]), 0.1, 50.0)
        gl.glTranslatef(0.0,0.0, -3)
    
        counter = 0
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    quit()
                    
            counter = np.mod(counter+1, self.quat.shape[0])
            if not looping and counter == self.quat.shape[0]-1:
                break
            
            gl.glClear(gl.GL_COLOR_BUFFER_BIT|gl.GL_DEPTH_BUFFER_BIT)
            gl.glEnable(gl.GL_DEPTH_TEST)
    
            # Camera position
            gl.glMatrixMode(gl.GL_MODELVIEW) 
            gl.glLoadIdentity()
            glu.gluLookAt(
                self.cam_pos[0], self.cam_pos[1], self.cam_pos[2],
                self.cam_target[0], self.cam_target[1], self.cam_target[2], 
                self.cam_up[0], self.cam_up[1], self.cam_up[2] )
    
            # Scene elements
            gl.glPushMatrix()
            cur_corners = vector.rotate_vector(self.vertices, self.quat[counter]) @ self.openGL2skin.T
            #cur_corners = cur_corners * np.r_[1, 1, -1] # This seems to be required
                        ##to get things right - but I don't understand OpenGL at this point
            
            self.draw_pointer(cur_corners)
            gl.glPopMatrix()
            self.draw_axes()
            
            pygame.display.flip()
            pygame.time.wait(dt)
コード例 #27
0
ファイル: Camera.py プロジェクト: CodyMcWilliams/Python
 def update_focus(self):
     focus = self.focus
     pos = self.pos
     up = self.up
     self.set_rad()
     rad = self.rad
     focus[0] = pos[0] + 100 * math.cos(rad[1])
     focus[1] = pos[1] + 100 * math.sin(rad[0])
     focus[2] = pos[2] + 100 * math.sin(rad[1])
     gl.glLoadIdentity()
     glu.gluLookAt(pos[0], pos[1], pos[2], focus[0], focus[1], focus[2], up[0], up[1], up[2])
コード例 #28
0
ファイル: demobase.py プロジェクト: caomw/FreenectFusion
 def display_base(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     
     # Prepare the model-view matrix.
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     glu.gluLookAt(*self.camera.get_glulookat_parameters())
     
     self.display()
     
     glut.glutSwapBuffers()
コード例 #29
0
ファイル: picking_test.py プロジェクト: arokem/Fos
def reshape (w, h):
    
    gl.glViewport (0, 0, w, h)
    gl.glMatrixMode (gl.GL_PROJECTION)    
    gl.glLoadIdentity ()
    glu.gluPerspective(60.0, w/ h , 1.0, 20.0)    
    #gl.glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);

    gl.glMatrixMode (gl.GL_MODELVIEW)    
    gl.glLoadIdentity ()
    glu.gluLookAt(0.0,0.0,15.0, 0.0,0.0,0.0, 0.0,1.0,0.0)
コード例 #30
0
ファイル: qt5_graphics.py プロジェクト: luzpaz/linuxcnc
    def redraw_ortho(self):
        if not self.initialised: return
        w = self.winfo_width()
        h = self.winfo_height()
        GL.glViewport(0, 0, w, h)
        if self.use_gradient_background:
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
            GL.glMatrixMode(GL.GL_PROJECTION)
            GL.glLoadIdentity()

            GL.glMatrixMode(GL.GL_MODELVIEW)
            GL.glPushMatrix()
            GL.glPushMatrix()
            GL.glLoadIdentity()

            GL.glDisable(GL.GL_DEPTH_TEST)
            GL.glBegin(GL.GL_QUADS)
            #//bottom color
            color = self.gradient_color1
            GL.glColor3f(color[0], color[1], color[2])
            GL.glVertex2f(-1.0, -1.0)
            GL.glVertex2f(1.0, -1.0)
            #//top color
            color = self.gradient_color2
            GL.glColor3f(color[0], color[1], color[2])
            GL.glVertex2f(1.0, 1.0)
            GL.glVertex2f(-1.0, 1.0)
            GL.glEnd()
            GL.glEnable(GL.GL_DEPTH_TEST)

            GL.glPopMatrix()
            GL.glPopMatrix()

        else:
            # Clear the background and depth buffer.
            GL.glClearColor(*(self.colors['back'] + (0, )))
            GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        ztran = self.distance
        k = (abs(ztran or 1))**.55555
        l = k * h / w
        GL.glOrtho(-k, k, -l, l, -1000, 1000.)
        GLU.gluLookAt(0, 0, 1, 0, 0, 0, 0., 1., 0.)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glPushMatrix()
        try:
            self.redraw()
        finally:
            GL.glFlush()  # Tidy up
            GL.glPopMatrix()  # Restore the matrix
コード例 #31
0
 def paintGL(self):
     gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
     gl.glLoadIdentity()
     glu.gluLookAt(self.location[0], self.location[1], self.location[2],
                   self.focus[0], self.focus[1], self.focus[2], self.up[0],
                   self.up[1], self.up[2])
     if self.data_buffer is not None:
         self.draw_points()
         diff = self.focus - self.location
         d = np.sqrt(diff.dot(diff))
         self.renderText(
             10, 10, "Position: %.2f,%.2f,%.2f, dist: %.2f" %
             (self.real_pos[0], self.real_pos[1], self.real_pos[2], d))
コード例 #32
0
    def update(self):
        rtheta = self.toRadian(self.theta)
        rphi = self.toRadian(self.phi)

        self.pos[0] = self.focus[0] + self.rad * n.cos(rtheta) * n.sin(rphi)
        self.pos[1] = self.focus[1] + self.rad * n.sin(rtheta)
        self.pos[2] = self.focus[2] + self.rad * n.cos(rtheta) * n.cos(rphi)

        self.moveFocus()

        GLU.gluLookAt(self.pos[0], self.pos[1], self.pos[2],
                      self.focus[0], self.focus[1], self.focus[2],
                      0, 1, 0)
コード例 #33
0
    def place_camera(self):

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluPerspective(60.0, self.screen_width / self.screen_height, 1.0,
                           2000.0)

        array = np.dot(np.transpose(self.rot_mat), np.array([0, 0, 10, 0]))
        back = np.dot(np.transpose(self.rot_mat), np.array([0, 45, -45, 0]))
        up = np.dot(np.transpose(self.rot_mat), np.array([0, 1, 0, 0]))

        GLU.gluLookAt(*(self.center + back)[0:-1],
                      *(self.center + array)[0:-1], *up[:-1])
コード例 #34
0
    def InitGL(self):
        # print "InitGL"
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glFrustum(-1.5, 1.5, -1.5, 1.5, 1, 100.0)
        # print "width height near far offset", width, height, znear, zfar, self.offset
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        # glLightfv( GL_LIGHT0, GL_AMBIENT, ( 0.5, 0.5, 0.5, 1.0 ) )
        # glLightfv( GL_LIGHT0, GL_AMBIENT, ( 1.0, 1.0, 1.0, 1.0 ) )
        # glLightfv( GL_LIGHT0, GL_POSITION, ( 0.0, 0.0, 0.0 ) )
        # glLightfv( GL_LIGHT0, GL_SPOT_DIRECTION, ( 0.0, 0.0, -1.0 ) )
        """
        glEnable(GL_LIGHT1)
        glLightfv( GL_LIGHT1, GL_DIFFUSE, ( 1.0, 1.0, 1.0, 1.0 ) )
        glLightfv( GL_LIGHT1, GL_SPECULAR, ( 1.0, 1.0, 1.0, 1.0 ) )
        glLightfv( GL_LIGHT1, GL_POSITION, ( 0.0, 0.0, -5.0 ) )
        glLightfv( GL_LIGHT1, GL_SPOT_DIRECTION, ( 0.0, 0.0, 0.0 ) )
        glEnable(GL_LIGHT2)
        glLightfv( GL_LIGHT2, GL_DIFFUSE, ( 1.0, 1.0, 1.0, 1.0 ) )
        glLightfv( GL_LIGHT2, GL_SPECULAR, ( 1.0, 1.0, 1.0, 1.0 ) )
        glLightfv( GL_LIGHT2, GL_POSITION, ( 0.0, 5.0, -2.0 ) )
        glLightfv( GL_LIGHT2, GL_SPOT_DIRECTION, ( 0.0, 0.0, -2.0 ) )

        glEnable(GL_LIGHT3)
        glLightfv( GL_LIGHT3, GL_DIFFUSE, ( 1.0, 1.0, 1.0, 1.0 ) )
        glLightfv( GL_LIGHT3, GL_SPECULAR, ( 1.0, 1.0, 1.0, 1.0 ) )
        glLightfv( GL_LIGHT3, GL_POSITION, ( 0.0, -5.0, -2.0 ) )
        glLightfv( GL_LIGHT3, GL_SPOT_DIRECTION, ( 0.0, 0.0, -2.0 ) )
        """

        gl.glEnable(gl.GL_COLOR_MATERIAL)
        """ anti-aliasing """
        gl.glEnable(gl.GL_LINE_SMOOTH)
        gl.glEnable(gl.GL_POINT_SMOOTH)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)

        gl.glClearColor(0.2, 0.2, 0.2, 1.0)  # set background color
        gl.glDepthFunc(gl.GL_LESS)
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        # gluLookAt( 0.0, 0.0, 50.0, 0.0, 0.0, -100.0, 0.0, 1.0, 0.0 )
        # gluLookAt( 0.0, 0.0, self.offset * -1.0, 0.0, 0.0, -50.0, 0.0, 1.0, 0.0 )
        glu.gluLookAt(0.0, 0.0, self.offset * -1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
                      0.0)
        # glTranslatef(0.0, 0.0, self.offset)
        # print "offset:", self.offset
        glut.glutInit(sys.argv)
コード例 #35
0
    def loadScene(self):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        _, _, width, height = GL.glGetDoublev(GL.GL_VIEWPORT)
        GLU.gluPerspective(
            45,
            width / float(height or 1), 
            .25, 
            200, 
        )

        cam_pos = self.center + self.front * 10
        GLU.gluLookAt(cam_pos[0], cam_pos[1], cam_pos[2], self.center[0], self.center[1], self.center[2], self.up[0], self.up[1], self.up[2])
コード例 #36
0
ファイル: GLViewer.py プロジェクト: yongheng1991/tk3dv
    def updateCamera(self):
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        glu.gluPerspective(self.FOVYStack[self.activeCamStackIdx], self.Width / self.Height, 1, 50000)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        glu.gluLookAt(self.CamPosStack[self.activeCamStackIdx][0], self.CamPosStack[self.activeCamStackIdx][1], self.CamPosStack[self.activeCamStackIdx][2]
                      , self.LAtStack[self.activeCamStackIdx][0], self.LAtStack[self.activeCamStackIdx][1], self.LAtStack[self.activeCamStackIdx][2]
                      , self.UpDir[0], self.UpDir[1], self.UpDir[2])

        gl.glMatrixMode(gl.GL_MODELVIEW)
コード例 #37
0
    def OnSize(self, event):
        # print "OnSize"
        s = self.GetClientSize()
        size = self.size = s
        if self.GetContext():
            self.SetCurrent()
            gl.glViewport(0, 0, size.width, size.height)

            # Maintain 1:1 Aspect Ratio
            """
            the screen starts out with a glFrustum left,right,bottom,top of -0.5,0.5,-0.5,0.5
            and an aspect ratio (screen width / screen height) of 1
            """
            w = float(size.width)
            h = float(size.height)
            if self.r == 0:
                self.r = 1
            height = width = self.r
            if size.width > size.height:
                width = width * (w / h)
            elif size.height > size.width:
                height = height * (h / w)
            # print width, "x", height
            gl.glMatrixMode(gl.GL_PROJECTION)
            gl.glLoadIdentity()
            # print "zoom", self.zoom

            znear = 0.1
            zfar = 100
            width = width / self.zoom
            height = height / self.zoom
            bottom_height = -1 * height
            top_height = height

            znear = (self.offset * -0.4)
            zfar = (self.offset * -1.6)
            #      if self.superimposition_method == IDX_SBR or self.superimposition_method == IDX_BOOKSTEIN:
            #        bottom_height += height
            #        top_height += height

            gl.glFrustum(-width, width, bottom_height, top_height, znear, zfar)
            glu.gluLookAt(0.0, 0.0, self.offset * -1.0, 0.0, 0.0, 0.0, 0.0,
                          1.0, 0.0)
            # print
            # print "width height near far offset", width, height, znear, zfar, self.offset
            # print self.r
            gl.glMatrixMode(gl.GL_MODELVIEW)  # switch back to model view

        event.Skip()
コード例 #38
0
    def display(self, delta_time, speed):
        """Refreshing screen, clearing buffers, and redrawing objects"""  #Ciscenje medjuspremnika i ponovno crtanje objekata
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(90, self.width / self.height, 0.1, 10000)
        if self.fps_view:
            glu.gluLookAt(self.player.position[0], self.player.position[1],
                          self.player.position[2] + 1, self.player.position[0],
                          self.player.position[1],
                          self.player.position[2] - 100, 0, 1, 0)
        else:
            glu.gluLookAt(self.player.position[0], self.player.position[1] + 3,
                          self.player.position[2] + 10,
                          self.player.position[0], self.player.position[1],
                          self.player.position[2] - 100, 0, 1, 0)
        self.skybox.sky_position = self.player.position
        self.ship_collider.position = self.player.position
        self.light.disable()
        self.skybox.render()
        self.light.enable()
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        for obj in self.objects:
            if my.collision_detection(self.ship_collider, obj):
                self.shield -= 1
                if self.shield <= 0:
                    del self.objects[100:]
                    self.init_properties()
                    self.player.position = [0.0, 0.0, 0.0]
            if obj.position[2] > 20:
                obj.position[0] = random.uniform(self.player.position[0] - 300,
                                                 self.player.position[0] + 300)
                obj.position[1] = random.uniform(self.player.position[1] - 300,
                                                 self.player.position[1] + 300)
                obj.position[2] = random.randint(-800, -300)
            else:
                obj.position[2] += speed * delta_time
                obj.render()

        self.center.position = self.player.position
        if not self.fps_view:
            self.light.disable()
            self.player.render()
            self.light.enable()
        else:
            self.center.render()
        self.ship_collider.render()
        self.light.render()
コード例 #39
0
ファイル: Display.py プロジェクト: chaserhkj/solar-system
 def setCamera(self):
     gl.glMatrixMode(gl.GL_PROJECTION)
     gl.glLoadIdentity()
     glu.gluPerspective(self._view_angle, self._aspect, 1e-2, 100)
     gl.glMatrixMode(gl.GL_MODELVIEW)
     gl.glLoadIdentity()
     gl.glTranslate(self._x, self._y, 0)
     glu.gluLookAt(
         self._rho * math.sin(math.radians(self._theta)) *
         math.cos(math.radians(self._phi)) + self._dx,
         self._rho * math.sin(math.radians(self._theta)) *
         math.sin(math.radians(self._phi)) + self._dy,
         self._rho * math.cos(math.radians(self._theta)) + self._dz,
         self._dx, self._dy, self._dz, 0, 0, 1)
     gl.glScale(self._scale_factor, self._scale_factor, self._scale_factor)
コード例 #40
0
    def paintGL(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45.0, 4.0 / 3.0, 0.1, 100.0)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        glu.gluLookAt(4, 3, 3, 0, 0, 0, 0, 1, 0)

        gl.glUseProgram(self._shader_program)
        gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._vbo)
        gl.glVertexPointer(3, gl.GL_FLOAT, 0, None)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 3)
コード例 #41
0
def plotpoints():
    GL.glClear(GL.GL_COLOR_BUFFER_BIT)
    GL.glColor3f(1.0, 1.0, 1.0)

    GL.glBegin(GL.GL_LINE_LOOP)
    for i, j, k in zip(vertex_x_array, vertex_y_array, vertex_z_array):
        GL.glVertex3f(i, j, k)
    GL.glEnd()
    GL.glBegin(GL.GL_LINE_LOOP)
    for i, j, k in zip(vertex_y_array, vertex_x_array, vertex_z_array):
        GL.glVertex3f(i, j, k)
    GL.glEnd()
    GLU.gluLookAt(0.0, 0.0, 0.0, vertex_x_array[0] + lol,
                  vertex_y_array[0] + lol, vertex_z_array[0] + lol, 1, 1, 1)
    GL.glFlush()
コード例 #42
0
def reshape(w, h) :
    gl.glViewport (0, 0, w, h)
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity ()

    # angulo de visao na direcao Y modificado de 60.0 para 55.0
    glu.gluPerspective(55.0, w/h, 1.0, 20.0)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    # posicao do olho no eixo X modificada de 0.0 para 1.0
    # posicao do olho no eixo Y modificada de 0.0 para 2.0
    # posicao do olho no eixo Z modificada de 5.0 para 3.5
    glu.gluLookAt(1.0, 2.0, 3.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
コード例 #43
0
def reshape(width, height):
    # parametrage du viewport :
    GL.glViewport(0, 0, width, height)
    # reinitialisation de la projection :
    GL.glMatrixMode(GL.GL_PROJECTION)
    GL.glLoadIdentity()
    # projection perspective :
    fAspect = width / height
    # utilisation de la fonction gluPerspective de GLU (voir documentation).
    # Les deux derniers parametres sont les plans de clipping (near, far) et sont
    # des valeurs positives. Note: 'near' ne doit pas etre nul.
    GLU.gluPerspective(60.0, fAspect, 1.0, 2000.0)
    # placement de la camera :
    # on utilise la fonction gluLookAt de GLU.
    GLU.gluLookAt(0, 0.0, 180.0, 0.0, 0.0, 0.0, 0, 1, 0)
コード例 #44
0
    def push(self):
        viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
        aspect = viewport[2] / float(viewport[3])

        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glPushMatrix()
        gl.glLoadIdentity()
        glu.gluPerspective(self.aperture * self.zoom, aspect, self.near,
                           self.far)
        glu.gluLookAt(self.center[0], self.center[1], self.center[2],
                      self.focus[0], self.focus[1], self.focus[2], self.up[0],
                      self.up[1], self.up[2])

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glPushMatrix()
        gl.glLoadIdentity()
コード例 #45
0
    def paintGL(self):
        self.loadScene()

        # camera rotation
        rad = self.zoom
        x_cam = rad * math.sin(self.yRot) * math.cos(self.xRot)
        y_cam = rad * math.sin(self.yRot) * math.sin(self.xRot)
        z_cam = rad * math.cos(self.yRot)
        glu.gluLookAt(x_cam, y_cam, z_cam, 0, 0, 0, 0, 1, 0)

        if self.timer.isActive():
            self.draw()
            if self.checkBox.isChecked():
                self.calculateSolar()
            else:
                self.calculateParticles()
コード例 #46
0
    def move(self, x=None, y=None, z=None):
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        facing = self.world.player.facing

        #(20 if facing == RIGHT else (-20 if facing == LEFT else 0)

        glu.gluLookAt(
            self.world.player.x, self.world.player.y, self.world.player.z,
            self.world.player.x + (20 if facing == RIGHT else
                                   (-20 if facing == LEFT else 0)),
            self.world.player.y,
            self.world.player.z + (20 if facing == FORWARDS else
                                   (-20 if facing == BACKWARDS else 0)), 0, 1,
            0)
コード例 #47
0
    def resizeGL(self, w, h):
        self.width, self.height = w, h

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluPerspective(45.0, 100, 0.1, 100.0)
        # GL.glOrtho(-1,self.width,-1,self.height,-2,2)
        GL.glFrustum(-self.width, self.width, -self.height, self.height, 1.0,
                     40.0)
        # GLU.gluOrtho2D(0, self.width, 0, self.height)
        GL.glMatrixMode(GL.GL_MODELVIEW)
        GL.glLoadIdentity()
        GLU.gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
        # GL.glRotatef(180.0, 0.0, 1.0, 0.0)
        # GL.glViewport(0, 0, w, h)
        GL.glFlush()
コード例 #48
0
ファイル: pyqt5_pyopengl.py プロジェクト: feldlime/SuperCAD
    def loadScene(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        x, y, width, height = gl.glGetDoublev(gl.GL_VIEWPORT)
        glu.gluPerspective(
            45,  # field of view in degrees
            width / float(height or 1),  # aspect ratio
            .25,  # near clipping plane
            200,  # far clipping plane
        )

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()

        glu.gluLookAt(12, 12, 12, 0, 0, 0, 0, 1, 0)
コード例 #49
0
ファイル: thumbnailmaker.py プロジェクト: olavw/RootPruning
 def paintGL(self):
     w,h = self.msize
     center = self.bbox.getCenter()
     size3d = max(self.bbox.getSize())*1.1
     ogl.glClearColor(0,0,0,0)
     ogl.glClear(ogl.GL_COLOR_BUFFER_BIT)
     ogl.glViewport(0,0,w,h)
     ogl.glMatrixMode(ogl.GL_PROJECTION);
     ogl.glLoadIdentity()
     ogl.glOrtho(-1.,1.,-1.,1.,-1000,1000)
     ogl.glMatrixMode(ogl.GL_MODELVIEW);
     ogl.glLoadIdentity()
     oglu.gluLookAt(0,1,0,0,0,0,0,0,1)
     ogl.glScalef(1./size3d,1./size3d,1./size3d)
     #ogl.glRotatef(1,0,0,pi/2.)
     ogl.glTranslatef(-center.x,-center.y,-center.z)
     self.scene.apply(self.renderer)
コード例 #50
0
ファイル: nodes.py プロジェクト: nvAli/openglcontext
    def render(self, mode):
        """Set up the perspective and model-view matrices

        Basically, we want to back-project

        context.getBoundingBox() -> center and range/scale values
        """
        self.frustum(mode, mode.context.getViewPort())
        if self.autocenter:
            center = self.context().getBoundingBox().center
        else:
            center = self.center
        # should sanity-check the up vector, range, and forward
        cameraPosition = center + (self.range * (-self.forward))
        GLU.gluLookAt(cameraPosition[0], cameraPosition[1], cameraPosition[2],
                      center[0], center[1], center[2], self.up[0], self.up[1],
                      self.up[2])
コード例 #51
0
    def reshape(self, w, h):

        gl.glViewport(0, 0, w, h)
        self.viewport = (0, 0, w, h)
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()

        if self.isperspect:
            fovy, aspect, zNear, zFar = self.glu_perspect
            glu.gluPerspective(fovy, w / float(h), zNear, zFar)
        else:
            left, right, bottom, top, near, far = self.gl_orthog
            gl.glOrtho(left, right, bottom, top, near, far)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        eyex, eyey, eyez, centx, centy, centz, upx, upy, upz = self.glu_lookat
        glu.gluLookAt(eyex, eyey, eyez, centx, centy, centz, upx, upy, upz)
コード例 #52
0
ファイル: render_scene.py プロジェクト: tpatten/pdproc
    def _set_camera(self):
        """
        Sets the camera's position relative to the scene and returns the
        projection and the view matrix
        """
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        glu.gluPerspective(45.0, float(self.width)/float(self.height),
                           self.z_near, self.z_far)
        projection = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gl.glViewport(0, 0, self.width, self.height)
        glu.gluLookAt(self.cam_pos[0], self.cam_pos[1], self.cam_pos[2],
                      0.0, 0.0, 0.0, 0.0, 1.0, .0)
        view = gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX)
        return projection, view
コード例 #53
0
    def render_rgb_indexed_colors(self, **kwargs):
        '''Draws scene in the background buffer to extract mouse click info'''
        import OpenGL.GL as gl
        import OpenGL.GLU as glu
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # camera_pos_rtp is relative to the target position. To get the
        # absolute camera position, we need to add the target position.
        gl.glPushMatrix()
        camera_pos_xyz = np.array(rtp_to_xyz(*self.camera_pos_rtp)) \
            + self.target_pos
        glu.gluLookAt(*(list(camera_pos_xyz) + list(self.target_pos) +
                        self.up))
        self.draw_data_set()
        gl.glPopMatrix()
        gl.glFlush()
コード例 #54
0
ファイル: ndwindow.py プロジェクト: w1malik/spectral
    def on_paint(self, event):
        '''Renders the entire scene.'''
        import time
        import OpenGL.GL as gl
        import OpenGL.GLU as glu

        self.canvas.SetCurrent(self.canvas.context)
        if not self.gl_initialized:
            self.initgl()
            self.gl_initialized = True
            self.print_help()
            self.resize(*self.size)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        while len(self._display_commands) > 0:
            self._display_commands.pop(0)()

        if self._refresh_display_lists:
            self.create_display_lists()

        gl.glPushMatrix()
        # camera_pos_rtp is relative to target position. To get the absolute
        # camera position, we need to add the target position.
        camera_pos_xyz = np.array(rtp_to_xyz(*self.camera_pos_rtp)) \
            + self.target_pos
        glu.gluLookAt(
            *(list(camera_pos_xyz) + list(self.target_pos) + self.up))

        if self.show_axes_tf:
            gl.glCallList(self.gllist_id)

        self.draw_data_set()

        gl.glPopMatrix()
        gl.glFlush()

        if self._selection_box is not None:
            self.draw_box(*self._selection_box)

        self.SwapBuffers()
        event.Skip()
コード例 #55
0
def main():
    "run the demo"
    # initialize pygame and setup an opengl display
    ## angle = 0.4  # camera rotation angle
    angle = 0.1  # camera rotation angle
    ## side = 700
    side = 1000
    delay = 0  # time to delay each rotation, in ms
    xyratio = 1.0  # == xside / yside
    title = 'pyboids 0.1'
    # random.seed(42)  # for repeatability
    pygame.init()
    pygame.display.set_caption(title, title)
    pygame.display.set_mode((side, side), pyg.OPENGL | pyg.DOUBLEBUF)
    gl.glEnable(gl.GL_DEPTH_TEST)   # use our zbuffer
    gl.glClearColor(0, 0, 0, 0)
    # setup the camera
    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()
    # glu.gluPerspective(60.0, xyratio, 1.0, 250.0)   # setup lens
    ## edge = 40.0
    edge = 50.0
    glu.gluPerspective(60.0, xyratio, 1.0, (6 * edge) + 10)   # setup lens
    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()
    # glu.gluLookAt(0.0, 0.0, 150, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
    glu.gluLookAt(0.0, 0.0, 3 * edge, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
    gl.glPointSize(3.0)
    cube0 = Vector3(- edge, - edge, - edge)  # cube min vertex
    cube1 = Vector3(+ edge, + edge, + edge)  # cube max vertex
    theflock = flock(200, cube0, cube1)
    # print(theflock)
    while True:
        event = pygame.event.poll()
        if event.type == pyg.QUIT or (event.type == pyg.KEYDOWN and
            (event.key == pyg.K_ESCAPE or event.key == pyg.K_q)):
            break
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
        theflock.render()
        gl.glRotatef(angle, 0, 1, 0)  # orbit camera around by angle
        pygame.display.flip()
        if delay > 0:
            pygame.time.wait(delay)
        theflock.update()
コード例 #56
0
 def position_camera(self):
     width, height = self._get_screen_dimensions()
     prev_mode = GL.glGetIntegerv(GL.GL_MATRIX_MODE)
     GL.glMatrixMode(GL.GL_PROJECTION)
     GL.glLoadIdentity()
     v = self.view
     # position the light according to the current bounding box
     light_pos = [0, 0, 0]
     low, high = self._get_low_high_dims()
     if None not in low and None not in high:
         for index in range(3):
             light_pos[index] = 2 * (high[index] - low[index])
     GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION,
                  (light_pos[0], light_pos[1], light_pos[2], 0.0))
     # position the camera
     camera_position = (v["center"][0] + v["distance"][0],
                        v["center"][1] + v["distance"][1],
                        v["center"][2] + v["distance"][2])
     # position a second light at camera position
     GL.glLightfv(
         GL.GL_LIGHT1, GL.GL_POSITION,
         (camera_position[0], camera_position[1], camera_position[2], 0.0))
     if self.core.get("view_perspective"):
         # perspective view
         GLU.gluPerspective(v["fovy"], (0.0 + width) / height, v["znear"],
                            v["zfar"])
     else:
         # parallel projection
         # This distance calculation is completely based on trial-and-error.
         distance = math.sqrt(sum([d**2 for d in v["distance"]]))
         distance *= math.log(math.sqrt(width * height)) / math.log(10)
         sin_factor = math.sin(v["fovy"] / 360.0 * math.pi) * distance
         left = v["center"][0] - sin_factor
         right = v["center"][0] + sin_factor
         top = v["center"][1] + sin_factor
         bottom = v["center"][1] - sin_factor
         near = v["center"][2] - 2 * sin_factor
         far = v["center"][2] + 2 * sin_factor
         GL.glOrtho(left, right, bottom, top, near, far)
     GLU.gluLookAt(camera_position[0], camera_position[1],
                   camera_position[2], v["center"][0], v["center"][1],
                   v["center"][2], v["up"][0], v["up"][1], v["up"][2])
     GL.glMatrixMode(prev_mode)
コード例 #57
0
ファイル: opengl.py プロジェクト: yves78/pyopengltk
    def tkRedraw(self, *dummy):
        """Cause the opengl widget to redraw itself."""

        if not self.initialised:
            return

        self.activate()

        GL.glPushMatrix()  # Protect our matrix
        self.update_idletasks()
        self.activate()
        w = self.winfo_width()
        h = self.winfo_height()
        GL.glViewport(0, 0, w, h)

        # Clear the background and depth buffer.
        GL.glClearColor(self.r_back, self.g_back, self.b_back, 0.)
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)

        GL.glMatrixMode(GL.GL_PROJECTION)
        GL.glLoadIdentity()
        GLU.gluPerspective(self.fovy, float(w) / float(h), self.near, self.far)

        if 0:
            # Now translate the scene origin away from the world origin
            GL.glMatrixMode(GL.GL_MODELVIEW)
            mat = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
            GL.glLoadIdentity()
            GL.glTranslatef(-self.xcenter, -self.ycenter,
                            -(self.zcenter + self.distance))
            GL.glMultMatrixd(mat)
        else:
            GLU.gluLookAt(self.xcenter, self.ycenter,
                          self.zcenter + self.distance, self.xcenter,
                          self.ycenter, self.zcenter, 0., 1., 0.)
            GL.glMatrixMode(GL.GL_MODELVIEW)

        # Call objects redraw method.
        self.redraw(self)
        GL.glFlush()  # Tidy up
        GL.glPopMatrix()  # Restore the matrix

        self.tkSwapBuffers()
コード例 #58
0
    def draw(self):
        t0 = time.time()

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        glu.gluPerspective(30, 1, 1, 20)
        x, y, z = camera.position
        glu.gluLookAt(x, y, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

        if draw_grid:
            grid_width = 10
            gl.glBegin(gl.GL_LINES)
            for i in range(-grid_width, grid_width + 1):
                gl.glColor4f(1, 1, 1, 0.25 - 0.25 * (i / 10)**2)
                gl.glVertex3f(i, 0, -grid_width)
                gl.glVertex3f(i, 0, grid_width)
            for i in range(-grid_width, grid_width + 1):
                gl.glColor4f(1, 1, 1, 0.25 - 0.25 * (i / 10)**2)
                gl.glVertex3f(-grid_width, 0, i)
                gl.glVertex3f(grid_width, 0, i)
            gl.glEnd()

        if draw_axes:
            gl.glBegin(gl.GL_LINES)
            gl.glColor4f(1, 0, 0, 0.2)
            gl.glVertex3f(0, 0, 0)
            gl.glVertex3f(10, 0, 0)
            gl.glColor4f(0, 1, 0, 0.2)
            gl.glVertex3f(0, 0, 0)
            gl.glVertex3f(0, 10, 0)
            gl.glColor4f(0, 0, 1, 0.2)
            gl.glVertex3f(0, 0, 0)
            gl.glVertex3f(0, 0, 10)
            gl.glEnd()

        self.universe.draw()

        gl.glFlush()

        self.num_frames += 1
        self.draw_time += time.time() - t0
コード例 #59
0
ファイル: boing.py プロジェクト: timweckx/cyglfw3
def reshape(window, w, h):
    global RADIUS, VIEW_SCENE_DIST

    gl.glViewport(0, 0, w, h)

    gl.glMatrixMode(gl.GL_PROJECTION)
    gl.glLoadIdentity()

    glu.gluPerspective(PerspectiveAngle(RADIUS * 2, 200),
                       float(w)/h,
                       1.0,
                       VIEW_SCENE_DIST)

    gl.glMatrixMode(gl.GL_MODELVIEW)
    gl.glLoadIdentity()

    glu.gluLookAt(0.0, 0.0, VIEW_SCENE_DIST,   # eye
                  0.0, 0.0, 0.0,               # center of vision
                  0.0, -1.0, 0.0)              # up vector
コード例 #60
-1
 def paintGL(self):
     GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
     
     GL.glPushMatrix()
     GL.glLoadIdentity()
     GLU.gluLookAt(self.camera.eye.x, self.camera.eye.y, self.camera.eye.z,
         self.camera.at.x , self.camera.at.y, self.camera.at.z ,
         self.camera.up.x , self.camera.up.y, self.camera.up.z)
     
     GL.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, (GL.GLfloat *4) ( self.camera.eye.x, self.camera.eye.y, self.camera.eye.z, 1 ))
     
     if self.wireframe:
         GL.glDisable(GL.GL_LIGHTING)
         GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
         GL.glColor3f(0, 1, 0)
     else:
         GL.glEnable(GL.GL_LIGHTING)
         GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
         GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, (GL.GLfloat * 4) ( 1, 1, 1, 1 ))
         
     if self.display_object:
         self.display_object.draw()
     
     GL.glDisable(GL.GL_LIGHTING)
     if self.grid:
         glutils.draw_grid()
         
     if self.frameRef:
         glutils.draw_frame()
     GL.glEnable(GL.GL_LIGHTING)
     
     GL.glPopMatrix()