Exemplo n.º 1
0
 def compile_total_list(self):
     if self.total_list is not None:
         glNewList(self.total_list, GL_COMPILE)
         # reset a few things
         glDisable(GL_DEPTH_TEST)
         glDisable(GL_LIGHTING)
         glMatrixMode(GL_PROJECTION)
         glLoadIdentity()
         glMatrixMode(GL_MODELVIEW)
         glLoadIdentity()
         # change the modelview to camera coordinates
         viewport = glGetIntegerv(GL_VIEWPORT)
         width = viewport[2] - viewport[0]
         height = viewport[3] - viewport[1]
         if width > height:
             w = float(width) / float(height)
             h = 1.0
         else:
             w = 1.0
             h = float(height) / float(width)
         glScalef(2/w, 2/h, 1.0)
         glCallList(self.draw_list)
         glEnable(GL_DEPTH_TEST)
         glEnable(GL_LIGHTING)
         glEndList()
Exemplo n.º 2
0
    def prepare_for_rendering(self, projector: Projector, camera: Camera,
                              lights: List[Light]):
        """Selects the window, clears buffers, and sets up the scene transform and lighting state.

        :param projector: The projector configuration to use for this rendering pass.
        :param camera: The camera object to use for this rendering pass.
        :param lights: The light list to use for this rendering pass.
        """
        glutSetWindow(self._gl_window)

        # Clear the screen and the depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Apply our projection so the window is ready to render in perspective
        projector.apply(self)

        # Add scene lights
        light_count = len(lights)
        for i in range(light_count):
            lights[i].apply(i)

        # Set scale from mm to cm
        glScalef(0.1, 0.1, 0.1)

        # Orient the camera
        camera.apply()
Exemplo n.º 3
0
    def draw(self):
        # background
        set_color(*self.style['bg-color'])
        drawCSSRectangle(size=self.size, style=self.style)

        # content dynamic update
        with gx_matrix:
            glTranslatef(self.style['margin'][3], self.style['margin'][2], 0)

            # draw precalculated background
            self._current_cache['background'].draw()

            # draw active keys layer
            # +2 and -4 result of hard margin coded in _do_update (m = 3 * s)
            # we substract 1 cause of border (draw-border is activated.)
            set_color(*self.style['color-down'])
            for key, size in self._active_keys:
                x, y, w, h = size
                drawCSSRectangle(pos=(x+2, y+2), size=(w-4, h-4),
                    style=self.style, prefix='key', state='down')

            # search the good scale for current precalculated keys layer
            if self._last_update_scale == self.scale:
                s = 1. / self.scale# / self._last_update_scale
                glScalef(s, s, s)
            else:
                s = 1. / self._last_update_scale
                glScalef(s, s, s)
            self._current_cache['keys'].draw()
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    def draw(self):
        # background
        set_color(*self.style['bg-color'])
        drawCSSRectangle(size=self.size, style=self.style)

        # content dynamic update
        with gx_matrix:
            glTranslatef(self.style['margin'][3], self.style['margin'][2], 0)

            # draw precalculated background
            self._current_cache['background'].draw()

            # draw active keys layer
            # +2 and -4 result of hard margin coded in _do_update (m = 3 * s)
            # we substract 1 cause of border (draw-border is activated.)
            set_color(*self.style['color-down'])
            for key, size in self._active_keys:
                x, y, w, h = size
                drawCSSRectangle(pos=(x+2, y+2), size=(w-4, h-4),
                    style=self.style, prefix='key', state='down')

            # search the good scale for current precalculated keys layer
            if self._last_update_scale == self.scale:
                s = 1. / self.scale# / self._last_update_scale
                glScalef(s, s, s)
            else:
                s = 1. / self._last_update_scale
                glScalef(s, s, s)
            self._current_cache['keys'].draw()
