Beispiel #1
0
    def set_default_light(self):
        default_ambiant = 0.22
        LightDiffuse = [ \
                1.0 - default_ambiant, 1.0 - default_ambiant,
                1.0 - default_ambiant, 1.0]
        LightAmbiant = [0, 0, 0, 1.0]
        LightSpecular = [1.0, 1.0, 1.0, 1.0]
        LightAmbiantScene = [
            default_ambiant, default_ambiant, default_ambiant, 1.0
        ]

        # Needed because when passing light infos : The position is transformed by the
        # modelview matrix when glLight is called (just as if it were a point), and it
        # is stored in eye coordinates.  If the w component of the position is 0.0, the
        # light is treated as a directional source.
        #
        # Save model view
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()

        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0)

        # Facial light - LIGHT 1
        look = [0., 0., -1.]
        quat = common_quaternion_from_angles(30., 30., 0.)
        v = multiply_point_by_matrix(quaternion_to_matrix(quat), look)
        light0Pos = map(lambda x: x * -1., v)  # * -1

        matShine = 60.00
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, matShine)
        glLightfv(GL_LIGHT0, GL_POSITION, light0Pos)
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightAmbiantScene)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse)
        glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular)
        glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbiant)
        glEnable(GL_LIGHT0)

        if True:
            # Opposite light - LIGHT 2
            matShine = 60.00
            light1Pos = [-0.7, -0.7, -0.7, 0.00]
            LightDiffuse = [1.0, 1.0, 1.0, 1.0]

            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, matShine)
            glLightfv(GL_LIGHT1, GL_POSITION, light1Pos)
            glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse)
            glLightfv(GL_LIGHT1, GL_SPECULAR, LightDiffuse)
            glEnable(GL_LIGHT1)

        glEnable(GL_COLOR_MATERIAL)
        glEnable(GL_LIGHTING)
        glShadeModel(GL_SMOOTH)

        # restore modelview
        glPopMatrix()
Beispiel #2
0
    def set_matrix(self, v):
        '''
        To debug this, make sure gluPerspective and gluLookAt have
        the same parameter when given the same mouse events in cpp and in python
        '''

        ############
        # Projection
        glMatrixMode( GL_PROJECTION )
        glLoadIdentity()

        pixel_ratio = self.w / float(self.h)
        zF = v.focal / 30.0

        diam2 = 2.0 * self.scene.bb.sphere_beam()

        look = sub(v.tget, v.eye)
        diam = 0.5 * norm(look)
        recul = 2 * diam

        zNear = 0.01 * recul # 1% du segment de visee oeil-cible
        zFar = recul + diam2

        if pixel_ratio < 1:
            zF /= pixel_ratio

        logger.info('gluPerspective %f %f %f %f' % (zF*30, pixel_ratio, zNear, zFar))
        gluPerspective (zF*30, pixel_ratio, zNear, zFar)
        # For debug: hard-coded values for some models
        #gluPerspective ( 32, 1.34, 27, 54 ) # Gears
        #gluPerspective ( 32, 1.44, 204, 409 ) # spaceship

        ############
        # Model View
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        glTranslatef(v.recenterX, v.recenterY, 0.0)

        # Take care of the eye
        rotation_matrix = quaternion_to_matrix(v.quat)
        new_look = [0, 0, recul] # LOL name
        v.eye = multiply_point_by_matrix(rotation_matrix, new_look)
        v.eye = add(v.eye, self.scene.bb.center())

        # Vector UP (Y)
        vup_t = multiply_point_by_matrix(rotation_matrix, [0.0, 1.0, 0.0])
        logger.info('gluLookAt eye  %s' % str(v.eye))
        logger.info('gluLookAt tget %s' % str(v.tget))
        logger.info('gluLookAt vup  %s' % str(vup_t))

        gluLookAt (	v.eye[0], v.eye[1], v.eye[2],
                    v.tget[0], v.tget[1], v.tget[2],
                    vup_t[0], vup_t[1], vup_t[2] )
Beispiel #3
0
    def set_default_light(self):
        default_ambiant = 0.22
        LightDiffuse = [ \
                1.0 - default_ambiant, 1.0 - default_ambiant, 
                1.0 - default_ambiant, 1.0]
        LightAmbiant      = [ 0, 0, 0, 1.0 ];
        LightSpecular     = [ 1.0, 1.0, 1.0, 1.0 ]
        LightAmbiantScene = [ default_ambiant, default_ambiant, default_ambiant, 1.0 ]

        # Needed because when passing light infos : The position is transformed by the
        # modelview matrix when glLight is called (just as if it were a point), and it
        # is stored in eye coordinates.  If the w component of the position is 0.0, the
        # light is treated as a directional source. 
        #
        # Save model view
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()

        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 1.0)

        # Facial light - LIGHT 1
        look = [0.,0.,-1.]
        quat = common_quaternion_from_angles(30.,30.,0.)
        v = multiply_point_by_matrix(quaternion_to_matrix(quat), look)
        light0Pos = map(lambda x: x * -1., v) # * -1

        matShine = 60.00
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, matShine)
        glLightfv(GL_LIGHT0, GL_POSITION, light0Pos)
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightAmbiantScene)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse)
        glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular)
        glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbiant)
        glEnable(GL_LIGHT0)

        if True:
            # Opposite light - LIGHT 2
            matShine = 60.00
            light1Pos = [ -0.7, -0.7, -0.7, 0.00 ]
            LightDiffuse = [1.0, 1.0, 1.0, 1.0]

            glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, matShine)
            glLightfv(GL_LIGHT1, GL_POSITION, light1Pos)
            glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse)
            glLightfv(GL_LIGHT1, GL_SPECULAR, LightDiffuse)
            glEnable(GL_LIGHT1)

        glEnable(GL_COLOR_MATERIAL)
        glEnable(GL_LIGHTING)
        glShadeModel(GL_SMOOTH)

        # restore modelview
        glPopMatrix()
Beispiel #4
0
    def set_matrix(self, v):
        '''
        To debug this, make sure gluPerspective and gluLookAt have
        the same parameter when given the same mouse events in cpp and in python
        '''

        ############
        # Projection
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        pixel_ratio = self.w / float(self.h)
        zF = v.focal / 30.0

        diam2 = 2.0 * self.scene.bb.sphere_beam()

        look = sub(v.tget, v.eye)
        diam = 0.5 * norm(look)
        recul = 2 * diam

        zNear = 0.01 * recul  # 1% du segment de visee oeil-cible
        zFar = recul + diam2

        if pixel_ratio < 1:
            zF /= pixel_ratio

        logger.info('gluPerspective %f %f %f %f' %
                    (zF * 30, pixel_ratio, zNear, zFar))
        gluPerspective(zF * 30, pixel_ratio, zNear, zFar)
        # For debug: hard-coded values for some models
        #gluPerspective ( 32, 1.34, 27, 54 ) # Gears
        #gluPerspective ( 32, 1.44, 204, 409 ) # spaceship

        ############
        # Model View
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        glTranslatef(v.recenterX, v.recenterY, 0.0)

        # Take care of the eye
        rotation_matrix = quaternion_to_matrix(v.quat)
        new_look = [0, 0, recul]  # LOL name
        v.eye = multiply_point_by_matrix(rotation_matrix, new_look)
        v.eye = add(v.eye, self.scene.bb.center())

        # Vector UP (Y)
        vup_t = multiply_point_by_matrix(rotation_matrix, [0.0, 1.0, 0.0])
        logger.info('gluLookAt eye  %s' % str(v.eye))
        logger.info('gluLookAt tget %s' % str(v.tget))
        logger.info('gluLookAt vup  %s' % str(vup_t))

        gluLookAt(v.eye[0], v.eye[1], v.eye[2], v.tget[0], v.tget[1],
                  v.tget[2], vup_t[0], vup_t[1], vup_t[2])
Beispiel #5
0
    def reset(self, _bb):
        self.recenterX = 0.0
        self.recenterY = 0.0
        self.focal = 32.0
        self.quat = common_quaternion_from_angles(180, 45 + 22.5, 0)
        self.quat = [-0.23, 0.40, 0.090, 0.88]

        recul = 1.5 * _bb.sphere_beam()
        if False:  # try to mimic cpp but that does not work
            look = [0.0, 0.0, recul]
            self.eye = point_by_matrix(quaternion_to_matrix(self.quat), look)
            self.tget = look

        # Using sub(_bb.min(), [recul, recul, recul]) has the same effects
        self.eye = add([recul, recul, recul], _bb.max())
        self.tget = _bb.center()
Beispiel #6
0
    def reset(self, _bb):
        self.recenterX = 0.0
        self.recenterY = 0.0
        self.focal = 32.0
        self.quat = common_quaternion_from_angles(180, 45+22.5, 0 )
        self.quat = [-0.23, 0.40, 0.090, 0.88]

        recul = 1.5 * _bb.sphere_beam()
        if False: # try to mimic cpp but that does not work
            look = [0.0, 0.0, recul]
            self.eye = point_by_matrix(quaternion_to_matrix(self.quat), look)
            self.tget = look

        # Using sub(_bb.min(), [recul, recul, recul]) has the same effects
        self.eye = add([recul, recul, recul], _bb.max())
        self.tget = _bb.center()