区块链技术博客
www.b2bchain.cn

Babylon.js 构建 地球,支持切片地图 (三)求职学习资料

本文介绍了Babylon.js 构建 地球,支持切片地图 (三)求职学习资料,有助于帮助完成毕业设计以及求职,是一篇很好的资料。

对技术面试,学习经验等有一些体会,在此分享。

继续上一篇camera 的类

Babylon.js 构建 地球,支持切片地图 (三)

针对CameraEarthWheelControl
“`javascript
const BABYLON = require(‘babylonjs’);
import {EarthTool} from ‘./EarthTool’;

export class CameraEarthWheelControl {
constructor(camera) {
this.camera = camera;
this.wheelPrecision = 3,
this.wheelDeltaPercentage = 0,
this._maxRadius = 150,
this._minRadius = 50
}
getTypeName() {
return null
}
getClassName() {
return “CameraEarthWheelControl”
}
getSimpleName() {
return “earthmousewheel”
}
computeDeltaFromMouseWheelLegacyEvent(e, t) {
let i = 0;
const n = .01 * e * this.wheelDeltaPercentage * t;
return i = e > 0 ? n / (1 + this.wheelDeltaPercentage) : n * (1 + this.wheelDeltaPercentage),
i
}
attachControl(e, t) {
const i = BABYLON.Vector2.Zero();
this._wheel = (e,i)=>{
if (e.type !== BABYLON.PointerEventTypes.POINTERWHEEL)
return;
const n = e.event;
let r = 0
, o = 0;
if (o = n.wheelDelta ? n.wheelDelta : 60 * -(n.deltaY || n.detail),
this.wheelDeltaPercentage) {
if (r = this.computeDeltaFromMouseWheelLegacyEvent(o, this.camera.radius),
r > 0) {
let e = this.camera.radius
, t = this.camera.inertialRadiusOffset + r;
for (let i = 0; i < 20 && Math.abs(t) > .001; i++)
e -= t,
t *= this.camera.inertia;
e = BABYLON.Scalar.Clamp(e, 0, Number.MAX_VALUE),
r = this.computeDeltaFromMouseWheelLegacyEvent(o, e)
}
} else {
r = o > 0 ? EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, 10, 1e-4) : -EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, 10, 1e-4);
let e = EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, .9, .2);
e > .9 ? e = .9 : e < 0 && (e = 0), this.camera.inertia = e } r && (this.camera.inertialRadiusOffset += r), n.preventDefault && (t || n.preventDefault()) } , this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, BABYLON.PointerEventTypes.POINTERWHEEL), this.camera.getScene(), this._pointer = ()=>{
const e = (this.camera.latLonAtmouse.x – i.x) * Math.PI / 180
, t = (this.camera.latLonAtmouse.y – i.y) * Math.PI / 180;
this.camera.distance && (this.camera.inertialAlphaOffset += t / 5,

继续上一篇camera 的类

Babylon.js 构建 地球,支持切片地图 (三)

针对CameraEarthWheelControl
“`javascript
const BABYLON = require(‘babylonjs’);
import {EarthTool} from ‘./EarthTool’;

