コード例 #1
0
ファイル: viewer.py プロジェクト: phantom2018/shiyanlou
    def init_opengl(self):

        #model view matrix
        self.inverseModelView = numpy.identity(4)
        #its anti-matrix
        self.modelView = numpy.identity(4)

        #open tichu effect
        glEnable(GL_CULL_FACE)
        #to not rend invisible part
        glCullFace(GL_BACK)
        #open depth test
        glEnable(GL_DEPTH_TEST)
        #objects being covered ot to rend
        glDepthFunc(GL_LESS)
        #open light 0
        glEnable(GL_LIGHT0)
        #to set the position of light
        glLightfv(GL_LIGHT0, GL_POSITION, GLfloat_4(0, 0, 1, 0))
        #to set the direction that light sheds at
        glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, GLfloat_3(0, 0, -1))
        #to set material color
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
        #set the color of a clear-screen
        glClearColor(0.4, 0.4, 0.4, 0.0)
コード例 #2
0
ファイル: canvas3D.py プロジェクト: softtrainee/arlab
    def _set_lighting(self):
        '''
        '''
        glEnable(GL_LIGHTING)
        lights = [(GL_LIGHT0, [(GL_POSITION, [1, 1, 0, 0]),
                            (GL_AMBIENT, [0.1, 0.1, 0.1, 1]),
                            (GL_SPECULAR, [1, 1, 1, 1]),
                            (GL_DIFFUSE, [1, 1, 1, 1])
                            ]),
#                  (GL_LIGHT1, [(GL_POSITION, [0, 0, 1, 0]),
#                            (GL_AMBIENT, [0.1, 0.1, 0.1, 1]),
#                            (GL_SPECULAR, [1, 1, 1, 1]),
#                            (GL_DIFFUSE, [1, 1, 1, 1])
#                            ]
#                   ),
                ]
        for l, params in lights:
            glEnable(l)
            for pa, args in params:
                glLightfv(l, pa, args)
#
                # glLightfv(GL_LIGHT0, GL_POSITION, [10, 0, 0, 0])
#        glLightfv(GL_LIGHT0, GL_AMBIENT, [0.1, 0.1, 0.1, 1])
#        glLightfv(GL_LIGHT0, GL_SPECULAR, [1, 1, 1, 1])
#        glLightfv(GL_LIGHT0, GL_DIFFUSE, [1, 1, 1, 1])
#
#        glLightfv(GL_LIGHT0,GL_SPOT_CUTOFF,30)
#
#        glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,[-1,0,0,0])
#



        glEnable(GL_COLOR_MATERIAL, GL_AMBIENT_AND_DIFFUSE)
コード例 #3
0
ファイル: D12.py プロジェクト: Vanojx1/AdventOfCode2019
def main():
    moons = [Moon(pos) for pos in d12_input]
    glutInit(sys.argv)
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
    glutInitWindowSize(800, 800)
    glutInitWindowPosition(350, 200)
    glutCreateWindow('name')
    glClearColor(0., 0., 0., 1.)
    glShadeModel(GL_SMOOTH)
    glEnable(GL_CULL_FACE)
    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    lightZeroPosition = [10., 4., 10., 1.]
    lightZeroColor = [0.8, 1.0, 0.8, 1.0]
    glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
    glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
    glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
    glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
    glEnable(GL_LIGHT0)
    glutDisplayFunc(lambda: display_scene(moons))
    glutTimerFunc(0, timer, 0)
    glMatrixMode(GL_PROJECTION)
    gluPerspective(40., 1., 1., 40.)
    glMatrixMode(GL_MODELVIEW)
    gluLookAt(0, -10, 10, 0, 0, 0, 0, 1, 0)
    glPushMatrix()
    glutMainLoop()
コード例 #4
0
    def init_opengl(self):
        """ initialize the opengl settings to render the scene """

        self.inverseModelView = numpy.identity(4)

        self.modelView = numpy.identity(4)

        glEnable(GL_CULL_FACE)

        glCullFace(GL_BACK)

        glEnable(GL_DEPTH_TEST)

        glDepthFunc(GL_LESS)

        glEnable(GL_LIGHT0)

        glLightfv(GL_LIGHT0, GL_POSITION, GLfloat_4(0, 0, 1, 0))

        glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, GLfloat_3(0, 0, -1))

        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)

        glEnable(GL_COLOR_MATERIAL)

        glClearColor(0.4, 0.4, 0.4, 0.0)
    def init_opengl(self):
        """ 初始化opengl的配置 """
        #模型视图矩阵
        self.inverseModelView = numpy.identity(4)
        #模型视图矩阵的逆矩阵
        self.modelView = numpy.identity(4)

        #开启剔除操作效果
        glEnable(GL_CULL_FACE)
        #取消对多边形背面进行渲染的计算(看不到的部分不渲染)
        glCullFace(GL_BACK)
        #开启深度测试
        glEnable(GL_DEPTH_TEST)
        #测试是否被遮挡,被遮挡的物体不予渲染
        glDepthFunc(GL_LESS)
        #启用0号光源
        glEnable(GL_LIGHT0)
        #设置光源的位置
        glLightfv(GL_LIGHT0, GL_POSITION, GLfloat_4(0, 0, 1, 0))
        #设置光源的照射方向
        glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, GLfloat_3(0, 0, -1))
        #设置材质颜色
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
        #设置清屏的颜色
        glClearColor(0.4, 0.4, 0.4, 0.0)
コード例 #6
0
ファイル: obj.py プロジェクト: OpenWerkplek/pymt
 def enter(self):
     if not self.compat:
         return
     glLightfv(GL_LIGHT0, GL_AMBIENT, (0, 0, 0, 1))
     glLightfv(GL_LIGHT0, GL_DIFFUSE, (.8, .8, .8, 1))
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (.9, .9, .9))
     glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)
     glEnable(GL_LIGHTING)
     glEnable(GL_LIGHT0)
     glEnable(GL_DEPTH_TEST)
     glColor3f(1, 1, 1)
