Changeset 378

Show
Ignore:
Timestamp:
11/16/02 01:24:15 (6 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBRapier/RBRapier/Renderer/Geometry/ArrayTraversal.py

    r375 r378  
    4141    'trifan': GL.GL_TRIANGLE_FAN, 
    4242    'tristrip': GL.GL_TRIANGLE_STRIP, 
     43 
     44    'quadlist': GL.GL_QUADS, 
     45    'quadstrip': GL.GL_QUAD_STRIP, 
    4346    } 
    4447 
     
    5356    GL.GL_TRIANGLE_FAN: ('triangles', lambda count: count-2),  
    5457    GL.GL_TRIANGLE_STRIP: ('triangles', lambda count: count-2),  
     58 
     59    GL.GL_QUADS: ('triangles', lambda count: count/2), 
     60    GL.GL_QUAD_STRIP: ('triangles', lambda count: count-2), 
    5561    } 
    5662     
  • trunk/RBRapier/RBRapier/Renderer/Geometry/VertexArrays.py

    r363 r378  
    5959        context.ClientStateMgr.Enable(self._glArrayType) 
    6060 
    61     def Deselct(self, context): 
     61    def Deselect(self, context): 
    6262        context.ClientStateMgr.Disable(self._glArrayType) 
    6363 
  • trunk/RBRapier/RBRapier/Tools/Visualizers/ProjectionBoxes.py

    r371 r378  
    2424#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2525 
     26import Numeric 
     27from OpenGL import GL 
     28from RBRapier.Renderer.Geometry.VertexArrays import VertexArray  
     29from RBRapier.Renderer.Geometry.ArrayTraversal import IndexedCollectionTraversal  
     30 
    2631#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2732#~ Definitions  
    2833#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    2934 
     35class ProjectionBox(object): 
     36    """ 
     37    >>> ProjectionBox()._UpdateBoxVertices() 
     38    array([[-1., -1., -1.], 
     39           [ 1., -1., -1.], 
     40           [ 1.,  1., -1.], 
     41           [-1.,  1., -1.], 
     42           [-1., -1.,  1.], 
     43           [ 1., -1.,  1.], 
     44           [ 1.,  1.,  1.], 
     45           [-1.,  1.,  1.]],'f') 
     46    """ 
    3047 
     48    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     49    #~ Constants / Variables / Etc.  
     50    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     51 
     52    Projection = None 
     53    _BoxTraversal = IndexedCollectionTraversal(GL.GL_LINES, [[0,1, 1,2, 2,3, 3,0,   0,4, 1,5, 2,6, 3,7,   4,5, 5,6, 6,7, 7,4]], Numeric.UInt8) 
     54 
     55    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     56    #~ Public Methods  
     57    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     58 
     59    def __init__(self, projection=None): 
     60        self.Projection = projection 
     61        self._Vertices= VertexArray(Numeric.zeros((8,3), Numeric.Float32)) 
     62 
     63    def Execute(self, context): 
     64        self._UpdateBoxVertices() 
     65        self._Vertices.Select(context) 
     66        self._BoxTraversal.Execute(context) 
     67        self._Vertices.Deselect(context) 
     68 
     69    def _UpdateBoxVertices(self): 
     70        l,r,b,t,n,f = (-1.,1.,-1.,1.,-1.,1.) 
     71        self._Vertices.data[:4] = [(l,b,n), (r,b,n), (r,t,n), (l,t,n)] 
     72        self._Vertices.data[4:] = [(l,b,f), (r,b,f), (r,t,f), (l,t,f)] 
     73        return self._Vertices.data 
     74 
     75    Draw = Execute 
     76 
     77#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     78 
     79class OrthographicBox(ProjectionBox): 
     80    """ 
     81    >>> from RBRapier.Tools.Projections import Orthographic 
     82    >>> OrthographicBox(Orthographic(-1, 1, -1, 1, -1, 1))._UpdateBoxVertices() 
     83    array([[-1., -1., -1.], 
     84           [ 1., -1., -1.], 
     85           [ 1.,  1., -1.], 
     86           [-1.,  1., -1.], 
     87           [-1., -1.,  1.], 
     88           [ 1., -1.,  1.], 
     89           [ 1.,  1.,  1.], 
     90           [-1.,  1.,  1.]],'f') 
     91    """ 
     92 
     93    def _UpdateBoxVertices(self): 
     94        l,r,b,t,n,f = [float(e) for e in self.Projection.asTuple] 
     95        self._Vertices.data[:4] = [(l,b,n), (r,b,n), (r,t,n), (l,t,n)] 
     96        self._Vertices.data[4:] = [(l,b,f), (r,b,f), (r,t,f), (l,t,f)] 
     97        return self._Vertices.data 
     98 
     99#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     100 
     101class FrustumBox(ProjectionBox): 
     102    """ 
     103    >>> from RBRapier.Tools.Projections import Frustum 
     104    >>> FrustumBox(Frustum(-1, 1, -1, 1, 1, 2))._UpdateBoxVertices() 
     105    array([[-1., -1.,  1.], 
     106           [ 1., -1.,  1.], 
     107           [ 1.,  1.,  1.], 
     108           [-1.,  1.,  1.], 
     109           [-2., -2.,  2.], 
     110           [ 2., -2.,  2.], 
     111           [ 2.,  2.,  2.], 
     112           [-2.,  2.,  2.]],'f') 
     113    >>> FrustumBox(Frustum(1, 2, 1, 2, 2, 4))._UpdateBoxVertices() 
     114    array([[ 1.,  1.,  2.], 
     115           [ 2.,  1.,  2.], 
     116           [ 2.,  2.,  2.], 
     117           [ 1.,  2.,  2.], 
     118           [ 2.,  2.,  4.], 
     119           [ 4.,  2.,  4.], 
     120           [ 4.,  4.,  4.], 
     121           [ 2.,  4.,  4.]],'f') 
     122    """ 
     123 
     124    def _UpdateBoxVertices(self): 
     125        l,r,b,t,n,f = [float(e) for e in self.Projection.asTuple] 
     126        self._Vertices.data[:4] = [(l,b,n), (r,b,n), (r,t,n), (l,t,n)] 
     127        scale = f/n 
     128        l = l*scale 
     129        r = r*scale 
     130        b = b*scale 
     131        t = t*scale 
     132        self._Vertices.data[4:] = [(l,b,f), (r,b,f), (r,t,f), (l,t,f)] 
     133        return self._Vertices.data 
     134 
     135#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     136#~ Testing  
     137#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     138 
     139if __name__=='__main__': 
     140    print "Testing..." 
     141    import doctest 
     142    import ProjectionBoxes as _testmod 
     143    doctest.testmod(_testmod) 
     144    print "Test complete." 
     145 
     146