Advertisement
Guest User

Untitled

a guest
Nov 18th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Scene.prototype.pickRegion = function(topLeftWindowPosition, bottomRightWindowPosition) {
  2.         //>>includeStart('debug', pragmas.debug);
  3.         if(!defined(topLeftWindowPosition)) {
  4.             throw new DeveloperError('topLeftWindowPosition is undefined.');
  5.         }
  6.  
  7.         if(!defined(bottomRightWindowPosition)) {
  8.             throw new DeveloperError('bottomRightWindowPosition is undefined.');
  9.         }
  10.         //>>includeEnd('debug');
  11.  
  12.         var minX = Math.min(topLeftWindowPosition.x, bottomRightWindowPosition.x);
  13.         var maxX = Math.max(topLeftWindowPosition.x, bottomRightWindowPosition.x);
  14.  
  15.         var minY = Math.min(topLeftWindowPosition.y, bottomRightWindowPosition.y);
  16.         var maxY = Math.max(topLeftWindowPosition.y, bottomRightWindowPosition.y);
  17.        
  18.         topLeftWindowPosition.x = minX;
  19.         topLeftWindowPosition.y = minY;
  20.  
  21.         bottomRightWindowPosition.x = maxX;
  22.         bottomRightWindowPosition.y = maxY;
  23.        
  24.         var context = this._context;
  25.         var us = context.uniformState;
  26.         var frameState = this._frameState;
  27.  
  28.         var drawingBufferPositionTopLeft = SceneTransforms.transformWindowToDrawingBuffer(this, topLeftWindowPosition, scratchPosition);
  29.         var drawingBufferPositionBottomRight = SceneTransforms.transformWindowToDrawingBuffer(this, bottomRightWindowPosition, scratchPosition2);
  30.        
  31.         drawingBufferPositionBottomRight.y = this.drawingBufferHeight - drawingBufferPositionBottomRight.y;
  32.         drawingBufferPositionTopLeft.y = this.drawingBufferHeight - drawingBufferPositionTopLeft.y;
  33.        
  34.         var drawingBufferPositionMiddle = new Cartesian2((drawingBufferPositionTopLeft.x + drawingBufferPositionBottomRight.x)*0.5, (drawingBufferPositionTopLeft.y + drawingBufferPositionBottomRight.y)*0.5);
  35.  
  36.         if (!defined(this._pickFramebuffer)) {
  37.             this._pickFramebuffer = context.createPickFramebuffer();
  38.         }
  39.        
  40.         var rectangleWidth = Math.abs(drawingBufferPositionTopLeft.x - drawingBufferPositionBottomRight.x);
  41.         var rectangleHeight = Math.abs(drawingBufferPositionTopLeft.y - drawingBufferPositionBottomRight.y);
  42.        
  43.         if (rectangleWidth<3) {
  44.             rectangleWidth = 3;
  45.         }
  46.  
  47.         if (rectangleHeight<3) {
  48.             rectangleHeight = 3;
  49.         }
  50.        
  51.         // Update with previous frame's number and time, assuming that render is called before picking.
  52.         updateFrameState(this, frameState.frameNumber, frameState.time);
  53.         //frameState.cullingVolume = getPickCullingVolume(this, drawingBufferPositionMiddle, rectangleWidth, rectangleHeight);
  54.         frameState.passes.pick = true;
  55.  
  56.         us.update(context, frameState);
  57.  
  58.         this._commandList.length = 0;
  59.         updatePrimitives(this);
  60.         createPotentiallyVisibleSet(this);
  61.  
  62.         var scratchRectangle = new BoundingRectangle(drawingBufferPositionTopLeft.x, drawingBufferPositionTopLeft.y, rectangleWidth, rectangleHeight);
  63.  
  64.         executeCommands(this, this._pickFramebuffer.begin(scratchRectangle), scratchColorZero, true);
  65.         var result = this._pickFramebuffer.endWithRect(scratchRectangle);
  66.         context.endFrame();
  67.         callAfterRenderFunctions(frameState);
  68.        
  69.        
  70.         return result;
  71.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement