Package toxi.geom

Examples of toxi.geom.Vec3D


      float[] gVertices = new float[vertNum];
      for (int i = 0; i < triangulate.vertexs.size(); i++) {
        Delaunay.Vertex v = (Delaunay.Vertex) triangulate.vertexs
            .get(i);

        Vec3D pointOnePlane = new Vec3D(new Float(v.x), new Float(v.y),
            0);

        if (this.getPlane().normal.z == -1) {
          pointOnePlane.z = this.getPlane().z;
        } else {
          pointOnePlane = pointOnePlane.rotateY(PApplet.PI / 2);

          float planeAngle = functions.angleOf(new Vec2D(this
              .getPlane().normal.x, this.getPlane().normal.y));
          pointOnePlane = pointOnePlane.rotateZ(-planeAngle);
          pointOnePlane.x += this.getPlane().x;
          pointOnePlane.y += this.getPlane().y;
          pointOnePlane.z += this.getPlane().z;
        }
View Full Code Here


    for (int sh = 0; sh < ShetchShapesIntersect.size(); sh++) {
      SketchPath path = (SketchPath) ShetchShapesIntersect.get(sh);

      for (int i = 1; i <= path.size(); i++) {
        Vec3D p1 = null;
        Vec3D p2 = null;

        if (i != 0) {
          p1 = this.getWorldPos((Vec2D) path.get(i - 1));
        } else {
          p1 = this.getWorldPos((Vec2D) path.get(path.size() - 1));
        }

        if (i != path.size()) {
          p2 = this.getWorldPos((Vec2D) path.get(i));
        } else {
          p2 = this.getWorldPos((Vec2D) path.get(0));
        }
        //

        // if one point is on one side of the plane and the other point is
        // on the other side !

        if (slicePlane.getPlane().classifyPoint(p1) != slicePlane
            .getPlane().classifyPoint(p2)) {
          //we found a intersect
          SketchPoint vec2D1 = null;

          if (i != 0) {
            vec2D1 = (SketchPoint) path.get(i - 1);
          } else {
            vec2D1 = (SketchPoint) path.get(path.size() - 1);
          }

          SketchPoint vec2D2 = null;
          if (i < path.size()) {
            vec2D2 = (SketchPoint) path.get(i);
          } else {
            vec2D2 = (SketchPoint) path.get(0);
          }

          if (vec2D1 == null || vec2D2 == null)
            break;

          if (vec2D1.containsBezier() || vec2D2.containsBezier()) {
            for (float t = 0; t < 1 - GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS; t += GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS) {
              Vec2D bez1 = vec2D1;
              Vec2D bez2 = vec2D2;

              if (vec2D1.controlPoint2 != null) {
                bez1 = vec2D1.controlPoint2;

              }

              if (vec2D2.controlPoint1 != null) {
                bez2 = vec2D2.controlPoint1;

              }

              float x = GLOBAL.g.bezierPoint(vec2D1.x, bez1.x,
                  bez2.x, vec2D2.x, t);
              float y = GLOBAL.g.bezierPoint(vec2D1.y, bez1.y,
                  bez2.y, vec2D2.y, t);

              float x2 = GLOBAL.g
                  .bezierPoint(
                      vec2D1.x,
                      bez1.x,
                      bez2.x,
                      vec2D2.x,
                      t
                          + (GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS));
              float y2 = GLOBAL.g
                  .bezierPoint(
                      vec2D1.y,
                      bez1.y,
                      bez2.y,
                      vec2D2.y,
                      t
                          + (GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS));

              Vec2D curveP1 = new Vec2D(x, y);
              Vec2D curveP2 = new Vec2D(x2, y2);

              Vec3D p1b = this.getWorldPos(curveP1);
              Vec3D p2b = this.getWorldPos(curveP2);

              if (slicePlane.getPlane().classifyPoint(p1b) != slicePlane
                  .getPlane().classifyPoint(p2b)) {

                Vec3D intersect = null;
                intersect = (Vec3D) slicePlane.getPlane()
                    .getIntersectionWithRay(
                        new Ray3D(p2b, p1b.sub(p2b)));
                if (intersect == null)
                  intersect = (Vec3D) slicePlane
                      .getPlane()
                      .getIntersectionWithRay(
                          new Ray3D(p1b, p2b.sub(p1b)));

                Vec2D intexsecX = new Vec2D(intersect.x,
                    intersect.y);

                if (intersect != null) {

                  intersect.subSelf(slicePlane.getPlane());

                  intersect
                      .rotateY((float) (functions.angleOf(new Vec2D(
                          slicePlane.getPlane().normal.x,
                          slicePlane.getPlane().normal.z)) - (Math.PI / 2)));

                  float rotateAn = (functions
                      .angleOf(new Vec2D(
                          slicePlane.getPlane().normal.x,
                          slicePlane.getPlane().normal.y)));

                  if (rotateAn < Math.PI / 2
                      || rotateAn > (Math.PI / 2) * 3)
                    rotateAn = (float) ((Math.PI * 2) - Math
                        .abs(rotateAn));

                  intersect.rotateX(rotateAn);

                  List<Vec2D> listItem = new ArrayList<Vec2D>();
                  listItem.add(new Vec2D(intersect.x,
                      intersect.y));
                  listItem.add(intexsecX);
                  returnList.add(listItem);
                  //t = 2;
                }
              }

            }

          } else {

            Vec3D intersect = null;
            intersect = (Vec3D) slicePlane.getPlane()
                .getIntersectionWithRay(
                    new Ray3D(p2, p1.sub(p2)));
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p1, p2.sub(p1)));

            if (intersect != null) {
              Vec2D intexsecX = new Vec2D(intersect.x,
                  intersect.y);

              intersect.subSelf(slicePlane.getPlane());

              intersect
                  .rotateY((float) (functions.angleOf(new Vec2D(
                      slicePlane.getPlane().normal.x,
                      slicePlane.getPlane().normal.z)) - (Math.PI / 2)));

              float rotateAn = (functions.angleOf(new Vec2D(
                  slicePlane.getPlane().normal.x, slicePlane
                      .getPlane().normal.y)));

              if (rotateAn < Math.PI / 2
                  || rotateAn > (Math.PI / 2) * 3)
                rotateAn = (float) ((Math.PI * 2) - Math
                    .abs(rotateAn));

              intersect.rotateX(rotateAn);

              List<Vec2D> listItem = new ArrayList<Vec2D>();
              listItem.add(new Vec2D(intersect.x, intersect.y));
              listItem.add(intexsecX);

View Full Code Here

    //LOGGER.info("");
    //LOGGER.info("");

    float neartestDist = -1;
    Vec3D returnVec3D = null;
    int collisionsFound = 0;

    float lenToNext = 0;

    //return if spline is too short
    if (spline.getCentrePath().size() < 2)
      return;

    spline.getCentrePath().cacheLength(true);

    Vec3D p1 = null, p2 = null;
    Vec2D p12D = null, p22D = null;

    for (int i = 0; i < spline.getCentrePath().size() - 1; i++) {

      SketchPoint point1 = spline.getCentrePath().get(i);
      SketchPoint point2 = spline.getCentrePath().get(i + 1);

      float step = 1;

      if (point1.containsBezier() || point2.containsBezier())
        step = GLOBAL.SketchGlobals.BEZIER_DETAIL_CALCULATIONS;

      float offset = 0;

      if (step != 1)
        offset = step;

      p22D = (Vec2D) point1.copy();
      spline.getCentrePath().resetPosStep();

      for (float i2 = 0; i2 < 1; i2 += step) {

        //If we are on a curve step though the curve
        if (step == 1) {
          p12D = (Vec2D) spline.getCentrePath().get(i);
          p22D = (Vec2D) spline.getCentrePath().get(i + 1);
          p1 = this.getWorldPos(p12D);
          p2 = this.getWorldPos(p22D);

        } else {
          p12D = p22D.copy();//get the previous point// (Vec2D) spline.getCentrePath().getPosStep(step);
          Vec2D p22dTemp = (Vec2D) spline.getCentrePath().getPosStep(
              point1, point2, step);//step to the next point

          if (p22dTemp != null) {
            p22D = p22dTemp;
          }
          p1 = this.getWorldPos(p12D);
          p2 = this.getWorldPos(p22D);
          // LOGGER.info("p1" + p1.x + ":" + p1.y);
          // LOGGER.info("p2" + p2.x + ":" + p2.y);
        }

        if (p2 != null) {
          /*
                  if(p12D.distanceTo(p22D) > 100)
                    LOGGER.info("-------------------------------------------------------");
                 
                  LOGGER.info("p12D.distanceTo(p22D); " + p12D.distanceTo(p22D)  + " i2 " + i2);
                  LOGGER.info(" p1 " + p1  + " p2 " + p2);
                  LOGGER.info("");
                  */

          //if(p12D.distanceTo(p22D) < 100)
          // 

          lenToNext += p12D.distanceTo(p22D);

          // if one point is on one side of the plane and the other point is
          // on the other side !
          if ((slicePlane.getPlane().classifyPoint(p1) != slicePlane
              .getPlane().classifyPoint(p2))) {
            //LOGGER.info("i2 on p"+i2 );

            Vec3D intersect = null;

            //try intersecting  ray in one direction
            intersect = (Vec3D) slicePlane.getPlane()
                .getIntersectionWithRay(
                    new Ray3D(p1, p2.sub(p1)));

            //if we do not find a point try the other direction
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p2, p1.sub(p2)));

            //if we do not find a point try the other direction
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p2.sub(p1.sub(p2)), p1
                          .sub(p2)));

            //if we do not find a point try the other direction
            if (intersect == null)
              intersect = (Vec3D) slicePlane.getPlane()
                  .getIntersectionWithRay(
                      new Ray3D(p2.add(p1.sub(p2)), p1
                          .sub(p2)));

            collisionsFound++;
            //we found a intersection with the plane
            if (intersect != null) {

              float distToP1 = intersect.distanceTo(p1); //dist to intersection
              float distToP2 = intersect.distanceTo(p2); //dist to intersection
              float distBetweenP1P2 = p1.distanceTo(p2);
              float percentBetween = distToP1 / distBetweenP1P2; //distBetweenP1P2;

              float percent = 0;

              //special case for 2 point lines
              float splneLen = (spline.getCentrePath()
                  .getlength());
              percent = ((lenToNext - distToP2) / splneLen);

              // System.out.println(percentBetween + "in");

              // for (int k = 0; k < points.size(); k++) {
              // float percent = (Float) points.get(k);
              float deltaPercent = Math.abs(percent
                  - externalCurvePercent);
              /*
              LOGGER.info("distToP1 " + distToP1 +
                  " distToP2 "+distToP2 +
                  " lenToNext " + lenToNext +
                  " percentBetween " + percentBetween +
                  " percent" + percent +
                  " splneLen " + splneLen +
                  " i " + i + " i2 " + i2 +
                  " externalCurvePercent "+externalCurvePercent +
                  " deltaPercent "+ deltaPercent +
                  " neartestDist " + neartestDist);

              */
              if (deltaPercent < neartestDist
                  || neartestDist == -1) {
                //  if (  collisionsFound == 3){

                neartestDist = deltaPercent;

                percentReturn.x = (p12D.x * (1 - percentBetween))
                    + (p22D.x * (percentBetween));
                percentReturn.y = (p12D.y * (1 - percentBetween))
                    + (p22D.y * (percentBetween));
                returnVec3D = intersect.copy();

                //if(neartestDist > .2f)
                //  returnVec3D = null;
                // System.out.println(percent +" P");
                //LOGGER.info("percent "+percentBetween);
View Full Code Here

  Vec3D getWorldPos(Vec2D vec) {

    if (vec == null)
      return null;

    Vec3D returnVec = new Vec3D(vec.x, vec.y, 0);

    // returnVec.rotateX(this.plane.x);
    // returnVec.rotateY(this.plane.y);
    // returnVec.rotateZ(this.plane.z);

    returnVec.addSelf(this.getPlane());
    return returnVec;

  }
View Full Code Here

        || coverPathOther.size() < 2) {
      //System.out.println("cover wrong");
      return null;
    }

    Vec3D prevHere = null;
    Vec3D prevThere = null;

    int vertNum = ((int) (1 / stepRes) * 3 * 2);
    int indNum = (int) (1 / stepRes) * 6;

    float[] gVertices = new float[vertNum];
    int[] gIndices = new int[indNum];

    int SideLen = (int) (1 / stepRes) - 1;
    int trigCount = 0;
    int step = 0;
    for (float i = 0; i <= 1 - stepRes; i += stepRes) {

      Vec2D pHere2D = coverPath.getPos(i);

      Vec3D pHere = new Vec3D(pHere2D.x, pHere2D.y, this.getPlane().z);

      Vec2D pThere2D = coverPathOther.getPos(i);
      Vec3D pThere = new Vec3D(pHere2D.x, pHere2D.y,
          planeOther.getPlane().z);

      if (pHere != null && pThere != null) {
        gVertices[((3 * step) + 0)] = GLOBAL.jBullet.scaleVal(pHere.x)
            - offset.x;
View Full Code Here

      GLOBAL.sketchChairs.hybernate();
      UITools.load(this.linkedChair);

      if (GLOBAL.sketchChairs.getCurChair() != null) {
        GLOBAL.sketchChairs.getCurChair().drag(
            new Vec3D(posDelta.x, posDelta.y, 0));
        //float height = (this.maxY - minY)*this.scale;
        //GLOBAL.sketchChairs.curChair.setHeight(height);
      }
      this.destroy();
    }
View Full Code Here

    LOGGER.setLevel(Level.FINEST);
  }
 
  //TODO @Before
  public Gml createGml() {
    gml = new Gml(new Vec3D(480, 240, 60));
   
    GmlStroke stroke = new GmlStroke();
    stroke.addPoint(new GmlPoint(new Vec3D(0.1f, 0.35f, 0.25f), 0.01f, 1, new Vec3D(), new Vec3D()));
    stroke.addPoint(new GmlPoint(new Vec3D(0.85f, 0.35f, 0.25f), 0.02f, 1, new Vec3D(), new Vec3D()));
    stroke.addPoint(new GmlPoint(new Vec3D(0.85f, 0.95f, 0.70f), 0.03f, 1, new Vec3D(), new Vec3D()));
    stroke.addPoint(new GmlPoint(new Vec3D(0.10f, 0.95f, 0.70f), 0.04f, 1, new Vec3D(), new Vec3D()));
    stroke.setLayer(0);
    gml.addStroke(stroke);
    return gml;
  }
View Full Code Here

 
  // Rotation from up 1,0,0 to up 0,-1,0
  @Test
  public void testReorientPlusX2MinusY() {
    gml = createGml();
    gml.environment.up = new Vec3D(1, 0, 0);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.35f, 0.15f, 0.25F), new Vec3D(0.95f, 0.9f, 0.7f));
   
    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testPlusX2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());
   
    // Check min-max bounding box
    assertTrue("x=1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here

  // Rotation from up -1,0,0 to up 0,-1,0
  @Test
  public void testReorientMinusX2MinusY() {
    Gml gml = createGml();
    gml.environment.up = new Vec3D(-1, 0, 0);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.05f, 0.1f, 0.25f), new Vec3D(0.65f, 0.85f, 0.7f));

    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testMinusX2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());

    // Check min-max bounding box
    assertTrue("x=-1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here

  // Rotation from up 0,1,0 to up 0,-1,0
  @Test
  public void testReorientPlusY2MinusY() {
    Gml gml = createGml();
    gml.environment.up = new Vec3D(0, 1, 0);

    AABB aabb = AABB.fromMinMax(new Vec3D(0.15f, 0.05f, 0.7f), new Vec3D(0.9f, 0.65f, 0.25f));
   
    GmlUtils.reorient(gml, true);
    LOGGER.log(Level.FINEST, "testPlusY2MinusY "+gml.getBoundingBox().getMin()+ " / " +gml.getBoundingBox().getMax());
    LOGGER.log(Level.FINEST, "Expected :"+aabb.getMin()+ " / "+ aabb.getMax());
   
    // Check min-max bounding box
    assertTrue("y=1 to y=-1", aabb.equalsWithTolerance(gml.getBoundingBox(), 0.0000001f));
    assertTrue("up vector", gml.environment.up.equals(new Vec3D(0, -1, 0)));
  }
View Full Code Here

TOP

Related Classes of toxi.geom.Vec3D

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.