コード例 #7
0
 def enter(self):
     if not self.compat:
         return
     glLightfv(GL_LIGHT0, GL_AMBIENT, (0, 0, 0, 1))
     glLightfv(GL_LIGHT0, GL_DIFFUSE, (.8, .8, .8, 1))
     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (.9, .9, .9))
     glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, 0)
     glEnable(GL_LIGHTING)
     glEnable(GL_LIGHT0)
     glEnable(GL_DEPTH_TEST)
     glColor3f(1, 1, 1)
コード例 #8
0
    def draw_light_source(self):

        glColor3f(1.0, 1.0, 1.0)

        # 15 is radius of the sphere that light source around
        self.light_source_position = [
            15 * sin(self.theta_light_angle * pi / 180) *
            sin(self.phi_light_angle * pi / 180),
            15 * cos(self.theta_light_angle * pi / 180),
            15 * sin(self.theta_light_angle * pi / 180) *
            cos(self.phi_light_angle * pi / 180)
        ]

        glTranslate(self.light_source_position[0],
                    self.light_source_position[1],
                    self.light_source_position[2])
        # set light source position
        glLightfv(GL_LIGHT0, GL_POSITION, [*self.light_source_position, 1])
        # set light color
        glLightfv(GL_LIGHT0, GL_DIFFUSE, self.light_color)
        # set light intensity
        glLightfv(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.7)
        glLightfv(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0001)

        # turning the rays of light so that the back of the ball is shaded
        gl_q = gluNewQuadric()
        gluQuadricOrientation(gl_q, GLU_INSIDE)

        # draw visual envelope (ball)
        gluSphere(gl_q, 1, 20, 20)

        glLoadIdentity()
コード例 #9
0
ファイル: viewer.py プロジェクト: 343829084/500lines
    def init_opengl(self):
        """ initialize the opengl settings to render the scene """
        self.inverseModelView = numpy.identity(4)
        self.modelView = numpy.identity(4)

        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)

        glEnable(GL_LIGHT0)
        glLightfv(GL_LIGHT0, GL_POSITION, GLfloat_4(0, 0, 1, 0))
        glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, GLfloat_3(0, 0, -1))

        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
        glClearColor(1.0, 1.0, 1.0, 0.0)
コード例 #10
0
ファイル: opengl.py プロジェクト: matqr/vector
    def apply(self, index: int):
        """Applies this light to the active OpenGL context.

        :param index: the internal OpenGL light index to apply this class's data to.
        """
        opengl_index = GL_LIGHT0 + index
        glLightfv(opengl_index, GL_AMBIENT, self._ambient_color)
        glLightfv(opengl_index, GL_DIFFUSE, self._diffuse_color)
        glLightfv(opengl_index, GL_SPECULAR, self._specular_color)
        glLightfv(opengl_index, GL_POSITION, self._position_coords)
        glEnable(opengl_index)
コード例 #11
0
ファイル: __main__.py プロジェクト: leriomaggio/rainbowalga
    def init_opengl(self, width, height, x, y):
        glutInit()
        glutInitWindowPosition(x, y)
        glutInitWindowSize(width, height)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE)
        glutCreateWindow("Rainbow Alga")
        glutDisplayFunc(self.render)
        glutIdleFunc(self.render)
        glutReshapeFunc(self.resize)

        glutMouseFunc(self.mouse)
        glutMotionFunc(self.drag)
        glutKeyboardFunc(self.keyboard)
        glutSpecialFunc(self.special_keyboard)

        glClearDepth(1.0)
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 3000)
        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)


        # Lighting
        light_ambient = (0.0, 0.0, 0.0, 1.0)
        light_diffuse = (1.0, 1.0, 1.0, 1.0)
        light_specular = (1.0, 1.0, 1.0, 1.0)
        light_position = (-100.0, 100.0, 100.0, 0.0)

        mat_ambient = (0.7, 0.7, 0.7, 1.0)
        mat_diffuse = (0.8, 0.8, 0.8, 1.0)
        mat_specular = (1.0, 1.0, 1.0, 1.0)
        high_shininess = (100)

        glEnable(GL_LIGHT0)
        glEnable(GL_NORMALIZE)
        glEnable(GL_COLOR_MATERIAL)
        glEnable(GL_LIGHTING)

        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse)
        glLightfv(GL_LIGHT0, GL_SPECULAR,  light_specular)
        glLightfv(GL_LIGHT0, GL_POSITION, light_position)

        glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient)
        glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse)
        glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular)
        glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess)

        # Transparency
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
コード例 #12
0
    def initializeGL(self):
        print("initializeGL")
        self.texNumeros, self.texDecor = self.load_textures()
        glEnable(GL_TEXTURE_2D)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glFrontFace(GL_CCW)

        light_ambient = [0.3, 0.3, 0.3, 0.1]

        glEnable(GL_LIGHTING)
        lightpos = (0, 0, 50)
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
        glLightfv(GL_LIGHT0, GL_POSITION, lightpos)
        glEnable(GL_LIGHT0)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)

        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
コード例 #13
0
ファイル: show.py プロジェクト: jszymon/pycsg
    def init(self):
        # Enable a single OpenGL light.
        glLightfv(GL_LIGHT0, GL_AMBIENT, self.light_ambient)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, self.light_diffuse)
        glLightfv(GL_LIGHT0, GL_POSITION, self.light_position)
        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHTING)

        # Use depth buffering for hidden surface elimination.
        glEnable(GL_DEPTH_TEST)

        # Setup the view of the cube.
        glMatrixMode(GL_PROJECTION)
        gluPerspective(40.0, 640. / 480., 1.0, 10.0)
        glMatrixMode(GL_MODELVIEW)
        gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.)
