Spaces:
Running
Running
| //////////////////////////////////////////////////////////////////////////////// | |
| // Orbit Camera Script // | |
| //////////////////////////////////////////////////////////////////////////////// | |
| var OrbitCamera = pc.createScript('orbitCamera'); | |
| OrbitCamera.attributes.add('distanceMax', { type: 'number', default: 20, title: 'Distance Max', description: 'Setting this at 0 will give an infinite distance limit' }); | |
| OrbitCamera.attributes.add('distanceMin', { type: 'number', default: 1, title: 'Distance Min' }); | |
| OrbitCamera.attributes.add('pitchAngleMax', { type: 'number', default: 90, title: 'Pitch Angle Max (degrees)' }); | |
| // Note: This default will be overridden by your JSON config. In your JSON you set minAngle to -90. | |
| OrbitCamera.attributes.add('pitchAngleMin', { type: 'number', default: 0, title: 'Pitch Angle Min (degrees)' }); | |
| OrbitCamera.attributes.add('yawAngleMax', { type: 'number', default: 360, title: 'Yaw Angle Max (degrees)' }); | |
| OrbitCamera.attributes.add('yawAngleMin', { type: 'number', default: -360, title: 'Yaw Angle Min (degrees)' }); | |
| // NEW: Added minY attribute to define the minimum allowed Y value for the camera. | |
| OrbitCamera.attributes.add('minY', { type: 'number', default: 0, title: 'Minimum Y', description: 'Minimum Y value for the camera during orbiting or translation' }); | |
| OrbitCamera.attributes.add('inertiaFactor', { | |
| type: 'number', | |
| default: 0.2, | |
| title: 'Inertia Factor', | |
| description: 'Higher value means that the camera will continue moving after the user has stopped dragging. 0 is fully responsive.' | |
| }); | |
| OrbitCamera.attributes.add('focusEntity', { | |
| type: 'entity', | |
| title: 'Focus Entity', | |
| description: 'Entity for the camera to focus on. If blank, then the camera will use the whole scene' | |
| }); | |
| OrbitCamera.attributes.add('frameOnStart', { | |
| type: 'boolean', | |
| default: true, | |
| title: 'Frame on Start', | |
| description: 'Frames the entity or scene at the start of the application."' | |
| }); | |
| // Property to get and set the distance between the pivot point and camera | |
| // Clamped between this.distanceMin and this.distanceMax | |
| Object.defineProperty(OrbitCamera.prototype, 'distance', { | |
| get: function () { | |
| return this._targetDistance; | |
| }, | |
| set: function (value) { | |
| this._targetDistance = this._clampDistance(value); | |
| } | |
| }); | |
| // Property to get and set the camera orthoHeight (clamped above 0) | |
| Object.defineProperty(OrbitCamera.prototype, 'orthoHeight', { | |
| get: function () { | |
| return this.entity.camera.orthoHeight; | |
| }, | |
| set: function (value) { | |
| this.entity.camera.orthoHeight = Math.max(0, value); | |
| } | |
| }); | |
| // Property to get and set the pitch (in degrees) of the camera around the pivot. | |
| // The pitch value is clamped between pitchAngleMin and pitchAngleMax. | |
| // With your JSON (minAngle: -90, maxAngle: 0), the allowed pitch will be from -90 (overhead) | |
| // to 0 (horizontal). | |
| Object.defineProperty(OrbitCamera.prototype, 'pitch', { | |
| get: function () { | |
| return this._targetPitch; | |
| }, | |
| set: function (value) { | |
| this._targetPitch = this._clampPitchAngle(value); | |
| } | |
| }); | |
| // Property to get and set the yaw (in degrees) of the camera around the pivot. | |
| Object.defineProperty(OrbitCamera.prototype, 'yaw', { | |
| get: function () { | |
| return this._targetYaw; | |
| }, | |
| set: function (value) { | |
| this._targetYaw = this._clampYawAngle(value); | |
| } | |
| }); | |
| // Property to get and set the world position of the pivot point that the camera orbits around. | |
| Object.defineProperty(OrbitCamera.prototype, 'pivotPoint', { | |
| get: function () { | |
| return this._pivotPoint; | |
| }, | |
| set: function (value) { | |
| this._pivotPoint.copy(value); | |
| } | |
| }); | |
| // Moves the camera to look at an entity and all its children so they are all in view. | |
| OrbitCamera.prototype.focus = function (focusEntity) { | |
| // Calculate a bounding box that encompasses all models to frame in the camera view. | |
| this._buildAabb(focusEntity); | |
| var halfExtents = this._modelsAabb.halfExtents; | |
| var radius = Math.max(halfExtents.x, Math.max(halfExtents.y, halfExtents.z)); | |
| this.distance = (radius * 1.5) / Math.sin(0.5 * this.entity.camera.fov * pc.math.DEG_TO_RAD); | |
| this._removeInertia(); | |
| this._pivotPoint.copy(this._modelsAabb.center); | |
| }; | |
| OrbitCamera.distanceBetween = new pc.Vec3(); | |
| // Set the camera position to a world position and look at a world position. | |
| OrbitCamera.prototype.resetAndLookAtPoint = function (resetPoint, lookAtPoint) { | |
| this.pivotPoint.copy(lookAtPoint); | |
| this.entity.setPosition(resetPoint); | |
| this.entity.lookAt(lookAtPoint); | |
| var distance = OrbitCamera.distanceBetween; | |
| distance.sub2(lookAtPoint, resetPoint); | |
| this.distance = distance.length(); | |
| this.pivotPoint.copy(lookAtPoint); | |
| var cameraQuat = this.entity.getRotation(); | |
| this.yaw = this._calcYaw(cameraQuat); | |
| this.pitch = this._calcPitch(cameraQuat, this.yaw); | |
| this._removeInertia(); | |
| this._updatePosition(); | |
| }; | |
| OrbitCamera.prototype.resetAndLookAtEntity = function (resetPoint, entity) { | |
| this._buildAabb(entity); | |
| this.resetAndLookAtPoint(resetPoint, this._modelsAabb.center); | |
| }; | |
| OrbitCamera.prototype.reset = function (yaw, pitch, distance) { | |
| this.pitch = pitch; | |
| this.yaw = yaw; | |
| this.distance = distance; | |
| this._removeInertia(); | |
| }; | |
| OrbitCamera.prototype.resetToPosition = function (position, lookAtPoint) { | |
| this.entity.setPosition(position); | |
| this.entity.lookAt(lookAtPoint); | |
| this._pivotPoint.copy(lookAtPoint); | |
| var distanceVec = new pc.Vec3(); | |
| distanceVec.sub2(position, lookAtPoint); | |
| this._targetDistance = this._distance = distanceVec.length(); | |
| var cameraQuat = this.entity.getRotation(); | |
| this._targetYaw = this._yaw = this._calcYaw(cameraQuat); | |
| this._targetPitch = this._pitch = this._calcPitch(cameraQuat, this._yaw); | |
| this._removeInertia(); | |
| this._updatePosition(); | |
| }; | |
| //////////////////////////////////////////////////////////////////////////////// | |
| // Private Methods // | |
| //////////////////////////////////////////////////////////////////////////////// | |
| OrbitCamera.prototype.initialize = function () { | |
| var self = this; | |
| var onWindowResize = function () { | |
| self._checkAspectRatio(); | |
| }; | |
| window.addEventListener('resize', onWindowResize, false); | |
| this._checkAspectRatio(); | |
| this._modelsAabb = new pc.BoundingBox(); | |
| this._buildAabb(this.focusEntity || this.app.root); | |
| this.entity.lookAt(this._modelsAabb.center); | |
| this._pivotPoint = new pc.Vec3(); | |
| this._pivotPoint.copy(this._modelsAabb.center); | |
| var cameraQuat = this.entity.getRotation(); | |
| this._yaw = this._calcYaw(cameraQuat); | |
| // Compute pitch and clamp it immediately. | |
| this._pitch = this._clampPitchAngle(this._calcPitch(cameraQuat, this._yaw)); | |
| this.entity.setLocalEulerAngles(this._pitch, this._yaw, 0); | |
| this._distance = 0; | |
| this._targetYaw = this._yaw; | |
| this._targetPitch = this._pitch; | |
| if (this.frameOnStart) { | |
| this.focus(this.focusEntity || this.app.root); | |
| } else { | |
| var distanceBetween = new pc.Vec3(); | |
| distanceBetween.sub2(this.entity.getPosition(), this._pivotPoint); | |
| this._distance = this._clampDistance(distanceBetween.length()); | |
| } | |
| this._targetDistance = this._distance; | |
| this.on('attr:distanceMin', function (value, prev) { | |
| this._distance = this._clampDistance(this._distance); | |
| }); | |
| this.on('attr:distanceMax', function (value, prev) { | |
| this._distance = this._clampDistance(this._distance); | |
| }); | |
| this.on('attr:pitchAngleMin', function (value, prev) { | |
| this._pitch = this._clampPitchAngle(this._pitch); | |
| }); | |
| this.on('attr:pitchAngleMax', function (value, prev) { | |
| this._pitch = this._clampPitchAngle(this._pitch); | |
| }); | |
| this.on('attr:focusEntity', function (value, prev) { | |
| if (this.frameOnStart) { | |
| this.focus(value || this.app.root); | |
| } else { | |
| this.resetAndLookAtEntity(this.entity.getPosition(), value || this.app.root); | |
| } | |
| }); | |
| this.on('attr:frameOnStart', function (value, prev) { | |
| if (value) { | |
| this.focus(this.focusEntity || this.app.root); | |
| } | |
| }); | |
| this.on('destroy', function () { | |
| window.removeEventListener('resize', onWindowResize, false); | |
| }); | |
| }; | |
| OrbitCamera.prototype.update = function (dt) { | |
| var t = this.inertiaFactor === 0 ? 1 : Math.min(dt / this.inertiaFactor, 1); | |
| this._distance = pc.math.lerp(this._distance, this._targetDistance, t); | |
| this._yaw = pc.math.lerp(this._yaw, this._targetYaw, t); | |
| this._pitch = pc.math.lerp(this._pitch, this._targetPitch, t); | |
| this._updatePosition(); | |
| }; | |
| OrbitCamera.prototype._updatePosition = function () { | |
| this.entity.setLocalPosition(0, 0, 0); | |
| this.entity.setLocalEulerAngles(this._pitch, this._yaw, 0); | |
| var position = this.entity.getPosition(); | |
| position.copy(this.entity.forward); | |
| position.mulScalar(-this._distance); | |
| position.add(this.pivotPoint); | |
| // NEW: Clamp the camera's Y position so it never goes below the specified minY value. | |
| position.y = Math.max(position.y, this.minY); | |
| this.entity.setPosition(position); | |
| }; | |
| OrbitCamera.prototype._removeInertia = function () { | |
| this._yaw = this._targetYaw; | |
| this._pitch = this._targetPitch; | |
| this._distance = this._targetDistance; | |
| }; | |
| OrbitCamera.prototype._checkAspectRatio = function () { | |
| var height = this.app.graphicsDevice.height; | |
| var width = this.app.graphicsDevice.width; | |
| this.entity.camera.horizontalFov = (height > width); | |
| }; | |
| OrbitCamera.prototype._buildAabb = function (entity) { | |
| var i, m, meshInstances = []; | |
| var renders = entity.findComponents('render'); | |
| for (i = 0; i < renders.length; i++) { | |
| var render = renders[i]; | |
| for (m = 0; m < render.meshInstances.length; m++) { | |
| meshInstances.push(render.meshInstances[m]); | |
| } | |
| } | |
| var models = entity.findComponents('model'); | |
| for (i = 0; i < models.length; i++) { | |
| var model = models[i]; | |
| for (m = 0; m < model.meshInstances.length; m++) { | |
| meshInstances.push(model.meshInstances[m]); | |
| } | |
| } | |
| var gsplats = entity.findComponents('gsplat'); | |
| for (i = 0; i < gsplats.length; i++) { | |
| var gsplat = gsplats[i]; | |
| var instance = gsplat.instance; | |
| if (instance?.meshInstance) { | |
| meshInstances.push(instance.meshInstance); | |
| } | |
| } | |
| for (i = 0; i < meshInstances.length; i++) { | |
| if (i === 0) { | |
| this._modelsAabb.copy(meshInstances[i].aabb); | |
| } else { | |
| this._modelsAabb.add(meshInstances[i].aabb); | |
| } | |
| } | |
| }; | |
| OrbitCamera.prototype._calcYaw = function (quat) { | |
| var transformedForward = new pc.Vec3(); | |
| quat.transformVector(pc.Vec3.FORWARD, transformedForward); | |
| return Math.atan2(-transformedForward.x, -transformedForward.z) * pc.math.RAD_TO_DEG; | |
| }; | |
| OrbitCamera.prototype._clampDistance = function (distance) { | |
| if (this.distanceMax > 0) { | |
| return pc.math.clamp(distance, this.distanceMin, this.distanceMax); | |
| } | |
| return Math.max(distance, this.distanceMin); | |
| }; | |
| // ----- FIXED PITCH CLAMPING ----- | |
| // Clamp the pitch between pitchAngleMin and pitchAngleMax so that with your JSON values | |
| // (minAngle: -90, maxAngle: 0) the allowed pitch is between -90 (overhead) and 0 (horizontal). | |
| OrbitCamera.prototype._clampPitchAngle = function (pitch) { | |
| return pc.math.clamp(pitch, this.pitchAngleMin, this.pitchAngleMax); | |
| }; | |
| OrbitCamera.prototype._clampYawAngle = function (yaw) { | |
| return pc.math.clamp(yaw, -this.yawAngleMax, -this.yawAngleMin); | |
| }; | |
| OrbitCamera.quatWithoutYaw = new pc.Quat(); | |
| OrbitCamera.yawOffset = new pc.Quat(); | |
| // ----- REVISED PITCH CALCULATION ----- | |
| // Modify _calcPitch so that horizontal (looking straight ahead) returns 0, | |
| // and looking overhead returns -90. | |
| // This change ensures that with JSON (minAngle: -90, maxAngle: 0) the allowed pitch is strictly between -90 and 0. | |
| OrbitCamera.prototype._calcPitch = function (quat, yaw) { | |
| var quatWithoutYaw = OrbitCamera.quatWithoutYaw; | |
| var yawOffset = OrbitCamera.yawOffset; | |
| yawOffset.setFromEulerAngles(0, -yaw, 0); | |
| quatWithoutYaw.mul2(yawOffset, quat); | |
| var transformedForward = new pc.Vec3(); | |
| quatWithoutYaw.transformVector(pc.Vec3.FORWARD, transformedForward); | |
| // Here we swap the sign of the computed angle so that: | |
| // - When the camera is horizontal, transformedForward.y is 0 and the result is 0. | |
| // - When the camera is overhead, transformedForward.y is negative and the result is -90. | |
| return Math.atan2(-transformedForward.y, -transformedForward.z) * pc.math.RAD_TO_DEG; | |
| }; | |
| //////////////////////////////////////////////////////////////////////////////// | |
| // Orbit Camera Mouse Input Script // | |
| //////////////////////////////////////////////////////////////////////////////// | |
| var OrbitCameraInputMouse = pc.createScript('orbitCameraInputMouse'); | |
| OrbitCameraInputMouse.attributes.add('orbitSensitivity', { | |
| type: 'number', | |
| default: 0.3, | |
| title: 'Orbit Sensitivity', | |
| description: 'How fast the camera moves around the orbit. Higher is faster' | |
| }); | |
| OrbitCameraInputMouse.attributes.add('distanceSensitivity', { | |
| type: 'number', | |
| default: 0.4, | |
| title: 'Distance Sensitivity', | |
| description: 'How fast the camera moves in and out. Higher is faster' | |
| }); | |
| OrbitCameraInputMouse.prototype.initialize = function () { | |
| this.orbitCamera = this.entity.script.orbitCamera; | |
| if (this.orbitCamera) { | |
| var self = this; | |
| var onMouseOut = function (e) { self.onMouseOut(e); }; | |
| this.app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this); | |
| this.app.mouse.on(pc.EVENT_MOUSEUP, this.onMouseUp, this); | |
| this.app.mouse.on(pc.EVENT_MOUSEMOVE, this.onMouseMove, this); | |
| this.app.mouse.on(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this); | |
| window.addEventListener('mouseout', onMouseOut, false); | |
| this.on('destroy', function () { | |
| this.app.mouse.off(pc.EVENT_MOUSEDOWN, this.onMouseDown, this); | |
| this.app.mouse.off(pc.EVENT_MOUSEUP, this.onMouseUp, this); | |
| this.app.mouse.off(pc.EVENT_MOUSEMOVE, this.onMouseMove, this); | |
| this.app.mouse.off(pc.EVENT_MOUSEWHEEL, this.onMouseWheel, this); | |
| window.removeEventListener('mouseout', onMouseOut, false); | |
| }); | |
| } | |
| this.app.mouse.disableContextMenu(); | |
| this.lookButtonDown = false; | |
| this.panButtonDown = false; | |
| this.lastPoint = new pc.Vec2(); | |
| }; | |
| OrbitCameraInputMouse.fromWorldPoint = new pc.Vec3(); | |
| OrbitCameraInputMouse.toWorldPoint = new pc.Vec3(); | |
| OrbitCameraInputMouse.worldDiff = new pc.Vec3(); | |
| OrbitCameraInputMouse.prototype.pan = function (screenPoint) { | |
| var fromWorldPoint = OrbitCameraInputMouse.fromWorldPoint; | |
| var toWorldPoint = OrbitCameraInputMouse.toWorldPoint; | |
| var worldDiff = OrbitCameraInputMouse.worldDiff; | |
| var camera = this.entity.camera; | |
| var distance = this.orbitCamera.distance; | |
| camera.screenToWorld(screenPoint.x, screenPoint.y, distance, fromWorldPoint); | |
| camera.screenToWorld(this.lastPoint.x, this.lastPoint.y, distance, toWorldPoint); | |
| worldDiff.sub2(toWorldPoint, fromWorldPoint); | |
| this.orbitCamera.pivotPoint.add(worldDiff); | |
| var pitchRadians = this.orbitCamera.pitch * pc.math.DEG_TO_RAD; | |
| var minPivotY = this.orbitCamera.distance * Math.sin(pitchRadians); | |
| if (this.orbitCamera.pivotPoint.y < minPivotY) { | |
| this.orbitCamera.pivotPoint.y = minPivotY; | |
| } | |
| }; | |
| OrbitCameraInputMouse.prototype.onMouseDown = function (event) { | |
| switch (event.button) { | |
| case pc.MOUSEBUTTON_LEFT: | |
| this.panButtonDown = true; | |
| break; | |
| case pc.MOUSEBUTTON_MIDDLE: | |
| case pc.MOUSEBUTTON_RIGHT: | |
| this.lookButtonDown = true; | |
| break; | |
| } | |
| }; | |
| OrbitCameraInputMouse.prototype.onMouseUp = function (event) { | |
| switch (event.button) { | |
| case pc.MOUSEBUTTON_LEFT: | |
| this.panButtonDown = false; | |
| break; | |
| case pc.MOUSEBUTTON_MIDDLE: | |
| case pc.MOUSEBUTTON_RIGHT: | |
| this.lookButtonDown = false; | |
| break; | |
| } | |
| }; | |
| OrbitCameraInputMouse.prototype.onMouseMove = function (event) { | |
| if (this.lookButtonDown) { | |
| this.orbitCamera.pitch -= event.dy * this.orbitSensitivity; | |
| this.orbitCamera.yaw -= event.dx * this.orbitSensitivity; | |
| } else if (this.panButtonDown) { | |
| this.pan(new pc.Vec2(event.x, event.y)); | |
| } | |
| this.lastPoint.set(event.x, event.y); | |
| }; | |
| OrbitCameraInputMouse.prototype.onMouseWheel = function (event) { | |
| if (this.entity.camera.projection === pc.PROJECTION_PERSPECTIVE) { | |
| this.orbitCamera.distance -= event.wheelDelta * this.distanceSensitivity * (this.orbitCamera.distance * 0.1); | |
| } else { | |
| this.orbitCamera.orthoHeight -= event.wheelDelta * this.distanceSensitivity * (this.orbitCamera.orthoHeight * 0.1); | |
| } | |
| event.event.preventDefault(); | |
| }; | |
| OrbitCameraInputMouse.prototype.onMouseOut = function (event) { | |
| this.lookButtonDown = false; | |
| this.panButtonDown = false; | |
| }; | |
| //////////////////////////////////////////////////////////////////////////////// | |
| // Orbit Camera Touch Input Script // | |
| //////////////////////////////////////////////////////////////////////////////// | |
| var OrbitCameraInputTouch = pc.createScript('orbitCameraInputTouch'); | |
| OrbitCameraInputTouch.attributes.add('orbitSensitivity', { | |
| type: 'number', | |
| default: 0.6, | |
| title: 'Orbit Sensitivity', | |
| description: 'How fast the camera moves around the orbit. Higher is faster' | |
| }); | |
| OrbitCameraInputTouch.attributes.add('distanceSensitivity', { | |
| type: 'number', | |
| default: 0.5, | |
| title: 'Distance Sensitivity', | |
| description: 'How fast the camera moves in and out. Higher is faster' | |
| }); | |
| OrbitCameraInputTouch.prototype.initialize = function () { | |
| this.orbitCamera = this.entity.script.orbitCamera; | |
| this.lastTouchPoint = new pc.Vec2(); | |
| this.lastPinchMidPoint = new pc.Vec2(); | |
| this.lastPinchDistance = 0; | |
| if (this.orbitCamera && this.app.touch) { | |
| this.app.touch.on(pc.EVENT_TOUCHSTART, this.onTouchStartEndCancel, this); | |
| this.app.touch.on(pc.EVENT_TOUCHEND, this.onTouchStartEndCancel, this); | |
| this.app.touch.on(pc.EVENT_TOUCHCANCEL, this.onTouchStartEndCancel, this); | |
| this.app.touch.on(pc.EVENT_TOUCHMOVE, this.onTouchMove, this); | |
| this.on('destroy', function () { | |
| this.app.touch.off(pc.EVENT_TOUCHSTART, this.onTouchStartEndCancel, this); | |
| this.app.touch.off(pc.EVENT_TOUCHEND, this.onTouchStartEndCancel, this); | |
| this.app.touch.off(pc.EVENT_TOUCHCANCEL, this.onTouchStartEndCancel, this); | |
| this.app.touch.off(pc.EVENT_TOUCHMOVE, this.onTouchMove, this); | |
| }); | |
| } | |
| }; | |
| OrbitCameraInputTouch.prototype.getPinchDistance = function (pointA, pointB) { | |
| var dx = pointA.x - pointB.x; | |
| var dy = pointA.y - pointB.y; | |
| return Math.sqrt((dx * dx) + (dy * dy)); | |
| }; | |
| OrbitCameraInputTouch.prototype.calcMidPoint = function (pointA, pointB, result) { | |
| result.set(pointB.x - pointA.x, pointB.y - pointA.y); | |
| result.mulScalar(0.5); | |
| result.x += pointA.x; | |
| result.y += pointA.y; | |
| }; | |
| OrbitCameraInputTouch.prototype.onTouchStartEndCancel = function (event) { | |
| var touches = event.touches; | |
| if (touches.length === 1) { | |
| this.lastTouchPoint.set(touches[0].x, touches[0].y); | |
| } else if (touches.length === 2) { | |
| this.lastPinchDistance = this.getPinchDistance(touches[0], touches[1]); | |
| this.calcMidPoint(touches[0], touches[1], this.lastPinchMidPoint); | |
| } | |
| }; | |
| OrbitCameraInputTouch.fromWorldPoint = new pc.Vec3(); | |
| OrbitCameraInputTouch.toWorldPoint = new pc.Vec3(); | |
| OrbitCameraInputTouch.worldDiff = new pc.Vec3(); | |
| OrbitCameraInputTouch.prototype.pan = function (midPoint) { | |
| var fromWorldPoint = OrbitCameraInputTouch.fromWorldPoint; | |
| var toWorldPoint = OrbitCameraInputTouch.toWorldPoint; | |
| var worldDiff = OrbitCameraInputTouch.worldDiff; | |
| var camera = this.entity.camera; | |
| var distance = this.orbitCamera.distance; | |
| camera.screenToWorld(midPoint.x, midPoint.y, distance, fromWorldPoint); | |
| camera.screenToWorld(this.lastPinchMidPoint.x, this.lastPinchMidPoint.y, distance, toWorldPoint); | |
| worldDiff.sub2(toWorldPoint, fromWorldPoint); | |
| this.orbitCamera.pivotPoint.add(worldDiff); | |
| var pitchRadians = this.orbitCamera.pitch * pc.math.DEG_TO_RAD; | |
| var minPivotY = this.orbitCamera.distance * Math.sin(pitchRadians); | |
| if (this.orbitCamera.pivotPoint.y < minPivotY) { | |
| this.orbitCamera.pivotPoint.y = minPivotY; | |
| } | |
| }; | |
| OrbitCameraInputTouch.pinchMidPoint = new pc.Vec2(); | |
| OrbitCameraInputTouch.prototype.onTouchMove = function (event) { | |
| var pinchMidPoint = OrbitCameraInputTouch.pinchMidPoint; | |
| var touches = event.touches; | |
| if (touches.length === 1) { | |
| var touch = touches[0]; | |
| this.orbitCamera.pitch -= (touch.y - this.lastTouchPoint.y) * this.orbitSensitivity; | |
| this.orbitCamera.yaw -= (touch.x - this.lastTouchPoint.x) * this.orbitSensitivity; | |
| this.lastTouchPoint.set(touch.x, touch.y); | |
| } else if (touches.length === 2) { | |
| var currentPinchDistance = this.getPinchDistance(touches[0], touches[1]); | |
| var diffInPinchDistance = currentPinchDistance - this.lastPinchDistance; | |
| this.lastPinchDistance = currentPinchDistance; | |
| this.orbitCamera.distance -= (diffInPinchDistance * this.distanceSensitivity * 0.1) * (this.orbitCamera.distance * 0.1); | |
| this.calcMidPoint(touches[0], touches[1], pinchMidPoint); | |
| this.pan(pinchMidPoint); | |
| this.lastPinchMidPoint.copy(pinchMidPoint); | |
| } | |
| }; | |