Commit 1d739c37 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

restructuring

parent 3ea9d6db
[Dolphin]
PreviewsShown=true
SortRole=date
Timestamp=2017,5,23,18,34,17
Timestamp=2017,6,5,18,57,32
Version=3
ViewMode=1
......@@ -358,7 +358,7 @@
this._basePoint.addTo(this._layerPaint).bringToFront();
var cHIcon = L.icon({
iconUrl: 'js/images/crosshair.png',
iconUrl: 'js/leaflet/images/crosshair.png',
iconSize: [32, 32]
});
......
// general
/*
*
*/
function ui_showMessage(id,msg,bg){
if (bg != undefined){
$("#"+id).css({background:bg});
}
$("#"+id).show();
$("#"+id).html($("<div>").html(msg).css({
padding:"5px 10px"
})).show();
}
function ui_hideMessage(id){
$("#"+id).hide();
}
// scene (x3dom)
// map (leaflet)
\ No newline at end of file
......@@ -12,8 +12,8 @@ var INIT_HEADING = 0;
var SETTINGS = {
'pointer': false,
'highlight': false,
'viewinfo': false,
'moreinfo': false,
'viewinfo': true,
'moreinfo': true,
'crosshair': false,
'shiftspeed': 0.01
}
......@@ -81,12 +81,14 @@ function light_init(){
INIT_HEADING = heading;
var element = document.getElementById('x3d_id');
Scene = new X3DOMObject(element,Data,{});
Scene.initResize();
$.getScript("js/x3dom-full.debug.js",function(){
$.getScript("js/x3dom/x3dom-full.debug.js",function(){
Map = new LeafletObject('leaflet_map',Data,{});
//wait until it parsed the DOM
//wait until it DOM is extended
x3dom.runtime.ready = function(){
map_resize_init();
deep_init();
......@@ -148,7 +150,8 @@ function map_resize(e){
}
function deep_init(){
//Scene.initResize();
Scene.FoVEvents();
Scene.KeyEvents();
......@@ -160,15 +163,14 @@ function deep_init(){
progress_counter = progress_counter.split(" ");
cnt = parseInt(progress_counter[1]);
if (!Scene._X3DOM_SCENE_INIT&&(cnt==0)){
if (!Scene._X3DOM_SCENE_INIT_DONE&&(cnt==0)){
//if(Scene._DEBUG){
Scene.initInfoWindow();
Scene.initViewInfoWindow();
Scene.registerShapesEvents();
//}
//Scene.initResize();
// now then all shapes are parsed and accessible
Scene.ShapeEvents();
Scene._X3DOM_SCENE_INIT = true;
Scene._X3DOM_SCENE_INIT_DONE = true;
x3d_events();
leaf_events();
......@@ -235,7 +237,7 @@ function x3d_events(){
var sr = elem.runtime.shootRay(e.path[0].mouse_drag_x,e.path[0].mouse_drag_y);
if (!$(sr.pickObject).hasClass("shapemarker")){
Scene.highlightShape(sr.pickObject);
X3DOMObject.Shape.highlight(sr.pickObject);
}
......@@ -268,7 +270,7 @@ function x3d_events(){
if (e.key=="Shift"){
// select shape
var sr = elem.runtime.shootRay(e.path[0].mouse_drag_x,e.path[0].mouse_drag_y);
Scene.dehighlightShape(sr.pickObject);
X3DOMObject.Shape.dehighlight(sr.pickObject);
}
if (e.key=="Control"){
......@@ -312,7 +314,7 @@ function x3d_events(){
if (SETTINGS.highlight&&!SETTINGS.pointer){
var sr = elem.runtime.shootRay(e.path[0].mouse_drag_x,e.path[0].mouse_drag_y);
Scene.highlightShape(sr.pickObject);
X3DOMObject.Shape.highlight(sr.pickObject);
}
......@@ -346,7 +348,7 @@ function x3d_events(){
// hide shadow marker
Map.marker.removeSlidingMarker();
Scene.hideMessage("window-info");
ui_hideMessage("window-info");
});
......@@ -575,11 +577,11 @@ function x3d_mouseMove(){
var initial_heading = Data.camera.heading;
//var initial_heading = INIT_HEADING;
var heading = Scene.getViewDirection();
var heading = x3dom_getViewDirection(Scene.element);
Map.marker.setHeading(heading+INIT_HEADING);
var d = Scene.getViewTranslation();
var d = x3dom_getViewTranslation(Scene.element);
var dx;
var dz;
......
/**
* output in units (meters)
*/
function x3dom_getViewTranslation(elem){
var vp_mat = elem.runtime.viewMatrix().inverse();
var vp_translation = vp_mat.e3();
return vp_translation;
}
/**
* output in degrees
*/
function x3dom_getViewDirection(elem){
var vp_mat = elem.runtime.viewMatrix();
var vMatInv = vp_mat.inverse();
var viewDir = vMatInv.multMatrixVec(new x3dom.fields.SFVec3f(0.0, 0.0, -1.0));
var angle = Math.atan2(viewDir.x,-viewDir.z)*180/Math.PI;
return angle;
}
/**
* get position and orientation in the 3D scene defined by mouse's canvas x,y
*/
function x3dom_getXYPosOr(cnvx,cnvy,round){
var elem = Scene.element;
var x,y,z;
var az,el,sk;
var id;
var dist_xyz = 1000;
var dist_xz = 1000;
var shootRay = elem.runtime.shootRay(cnvx,cnvy);
if (shootRay.pickPosition != null){
var index = Scene.highlighted_marker_index;
if ((index==null)||(Data.markers[index]==undefined)){
x = shootRay.pickPosition.x;
y = shootRay.pickPosition.y;
z = shootRay.pickPosition.z;
}else{
x = Data.markers[index].x;
y = Data.markers[index].y;
z = Data.markers[index].z;
}
dist_xz = Math.sqrt(x*x+z*z);
dist_xyz = Math.sqrt(y*y+dist_xz*dist_xz);
if (round){
dist_xz.toFixed(2);
dist_xyz.toFixed(2);
}
id = $(shootRay.pickObject).attr("id");
}else{
var viewingRay = elem.runtime.getViewingRay(cnvx,cnvy);
x = viewingRay.dir.x;
y = viewingRay.dir.y;
z = viewingRay.dir.z;
dist_xz = null;
dist_xyz = null;
}
az = Math.atan2(x,-z)*180/Math.PI;
az = (az+INIT_HEADING+360)%360;
el = Math.atan2(y,Math.sqrt(x*x+z*z))*180/Math.PI;
sk = 0;
var result = {
x: !round? x : x.toFixed(2),
y: !round? y : y.toFixed(2),
z: !round? z : z.toFixed(2),
a: !round? az : az.toFixed(1),
e: !round? el : el.toFixed(1),
s: !round? sk : sk.toFixed(1)
};
if (dist_xz!=null){
result.d_xz = !round? dist_xz : dist_xz.toFixed(1);
result.d_xyz = !round? dist_xyz : dist_xyz.toFixed(1);
}else{
result.d_xz = dist_xz;
result.d_xyz = dist_xyz;
}
result.id = id;
return result;
}
/**
* Get position and orientation of the observer (=viewer=camera)
* in the 3D scene
*/
function x3dom_getCameraPosOr(round){
var elem = Scene.element;
var vm = elem.runtime.viewMatrix().inverse();
var tr = vm.e3();
var x = tr.x;
var y = tr.y;
var z = tr.z;
var R = vm;
var az = Math.atan2(R._02,R._22)*180/Math.PI;
az = (az+INIT_HEADING+360)%360;
var el = -Math.asin(R._12)*180/Math.PI;
var sk = Math.atan2(R._10,R._11);
if (!round){
return {
x: x,
y: y,
z: z,
a: az,
e: el,
s: sk
};
}else{
return {
x: x.toFixed(2),
y: y.toFixed(2),
z: z.toFixed(2),
a: az.toFixed(1),
e: el.toFixed(1),
s: sk.toFixed(1)
};
}
}
function x3dom_setUpRight(){
var mat = Scene.element.runtime.viewMatrix().inverse();
var from = mat.e3();
var at = from.subtract(mat.e2());
var up = new x3dom.fields.SFVec3f(0, 1, 0);
var s = mat.e2().cross(up).normalize();
var newup = mat.e2().cross(s).normalize().negate();
//at = from.add(v);
mat = x3dom.fields.SFMatrix4f.lookAt(from, at, newup);
//mat = mat.inverse();
//var m1 = x3dom.fields.SFMatrix4f.translation(from);
//var m1n = x3dom.fields.SFMatrix4f.translation(from.negate());
//mat = m1.mult(mat).mult(m1n);
var Q = new x3dom.fields.Quaternion(0,0,1,0);
Q.setValue(mat);
var AA = Q.toAxisAngle();
var viewpoint = $(Scene.element).find("Viewpoint");
viewpoint.attr("position",mat.e3().toString());
viewpoint.attr("centerOfRotation",mat.e3().toString());
viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]);
}
function x3dom_rotation(delta_a){
/*
* Printing values:
*
* var mat = Scene.element.runtime.viewMatrix().inverse();
* var rotation = new x3dom.fields.Quaternion(0, 0, 1, 0);
* rotation.setValue(mat);
* var translation = mat.e3();
*
*/
var mat = Scene.element.runtime.viewMatrix();
mat = mat.inverse();
//console.log(mat.toString());
var from = mat.e3();
var at = from.subtract(mat.e2());
var up = mat.e1();
var q0 = x3dom.fields.Quaternion.axisAngle(up, -delta_a);
var m0 = q0.toMatrix();
var m1 = x3dom.fields.SFMatrix4f.translation(from);
var m1n = x3dom.fields.SFMatrix4f.translation(from.negate());
var mres = m1.mult(m0).mult(m1n);
newat = mres.multMatrixPnt(at);
newmat = x3dom.fields.SFMatrix4f.lookAt(from, newat, up);
var Q = new x3dom.fields.Quaternion(0,0,1,0);
//Q.setValue(newmat.inverse());
Q.setValue(newmat);
var AA = Q.toAxisAngle();
var viewpoint = $(Scene.element).find("Viewpoint");
viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]);
viewpoint.attr("position",from.toString());
viewpoint.attr("centerOfRotation",from.toString());
}
// horizontal?
function x3dom_translation(dx,dy,dz){
var mat = Scene.element.runtime.viewMatrix().inverse();
var tr = mat.e3();
var x = tr.x+dx;
var y = tr.y+dy;
var z = tr.z+dz;
var viewpoint = $(Scene.element).find("Viewpoint");
viewpoint.attr("position",x+" "+y+" "+z);
viewpoint.attr("centerOfRotation",x+" "+y+" "+z);
}
function x3dom_altelev(alt,elev){
//x3dom_matrix_test();
var mat = Scene.element.runtime.viewMatrix().inverse();
var from = mat.e3();
from.y = alt;
var az = Math.atan2(mat._02,mat._22);
var el = elev;
var sk = Math.atan2(mat._10,mat._11);
var matx = x3dom.fields.SFMatrix4f.rotationX(el);
var maty = x3dom.fields.SFMatrix4f.rotationY(az);
var matz = x3dom.fields.SFMatrix4f.rotationZ(sk);
var matt = x3dom.fields.SFMatrix4f.translation(from);
var newmat = matt.mult(maty).mult(matx).mult(matz);
var Q = new x3dom.fields.Quaternion(0,0,1,0);
Q.setValue(newmat);
var AA = Q.toAxisAngle();
var viewpoint = $(Scene.element).find("Viewpoint");
viewpoint.attr("position",newmat.e3().toString());
viewpoint.attr("centerOfRotation",newmat.e3().toString());
viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]);
}
function x3dom_matrix_test(){
var viewpoint = $(Scene.element).find("Viewpoint");
console.log("Viewpoint DOM element");
console.log("position: "+viewpoint.attr("position"));
console.log("orientation: "+viewpoint.attr("orientation"));
var mat = Scene.element.runtime.viewMatrix().inverse();
console.log("inversed viewMatrix");
console.log(mat.toString());
var from = mat.e3();
var at = from.subtract(mat.e2());
var up = mat.e1();
console.log("matrix from from-at-up");
var newmat = x3dom.fields.SFMatrix4f.lookAt(from, at, up);
console.log(newmat.toString());
var R = mat;
var az = Math.atan2(R._02,R._22)*180/Math.PI;
//az = (az+INIT_HEADING+360)%360;
//az = (az+360)%360;
var el = -Math.asin(R._12)*180/Math.PI;
var sk = Math.atan2(R._10,R._11);
console.log("Angles:");
console.log("az="+az+" el="+el+" sk="+sk);
console.log("matrix from angles");
var matx = x3dom.fields.SFMatrix4f.rotationX(el*Math.PI/180);
var maty = x3dom.fields.SFMatrix4f.rotationY(az*Math.PI/180);
var matz = x3dom.fields.SFMatrix4f.rotationZ(sk*Math.PI/180);
var m1 = x3dom.fields.SFMatrix4f.translation(from);
var m1n = x3dom.fields.SFMatrix4f.translation(from.negate());
var newmat = maty.mult(matx).mult(matz);
console.log(newmat.toString());
}
/**
* Get World to Camera coordinates tranform matrix
* what's native getWCtoCCMatrix()?
*/
function x3dom_W2C(){
return new x3dom.fields.SFMatrix4f(
0, 0, 1, 0,
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, 1,
);
}
function x3dom_C2W(){
return x3dom_W2C().inverse();
}
This diff is collapsed.
......@@ -4,7 +4,7 @@
<meta charset="utf-8"/>
<title>Scene+Map</title>
<script type='text/javascript' src='js/jquery-3.1.1.js'></script>
<script type='text/javascript' src='js/jquery/jquery-3.1.1.js'></script>
<script type='text/javascript' src='js/leaflet/leaflet-src.js'></script>
<script type='text/javascript' src='js/leaflet/L.extra.js'></script>
......@@ -12,20 +12,20 @@
<script type='text/javascript' src='js/leaflet/leaflet.camera-view-marker.js'></script>
<script type='text/javascript' src='js/leaflet/leaflet.camera-view-marker.measure.js'></script>
<script type='text/javascript' src='js/X3DOMObject.js'></script>
<script type='text/javascript' src='js/LeafletObject.js'></script>
<!-- <script type='text/javascript' src='js/LeafletObject.js'></script> -->
<script type='text/javascript' src='js/leaflet-x3dom.js'></script>
<script type='text/javascript' src='js/x3dom_init.js'></script>
<script type='text/javascript' src='js/x3dom_functions.js'></script>
<script type='text/javascript' src='js/leaflet_init.js'></script>
<script type='text/javascript' src='js/x3l.js'></script>
<script type='text/javascript' src='js/index.js'></script>
<script type='text/javascript' src='js/menu.js'></script>
<script type='text/javascript' src='js/help.js'></script>
<script type='text/javascript' src='js/align.js'></script>
<script type='text/javascript' src='js/ui_init.js'></script>
<script type='text/javascript' src='js/ui_menu.js'></script>
<script type='text/javascript' src='js/ui_help.js'></script>
<script type='text/javascript' src='js/ui_functions.js'></script>
<script type='text/javascript' src='js/ui_align.js'></script>
<link rel='stylesheet' type='text/css' href='js/leaflet/leaflet.css'></link>
<!-- <link rel='stylesheet' type='text/css' href='js/map.css'></link> -->
<link rel='stylesheet' type='text/css' href='js/x3dom.css'></link>
<!-- <link rel='stylesheet' type='text/css' href='js/index.css'></link> -->
<link rel='stylesheet' type='text/css' href='js/x3dom/x3dom.css'></link>
<link rel='stylesheet' type='text/css' href='js/index.css'></link>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment