Changeset 704

Show
Ignore:
Timestamp:
09/16/03 16:12:35 (5 years ago)
Author:
sholloway
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/RBRapier/RBRapier/Renderer/Environment/FragmentTests.py

    r702 r704  
    2525 
    2626from OpenGL import GL 
    27 from RBRapier.Tools import RectangleBase 
     27 
     28from RBFoundation.Objects.Properties import LazyProperty 
     29from RBRapier.Tools import ViewBox 
    2830from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 
    2931 
     
    3234#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3335 
    34 class ScissorTest(RectangleBase.RectangleBase): 
     36class ScissorTest(object): 
    3537    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3638    #~ Constants / Variables / Etc.  
     
    3840 
    3941    AttributeChange = AttributeChangeElement(GL.GL_SCISSOR_BIT) 
     42    Box = LazyProperty(ViewBox) 
    4043 
    4144    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4447 
    4548    def GLSelect(self, context): 
    46         GL.glScissor(*self.Rectangle) 
     49        rectangle = map(int, self.Box.GetRectangle()) 
     50        GL.glScissor(*rectangle) 
    4751        context.StateMgr.Enable(GL.GL_SCISSOR_TEST) 
    4852 
  • trunk/RBRapier/RBRapier/Renderer/View/Transformations.py

    r703 r704  
    2727from RBRapier.Tools import Projections 
    2828from RBRapier.Tools import Quaternion 
    29 from RBRapier.Tools import RectangleBase 
     29from RBRapier.Tools import ViewBox 
    3030 
    3131from Numeric import transpose 
    3232from OpenGL import GL, GLU 
     33 
     34try: 
     35    GL.GL_COLOR_MATRIX 
     36except AttributeError: 
     37    GL.GL_COLOR_MATRIX = 0x80B1 
    3338 
    3439#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    4853    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    4954 
    50     _ModeNameTable = {None:"< None >", GL.GL_MODELVIEW:"Model View", GL.GL_PROJECTION:"Projection", GL.GL_TEXTURE_MATRIX:"Texture", GL.GL_COLOR:"Color"} 
     55    _ModeNameTable = {None:"< None >", GL.GL_MODELVIEW:"Model View", GL.GL_PROJECTION:"Projection", GL.GL_TEXTURE:"Texture", GL.GL_COLOR:"Color"} 
     56    _SaveMatrixLookup = { 
     57        None: GL.GL_MODELVIEW_MATRIX, 
     58        GL.GL_MODELVIEW: GL.GL_MODELVIEW_MATRIX, 
     59        GL.GL_PROJECTION: GL.GL_PROJECTION_MATRIX, 
     60        GL.GL_TEXTURE: GL.GL_TEXTURE_MATRIX, 
     61        GL.GL_COLOR: GL.GL_COLOR_MATRIX, 
     62        } 
    5163    Mode = None 
    5264    Save = 0 
     
    6779        if self.Mode:  
    6880            GL.glMatrixMode(self.Mode) 
     81            if self.Save: 
     82                self._SaveMatrix() 
     83            self.GLExecute(context) 
     84            GL.glMatrixMode(GL.GL_MODELVIEW) 
     85        elif self.Save: 
    6986            self._SaveMatrix() 
    7087            self.GLExecute(context) 
    71             GL.glMatrixMode(GL.GL_MODELVIEW) 
    7288        else: 
    73             self._SaveMatrix() 
    7489            self.GLExecute(context) 
    7590 
     
    86101        try: 
    87102            GL.glPushMatrix() 
    88         except GL.GLerror: 
    89             self._save_matrix = GL.glGetDouble(Gl.GL_MODELVIEW_MATRIX) 
     103        except GL.GLerror, e: 
     104            self._save_matrix = GL.glGetDouble(self._SaveMatrixLookup[self.Mode]) 
     105    #_SaveMatrix = staticmethod(GL.glPushMatrix) 
    90106 
    91107    def _RestoreMatrix(self): 
     
    96112            GL.glLoadMatrixd(oldmatrix) 
    97113            del self._save_matrix 
     114    #_RestoreMatrix = staticmethod(GL.glPopMatrix) 
    98115 
    99116#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    169186    pass 
    170187 
    171 class RectangleMappingMatrix(RectangleBase.RectangleMappingMatrix3dh): 
    172     GLExecute = GLExecuteAsMatrix 
    173  
    174 class RectangleMappingMatrixMgd(ManagedTransformationMixin, RectangleMappingMatrix): 
     188class ViewBoxMappingMatrix(ViewBox.ViewBoxMappingMatrix3dh): 
     189    GLExecute = GLExecuteAsMatrix 
     190 
     191class ViewBoxMappingMatrixMgd(ManagedTransformationMixin, ViewBoxMappingMatrix): 
    175192    pass 
    176193 
  • trunk/RBRapier/RBRapier/Renderer/View/Viewport.py

    r702 r704  
    2525 
    2626from OpenGL import GL 
    27 from RBRapier.Tools import RectangleBase 
     27from RBRapier.Tools import ViewBox 
    2828from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 
    2929 
     
    3232#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3333 
    34 class Viewport(RectangleBase.RectangleBase): 
     34class Viewport(ViewBox.ViewBox): 
    3535    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    3636    #~ Constants / Variables / Etc.  
     
    4444 
    4545    def GLExecute(self, context): 
    46         GL.glViewport(*self.Rectangle) 
     46        rectangle = map(int, self.GetRectangle()) 
     47        GL.glViewport(*rectangle) 
    4748 
  • trunk/RBRapier/RBRapier/Tools/RectangleBase.py

    r703 r704  
    109109 
    110110    def GetBox(self): 
    111         x, y, w, h = self.Rectangle() 
     111        x, y, w, h = self.GetRectangle() 
    112112        return (x, y), (x+w, y+h) 
    113113    def SetBox(self, box): 
     
    122122 
    123123    def GetRectangle(self):  
    124         return self.Rectangle 
     124        return map(float, self.Rectangle) 
    125125    def SetRectangle(self, *args):  
    126126        if len(args) == 1: args = args[0] 
     
    128128 
    129129    def MapPointTo(self, point, *args, **kw): 
    130         return self.MapPoints([point], *args, **kw) 
     130        return self.MapPointsTo([point], *args, **kw)[0] 
    131131 
    132132    def MapPointsTo(self, points, xspan=(-1., 1.), yspan=None, flipx=False, flipy=False): 
     
    140140 
    141141    def MapPointsFrom(self, point, *args, **kw): 
    142         return self.MapPointsFrom([point], *args, **kw) 
     142        return self.MapPointsFrom([point], *args, **kw)[0] 
    143143 
    144144    def MapPointsFrom(self, points, xspan=(-1., 1.), yspan=None, flipx=False, flipy=False): 
     
    176176 
    177177    def __repr__(self): 
    178         return "<%s from:%r to:%r>" % (self.__class__.__name__, self.FromRect, self.ToRect
    179  
    180     def GetToRect(self): 
     178        return "<%s from:%r to:%r>" % (self.__class__.__name__, self.MapFrom, self.MapTo
     179 
     180    def GetMapTo(self): 
    181181        return self._torect 
    182     def SetToRect(self, torect): 
     182    def SetMapTo(self, torect): 
    183183        self._torect = torect 
    184     def DelToRect(self): 
     184    def DelMapTo(self): 
    185185        del self._torect 
    186     ToRect = property(GetToRect, SetToRect, DelToRect
    187  
    188     def GetFromRect(self): 
     186    MapTo = property(GetMapTo, SetMapTo, DelMapTo
     187 
     188    def GetMapFrom(self): 
    189189        return self._fromrect 
    190     def SetFromRect(self, fromrect): 
     190    def SetMapFrom(self, fromrect): 
    191191        self._fromrect = fromrect 
    192     def DelFromRect(self): 
     192    def DelMapFrom(self): 
    193193        del self._fromrect 
    194     FromRect = property(GetFromRect, SetFromRect, DelFromRect) 
     194    MapFrom = property(GetMapFrom, SetMapFrom, DelMapFrom) 
     195 
     196    def _GetMapping(self, frombox, tobox): 
     197        (x0f, y0f), (x1f, y1f) = frombox 
     198        (x0t, y0t), (x1t, y1t) = tobox 
     199        sx, tx = LinearMapping((x0f, x1f), (x0t, x1t), False) 
     200        sy, ty = LinearMapping((y0f, y1f), (y0t, y1t), False) 
     201        return (sx, tx), (sy,ty) 
    195202 
    196203#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    198205class RectangleMappingMatrix3dh(RectangleMappingBase, TransformPrimitive3dh): 
    199206    def asArray4x4(self): 
    200         x0f, y0f, wf, hf = map(float, self.GetFromRect().GetRectangle()) 
    201         x0t, y0t, wt, ht = map(float, self.GetToRect().GetRectangle()) 
    202         sx, tx = LinearDimMapping((x0f, wf), (x0t, wt), False) 
    203         sy, ty = LinearDimMapping((y0f, hf), (y0t, ht), False) 
     207        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapFrom().GetBox(), self.GetMapTo().GetBox()) 
    204208        result = Numeric.asarray([ 
    205209            [sx,  0,  0, tx], 
     
    210214 
    211215    def asInverse4x4_(self): 
    212         x0f, y0f, wf, hf = map(float, self.GetFromRect().GetRectangle()) 
    213         x0t, y0t, wt, ht = map(float, self.GetToRect().GetRectangle()) 
    214         sx, tx = LinearDimMapping((x0t, wt),(x0f, wf), False) 
    215         sy, ty = LinearDimMapping((y0t, ht),(y0f, hf), False) 
     216        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapTo().GetBox(), self.GetMapFrom().GetBox()) 
    216217        result = Numeric.asarray([ 
    217218            [sx,  0,  0, tx], 
     
    225226class RectangleMappingMatrix2dh(RectangleMappingBase, TransformPrimitive2dh): 
    226227    def asArray4x4(self): 
    227         x0f, y0f, wf, hf = map(float, self.GetFromRect().GetRectangle()) 
    228         x0t, y0t, wt, ht = map(float, self.GetToRect().GetRectangle()) 
    229         sx, tx = LinearDimMapping((x0f, wf), (x0t, wt), False) 
    230         sy, ty = LinearDimMapping((y0f, hf), (y0t, ht), False) 
     228        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapFrom().GetBox(), self.GetMapTo().GetBox()) 
    231229        result = Numeric.asarray([ 
    232230            [sx,  0, tx], 
     
    236234 
    237235    def asInverse4x4_(self): 
    238         x0f, y0f, wf, hf = map(float, self.GetFromRect().GetRectangle()) 
    239         x0t, y0t, wt, ht = map(float, self.GetToRect().GetRectangle()) 
    240         sx, tx = LinearDimMapping((x0t, wt),(x0f, wf), False) 
    241         sy, ty = LinearDimMapping((y0t, ht),(y0f, hf), False) 
     236        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapTo().GetBox(), self.GetMapFrom().GetBox()) 
    242237        result = Numeric.asarray([ 
    243238            [sx,  0, tx], 
  • trunk/RBRapier/RBRapier/Tools/ViewBox.py

    r703 r704  
    66from OpenGL import GL 
    77from Geometry import Curves 
     8from Vector import LinearMapping 
     9from Transformations import TransformPrimitive3dh 
     10from Transformations2d import TransformPrimitive2dh 
    811 
    912#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    107110        return self.fromBox(self.GetBox()/value) 
    108111 
     112    def GetP0(self): 
     113        return self.GetBox()[0] 
     114    def GetP1(self): 
     115        return self.GetBox()[1] 
    109116    def GetBox(self): 
    110117        return self._box 
     118    def GetRect(self): 
     119        _box = self.GetBox() 
     120        return _box[0], _box[1]-_box[0] 
    111121    def GetRectangle(self): 
    112122        _box = self.GetBox() 
    113         return _box[0], _box[1]-_box[0] 
     123        (x, y), (w, h) = _box[0], _box[1]-_box[0] 
     124        return x, y, w, h 
    114125    def GetPts(self): 
    115126        return self.GetBox() 
     
    123134        size = self.GetSize() 
    124135        return size[1]/size[0] 
    125  
     136    def GetWidth(self): 
     137        return self.GetSize()[0] 
     138    def GetHeight(self): 
     139        return self.GetSize()[1] 
     140    def GetXSpan(self): 
     141        box = self.GetBox() 
     142        return (box[0][0], box[1][0]) 
     143    def GetYSpan(self): 
     144        box = self.GetBox() 
     145        return (box[0][1], box[1][1]) 
     146    def GetXYSpan(self): 
     147        return Numeric.transpose(self.GetBox()) 
     148 
     149    def SetP0(self, p0): 
     150        return self.SetBox((p0, self.GetP1())) 
     151    def SetP1(self, p1): 
     152        return self.SetBox((self.GetP0(), p1)) 
    126153    def SetBox(self, box): 
    127154        self._box = Numeric.asarray(box, self.NumericType) 
    128155        return self._box 
    129     def SetRectangle(self, pos, dim): 
     156    def SetRect(self, pos, dim): 
    130157        pos, dim = self._ascoords(pos, dim) 
     158        return self.SetPts(pos, pos+dim) 
     159    def SetRectangle(self, rect): 
     160        pos, dim = self._ascoords(rect[:2], rect[2:4]) 
    131161        return self.SetPts(pos, pos+dim) 
    132162    def SetPts(self, pos0, pos1): 
     
    142172        _box = self.GetBox() 
    143173        return self.SetBox((_box[0], _box[0] + dim)) 
     174    def SetWidth(self, width): 
     175        return self.SetSize((width, self.GetHeight())) 
     176    def SetHeight(self, height): 
     177        return self.SetSize((self.GetWidth(), height)) 
     178         
    144179    def SetAspectRatio(self, aspectYX=1.0, largest=True): 
    145180        return self.ViewBoxSize(self.GetSize(), aspectYX, largest) 
     
    196231        _box = self.GetBox() 
    197232        return (pos-_box[0])/(_box[1]-_box[0]) 
     233 
     234    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     235 
     236    def MapPointTo(self, point, *args, **kw): 
     237        return self.MapPointsTo([point], *args, **kw)[0] 
     238 
     239    def MapPointsTo(self, points, xspan=(-1., 1.), yspan=None, flipx=False, flipy=False): 
     240        if yspan is None and hasattr(xspan, 'GetXYSpan'): 
     241            xspan, yspan = xspan.GetXYSpan() 
     242        xspan, yspan = xspan or yspan, yspan or xspan 
     243        if flipx: xspan = xspan[1], xspan[0] 
     244        if flipy: yspan = yspan[1], yspan[0] 
     245        span = Numeric.transpose(Numeric.asarray([xspan, yspan], self.NumericType)) 
     246        linearfn = LinearMapping(self.GetBox(), span) 
     247        points = Numeric.asarray(points, self.NumericType) 
     248        return Numeric.asarray(map(linearfn, points), self.NumericType) 
     249 
     250    def MapPointFrom(self, point, *args, **kw): 
     251        return self.MapPointsFrom([point], *args, **kw)[0] 
     252 
     253    def MapPointsFrom(self, points, xspan=(-1., 1.), yspan=None, flipx=False, flipy=False): 
     254        if yspan is None and hasattr(xspan, 'GetXYSpan'): 
     255            xspan, yspan = xspan.GetXYSpan() 
     256        xspan, yspan = xspan or yspan, yspan or xspan 
     257        if flipx: xspan = xspan[1], xspan[0] 
     258        if flipy: yspan = yspan[1], yspan[0] 
     259        span = Numeric.transpose(Numeric.asarray([xspan, yspan], self.NumericType)) 
     260        linearfn = LinearMapping(span, self.GetBox()) 
     261        points = Numeric.asarray(points, self.NumericType) 
     262        return Numeric.asarray(map(linearfn, points), self.NumericType) 
    198263 
    199264    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    267332        else: return self 
    268333 
    269  
     334#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     335#~ ViewBoxMappingMatrix 
     336#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     337 
     338class ViewBoxMappingBase(object): 
     339    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     340    #~ Constants / Variables / Etc.  
     341    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     342 
     343    _fromrect = ViewBox() 
     344    _torect = ViewBox() 
     345 
     346    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     347    #~ Public Methods  
     348    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     349 
     350    def __init__(self, fromrect=None, torect=None): 
     351        if isinstance(fromrect, (list, tuple)): 
     352            self._fromrect = ViewBox(fromrect) 
     353        elif fromrect is not None: 
     354            self._fromrect = fromrect 
     355        if isinstance(torect, (list, tuple)): 
     356            self._torect = ViewBox(torect) 
     357        elif torect is not None: 
     358            self._torect = torect 
     359 
     360    def __repr__(self): 
     361        return "<%s from:%r to:%r>" % (self.__class__.__name__, self.MapFrom, self.MapTo) 
     362 
     363    def GetMapTo(self): 
     364        return self._torect 
     365    def SetMapTo(self, torect): 
     366        self._torect = torect 
     367    def DelMapTo(self): 
     368        del self._torect 
     369    MapTo = property(GetMapTo, SetMapTo, DelMapTo) 
     370 
     371    def GetMapFrom(self): 
     372        return self._fromrect 
     373    def SetMapFrom(self, fromrect): 
     374        self._fromrect = fromrect 
     375    def DelMapFrom(self): 
     376        del self._fromrect 
     377    MapFrom = property(GetMapFrom, SetMapFrom, DelMapFrom) 
     378 
     379    def _GetMapping(self, frombox, tobox): 
     380        (x0f, y0f), (x1f, y1f) = frombox 
     381        (x0t, y0t), (x1t, y1t) = tobox 
     382        sx, tx = LinearMapping((x0f, x1f), (x0t, x1t), False) 
     383        sy, ty = LinearMapping((y0f, y1f), (y0t, y1t), False) 
     384        return (sx, tx), (sy,ty) 
     385 
     386#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     387 
     388class ViewBoxMappingMatrix3dh(ViewBoxMappingBase, TransformPrimitive3dh): 
     389    def asArray4x4(self): 
     390        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapFrom().GetBox(), self.GetMapTo().GetBox()) 
     391        result = Numeric.asarray([ 
     392            [sx,  0,  0, tx], 
     393            [ 0, sy,  0, ty], 
     394            [ 0,  0,  1,  0], 
     395            [ 0,  0,  0,  1]], self.NumericType) 
     396        return result 
     397 
     398    def asInverse4x4_(self): 
     399        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapTo().GetBox(), self.GetMapFrom().GetBox()) 
     400        result = Numeric.asarray([ 
     401            [sx,  0,  0, tx], 
     402            [ 0, sy,  0, ty], 
     403            [ 0,  0,  1,  0], 
     404            [ 0,  0,  0,  1]], self.NumericType) 
     405        return result 
     406 
     407#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     408 
     409class ViewBoxMappingMatrix2dh(ViewBoxMappingBase, TransformPrimitive2dh): 
     410    def asArray4x4(self): 
     411        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapFrom().GetBox(), self.GetMapTo().GetBox()) 
     412        result = Numeric.asarray([ 
     413            [sx,  0, tx], 
     414            [ 0, sy, ty], 
     415            [ 0,  0,  1]], self.NumericType) 
     416        return result 
     417 
     418    def asInverse4x4_(self): 
     419        (sx, tx), (sy, ty) = self._GetMapping(self.GetMapTo().GetBox(), self.GetMapFrom().GetBox()) 
     420        result = Numeric.asarray([ 
     421            [sx,  0, tx], 
     422            [ 0, sy, ty], 
     423            [ 0,  0,  1]], self.NumericType) 
     424        return result 
     425