Commit 43da7d62 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

subbing INIT_HEADING to matrix mults

parent 233e7e28
...@@ -289,22 +289,30 @@ function x3d_initial_camera_placement(){ ...@@ -289,22 +289,30 @@ function x3d_initial_camera_placement(){
// rw = real world with North // rw = real world with North
// w = virtual world = x3dom frame reference // w = virtual world = x3dom frame reference
var R_rw2w = T.inverse().mult(R).mult(T); var Rw_rw = T.inverse().mult(R).mult(T);
var M_rw2w = R_rw2w.inverse(); var M_rw2w = Rw_rw.inverse();
var Rmap_rw = T.inverse().mult(Mh).mult(T); // _rw - real world
// _w - virt world
var Rc_rw = T.inverse().mult(Mh).mult(T);
var Rc_w = M_rw2w.mult(T.inverse()).mult(Mh).mult(T); var Rc_w = M_rw2w.mult(Rc_rw);
//var Rm_w = M_rw2w.mult(Rm_rw);
// store matrices // store matrices
Data.camera.Matrices = { Data.camera.Matrices = {
Ah: heading,
At: tilt,
Ar: roll,
R_h_eul: Mh, R_h_eul: Mh,
R_t_eul: Mt, R_t_eul: Mt,
R_r_eul: Mr, R_r_eul: Mr,
R_rw2w : R_rw2w, Rw_rw : Rw_rw,
M_rw2w : M_rw2w, M_rw2w : M_rw2w,
V_trueUp_w: Rc_w.e1() V_trueUp_w: Rc_w.e1(),
Rc_w: Rc_w,
//Rm_w: Rm_w
}; };
// set view // set view
...@@ -317,6 +325,9 @@ function x3d_initial_camera_placement(){ ...@@ -317,6 +325,9 @@ function x3d_initial_camera_placement(){
viewpoint.attr("position",Rc_w.e3().toString()); viewpoint.attr("position",Rc_w.e3().toString());
viewpoint.attr("centerOfRotation",Rc_w.e3().toString()); viewpoint.attr("centerOfRotation",Rc_w.e3().toString());
// update every time
Data.camera.Matrices.Rc_w = Rc_w;
} }
function x3d_events(){ function x3d_events(){
...@@ -493,9 +504,9 @@ function leaf_events(){ ...@@ -493,9 +504,9 @@ function leaf_events(){
//var azimuth = getAzimuth(p1_ll,p2_ll); //var azimuth = getAzimuth(p1_ll,p2_ll);
var azimuth = getAzimuth(p1_ll,p2_ll); var azimuth = getAzimuth(p1_ll,p2_ll);
var initial_heading = INIT_HEADING; //var initial_heading = Data.camera.Matrices.Ah*180/Math.PI;
var angle = azimuth - initial_heading; var angle = azimuth - Data.camera.Matrices.Ah*180/Math.PI;
var distance = p1_ll.distanceTo(p2_ll); var distance = p1_ll.distanceTo(p2_ll);
//console.log("angle from lat lng: "+angle); //console.log("angle from lat lng: "+angle);
...@@ -595,7 +606,7 @@ function leaf_mousemove_nohc(e){ ...@@ -595,7 +606,7 @@ function leaf_mousemove_nohc(e){
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{ }else{
//leaf_rotation_v1(newheading,dh); //leaf_rotation_v1(newheading,dh);
...@@ -625,58 +636,29 @@ function leaf_drag_marker(){ ...@@ -625,58 +636,29 @@ function leaf_drag_marker(){
mark.latitude = p2_ll.lat; mark.latitude = p2_ll.lat;
mark.longitude = p2_ll.lng; mark.longitude = p2_ll.lng;
var azimuth = getAzimuth(p1_ll,p2_ll);
//var initial_heading = Data.camera.heading;
var angle = azimuth - INIT_HEADING;
var distance = p1_ll.distanceTo(p2_ll); var distance = p1_ll.distanceTo(p2_ll);
mark.x = distance*Math.sin(Math.PI/180*angle); var dp_w = x3dom_delta_map2scene(p1_ll,p2_ll);
mark.z = -distance*Math.cos(Math.PI/180*angle);
mark.x = dp_w.x;
mark.z = dp_w.z;
mark.d_map = distance; mark.d_map = distance;
X3DOMObject.displayMarkInfo(index); X3DOMObject.displayMarkInfo(index);
X3DOMObject.Marker.place(mark.x,mark.y,mark.z,"my-sph-"+index); X3DOMObject.Marker.place(mark.x,mark.y,mark.z,"my-sph-"+index);
} }
} }
function leaf_translation_v1(p0,p1){ function leaf_translation_v1(p0,p1){
var pi = new L.LatLng(p0.lat,p1.lng); var dp_w = x3dom_delta_map2scene(p0,p1);
var dx = p0.distanceTo(pi);
var dy = 0;
var dz = p1.distanceTo(pi);
var dl = p0.distanceTo(p1);
//console.log(dx+" "+dz+" "+dl);
if (p1.lng<p0.lng){
dx = -dx;
}
if (p1.lat<p0.lat){
dz = -dz;
}
//transform to camera coordinates
var A = Math.PI/180*INIT_HEADING;
var a = Math.atan2(dx,dz);
console.log(A);
dx = -dl*Math.sin(A-a);
dz = -dl*Math.cos(A-a);
console.log("dx="+dx+" dy="+dy+" dz="+dz);
// translation over map = xz x3dom_translation(dp_w.x,dp_w.y,dp_w.z);
x3dom_translation(dx,dy,dz);
// if not updated then moving in 3D scene will make it jump // if not updated then moving in 3D scene will make it jump
Scene.old_view_translation = x3dom_getViewTranslation(Scene.element); Scene.old_view_translation = x3dom_getViewTranslation(Scene.element);
...@@ -687,7 +669,7 @@ function x3d_mouseMove(){ ...@@ -687,7 +669,7 @@ function x3d_mouseMove(){
var Camera = Map.marker; var Camera = Map.marker;
var initial_heading = Data.camera.heading; //var initial_heading = Data.camera.heading;
//var initial_heading = INIT_HEADING; //var initial_heading = INIT_HEADING;
var heading = x3dom_getViewDirection(Scene.element); var heading = x3dom_getViewDirection(Scene.element);
......
...@@ -162,6 +162,8 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){ ...@@ -162,6 +162,8 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
*/ */
function x3dom_getCameraPosOr(round){ function x3dom_getCameraPosOr(round){
//console.log("Getting PosOr");
var elem = Scene.element; var elem = Scene.element;
var vm = elem.runtime.viewMatrix().inverse(); var vm = elem.runtime.viewMatrix().inverse();
...@@ -173,14 +175,26 @@ function x3dom_getCameraPosOr(round){ ...@@ -173,14 +175,26 @@ function x3dom_getCameraPosOr(round){
var z = tr.z; var z = tr.z;
var R = vm; var R = vm;
// double check below, random correct result?
var az = Math.atan2(R._02,R._22)*180/Math.PI; //var mat = Data.camera.Matrices.Rw_rw;
var mat = Data.camera.Matrices.M_rw2w;
var T = x3dom_C2E();
az = (az+INIT_HEADING+360)%360; mat = T.mult(mat).mult(vm).mult(T.inverse());
var el = -Math.asin(R._12)*180/Math.PI; var test = x3dom_YawPitchRoll(mat);
var sk = Math.atan2(R._10,R._11); test.yaw = (-180/Math.PI*test.yaw+360)%360;
test.pitch *= 180/Math.PI;
test.roll *= 180/Math.PI;
//console.log(test);
az = test.yaw;
el = test.pitch;
sk = test.roll;
if (!round){ if (!round){
return { return {
...@@ -238,6 +252,8 @@ function x3dom_setUpRight(){ ...@@ -238,6 +252,8 @@ function x3dom_setUpRight(){
viewpoint.attr("position",mat.e3().toString()); viewpoint.attr("position",mat.e3().toString());
viewpoint.attr("centerOfRotation",mat.e3().toString()); viewpoint.attr("centerOfRotation",mat.e3().toString());
viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]); viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]);
Data.camera.Matrices.Rc_w = mat;
} }
...@@ -283,6 +299,8 @@ function x3dom_rotation(delta_a){ ...@@ -283,6 +299,8 @@ function x3dom_rotation(delta_a){
viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]); viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]);
viewpoint.attr("position",from.toString()); viewpoint.attr("position",from.toString());
viewpoint.attr("centerOfRotation",from.toString()); viewpoint.attr("centerOfRotation",from.toString());
Data.camera.Matrices.Rc_w = newmat;
} }
...@@ -297,11 +315,11 @@ function x3dom_translation(dx,dy,dz){ ...@@ -297,11 +315,11 @@ function x3dom_translation(dx,dy,dz){
var from = mat.e3(); var from = mat.e3();
var at = from.subtract(mat.e2()); var at = from.subtract(mat.e2());
console.log(from.toString()); //console.log(from.toString());
var newfrom = from.add(delta); var newfrom = from.add(delta);
console.log(newfrom.toString()); //console.log(newfrom.toString());
var newat = newfrom.subtract(mat.e2()); var newat = newfrom.subtract(mat.e2());
...@@ -319,6 +337,8 @@ function x3dom_translation(dx,dy,dz){ ...@@ -319,6 +337,8 @@ function x3dom_translation(dx,dy,dz){
viewpoint.attr("position",newfrom.toString()); viewpoint.attr("position",newfrom.toString());
viewpoint.attr("centerOfRotation",newfrom.toString()); viewpoint.attr("centerOfRotation",newfrom.toString());
Data.camera.Matrices.Rc_w = newmat;
} }
function x3dom_altelev(alt,elev){ function x3dom_altelev(alt,elev){
...@@ -352,6 +372,7 @@ function x3dom_altelev(alt,elev){ ...@@ -352,6 +372,7 @@ function x3dom_altelev(alt,elev){
viewpoint.attr("centerOfRotation",newmat.e3().toString()); viewpoint.attr("centerOfRotation",newmat.e3().toString());
viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]); viewpoint.attr("orientation",AA[0].toString()+" "+AA[1]);
Data.camera.Matrices.Rc_w = newmat;
} }
/** /**
...@@ -420,7 +441,7 @@ function x3dom_C2E(){ ...@@ -420,7 +441,7 @@ function x3dom_C2E(){
} }
function x3dom_E2C(){ function x3dom_E2C(){
return x3dom_W2C().inverse(); return x3dom_C2E().inverse();
} }
function x3dom_YawPitchRoll(m){ function x3dom_YawPitchRoll(m){
...@@ -435,3 +456,24 @@ function x3dom_YawPitchRoll(m){ ...@@ -435,3 +456,24 @@ function x3dom_YawPitchRoll(m){
roll: roll roll: roll
}; };
} }
function x3dom_delta_map2scene(p0,p1){
var pi = new L.LatLng(p0.lat,p1.lng);
var dx = p0.distanceTo(pi);
var dy = 0;
var dz = p1.distanceTo(pi);
var dp_rw = new x3dom.fields.SFVec3f(dx,dy,dz);
if (p1.lng<p0.lng) dp_rw.x = -dp_rw.x;
if (p1.lat>p0.lat) dp_rw.z = -dp_rw.z;
// rotate, not transform - because rotated is the camera
var mat = Data.camera.Matrices.Rw_rw;
var dp_w = mat.multMatrixVec(dp_rw);
return dp_w;
}
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