コード例 #1
0
class Lines(object):
    def __init__(self, start=(0,0,0), end=(0,1,0), colorize=(1,1,1,1)):
        view.require_init()
        self.start = start
        self.end = end
        self.texture = BlankTexture()
        self.colorize = colorize

        self.display_list = data.DisplayList()

        self.visible = True
        self.pickable = True
        self.outline = False
        self.outline_size = 4
        self.outline_color=(1,0,0)

        self._compile()

    def get_dimensions(self):
        """Return a tuple of the size of the cube - to be used by the quad tree and collision testing"""
        return abs(self.start[0]-self.end[0]), abs(self.start[1]-self.end[1]), abs(self.start[2]-self.end[2])

    def get_pos(self):
        """Return the position of the quad"""
        return (self.start[0]+self.end[0])*0.5, (self.start[1]+self.end[1])*0.5, (self.start[2]+self.end[2])*0.5

    def _compile(self):
        """Compile the cube's rendering into a data.DisplayList"""
        self.display_list.begin()

        glBegin(GL_LINES)
        glTexCoord2fv((0,0))
        glVertex3f(*self.start)
        glTexCoord2fv((1,01))
        glVertex3f(*self.end)
        glEnd()
        self.display_list.end()

    def render(self, camera=None):
        """Render the cube
           camera is None or the camera object the scene is using to render this object"""
        glPushMatrix()
        glColor(*self.colorize)
        self.texture.bind()
        if self.outline:
            misc.outline(self.display_list, self.outline_color, self.outline_size)
        self.display_list.render()
        glPopMatrix()

    def copy(self):
        """Return a copy of the quad - uses the same display list"""
        n = Lines(self.start, self.end, self.colorize)
        n.display_list = self.display_list
        return n

    def get_scale(self):
        """Return the scale of the object."""
        return 1
コード例 #2
0
ファイル: geometry.py プロジェクト: AjaxVM/pyggel
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, show_inside=False,
                 detail=10):
        """Create the Sphere
           size is the radius of the Sphere
           pos ithe position of the sphere
           rotation is the rotation of the sphere
           colorize is the color of the sphere
           texture can be None, a string filename of an image to load or a data.Texture object that will be mapped to the sphere
           show_inside indicates whether the inside of the sphere is rendered or not
           detail is the size of each section - lower = smoother/slower"""
        BaseSceneObject.__init__(self)

        self.size = size
        self.pos = pos
        self.rotation = rotation
        self.colorize = colorize
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.scale = 1
        self.detail = detail

        self.show_inside = show_inside

        self.display_list = data.DisplayList()

        self._compile()
コード例 #3
0
ファイル: geometry.py プロジェクト: AjaxVM/team-pp-pyweek9
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, detail=30):
        """Create the Sphere
           size is the radius of the Sphere
           pos ithe position of the sphere
           rotation is the rotation of the sphere
           colorize is the color of the sphere
           texture can be None, a string filename of an image to load or a data.Texture object that will be mapped to the sphere
           detail is the level of detail for the Sphere, higher = a more smooth sphere"""
        BaseSceneObject.__init__(self)

        self.size = size
        self.pos = pos
        self.rotation = rotation
        self.colorize = colorize
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.detail = detail
        self.scale = 1

        self.display_list = data.DisplayList()

        self._compile()
コード例 #4
0
    def __init__(self, start=(0,0,0), end=(0,1,0), colorize=(1,1,1,1)):
        view.require_init()
        self.start = start
        self.end = end
        self.texture = BlankTexture()
        self.colorize = colorize

        self.display_list = data.DisplayList()

        self.visible = True
        self.pickable = True
        self.outline = False
        self.outline_size = 4
        self.outline_color=(1,0,0)

        self._compile()
コード例 #5
0
ファイル: geometry.py プロジェクト: AjaxVM/pyggel
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, hide_faces=[]):
        BaseSceneObject.__init__(self)

        self.hide_faces = hide_faces

        self.size = size
        self.pos = pos
        self.rotation = rotation
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.colorize = colorize

        self.scale = 1

        self.display_list = data.DisplayList()

        self._compile()
