Commit 5746e1ca authored by Oleg Dzhimiev's avatar Oleg Dzhimiev
Browse files

zNear fix

parent 8a308371
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -489,6 +489,8 @@ function x3d_events(){
        // sliding marker
        if (e.key=="Control"){

            //console.log("Control!");

            X3DOMObject.PointerMarker.updatePars();

            Scene._ctrlKey = true;
@@ -512,6 +514,36 @@ function x3d_events(){

            Map.marker.placeSlidingMarker(mouse.a,dist);

            /*
            // Debugging
            console.log("Canvas event:");
            console.log(e);

            console.log("Page coordinates: x:"+e.path[0].mouse_drag_x+" y:"+e.path[0].mouse_drag_y);

            //shoot a ray
            var cnvx = e.path[0].mouse_drag_x;
            var cnvy = e.path[0].mouse_drag_y;
            var shootRay = elem.runtime.shootRay(cnvx,cnvy);

            var pickPos = shootRay.pickPosition;

            console.log("Shoot ray: "+pickPos.toString());

            var tmp0 = elem.runtime.calcCanvasPos(pickPos.x,pickPos.y,pickPos.z);

            console.log("calcCanvasPos from x,y,z = "+tmp0.toString());


            var mat1 = elem.runtime.getWorldToCameraCoordinatesMatrix();
            var mat2 = elem.runtime.getCameraToWorldCoordinatesMatrix();

            //var w =;

            var vr = elem.runtime.getViewingRay(cnvx,cnvy);
            console.log("Viewing ray: "+vr.toString());
            */

        }

    },true);
+39 −1
Original line number Diff line number Diff line
@@ -230,8 +230,25 @@ function x3dom_getCameraPosOr(round){
 */
function zNear_bug_correction(xyz){

  //var mat = Scene.element.runtime.viewMatrix().inverse();
  var mat = Scene.element.runtime.viewMatrix();

  var mat1 = Scene.element.runtime.getWorldToCameraCoordinatesMatrix();
  var mat2 = Scene.element.runtime.getCameraToWorldCoordinatesMatrix();

  /*
  console.log("wctocc");
  console.log(mat1.toString());
  console.log("cctowc");
  console.log(mat2.toString());
  */

  var zNear = Scene.element.runtime.viewpoint().getNear();

  //console.log("zNear: "+zNear);

  var vec = new x3dom.fields.SFVec3f(xyz[0],xyz[1],xyz[2]);

  var x = xyz[0];
  var y = xyz[1];
  var z = xyz[2];
@@ -243,7 +260,28 @@ function zNear_bug_correction(xyz){
  y = zratio*y;
  z = z1;

  return [x,y,z];
//   console.log("v1: "+x+" "+y+" "+z);

  var vec_cam = mat.multFullMatrixPnt(vec);

  var z1 = vec_cam.z + zNear;
  var zratio = z1 / vec_cam.z;

//   console.log("initial coordinates: "+vec.toString());
//   console.log("camera  coordinates: "+vec_cam.toString());

  //console.log("z1: "+z1+" zratio: "+zratio);

  vec_cam.x = zratio*vec_cam.x;
  vec_cam.y = zratio*vec_cam.y;
  vec_cam.z = z1;

  vec_w = mat.inverse().multFullMatrixPnt(vec_cam);

  //console.log("world coordinates: "+vec_w.toString());

  return [vec_w.x,vec_w.y,vec_w.z];
  //return [x,y,z];
  //return xyz;

}
+4 −0
Original line number Diff line number Diff line
@@ -374,6 +374,10 @@ X3DOMObject.Shape.prototype._registerEvents = function(){

        }

        console.log("Shape event: ");
        console.log("  canvas: x= "+e.originalEvent.layerX+" y= "+e.originalEvent.layerY);
        console.log("  scene: x= "+e.originalEvent.worldX+" y= "+e.originalEvent.worldY+" z="+e.originalEvent.worldZ);

    });

    $(this._elem).on("mouseover",function(e){