Changeset 704
- Timestamp:
- 09/16/03 16:12:35 (5 years ago)
- Files:
-
- trunk/RBRapier/RBRapier/Renderer/Environment/FragmentTests.py (modified) (4 diffs)
- trunk/RBRapier/RBRapier/Renderer/View/Transformations.py (modified) (6 diffs)
- trunk/RBRapier/RBRapier/Renderer/View/Viewport.py (modified) (3 diffs)
- trunk/RBRapier/RBRapier/Tools/RectangleBase.py (modified) (9 diffs)
- trunk/RBRapier/RBRapier/Tools/ViewBox.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/RBRapier/RBRapier/Renderer/Environment/FragmentTests.py
r702 r704 25 25 26 26 from OpenGL import GL 27 from RBRapier.Tools import RectangleBase 27 28 from RBFoundation.Objects.Properties import LazyProperty 29 from RBRapier.Tools import ViewBox 28 30 from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 29 31 … … 32 34 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33 35 34 class ScissorTest( RectangleBase.RectangleBase):36 class ScissorTest(object): 35 37 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 36 38 #~ Constants / Variables / Etc. … … 38 40 39 41 AttributeChange = AttributeChangeElement(GL.GL_SCISSOR_BIT) 42 Box = LazyProperty(ViewBox) 40 43 41 44 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 44 47 45 48 def GLSelect(self, context): 46 GL.glScissor(*self.Rectangle) 49 rectangle = map(int, self.Box.GetRectangle()) 50 GL.glScissor(*rectangle) 47 51 context.StateMgr.Enable(GL.GL_SCISSOR_TEST) 48 52 trunk/RBRapier/RBRapier/Renderer/View/Transformations.py
r703 r704 27 27 from RBRapier.Tools import Projections 28 28 from RBRapier.Tools import Quaternion 29 from RBRapier.Tools import RectangleBase29 from RBRapier.Tools import ViewBox 30 30 31 31 from Numeric import transpose 32 32 from OpenGL import GL, GLU 33 34 try: 35 GL.GL_COLOR_MATRIX 36 except AttributeError: 37 GL.GL_COLOR_MATRIX = 0x80B1 33 38 34 39 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 48 53 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 49 54 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 } 51 63 Mode = None 52 64 Save = 0 … … 67 79 if self.Mode: 68 80 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: 69 86 self._SaveMatrix() 70 87 self.GLExecute(context) 71 GL.glMatrixMode(GL.GL_MODELVIEW)72 88 else: 73 self._SaveMatrix()74 89 self.GLExecute(context) 75 90 … … 86 101 try: 87 102 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) 90 106 91 107 def _RestoreMatrix(self): … … 96 112 GL.glLoadMatrixd(oldmatrix) 97 113 del self._save_matrix 114 #_RestoreMatrix = staticmethod(GL.glPopMatrix) 98 115 99 116 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 169 186 pass 170 187 171 class RectangleMappingMatrix(RectangleBase.RectangleMappingMatrix3dh):172 GLExecute = GLExecuteAsMatrix 173 174 class RectangleMappingMatrixMgd(ManagedTransformationMixin, RectangleMappingMatrix):188 class ViewBoxMappingMatrix(ViewBox.ViewBoxMappingMatrix3dh): 189 GLExecute = GLExecuteAsMatrix 190 191 class ViewBoxMappingMatrixMgd(ManagedTransformationMixin, ViewBoxMappingMatrix): 175 192 pass 176 193 trunk/RBRapier/RBRapier/Renderer/View/Viewport.py
r702 r704 25 25 26 26 from OpenGL import GL 27 from RBRapier.Tools import RectangleBase27 from RBRapier.Tools import ViewBox 28 28 from RBRapier.Renderer.AttributeMgr import AttributeChangeElement 29 29 … … 32 32 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 33 33 34 class Viewport( RectangleBase.RectangleBase):34 class Viewport(ViewBox.ViewBox): 35 35 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 36 36 #~ Constants / Variables / Etc. … … 44 44 45 45 def GLExecute(self, context): 46 GL.glViewport(*self.Rectangle) 46 rectangle = map(int, self.GetRectangle()) 47 GL.glViewport(*rectangle) 47 48 trunk/RBRapier/RBRapier/Tools/RectangleBase.py
r703 r704 109 109 110 110 def GetBox(self): 111 x, y, w, h = self. Rectangle()111 x, y, w, h = self.GetRectangle() 112 112 return (x, y), (x+w, y+h) 113 113 def SetBox(self, box): … … 122 122 123 123 def GetRectangle(self): 124 return self.Rectangle124 return map(float, self.Rectangle) 125 125 def SetRectangle(self, *args): 126 126 if len(args) == 1: args = args[0] … … 128 128 129 129 def MapPointTo(self, point, *args, **kw): 130 return self.MapPoints ([point], *args, **kw)130 return self.MapPointsTo([point], *args, **kw)[0] 131 131 132 132 def MapPointsTo(self, points, xspan=(-1., 1.), yspan=None, flipx=False, flipy=False): … … 140 140 141 141 def MapPointsFrom(self, point, *args, **kw): 142 return self.MapPointsFrom([point], *args, **kw) 142 return self.MapPointsFrom([point], *args, **kw)[0] 143 143 144 144 def MapPointsFrom(self, points, xspan=(-1., 1.), yspan=None, flipx=False, flipy=False): … … 176 176 177 177 def __repr__(self): 178 return "<%s from:%r to:%r>" % (self.__class__.__name__, self. FromRect, self.ToRect)179 180 def Get ToRect(self):178 return "<%s from:%r to:%r>" % (self.__class__.__name__, self.MapFrom, self.MapTo) 179 180 def GetMapTo(self): 181 181 return self._torect 182 def Set ToRect(self, torect):182 def SetMapTo(self, torect): 183 183 self._torect = torect 184 def Del ToRect(self):184 def DelMapTo(self): 185 185 del self._torect 186 ToRect = property(GetToRect, SetToRect, DelToRect)187 188 def Get FromRect(self):186 MapTo = property(GetMapTo, SetMapTo, DelMapTo) 187 188 def GetMapFrom(self): 189 189 return self._fromrect 190 def Set FromRect(self, fromrect):190 def SetMapFrom(self, fromrect): 191 191 self._fromrect = fromrect 192 def Del FromRect(self):192 def DelMapFrom(self): 193 193 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) 195 202 196 203 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 198 205 class RectangleMappingMatrix3dh(RectangleMappingBase, TransformPrimitive3dh): 199 206 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()) 204 208 result = Numeric.asarray([ 205 209 [sx, 0, 0, tx], … … 210 214 211 215 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()) 216 217 result = Numeric.asarray([ 217 218 [sx, 0, 0, tx], … … 225 226 class RectangleMappingMatrix2dh(RectangleMappingBase, TransformPrimitive2dh): 226 227 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()) 231 229 result = Numeric.asarray([ 232 230 [sx, 0, tx], … … 236 234 237 235 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()) 242 237 result = Numeric.asarray([ 243 238 [sx, 0, tx], trunk/RBRapier/RBRapier/Tools/ViewBox.py
r703 r704 6 6 from OpenGL import GL 7 7 from Geometry import Curves 8 from Vector import LinearMapping 9 from Transformations import TransformPrimitive3dh 10 from Transformations2d import TransformPrimitive2dh 8 11 9 12 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 107 110 return self.fromBox(self.GetBox()/value) 108 111 112 def GetP0(self): 113 return self.GetBox()[0] 114 def GetP1(self): 115 return self.GetBox()[1] 109 116 def GetBox(self): 110 117 return self._box 118 def GetRect(self): 119 _box = self.GetBox() 120 return _box[0], _box[1]-_box[0] 111 121 def GetRectangle(self): 112 122 _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 114 125 def GetPts(self): 115 126 return self.GetBox() … … 123 134 size = self.GetSize() 124 135 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)) 126 153 def SetBox(self, box): 127 154 self._box = Numeric.asarray(box, self.NumericType) 128 155 return self._box 129 def SetRect angle(self, pos, dim):156 def SetRect(self, pos, dim): 130 157 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]) 131 161 return self.SetPts(pos, pos+dim) 132 162 def SetPts(self, pos0, pos1): … … 142 172 _box = self.GetBox() 143 173 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 144 179 def SetAspectRatio(self, aspectYX=1.0, largest=True): 145 180 return self.ViewBoxSize(self.GetSize(), aspectYX, largest) … … 196 231 _box = self.GetBox() 197 232 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) 198 263 199 264 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ … … 267 332 else: return self 268 333 269 334 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 335 #~ ViewBoxMappingMatrix 336 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 337 338 class 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 388 class 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 409 class 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
