提交 fa2c8ee3 编写于 作者: N nicolo.carpignoli

fixed hide objects when minDistance is set

上级 f78d99a7
......@@ -5838,7 +5838,7 @@ AFRAME.registerComponent('gps-camera', {
* @param {Position} dest
* @param {Boolean} isPlace
*
* @returns {number} distance
* @returns {number} distance | Number.MAX_SAFE_INTEGER
*/
computeDistanceMeters: function (src, dest, isPlace) {
var dlongitude = THREE.Math.degToRad(dest.longitude - src.longitude);
......@@ -5849,7 +5849,7 @@ AFRAME.registerComponent('gps-camera', {
var distance = angle * 6378160;
// if function has been called for a place, and if it's too near and a min distance has been set,
// set a very high distance to hide the object
// return max distance possible - to be handled by the method caller
if (isPlace && this.data.minDistance && this.data.minDistance > 0 && distance < this.data.minDistance) {
return Number.MAX_SAFE_INTEGER;
}
......@@ -5973,7 +5973,8 @@ AFRAME.registerComponent('gps-entity-place', {
latitude: this.data.latitude,
};
var distance = this._cameraGps.computeDistanceMeters(ev.detail.position, dstCoords, true);
// it's actually a 'distance place', but we don't call it with last param, because we want to retrieve distance even if it's < minDistance property
var distance = this._cameraGps.computeDistanceMeters(ev.detail.position, dstCoords);
this.el.setAttribute('distance', distance);
this.el.setAttribute('distanceMsg', formatDistance(distance));
......@@ -5999,6 +6000,7 @@ AFRAME.registerComponent('gps-entity-place', {
*/
_updatePosition: function () {
var position = { x: 0, y: this.el.getAttribute('position').y || 0, z: 0 }
var hideEntity = false;
// update position.x
var dstCoords = {
......@@ -6007,6 +6009,12 @@ AFRAME.registerComponent('gps-entity-place', {
};
position.x = this._cameraGps.computeDistanceMeters(this._cameraGps.originCoords, dstCoords, true);
// place has to be hide
if (position.x === Number.MAX_SAFE_INTEGER) {
hideEntity = true;
}
this._positionXDebug = position.x;
position.x *= this.data.longitude > this._cameraGps.originCoords.longitude ? 1 : -1;
......@@ -6018,11 +6026,24 @@ AFRAME.registerComponent('gps-entity-place', {
};
position.z = this._cameraGps.computeDistanceMeters(this._cameraGps.originCoords, dstCoords, true);
// place has to be hide
if (position.z === Number.MAX_SAFE_INTEGER) {
hideEntity = true;
}
position.z *= this.data.latitude > this._cameraGps.originCoords.latitude ? -1 : 1;
if(position.y !== 0) {
if (position.y !== 0) {
position.y = position.y - this._cameraGps.originCoords.altitude;
}
if (hideEntity) {
this.el.setAttribute('visible', false);
} else {
this.el.setAttribute('visible', true);
}
// update element's position in 3D world
this.el.setAttribute('position', position);
},
......
此差异已折叠。
......@@ -245,7 +245,7 @@ AFRAME.registerComponent('gps-camera', {
* @param {Position} dest
* @param {Boolean} isPlace
*
* @returns {number} distance
* @returns {number} distance | Number.MAX_SAFE_INTEGER
*/
computeDistanceMeters: function (src, dest, isPlace) {
var dlongitude = THREE.Math.degToRad(dest.longitude - src.longitude);
......@@ -256,7 +256,7 @@ AFRAME.registerComponent('gps-camera', {
var distance = angle * 6378160;
// if function has been called for a place, and if it's too near and a min distance has been set,
// set a very high distance to hide the object
// return max distance possible - to be handled by the method caller
if (isPlace && this.data.minDistance && this.data.minDistance > 0 && distance < this.data.minDistance) {
return Number.MAX_SAFE_INTEGER;
}
......
......@@ -34,7 +34,8 @@ AFRAME.registerComponent('gps-entity-place', {
latitude: this.data.latitude,
};
var distance = this._cameraGps.computeDistanceMeters(ev.detail.position, dstCoords, true);
// it's actually a 'distance place', but we don't call it with last param, because we want to retrieve distance even if it's < minDistance property
var distance = this._cameraGps.computeDistanceMeters(ev.detail.position, dstCoords);
this.el.setAttribute('distance', distance);
this.el.setAttribute('distanceMsg', formatDistance(distance));
......@@ -60,6 +61,7 @@ AFRAME.registerComponent('gps-entity-place', {
*/
_updatePosition: function () {
var position = { x: 0, y: this.el.getAttribute('position').y || 0, z: 0 }
var hideEntity = false;
// update position.x
var dstCoords = {
......@@ -68,6 +70,12 @@ AFRAME.registerComponent('gps-entity-place', {
};
position.x = this._cameraGps.computeDistanceMeters(this._cameraGps.originCoords, dstCoords, true);
// place has to be hide
if (position.x === Number.MAX_SAFE_INTEGER) {
hideEntity = true;
}
this._positionXDebug = position.x;
position.x *= this.data.longitude > this._cameraGps.originCoords.longitude ? 1 : -1;
......@@ -79,11 +87,24 @@ AFRAME.registerComponent('gps-entity-place', {
};
position.z = this._cameraGps.computeDistanceMeters(this._cameraGps.originCoords, dstCoords, true);
// place has to be hide
if (position.z === Number.MAX_SAFE_INTEGER) {
hideEntity = true;
}
position.z *= this.data.latitude > this._cameraGps.originCoords.latitude ? -1 : 1;
if(position.y !== 0) {
if (position.y !== 0) {
position.y = position.y - this._cameraGps.originCoords.altitude;
}
if (hideEntity) {
this.el.setAttribute('visible', false);
} else {
this.el.setAttribute('visible', true);
}
// update element's position in 3D world
this.el.setAttribute('position', position);
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册