Пример #1
0
  private Point3d computeWinCoord(
      Canvas3D canvas,
      RenderAtom ra,
      Point2d winCoord,
      Point3d objCoord,
      Transform3D localToImagePlate) {
    // Get local to Vworld transform
    RenderMolecule rm = ra.renderMolecule;

    if (rm == null) {
      // removeRenderAtom() may set ra.renderMolecule to null
      // in RenderBin before this renderer thread run.
      return null;
    }

    // MT safe issue: We can't reference ra.renderMolecule below since
    // RenderBin thread may set it to null anytime. Use rm instead.

    Transform3D lvw = rm.localToVworld[rm.localToVworldIndex[NodeRetained.LAST_LOCAL_TO_VWORLD]];

    Point3d clipCoord3 = new Point3d();
    clipCoord3.set(objCoord);
    Point4d clipCoord4 = new Point4d();

    // Transform point from local coord. to clipping coord.
    lvw.transform(clipCoord3);
    canvas.vworldToEc.transform(clipCoord3);
    canvas.projTrans.transform(clipCoord3, clipCoord4);

    // clip check in Z
    if ((clipCoord4.w <= 0.0) || (clipCoord4.z > clipCoord4.w) || (-clipCoord4.z > clipCoord4.w)) {

      return null;
    }
    double invW = 1.0 / clipCoord4.w;

    clipCoord3.x = clipCoord4.x * invW;
    clipCoord3.y = clipCoord4.y * invW;
    clipCoord3.z = clipCoord4.z * invW;

    // Get Vworld to image plate Xform
    canvas.getLastVworldToImagePlate(localToImagePlate);

    // v' = vwip x lvw x v
    // 		where v' = transformed vertex,
    // 			  lvw = local to Vworld Xform
    //			  vwip = Vworld to Image plate Xform
    //			  v = vertex

    // Compute composite local to image plate Xform
    localToImagePlate.mul(lvw);

    // Transform the Raster's position from object to world coordinates
    localToImagePlate.transform(objCoord);

    // Get the window coordinates of this point
    canvas.getPixelLocationFromImagePlate(objCoord, winCoord);

    return clipCoord3;
  }
Пример #2
0
 @Override
 public void windowOpened(WindowEvent e) {
   if (DEBUG) {
     System.err.println(e);
   }
   canvas.sendEventToBehaviorScheduler(e);
   canvas.evaluateVisiblilty();
 }
Пример #3
0
 @Override
 public void componentShown(ComponentEvent e) {
   if (DEBUG) {
     System.err.println(e);
   }
   if (e.getSource() == canvas) {
     canvas.sendEventToBehaviorScheduler(e);
   }
   canvas.evaluateVisiblilty();
 }
Пример #4
0
 @Override
 public void windowIconified(WindowEvent e) {
   if (DEBUG) {
     System.err.println(e);
   }
   canvas.sendEventToBehaviorScheduler(e);
   if (canvas.view != null) {
     canvas.view.sendEventToSoundScheduler(e);
   }
   canvas.evaluateVisiblilty();
 }
Пример #5
0
 void enableKeyEvents() {
   if (!keyEvents) {
     canvas.addKeyListener(this);
     keyEvents = true;
     // listen for mouseEntered events for keyboard focusing
     if (!mouseListenerAdded) {
       canvas.addMouseListener(this);
       mouseListenerAdded = true;
     }
   }
 }
Пример #6
0
 void disableKeyEvents() {
   if (keyEvents) {
     canvas.removeKeyListener(this);
     keyEvents = false;
     // listen for mouseEntered events for keyboard focusing
     if (!mouseEvents) {
       if (mouseListenerAdded) {
         canvas.removeMouseListener(this);
         mouseListenerAdded = false;
       }
     }
   }
 }
Пример #7
0
 @Override
 public void focusLost(FocusEvent e) {
   canvas.sendEventToBehaviorScheduler(e);
   if (DEBUG) {
     System.err.println(e);
   }
 }
Пример #8
0
 @Override
 public void mouseReleased(MouseEvent e) {
   if (mouseEvents) canvas.sendEventToBehaviorScheduler(e);
   if (DEBUG) {
     System.err.println(e);
   }
 }
Пример #9
0
 @Override
 public void windowDeactivated(WindowEvent e) {
   if (DEBUG) {
     System.err.println(e);
   }
   canvas.sendEventToBehaviorScheduler(e);
 }
Пример #10
0
 @Override
 public void keyTyped(KeyEvent e) {
   canvas.sendEventToBehaviorScheduler(e);
   if (DEBUG) {
     System.err.println(e);
   }
 }
Пример #11
0
 @Override
 public void windowClosing(WindowEvent e) {
   if (DEBUG) {
     System.err.println(e);
   }
   canvas.sendEventToBehaviorScheduler(e);
   // Issue 458 - Don't set canvas.visible to false
 }
Пример #12
0
 @Override
 public void mouseWheelMoved(MouseWheelEvent e) {
   // Note : We don't have to test for mouseWheelEvent here because
   // this routine will never be called unless mouseWheelEvent is enabled.
   canvas.sendEventToBehaviorScheduler(e);
   if (DEBUG) {
     System.err.println(e);
   }
 }
Пример #13
0
 void enableMouseEvents() {
   if (!mouseEvents) {
     mouseEvents = true;
     if (!mouseListenerAdded) {
       canvas.addMouseListener(this);
       mouseListenerAdded = true;
     }
   }
 }
Пример #14
0
 void disableMouseEvents() {
   if (mouseEvents) {
     mouseEvents = false;
     if (!keyEvents) {
       if (mouseListenerAdded) {
         canvas.removeMouseListener(this);
         mouseListenerAdded = false;
       }
     }
   }
 }
Пример #15
0
 @Override
 public void keyReleased(KeyEvent e) {
   canvas.sendEventToBehaviorScheduler(e);
   if (stopped) {
     stopped = false;
   } else {
     stopped = true;
   }
   if (DEBUG) {
     System.err.println(e);
   }
 }
Пример #16
0
  private void computeObjCoord(
      Canvas3D canvas, Point2d winCoord, Point3d objCoord, Transform3D localToImagePlate) {
    // Back transform this pt. from window to object coordinates
    // Assumes this method is ALWAYS called after computeWinCoord has been
    // called. computeWinCoord calculates the Vworld to Image Plate Xform.
    // This method simply uses it without recomputing it.

    canvas.getPixelLocationInImagePlate(winCoord.x, winCoord.y, objCoord.z, objCoord);
    // Get image plate to object coord transform
    // inv(P x M)
    localToImagePlate.invert();
    localToImagePlate.transform(objCoord);
  }
Пример #17
0
  @Override
  public void componentMoved(ComponentEvent e) {
    if (e.getSource() == canvas) {
      if (DEBUG) {
        System.err.println(e);
      }
      canvas.sendEventToBehaviorScheduler(e);

      // Issue 458 - the following is not needed for a move
      //            if (VirtualUniverse.mc.isD3D()) {
      //                canvas.notifyD3DPeer(Canvas3D.RESIZE);
      //            }
      //            canvas.evaluateVisiblilty(true);
    }
  }
Пример #18
0
 @Override
 public void mouseEntered(MouseEvent e) {
   //	if (keyEvents &&
   //           (VirtualUniverse.mc.getRenderingAPI() ==
   //	     MasterControl.RENDER_OPENGL_SOLARIS)) {
   //	     // bug 4362074
   //           canvas.requestFocus();
   //	}
   if (mouseEvents) {
     canvas.sendEventToBehaviorScheduler(e);
   }
   if (DEBUG) {
     System.err.println(e);
   }
 }
Пример #19
0
  @Override
  void execute(
      Canvas3D cv,
      RenderAtom ra,
      boolean isNonUniformScale,
      boolean updateAlpha,
      float alpha,
      int screen,
      boolean ignoreVertexColors) {

    Transform3D trans = new Transform3D();

    for (int i = 0; i < geometryList.length; i++) {
      trans.set(drawTransform);
      trans.mul(charTransforms[i]);
      cv.setModelViewMatrix(cv.ctx, vpcToEc.mat, trans);
      geometryList[i].execute(
          cv, ra, isNonUniformScale, updateAlpha, alpha, screen, ignoreVertexColors);
    }
  }
