Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scene.prototype.pickRegion = function(topLeftWindowPosition, bottomRightWindowPosition) {
- //>>includeStart('debug', pragmas.debug);
- if(!defined(topLeftWindowPosition)) {
- throw new DeveloperError('topLeftWindowPosition is undefined.');
- }
- if(!defined(bottomRightWindowPosition)) {
- throw new DeveloperError('bottomRightWindowPosition is undefined.');
- }
- //>>includeEnd('debug');
- var minX = Math.min(topLeftWindowPosition.x, bottomRightWindowPosition.x);
- var maxX = Math.max(topLeftWindowPosition.x, bottomRightWindowPosition.x);
- var minY = Math.min(topLeftWindowPosition.y, bottomRightWindowPosition.y);
- var maxY = Math.max(topLeftWindowPosition.y, bottomRightWindowPosition.y);
- topLeftWindowPosition.x = minX;
- topLeftWindowPosition.y = minY;
- bottomRightWindowPosition.x = maxX;
- bottomRightWindowPosition.y = maxY;
- var context = this._context;
- var us = context.uniformState;
- var frameState = this._frameState;
- var drawingBufferPositionTopLeft = SceneTransforms.transformWindowToDrawingBuffer(this, topLeftWindowPosition, scratchPosition);
- var drawingBufferPositionBottomRight = SceneTransforms.transformWindowToDrawingBuffer(this, bottomRightWindowPosition, scratchPosition2);
- drawingBufferPositionBottomRight.y = this.drawingBufferHeight - drawingBufferPositionBottomRight.y;
- drawingBufferPositionTopLeft.y = this.drawingBufferHeight - drawingBufferPositionTopLeft.y;
- var drawingBufferPositionMiddle = new Cartesian2((drawingBufferPositionTopLeft.x + drawingBufferPositionBottomRight.x)*0.5, (drawingBufferPositionTopLeft.y + drawingBufferPositionBottomRight.y)*0.5);
- if (!defined(this._pickFramebuffer)) {
- this._pickFramebuffer = context.createPickFramebuffer();
- }
- var rectangleWidth = Math.abs(drawingBufferPositionTopLeft.x - drawingBufferPositionBottomRight.x);
- var rectangleHeight = Math.abs(drawingBufferPositionTopLeft.y - drawingBufferPositionBottomRight.y);
- if (rectangleWidth<3) {
- rectangleWidth = 3;
- }
- if (rectangleHeight<3) {
- rectangleHeight = 3;
- }
- // Update with previous frame's number and time, assuming that render is called before picking.
- updateFrameState(this, frameState.frameNumber, frameState.time);
- //frameState.cullingVolume = getPickCullingVolume(this, drawingBufferPositionMiddle, rectangleWidth, rectangleHeight);
- frameState.passes.pick = true;
- us.update(context, frameState);
- this._commandList.length = 0;
- updatePrimitives(this);
- createPotentiallyVisibleSet(this);
- var scratchRectangle = new BoundingRectangle(drawingBufferPositionTopLeft.x, drawingBufferPositionTopLeft.y, rectangleWidth, rectangleHeight);
- executeCommands(this, this._pickFramebuffer.begin(scratchRectangle), scratchColorZero, true);
- var result = this._pickFramebuffer.endWithRect(scratchRectangle);
- context.endFrame();
- callAfterRenderFunctions(frameState);
- return result;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement