本文純屬個人見解婚温,可能是正經(jīng)的胡扯。
最近在支持工作中有部分客戶提出能否模擬導(dǎo)航羅盤的操作儡湾,包括俯仰和旋轉(zhuǎn)等特恬。在看不到源碼的情況下,小編我只能通過操作現(xiàn)象來推測徐钠。在旋轉(zhuǎn)時癌刽,首先看到的是相機似乎是繞軸的旋轉(zhuǎn),在俯仰時尝丐,相機似乎又是繞點固定半徑操作显拜。以上的一些跡象表明,相機應(yīng)該是被鎖死在一個點上爹袁。話不多說远荠,下面來看代碼:
function compassControlsimulation(scene) {
this.scene = scene
this.islocked = false
compassControlsimulation.prototype.lookat = function() {
var that = this
var pixcelx = that.scene.canvas.width / 2
var pixcely = that.scene.canvas.height / 2
var position = that.scene.pickPosition(new Cesium.Cartesian2(pixcelx, pixcely))
var transform = Cesium.Transforms.eastNorthUpToFixedFrame(position);
that.scene.camera.lookAtTransform(transform)
that.islocked = true
}
compassControlsimulation.prototype.unlookat = function() {
var that = this
that.scene.camera.lookAtTransform(Cesium.Matrix4.IDENTITY)
that.islocked = false
}
compassControlsimulation.prototype.rotatedown = function(value) {
var that = this
if (typeof value === "number" && that.islocked === true) {
that.scene.camera.rotateDown(value)
}
}
compassControlsimulation.prototype.rotateup = function(value) {
var that = this
if (typeof value === "number" && that.islocked === true) {
that.scene.camera.rotateUp(value)
}
}
compassControlsimulation.prototype.rotateleft = function(value) {
var that = this
if (typeof value === "number" && that.islocked === true) {
that.scene.camera.rotateLeft(value)
}
}
compassControlsimulation.prototype.rotateright = function(value) {
var that = this
if (typeof value === "number" && that.islocked === true) {
that.scene.camera.rotateRight(value)
}
}
}
羅盤操作模擬