Exemplo n.º 7
0
 def compile_total_list(self):
     if self.total_list is not None:
         glNewList(self.total_list, GL_COMPILE)
         # reset a few things
         glDisable(GL_DEPTH_TEST)
         glDisable(GL_LIGHTING)
         glMatrixMode(GL_PROJECTION)
         glLoadIdentity()
         glMatrixMode(GL_MODELVIEW)
         glLoadIdentity()
         # change the modelview to camera coordinates
         viewport = glGetIntegerv(GL_VIEWPORT)
         width = viewport[2] - viewport[0]
         height = viewport[3] - viewport[1]
         if width > height:
             w = float(width) / float(height)
             h = 1.0
         else:
             w = 1.0
             h = float(height) / float(width)
         glScalef(2 / w, 2 / h, 1.0)
         glCallList(self.draw_list)
         glEnable(GL_DEPTH_TEST)
         glEnable(GL_LIGHTING)
         glEndList()
Exemplo n.º 8
0
    def reshape_function(self, w, h):

        # prevent dividing by zero if window height is 0
        if h == 0:
            h = 1

        self.window_width = w
        self.window_height = h

        proportional_rate = float(w) / h

        glViewport(0, 0, w, h)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluPerspective(60.0, proportional_rate, 0.1, 100)

        camera_settings_matrix = [0 for i in range(9)]

        # calculate camera's point of view
        camera_settings_matrix = self.recalculate_camera_settings(
            camera_settings_matrix)

        # set camera's point of view
        gluLookAt(camera_settings_matrix[0], camera_settings_matrix[1],
                  camera_settings_matrix[2], camera_settings_matrix[3],
                  camera_settings_matrix[4], camera_settings_matrix[5],
                  camera_settings_matrix[6], camera_settings_matrix[7],
                  camera_settings_matrix[8])

        glScalef(self.scale_factor, self.scale_factor, self.scale_factor)

        glMatrixMode(GL_MODELVIEW)
Exemplo n.º 9
0
def traverse(node):
    '''
    '''
    def rotate():
        if len(node.rotate) != 4:

            for r in node.rotate:
                glRotatef(*r)
        else:
            glRotatef(*node.rotate)

    glPushMatrix()
    if isinstance(node, Object3D):

        glTranslatef(*node.translate)
        if node.rotation_points is not None:

            glTranslatef(*node.rotation_points[0])
            rotate()
            glTranslatef(*node.rotation_points[1])

        else:
            rotate()

        glScalef(*node.scale)
        node.render()

    for b in node.branches:
        traverse(b)

    glPopMatrix()
Exemplo n.º 10
0
    def draw(self, x, y, z=0, angle=0, scale=1):
        """Draws the SVG to screen.

        :Parameters
            `x` : float
                The x-coordinate at which to draw.
            `y` : float
                The y-coordinate at which to draw.
            `z` : float
                The z-coordinate at which to draw. Defaults to 0. Note that z-ordering may not
                give expected results when transparency is used.
            `angle` : float
                The angle by which the image should be rotated (in degrees). Defaults to 0.
            `scale` : float
                The amount by which the image should be scaled, either as a float, or a tuple
                of two floats (xscale, yscale).

        """
        glPushMatrix()
        glTranslatef(x, y, z)
        if angle:
            glRotatef(angle, 0, 0, 1)
        if scale != 1:
            try:
                glScalef(scale[0], scale[1], 1)
            except TypeError:
                glScalef(scale, scale, 1)
        if self._a_x or self._a_y:
            glTranslatef(-self._a_x, -self._a_y, 0)
        glCallList(self.disp_list)
        glPopMatrix()
Exemplo n.º 11
0
    def draw(self, x, y, z=0, angle=0, scale=1):
        """Draws the SVG to screen.

        :Parameters
            `x` : float
                The x-coordinate at which to draw.
            `y` : float
                The y-coordinate at which to draw.
            `z` : float
                The z-coordinate at which to draw. Defaults to 0. Note that z-ordering may not
                give expected results when transparency is used.
            `angle` : float
                The angle by which the image should be rotated (in degrees). Defaults to 0.
            `scale` : float
                The amount by which the image should be scaled, either as a float, or a tuple
                of two floats (xscale, yscale).

        """
        glPushMatrix()
        glTranslatef(x, y, z)
        if angle:
            glRotatef(angle, 0, 0, 1)
        if scale != 1:
            try:
                glScalef(scale[0], scale[1], 1)
            except TypeError:
                glScalef(scale, scale, 1)
        if self._a_x or self._a_y:
            glTranslatef(-self._a_x, -self._a_y, 0)
        glCallList(self.disp_list)
        glPopMatrix()
Exemplo n.º 12
0
    def InitGL(self, Width, Height):
        self.view_port_xr = 1
        self.view_port_yr = 1
        self.original_x = Width
        self.original_y = Height

        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity()
        glOrtho(0, Width, 0, Height, -1, 1)
        glScalef(1, -1, 1)
        glTranslatef(0, -Height, 0)
        glMatrixMode(GL_MODELVIEW)
        glDisable(GL_DEPTH_TEST)  # Disables Depth Testing
        glShadeModel(GL_SMOOTH)  # Enables Smooth Color Shading

        # Anti-aliasing/prettyness stuff
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)
        glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
        glHint(GL_POINT_SMOOTH_HINT, GL_NICEST)
        glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
        glEnable(GL_LINE_SMOOTH)
        glEnable(GL_POINT_SMOOTH)
        glEnable(GL_POLYGON_SMOOTH)
        glClearColor(background_color()[0],
                     background_color()[1],
                     background_color()[2], 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
Exemplo n.º 13
0
 def iniciar_renderizado(self):
     """Acciones posteriores al renderizado de objetos."""
     self.fbos[0].usar()
     #glClearColor(*self.capa.escena.color)#0.) para fondo transparente
     glClear(GL_COLOR_BUFFER_BIT) #| GL_DEPTH_BUFFER_BIT)
     # Transformación de la cámara
     glLoadIdentity()
     glScalef(self.acerc, self.acerc, 0.)
     glTranslatef(-self.pos.x, -self.pos.y, 0.)
     glRotatef(-self.angulo, 0., 0., 1.)
Exemplo n.º 14
0
    def draw(self, from_fixed_frame: bool = True):
        self.opgl_move_to_pose(from_fixed_frame)
        self.apply_material()

        # draw parallelepiped
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        glScalef(self.length, self.width, self.height)
        glutSolidCube(1)
Exemplo n.º 15
0
    def draw(self, from_fixed_frame: bool = True):
        self.opgl_move_to_pose(from_fixed_frame)
        self.apply_material()

        # draw parallelepiped
        quad = gluNewQuadric()
        gluQuadricDrawStyle(quad, GLU_FILL)
        gluQuadricTexture(quad, True)
        gluQuadricNormals(quad, GLU_SMOOTH)
        glScalef(self.length, self.width, self.height)
        glutSolidCube(1)
Exemplo n.º 16
0
    def render(self):
        '''
        '''
        super(Sector, self).render()

        glPushMatrix()

        glScalef(3, 5, 5)
        self._set_material()
        self._cube_()

        glPopMatrix()
Exemplo n.º 17
0
 def DrawPlot(self):
     """Plots the curves for all sensors in self.sensors"""
     glPushMatrix()
     # TODO the following is "moving away from frame",
     # and should use the framedata (plastic, etc.)
     # from the GuiObject base class.
     # Probably this stuff should be done in GuiObject!
     glTranslatef(0.005, 0.01, 0.0)
     glScalef(0.99 / self.resolution, 0.7 / self.maxValue, 1.0)
     for sensorInfo, data in zip(self.sensors, self.history):
         glColor3f(*(sensorInfo["color"]))
         data.Draw()
     glPopMatrix()
Exemplo n.º 18
0
Arquivo: graph.py Projeto: reims/wesen
 def DrawPlot(self):
     """Plots the curves for all sensors in self.sensors"""
     glPushMatrix()
     # TODO the following is "moving away from frame",
     # and should use the framedata (plastic, etc.)
     # from the GuiObject base class.
     # Probably this stuff should be done in GuiObject!
     glTranslatef(0.005, 0.01, 0.0)
     glScalef(0.99 / self.resolution, 0.7 / self.maxValue, 1.0)
     for sensorInfo, data in zip(self.sensors, self.history):
         glColor3f(*(sensorInfo["color"]))
         data.Draw()
     glPopMatrix()
Exemplo n.º 19
0
    def render(self):
        glTranslatef(self.position.x, self.position.y, 0.0)
        glRotatef(self.rotation, 0.0, 0.0, 1.0)
        glScalef(self.scale.x, self.scale.y, 0.0)

        for child in self._children:
            glPushMatrix()

            child.render()

            glPopMatrix()

        self.draw()
Exemplo n.º 20
0
    def on_resize(self, width, height):
        '''Event called when the window is resized'''
        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glFrustum(-width / 2, width / 2, -height / 2, height / 2, .1, 1000)
        glScalef(5000, 5000, 1)
        glTranslatef(-width / 2, -height / 2, -500)
        glMatrixMode(GL_MODELVIEW)

        for w in self.children:
            shw, shh = w.size_hint
            if shw and shh:
                w.size = shw * width, shh * height
            elif shw:
                w.width = shw * width
            elif shh:
                w.height = shh * height
Exemplo n.º 21
0
 def __draw(self, widget, event):
     x = self.__distance * sin(self.__angle)
     z = self.__distance * cos(self.__angle)
     gldrawable = widget.get_gl_drawable()
     glcontext = widget.get_gl_context()
     # OpenGL begin.
     if not gldrawable.gl_begin(glcontext):
         return
     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glLoadIdentity ()
     gluLookAt(x, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)  
     #==========================
     glPushMatrix()
     glLineWidth(3)
     glRotatef(self.__arm_angles[0], 1., 0., 0.)
     glRotatef(self.__arm_angles[1], 0., 1., 0.)
     glRotatef(self.__arm_angles[2], 0., 0., 1.)
     glTranslatef(self.__upper_arm, 0., 0.)
     #==========================
     glPushMatrix()
     glColor3f(30./255., 126./255., 30./255.)
     glScalef(self.__upper_arm, 0.4, 1.0)
     self.__draw_cube()       # shoulder
     glPopMatrix()
     #==========================
     glTranslatef(self.__upper_arm, 0., 0.)
     glRotatef(self.__arm_angles[3] , 0., 0., 1.)
     glTranslatef(self.__forearm, 0., 0.)
     glPushMatrix()
     #==========================
     glScalef(self.__forearm, 0.3, 0.75)
     glColor3f(126./255., 30./255., 30./255.)
     self.__draw_cube()      # elbow
     glPopMatrix()
     glPopMatrix()
     #==========================
     if gldrawable.is_double_buffered():
         gldrawable.swap_buffers()
     else:
         glFlush()
     gldrawable.gl_end()
     # OpenGL end
     return
Exemplo n.º 22
0
    def drawGround(self):
        GROUND_SIZE = 1000
        glColor3f(0.9, 0.9, 0.9)
        glPushAttrib(GL_POLYGON_BIT)
        glEnable(GL_POLYGON_OFFSET_FILL)
        glPolygonOffset(2.0, 2.0)

        glDisable(GL_COLOR_MATERIAL)
        glPushMatrix()
        glTranslatef(0, 0, 0)
        glScalef(GROUND_SIZE, GROUND_SIZE, 1.0)
        glBegin(GL_QUADS)
        glVertex2d(1, 1)
        glVertex2d(1, -1)
        glVertex2d(-1, -1)
        glVertex2d(-1, 1)
        glEnd()
        glPopMatrix()
        glPopAttrib()
Exemplo n.º 23
0
    def display(self, pose: util.Pose):
        """Displays the precomputed view at a specific pose in 3d space.

        :param pose: Where to display the cube.
        """
        glPushMatrix()

        # TODO if cube_pose.is_accurate is False, render half-translucent?
        #  (This would require using a shader, or having duplicate objects)

        cube_matrix = pose.to_matrix()
        glMultMatrixf(cube_matrix.in_row_order)

        # Cube is drawn slightly larger than the 10mm to 1 cm scale, as the model looks small otherwise
        cube_scale_amt = 10.7
        glScalef(cube_scale_amt, cube_scale_amt, cube_scale_amt)

        self.display_all()
        glPopMatrix()
Exemplo n.º 24
0
    def display(self, pose: util.Pose, head_angle: util.Angle,
                lift_position: util.Distance):
        """Displays the precomputed view at a specific pose in 3d space.

        :param pose: Where to display the robot.
        """
        if not self._display_lists:
            return

        robot_matrix = pose.to_matrix()
        head_angle_degrees = head_angle.degrees

        # Get the angle of Vector's lift for rendering - we subtract the angle
        # of the lift in the default pose in the object, and apply the inverse
        # rotation
        sin_angle = (lift_position.distance_mm -
                     LIFT_PIVOT_HEIGHT_MM) / LIFT_ARM_LENGTH_MM
        angle_radians = math.asin(sin_angle)

        lift_angle = -(angle_radians - LIFT_ANGLE_IN_DEFAULT_POSE)
        lift_angle_degrees = math.degrees(lift_angle)

        glPushMatrix()
        glEnable(GL_LIGHTING)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)

        glMultMatrixf(robot_matrix.in_row_order)

        robot_scale_amt = 10.0  # cm to mm
        glScalef(robot_scale_amt, robot_scale_amt, robot_scale_amt)
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

        self._display_vector_body()
        self._display_vector_lift(lift_angle_degrees)
        self._display_vector_head(head_angle_degrees)

        glDisable(GL_LIGHTING)
        glPopMatrix()
