Package javax.vecmath

Examples of javax.vecmath.Vector3d


//        rotation.fromRotationMatrix(rot);

        // Correctly compute the inversion, use Vecmath as the matrix invert
        // in JME does not function when scale!=1
        Quat4d q = new Quat4d(rotation.x, rotation.y, rotation.z, rotation.w);
        Vector3d t = new Vector3d(translation.x, translation.y, translation.z);
        Matrix4d m = new Matrix4d(q,t,scale);
        m.invert();

        m.get(q);
        m.get(t);
View Full Code Here


/**
* Returns the square of the minimum distance from the given point to the segment
* defined by start, end.
*/
static final double ptToSegSquare(Point3d pt, Point3d start, Point3d end, Point3d closest) {
  Vector3d dir = new Vector3d();
  dir.sub(end, start);

  Vector3d dt = new Vector3d();
  dt.sub(pt, start);

  // Project the point onto the line defined by the segment
  double proj = dir.dot(dt);

  // We projected 'before' the start point, just return the dSquared between
  // the point and the start
  if (proj <= 0.0d) {
    if (closest != null) closest.set(start);
    return dt.lengthSquared();
  }

  // Project the segment onto itself
  double segSquared = dir.lengthSquared();

  // If our point projected off the end of the segment, return the dSquared between
  // the point and the end
  if (proj >= segSquared) {
    if (closest != null) closest.set(end);
    dt.sub(pt, end);
    return dt.lengthSquared();
  }

  // We projected somewhere along the segment, calculate the closest point
  dt.scaleAdd(proj / segSquared, dir, start);
  if (closest != null) closest.set(dt);

  // return the distance from the point to the closest point on the segment
  dt.sub(pt, dt);
  return dt.lengthSquared();
}
View Full Code Here

/**
* Returns the square of the minimum distance from the given point to the ray
* defined by start, dir.
*/
static final double ptToRaySquare(Point3d pt, Point3d start, Vector3d dir, Point3d closest) {
  Vector3d dt = new Vector3d();
  dt.sub(pt, start);

  // Project the point onto the ray
  double proj = dir.dot(dt);

  // We projected 'before' the start point, just return the dSquared between
  // the point and the start
  if (proj <= 0.0d) {
    if (closest != null) closest.set(start);
    return dt.lengthSquared();
  }

  // Project the ray onto itself
  double raySquared = dir.lengthSquared();

  // We projected somewhere along the ray, calculate the closest point
  dt.scaleAdd(proj / raySquared, dir, start);
  if (closest != null) closest.set(dt);

  // return the distance from the point to the closest point on the ray
  dt.sub(pt, dt);
  return dt.lengthSquared();
}
View Full Code Here

static public double rayToSegment(Point3d rayorig, Vector3d raydir,
                                  Point3d segstart, Point3d segend,
                                  Point3d rayint, Point3d segint, double[] param) {
  double s, t;

  Vector3d diff = new Vector3d();
  diff.sub(rayorig, segstart);
  Vector3d segdir = new Vector3d();
  segdir.sub(segend, segstart);

  double A = raydir.dot(raydir);// Dot(ray.m,ray.m);
  double B = -raydir.dot(segdir);// -Dot(ray.m,seg.m);
  double C = segdir.dot(segdir);// Dot(seg.m,seg.m);
  double D = raydir.dot(diff);// Dot(ray.m,diff);
  double E; // -Dot(seg.m,diff), defer until needed
  double F = diff.dot(diff);// Dot(diff,diff);
  double det = Math.abs(A * C - B * B); // A*C-B*B = |Cross(M0,M1)|^2 >= 0

  double tmp;

  if (det >= ZERO_TOL) {
    // ray and segment are not parallel
    E = -segdir.dot(diff);// -Dot(seg.m,diff);
    s = B * E - C * D;
    t = B * D - A * E;

    if (s >= 0) {
      if (t >= 0) {
        if (t <= det) { // region 0
          // minimum at interior points of ray and segment
          double invDet = 1.0f / det;
          s *= invDet;
          t *= invDet;
          if (rayint != null) rayint.scaleAdd(s, raydir, rayorig);
          if (segint != null) segint.scaleAdd(t, segdir, segstart);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(s * (A * s + B * t + 2 * D) + t
              * (B * s + C * t + 2 * E) + F);
        }
        else { // region 1

          t = 1;
          if (D >= 0) {
            s = 0;
            if (rayint != null) rayint.set(rayorig);
            if (segint != null) segint.set(segend);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(C + 2 * E + F);
          }
          else {
            s = -D / A;
            if (rayint != null) rayint.scaleAdd(s, raydir, rayorig);
            if (segint != null) segint.set(segend);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs((D + 2 * B) * s + C + 2 * E + F);
          }
        }
      }
      else { // region 5
        t = 0;
        if (D >= 0) {
          s = 0;
          if (rayint != null) rayint.set(rayorig);
          if (segint != null) segint.set(segstart);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(F);
        }
        else {
          s = -D / A;
          if (rayint != null) rayint.scaleAdd(s, raydir, rayorig);
          if (segint != null) segint.set(segstart);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(D * s + F);
        }
      }
    }
    else {
      if (t <= 0) { // region 4
        if (D < 0) {
          s = -D / A;
          t = 0;
          if (rayint != null) rayint.scaleAdd(s, raydir, rayorig);
          if (segint != null) segint.set(segstart);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(D * s + F);
        }
        else {
          s = 0;
          if (E >= 0) {
            t = 0;
            if (rayint != null) rayint.set(rayorig);
            if (segint != null) segint.set(segstart);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(F);
          }
          else if (-E >= C) {
            t = 1;
            if (rayint != null) rayint.set(rayorig);
            if (segint != null) segint.set(segend);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(C + 2 * E + F);
          }
          else {
            t = -E / C;
            if (rayint != null) rayint.set(rayorig);
            if (segint != null) segint.scaleAdd(t, segdir, segstart);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(E * t + F);
          }
        }
      }
      else if (t <= det) { // region 3
        s = 0;
        if (E >= 0) {
          t = 0;
          if (rayint != null) rayint.set(rayorig);
          if (segint != null) segint.set(segstart);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(F);
        }
        else if (-E >= C) {
          t = 1;
          if (rayint != null) rayint.set(rayorig);
          if (segint != null) segint.set(segend);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(C + 2 * E + F);
        }
        else {
          t = -E / C;
          if (rayint != null) rayint.set(rayorig);
          if (segint != null) segint.scaleAdd(t, segdir, segstart);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(E * t + F);
        }
      }
      else { // region 2
        tmp = B + D;
        if (tmp < 0) {
          s = -tmp / A;
          t = 1;
          if (rayint != null) rayint.scaleAdd(s, raydir, rayorig);
          if (segint != null) segint.set(segend);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(tmp * s + C + 2 * E + F);
        }
        else {
          s = 0;
          if (E >= 0) {
            t = 0;
            if (rayint != null) rayint.set(rayorig);
            if (segint != null) segint.set(segstart);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(F);
          }
          else if (-E >= C) {
            t = 1;
            if (rayint != null) rayint.set(rayorig);
            if (segint != null) segint.set(segend);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(C + 2 * E + F);
          }
          else {
            t = -E / C;
            if (rayint != null) rayint.set(rayorig);
            if (segint != null) segint.scaleAdd(t, segdir, segstart);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(E * t + F);
          }
        }
      }
    }
  }
  else {
    // ray and segment are parallel
    if (B > 0) {
      // opposite direction vectors
      t = 0;
      if (D >= 0) {
        s = 0;
        if (rayint != null) rayint.set(rayorig);
        if (segint != null) segint.set(segstart);
        if (param != null) { param[0] = s; param[1] = t; }
        return Math.abs(F);
      }
      else {
        s = -D / A;
        if (rayint != null) rayint.scaleAdd(s, raydir, rayorig);
        if (segint != null) segint.set(segstart);
        if (param != null) { param[0] = s; param[1] = t; }
        return Math.abs(D * s + F);
      }
    }
    else {
      // same direction vectors
      E = segdir.dot(diff);// -Dot(seg.m,diff);
      t = 1;
      tmp = B + D;
      if (tmp >= 0) {
        s = 0;
        if (rayint != null) rayint.set(rayorig);
View Full Code Here

static public double segmentToSegment(Point3d s0start, Point3d s0end,
                                      Point3d s1start, Point3d s1end,
                                      Point3d s0int, Point3d s1int, double[] param) {
  double s, t;

  Vector3d diff = new Vector3d();
  diff.sub(s0start, s1start);

  Vector3d seg0dir = new Vector3d();
  seg0dir.sub(s0end, s0start);
  Vector3d seg1dir = new Vector3d();
  seg1dir.sub(s1end, s1start);

  double A = seg0dir.dot(seg0dir); // Dot(seg0dir,seg0dir);
  double B = -seg0dir.dot(seg1dir); // -Dot(seg0dir,seg1dir);
  double C = seg1dir.dot(seg1dir); // Dot(seg1dir,seg1dir);
  double D = seg0dir.dot(diff); // Dot(seg0dir,diff);
  double E; // -Dot(seg1dir,diff), defer until needed
  double F = diff.dot(diff); // Dot(diff,diff);
  double det = Math.abs(A * C - B * B); // A*C-B*B = |Cross(M0,M1)|^2 >= 0

  double tmp;

  if (det >= ZERO_TOL) {
    // line segments are not parallel
    E = -seg1dir.dot(diff); // -Dot(seg1dir,diff);
    s = B * E - C * D;
    t = B * D - A * E;

    if (s >= 0) {
      if (s <= det) {
        if (t >= 0) {
          if (t <= det) { // region 0 (interior)
            // minimum at two interior points of 3D lines
            double invDet = 1.0f / det;
            s *= invDet;
            t *= invDet;
            if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
            if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(s * (A * s + B * t + 2 * D) + t
                * (B * s + C * t + 2 * E) + F);
          }
          else { // region 3 (side)
            t = 1;
            tmp = B + D;
            if (tmp >= 0) {
              s = 0;
              if (s0int != null) s0int.set(s0start);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(C + 2 * E + F);
            }
            else if (-tmp >= A) {
              s = 1;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(A + C + F + 2 * (E + tmp));
            }
            else {
              s = -tmp / A;
              if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(tmp * s + C + 2 * E + F);
            }
          }
        }
        else { // region 7 (side)
          t = 0;
          if (D >= 0) {
            s = 0;
            if (s0int != null) s0int.set(s0start);
            if (s1int != null) s1int.set(s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(F);
          }
          else if (-D >= A) {
            s = 1;
            if (s0int != null) s0int.set(s0end);
            if (s1int != null) s1int.set(s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(A + 2 * D + F);
          }
          else {
            s = -D / A;
            if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
            if (s1int != null) s1int.set(s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(D * s + F);
          }
        }
      }
      else {
        if (t >= 0) {
          if (t <= det) { // region 1 (side)
            s = 1;
            tmp = B + E;
            if (tmp >= 0) {
              t = 0;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.set(s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(A + 2 * D + F);
            }
            else if (-tmp >= C) {
              t = 1;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(A + C + F + 2 * (D + tmp));
            }
            else {
              t = -tmp / C;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(tmp * t + A + 2 * D + F);
            }
          }
          else { // region 2 (corner)
            tmp = B + D;
            if (-tmp <= A) {
              t = 1;
              if (tmp >= 0) {
                s = 0;
                if (s0int != null) s0int.set(s0start);
                if (s1int != null) s1int.set(s1end);
                if (param != null) { param[0] = s; param[1] = t; }
                return Math.abs(C + 2 * E + F);
              }
              else {
                s = -tmp / A;
                if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
                if (s1int != null) s1int.set(s1end);
                if (param != null) { param[0] = s; param[1] = t; }
                return Math.abs(tmp * s + C + 2 * E + F);
              }
            }
            else {
              s = 1;
              tmp = B + E;
              if (tmp >= 0) {
                t = 0;
                if (s0int != null) s0int.set(s0end);
                if (s1int != null) s1int.set(s1start);
                if (param != null) { param[0] = s; param[1] = t; }
                return Math.abs(A + 2 * D + F);
              }
              else if (-tmp >= C) {
                t = 1;
                if (s0int != null) s0int.set(s0end);
                if (s1int != null) s1int.set(s1end);
                if (param != null) { param[0] = s; param[1] = t; }
                return Math.abs(A + C + F + 2 * (D + tmp));
              }
              else {
                t = -tmp / C;
                if (s0int != null) s0int.set(s0end);
                if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
                if (param != null) { param[0] = s; param[1] = t; }
                return Math.abs(tmp * t + A + 2 * D + F);
              }
            }
          }
        }
        else { // region 8 (corner)
          if (-D < A) {
            t = 0;
            if (D >= 0) {
              s = 0;
              if (s0int != null) s0int.set(s0start);
              if (s1int != null) s1int.set(s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(F);
            }
            else {
              s = -D / A;
              if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
              if (s1int != null) s1int.set(s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(D * s + F);
            }
          }
          else {
            s = 1;
            tmp = B + E;
            if (tmp >= 0) {
              t = 0;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.set(s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(A + 2 * D + F);
            }
            else if (-tmp >= C) {
              t = 1;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(A + C + F + 2 * (D + tmp));
            }
            else {
              t = -tmp / C;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(tmp * t + A + 2 * D + F);
            }
          }
        }
      }
    }
    else {
      if (t >= 0) {
        if (t <= det) { // region 5 (side)
          s = 0;
          if (E >= 0) {
            t = 0;
            if (s0int != null) s0int.set(s0start);
            if (s1int != null) s1int.set(s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(F);
          }
          else if (-E >= C) {
            t = 1;
            if (s0int != null) s0int.set(s0start);
            if (s1int != null) s1int.set(s1end);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(C + 2 * E + F);
          }
          else {
            t = -E / C;
            if (s0int != null) s0int.set(s0start);
            if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(E * t + F);
          }
        }
        else { // region 4 (corner)
          tmp = B + D;
          if (tmp < 0) {
            t = 1;
            if (-tmp >= A) {
              s = 1;
              if (s0int != null) s0int.set(s0end);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(A + C + F + 2 * (E + tmp));
            }
            else {
              s = -tmp / A;
              if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(tmp * s + C + 2 * E + F);
            }
          }
          else {
            s = 0;
            if (E >= 0) {
              t = 0;
              if (s0int != null) s0int.set(s0start);
              if (s1int != null) s1int.set(s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(F);
            }
            else if (-E >= C) {
              t = 1;
              if (s0int != null) s0int.set(s0start);
              if (s1int != null) s1int.set(s1end);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(C + 2 * E + F);
            }
            else {
              t = -E / C;
              if (s0int != null) s0int.set(s0start);
              if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
              if (param != null) { param[0] = s; param[1] = t; }
              return Math.abs(E * t + F);
            }
          }
        }
      }
      else { // region 6 (corner)
        if (D < 0) {
          t = 0;
          if (-D >= A) {
            s = 1;
            if (s0int != null) s0int.set(s0end);
            if (s1int != null) s1int.set(s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(A + 2 * D + F);
          }
          else {
            s = -D / A;
            if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
            if (s1int != null) s1int.set(s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(D * s + F);
          }
        }
        else {
          s = 0;
          if (E >= 0) {
            t = 0;
            if (s0int != null) s0int.set(s0start);
            if (s1int != null) s1int.set(s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(F);
          }
          else if (-E >= C) {
            t = 1;
            if (s0int != null) s0int.set(s0start);
            if (s1int != null) s1int.set(s1end);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(C + 2 * E + F);
          }
          else {
            t = -E / C;
            if (s0int != null) s0int.set(s0start);
            if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
            if (param != null) { param[0] = s; param[1] = t; }
            return Math.abs(E * t + F);
          }
        }
      }
    }
  }
  else {
    // line segments are parallel
    if (B > 0) {
      // direction vectors form an obtuse angle
      if (D >= 0) {
        s = 0;
        t = 0;
        if (s0int != null) s0int.set(s0start);
        if (s1int != null) s1int.set(s1start);
        if (param != null) { param[0] = s; param[1] = t; }
        return Math.abs(F);
      }
      else if (-D <= A) {
        s = -D / A;
        t = 0;
        if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
        if (s1int != null) s1int.set(s1start);
        if (param != null) { param[0] = s; param[1] = t; }
        return Math.abs(D * s + F);
      }
      else {
        E = -seg1dir.dot(diff); // -Dot(seg1dir,diff);
        s = 1;
        tmp = A + D;
        if (-tmp >= B) {
          t = 1;
          if (s0int != null) s0int.set(s0end);
          if (s1int != null) s1int.set(s1end);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(A + C + F + 2 * (B + D + E));
        }
        else {
          t = -tmp / B;
          if (s0int != null) s0int.set(s0end);
          if (s1int != null) s1int.scaleAdd(t, seg1dir, s1start);
          if (param != null) { param[0] = s; param[1] = t; }
          return Math.abs(A + 2 * D + F + t * (C * t + 2 * (B + E)));
        }
      }
    }
    else {
      // direction vectors form an acute angle
      if (-D >= A) {
        s = 1;
        t = 0;
        if (s0int != null) s0int.set(s0end);
        if (s1int != null) s1int.set(s1start);
        if (param != null) { param[0] = s; param[1] = t; }
        return Math.abs(A + 2 * D + F);
      }
      else if (D <= 0) {
        s = -D / A;
        t = 0;
        if (s0int != null) s0int.scaleAdd(s, seg0dir, s0start);
        if (s1int != null) s1int.set(s1start);
        if (param != null) { param[0] = s; param[1] = t; }
        return Math.abs(D * s + F);
      }
      else {
        E = -seg1dir.dot(diff); // -Dot(seg1dir,diff);
        s = 0;
        if (D >= -B) {
          t = 1;
          if (s0int != null) s0int.set(s0start);
          if (s1int != null) s1int.set(s1end);
View Full Code Here

    }
      }
      break;
  case PickShape.PICKSEGMENT:
      PickSegment pickSegment = (PickSegment) pickShape;
      Vector3d dir =
    new Vector3d(pickSegment.end.x - pickSegment.start.x,
           pickSegment.end.y - pickSegment.start.y,
           pickSegment.end.z - pickSegment.start.z);

      while (i < stripIndexCounts.length) {
                vtxIndexArr[0] = indexCoord[count];
View Full Code Here

  int i = 0;
  int j, count=0;
  int scount;
  Point3d[] points = new Point3d[2];
  double dist[] = new double[1];
  Vector3d dir;

  points[0] = new Point3d();
  points[1] = new Point3d();

  switch (pnts.length) {
  case 3:
  case 4: // Triangle, Quad
     while (i < stripIndexCounts.length) {
    getVertexData(indexCoord[count++], points[0]);
    scount = stripIndexCounts[i++];
    for (j=1; j < scount; j++) {
        getVertexData(indexCoord[count++], points[1]);
        if (intersectSegment(pnts, points[0], points[1],
           dist, null)) {
      return true;
        }
        points[0].set(points[1]);
    }
      }
      break;
  case 2: // line
      dir = new Vector3d();
      while (i < stripIndexCounts.length) {
    getVertexData(indexCoord[count++], points[0]);
    scount = stripIndexCounts[i++];
    for (j=1; j < scount; j++) {
        getVertexData(indexCoord[count++], points[1]);
        dir.x = points[1].x - points[0].x;
        dir.y = points[1].y - points[0].y;
        dir.z = points[1].z - points[0].z;
        if (intersectLineAndRay(pnts[0], pnts[1],
             points[0], dir, dist, null)
      && (dist[0] <= 1.0)) {
      return true;
        }
        points[0].set(points[1]);
    }
      }
      break;
  case 1: // point
      dir = new Vector3d();
      while (i < stripIndexCounts.length) {
    getVertexData(indexCoord[count++], points[0]);
    scount = stripIndexCounts[i++];
    for (j=1; j < scount; j++) {
        getVertexData(indexCoord[count++], points[1]);
View Full Code Here

  Point3d pnt0 = new Point3d();
  Point3d pnt1 = new Point3d();
  Point3d pnt2 = new Point3d();
  Point3d pnt3 = new Point3d();
  Vector3d vec = new Vector3d();
  Vector3d normal = new Vector3d();
  Vector3d tmpvec = new Vector3d();

  double area;
  double totalarea = 0;

  centroid.x = 0;
  centroid.y = 0;
  centroid.z = 0;

  while (i < validVertexCount) {
      getVertexData(i++, pnt0);
      getVertexData(i++, pnt1);
      getVertexData(i++, pnt2);
      getVertexData(i++, pnt3);

      // Determine the normal
      tmpvec.sub(pnt0, pnt1);
      vec.sub(pnt1, pnt2);

      // Do the cross product
      normal.cross(tmpvec, vec);
      normal.normalize();
      // If a degenerate triangle, don't include
      if (Double.isNaN(normal.x+normal.y+normal.z))
    continue;
      tmpvec.set(0,0,0);
      // compute the area of each triangle
      getCrossValue(pnt0, pnt1, tmpvec);
      getCrossValue(pnt1, pnt2, tmpvec);
      getCrossValue(pnt2, pnt0, tmpvec);
      area = normal.dot(tmpvec);
      totalarea += area;
      centroid.x += (pnt0.x+pnt1.x+pnt2.x) * area;
      centroid.y += (pnt0.y+pnt1.y+pnt2.y) * area;
      centroid.z += (pnt0.z+pnt1.z+pnt2.z) * area;

      // compute the area of each triangle
      tmpvec.set(0,0,0);
      getCrossValue(pnt0, pnt2, tmpvec);
      getCrossValue(pnt2, pnt3, tmpvec);
      getCrossValue(pnt3, pnt0, tmpvec);
      area = normal.dot(tmpvec);
      totalarea += area;
View Full Code Here

    // Initialize the head to head-tracker transform
    private void initHeadToHeadTracker() {
  // By default the center of the crystal eyes tracker is 20mm down
  // and 35 mm closer to the screen from the origin of head coordinates
  // (the center eye).
  Vector3d v = new Vector3d(0.0, 0.020, 0.035);
  headToHeadTracker.set(v);
    }
View Full Code Here

      position.w = 0.0;
      return true;
  }

  double l2oc,rad2,tca,t2hc,invMag,t;
  Vector3d dir = new Vector3d()// normalized direction of ray
  Point3d oc  = new Point3d()// vector from sphere center to ray origin
  Vector3d direction = new Vector3d();

  oc.x = center.x - start.x;
  oc.y = center.y - start.y;
  oc.z = center.z - start.z;
  direction.x = end.x - start.x;
View Full Code Here

TOP

Related Classes of javax.vecmath.Vector3d

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.