Пример #20
0
  @Override
  void execute(
      Canvas3D cv,
      RenderAtom ra,
      boolean isNonUniformScale,
      boolean updateAlpha,
      float alpha,
      int screen,
      boolean ignoreVertexColors) {

    // Compute the offset position of the raster
    // This has to be done at render time because we need access
    // to the Canvas3D info

    // Check if adjusted position needs to be computed
    Point3d adjPos = new Point3d(); // Position of the Raster after adjusting for dstOffset
    adjPos.set(position);

    Point2d winCoord = new Point2d(); // Position of Raster in window coordinates
    Transform3D localToImagePlate = new Transform3D(); // Local to Image plate transform

    Point3d clipCoord = computeWinCoord(cv, ra, winCoord, adjPos, localToImagePlate);

    // Test raster for out of bounds in Z.
    if (clipCoord == null) {
      return;
    }

    if (clipMode == Raster.CLIP_POSITION) {
      // Do trivial reject test on Raster position.
      if (!isRasterClipPositionInside(clipCoord)) {
        return;
      }
    }

    // Add the destination offset to the Raster position in window coordinates
    winCoord.x += xDstOffset;
    winCoord.y += yDstOffset;

    // System.err.println("Step 2 : adjPos " + adjPos + " winCoord " + winCoord);

    if ((type == Raster.RASTER_COLOR) || (type == Raster.RASTER_COLOR_DEPTH)) {
      float devCoordZ = (float) (clipCoord.z * 0.5 - 0.5);
      // Do textfill stuffs
      if (texture != null) {
        // setup Texture pipe.
        cv.updateTextureForRaster(texture);

        cv.textureFill(this, winCoord, devCoordZ, alpha);

        // Restore texture pipe.
        cv.restoreTextureBin();
      }
    }

    if ((type == Raster.RASTER_DEPTH) || (type == Raster.RASTER_COLOR_DEPTH)) {

      Point2i srcOffset = new Point2i(xSrcOffset, ySrcOffset);

      if (clipMode == Raster.CLIP_IMAGE) {
        clipImage(cv, ra, winCoord, srcOffset);
      }

      computeObjCoord(cv, winCoord, adjPos, localToImagePlate);

      cv.executeRasterDepth(
          cv.ctx,
          (float) adjPos.x,
          (float) adjPos.y,
          (float) adjPos.z,
          srcOffset.x,
          srcOffset.y,
          width,
          height,
          depthComponent.width,
          depthComponent.height,
          depthComponent.type,
          ((DepthComponentIntRetained) depthComponent).depthData);
    }
  }
Пример #21
0
  /**
   * Invoked when a window is changed from a minimized to a normal state.
   *
   * @param evt The window event that caused the method to be called.
   */
  public void windowDeiconified(WindowEvent evt) {
    if (frameMillis < 0) mainCanvas.setMinimumFrameInterval(0, false);
    else mainCanvas.setMinimumFrameInterval(frameMillis, false);

    j3dCanvas.requestFocusInWindow();
  }
Пример #22
0
 /**
  * The window has opened, so requst input focus.
  *
  * @param evt The window event that caused the method to be called.
  */
 public void windowOpened(WindowEvent evt) {
   j3dCanvas.requestFocusInWindow();
 }
Пример #23
0
 void disableFocusEvents() {
   if (focusEvents) {
     canvas.removeFocusListener(this);
     focusEvents = false;
   }
 }
Пример #24
0
 void enableFocusEvents() {
   if (!focusEvents) {
     canvas.addFocusListener(this);
     focusEvents = true;
   }
 }