Exemplo n.º 25
0
def display():
    start_point = (
        start_picture_coord[0] * HEIGHT * mosaic_factory.ratio / (args.tiles - 1),
        start_picture_coord[1] * HEIGHT / (args.tiles - 1)
    )
    center = (HEIGHT * mosaic_factory.ratio / 2., HEIGHT / 2.)
    reverse_sigmoid_progress = fake_sigmoid(1 - progress)
    sigmoid_progress = 1 - reverse_sigmoid_progress
    max_zoom = args.tiles
    zoom = max_zoom ** reverse_sigmoid_progress
    angle = start_orientation + sigmoid_progress * angle_difference(
        current_mosaic_picture.orientation,
        start_orientation
    )
    if reverse_sigmoid_progress > 0.1:
        alpha = 1.0
    else:
        alpha = reverse_sigmoid_progress * 10.0

    glClear(GL_COLOR_BUFFER_BIT)
    glPushMatrix()

    glTranslatef(center[0], center[1], 0.0)
    glRotatef(angle, 0, 0, 1)
    glTranslatef(-center[0], -center[1], 0.0)

    glTranslatef(start_point[0], start_point[1], 0.0)
    glScalef(zoom, zoom, 1.0)
    glTranslatef(-start_point[0], -start_point[1], 0.0)

    glColor4f(0.0, 0.0, 0.0, alpha)
    glCallList(mosaic_display_lists[current_mosaic_picture])
    glColor4f(0.0, 0.0, 0.0, 1.0 - alpha)

    glScalef(max_zoom, max_zoom, 1.0)
    glCallList(picture_display_lists[current_mosaic_picture])

    glPopMatrix()
    glutSwapBuffers()
Exemplo n.º 26
0
    def render(self):
        '''
        '''
        super(IonPump, self).render()
        pumpheight = 3
        pumpwidth = 2
        pumplength = 4

        glPushMatrix()

        self._set_material()

        h = 0.75
        glPushMatrix()
        glTranslatef(pumpwidth / 4.0, pumpheight / 2.0 + h, 0)
        self._cylinder_(0.5, h)
        glPopMatrix()

        h = 0.5
        glPushMatrix()
        glTranslatef(pumpwidth / 4.0, pumpheight / 2.0 + 1.5 - h, 0)
        self._can_(radius=0.75, height=h)
        glPopMatrix()

        h = pumpheight / 2.0 + 0.75
        h2 = 10.5
        points = [(pumpwidth / 4.0, h, 0),
                (pumpwidth / 4.0, h, 0),
                (pumpwidth / 4.0, h + 2, 0),
                (0, h2 - 2, 0), (0, h2, 0), (0, h2, 0)]

        self._tube_(points, self.color, radius=0.45)

        glScalef(pumplength, pumpheight, pumpwidth)

        self._cube_()

        glPopMatrix()
Exemplo n.º 27
0
    def update_viewport(self):
        width, height = self.system_size
        w2 = width / 2.0
        h2 = height / 2.0

        # prepare the viewport
        glViewport(0, 0, width, height)

        # set the projection
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glFrustum(-w2, w2, -h2, h2, 0.1, 1000)
        glScalef(5000, 5000, 1)

        # use the rotated size.
        width, height = self.size
        w2 = width / 2.0
        h2 = height / 2.0
        glTranslatef(-w2, -h2, -500)

        # set the model view
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glTranslatef(w2, h2, 0)
        glRotatef(self._rotation, 0, 0, 1)
        glTranslatef(-w2, -h2, 0)

        # update window size
        for w in self.children:
            shw, shh = w.size_hint
            if shw and shh:
                w.size = shw * width, shh * height
            elif shw:
                w.width = shw * width
            elif shh:
                w.height = shh * height
