Commit 401fc593 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

fixed jumping: map-drag cam - scene-drag cam

parent 47d7e72e
...@@ -7,6 +7,7 @@ var Data = { ...@@ -7,6 +7,7 @@ var Data = {
var Scene; var Scene;
var Map; var Map;
// this var needs to go
var INIT_HEADING = 0; var INIT_HEADING = 0;
var SETTINGS = { var SETTINGS = {
...@@ -505,6 +506,7 @@ function leaf_mousemove_nohc(e){ ...@@ -505,6 +506,7 @@ function leaf_mousemove_nohc(e){
var p0 = new L.LatLng(Data.camera.latitude,Data.camera.longitude); var p0 = new L.LatLng(Data.camera.latitude,Data.camera.longitude);
var p1 = new L.LatLng(Camera._latlng.lat,Camera._latlng.lng); var p1 = new L.LatLng(Camera._latlng.lat,Camera._latlng.lng);
//update Data
Data.camera.latitude = Camera._latlng.lat; Data.camera.latitude = Camera._latlng.lat;
Data.camera.longitude = Camera._latlng.lng; Data.camera.longitude = Camera._latlng.lng;
...@@ -514,15 +516,15 @@ function leaf_mousemove_nohc(e){ ...@@ -514,15 +516,15 @@ function leaf_mousemove_nohc(e){
Data.camera.heading = Camera._heading*180/Math.PI; Data.camera.heading = Camera._heading*180/Math.PI;
var newheading = Data.camera.heading;// - INIT_HEADING; var newheading = Data.camera.heading - INIT_HEADING;
if ((p0.lat!=p1.lat)||(p0.lng!=p1.lng)){ if ((p0.lat!=p1.lat)||(p0.lng!=p1.lng)){
console.log("translation"); console.log("translation");
leaf_translation_v1(p0,p1); leaf_translation_v1(p0,p1);
} }else{
//leaf_rotation_v1(newheading,dh); //leaf_rotation_v1(newheading,dh);
x3dom_rotation(dh); x3dom_rotation(dh);
}
X3DOMObject.displayViewInfo({}); X3DOMObject.displayViewInfo({});
...@@ -586,17 +588,22 @@ function leaf_translation_v1(p0,p1){ ...@@ -586,17 +588,22 @@ function leaf_translation_v1(p0,p1){
dz = -dz; dz = -dz;
} }
var da = Math.atan2(dz,dx); //transform to camera coordinates
var A = Math.PI/180*INIT_HEADING; var A = Math.PI/180*INIT_HEADING;
var a = Math.atan2(dx,dz);
console.log(A);
dx = dl*Math.sin(A-da); dx = -dl*Math.sin(A-a);
dz = -dl*Math.cos(A-da); dz = -dl*Math.cos(A-a);
console.log("dx="+dx+" dy="+dy+" dz="+dz+" A="+A+" da="+da); console.log("dx="+dx+" dy="+dy+" dz="+dz);
// translation over map = xz // translation over map = xz
x3dom_translation(dx,dy,dz) x3dom_translation(dx,dy,dz);
// if not updated then moving in 3D scene will make it jump
Scene.old_view_translation = x3dom_getViewTranslation(Scene.element);
} }
......
...@@ -249,16 +249,35 @@ function x3dom_rotation(delta_a){ ...@@ -249,16 +249,35 @@ function x3dom_rotation(delta_a){
// horizontal? // horizontal?
function x3dom_translation(dx,dy,dz){ function x3dom_translation(dx,dy,dz){
var delta = new x3dom.fields.SFVec3f(dx,dy,dz);
var mat = Scene.element.runtime.viewMatrix().inverse(); var mat = Scene.element.runtime.viewMatrix().inverse();
var tr = mat.e3(); var tr = mat.e3();
var x = tr.x+dx; var from = mat.e3();
var y = tr.y+dy; var at = from.subtract(mat.e2());
var z = tr.z+dz;
console.log(from.toString());
var newfrom = from.add(delta);
console.log(newfrom.toString());
var newat = newfrom.subtract(mat.e2());
var up = mat.e1();
var newmat = x3dom.fields.SFMatrix4f.lookAt(newfrom, 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"); var viewpoint = $(Scene.element).find("Viewpoint");
viewpoint.attr("position",x+" "+y+" "+z); viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]);
viewpoint.attr("centerOfRotation",x+" "+y+" "+z); viewpoint.attr("position",newfrom.toString());
viewpoint.attr("centerOfRotation",newfrom.toString());
} }
......
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