Пример #25
0
  // called on the parent object
  // Should be synchronized so that the user thread does not modify the
  // OrientedShape3D params while computing the transform
  synchronized void updateOrientedTransform(Canvas3D canvas, int viewIndex) {
    double angle = 0.0;
    double sign;
    boolean status;

    Transform3D orientedxform = getOrientedTransform(viewIndex);
    //  get viewplatforms's location in virutal world
    if (mode == OrientedShape3D.ROTATE_ABOUT_AXIS) { // rotate about axis
      canvas.getCenterEyeInImagePlate(viewPosition);
      canvas.getImagePlateToVworld(xform); // xform is imagePlateToLocal
      xform.transform(viewPosition);

      // get billboard's transform
      xform.set(getCurrentLocalToVworld());
      xform.invert(); // xform is now vWorldToLocal

      // transform the eye position into the billboard's coordinate system
      xform.transform(viewPosition);

      // eyeVec is a vector from the local origin to the eye pt in local
      eyeVec.set(viewPosition);
      eyeVec.normalize();

      // project the eye into the rotation plane
      status = projectToPlane(eyeVec, nAxis);

      if (status) {
        // project the z axis into the rotation plane
        zAxis.x = 0.0;
        zAxis.y = 0.0;
        zAxis.z = 1.0;
        status = projectToPlane(zAxis, nAxis);
      }
      if (status) {

        // compute the sign of the angle by checking if the cross product
        // of the two vectors is in the same direction as the normal axis
        vector.cross(eyeVec, zAxis);
        if (vector.dot(nAxis) > 0.0) {
          sign = 1.0;
        } else {
          sign = -1.0;
        }

        // compute the angle between the projected eye vector and the
        // projected z

        double dot = eyeVec.dot(zAxis);
        if (dot > 1.0f) {
          dot = 1.0f;
        } else if (dot < -1.0f) {
          dot = -1.0f;
        }

        angle = sign * Math.acos(dot);

        // use -angle because xform is to *undo* rotation by angle
        aa.x = nAxis.x;
        aa.y = nAxis.y;
        aa.z = nAxis.z;
        aa.angle = -angle;
        orientedxform.set(aa);
      } else {
        orientedxform.setIdentity();
      }

    } else if (mode == OrientedShape3D.ROTATE_ABOUT_POINT) { // rotate about point
      // Need to rotate Z axis to point to eye, and Y axis to be
      // parallel to view platform Y axis, rotating around rotation pt

      // get the eye point
      canvas.getCenterEyeInImagePlate(viewPosition);

      // derive the yUp point
      yUpPoint.set(viewPosition);
      yUpPoint.y += 0.01; // one cm in Physical space

      // transform the points to the Billboard's space
      canvas.getImagePlateToVworld(xform); // xform is ImagePlateToVworld
      xform.transform(viewPosition);
      xform.transform(yUpPoint);

      // get billboard's transform
      xform.set(getCurrentLocalToVworld());
      xform.invert(); // xform is vWorldToLocal

      // transfom points to local coord sys
      xform.transform(viewPosition);
      xform.transform(yUpPoint);

      // Make a vector from viewPostion to 0,0,0 in the BB coord sys
      eyeVec.set(viewPosition);
      eyeVec.normalize();

      // create a yUp vector
      yUp.set(yUpPoint);
      yUp.sub(viewPosition);
      yUp.normalize();

      // find the plane to rotate z
      zAxis.x = 0.0;
      zAxis.y = 0.0;
      zAxis.z = 1.0;

      // rotation axis is cross product of eyeVec and zAxis
      vector.cross(eyeVec, zAxis); // vector is cross product

      // if cross product is non-zero, vector is rotation axis and
      // rotation angle is acos(eyeVec.dot(zAxis)));
      double length = vector.length();
      if (length > 0.0001) {
        double dot = eyeVec.dot(zAxis);
        if (dot > 1.0f) {
          dot = 1.0f;
        } else if (dot < -1.0f) {
          dot = -1.0f;
        }
        angle = Math.acos(dot);
        aa.x = vector.x;
        aa.y = vector.y;
        aa.z = vector.z;
        aa.angle = -angle;
        zRotate.set(aa);
      } else {
        // no rotation needed, set to identity (scale = 1.0)
        zRotate.set(1.0);
      }

      // Transform the yAxis by zRotate
      yAxis.x = 0.0;
      yAxis.y = 1.0;
      yAxis.z = 0.0;
      zRotate.transform(yAxis);

      // project the yAxis onto the plane perp to the eyeVec
      status = projectToPlane(yAxis, eyeVec);

      if (status) {
        // project the yUp onto the plane perp to the eyeVec
        status = projectToPlane(yUp, eyeVec);
      }

      if (status) {
        // rotation angle is acos(yUp.dot(yAxis));
        double dot = yUp.dot(yAxis);

        // Fix numerical error, otherwise acos return NULL
        if (dot > 1.0f) {
          dot = 1.0f;
        } else if (dot < -1.0f) {
          dot = -1.0f;
        }

        angle = Math.acos(dot);

        // check the sign by looking a the cross product vs the eyeVec
        vector.cross(yUp, yAxis); // vector is cross product
        if (eyeVec.dot(vector) < 0) {
          angle *= -1;
        }
        aa.x = eyeVec.x;
        aa.y = eyeVec.y;
        aa.z = eyeVec.z;
        aa.angle = -angle;
        xform.set(aa); // xform is now yRotate

        // rotate around the rotation point
        vector.x = rotationPoint.x;
        vector.y = rotationPoint.y;
        vector.z = rotationPoint.z; // vector to translate to RP
        orientedxform.set(vector); // translate to RP
        orientedxform.mul(xform); // yRotate
        orientedxform.mul(zRotate); // zRotate
        vector.scale(-1.0); // vector to translate back
        xform.set(vector); // xform to translate back
        orientedxform.mul(xform); // translate back
      } else {
        orientedxform.setIdentity();
      }
    }
    // Scale invariant computation
    if (constantScale) {
      // Back Xform a unit vector to local world coords
      canvas.getInverseVworldProjection(left_xform, right_xform);

      // the two endpts of the vector have to be transformed
      // individually because the Xform is not affine
      im_vec[0].set(0.0, 0.0, 0.0, 1.0);
      im_vec[1].set(1.0, 0.0, 0.0, 1.0);
      left_xform.transform(im_vec[0]);
      left_xform.transform(im_vec[1]);

      left_xform.set(getCurrentLocalToVworld());
      left_xform.invert();
      left_xform.transform(im_vec[0]);
      left_xform.transform(im_vec[1]);
      lvec.set(im_vec[1]);
      lvec.sub(im_vec[0]);

      // We simply need the direction of this vector
      lvec.normalize();
      im_vec[0].set(0.0, 0.0, 0.0, 1.0);
      im_vec[1].set(lvec);
      im_vec[1].w = 1.0;

      // Forward Xfrom to clip coords
      left_xform.set(getCurrentLocalToVworld());
      left_xform.transform(im_vec[0]);
      left_xform.transform(im_vec[1]);

      canvas.getVworldProjection(left_xform, right_xform);
      left_xform.transform(im_vec[0]);
      left_xform.transform(im_vec[1]);

      // Perspective division
      im_vec[0].x /= im_vec[0].w;
      im_vec[0].y /= im_vec[0].w;
      im_vec[0].z /= im_vec[0].w;

      im_vec[1].x /= im_vec[1].w;
      im_vec[1].y /= im_vec[1].w;
      im_vec[1].z /= im_vec[1].w;

      lvec.set(im_vec[1]);
      lvec.sub(im_vec[0]);

      // Use the length of this vector to determine the scaling
      // factor
      double scale = 1 / lvec.length();

      // Convert to meters
      scale *= scaleFactor * canvas.getPhysicalWidth() / 2;

      // Scale object so that it appears the same size
      scaleXform.setScale(scale);
      orientedxform.mul(scaleXform);
    }
  }
Пример #26
0
 void enableMouseMotionEvents() {
   if (!mouseMotionEvents) {
     canvas.addMouseMotionListener(this);
     mouseMotionEvents = true;
   }
 }
Пример #27
0
 void disableMouseMotionEvents() {
   if (mouseMotionEvents) {
     canvas.removeMouseMotionListener(this);
     mouseMotionEvents = false;
   }
 }
Пример #28
0
 void enableMouseWheelEvents() {
   if (!mouseWheelEvents) {
     canvas.addMouseWheelListener(this);
     mouseWheelEvents = true;
   }
 }
Пример #29
0
 void disableMouseWheelEvents() {
   if (mouseWheelEvents) {
     canvas.removeMouseWheelListener(this);
     mouseWheelEvents = false;
   }
 }
Пример #30
0
 /**
  * The window has been given focus.
  *
  * @param evt The window event that caused the method to be called.
  */
 public void windowActivated(WindowEvent evt) {
   j3dCanvas.requestFocusInWindow();
 }