Exemplo n.º 28
0
def display():
    start_point = (start_picture_coord[0] * HEIGHT * mosaic_factory.ratio /
                   (args.tiles - 1),
                   start_picture_coord[1] * HEIGHT / (args.tiles - 1))
    center = (HEIGHT * mosaic_factory.ratio / 2., HEIGHT / 2.)
    reverse_sigmoid_progress = fake_sigmoid(1 - progress)
    sigmoid_progress = 1 - reverse_sigmoid_progress
    max_zoom = args.tiles
    zoom = max_zoom**reverse_sigmoid_progress
    angle = start_orientation + sigmoid_progress * angle_difference(
        current_mosaic_picture.orientation, start_orientation)
    if reverse_sigmoid_progress > 0.1:
        alpha = 1.0
    else:
        alpha = reverse_sigmoid_progress * 10.0

    glClear(GL_COLOR_BUFFER_BIT)
    glPushMatrix()

    glTranslatef(center[0], center[1], 0.0)
    glRotatef(angle, 0, 0, 1)
    glTranslatef(-center[0], -center[1], 0.0)

    glTranslatef(start_point[0], start_point[1], 0.0)
    glScalef(zoom, zoom, 1.0)
    glTranslatef(-start_point[0], -start_point[1], 0.0)

    glColor4f(0.0, 0.0, 0.0, alpha)
    glCallList(mosaic_display_lists[current_mosaic_picture])
    glColor4f(0.0, 0.0, 0.0, 1.0 - alpha)

    glScalef(max_zoom, max_zoom, 1.0)
    glCallList(picture_display_lists[current_mosaic_picture])

    glPopMatrix()
    glutSwapBuffers()
Exemplo n.º 29
0
    def update_viewport(self):
        width, height = self.system_size
        w2 = width / 2.
        h2 = height / 2.

        # prepare the viewport
        glViewport(0, 0, width, height)

        # set the projection
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glFrustum(-w2, w2, -h2, h2, .1, 1000)
        glScalef(5000, 5000, 1)

        # use the rotated size.
        width, height = self.size
        w2 = width / 2.
        h2 = height / 2.
        glTranslatef(-w2, -h2, -500)

        # set the model view
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glTranslatef(w2, h2, 0)
        glRotatef(self._rotation, 0, 0, 1)
        glTranslatef(-w2, -h2, 0)

        # update window size
        for w in self.children:
            shw, shh = w.size_hint
            if shw and shh:
                w.size = shw * width, shh * height
            elif shw:
                w.width = shw * width
            elif shh:
                w.height = shh * height
Exemplo n.º 30
0
def scale(x=0.0, y=0.0, z=0.0):
    glScalef(x, y, z)
Exemplo n.º 31
0
 def draw_cuboid(self, x, y, z):
     glPushMatrix()
     glScalef(x, y, z) # size cuboid
     self.cube()
     glPopMatrix()
Exemplo n.º 32
0
    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()
Exemplo n.º 33
0
 def draw_cuboid(self, x, y, z):
     glPushMatrix()
     glScalef(x, y, z)  # size cuboid
     self.cube()
     glPopMatrix()
Exemplo n.º 34
0
    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()
Exemplo n.º 35
0
shaders.glUseProgram(shaderProg)

points = vbo.VBO(data=imgnp,
                 usage="GL_DYNAMIC_DRAW",
                 target='GL_ARRAY_BUFFER',
                 size=None)
points.bind()

modelmat = glGetUniformLocation(shaderProg, 'model')
viewmat = glGetUniformLocation(shaderProg, 'view')
projectionmat = glGetUniformLocation(shaderProg, 'projection')

glPushMatrix()
glRotatef(-90, 0, 0, 1)

