Package toxi.geom

Examples of toxi.geom.Vec3D


  public Vec2D getPointOnPlane(Vec2D mousePoint, Plane planeIn) {

    Plane plane = new Plane(planeIn.copy(), planeIn.normal.copy());

    Vec3D mouseRayPos = new Vec3D(mousePoint.x, mousePoint.y, planeIn.z); // this only works for planes perpendicular to the screen
    Vec3D mouseRayDir = new Vec3D(0, 0, -1);

    Vec3D focusCentre = new Vec3D(
        ((GLOBAL.windowWidth / 2) - (float)GLOBAL.CAM_OFFSET_X),
        ((GLOBAL.windowHeight / 2) - (float)GLOBAL.CAM_OFFSET_Y), 0);

    //now mouse pos is refereced from the centre of the screen
    mouseRayPos.x -= (GLOBAL.windowWidth / 2);
    mouseRayPos.y -= (GLOBAL.windowHeight / 2);
    mouseRayPos.scaleSelf((float) (1 / GLOBAL.getZOOM()));

    mouseRayPos.addSelf(focusCentre);

    Ray3D ray;

    Vec3D mousePos = null;
    Vec3D intersect;
    mouseRayDir = new Vec3D(0, 0, -1);

    plane.z = 0;
    //we need to rotate the plane so that it matches the one on the draw view
    plane.normal.rotateY(GLOBAL.rotateModelsY);
    plane.normal.rotateX(GLOBAL.rotateModelsX);

    plane.addSelf(plane.normal.scale(planeIn.z));
    //mouseRayDir.rotateY(GLOBAL.rotateModelsY);
    //mouseRayDir.rotateX(GLOBAL.rotateModelsX);

    mouseRayPos.subSelf(focusCentre);
    ray = new Ray3D(mouseRayPos, mouseRayDir); // this should be the world position of the mouse poiner on the 0,0,-1 plane

    intersect = plane.getIntersectionWithRay(ray);

    if (intersect == null) {
      ray = new Ray3D(mouseRayPos, mouseRayDir.invert());
      intersect = plane.getIntersectionWithRay(ray);
    }

    ray = new Ray3D(mouseRayPos, mouseRayDir);
    ray.addSelf(focusCentre);

    //if(this.mouseDown)
    //  GLOBAL.debugRay = ray;

    if (intersect != null) {

      //  System.out.println(plane.getProjectedPoint(intersect));
      //  intersect.z -= plane.z*2;
      //intersect.x += 70; 
      //  System.out.println("before rotate " +intersect);
      //  intersect.subSelf(focusCentre.scale(GLOBAL.getZOOM()));

      //   intersect.
      intersect.rotateX(-GLOBAL.rotateModelsX);
      intersect.rotateY(-GLOBAL.rotateModelsY);

      intersect.addSelf(focusCentre);

      //intersect.x += (GLOBAL.CAM_OFFSET_X*GLOBAL.getZOOM());
      //intersect.y += GLOBAL.CAM_OFFSET_Y;

      //intersect.rotateAroundAxis(axis, theta)
      mousePos = intersect;
      //mousePos.x += intersect.z;
      //System.out.println("after rotate " +intersect);
    }

    //get the chair matrix
    Matrix4f chairMatrix = new Matrix4f();
    Vec3D chairCentreOfMass = new Vec3D();
    if (GLOBAL.sketchChairs.getCurChair() != null
        && GLOBAL.sketchChairs.getCurChair().rigidBody != null) {
      Transform transform = new Transform();
      GLOBAL.sketchChairs.getCurChair().rigidBody
          .getWorldTransform(transform);
View Full Code Here


  }

  public Vec2D getPointOnPlaneOld(Vec2D mousePoint, Plane planeIn) {
    //get the chair matrix
    Matrix4f chairMatrix = new Matrix4f();
    Vec3D chairCentreOfMass = new Vec3D();
    if (GLOBAL.sketchChairs.getCurChair() != null
        && GLOBAL.sketchChairs.getCurChair().rigidBody != null) {
      Transform transform = new Transform();
      GLOBAL.sketchChairs.getCurChair().rigidBody
          .getWorldTransform(transform);
      transform.getMatrix(chairMatrix);
      chairCentreOfMass = GLOBAL.sketchChairs.getCurChair().centreOfMass;
    }

    Plane plane = new Plane(planeIn.copy(), planeIn.normal.copy());

    Vec3D mouseRayPos = new Vec3D(mousePoint.x, mousePoint.y, plane.z); // this only works for planes perpendicular to the screen
    Vec3D mouseRayDir = new Vec3D(0, 0, -1);

    Vec3D focusCentre = new Vec3D(
        ((GLOBAL.windowWidth / 2) - (float)GLOBAL.CAM_OFFSET_X),
        ((GLOBAL.windowHeight / 2) - (float)GLOBAL.CAM_OFFSET_Y), 0);

    //now mouse pos is refereced from the centre of the screen
    mouseRayPos.x -= (GLOBAL.windowWidth / 2);
    mouseRayPos.y -= (GLOBAL.windowHeight / 2);
    mouseRayPos.scaleSelf((float) (1 / GLOBAL.getZOOM()));

    //mouseRayPos.addSelf(-screenCentre.x,-screenCentre.y, 0);
    mouseRayPos.rotateX((GLOBAL.rotateModelsX));
    mouseRayPos.rotateY((GLOBAL.rotateModelsY));

    mouseRayPos.addSelf(focusCentre);

    mouseRayDir.x = mouseRayDir.x - mouseRayPos.x;
    mouseRayDir.y = mouseRayDir.y - mouseRayPos.y;
    mouseRayDir.z = mouseRayDir.z - mouseRayPos.z;

    mouseRayDir.rotateX((GLOBAL.rotateModelsX));
    mouseRayDir.rotateY((GLOBAL.rotateModelsY));

    Ray3D ray = new Ray3D(mouseRayPos, mouseRayDir);

    Vec3D mousePos = null;

    if (GLOBAL.rotateModelsX == 0 && GLOBAL.rotateModelsY == 0
        && plane.normal.x == 0 && plane.normal.y == 0)
      mousePos = new Vec3D(ray.x, ray.y, ray.z);

    //put these back in for 3d
    //  if(mousePos == null) 
    //    mousePos = plane.getIntersectionWithRay(ray);

    if (mousePos == null) {

      mouseRayDir = new Vec3D(0, 0, 1);
      mouseRayDir.x = mouseRayDir.x - mouseRayPos.x;
      mouseRayDir.y = mouseRayDir.y - mouseRayPos.y;
      mouseRayDir.z = mouseRayDir.z - mouseRayPos.z;

      mouseRayDir.rotateX((GLOBAL.rotateModelsX));
View Full Code Here

    }
    return area;
  }

  public Vec3D getCentre() {
    Vec3D centre = new Vec3D();

    for (SlicePlane plane : this.getList()) {
      centre.addSelf(plane.getPlane());
    }
    centre.scaleSelf(1 / this.getList().size());

    return centre;
  }
View Full Code Here

   * Build design from SketchShape element
   * @param shape
   */
  public SketchChair(SketchShape shape) {

    SlicePlane plane = new SlicePlane(new Plane(new Vec3D(0, 0, 0),
        new Vec3D(0, 0, -1)));
    plane.setSelected(true);
    plane.getSketch().getSketchShapes().add(shape);
    this.selectedPlanes.add(plane);
    this.mouseReleased(0, 0);
   
View Full Code Here

   * @return
   */
  public Vec3D getPhysicsOrigin() {

    if (currentWorldTransform == null || rigidBody == null)
      return new Vec3D(0, 0, 0);

    float scaleBy = 1f / GLOBAL.jBullet.getScale();
    Transform myTransform = new Transform();
    myTransform = rigidBody.getMotionState().getWorldTransform(myTransform);

    Vector3f center = new Vector3f();
    rigidBody.getCenterOfMassPosition(center);

    return new Vec3D(center.x, center.y, center.z);
  }
View Full Code Here

      GLOBAL.jBullet.myWorld.removeRigidBody(this.rigidBody);
      GLOBAL.jBullet.rigidBodies.remove(this.rigidBody);
      GLOBAL.jBullet.myWorld.stepSimulation(1);
    }

    Vec3D centreOfMass = this.getCentreOfMass();
    this.centreOfMass = centreOfMass;
    indexVertexArrays = this.getVertexArray(centreOfMass.x, centreOfMass.y,
        centreOfMass.z);
    //this.buildCoverMesh(indexVertexArrays, centreOfMass);
View Full Code Here

   
   

    for (float i = (-this.getWidth() / 2); i < (this.getWidth() / 2); i += spacing) {
      SlicePlane slicePlane = new SlicePlane(new Plane(
          new Vec3D(0, 0, i), new Vec3D(0, 0, -1)));
      this.getSlicePlanesY().add(slicePlane);
    }

    //this.updateCollisionShape();
    this.selectedPlanes.empty();
View Full Code Here

  /**
   * Flip the design around the Z Axis.
   */
  public void flipDesign() {
    Vec3D centre = this.getCentreOfMass();
    this.getSlicePlanesY().flipHorizontal(centre);
    this.buildLen();
  }
View Full Code Here

  /**
   * Return the center of mass for the current design.
   * @return
   */
  private Vec3D getCentreOfMass() {
    Vec3D centre = new Vec3D();
    int planeCount = 0;
    for (int i = 0; i < this.getSlicePlanesY().size(); i++) {
      SlicePlane slicePlane = this.getSlicePlanesY().get(i);
      if (slicePlane.getCentreOfMass() != null) {
        centre.addSelf(slicePlane.getCentreOfMass());
        planeCount++;
      }
    }

    centre.x /= planeCount;
View Full Code Here

    return slicePlanesY;
  }

  //translates into model space
  public Vec3D getTranslated(Vec3D pIn) {
    Vec3D p = pIn.copy();
    if (this.built == true) {

      if (rigidBody == null) {
        LOGGER.debug("no rigid body in get Translated");
        return p;
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.