Skip to content

Commit

Permalink
Debug and clean up globe control
Browse files Browse the repository at this point in the history
Add feature : Continue globe move, when mouse enters the sky
Add double click event in control
Proposal to fix error in compute of preSSE in camera

Fix error return undefined tile in getTile function
Fix error accuracy target globe
Fix error accuracy camera position
Fix error ApiGlobe.setCenter
  • Loading branch information
gchoqueux committed Oct 3, 2016
1 parent b3d6093 commit 7b94f76
Show file tree
Hide file tree
Showing 13 changed files with 451 additions and 286 deletions.
6 changes: 2 additions & 4 deletions src/Core/Commander/Interfaces/ApiInterface/ApiGlobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ ApiGlobe.prototype.removeImageryLayer = function(id) {
return false;
};


/**
* Add an elevation layer to the map. Elevations layers are used to build the terrain.
* Only one elevation layer is used, so if multiple layers cover the same area, the one
Expand Down Expand Up @@ -220,7 +219,7 @@ ApiGlobe.prototype.createSceneGlobe = function(coordCarto, viewerDiv) {
var debugMode = false;

//gLDebug = true; // true to support GLInspector addon
debugMode = true;
//debugMode = true;

var ellipsoid = new Ellipsoid({
x: 6378137,
Expand Down Expand Up @@ -530,8 +529,7 @@ ApiGlobe.prototype.computeDistance = function(p1, p2) {
*/

ApiGlobe.prototype.setCenter = function(coordinates) {

var position3D = this.scene.getEllipsoid().cartographicToCartesian(new GeoCoordinate().copyFromDegree(coordinates));
var position3D = this.scene.getEllipsoid().cartographicToCartesian(new GeoCoordinate(coordinates.longitude,coordinates.latitude,0,UNIT.DEGREE));
this.scene.currentControls().setCenter(position3D);
};

Expand Down
10 changes: 4 additions & 6 deletions src/Core/Commander/Providers/TileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
*
*/



import Provider from 'Core/Commander/Providers/Provider';
import Projection from 'Core/Geographic/Projection';
import TileGeometry from 'Globe/TileGeometry';
Expand All @@ -41,10 +39,10 @@ TileProvider.prototype.constructor = TileProvider;

TileProvider.prototype.preprocessLayer = function( /*layer*/ ) {
/* no-op */
}
};

TileProvider.prototype.getGeometry = function(bbox, cooWMTS) {
var geometry = undefined;
var geometry;
var n = Math.pow(2, cooWMTS.zoom + 1);
var part = Math.PI * 2.0 / n;

Expand Down Expand Up @@ -75,15 +73,15 @@ TileProvider.prototype.executeCommand = function(command) {
var parent = command.requester;

// build tile
var geometry = undefined; //getGeometry(bbox,tileCoord);
var geometry; //getGeometry(bbox,tileCoord);

var params = {
bbox: bbox,
zoom: tileCoord.zoom,
segment: 16,
center: null,
projected: null
}
};

var tile = new command.type(params, this.builder);

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Geographic/GeoCoordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var getCoordinateValue = function(unit,coord,id)

return mE.radToDeg(coord[id]);

}
};

var setCoordinateValue = function(unit,coord,id,value)
{
Expand All @@ -49,7 +49,7 @@ var setCoordinateValue = function(unit,coord,id,value)

return coord[id] = mE.degToRad(value);

}
};

