本文纯属个人见解,可能是正经的胡扯。
最近在支持工作中有部分客户提出能否模拟导航罗盘的操作,包括俯仰和旋转等。在看不到源码的情况下,小编我只能通过操作现象来推测。在旋转时,首先看到的是相机似乎是绕轴的旋转,在俯仰时,相机似乎又是绕点固定半径操作。以上的一些迹象表明,相机应该是被锁死在一个点上。话不多说,下面来看代码:
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)
}
}
}
罗盘操作模拟
网友评论