コード例 #6
0
ファイル: geometry.py プロジェクト: AjaxVM/pyggel
class Pyramid(BaseSceneObject):
    """A geometric pyramid that can be colored and textured"""
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, hide_faces=[]):
        BaseSceneObject.__init__(self)

        self.hide_faces = hide_faces

        self.size = size
        self.pos = pos
        self.rotation = rotation
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.colorize = colorize

        self.scale = 1

        self.display_list = data.DisplayList()

        self._compile()

    def _compile(self):
        """Compile the cube's rendering into a data.DisplayList"""
        self.display_list.begin()

        top = (0,0.5,0)
        bottomleft = (-math.sqrt(3)*0.25,-0.5,0.25)
        bottomright = (math.sqrt(3)*0.25,-0.5,0.25)
        bottomback = (0,-0.5,-0.5)

        tpoints = [[bottomleft,bottomright,bottomback],
                   [top, bottomleft, bottomright],
                   [top, bottomright, bottomback],
                   [top, bottomback, bottomleft]]

        ttp = []
        if not "bottom" in self.hide_faces:
            ttp.append(tpoints[0])
        if not "front" in self.hide_faces:
            ttp.append(tpoints[1])
        if not "right" in self.hide_faces:
            ttp.append(tpoints[2])
        if not "left" in self.hide_faces:
            ttp.append(tpoints[3])

        glBegin(GL_TRIANGLES)
        for i in ttp:
            coords = ((0.5,1), (0,0), (1,0))

            glNormal3f(*math3d.calcTriNormal(i[0],i[1],i[2],False))

            for p in xrange(3):
                glTexCoord2fv(coords[p])
                glVertex3f(*i[p])
        glEnd()

        self.display_list.end()

    def render(self, camera=None):
        """Render the cube
           camera is None or the camera object the scene is using to render this object"""
        glPushMatrix()
        x, y, z = self.pos
        glTranslatef(x, y, -z)
        a, b, c = self.rotation
        glRotatef(a, 1, 0, 0)
        glRotatef(b, 0, 1, 0)
        glRotatef(c, 0, 0, 1)
        glScalef(self.size,self.size,self.size)
        try:
            glScalef(*self.scale)
        except:
            glScalef(self.scale, self.scale, self.scale)
        glColor(*self.colorize)
        self.texture.bind()
        if self.outline:
            misc.outline(self.display_list, self.outline_color, self.outline_size)
        self.display_list.render()
        glPopMatrix()