scal = 0.01
glTranslatef(-0.5, -0.5, 0)
glScalef(1 / imgnp.shape[0], 1 / imgnp.shape[1], 1)
model2 = glGetDoublev(GL_MODELVIEW_MATRIX)
glPopMatrix()
# print(model2)

glUniformMatrix4fv(modelmat, 1, GL_FALSE, model2)

glutDisplayFunc(draw_points)

# glutInitWindowPosition(600, 100)
# wind2 = glutCreateWindow("OpenGL Window2")
# glutMouseFunc(moveMouse)
glutMainLoop()
Exemplo n.º 36
0
def mirror_y():
    glScalef(1.0, -1.0, 1.0)
Exemplo n.º 37
0
 def resize(w, h):
     glViewport(0, 0, w, h)
     glLoadIdentity()
     glTranslatef(-1 , 1, 0)
     glScalef(2 / w, -2 / h, 1)
     pass
Exemplo n.º 38
0
    def _render_world_frame(self, world_frame: opengl_vector.WorldRenderFrame):
        """Render the world to the current OpenGL context

        :param world_frame: frame to render
        """
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        glEnable(GL_NORMALIZE)  # to re-scale scaled normals

        light_cube_view = self._vector_view_manifest.light_cube_view
        unit_cube_view = self._vector_view_manifest.unit_cube_view
        robot_view = self._vector_view_manifest.robot_view
        nav_map_view = self._vector_view_manifest.nav_map_view

        robot_frame = world_frame.robot_frame
        robot_pose = robot_frame.pose

        try:
            glDisable(GL_LIGHTING)
            nav_map_view.display()

            glEnable(GL_LIGHTING)
            # Render the cube
            for obj in world_frame.cube_frames:
                cube_pose = obj.pose
                if cube_pose is not None and cube_pose.is_comparable(
                        robot_pose):
                    light_cube_view.display(cube_pose)

            # Render the custom objects
            for obj in world_frame.custom_object_frames:
                obj_pose = obj.pose
                if obj_pose is not None and obj_pose.is_comparable(robot_pose):
                    glPushMatrix()
                    obj_matrix = obj_pose.to_matrix()
                    glMultMatrixf(obj_matrix.in_row_order)

                    glScalef(obj.x_size_mm * 0.5, obj.y_size_mm * 0.5,
                             obj.z_size_mm * 0.5)

                    # Only draw solid object for observable custom objects

                    if obj.is_fixed:
                        # fixed objects are drawn as transparent outlined boxes to make
                        # it clearer that they have no effect on vision.
                        FIXED_OBJECT_COLOR = [1.0, 0.7, 0.0, 1.0]
                        unit_cube_view.display(FIXED_OBJECT_COLOR, False)
                    else:
                        CUSTOM_OBJECT_COLOR = [1.0, 0.3, 0.3, 1.0]
                        unit_cube_view.display(CUSTOM_OBJECT_COLOR, True)

                    glPopMatrix()

            glBindTexture(GL_TEXTURE_2D, 0)

            for face in world_frame.face_frames:
                face_pose = face.pose
                if face_pose is not None and face_pose.is_comparable(
                        robot_pose):
                    glPushMatrix()
                    face_matrix = face_pose.to_matrix()
                    glMultMatrixf(face_matrix.in_row_order)

                    # Approximate size of a head
                    glScalef(100, 25, 100)

                    FACE_OBJECT_COLOR = [0.5, 0.5, 0.5, 1.0]
                    draw_solid = face.time_since_last_seen < 30
                    unit_cube_view.display(FACE_OBJECT_COLOR, draw_solid)

                    glPopMatrix()
        except BaseException as e:
            self._logger.error('rendering error: {0}'.format(e))

        glDisable(GL_LIGHTING)

        # Draw the Vector robot to the screen
        robot_view.display(robot_frame.pose, robot_frame.head_angle,
                           robot_frame.lift_position)

        if self.show_controls:
            self._draw_controls(world_frame.cube_connected(),
                                world_frame.cube_connecting())
Exemplo n.º 39
0
def mirror_x():
    glScalef(-1.0, 1.0, 1.0)
Exemplo n.º 40
0
 def scale(cls, x: float, y: float, z: float):
     glScalef(x, y, z)