Esempio n. 1
0
def create_octahedron(color=None):
    """
    Crates an octahedron.

    :param color: Octahedron color
    :type color: list
    :return: OpenGL list
    """
    obj = _gl.glGenLists(1)
    _gl.glNewList(obj, _gl.GL_COMPILE)
    _gl.glPushMatrix()
    if color is not None:
        _gl.glColor4fv(color)
    # noinspection PyBroadException
    try:
        _glut.glutSolidOctahedron()
    except:
        if not _FIGURES_ERRS[7]:
            _print_gl_error(
                'OpenGL actual version does not support glutSolidOctahedron function'
            )
        _FIGURES_ERRS[7] = True
    _gl.glPopMatrix()
    _gl.glEndList()
    return obj
Esempio n. 2
0
    def paintGL(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        _array = galaxy.\
                celaArray_frompointer(self._galaxy.\
                                      output())
        if self._trace >= 0:
            self._dx = _array[self._trace].p.x * self._scale_factor
            self._dy = _array[self._trace].p.y * self._scale_factor
            self._dz = _array[self._trace].p.z * self._scale_factor
            if self._trace_v:
                self._phi, self._theta = self._get_angle_by_v(_array[self._trace].v)
            self.setCamera()
            
        gl.glColor(*self._planec)
        step = self._planes / float(self._celld)
        gl.glBegin(gl.GL_LINES)
        for i in xrange(2 * self._celld):
            gl.glVertex(- self._planes + i*step,
                        - self._planes)
            gl.glVertex(- self._planes + i*step,
                        self._planes - step)
        for i in xrange(2 * self._celld):
            gl.glVertex(- self._planes,
                        - self._planes + i*step)
            gl.glVertex(self._planes - step,
                        - self._planes + i*step)

        gl.glEnd()
        if self._axisl > 0:
            gl.glColor(*self._axisc)
            gl.glBegin(gl.GL_LINES)
            gl.glVertex(0,0,0)
            gl.glVertex((self._axisl+1) * step, 0 ,0)
            gl.glEnd()
            gl.glPushMatrix()
            gl.glTranslate(self._axisl * step, 0, 0)
            gl.glRotate(90, 0, 1, 0)
            glut.glutWireCone(step / 4, step , 8, 8)
            gl.glPopMatrix()

            gl.glBegin(gl.GL_LINES)
            gl.glVertex(0,0,0)
            gl.glVertex(0,(self._axisl+1) * step, 0)
            gl.glEnd()
            gl.glPushMatrix()
            gl.glTranslate(0, self._axisl * step, 0)
            gl.glRotate(-90, 1, 0, 0)
            glut.glutWireCone(step / 4, step , 8, 8)
            gl.glPopMatrix()

            gl.glBegin(gl.GL_LINES)
            gl.glVertex(0,0,0)
            gl.glVertex(0,0,(self._axisl+1) * step)
            gl.glEnd()
            gl.glPushMatrix()
            gl.glTranslate(0,0,self._axisl * step)
            glut.glutWireCone(step / 4, step , 8, 8)
            gl.glPopMatrix()

        for i in xrange(self._n):
            graphic = self._graphic[i]

            if "color" in graphic:
                gl.glColor(*graphic["color"])
            else:
                gl.glColor(*self._planec)

            if "style" in graphic:
                style = graphic["style"]
            else:
                style = self._dstyle
                
            if style == "solid":
                drawfunc = glut.glutSolidSphere
            else:
                drawfunc = glut.glutWireSphere
                
            gl.glPushMatrix()
            gl.glTranslate(_array[i].p.x,
                           _array[i].p.y,
                           _array[i].p.z)
            drawfunc(graphic["radius"], 16, 16)
            if i == self._trace:
                gl.glColor(0.0,1.0,0.0)
                
                gl.glScale(graphic["radius"],graphic["radius"],graphic["radius"])
                gl.glTranslate(0 ,0, 3)
                glut.glutSolidOctahedron()
                gl.glColor(1.0,1.0,1.0) 
                glut.glutWireOctahedron()
            gl.glPopMatrix()
            if self._trace_line and (self._trace == i or self._trace == - 1 ) :
                if self._timer.isActive():
                    self._trace_buffer[i].append(_array[i].p.x)
                    self._trace_buffer[i].append(_array[i].p.y)
                    self._trace_buffer[i].append(_array[i].p.z)
                    if len(self._trace_buffer[i]) > self._trace_buffer_size:
                        self._trace_buffer[i].pop(0)
                        self._trace_buffer[i].pop(0)
                        self._trace_buffer[i].pop(0)
                gl.glBegin(gl.GL_LINE_STRIP)
                line_step = 3 * self._line_int
                num = len(self._trace_buffer[i]) / line_step
                for j in xrange(num):
                    if self._shadow:
                        color = [float(k) / num * j for k in self._axisc]
                    else:
                        color = self._axisc
                    gl.glColor(*color)
                    gl.glVertex(self._trace_buffer[i][j * line_step],
                                self._trace_buffer[i][j * line_step+ 1],
                                self._trace_buffer[i][j * line_step+ 2])
                gl.glEnd()
Esempio n. 3
0
    def paintGL(self):
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        _array = galaxy.\
                celaArray_frompointer(self._galaxy.\
                                      output())
        if self._trace >= 0:
            self._dx = _array[self._trace].p.x * self._scale_factor
            self._dy = _array[self._trace].p.y * self._scale_factor
            self._dz = _array[self._trace].p.z * self._scale_factor
            if self._trace_v:
                self._phi, self._theta = self._get_angle_by_v(
                    _array[self._trace].v)
            self.setCamera()

        gl.glColor(*self._planec)
        step = self._planes / float(self._celld)
        gl.glBegin(gl.GL_LINES)
        for i in xrange(2 * self._celld):
            gl.glVertex(-self._planes + i * step, -self._planes)
            gl.glVertex(-self._planes + i * step, self._planes - step)
        for i in xrange(2 * self._celld):
            gl.glVertex(-self._planes, -self._planes + i * step)
            gl.glVertex(self._planes - step, -self._planes + i * step)

        gl.glEnd()
        if self._axisl > 0:
            gl.glColor(*self._axisc)
            gl.glBegin(gl.GL_LINES)
            gl.glVertex(0, 0, 0)
            gl.glVertex((self._axisl + 1) * step, 0, 0)
            gl.glEnd()
            gl.glPushMatrix()
            gl.glTranslate(self._axisl * step, 0, 0)
            gl.glRotate(90, 0, 1, 0)
            glut.glutWireCone(step / 4, step, 8, 8)
            gl.glPopMatrix()

            gl.glBegin(gl.GL_LINES)
            gl.glVertex(0, 0, 0)
            gl.glVertex(0, (self._axisl + 1) * step, 0)
            gl.glEnd()
            gl.glPushMatrix()
            gl.glTranslate(0, self._axisl * step, 0)
            gl.glRotate(-90, 1, 0, 0)
            glut.glutWireCone(step / 4, step, 8, 8)
            gl.glPopMatrix()

            gl.glBegin(gl.GL_LINES)
            gl.glVertex(0, 0, 0)
            gl.glVertex(0, 0, (self._axisl + 1) * step)
            gl.glEnd()
            gl.glPushMatrix()
            gl.glTranslate(0, 0, self._axisl * step)
            glut.glutWireCone(step / 4, step, 8, 8)
            gl.glPopMatrix()

        for i in xrange(self._n):
            graphic = self._graphic[i]

            if "color" in graphic:
                gl.glColor(*graphic["color"])
            else:
                gl.glColor(*self._planec)

            if "style" in graphic:
                style = graphic["style"]
            else:
                style = self._dstyle

            if style == "solid":
                drawfunc = glut.glutSolidSphere
            else:
                drawfunc = glut.glutWireSphere

            gl.glPushMatrix()
            gl.glTranslate(_array[i].p.x, _array[i].p.y, _array[i].p.z)
            drawfunc(graphic["radius"], 16, 16)
            if i == self._trace:
                gl.glColor(0.0, 1.0, 0.0)

                gl.glScale(graphic["radius"], graphic["radius"],
                           graphic["radius"])
                gl.glTranslate(0, 0, 3)
                glut.glutSolidOctahedron()
                gl.glColor(1.0, 1.0, 1.0)
                glut.glutWireOctahedron()
            gl.glPopMatrix()
            if self._trace_line and (self._trace == i or self._trace == -1):
                if self._timer.isActive():
                    self._trace_buffer[i].append(_array[i].p.x)
                    self._trace_buffer[i].append(_array[i].p.y)
                    self._trace_buffer[i].append(_array[i].p.z)
                    if len(self._trace_buffer[i]) > self._trace_buffer_size:
                        self._trace_buffer[i].pop(0)
                        self._trace_buffer[i].pop(0)
                        self._trace_buffer[i].pop(0)
                gl.glBegin(gl.GL_LINE_STRIP)
                line_step = 3 * self._line_int
                num = len(self._trace_buffer[i]) / line_step
                for j in xrange(num):
                    if self._shadow:
                        color = [float(k) / num * j for k in self._axisc]
                    else:
                        color = self._axisc
                    gl.glColor(*color)
                    gl.glVertex(self._trace_buffer[i][j * line_step],
                                self._trace_buffer[i][j * line_step + 1],
                                self._trace_buffer[i][j * line_step + 2])
                gl.glEnd()