Added distance and time calculations. General tweaks.

This commit is contained in:
Rob L committed 2016-07-22 10:23:16 -04:00
1 parent 2de0aa215c
commit a20a24fd76
5 files changed
+220 -56

No files matched your search

+66 -16
View File
@@ -1,36 +1,71 @@
var lastInputBox;
$(document).ready(function() {
// Controls menu hide/show
$('#hotdog').click(function(){
$('#controls').toggleClass("active");
});
// Reset view
$('.reset-container').click(function(){ reset_view(); });
$('#submitfindbyname').click( function() {
});
// Reset view
$('.reset-container').click(function(){ reset_view(); });
$('#submitfindbyname').click(function() {
var selected = $('#findbyselect option:selected').text();
zoomfocus(selected);
});
$('#calctnd').click(function() {
$('#cal_start').html( $('#pointa option:selected').text() );
$('#cal_end').html( $('#pointb option:selected').text() );
$('#cal_speed').html( $('#speed').val() +" " + $('#speedunit option:selected').val() );
var dist = calcDist( $('#pointa option:selected').text(), $('#pointb option:selected').text() );
var eta = calcETA({'speed': $('#speed').val(), 'unit': $('#speedunit option:selected').val()},dist)
$('#cal_eta').html( timeformat(eta) );
$('#cal_dist').html( dist.toFixed(2) + " PC");
});
$("#pointa").focus(function() {
lastInputBox = "pointa";
// console.log('Updating last touched box to : ' + lastInputBox)
});
$("#pointb").focus(function() {
lastInputBox = "pointb";
// console.log('Updating last touched box to : ' + lastInputBox)
});
});
function populateUserFields() {
//Populate find by select dropdown
var types = [];
var checkboxes = document.getElementsByName("objtype");
var types = [];
var checkboxes = document.getElementsByName("objtype");
for (var type in checkboxes) {
if(checkboxes[type].checked) {
types[type] = checkboxes[type].value;
if(checkboxes[type].checked) {
types[type] = checkboxes[type].value;
}
}
}
var option = '';
for (var type in types){
for ( var key in listobjects(types[type]) ){
option += '<option value="'+ escapeHTML(key) + '">' + escapeHTML(key) + '</option>';
}
}
$('#findbyselect').html(option);
// Populate pointa and pointb dropdowns
var types = ['planets','stations'];
for (var type in types){
for ( var key in listobjects(types[type]) ){
option += '<option value="'+ escapeHTML(key) + '">' + escapeHTML(key) + '</option>';
}
}
$('#pointa').html(option);
$('#pointb').html(option);
}
function openTab(evt,tabName) {
@@ -47,12 +82,27 @@ function openTab(evt,tabName) {
evt.currentTarget.className += " wvg-tab-active";
}
function escapeHTML(text)
{
function escapeHTML(text) {
var chr = { '"': '"', '&': '&', '<': '[', '>': ']' };
function abc(a)
{
return chr[a];
}
return text.replace(/[\"&<>]/g, abc);
}
}
function timeformat(secs) {
var s = new Decimal(secs);
var hours = new Decimal(secs / 3600);
var h = hours.floor(); //Get whole hours
s = s - (h * 3600);
var m = new Decimal(s / 60); //Get remaining minutes
m = m.floor();
s = s - (m * 60 );
s = Math.round(s,0)
console.log("Hours :"+ h);
console.log("Minutes :"+ m);
console.log("Seconds :"+ s);
console.log("Input :"+ secs);
return h+":"+(m < 10 ? '0'+m : m)+":"+(s < 10 ? '0'+s : s); //zero padding on minutes and seconds
}
+3
View File
@@ -0,0 +1,3 @@
/* decimal.js v6.0.0 https://github.com/MikeMcl/decimal.js/LICENCE */
!function(n){"use strict";function e(n){var e,i,t,r=n.length-1,s="",o=n[0];if(r>0){for(s+=o,e=1;r>e;e++)t=n[e]+"",i=Rn-t.length,i&&(s+=l(i)),s+=t;o=n[e],t=o+"",i=Rn-t.length,i&&(s+=l(i))}else if(0===o)return"0";for(;o%10===0;)o/=10;return s+o}function i(n,e,i){if(n!==~~n||e>n||n>i)throw Error(Mn+n)}function t(n,e,i,t){var r,s,o,u;for(s=n[0];s>=10;s/=10)--e;return--e<0?(e+=Rn,r=0):(r=Math.ceil((e+1)/Rn),e%=Rn),s=On(10,Rn-e),u=n[r]%s|0,null==t?3>e?(0==e?u=u/100|0:1==e&&(u=u/10|0),o=4>i&&99999==u||i>3&&49999==u||5e4==u||0==u):o=(4>i&&u+1==s||i>3&&u+1==s/2)&&(n[r+1]/s/100|0)==On(10,e-2)-1||(u==s/2||0==u)&&0==(n[r+1]/s/100|0):4>e?(0==e?u=u/1e3|0:1==e?u=u/100|0:2==e&&(u=u/10|0),o=(t||4>i)&&9999==u||!t&&i>3&&4999==u):o=((t||4>i)&&u+1==s||!t&&i>3&&u+1==s/2)&&(n[r+1]/s/1e3|0)==On(10,e-3)-1,o}function r(n,e,i){for(var t,r,s=[0],o=0,u=n.length;u>o;){for(r=s.length;r--;)s[r]*=e;for(s[0]+=wn.indexOf(n.charAt(o++)),t=0;t<s.length;t++)s[t]>i-1&&(void 0===s[t+1]&&(s[t+1]=0),s[t+1]+=s[t]/i|0,s[t]%=i)}return s.reverse()}function s(n,e){var i,t,r=e.d.length;32>r?(i=Math.ceil(r/3),t=Math.pow(4,-i).toString()):(i=16,t="2.3283064365386962890625e-10"),n.precision+=i,e=E(n,1,e.times(t),new n(1));for(var s=i;s--;){var o=e.times(e);e=o.times(o).minus(o).times(8).plus(1)}return n.precision-=i,e}function o(n,e,i,t){var r,s,o,u,c,f,a,h,l,d=n.constructor;n:if(null!=e){if(h=n.d,!h)return n;for(r=1,u=h[0];u>=10;u/=10)r++;if(s=e-r,0>s)s+=Rn,o=e,a=h[l=0],c=a/On(10,r-o-1)%10|0;else if(l=Math.ceil((s+1)/Rn),u=h.length,l>=u){if(!t)break n;for(;u++<=l;)h.push(0);a=c=0,r=1,s%=Rn,o=s-Rn+1}else{for(a=u=h[l],r=1;u>=10;u/=10)r++;s%=Rn,o=s-Rn+r,c=0>o?0:a/On(10,r-o-1)%10|0}if(t=t||0>e||void 0!==h[l+1]||(0>o?a:a%On(10,r-o-1)),f=4>i?(c||t)&&(0==i||i==(n.s<0?3:2)):c>5||5==c&&(4==i||t||6==i&&(s>0?o>0?a/On(10,r-o):0:h[l-1])%10&1||i==(n.s<0?8:7)),1>e||!h[0])return h.length=0,f?(e-=n.e+1,h[0]=On(10,(Rn-e%Rn)%Rn),n.e=-e||0):h[0]=n.e=0,n;if(0==s?(h.length=l,u=1,l--):(h.length=l+1,u=On(10,Rn-s),h[l]=o>0?(a/On(10,r-o)%On(10,o)|0)*u:0),f)for(;;){if(0==l){for(s=1,o=h[0];o>=10;o/=10)s++;for(o=h[0]+=u,u=1;o>=10;o/=10)u++;s!=u&&(n.e++,h[0]==Pn&&(h[0]=1));break}if(h[l]+=u,h[l]!=Pn)break;h[l--]=0,u=1}for(s=h.length;0===h[--s];)h.pop()}return xn&&(n.e>d.maxE?(n.d=null,n.e=NaN):n.e<d.minE&&(n.e=0,n.d=[0])),n}function u(n,i,t){if(!n.isFinite())return v(n);var r,s=n.e,o=e(n.d),u=o.length;return i?(t&&(r=t-u)>0?o=o.charAt(0)+"."+o.slice(1)+l(r):u>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(n.e<0?"e":"e+")+n.e):0>s?(o="0."+l(-s-1)+o,t&&(r=t-u)>0&&(o+=l(r))):s>=u?(o+=l(s+1-u),t&&(r=t-s-1)>0&&(o=o+"."+l(r))):((r=s+1)<u&&(o=o.slice(0,r)+"."+o.slice(r)),t&&(r=t-u)>0&&(s+1===u&&(o+="."),o+=l(r))),o}function c(n,e){for(var i=1,t=n[0];t>=10;t/=10)i++;return i+e*Rn-1}function f(n,e,i){if(e>Un)throw xn=!0,i&&(n.precision=i),Error(yn);return o(new n(mn),e,1,!0)}function a(n,e,i){if(e>_n)throw Error(yn);return o(new n(vn),e,i,!0)}function h(n){var e=n.length-1,i=e*Rn+1;if(e=n[e]){for(;e%10==0;e/=10)i--;for(e=n[0];e>=10;e/=10)i++}return i}function l(n){for(var e="";n--;)e+="0";return e}function d(n,e,i,t){var r,s=new n(1),o=Math.ceil(t/Rn+4);for(xn=!1;;){if(i%2&&(s=s.times(e),q(s.d,o)&&(r=!0)),i=qn(i/2),0===i){i=s.d.length-1,r&&0===s.d[i]&&++s.d[i];break}e=e.times(e),q(e.d,o)}return xn=!0,s}function p(n){return 1&n.d[n.d.length-1]}function g(n,e,i){for(var t,r=new n(e[0]),s=0;++s<e.length;){if(t=new n(e[s]),!t.s){r=t;break}r[i](t)&&(r=t)}return r}function w(n,i){var r,s,u,c,f,a,h,l=0,d=0,p=0,g=n.constructor,w=g.rounding,m=g.precision;if(!n.d||!n.d[0]||n.e>17)return new g(n.d?n.d[0]?n.s<0?0:1/0:1:n.s?n.s<0?0:n:NaN);for(null==i?(xn=!1,h=m):h=i,a=new g(.03125);n.e>-2;)n=n.times(a),p+=5;for(s=Math.log(On(2,p))/Math.LN10*2+5|0,h+=s,r=c=f=new g(1),g.precision=h;;){if(c=o(c.times(n),h,1),r=r.times(++d),a=f.plus(Sn(c,r,h,1)),e(a.d).slice(0,h)===e(f.d).slice(0,h)){for(u=p;u--;)f=o(f.times(f),h,1);if(null!=i)return g.precision=m,f;if(!(3>l&&t(f.d,h-s,w,l)))return o(f,g.precision=m,w,xn=!0);g.precision=h+=10,r=c=a=new g(1),d=0,l++}f=a}}function m(n,i){var r,s,u,c,a,h,l,d,p,g,w,v=1,N=10,b=n,x=b.d,E=b.constructor,M=E.rounding,y=E.precision;if(b.s<0||!x||!x[0]||!b.e&&1==x[0]&&1==x.length)return new E(x&&!x[0]?-1/0:1!=b.s?NaN:x?0:b);if(null==i?(xn=!1,p=y):p=i,E.precision=p+=N,r=e(x),s=r.charAt(0),!(Math.abs(c=b.e)<15e14))return d=f(E,p+2,y).times(c+""),b=m(new E(s+"."+r.slice(1)),p-N).plus(d),E.precision=y,null==i?o(b,y,M,xn=!0):b;for(;7>s&&1!=s||1==s&&r.charAt(1)>3;)b=b.times(n),r=e(b.d),s=r.charAt(0),v++;for(c=b.e,s>1?(b=new E("0."+r),c++):b=new E(s+"."+r.slice(1)),g=b,l=a=b=Sn(b.minus(1),b.plus(1),p,1),w=o(b.times(b),p,1),u=3;;){if(a=o(a.times(w),p,1),d=l.plus(Sn(a,new E(u),p,1)),e(d.d).slice(0,p)===e(l.d).slice(0,p)){if(l=l.times(2),0!==c&&(l=l.plus(f(E,p+2,y).times(c+""))),l=Sn(l,new E(v),p,1),null!=i)return E.precision=y,l;if(!t(l.d,p-N,M,h))return o(l,E.precision=y,M,xn=!0);E.precision=p+=N,d=a=b=Sn(g.minus(1),g.plus(1),p,1),w=o(b.times(b),p,1),u=h=1}l=d,u+=2}}function v(n){return String(n.s*n.s/0)Line truncated
//# sourceMappingURL=doc/decimal.js.map
+89 -15
View File
@@ -2,12 +2,15 @@ if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var camera, controls, scene, renderer;
var clock = new THREE.Clock();
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2(), INTERSECTED;
var WIDTH = window.innerWidth , HEIGHT = window.innerHeight
window.onload = function() {
loadData(function() {
init();
animate();
populateUserFields();
});
}
@@ -54,18 +57,13 @@ function init() {
controls.dampingFactor = 0.25;
controls.enableZoom = true;
controls.addEventListener( 'change', render );
document.addEventListener( 'mousedown', onCanvasClick, false );
var Text2D = THREE_Text.Text2D;
var SpriteText2D = THREE_Text.SpriteText2D;
var textAlign = THREE_Text.textAlign
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
var b_geometry, b_material, b_mesh, p_geometry, p_material, p_mesh, s_geometry, s_material, s_mesh, l_text;
@@ -83,7 +81,7 @@ for (var key in jsonEmpire) {
b_mesh.position.x = border.x;
b_mesh.position.y = border.y;
b_mesh.position.z = border.z;
b_mesh.name = border.name;
b_mesh.name = escapeHTML(border.name);
scene.add( b_mesh );
if (border.radius > 10) {
l_text = new Text2D(border.name, { align: textAlign.center, font: '25px Arial', fillStyle: '#777' , antialias: false });
@@ -105,9 +103,9 @@ for (var key in jsonEmpire) {
p_mesh.position.x=planet.x;
p_mesh.position.y=planet.y;
p_mesh.position.z=planet.z;
p_mesh.name = planet.name;
p_mesh.name = escapeHTML(planet.name);
scene.add( p_mesh );
l_text = new Text2D(planet.name, { align: textAlign.right, font: '12px Arial', fillStyle: '#FFF' , antialias: false });
l_text = new Text2D(escapeHTML(planet.name), { align: textAlign.right, font: '12px Arial', fillStyle: '#FFF' , antialias: false });
l_text.material.alphaTest = 0.0;
l_text.position.set(planet.x,planet.y,planet.z);
l_text.scale.set(0.25,0.25,0.25);
@@ -123,9 +121,9 @@ for (var key in jsonEmpire) {
s_mesh.position.x=base.x;
s_mesh.position.y=base.y;
s_mesh.position.z=base.z;
s_mesh.name = base.name;
s_mesh.name = escapeHTML(base.name);
scene.add( s_mesh );
l_text = new Text2D(base.name, { align: textAlign.left, font: '12px Arial', fillStyle: '#ABABAB' , antialias: false });
l_text = new Text2D(escapeHTML(base.name), { align: textAlign.left, font: '12px Arial', fillStyle: '#ABABAB' , antialias: false });
l_text.material.alphaTest = 0.0;
l_text.position.set(base.x,base.y+3,base.z);
l_text.scale.set(0.20,0.20,0.20);
@@ -148,20 +146,46 @@ window.onresize = function() {
render();
}
function onCanvasClick( event ) {
//event.preventDefault();
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );
if ( intersects.length > 0 ) {
if ( INTERSECTED != intersects[ 0 ].object ) {
INTERSECTED = intersects[ 0 ].object;
// console.log( INTERSECTED.name );
document.getElementById(lastInputBox).value = INTERSECTED.name;
}
} else {
INTERSECTED = null;
}
}
function animate() {
var delta = clock.getDelta();
requestAnimationFrame( animate );
scene.updateMatrixWorld()
controls.update(delta);
render();
}
}
function render () {
//requestAnimationFrame( render );
renderer.render( scene, camera );
// find intersections
}
@@ -187,7 +211,7 @@ function zoomfocus(name) {
for (var type in types) {
var objects = listobjects(types[type]);
for ( var key in objects ) {
if (escapeHTML(key) == name) {
if (key == name) {
var object = objects[key];
controls.target.x = object.x;
controls.target.y = object.y;
@@ -225,3 +249,53 @@ function removeEntity(object) {
scene.remove( selectedObject );
animate();
}
// Calculates SU/s with given warp factor
function calcSUpS(warpfactor) {
// 14.0*29.979246*1298.737508 = 257494817.55 SU/s
// Velocity = WF^3.333333*lightspeed*cochranes
// 3087467836.3256578445 = 1 Parsec
var cochranes = 1298.737508; // Average cochranes
var lightspeed = 29.979246; // Lightspeed constant
var exponent = 3.333333;
var sus = Math.pow(warpfactor,exponent) * lightspeed * cochranes ;
return sus;
}
function su2pc ( su ) {
return su / 3087467836.3256578445;
}
// Calculates ETA for given distance and velocity.
// Velocity should be supplied as an array of speed and unit
function calcETA(velocity,distance) {
var speed = velocity.speed;
var unit = velocity.unit;
var seconds;
switch (unit) {
case 'SU/s':
seconds = new Decimal( distance / su2pc(speed) );
break;
case 'PC/s':
seconds = new Decimal( distance / speed );
break;
case 'WF':
seconds = distance / su2pc(calcSUpS(speed));
break;
default:
throw "Invalid unit of speed."
}
return seconds;
}
// Calculate the distance between two named points ( Stations or Bases )
function calcDist(pointa, pointb) {
var obj_A = scene.getObjectByName(pointa);
var obj_B = scene.getObjectByName(pointb);
var distance = obj_A.position.distanceTo(obj_B.position);
return distance;
}
+12 -13
View File
@@ -2504,9 +2504,9 @@ THREE.Vector3.prototype = {
projectOnVector: function ( vector ) {
var scalar = vector.dot( this ) / vector.lengthSq();
return this.copy( vector ).multiplyScalar( scalar );
},
projectOnPlane: function () {
@@ -3551,7 +3551,7 @@ THREE.Euler.prototype = {
return function reorder( newOrder ) {
q.setFromEuler( this );
return this.setFromQuaternion( q, newOrder );
};
@@ -4649,7 +4649,7 @@ THREE.Matrix3.prototype = {
return this.identity();
}
var detInv = 1 / det;
te[ 0 ] = t11 * detInv;
@@ -5383,7 +5383,7 @@ THREE.Matrix4.prototype = {
return this.identity();
}
var detInv = 1 / det;
te[ 0 ] = t11 * detInv;
@@ -33000,7 +33000,7 @@ THREE.SpritePlugin = function ( renderer, sprites ) {
}
function painterSortStable ( a, b ) {
if ( a.renderOrder !== b.renderOrder ) {
return a.renderOrder - b.renderOrder;
@@ -36164,7 +36164,7 @@ THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
var b3 = THREE.ShapeUtils.b3;
return new THREE.Vector2(
return new THREE.Vector2(
b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
);
@@ -36175,7 +36175,7 @@ THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
return new THREE.Vector2(
return new THREE.Vector2(
tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
).normalize();
@@ -36237,7 +36237,7 @@ THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle
this.aEndAngle = aEndAngle;
this.aClockwise = aClockwise;
this.aRotation = aRotation || 0;
};
@@ -36263,7 +36263,7 @@ THREE.EllipseCurve.prototype.getPoint = function ( t ) {
angle = this.aStartAngle + t * deltaAngle;
}
var x = this.aX + this.xRadius * Math.cos( angle );
var y = this.aY + this.yRadius * Math.sin( angle );
@@ -36346,7 +36346,7 @@ THREE.QuadraticBezierCurve3 = THREE.Curve.create(
function ( t ) {
var b2 = THREE.ShapeUtils.b2;
var b2 = THREE.ShapeUtils.b2;
return new THREE.Vector3(
b2( t, this.v0.x, this.v1.x, this.v2.x ),
@@ -40467,7 +40467,7 @@ THREE.ArrowHelper.prototype.setColor = function ( color ) {
*/
THREE.BoxHelper = function ( object, color ) {
if ( color === undefined ) color = 0xffff00;
var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
@@ -41869,4 +41869,3 @@ THREE.MorphBlendMesh.prototype.update = function ( delta ) {
}
};