mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
Merge pull request #935 from openglobus/read-depth-buffer-fix
Read depth buffer fix
This commit is contained in:
commit
bc6b6aea92
@ -13,7 +13,21 @@ import {Plane} from "../math/Plane";
|
||||
import { createEvents, EventsHandler } from "../Events";
|
||||
|
||||
interface ITouchNavigationParams extends IControlParams {
|
||||
/**
|
||||
* Inertia factor.
|
||||
* Default: 0.007
|
||||
*/
|
||||
inertia?: number;
|
||||
/**
|
||||
* Limit for tilt angle.
|
||||
* Default: 0.1
|
||||
*/
|
||||
minSlope?: number;
|
||||
/**
|
||||
* Limit for touch jerk speed to prevent unexpected camera zooming.
|
||||
* Default: 0.3
|
||||
*/
|
||||
jerkLimit?: number;
|
||||
}
|
||||
|
||||
export type TouchNavigationEventsList = [
|
||||
@ -41,6 +55,9 @@ const TOUCH_NAVIGATION_EVENTS: TouchNavigationEventsList = [
|
||||
*/
|
||||
"doubletapzoom",
|
||||
];
|
||||
const DEFAULT_INERTIA = 0.007;
|
||||
const DEFAULT_MIN_SLOPE = 0.1;
|
||||
const DEFAULT_JERK_LIMIT = 0.3;
|
||||
|
||||
class TouchExt {
|
||||
public x: number;
|
||||
@ -86,8 +103,10 @@ class TouchExt {
|
||||
* Touch pad planet camera dragging control.
|
||||
* @class
|
||||
* @extends {Control}
|
||||
* @param {ITouchNavigationParams} [options] - Mouse navigation options:
|
||||
* @param {ITouchNavigationParams} [options] - Touch navigation options:
|
||||
* @param {number} [options.inertia] - inertia factor. Default is 0.007
|
||||
* @param {number} [options.minSlope] - minimal slope for vertical camera movement. Default is 0.1
|
||||
* @param {number} [options.jerkLimit] - limit for touch jerk speed to prevent unexpected camera movement. Default is 0.08
|
||||
* @fires og.TouchNavigation#inertiamove
|
||||
* @fires og.TouchNavigation#drag
|
||||
* @fires og.TouchNavigation#doubletapzoom
|
||||
@ -96,6 +115,8 @@ export class TouchNavigation extends Control {
|
||||
|
||||
public grabbedPoint: Vec3;
|
||||
public inertia: number;
|
||||
public minSlope: number;
|
||||
public jerkLimit: number;
|
||||
public events: EventsHandler<TouchNavigationEventsList>;
|
||||
|
||||
protected grabbedSpheroid: Sphere;
|
||||
@ -117,7 +138,9 @@ export class TouchNavigation extends Control {
|
||||
|
||||
this.events = createEvents<TouchNavigationEventsList>(TOUCH_NAVIGATION_EVENTS, this);
|
||||
this.grabbedPoint = new Vec3();
|
||||
this.inertia = options.inertia != undefined ? options.inertia : 0.007;
|
||||
this.inertia = options.inertia != undefined ? options.inertia : DEFAULT_INERTIA;
|
||||
this.minSlope = options.minSlope != undefined ? options.minSlope : DEFAULT_MIN_SLOPE;
|
||||
this.jerkLimit = options.jerkLimit != undefined ? options.jerkLimit : DEFAULT_JERK_LIMIT;
|
||||
this.grabbedSpheroid = new Sphere();
|
||||
this.planet = null;
|
||||
this.qRot = new Quat();
|
||||
@ -288,14 +311,14 @@ export class TouchNavigation extends Control {
|
||||
t1.y = (e.sys!.touches.item(1)!.clientY - e.sys!.offsetTop) * handler.pixelRatio;
|
||||
|
||||
const middle = t0.vec.add(t1.vec).scale(0.5);
|
||||
const earthMiddlePoint = this.planet!.getCartesianFromPixelTerrain(
|
||||
const earthMiddlePoint = this.planet!.getCartesianFromPixelEllipsoid(
|
||||
middle
|
||||
);
|
||||
if (earthMiddlePoint) {
|
||||
this.pointOnEarth = earthMiddlePoint
|
||||
this.pointOnEarth = earthMiddlePoint;
|
||||
|
||||
const prevAngle = Math.atan2(t0.prev_y - t1.prev_y, t0.prev_x - t1.prev_x)
|
||||
const curAngle = Math.atan2(t0.y - t1.y, t0.x - t1.x)
|
||||
const prevAngle = Math.atan2(t0.prev_y - t1.prev_y, t0.prev_x - t1.prev_x);
|
||||
const curAngle = Math.atan2(t0.y - t1.y, t0.x - t1.x);
|
||||
|
||||
const deltaAngle = curAngle - prevAngle;
|
||||
const distanceToPointOnEarth = cam.eye.distance(this.pointOnEarth);
|
||||
@ -303,8 +326,9 @@ export class TouchNavigation extends Control {
|
||||
const zoomCur = t0.vec.sub(t1.vec);
|
||||
const zoomPrev = t0.vecPrev.sub(t1.vecPrev);
|
||||
let scale = zoomCur.length() / zoomPrev.length();
|
||||
scale = scale > 1.08 ? 1.08 : scale < 0.92 ? 0.92 : scale;
|
||||
|
||||
const jerkMax = 1 + this.jerkLimit;
|
||||
const jerkMin = 1 - this.jerkLimit;
|
||||
scale = scale > jerkMax ? jerkMax : scale < jerkMin ? jerkMin : scale;
|
||||
let d = distanceToPointOnEarth * -(1 - scale);
|
||||
cam.eye.addA(cam.getForward().scale(d));
|
||||
cam.rotateAround(-deltaAngle, false, this.pointOnEarth, this.earthUp!);
|
||||
@ -315,7 +339,7 @@ export class TouchNavigation extends Control {
|
||||
var l = 0.5 / distanceToPointOnEarth * cam._lonLat.height * math.RADIANS;
|
||||
if (l > 0.003) l = 0.003;
|
||||
cam.rotateHorizontal(l * -panOffset.x, false, this.pointOnEarth, this.earthUp!);
|
||||
cam.rotateVertical(l * -panOffset.y, this.pointOnEarth, 0.1);
|
||||
cam.rotateVertical(l * -panOffset.y, this.pointOnEarth, this.minSlope);
|
||||
|
||||
cam.checkTerrainCollision();
|
||||
cam.update();
|
||||
|
||||
@ -996,8 +996,10 @@ class Renderer {
|
||||
*/
|
||||
public draw() {
|
||||
this.activeCamera!.checkMoveEnd();
|
||||
|
||||
let e = this.events;
|
||||
let pointerEvent = e.pointerEvent();
|
||||
let pointerFree = !e.mouseState.leftButtonDown && !e.mouseState.rightButtonDown;
|
||||
let touchTrigger = e.touchState.touchStart || e.touchState.touchEnd;
|
||||
e.handleEvents();
|
||||
|
||||
let sceneFramebuffer = this.sceneFramebuffer!;
|
||||
@ -1017,8 +1019,7 @@ class Renderer {
|
||||
|
||||
let frustums = this.activeCamera!.frustums;
|
||||
|
||||
let pointerEvent = e.pointerEvent();
|
||||
let pointerFree = !e.mouseState.leftButtonDown && !e.mouseState.rightButtonDown && !e.touchState.touching && !e.touchState.moving;
|
||||
|
||||
|
||||
// Rendering scene nodes and entityCollections
|
||||
let rn = this._renderNodesArr;
|
||||
@ -1046,7 +1047,7 @@ class Renderer {
|
||||
|
||||
e.dispatch(e.drawtransparent, this);
|
||||
|
||||
if (pointerEvent && pointerFree) {
|
||||
if ((pointerEvent && pointerFree) || touchTrigger) {
|
||||
this._drawPickingBuffer(0);
|
||||
}
|
||||
|
||||
@ -1066,7 +1067,7 @@ class Renderer {
|
||||
|
||||
this._drawEntityCollections(i);
|
||||
|
||||
if (pointerEvent && pointerFree) {
|
||||
if ((pointerEvent && pointerFree) || touchTrigger) {
|
||||
this._drawPickingBuffer(i);
|
||||
}
|
||||
|
||||
@ -1080,7 +1081,7 @@ class Renderer {
|
||||
|
||||
this.blitFramebuffer && (sceneFramebuffer as Multisample).blitTo(this.blitFramebuffer, 0);
|
||||
|
||||
if (pointerEvent && pointerFree) {
|
||||
if ((pointerEvent && pointerFree) || touchTrigger) {
|
||||
this._readPickingBuffer();
|
||||
this._readDepthBuffer();
|
||||
}
|
||||
|
||||
@ -337,14 +337,10 @@ class RendererEvents extends Events<RendererEventsType> implements RendererEvent
|
||||
}
|
||||
|
||||
public pointerEvent(): boolean {
|
||||
let ms = this.mouseState,
|
||||
ts = this.touchState;
|
||||
let ms = this.mouseState;
|
||||
return (
|
||||
ms.moving ||
|
||||
ms.justStopped ||
|
||||
ts.moving ||
|
||||
ts.touchStart ||
|
||||
ts.touchEnd ||
|
||||
ms.wheelDelta !== 0
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user