Exemplo n.º 1
0
  private float getCylinderDistance(IVector3f i_rayOrigin, IVector3f i_rayDirection) {

    // if we hit one of the end caps, we are done
    float d = getCapDistance(i_rayOrigin, i_rayDirection);
    if (!Float.isNaN(d)) return d;

    // it's much quicker to intersect with a cylinder that stands on the
    // origin and extends along the positive Z axis, so translate the ray
    // accordingly
    Vector3f newOrigin = Draw3DCache.getVector3f();
    try {
      Math3D.translate(i_rayOrigin, -0.5f, -0.5f, 0, newOrigin);

      // now intersect with infinite cylinder along Z axis:
      float xo = newOrigin.getX();
      float yo = newOrigin.getY();
      float xd = i_rayDirection.getX();
      float yd = i_rayDirection.getY();

      float A = xd * xd + yd * yd;
      float B = 2 * (xo * xd + yo * yd);
      float C = xo * xo + yo * yo - 0.25f; // radius^2 = 0.25f

      Math3D.solveQuadraticEquation(A, B, C, TMP_F2);
      return Math3D.minDistance(TMP_F2);
    } finally {
      Draw3DCache.returnVector3f(newOrigin);
    }
  }
Exemplo n.º 2
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.draw3d.ISurface#getSurfaceRotation(org.eclipse.draw3d.geometry.Vector3f)
   */
  public Vector3f getSurfaceRotation(Vector3f o_result) {

    Vector3f zAxis = Draw3DCache.getVector3f();
    try {
      getZAxis(zAxis);
      return Math3D.eulerAngles(zAxis, IVector3f.Z_AXIS, o_result);
    } finally {
      Draw3DCache.returnVector3f(zAxis);
    }
  }
Exemplo n.º 3
0
  private float getConeDistance(IVector3f i_rayOrigin, IVector3f i_rayDirection) {

    // if we hit an end cap, we are done
    float d = getCapDistance(i_rayOrigin, i_rayDirection);
    if (!Float.isNaN(d)) return d;

    // it's much quicker to intersect with a cone whose apex is the
    // origin and that extends along the positive Z axis, so translate the
    // ray accordingly
    Vector3f newOrigin = Draw3DCache.getVector3f();
    try {
      Math3D.translate(i_rayOrigin, -0.5f, -0.5f, 0, newOrigin);
      return doGetConeDistance(newOrigin, i_rayDirection, 0, 1);
    } finally {
      Draw3DCache.returnVector3f(newOrigin);
    }
  }
Exemplo n.º 4
0
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.draw3d.ISurface#findFigureAt(int, int, org.eclipse.draw2d.TreeSearch)
   */
  public IFigure findFigureAt(int i_sx, int i_sy, TreeSearch i_search) {

    Point sLocation = Draw3DCache.getPoint();
    Vector3f rayPoint = Draw3DCache.getVector3f();
    try {
      Picker picker = m_scene.getPicker();
      ISurface currentSurface = picker.getCurrentSurface();

      sLocation.setLocation(i_sx, i_sy);
      currentSurface.getWorldLocation(sLocation, rayPoint);

      Hit hit = picker.getHit(rayPoint, i_search);
      if (hit != null) return hit.getSearchResult();

      if (i_search == null || (!i_search.prune(m_host) && i_search.accept(m_host))) return m_host;

      return null;
    } finally {
      Draw3DCache.returnPoint(sLocation);
      Draw3DCache.returnVector3f(rayPoint);
    }
  }