コード例 #7
0
ファイル: geometry.py プロジェクト: AjaxVM/pyggel
class Sphere(BaseSceneObject):
    """A geometric Sphere object that can be colored and textured"""
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, show_inside=False,
                 detail=10):
        """Create the Sphere
           size is the radius of the Sphere
           pos ithe position of the sphere
           rotation is the rotation of the sphere
           colorize is the color of the sphere
           texture can be None, a string filename of an image to load or a data.Texture object that will be mapped to the sphere
           show_inside indicates whether the inside of the sphere is rendered or not
           detail is the size of each section - lower = smoother/slower"""
        BaseSceneObject.__init__(self)

        self.size = size
        self.pos = pos
        self.rotation = rotation
        self.colorize = colorize
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.scale = 1
        self.detail = detail

        self.show_inside = show_inside

        self.display_list = data.DisplayList()

        self._compile()

    def get_dimensions(self):
        """Return a three part tuple of the radius of the sphere - used in teh quadtree and collision testing"""
        return self.size, self.size, self.size

    def get_pos(self):
        """Return the position of the sphere"""
        return self.pos

    def _compile(self):
        self.display_list.begin()

        verts = []
        texcs = []
        norms = []

        space=self.detail

        for b in xrange(0, 180, space):
            b *= 1.0
            for a in xrange(0, 360, space):
                a *= 1.0
                _v = []
                _t = []
                for i in xrange(2):
                    for j in xrange(2):
                        s1 = space*i
                        s2 = space*j
                        x=self.size * math.sin(math3d.safe_div(a+s1, 180)*math.pi) * math.sin(math3d.safe_div(b+s2, 180)*math.pi)
                        z=self.size * math.cos(math3d.safe_div(a+s1, 180)*math.pi) * math.sin(math3d.safe_div(b+s2, 180)*math.pi)
                        y=self.size * math.cos(math3d.safe_div(b+s2, 180)*math.pi)
                        u=math3d.safe_div(a+s1,360)
                        v=math3d.safe_div(b+s2,360)
                        _v.append((x,y,z))
                        _t.append((u,1-v*2))
                verts.extend([_v[0], _v[1], _v[3], _v[0], _v[3], _v[2]])
                texcs.extend([_t[0], _t[1], _t[3], _t[0], _t[3], _t[2]])
                norms.extend([math3d.calcTriNormal(*verts[-6:-3])]*3)
                norms.extend([math3d.calcTriNormal(*verts[-3::])]*3)
                if self.show_inside:
                    verts.extend(reversed(verts[-6::]))
                    texcs.extend(reversed(texcs[-6::]))
                    norms.extend([math3d.calcTriNormal(*verts[-6:-3])]*3)
                    norms.extend([math3d.calcTriNormal(*verts[-3::])]*3)
        glBegin(GL_TRIANGLES)
        for i in xrange(len(verts)):
            u,v = texcs[i]
            glTexCoord2f(u,v)
            glNormal3f(*norms[i])
            x,y,z = verts[i]
            glVertex3f(x,y,z)
        glEnd()
        self.display_list.end()

    def render(self, camera=None):
        """Render the Sphere
           camera can be None or the camera object the scene is using"""
        glPushMatrix()
        x, y, z = self.pos
        glTranslatef(x, y, -z)
        a, b, c = self.rotation
        glRotatef(a, 1, 0, 0)
        glRotatef(b, 0, 1, 0)
        glRotatef(c, 0, 0, 1)
        try:
            glScalef(*self.scale)
        except:
            glScalef(self.scale, self.scale, self.scale)
        glColor(*self.colorize)
        self.texture.bind()
        if self.outline:
            misc.outline(self.display_list, self.outline_color, self.outline_size)
        self.display_list.render()
        glPopMatrix()

    def copy(self):
        """Return a copy of the Sphere - sharing the same display list"""
        n = Sphere(self.size, self.pos, self.colorize, self.texture, self.detail)
        n.scale = self.scale
        n.display_list = self.display_list
        return n

    def get_scale(self):
        """Return the scale of the object."""
        try: return self.scale[0], self.scale[1], self.scale[2]
        except: return self.scale, self.scale, self.scale
コード例 #8
0
ファイル: geometry.py プロジェクト: AjaxVM/pyggel
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, mirror=True,
                 hide_faces=[]):
        """Create a cube
           size is the absolute size of the cube
           pos is the position of the cube
           rotation is the rotation of the cube
           colorize is the color of the cube (0-1 RGBA)
           texture can be None, a data.Texture object or a string representing the filename of a texture to load
           mirror indicates whether each face of the cube has the full texture on it (so each is identicle) or
               if True, each face will have the entire texture mapped to it
               if False, the Texture is considered a cube map, like this:
                   blank, blank, top, blank,
                   back, left, front, right,
                   blank, blank, bottom, blank
           hide_faces must be a list of the sides of the cube not to add:
               acceptable values are left, right, top, bottom, back, front"""
        BaseSceneObject.__init__(self)

        self.hide_faces = hide_faces

        self.size = size
        self.pos = pos
        self.rotation = rotation
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.colorize = colorize

        self.mirror = mirror

        self.corners = ((-1, -1, 1),#topleftfront
                      (1, -1, 1),#toprightfront
                      (1, 1, 1),#bottomrightfront
                      (-1, 1, 1),#bottomleftfront
                      (-1, -1, -1),#topleftback
                      (1, -1, -1),#toprightback
                      (1, 1, -1),#bottomrightback
                      (-1, 1, -1))#bottomleftback

        sides = ((7,4,0,3, 2, 2, 5),#left
                      (2,1,5,6, 3, 4, 4),#right
                      (7,3,2,6, 5, 0, 3),#top
                      (0,4,5,1, 4, 5, 2),#bottom
                      (3,0,1,2, 0, 1, 0),#front
                      (6,5,4,7, 1, 3, 1))#back
        self.sides = []
        if not "left" in hide_faces:
            self.sides.append(sides[0])
        if not "right" in hide_faces:
            self.sides.append(sides[1])
        if not "top" in hide_faces:
            self.sides.append(sides[2])
        if not "bottom" in hide_faces:
            self.sides.append(sides[3])
        if not "front" in hide_faces:
            self.sides.append(sides[4])
        if not "back" in hide_faces:
            self.sides.append(sides[5])
        self.normals = ((0, 0, 1), #front
                        (0, 0, -1), #back
                        (0, -1, 0), #top
                        (0, 1, 0), #bottom
                        (1, 0, 0), #right
                        (-1, 0, 0)) #left

        self.split_coords = ((2,2),#top
                             (0,1),#back
                             (1,1),#left
                             (2,1),#front
                             (3,1),#right
                             (2,0))#bottom

        self.scale = 1

        self.display_list = data.DisplayList()

        self._compile()
