Commit 65c3858d authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. update pointer marker pars 2. camera dragging over map != dragging over scene?

parent 760d94bb
......@@ -51,7 +51,7 @@ var SETTINGS = {
'moreinfo': true,
'crosshair': false,
'shiftspeed' : 0.01,
'markersize' : 2,
'markersize' : 1,
'markercolor': "#1f1",
'slidingdrag': true,
'basepath': "models",
......@@ -474,8 +474,7 @@ function x3d_events(){
elem.addEventListener('keydown',function(e){
//console.log("scene keydown");
// 'shift' is for shapes toggling
if ((e.key=="Shift")||(SETTINGS.highlight&&!SETTINGS.pointer)){
// select shape
var sr = elem.runtime.shootRay(e.path[0].mouse_drag_x,e.path[0].mouse_drag_y);
......@@ -487,8 +486,11 @@ function x3d_events(){
}
// sliding marker
if (e.key=="Control"){
X3DOMObject.PointerMarker.updatePars();
Scene._ctrlKey = true;
var x,y,z;
......@@ -501,7 +503,10 @@ function x3d_events(){
dist = parseFloat(mouse.d_xz);
X3DOMObject.Marker.place(mouse.x,mouse.y,mouse.z,"sliding_sphere");
if (Scene.highlighted_marker_index==null) $("#sliding_sphere").find("switch").attr("whichChoice",0);
if (Scene.highlighted_marker_index==null) {
$("#sliding_sphere").find("switch").attr("whichChoice",0);
}
}
......@@ -513,8 +518,8 @@ function x3d_events(){
elem.addEventListener('keyup',function(e){
// 'shift' is for shapes toggling
if (e.key=="Shift"){
// select shape
var sr = elem.runtime.shootRay(e.path[0].mouse_drag_x,e.path[0].mouse_drag_y);
X3DOMObject.Shape.dehighlight(sr.pickObject);
}
......@@ -558,9 +563,11 @@ function x3d_events(){
//2: new
if (!e.target) e.target = Scene.element;
var mouse_position = Scene.element.runtime.mousePosition(e);
var camera = x3dom_getCameraPosOr(mouse_position[0],mouse_position[1],false);
// these functions belong to 'leaflet.camera-view-marker.js'
Map.marker.setAltitude(camera.y);
Map.marker.setElevation(camera.e*Math.PI/180);
......@@ -569,29 +576,22 @@ 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);
X3DOMObject.Shape.highlight(sr.pickObject);
// this is for highlighting, no need to correct zNear bug
var sr = elem.runtime.shootRay(e.path[0].mouse_drag_x,e.path[0].mouse_drag_y);
X3DOMObject.Shape.highlight(sr.pickObject);
}
if ((Scene._ctrlKey)||(SETTINGS.pointer)){
// show shadow marker
//1: old
//var mouse = x3dom_getXYPosOr(e.clientX,e.clientY,false);
//2: new
//if (!e.target) e.target = Scene.element;
//var mouse_position = Scene.element.runtime.mousePosition(e);
var mouse = x3dom_getXYPosOr(mouse_position[0],mouse_position[1],false);
var dist = parseFloat(mouse.d_xz) || 1116;
Map.marker.placeSlidingMarker(mouse.a,dist);
// sliding marker
var mouse = x3dom_getXYPosOr(mouse_position[0],mouse_position[1],false);
var dist = parseFloat(mouse.d_xz) || 1116;
Map.marker.placeSlidingMarker(mouse.a,dist);
}else{
// hide shadow marker
// hide sliding marker
Map.marker.removeSlidingMarker();
}
......@@ -685,6 +685,7 @@ function leaf_events(){
X3DOMObject.displayMarkInfo(Data.markers.length-1);
// note: the 2nd place where marker is created is in x3dom_init.js (createNewMarker)
//new X3DOMObject.Marker(mark.x,mark.y,mark.z,true);
new X3DOMObject.Marker(mark.x,mark.y,mark.z,false);
......@@ -731,6 +732,7 @@ function leaf_mouseup(e){
function leaf_mousemove(e){
var Camera = Map.marker;
if (Camera.draggedMarker._index!=null){
var index = Camera.draggedMarker._index;
var elem = $("#my-sph-"+index);
......
......@@ -52,23 +52,26 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
var elem = Scene.element;
var x,y,z;
var xc,yc,zc;
var az,el,sk;
var id;
var dist_xyz = 1112;
var dist_xz = 1113;
//console.log("That event:");
//console.log(Scene._stored_x3dom_event);
var valid_distance;
// camera coordinates, not correcting with zNear
var campos = x3dom_getCameraPosOr();
var xc = campos.x;
var yc = campos.y;
var zc = campos.z;
xc = campos.x;
yc = campos.y;
zc = campos.z;
// shoot ray based on canvas coordinates
// if hits a shape > .pickPosition and .pickObject
var shootRay = elem.runtime.shootRay(cnvx,cnvy);
var valid_distance = true;
// check infinity shape
if (shootRay.pickPosition != null){
if ($(shootRay.pickObject).hasClass('INFINITY')){
......@@ -80,75 +83,70 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
var index = Scene.highlighted_marker_index;
// didn't hit a marker?
if (index==null){
// some marker being dragged but the mouse is not over it. If yes - update index
if ((Scene.draggedTransformNode!=undefined)&&(Scene.draggedTransformNode!=null)){
var sphere = Scene.draggedTransformNode.parent().parent();
index = parseInt(sphere.attr("id").substr(7));
}
}
// didn't hit marker
if ((index==null)||(Data.markers[index]==undefined)){
x = shootRay.pickPosition.x;
y = shootRay.pickPosition.y;
z = shootRay.pickPosition.z;
var xyz = zNear_bug_correction([x,y,z]);
// needs zNear bug correction
var xyz = zNear_bug_correction([shootRay.pickPosition.x,shootRay.pickPosition.y,shootRay.pickPosition.z]);
x = xyz[0];
y = xyz[1];
z = xyz[2];
//dist_xz = Math.sqrt(Math.pow(x-xc,2)+Math.pow(z-zc,2));
}else{
// zNear bug is already corrected
x = Data.markers[index].x;
y = Data.markers[index].y;
z = Data.markers[index].z;
/*
dist_xz = Data.markers[index].d_x3d;
if (isNaN(dist_xz)){
dist_xz = Math.sqrt(Math.pow(x-xc,2)+Math.pow(z-zc,2));;
}
*/
}
//dist_xyz = Math.sqrt(Math.pow(y-yc,2)+Math.pow(dist_xz,2));
id = $(shootRay.pickObject).attr("id");
valid_distance = true;
}else{
// returns a |1| viewing direction based on canvas coordinates
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;
valid_distance = false;
}
// to get XZ(horizontal) distance - convert to real world coordinates
var R0 = Data.camera.Matrices.R0;
var p_w = new x3dom.fields.SFVec3f(x-xc,y-yc,z-zc);
var p_rw = R0.multMatrixVec(p_w);
if (valid_distance){
dist_xz = Math.sqrt(p_rw.x*p_rw.x+p_rw.z*p_rw.z);
dist_xyz = Math.sqrt(p_rw.y*p_rw.y+dist_xz*dist_xz);
dist_xz = Math.sqrt(Math.pow(p_rw.x,2)+Math.pow(p_rw.z,2));
dist_xyz = Math.sqrt(Math.pow(p_rw.y,2)+Math.pow(dist_xz,2));
}else{
dist_xz = null;
dist_xyz = null;
}
// azimuth, elevation and skew are relative to the camera location
az = Math.atan2(p_rw.x,-p_rw.z)*180/Math.PI;
az = (az+360)%360;
el = Math.atan2(p_rw.y,Math.sqrt(p_rw.x*p_rw.x+p_rw.z*p_rw.z))*180/Math.PI;
sk = 0;
// fill out the output
var result = {
x: !round? x : x.toFixed(2),
y: !round? y : y.toFixed(2),
......@@ -180,8 +178,6 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
*/
function x3dom_getCameraPosOr(round){
//console.log("Getting PosOr");
var elem = Scene.element;
var m = elem.runtime.viewMatrix().inverse();
......@@ -203,20 +199,24 @@ function x3dom_getCameraPosOr(round){
//x3dom_matrix_test();
var x = tr.x;
var y = tr.y;
var z = tr.z;
if (!round){
return {
x: tr.x,
y: tr.y,
z: tr.z,
x: x,
y: y,
z: z,
a: ypr.yaw,
e: ypr.pitch,
s: ypr.roll
};
}else{
return {
x: tr.x.toFixed(2),
y: tr.y.toFixed(2),
z: tr.z.toFixed(2),
x: x.toFixed(2),
y: y.toFixed(2),
z: z.toFixed(2),
a: ypr.yaw.toFixed(1),
e: ypr.pitch.toFixed(1),
s: ypr.roll.toFixed(1)
......@@ -244,6 +244,7 @@ function zNear_bug_correction(xyz){
z = z1;
return [x,y,z];
//return xyz;
}
......
......@@ -317,9 +317,7 @@ X3DOMObject.Shape.prototype._registerEvents = function(){
if (self._ctrlKey||SETTINGS.pointer){
// place pointer marker
$("#sliding_sphere").find('material').attr("diffuseColor",convert_color_l2x(SETTINGS.markercolor));
$("#sliding_sphere").find('material').attr("transparency","0.2");
$("#sliding_sphere").find('Sphere').attr("radius",SETTINGS.markersize/2);
X3DOMObject.PointerMarker.updatePars();
X3DOMObject.Marker.place(x,y,z,"sliding_sphere");
$("#sliding_sphere").find("switch").attr("whichChoice",0);
......@@ -362,7 +360,17 @@ X3DOMObject.Shape.prototype._registerEvents = function(){
if (self._ctrlKey){
X3DOMObject.createNewMarker(e.originalEvent.worldX,e.originalEvent.worldY,e.originalEvent.worldZ);
var x = e.originalEvent.worldX;
var y = e.originalEvent.worldY;
var z = e.originalEvent.worldZ;
var xyz = zNear_bug_correction([x,y,z]);
x = xyz[0];
y = xyz[1];
z = xyz[2];
X3DOMObject.createNewMarker(x,y,z);
}
......@@ -451,6 +459,9 @@ X3DOMObject.Shape.deselect = function(elem){
}
/**
* Create marker at x,y,z (need global)
*/
X3DOMObject.prototype.createMarker = function(x,y,z,id){
var self = this;
......@@ -530,6 +541,7 @@ X3DOMObject.Marker = function(x,y,z,ylevel){
X3DOMObject.Marker.prototype.init = function(){
// this branch is experimental and inactive
if (this._ylevel){
//console.log(this._x+" "+this._y+" "+this._z);
......@@ -572,81 +584,6 @@ X3DOMObject.Marker.prototype.init = function(){
}
/*
//var from = new x3dom.fields.SFVec3f(this._x, 100, this._z);
var from = new x3dom.fields.SFVec3f(0, 0, 0);
//var at = new x3dom.fields.SFVec3f(this._x, -100, this._z);
var dir = new x3dom.fields.SFVec3f(0, -0, -1);//at.subtract(from);
// dir gets auto normalized
var vray = new x3dom.fields.Ray(from, dir);
//var vray = Scene.element.runtime.getViewingRay(0,0);
console.log(vray);
var scene = Scene.element.runtime.canvas.doc._scene;
var info = Scene.element.runtime.canvas.doc._viewarea._pickingInfo;
console.log(Scene.element.runtime.pickMode());
//console.log(Scene.element.runtime.changePickMode('idbuf'));
//console.log(Scene.element.runtime.changePickMode('color'));
console.log(Scene.element.runtime.changePickMode('texcoord'));
//console.log(Scene.element.runtime.changePickMode('box'));
console.log(Scene.element.runtime.pickMode());
var isect = scene.doIntersect(vray);
console.log(info);
console.log("vr");
console.log(vray);
if (vray.hitObject!=null){
console.log($(vray.hitObject._xmlNode).parent().find("ImageTexture").attr("url"));
var el = $(vray.hitObject._xmlNode).parent();
var bbox = Scene.element.runtime.getSceneBBox();
console.log(bbox);
this._x = vray.hitPoint.x;
this._y = vray.hitPoint.y;
this._z = vray.hitPoint.z;
}
*/
/*
// sane output
console.log("scene bbox");
var bbox = Scene.element.runtime.getSceneBBox();
console.log(bbox);
*/
/*
var sr = Scene.element.runtime.shootRay(1000,450);
console.log("sr");
console.log(sr);
*/
/*
//while(vray.hitPoint.y>-100){
var n=0;
while(n<1000){
var from = new x3dom.fields.SFVec3f(vray.hitPoint.x,vray.hitPoint.y-0.1,vray.hitPoint.z);
var at = new x3dom.fields.SFVec3f(vray.hitPoint.x, -100, vray.hitPoint.z);
var dir = at.subtract(from).normalize();
var vray = new x3dom.fields.Ray(from, dir);
var isect = scene.doIntersect(vray);
console.log(vray);
n++;
}
*/
//do intersect
//hitobject
//get y
}
this._elem = Scene.createMarker(this._x,this._y,this._z);
......@@ -892,6 +829,7 @@ X3DOMObject.Marker.mouseMove = function(event){
var sphere = Scene.draggedTransformNode.parent().parent();
var index = parseInt(sphere.attr("id").substr(7));
// zNear bug correction
var xyz = [sr.pickPosition.x,sr.pickPosition.y,sr.pickPosition.z];
xyz = zNear_bug_correction(xyz);
......@@ -932,7 +870,13 @@ X3DOMObject.Marker.drag = function(dx,dy){
X3DOMObject.Marker.slide = function(index,x,y,z){
var da = x3dom_getDistAngle(x,y,z);
// camera coordinates, not correcting with zNear
var campos = x3dom_getCameraPosOr();
xc = campos.x;
yc = campos.y;
zc = campos.z;
var da = x3dom_getDistAngle(x-xc,y-yc,z-zc);
var distance = da[0];
var angle = da[1];
......@@ -1013,6 +957,15 @@ X3DOMObject.PointerMarker.prototype._init = function(){
}
X3DOMObject.PointerMarker.updatePars = function(){
// place pointer marker
$("#sliding_sphere").find('material').attr("diffuseColor",convert_color_l2x(SETTINGS.markercolor));
$("#sliding_sphere").find('material').attr("transparency","0.2");
$("#sliding_sphere").find('Sphere').attr("radius",SETTINGS.markersize/2);
}
X3DOMObject.PointerMarker.prototype._registerEvents = function(){
var self = this;
......@@ -1413,7 +1366,14 @@ X3DOMObject.createNewMarker = function(x,y,z){
// Create marker on the scene
new X3DOMObject.Marker(mark.x,mark.y,mark.z);
var da = x3dom_getDistAngle(mark.x,mark.y,mark.z);
// camera coordinates, not correcting with zNear
var campos = x3dom_getCameraPosOr();
xc = campos.x;
yc = campos.y;
zc = campos.z;
// calculate relative to the camera base
var da = x3dom_getDistAngle(mark.x-xc,mark.y-yc,mark.z-zc);
var distance = da[0];
var angle = da[1];
......
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