コード例 #14
0
def render_to_png(filename,
                  callback,
                  obb,
                  model_matrix=(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
                                1)):
    from pygame import init, display, quit
    from pygame.constants import OPENGL, DOUBLEBUF
    from OpenGL.GL import glLightfv, glCullFace, glEnable, glShadeModel, glMatrixMode, glLoadIdentity, glClear, \
        glLoadMatrixf, glPolygonMode, glCallList, glReadPixels, GL_LIGHT0, GL_POSITION, GL_AMBIENT, GL_DIFFUSE, \
        GL_BACK, GL_LIGHTING, GL_COLOR_MATERIAL, GL_DEPTH_TEST, GL_SMOOTH, GL_PROJECTION, GL_MODELVIEW, \
        GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_FRONT_AND_BACK, GL_FILL, GL_LINE, GL_BGR, GL_UNSIGNED_BYTE
    from OpenGL.GLU import gluPerspective
    from cv2 import imwrite
    from numpy import frombuffer, uint8
    init()
    viewport = (800, 600)
    display.set_mode(viewport, OPENGL | DOUBLEBUF)
    glLightfv(GL_LIGHT0, GL_POSITION, (0, -1, 0, 0))
    glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, 0.2, 0.2, 1))
    glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1))
    glCullFace(GL_BACK)
    glEnable(GL_LIGHT0)
    glEnable(GL_LIGHTING)
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_DEPTH_TEST)
    glShadeModel(GL_SMOOTH)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    width, height = viewport
    gluPerspective(90.0, width / float(height), 0.1, 100.0)
    glEnable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glLoadMatrixf(model_matrix)
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    glCallList(callback())
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glCallList(create_obb_gl_list(obb))
    img_data = glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE)
    img = frombuffer(img_data, dtype=uint8)
    img = img.reshape((height, width, 3))
    imwrite(filename, img)
    quit()
コード例 #15
0
    def initializeGL(self):
        # We call this right after our OpenGL window is created.
        glClearColor(1.0, 1.0, 1.0, 1.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glShadeModel(GL_SMOOTH)

        glEnable(GL_NORMALIZE)
        light_position = (0., 0., 1., 0.)
        white_light = (1., 1., 1., 0.501)
        d_light = (1., 1., 1., 0.01)
        spec = (1., 1., 1., 0.08)
        glLightfv(GL_LIGHT0, GL_POSITION, light_position)
        glLightfv(GL_LIGHT0, GL_AMBIENT, white_light)
        #glLightfv(GL_LIGHT0, GL_DIFFUSE,  d_light)
        glLightfv(GL_LIGHT0, GL_SPECULAR, spec)

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        #glBlendFunc(GL_SRC_ALPHA,GL_ONE)
        glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
        glEnable(GL_COLOR_MATERIAL)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluPerspective(
            45.0,
            float(self.size().height()) / float(self.size().width()), 0.1,
            1000000.0)

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        self.rotation = [0.0, 0.0]
        self.mesh.prepDraw()
コード例 #16
0
ファイル: widgets.py プロジェクト: wwu-numerik/pydune
	def initializeGL(self):
		# We call this right after our OpenGL window is created.
		glClearColor(1.0, 1.0, 1.0, 1.0)
		glClearDepth(1.0)
		glDepthFunc(GL_LESS)
		glEnable(GL_DEPTH_TEST)
		glShadeModel(GL_SMOOTH)

		glEnable(GL_NORMALIZE)
		light_position = (0., 0., 1., 0.)
		white_light = (1., 1., 1., 0.501)
		d_light = (1., 1., 1., 0.01)
		spec = (1., 1., 1., 0.08)
		glLightfv(GL_LIGHT0, GL_POSITION, light_position)
		glLightfv(GL_LIGHT0, GL_AMBIENT,  white_light)
		#glLightfv(GL_LIGHT0, GL_DIFFUSE,  d_light)
		glLightfv(GL_LIGHT0, GL_SPECULAR, spec)

		glEnable(GL_LIGHTING)
		glEnable(GL_LIGHT0)

		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
		#glBlendFunc(GL_SRC_ALPHA,GL_ONE)
		glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
		glEnable(GL_COLOR_MATERIAL)
		glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()

		gluPerspective(45.0, float(self.size().height())/
						float(self.size().width()), 0.1, 1000000.0)

		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()
		self.rotation = [0.0, 0.0]
		self.mesh.prepDraw()
コード例 #17
0
ファイル: gl_lighting.py プロジェクト: pmetzger/nanoengineer
def setup_standard_lights( lights, glprefs):
    """
    Set up lighting in the current GL context using the supplied "lights" tuple
    (in the format used by GLPane's prefs) and the required glprefs object
    (of class GLPrefs).

    @note: the glprefs data used can be summarized by the related function
        glprefs_data_used_by_setup_standard_lights (which see).

    @warning: has side effects on GL_MODELVIEW matrix.

    @note: If GL_NORMALIZE needs to be enabled, callers should do that
        themselves, since this depends on what they will draw and might
        slow down drawing.
    """

    assert glprefs is not None
    
    # note: whatever glprefs data is used below must also be present
    # in the return value of glprefs_data_used_by_setup_standard_lights().
    # [bruce 051212]

    #e not sure whether projection matrix also needs to be reset here
    # [bruce 051212]
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    try:
        # new code
        (((r0,g0,b0),a0,d0,s0,x0,y0,z0,e0), \
         ( (r1,g1,b1),a1,d1,s1,x1,y1,z1,e1), \
         ( (r2,g2,b2),a2,d2,s2,x2,y2,z2,e2)) = lights

        # Great place for a print statement for debugging lights.  Keep this.
        # Mark 051204. [revised by bruce 051212]
        #print "-------------------------------------------------------------"
        #print "setup_standard_lights: lights[0]=", lights[0]
        #print "setup_standard_lights: lights[1]=", lights[1]
        #print "setup_standard_lights: lights[2]=", lights[2]

        glLightfv(GL_LIGHT0, GL_POSITION, (x0, y0, z0, 0))
        glLightfv(GL_LIGHT0, GL_AMBIENT, (r0*a0, g0*a0, b0*a0, 1.0))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, (r0*d0, g0*d0, b0*d0, 1.0))
        if glprefs.override_light_specular is not None:
            glLightfv(GL_LIGHT0, GL_SPECULAR, glprefs.override_light_specular)
        else:
            # grantham 20051121 - this should be a component on its own
            # not replicating the diffuse color.
            # Added specular (s0) as its own component.  mark 051202.
            glLightfv(GL_LIGHT0, GL_SPECULAR, (r0*s0, g0*s0, b0*s0, 1.0))
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT1, GL_POSITION, (x1, y1, z1, 0))
        glLightfv(GL_LIGHT1, GL_AMBIENT, (r1*a1, g1*a1, b1*a1, 1.0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, (r1*d1, g1*d1, b1*d1, 1.0))
        if glprefs.override_light_specular is not None:
            glLightfv(GL_LIGHT1, GL_SPECULAR, glprefs.override_light_specular)
        else:
            glLightfv(GL_LIGHT1, GL_SPECULAR, (r1*s1, g1*s1, b1*s1, 1.0))
        glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT2, GL_POSITION, (x2, y2, z2, 0))
        glLightfv(GL_LIGHT2, GL_AMBIENT, (r2*a2, g2*a2, b2*a2, 1.0))
        glLightfv(GL_LIGHT2, GL_DIFFUSE, (r2*d2, g2*d2, b2*d2, 1.0))
        if glprefs.override_light_specular is not None:
            glLightfv(GL_LIGHT2, GL_SPECULAR, glprefs.override_light_specular)
        else:
            glLightfv(GL_LIGHT2, GL_SPECULAR, (r2*s2, g2*s2, b2*s2, 1.0))
        glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 1.0)

        glEnable(GL_LIGHTING)

        if e0:
            glEnable(GL_LIGHT0)
        else:
            glDisable(GL_LIGHT0)

        if e1:
            glEnable(GL_LIGHT1)
        else:
            glDisable(GL_LIGHT1)

        if e2:
            glEnable(GL_LIGHT2)
        else:
            glDisable(GL_LIGHT2)
    except:
        print_compact_traceback(
            "bug (worked around): setup_standard_lights reverting to old code.")
        # old code, used only to set up some sort of workable lighting in case
        # of bugs (this is not necessarily using the same values as
        # _default_lights; doesn't matter since never used unless there are
        # bugs)
        glLightfv(GL_LIGHT0, GL_POSITION, (-50, 70, 30, 0))
        glLightfv(GL_LIGHT0, GL_AMBIENT, (0.3, 0.3, 0.3, 1.0))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.8, 0.8, 0.8, 1.0))
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT1, GL_POSITION, (-20, 20, 20, 0))
        glLightfv(GL_LIGHT1, GL_AMBIENT, (0.4, 0.4, 0.4, 1.0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, (0.4, 0.4, 0.4, 1.0))
        glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT2, GL_POSITION, (0, 0, 100, 0))
        glLightfv(GL_LIGHT2, GL_AMBIENT, (1.0, 1.0, 1.0, 1.0))
        glLightfv(GL_LIGHT2, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
        glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 1.0)

        glEnable(GL_LIGHTING)

        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)
        glDisable(GL_LIGHT2)
    return # from setup_standard_lights
コード例 #18
0
ファイル: gl.py プロジェクト: eecs-susu/computer-graphics
 def light(cls, light: Capability, light_parameter: LightParameter, value):
     if isinstance(value, Iterable):
         glLightfv(light.value, light_parameter.value, value)
     else:
         glLightf(light.value, light_parameter.value, value)
コード例 #19
0
ファイル: show3d.py プロジェクト: Mahdisadjadi/pele
 def initializeGL(self):
     """
     Initialize GL
     """
     
     GL.glClearColor(1., 1., 1., 1.)
     GL.glShadeModel(GL.GL_SMOOTH)
     glEnable(GL.GL_CULL_FACE)
     glEnable(GL.GL_DEPTH_TEST)
     glEnable(GL.GL_LIGHTING)
     lightZeroPosition = [-800., 500., 1500., 1.]
     lightZeroColor = [1.0, 1., 1., 1.0] #green tinged
     glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightZeroPosition)
     glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, lightZeroColor)
     glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [0.5, 0.5, 0.5, 1.0])
     
     
     GL.glLightf(GL.GL_LIGHT0, GL.GL_CONSTANT_ATTENUATION, 1.000)
     #glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.01)
     glEnable(GL.GL_LIGHT0)
     
     glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, [100., 200., -20., 1.])
     glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, [1., 1., 1., 1.0])
     glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
     glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, [0., 0., 0., 1.0])
     GL.glLightf(GL.GL_LIGHT1, GL.GL_CONSTANT_ATTENUATION, 1)
     #glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.01)
     glEnable(GL.GL_LIGHT1)
     
     GL.glShadeModel(GL.GL_SMOOTH)
     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()