var setCoordinate = function(coordinate,longitude, latitude, altitude,unit) {

Expand Down
76 changes: 23 additions & 53 deletions src/Core/Math/MathExtented.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,82 +48,52 @@ MathExt.RADTODEG = 180.0 / MathExt.PI;

MathExt.DEGTORAD = MathExt.PI / 180.0;

MathExt.radToDeg = function(rad)
{
MathExt.radToDeg = function(rad) {

return rad * MathExt.RADTODEG;
};

MathExt.degToRad = function(deg)
{
MathExt.degToRad = function(deg) {

return deg * MathExt.DEGTORAD;
};

MathExt.arrayDegToRad = function(arrayDeg)
{
if(arrayDeg)
{
MathExt.arrayDegToRad = function(arrayDeg) {

if(arrayDeg) {
for (var i = 0; i < arrayDeg.length; i++) {
arrayDeg[i]= MathExt.degToRad(arrayDeg[i]);
}
}
};

MathExt.arrayRadToDeg = function(arrayDeg)
{
if(arrayDeg)
{
MathExt.arrayRadToDeg = function(arrayDeg) {

if(arrayDeg) {
for (var i = 0; i < arrayDeg.length; i++) {
arrayDeg[i]= MathExt.radToDeg(arrayDeg[i]);
}
}
};

// TODO: Function in test :
MathExt.step = function(val,stepVal)
{
if(val<stepVal)
return 0.0;
else
return 1.0;
MathExt.step = function(val, stepVal) {

};
if(val<stepVal) {

MathExt.exp2 = function(expo)
{
return Math.pow(2,expo);
};
return 0.0;

MathExt.parseFloat2= function(str) {
var float = 0, sign, /*order,*/ mantissa,exp,
int = 0, multi = 1;
if (/^0x/.exec(str)) {
int = parseInt(str,16);
}else{
for (var i = str.length -1; i >=0; i -= 1) {
if (str.charCodeAt(i)>255) {
//console.log('Wrong string parametr');
return false;
}
int += str.charCodeAt(i) * multi;
multi *= 256;
}
}
sign = (int>>>31)?-1:1;
exp = (int >>> 23 & 0xff) - 127;
mantissa = ((int & 0x7fffff) + 0x800000).toString(2);
for (i=0; i<mantissa.length; i+=1){
float += parseInt(mantissa[i])? Math.pow(2,exp):0;
exp--;
else {

return 1.0;
}
return float*sign;
}

MathExt.decode32= function(rgba) {
var Sign = 1.0 - this.step(128.0,rgba[0])*2.0;
var Exponent = 2.0 * (rgba[0]%128.0) + this.step(128.0,rgba[1]) - 127.0;
var Mantissa = (rgba[1]%128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + this.parseFloat2(0x800000);
var Result = Sign * this.exp2(Exponent) * (Mantissa * this.exp2(-23.0 ));
return Result;
}
};

MathExt.exp2 = function(expo) {

return Math.pow(2, expo);

};

export default MathExt;
47 changes: 30 additions & 17 deletions src/Core/Math/Sphere.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import THREE from 'THREE';
import defaultValue from 'Core/defaultValue';


function Sphere(center,radius) {

this.center = defaultValue(center,new THREE.Vector3());
this.radius = defaultValue(radius,1.0);

this.center = center || new THREE.Vector3();
this.radius = radius || 1.0;
}

Sphere.prototype.constructor = Sphere;
Expand All @@ -23,23 +20,39 @@ Sphere.prototype.setRadius = function(radius) {

var vector = new THREE.Vector3();

Sphere.prototype.intersectWithRay = function(ray) {
//
Sphere.prototype.intersectWithRayNoMiss = function(ray) {

let pc = ray.closestPointToPoint(this.center);
let a = pc.length(),d,b;

// TODO: recompute mirror ray
// If the ray miss sphere, we recompute the new ray with point symetric to tangent sphere
if (a > this.radius) {
// mirror point is symetric of pc
// The mirror ray must pass through the point mirrorPoint
let mirrorPoint = pc.clone().setLength(this.radius*2 - a);

var pc = ray.closestPointToPoint(this.center);
var a = pc.length();
// Compute the new direction
d = ray.direction.subVectors(mirrorPoint,ray.origin).normalize();

if (a > this.radius)
return undefined; // new THREE.Vector3();
// Classic intersection with the new ray
pc = ray.closestPointToPoint(this.center);
a = pc.length();

if (ray.origin.length() > this.radius) {
var d = ray.direction.clone();
var b = Math.sqrt(this.radius * this.radius - a * a);
b = Math.sqrt(this.radius * this.radius - a * a);
d.setLength(b);

return vector.subVectors(pc, d);
} else
return undefined;
return vector.addVectors(pc, d);
}

}
// TODO: check all intersections : if (ray.origin.length() > this.radius)
d = ray.direction.clone();
b = Math.sqrt(this.radius * this.radius - a * a);
d.setLength(b);

return vector.subVectors(pc, d);

};

export default Sphere;
6 changes: 5 additions & 1 deletion src/Globe/Globe.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Globe.prototype = Object.create(Layer.prototype);
Globe.prototype.constructor = Globe;

/**
* @documentation: Rafrachi les mat�riaux en fonction du quadTree ORTHO
* @documentation: Rafrachi les materiaux en fonction du quadTree ORTHO
*
*/
Globe.prototype.QuadTreeToMaterial = function() {
Expand Down Expand Up @@ -223,6 +223,10 @@ Globe.prototype.getZoomLevel = function( /*id*/ ) {
return cO();
};

Globe.prototype.getTile = function(coordinate) {
return this.tiles.getTile(coordinate);
};

Globe.prototype.setRealisticLightingOn = function(bool) {

this.atmosphere.setRealisticOn(bool);
Expand Down
5 changes: 2 additions & 3 deletions src/Globe/TileMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ TileMesh.prototype.setUuid = function(uuid) {
TileMesh.prototype.getUuid = function(uuid) {

return this.materials[RendererConstant.ID].getUuid(uuid);
}
};

TileMesh.prototype.setColorLayerParameters = function(paramsTextureColor) {
this.materials[RendererConstant.FINAL].setParam(paramsTextureColor);
Expand Down Expand Up @@ -190,8 +190,7 @@ TileMesh.prototype.setTextureElevation = function(elevation) {
return;
}

var texture = undefined;
var pitScale;
var texture, pitScale;

if (elevation) {
texture = elevation.texture;
Expand Down
57 changes: 44 additions & 13 deletions src/Renderer/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ function Camera(width, height, debug) {
this.frustum = new THREE.Frustum();
this.width = width;
this.height = height;
this.Hypotenuse = Math.sqrt(this.width * this.width + this.height * this.height);

var radAngle = this.FOV * Math.PI / 180;
this.HFOV = 2.0 * Math.atan(Math.tan(radAngle * 0.5) / this.ratio); // TODO surement faux
this.HYFOV = 2.0 * Math.atan(Math.tan(radAngle * 0.5) * this.Hypotenuse / this.width);
this.preSSE = this.Hypotenuse * (2.0 * Math.tan(this.HYFOV * 0.5));
this.updatePreSSE();

this.cameraHelper = debug ? new THREE.CameraHelper(this.camera3D) : undefined;
}
Expand All @@ -57,10 +53,42 @@ Camera.prototype.camHelper = function() {

};

Camera.prototype.updatePreSSE = function() {

this.Hypotenuse = Math.sqrt(this.width * this.width + this.height * this.height);
var radAngle = this.FOV * Math.PI / 180;

this.HFOV = 2.0 * Math.atan(Math.tan(radAngle * 0.5) / this.ratio); // TODO: not correct -> see new preSSE
this.HYFOV = 2.0 * Math.atan(Math.tan(radAngle * 0.5) * this.Hypotenuse / this.width);
this.preSSE = this.Hypotenuse * (2.0 * Math.tan(this.HYFOV * 0.5));

/* TODO: New preSSE but problem on Windows
var d = this.height / (2*Math.tan(radAngle/2));
//TODO: Verify with arrow helper
this.HFOV = 2*Math.atan((this.width/2)/d);
this.HYFOV = 2*Math.atan((this.Hypotenuse/2)/d);
this.preSSE = this.Hypotenuse * (2.0 * Math.tan(this.HYFOV * 0.5));
*/
};

Camera.prototype.createCamHelper = function() {

this.cameraHelper = new THREE.CameraHelper(this.camera3D);

var dir = new THREE.Vector3( 0, 0, -1 );
var quaternion = new THREE.Quaternion();

quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), this.HFOV/2);
dir.applyQuaternion( quaternion );
var origin = new THREE.Vector3();
var length = 100000000;
var hex = 0xffff00;

this.arrowHelper = new THREE.ArrowHelper( dir, origin, length, hex );
this.cameraHelper.add(this.arrowHelper);

};

Camera.prototype.matrixWorldInverse = function() {
Expand All @@ -74,18 +102,21 @@ Camera.prototype.resize = function(width, height) {
this.height = height;
this.ratio = width / height;

this.Hypotenuse = Math.sqrt(this.width * this.width + this.height * this.height);

var radAngle = this.FOV * Math.PI / 180;

this.HYFOV = 2.0 * Math.atan(Math.tan(radAngle * 0.5) * this.Hypotenuse / this.width);

this.preSSE = this.Hypotenuse * (2.0 * Math.tan(this.HYFOV * 0.5));
this.updatePreSSE();

this.camera3D.aspect = this.ratio;

this.camera3D.updateProjectionMatrix();

if(this.cameraHelper) {
var dir = new THREE.Vector3( 0, 0, -1 );
var quaternion = new THREE.Quaternion();
quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), this.HFOV/2);
dir.applyQuaternion( quaternion );

this.arrowHelper.setDirection(dir);
this.cameraHelper.update();
}

};

Camera.prototype.computeNodeSSE = function(node) {
Expand Down
Loading

0 comments on commit 7b94f76

Please sign in to comment.