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
  • Loading branch information
gchoqueux committed Sep 16, 2016
1 parent cef8c0a commit 62c69a4
Show file tree
Hide file tree
Showing 10 changed files with 380 additions and 196 deletions.
3 changes: 1 addition & 2 deletions src/Core/Commander/Interfaces/ApiInterface/ApiGlobe.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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 @@ -213,7 +212,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
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
25 changes: 17 additions & 8 deletions src/Core/Math/Sphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,28 @@ var vector = new THREE.Vector3();
Sphere.prototype.intersectWithRay = function(ray) {

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

// TODO: recompute mirror ray
if (a > this.radius)
return undefined; // new THREE.Vector3();
{
var mirrorPoint = pc.clone().setLength(this.radius*2 - a);
d = ray.direction.subVectors(mirrorPoint,ray.origin).normalize();
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);

}

Expand Down
4 changes: 4 additions & 0 deletions src/Globe/Globe.js
Original file line number Diff line number Diff line change
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 @@ -131,7 +131,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 @@ -231,8 +231,7 @@ TileMesh.prototype.setTextureElevation = function(elevation) {
return;
}

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

if (elevation === -1) { // No texture
this.currentElevation = -2;
Expand Down
58 changes: 45 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,22 @@ 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
11 changes: 5 additions & 6 deletions src/Renderer/LayeredMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var getColorAtIdUv = function(nbTex) {
}

return fooTexture;
}
};

var LayeredMaterial = function(id) {

Expand Down Expand Up @@ -142,12 +142,11 @@ var LayeredMaterial = function(id) {
this.uniforms.lightingOn = {
type: "i",
value: gfxEngine().lightingOn
},
this.uniforms.lightPosition = {
type: "v3",
value: new THREE.Vector3(-0.5, 0.0, 1.0)
};

this.uniforms.lightPosition = {
type: "v3",
value: new THREE.Vector3(-0.5, 0.0, 1.0)
};
this.setUuid(id || 0);
this.wireframe = false;
//this.wireframe = true;
Expand Down
Loading

0 comments on commit 62c69a4

Please sign in to comment.