コード例 #9
0
ファイル: geometry.py プロジェクト: AjaxVM/pyggel
class Cube(BaseSceneObject):
    """A geometric cube that can be colored and textured"""
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, mirror=True,
                 hide_faces=[]):
        """Create a cube
           size is the absolute size of the cube
           pos is the position of the cube
           rotation is the rotation of the cube
           colorize is the color of the cube (0-1 RGBA)
           texture can be None, a data.Texture object or a string representing the filename of a texture to load
           mirror indicates whether each face of the cube has the full texture on it (so each is identicle) or
               if True, each face will have the entire texture mapped to it
               if False, the Texture is considered a cube map, like this:
                   blank, blank, top, blank,
                   back, left, front, right,
                   blank, blank, bottom, blank
           hide_faces must be a list of the sides of the cube not to add:
               acceptable values are left, right, top, bottom, back, front"""
        BaseSceneObject.__init__(self)

        self.hide_faces = hide_faces

        self.size = size
        self.pos = pos
        self.rotation = rotation
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.colorize = colorize

        self.mirror = mirror

        self.corners = ((-1, -1, 1),#topleftfront
                      (1, -1, 1),#toprightfront
                      (1, 1, 1),#bottomrightfront
                      (-1, 1, 1),#bottomleftfront
                      (-1, -1, -1),#topleftback
                      (1, -1, -1),#toprightback
                      (1, 1, -1),#bottomrightback
                      (-1, 1, -1))#bottomleftback

        sides = ((7,4,0,3, 2, 2, 5),#left
                      (2,1,5,6, 3, 4, 4),#right
                      (7,3,2,6, 5, 0, 3),#top
                      (0,4,5,1, 4, 5, 2),#bottom
                      (3,0,1,2, 0, 1, 0),#front
                      (6,5,4,7, 1, 3, 1))#back
        self.sides = []
        if not "left" in hide_faces:
            self.sides.append(sides[0])
        if not "right" in hide_faces:
            self.sides.append(sides[1])
        if not "top" in hide_faces:
            self.sides.append(sides[2])
        if not "bottom" in hide_faces:
            self.sides.append(sides[3])
        if not "front" in hide_faces:
            self.sides.append(sides[4])
        if not "back" in hide_faces:
            self.sides.append(sides[5])
        self.normals = ((0, 0, 1), #front
                        (0, 0, -1), #back
                        (0, -1, 0), #top
                        (0, 1, 0), #bottom
                        (1, 0, 0), #right
                        (-1, 0, 0)) #left

        self.split_coords = ((2,2),#top
                             (0,1),#back
                             (1,1),#left
                             (2,1),#front
                             (3,1),#right
                             (2,0))#bottom

        self.scale = 1

        self.display_list = data.DisplayList()

        self._compile()

    def get_dimensions(self):
        """Return a tuple of the size of the cube - to be used by the quad tree and collision testing"""
        return self.size, self.size, self.size

    def get_pos(self):
        """Return the position of the quad"""
        return self.pos

    def _compile(self):
        """Compile the cube's rendering into a data.DisplayList"""
        self.display_list.begin()

        ox = .25
        oy = .33
        last_tex = None

        glBegin(GL_QUADS)
        for i in self.sides:
            ix = 0
            x, y = self.split_coords[i[5]]
            x *= ox
            y *= oy
            if self.mirror:
                coords = ((1,1), (1,0), (0,0), (0,1))
            else:
                coords = ((x+ox, y+oy), (x+ox, y), (x, y), (x, y+oy))

            glNormal3f(*self.normals[i[6]])

            for x in i[:4]:
                glTexCoord2fv(coords[ix])
                a, b, c = self.corners[x]
                glVertex3f(a,b,c)
                ix += 1
        glEnd()
        self.display_list.end()

    def render(self, camera=None):
        """Render the cube
           camera is None or the camera object the scene is using to render this object"""
        glPushMatrix()
        x, y, z = self.pos
        glTranslatef(x, y, -z)
        a, b, c = self.rotation
        glRotatef(a, 1, 0, 0)
        glRotatef(b, 0, 1, 0)
        glRotatef(c, 0, 0, 1)
        glScalef(.5*self.size,.5*self.size,.5*self.size)
        try:
            if not self.scale == (1,1,1):
                glScalef(*self.scale)
        except:
            if not self.scale == 1:
                glScalef(self.scale, self.scale, self.scale)
        glColor(*self.colorize)
        self.texture.bind()
        if self.outline:
            misc.outline(self.display_list, self.outline_color, self.outline_size)
        self.display_list.render()
        glPopMatrix()

    def copy(self):
        """Return a copy of the quad - uses the same display list"""
        n = Cube(self.size, self.pos, self.rotation, self.colorize, self.texture, self.mirror, self.hide_faces)
        n.display_list = self.display_list
        n.scale = self.scale
        return n

    def get_scale(self):
        """Return the scale of the object."""
        try: return self.scale[0], self.scale[1], self.scale[2]
        except: return self.scale, self.scale, self.scale
コード例 #10
0
ファイル: geometry.py プロジェクト: AjaxVM/team-pp-pyweek9
class Sphere(BaseSceneObject):
    """A geometric Sphere object that can be colored and textured"""
    def __init__(self, size, pos=(0,0,0), rotation=(0,0,0),
                 colorize=(1,1,1,1), texture=None, detail=30):
        """Create the Sphere
           size is the radius of the Sphere
           pos ithe position of the sphere
           rotation is the rotation of the sphere
           colorize is the color of the sphere
           texture can be None, a string filename of an image to load or a data.Texture object that will be mapped to the sphere
           detail is the level of detail for the Sphere, higher = a more smooth sphere"""
        BaseSceneObject.__init__(self)

        self.size = size
        self.pos = pos
        self.rotation = rotation
        self.colorize = colorize
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        else:
            self.texture = BlankTexture()
        self.detail = detail
        self.scale = 1

        self.display_list = data.DisplayList()

        self._compile()

    def get_dimensions(self):
        """Return a three part tuple of the radius of the sphere - used in teh quadtree and collision testing"""
        return self.size, self.size, self.size

    def get_pos(self):
        """Return the position of the sphere"""
        return self.pos

    def _compile(self):
        """Compile the Sphere into a data.DisplayList"""
        self.display_list.begin()
        #Pyweek change - set rotation for faces to be correct!
        glRotatef(-90,1,0,0)
        Sphere = gluNewQuadric()
        gluQuadricTexture(Sphere, GLU_TRUE)
        gluSphere(Sphere, 1, self.detail, self.detail)
        self.display_list.end()

    def render(self, camera=None):
        """Render the Sphere
           camera can be None or the camera object the scene is using"""
        glPushMatrix()
        x, y, z = self.pos
        glTranslatef(x, y, -z)
        a, b, c = self.rotation
        glRotatef(a, 1, 0, 0)
        glRotatef(b, 0, 1, 0)
        glRotatef(c, 0, 0, 1)
        glScalef(self.size, self.size, self.size)
        try:
            glScalef(*self.scale)
        except:
            glScalef(self.scale, self.scale, self.scale)
        glColor(*self.colorize)
        self.texture.bind()
        if self.outline:
            misc.outline(self.display_list, self.outline_color, self.outline_size)
        self.display_list.render()
        glPopMatrix()

    def copy(self):
        """Return a copy of the Sphere - sharing the same display list"""
        n = Sphere(self.size, self.pos, self.colorize, self.texture, self.detail)
        n.scale = self.scale
        n.display_list = self.display_list
        return n

    def get_scale(self):
        """Return the scale of the object."""
        try: return self.scale[0], self.scale[1], self.scale[2]
        except: return self.scale, self.scale, self.scale