コード例 #20
0
def setup_standard_lights(lights, glprefs=None):
    """
    Set up lighting in the current GL context using the supplied "lights" tuple
    (in the format used by GLPane's prefs) and the optional glprefs object
    (which defaults to drawing_globals.glprefs ).

       Note: the glprefs data used can be summarized by the related function
       glprefs_data_used_by_setup_standard_lights (which see).

       Warning: has side effects on GL_MODELVIEW matrix.

       Note: If GL_NORMALIZE needs to be enabled, callers should do that
       themselves, since this depends on what they will draw and might slow down
       drawing.
    """
    #e not sure whether projection matrix also needs to be reset here
    # [bruce 051212]
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    if glprefs is None:
        glprefs = drawing_globals.glprefs
        # note: whatever glprefs data is used below must also be present
        # in the return value of glprefs_data_used_by_setup_standard_lights().
        # [bruce 051212]

    try:
        # new code
        (((r0,g0,b0),a0,d0,s0,x0,y0,z0,e0), \
         ( (r1,g1,b1),a1,d1,s1,x1,y1,z1,e1), \
         ( (r2,g2,b2),a2,d2,s2,x2,y2,z2,e2)) = lights

        # Great place for a print statement for debugging lights.  Keep this.
        # Mark 051204. [revised by bruce 051212]
        #print "-------------------------------------------------------------"
        #print "setup_standard_lights: lights[0]=", lights[0]
        #print "setup_standard_lights: lights[1]=", lights[1]
        #print "setup_standard_lights: lights[2]=", lights[2]

        glLightfv(GL_LIGHT0, GL_POSITION, (x0, y0, z0, 0))
        glLightfv(GL_LIGHT0, GL_AMBIENT, (r0 * a0, g0 * a0, b0 * a0, 1.0))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, (r0 * d0, g0 * d0, b0 * d0, 1.0))
        if glprefs.override_light_specular is not None:
            glLightfv(GL_LIGHT0, GL_SPECULAR, glprefs.override_light_specular)
        else:
            # grantham 20051121 - this should be a component on its own
            # not replicating the diffuse color.
            # Added specular (s0) as its own component.  mark 051202.
            glLightfv(GL_LIGHT0, GL_SPECULAR, (r0 * s0, g0 * s0, b0 * s0, 1.0))
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT1, GL_POSITION, (x1, y1, z1, 0))
        glLightfv(GL_LIGHT1, GL_AMBIENT, (r1 * a1, g1 * a1, b1 * a1, 1.0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, (r1 * d1, g1 * d1, b1 * d1, 1.0))
        if glprefs.override_light_specular is not None:
            glLightfv(GL_LIGHT1, GL_SPECULAR, glprefs.override_light_specular)
        else:
            glLightfv(GL_LIGHT1, GL_SPECULAR, (r1 * s1, g1 * s1, b1 * s1, 1.0))
        glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT2, GL_POSITION, (x2, y2, z2, 0))
        glLightfv(GL_LIGHT2, GL_AMBIENT, (r2 * a2, g2 * a2, b2 * a2, 1.0))
        glLightfv(GL_LIGHT2, GL_DIFFUSE, (r2 * d2, g2 * d2, b2 * d2, 1.0))
        if glprefs.override_light_specular is not None:
            glLightfv(GL_LIGHT2, GL_SPECULAR, glprefs.override_light_specular)
        else:
            glLightfv(GL_LIGHT2, GL_SPECULAR, (r2 * s2, g2 * s2, b2 * s2, 1.0))
        glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 1.0)

        glEnable(GL_LIGHTING)

        if e0:
            glEnable(GL_LIGHT0)
        else:
            glDisable(GL_LIGHT0)

        if e1:
            glEnable(GL_LIGHT1)
        else:
            glDisable(GL_LIGHT1)

        if e2:
            glEnable(GL_LIGHT2)
        else:
            glDisable(GL_LIGHT2)
    except:
        debug.print_compact_traceback(
            "bug (worked around): setup_standard_lights reverting to old code."
        )
        # old code, used only to set up some sort of workable lighting in case
        # of bugs (this is not necessarily using the same values as
        # _default_lights; doesn't matter since never used unless there are
        # bugs)
        glLightfv(GL_LIGHT0, GL_POSITION, (-50, 70, 30, 0))
        glLightfv(GL_LIGHT0, GL_AMBIENT, (0.3, 0.3, 0.3, 1.0))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.8, 0.8, 0.8, 1.0))
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT1, GL_POSITION, (-20, 20, 20, 0))
        glLightfv(GL_LIGHT1, GL_AMBIENT, (0.4, 0.4, 0.4, 1.0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, (0.4, 0.4, 0.4, 1.0))
        glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.0)

        glLightfv(GL_LIGHT2, GL_POSITION, (0, 0, 100, 0))
        glLightfv(GL_LIGHT2, GL_AMBIENT, (1.0, 1.0, 1.0, 1.0))
        glLightfv(GL_LIGHT2, GL_DIFFUSE, (1.0, 1.0, 1.0, 1.0))
        glLightf(GL_LIGHT2, GL_CONSTANT_ATTENUATION, 1.0)

        glEnable(GL_LIGHTING)

        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)
        glDisable(GL_LIGHT2)
    return  # from setup_standard_lights
コード例 #21
0
ファイル: position_mars_3d.py プロジェクト: xnchu/PyTplot
 def paintGL(self, region=None, viewport=None, useItemNames=False):
     glLightfv(GL_LIGHT0, GL_POSITION, [-100000, 0, 0, 0])
     super().paintGL(region=region,
                     viewport=viewport,
                     useItemNames=useItemNames)
コード例 #22
0
ファイル: ncviewer.py プロジェクト: jbernardis/cnctools
    def InitGL(self):
        glClearColor(0.0, 0.0, 0.0, 1)
        glColor3f(1, 0, 0)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_LIGHT1)

        glLightfv(GL_LIGHT0, GL_POSITION, vec(.5, .5, 1, 0))
        glLightfv(GL_LIGHT0, GL_SPECULAR, vec(.5, .5, 0.5, 1))
        glLightfv(GL_LIGHT0, GL_DIFFUSE, vec(1, 1, 1, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(1, 0, .5, 0))
        glLightfv(GL_LIGHT1, GL_DIFFUSE, vec(.5, .5, .5, 1))
        glLightfv(GL_LIGHT1, GL_SPECULAR, vec(1, 1, 1, 1))

        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
                     vec(0.5, 0, 0.3, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 80)
        glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0.1, 0.1, 0.1, 0.9))

        glLightfv(GL_LIGHT0, GL_POSITION, vec(0.0, 200.0, 100.0, 1))
        glLightfv(GL_LIGHT1, GL_POSITION, vec(0.0, -200.0, 100.0, 1))