export class CameraEarthWheelControl {
constructor(camera) {
this.camera = camera;
this.wheelPrecision = 3,
this.wheelDeltaPercentage = 0,
this._maxRadius = 150,
this._minRadius = 50
}
getTypeName() {
return null
}
getClassName() {
return “CameraEarthWheelControl”
}
getSimpleName() {
return “earthmousewheel”
}
computeDeltaFromMouseWheelLegacyEvent(e, t) {
let i = 0;
const n = .01 * e * this.wheelDeltaPercentage * t;
return i = e > 0 ? n / (1 + this.wheelDeltaPercentage) : n * (1 + this.wheelDeltaPercentage),
i
}
attachControl(e, t) {
const i = BABYLON.Vector2.Zero();
this._wheel = (e,i)=>{
if (e.type !== BABYLON.PointerEventTypes.POINTERWHEEL)
return;
const n = e.event;
let r = 0
, o = 0;
if (o = n.wheelDelta ? n.wheelDelta : 60 * -(n.deltaY || n.detail),
this.wheelDeltaPercentage) {
if (r = this.computeDeltaFromMouseWheelLegacyEvent(o, this.camera.radius),
r > 0) {
let e = this.camera.radius
, t = this.camera.inertialRadiusOffset + r;
for (let i = 0; i < 20 && Math.abs(t) > .001; i++)
e -= t,
t *= this.camera.inertia;
e = BABYLON.Scalar.Clamp(e, 0, Number.MAX_VALUE),
r = this.computeDeltaFromMouseWheelLegacyEvent(o, e)
}
} else {
r = o > 0 ? EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, 10, 1e-4) : -EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, 10, 1e-4);
let e = EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, .9, .2);
e > .9 ? e = .9 : e < 0 && (e = 0), this.camera.inertia = e } r && (this.camera.inertialRadiusOffset += r), n.preventDefault && (t || n.preventDefault()) } , this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, BABYLON.PointerEventTypes.POINTERWHEEL), this.camera.getScene(), this._pointer = ()=>{
const e = (this.camera.latLonAtmouse.x – i.x) * Math.PI / 180
, t = (this.camera.latLonAtmouse.y – i.y) * Math.PI / 180;
this.camera.distance && (this.camera.inertialAlphaOffset += t / 5,

继续上一篇camera 的类

Babylon.js 构建 地球,支持切片地图 (三)

针对CameraEarthWheelControl
“`javascript
const BABYLON = require(‘babylonjs’);
import {EarthTool} from ‘./EarthTool’;

export class CameraEarthWheelControl {
constructor(camera) {
this.camera = camera;
this.wheelPrecision = 3,
this.wheelDeltaPercentage = 0,
this._maxRadius = 150,
this._minRadius = 50
}
getTypeName() {
return null
}
getClassName() {
return “CameraEarthWheelControl”
}
getSimpleName() {
return “earthmousewheel”
}
computeDeltaFromMouseWheelLegacyEvent(e, t) {
let i = 0;
const n = .01 * e * this.wheelDeltaPercentage * t;
return i = e > 0 ? n / (1 + this.wheelDeltaPercentage) : n * (1 + this.wheelDeltaPercentage),
i
}
attachControl(e, t) {
const i = BABYLON.Vector2.Zero();
this._wheel = (e,i)=>{
if (e.type !== BABYLON.PointerEventTypes.POINTERWHEEL)
return;
const n = e.event;
let r = 0
, o = 0;
if (o = n.wheelDelta ? n.wheelDelta : 60 * -(n.deltaY || n.detail),
this.wheelDeltaPercentage) {
if (r = this.computeDeltaFromMouseWheelLegacyEvent(o, this.camera.radius),
r > 0) {
let e = this.camera.radius
, t = this.camera.inertialRadiusOffset + r;
for (let i = 0; i < 20 && Math.abs(t) > .001; i++)
e -= t,
t *= this.camera.inertia;
e = BABYLON.Scalar.Clamp(e, 0, Number.MAX_VALUE),
r = this.computeDeltaFromMouseWheelLegacyEvent(o, e)
}
} else {
r = o > 0 ? EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, 10, 1e-4) : -EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, 10, 1e-4);
let e = EarthTool.MapNumberToInterval(this.camera.radius, 220, 50, .9, .2);
e > .9 ? e = .9 : e < 0 && (e = 0), this.camera.inertia = e } r && (this.camera.inertialRadiusOffset += r), n.preventDefault && (t || n.preventDefault()) } , this._observer = this.camera.getScene().onPointerObservable.add(this._wheel, BABYLON.PointerEventTypes.POINTERWHEEL), this.camera.getScene(), this._pointer = ()=>{
const e = (this.camera.latLonAtmouse.x – i.x) * Math.PI / 180
, t = (this.camera.latLonAtmouse.y – i.y) * Math.PI / 180;
this.camera.distance && (this.camera.inertialAlphaOffset += t / 5,

部分转自互联网,侵权删除联系

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » Babylon.js 构建 地球,支持切片地图 (三)求职学习资料
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们