Commit 38c56432 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

fixed zNear x3dom 1.7.2 bug?

parent f7519622
......@@ -60,6 +60,10 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
//console.log("That event:");
//console.log(Scene._stored_x3dom_event);
var campos = x3dom_getCameraPosOr();
var xc = campos.x;
var yc = campos.y;
var zc = campos.z;
var shootRay = elem.runtime.shootRay(cnvx,cnvy);
......@@ -89,7 +93,13 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
y = shootRay.pickPosition.y;
z = shootRay.pickPosition.z;
dist_xz = Math.sqrt(x*x+z*z);
var xyz = zNear_bug_correction([x,y,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{
......@@ -99,11 +109,11 @@ function x3dom_getXYPosOr(cnvx,cnvy,round){
dist_xz = Data.markers[index].d_x3d;
if (isNaN(dist_xz)){
dist_xz = Math.sqrt(x*x+z*z);
dist_xz = Math.sqrt(Math.pow(x-xc,2)+Math.pow(z-zc,2));;
}
}
dist_xyz = Math.sqrt(y*y+dist_xz*dist_xz);
dist_xyz = Math.sqrt(Math.pow(y-yc,2)+Math.pow(dist_xz,2));
id = $(shootRay.pickObject).attr("id");
......@@ -214,6 +224,28 @@ function x3dom_getCameraPosOr(round){
}
/**
* Fix a bug with zNear in x3dom 1.7.2
*/
function zNear_bug_correction(xyz){
var zNear = Scene.element.runtime.viewpoint().getNear();
var x = xyz[0];
var y = xyz[1];
var z = xyz[2];
var z1 = z + zNear;
var zratio = z1/z;
x = zratio*x;
y = zratio*y;
z = z1;
return [x,y,z];
}
// this upright is for world coordinates, not the camera's
// the up vector should be taken from the initial camera orientation in kml.
function x3dom_setUpRight(){
......
......@@ -305,6 +305,12 @@ X3DOMObject.Shape.prototype._registerEvents = function(){
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];
// (not used atm) store x3dom event to use in normal events
self._stored_x3dom_event = e.originalEvent;
......@@ -547,6 +553,13 @@ X3DOMObject.Marker.prototype.init = function(){
x = sr.pickPosition.x;
y = sr.pickPosition.y;
z = sr.pickPosition.z;
var xyz = zNear_bug_correction([x,y,z]);
x = xyz[0];
y = xyz[1];
z = xyz[2];
d1 = Math.sqrt(x*x+z*z);
if ((d1-d0)<0.1){
......@@ -879,10 +892,13 @@ X3DOMObject.Marker.mouseMove = function(event){
var sphere = Scene.draggedTransformNode.parent().parent();
var index = parseInt(sphere.attr("id").substr(7));
X3DOMObject.Marker.place(sr.pickPosition.x,sr.pickPosition.y,sr.pickPosition.z,"my-sph-"+index);
var xyz = [sr.pickPosition.x,sr.pickPosition.y,sr.pickPosition.z];
xyz = zNear_bug_correction(xyz);
X3DOMObject.Marker.place(xyz[0],xyz[1],xyz[2],"my-sph-"+index);
//console.log("got shape");
//Scene.draggedTransformNode
X3DOMObject.Marker.slide(index,sr.pickPosition.x,sr.pickPosition.y,sr.pickPosition.z);
X3DOMObject.Marker.slide(index,xyz[0],xyz[1],xyz[2]);
X3DOMObject.displayInfo(event);
X3DOMObject.displayViewInfo(event);
......
......@@ -55,7 +55,9 @@
<x3d id="x3d_id" width='1600px' height='800px' showProgress="true" showStat="false" showLog="false" disableDoubleClick="true" keysEnabled="true">
<scene>
<navigationInfo id="navInfo" type='"examine"' speed='0.01'></navigationInfo>
<Viewpoint fieldOfView='1' position='0 0 0' orientation='0 0 1 0'></Viewpoint>
<Viewpoint fieldOfView='1' position='0 0 0' orientation='0 0 1 0' ></Viewpoint>
<!-- in x3dom 1.7.2 - big zNear does not work properly -->
<!--<Viewpoint fieldOfView='1' position='0 0 0' orientation='0 0 1 0' zNear='2'></Viewpoint>-->
<!-- <group>
<inline name="back" namespacename="back" url="models/m1/v1/background.x3d"/>
</group>-->
......
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