コード例 #23
0
    def __init__(self):

        print(str(bool(glutInit)))
        print("hello and weolcome")
        print(
            "if you see an error next try the unofficial binaries of pyopengl")

        print("initializing glut etc")
        glutInit(sys.argv)
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
        glutInitWindowSize(640, 480)
        glutCreateWindow(name)

        print("set blend function")
        glBlendFunc(GL_SRC_ALPHA, GL_ONE)

        print("set colours and lights")
        glClearColor(0., 0., 0., 1.)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_CULL_FACE)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)

        print("set light 1")
        lightZeroPosition = [10., 4., 10., 1.]
        lightZeroColor = [0.9, 1.0, 0.9, 1.0]  #green tinged
        glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.2)
        glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
        glEnable(GL_LIGHT0)

        print("set light 2")
        lightZeroPosition2 = [-10., -4., 10., 1.]
        lightZeroColor2 = [1.0, 0.9, 0.9, 1.0]  #green tinged
        glLightfv(GL_LIGHT1, GL_POSITION, lightZeroPosition2)
        glLightfv(GL_LIGHT1, GL_DIFFUSE, lightZeroColor2)
        glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0.2)
        glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.05)
        glEnable(GL_LIGHT1)

        #initialization of letters
        print("initialzing letters")
        self.letters = Letters.Letters()

        #for game models
        print("making model lists")
        MakeLists()

        print("ignore key repeat")
        glutIgnoreKeyRepeat(1)

        print("attach glut events to functions")
        glutSpecialFunc(self.keydownevent)
        glutSpecialUpFunc(self.keyupevent)
        glutReshapeFunc(self.reshape)

        glutKeyboardFunc(self.keydownevent)
        glutKeyboardUpFunc(self.keyupevent)
        glutDisplayFunc(self.display)
        #glutIdleFunc(self.display)

        print("initial projection")
        glMatrixMode(GL_PROJECTION)
        gluPerspective(60.0, 640.0 / 480., 1., 50.)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()

        print("generating level")
        self.level = generateLevel(0)

        print("keys set up")
        self.initkey("zxdcfvqaopm")
        self.animate()

        print("about to loop...")
        glutMainLoop()

        return
コード例 #24
0
ファイル: imu_gl_widget.py プロジェクト: jose1711/brickv
    def initializeGL(self):
        glClearColor(0.85, 0.85, 0.85, 1.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glShadeModel(GL_SMOOTH)
        glEnable(GL_NORMALIZE)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
        glLightfv(GL_LIGHT0, GL_POSITION, (0.0, 0.0, 1.0, 0.0))
        glEnable(GL_LIGHT0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.display_list = glGenLists(1)
        glNewList(self.display_list, GL_COMPILE)
        glScalef(0.5, 0.5, 0.5)

        glEnable(GL_LIGHTING)

        # board
        glColor3f(0.0, 0.0, 0.0)
        self.draw_cuboid(4.0, 4.0, 0.16)

        # USB connector
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(0.0, -1.6, 0.28)
        self.draw_cuboid(0.75, 0.9, 0.4)
        glPopMatrix()

        # right button
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(1.15, -1.85, 0.16)
        self.draw_cuboid(0.4, 0.3, 0.16)
        glColor3f(0.0, 0.0, 0.0)
        glTranslatef(0.0, -0.155, 0.025)
        self.draw_cuboid(0.18, 0.1, 0.08)
        glPopMatrix()

        # left button
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(-1.15, -1.85, 0.16)
        self.draw_cuboid(0.4, 0.3, 0.16)
        glColor3f(0.0, 0.0, 0.0)
        glTranslatef(0.0, -0.155, 0.025)
        self.draw_cuboid(0.18, 0.1, 0.08)
        glPopMatrix()

        # left btb top
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-1.65, 0.0, 0.38)
        self.draw_cuboid(0.5, 1.4, 0.6)
        glPopMatrix()

        # right btb top
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(1.65, 0.0, 0.38)
        self.draw_cuboid(0.5, 1.4, 0.6)
        glPopMatrix()

        # left btb bottom
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-1.65, 0.0, -0.33)
        self.draw_cuboid(0.5, 1.4, 0.5)
        glPopMatrix()

        # right btb bottom
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(1.65, 0.0, -0.33)
        self.draw_cuboid(0.5, 1.4, 0.5)
        glPopMatrix()

        # left bricklet port
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-0.85, 1.8, -0.23)
        self.draw_cuboid(1.2, 0.4, 0.3)
        glPopMatrix()

        # right bricklet port
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(0.85, 1.8, -0.23)
        self.draw_cuboid(1.2, 0.4, 0.3)
        glPopMatrix()

        # left direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-1.05, 1.425, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # top direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.675, 1.8, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # right direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.3, 1.425, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # bottom direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.675, 1.05, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # left y orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(0.275, 1.7, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # right y orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(0.425, 1.7, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # top z orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(0.35, 1.15, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # bottom z orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(0.35, 1.0, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # top x orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(1.0, 1.15, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # bottom x orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(1.0, 1.0, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # top alignment corner
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glBegin(GL_TRIANGLES)
        glNormal3f(0.0, 0.0, 1.0)
        glVertex3f(-2.0, -2.0, 0.081)
        glVertex3f(-1.1, -2.0, 0.081)
        glVertex3f(-2.0, -1.1, 0.081)
        glEnd()
        glPopMatrix()

        # bottom alignment corner
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glBegin(GL_TRIANGLES)
        glNormal3f(0.0, 0.0, -1.0)
        glVertex3f(-2.0, -2.0, -0.081)
        glVertex3f(-2.0, -1.1, -0.081)
        glVertex3f(-1.1, -2.0, -0.081)
        glEnd()
        glPopMatrix()

        glDisable(GL_LIGHTING)

        # axis
        glPushMatrix()
        glTranslatef(-2.3, -2.3, -0.38)
        glLineWidth(3.0)
        glBegin(GL_LINES)
        glColor3f(1, 0, 0)  # x axis is red
        glVertex3f(0, 0, 0)
        glVertex3f(3, 0, 0)
        glColor3f(0, 0.5, 0)  # y axis is green
        glVertex3f(0, 0, 0)
        glVertex3f(0, 3, 0)
        glColor3f(0, 0, 1)  # z axis is blue
        glVertex3f(0, 0, 0)
        glVertex3f(0, 0, 3)
        glEnd()
        glLineWidth(1.0)
        glPopMatrix()

        glEndList()
コード例 #25
0
    def initializeGL(self):
        """
        Initialize GL
        """

        GL.glClearColor(1., 1., 1., 1.)
        GL.glShadeModel(GL.GL_SMOOTH)
        glEnable(GL.GL_CULL_FACE)
        glEnable(GL.GL_DEPTH_TEST)
        glEnable(GL.GL_LIGHTING)
        lightZeroPosition = [-800., 500., 1500., 1.]
        lightZeroColor = [1.0, 1., 1., 1.0]  #green tinged
        glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, lightZeroPosition)
        glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, lightZeroColor)
        glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, [0.5, 0.5, 0.5, 1.0])

        GL.glLightf(GL.GL_LIGHT0, GL.GL_CONSTANT_ATTENUATION, 1.000)
        #glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.01)
        glEnable(GL.GL_LIGHT0)

        glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, [100., 200., -20., 1.])
        glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, [1., 1., 1., 1.0])
        glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
        glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, [0., 0., 0., 1.0])
        GL.glLightf(GL.GL_LIGHT1, GL.GL_CONSTANT_ATTENUATION, 1)
        #glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, 0.01)
        glEnable(GL.GL_LIGHT1)

        GL.glShadeModel(GL.GL_SMOOTH)
        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()
コード例 #26
0
ファイル: imu_v2_gl_widget.py プロジェクト: fischero19/brickv
    def initializeGL(self):
        glClearColor(0.85, 0.85, 0.85, 1.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glShadeModel(GL_SMOOTH)
        glEnable(GL_NORMALIZE)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)
        glLightfv(GL_LIGHT0, GL_POSITION, (0.0, 0.0, 1.0, 0.0))
        glEnable(GL_LIGHT0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.display_list = glGenLists(1)
        glNewList(self.display_list, GL_COMPILE)
        glScalef(0.5, 0.5, 0.5)

        glEnable(GL_LIGHTING)

        # board
        glColor3f(0.0, 0.0, 0.0)
        self.draw_cuboid(4.0, 4.0, 0.16)

        # USB connector
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(0.0, -1.6, 0.28)
        self.draw_cuboid(0.75, 0.9, 0.4)
        glPopMatrix()

        # right button
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(1.15, -1.85, 0.16)
        self.draw_cuboid(0.4, 0.3, 0.16)
        glColor3f(0.0, 0.0, 0.0)
        glTranslatef(0.0, -0.155, 0.025)
        self.draw_cuboid(0.18, 0.1, 0.08)
        glPopMatrix()

        # left button
        glPushMatrix()
        glColor3f(0.5, 0.51, 0.58)
        glTranslatef(-1.15, -1.85, 0.16)
        self.draw_cuboid(0.4, 0.3, 0.16)
        glColor3f(0.0, 0.0, 0.0)
        glTranslatef(0.0, -0.155, 0.025)
        self.draw_cuboid(0.18, 0.1, 0.08)
        glPopMatrix()

        # left btb top
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-1.65, 0.0, 0.38)
        self.draw_cuboid(0.5, 1.4, 0.9)
        glPopMatrix()

        # right btb top
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(1.65, 0.0, 0.38)
        self.draw_cuboid(0.5, 1.4, 0.9)
        glPopMatrix()

        # left btb bottom
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-1.65, 0.0, -0.33)
        self.draw_cuboid(0.5, 1.4, 0.5)
        glPopMatrix()

        # right btb bottom
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(1.65, 0.0, -0.33)
        self.draw_cuboid(0.5, 1.4, 0.5)
        glPopMatrix()

        # left bricklet port
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(-0.85, 1.8, -0.23)
        self.draw_cuboid(1.2, 0.4, 0.3)
        glPopMatrix()

        # right bricklet port
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glTranslatef(0.85, 1.8, -0.23)
        self.draw_cuboid(1.2, 0.4, 0.3)
        glPopMatrix()

        # left direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-1.05, 1.425, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # top direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.675, 1.8, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # right direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.3, 1.425, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # bottom direction LED
        glPushMatrix()
        glColor3f(0.0, 0.5, 0.0)
        glTranslatef(-0.675, 1.05, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # left y orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(0.275, 1.7, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # right y orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(0.425, 1.7, 0.115)
        self.draw_cuboid(0.1, 0.2, 0.07)
        glPopMatrix()

        # top z orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(0.35, 1.15, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # bottom z orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(0.35, 1.0, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # top x orientation LED
        glPushMatrix()
        glColor3f(1.0, 0.0, 0.0)
        glTranslatef(1.0, 1.15, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # bottom x orientation LED
        glPushMatrix()
        glColor3f(0.0, 0.0, 1.0)
        glTranslatef(1.0, 1.0, 0.115)
        self.draw_cuboid(0.2, 0.1, 0.07)
        glPopMatrix()

        # top alignment corner
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glBegin(GL_TRIANGLES)
        glNormal3f(0.0, 0.0, 1.0)
        glVertex3f(-2.0, -2.0, 0.09)
        glVertex3f(-1.1, -2.0, 0.09)
        glVertex3f(-2.0, -1.1, 0.09)
        glEnd()
        glPopMatrix()

        # bottom alignment corner
        glPushMatrix()
        glColor3f(1.0, 1.0, 1.0)
        glBegin(GL_TRIANGLES)
        glNormal3f(0.0, 0.0, -1.0)
        glVertex3f(-2.0, -2.0, -0.09)
        glVertex3f(-2.0, -1.1, -0.09)
        glVertex3f(-1.1, -2.0, -0.09)
        glEnd()
        glPopMatrix()

        glDisable(GL_LIGHTING)

        # axis
        glPushMatrix()
        glTranslatef(-2.3, -2.3, -0.38)
        glLineWidth(3.0)
        glBegin(GL_LINES)
        glColor3f(1,0,0) # x axis is red
        glVertex3f(0,0,0)
        glVertex3f(3,0,0)
        glColor3f(0,0.5,0) # y axis is green
        glVertex3f(0,0,0)
        glVertex3f(0,3,0)
        glColor3f(0,0,1) # z axis is blue
        glVertex3f(0,0,0)
        glVertex3f(0,0,3)
        glEnd()
        glLineWidth(1.0)
        glPopMatrix()

        glEndList()
コード例 #27
0
ファイル: position_mars_3d.py プロジェクト: xnchu/PyTplot
def position_mars_3d(temp=None):
    '''
    This is a simple 3D window that shows a spacecraft in MSO coordinates.
    This tool will look for links to the tplot variable that are named either "x/y/z" or "mso_(x/y/z)"
    '''

    # Import 3D functionality from opengl
    try:
        import pyqtgraph.opengl as gl
        from pyqtgraph.Qt import QtGui
        from OpenGL.GL import glLightModelfv, glLightfv, GL_LIGHT0, GL_POSITION, \
            GL_LIGHT_MODEL_AMBIENT, GL_LIGHTING, glEnable, GL_COLOR_MATERIAL, \
            GL_AMBIENT, GL_SPECULAR, GL_DIFFUSE, glMaterial, GL_FRONT_AND_BACK, \
            GL_AMBIENT_AND_DIFFUSE, GL_FRONT, glColorMaterial, GL_PROJECTION, \
            glMatrixMode, glLoadIdentity, glTexParameterf
    except:
        raise (
            "In order to use the 3D position viewing tool you must pip install PyOpenGL"
        )

    # Tell Pytplot about new window
    window = pytplot.tplot_utilities.get_available_qt_window(name='3D_MARS')
    window.resize(1000, 600)
    window.setWindowTitle('3D Mars Window')

    # Defining a new class that keeps track of spacecraft position and moves the
    class PlanetView(gl.GLViewWidget):
        spacecraft_x = 0
        spacecraft_y = 0
        spacecraft_z = 0
        tvar_name = 'temp'  # Store the name of the tplot variable stored, so we know if we need to redraw the orbit

        def paintGL(self, region=None, viewport=None, useItemNames=False):
            glLightfv(GL_LIGHT0, GL_POSITION, [-100000, 0, 0, 0])
            super().paintGL(region=region,
                            viewport=viewport,
                            useItemNames=useItemNames)

    plot1 = PlanetView()

    # Set up the "sun"
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [.3, .3, .3, 1.0])
    light_position = [-100000, 0, 0, 0]
    glLightfv(GL_LIGHT0, GL_POSITION, light_position)
    glEnable(GL_LIGHTING)
    glEnable(GL_LIGHT0)
    glEnable(GL_COLOR_MATERIAL)
    glLightfv(GL_LIGHT0, GL_AMBIENT, [1, 1, 1, 0])
    glLightfv(GL_LIGHT0, GL_DIFFUSE, [1, 1, 1, 1])
    glLightfv(GL_LIGHT0, GL_SPECULAR, [1, 0, 0, 0])

    # Create Mars and spacecraft icons (assuming spherical spacecraft)
    md = gl.MeshData.sphere(rows=100, cols=220)
    mars = gl.GLMeshItem(meshdata=md,
                         smooth=True,
                         color=(.5, 0, 0, 1),
                         glOptions='opaque')
    mars.translate(0, 0, 0)
    mars.scale(3390, 3390, 3390)
    spacecraft = gl.GLMeshItem(meshdata=md, smooth=True, color=(1, 1, 1, 1))
    spacecraft.translate(plot1.spacecraft_x, plot1.spacecraft_y,
                         plot1.spacecraft_z)

    spacecraft.scale(200, 200, 200)
    orbit_path = gl.GLLinePlotItem()
    plot1.addItem(mars)
    plot1.addItem(spacecraft)
    plot1.addItem(orbit_path)
    glMaterial(GL_FRONT_AND_BACK, GL_SPECULAR, [.5, .5, .5, 1])
    glEnable(GL_COLOR_MATERIAL)
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)

    # Put the planetview plot into the pytplot window
    window.setCentralWidget(plot1)

    # Move around the camera
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    plot1.setModelview()
    plot1.setCameraPosition(distance=30000, azimuth=0, elevation=0)

    # Turn on the window!
    window.show()

    # Define the function that is called on new hover_time updates
    def update(t, name):
        # Move spacecraft back to 0,0,0
        previous_x = plot1.spacecraft_x
        previous_y = plot1.spacecraft_y
        previous_z = plot1.spacecraft_z
        previous_tvar = plot1.tvar_name

        spacecraft.translate(-1 * previous_x, -1 * previous_y, -1 * previous_z)

        # Get the xarray for x/y/z positions of the spacecraft
        if 'x' in pytplot.data_quants[name].attrs['plot_options']['links']:
            x_tvar = pytplot.data_quants[
                pytplot.data_quants[name].attrs['plot_options']['links']['x']]
            y_tvar = pytplot.data_quants[
                pytplot.data_quants[name].attrs['plot_options']['links']['y']]
            z_tvar = pytplot.data_quants[
                pytplot.data_quants[name].attrs['plot_options']['links']['z']]
        elif 'mso_x' in pytplot.data_quants[name].attrs['plot_options'][
                'links']:
            x_tvar = pytplot.data_quants[pytplot.data_quants[name].attrs[
                'plot_options']['links']['mso_x']]
            y_tvar = pytplot.data_quants[pytplot.data_quants[name].attrs[
                'plot_options']['links']['mso_y']]
            z_tvar = pytplot.data_quants[pytplot.data_quants[name].attrs[
                'plot_options']['links']['mso_z']]
        else:
            return

        if name != previous_tvar:
            import numpy as np
            pathasdf = np.array((x_tvar.data, y_tvar.data, z_tvar.data),
                                dtype=float).T
            orbit_path.setData(pos=pathasdf)

        # Get the nearest x/y/z of the hover time
        new_x = x_tvar.sel(time=t, method='nearest').values
        new_y = y_tvar.sel(time=t, method='nearest').values
        new_z = z_tvar.sel(time=t, method='nearest').values

        # Move the spacecraft
        spacecraft.translate(new_x, new_y, new_z)
        plot1.spacecraft_x, plot1.spacecraft_y, plot1.spacecraft_z = new_x, new_y, new_z
        plot1.tvar_name = name
        plot1.paintGL()

    # Register the above update function to the called functions
    pytplot.hover_time.register_listener(update)

    return