Package javax.vecmath

Examples of javax.vecmath.Vector3f


    float maxY = -1;

    for (int i = 0; i < this.getPath().size(); i++) {
      SketchPoint v = (SketchPoint) this.getPath().get(i);

      Vector3f vecWorld = new Vector3f(
          v.x
              / getParentSketch().getSketchGlobals().physicsEngineScale,
          v.y
              / getParentSketch().getSketchGlobals().physicsEngineScale,
          0);
      //Vector3f vecWorld = new Vector3f(1,1,1);
      //System.out.print(currentWorldTransform.origin);
      //System.out.print("before Y:"+vecWorld);
      currentWorldTransform.transform(vecWorld);
      //System.out.print(" after1  Y:"+vecWorld);

      vecWorld.y -= currentWorldTransform.origin.y;
      //System.out.print(" after2  Y:"+vecWorld);
      vecWorld.scale(getParentSketch().getSketchGlobals().physicsEngineScale);
      //System.out.println(" after3  Y:"+vecWorld);

      if (i == 0 || -vecWorld.y > maxY)
        maxY = -vecWorld.y;
    }
View Full Code Here


    float MinX = -1;

    for (int i = 0; i < this.getPath().size(); i++) {
      SketchPoint v = (SketchPoint) this.getPath().get(i);

      Vector3f vecWorld = new Vector3f(
          v.x
              / getParentSketch().getSketchGlobals().physicsEngineScale,
          v.y
              / getParentSketch().getSketchGlobals().physicsEngineScale,
          0);

      currentWorldTransform.transform(vecWorld);
      vecWorld.x -= currentWorldTransform.origin.x;
      vecWorld.scale(getParentSketch().getSketchGlobals().physicsEngineScale);

      if (i == 0 || vecWorld.x < MinX)
        MinX = vecWorld.x;
    }
View Full Code Here

    float MinY = -1;

    for (int i = 0; i < this.getPath().size(); i++) {
      SketchPoint v = (SketchPoint) this.getPath().get(i);

      Vector3f vecWorld = new Vector3f(
          v.x
              / getParentSketch().getSketchGlobals().physicsEngineScale,
          v.y
              / getParentSketch().getSketchGlobals().physicsEngineScale,
          0);
      currentWorldTransform.transform(vecWorld);
      vecWorld.y -= currentWorldTransform.origin.y;
      vecWorld.scale(getParentSketch().getSketchGlobals().physicsEngineScale);

      if (i == 0 || -vecWorld.y < MinY)
        MinY = -vecWorld.y;
    }
View Full Code Here

      int[] contourCounts = new int[1];
      int currCoordIndex = 0, vertOffset = 0;
    ArrayList<GeometryArray> triangData = new ArrayList<GeometryArray>();

      Point3f q1 = new Point3f(), q2 = new Point3f(), q3 = new Point3f();
      Vector3f n1 = new Vector3f(), n2 = new Vector3f();
      numPoints = 0;
      //Now loop thru each island, calling triangulator once per island.
      //Combine triangle data for all islands together in one object.
    NormalGenerator ng = new NormalGenerator();
    for (i = 0; i < islandCounts.length; i++) {
      contourCounts[0] = islandCounts[i].length;
      numPoints += outVerts[i].length;
      GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
      gi.setCoordinates(outVerts[i]);
      gi.setStripCounts(islandCounts[i]);
      gi.setContourCounts(contourCounts);
      ng.generateNormals(gi);

      GeometryArray ga = gi.getGeometryArray(false, false, false);
      vertOffset += ga.getVertexCount();

      triangData.add(ga);
    }
      // Multiply by 2 since we create 2 faces of the font
      // Second term is for side-faces along depth of the font
      if (fontExtrusion == null)
        vertCnt = vertOffset;
      else{
        if (fontExtrusion.shape == null)
    vertCnt = vertOffset * 2 + numPoints *6;
        else{
    vertCnt = vertOffset * 2 + numPoints * 6 *
      (fontExtrusion.pnts.length -1);
        }
      }

      // XXXX: Should use IndexedTriangleArray to avoid
      // duplication of vertices. To create triangles for
      // side faces, every vertex is duplicated currently.
      TriangleArray triAry = new TriangleArray(vertCnt,
                 GeometryArray.COORDINATES |
                 GeometryArray.NORMALS);

      boolean flip_orient[] = new boolean[islandCounts.length];
      boolean findOrient;
      // last known non-degenerate normal
      Vector3f goodNormal = new Vector3f();


      for (j=0;j < islandCounts.length;j++) {
      GeometryArray ga = triangData.get(j);
    vertOffset = ga.getVertexCount();

    findOrient = false;

    //Create the triangle array
    for (i= 0; i < vertOffset; i+= 3, currCoordIndex += 3){
        //Get 3 points. Since triangle is known to be flat, normal
        // must be same for all 3 points.
        ga.getCoordinate(i, p1);
        ga.getNormal(i, n1);
        ga.getCoordinate(i+1, p2);
        ga.getCoordinate(i+2, p3);

        if (!findOrient) {
      //Check here if triangles are wound incorrectly and need
      //to be flipped.
      if (!getNormal(p1,p2, p3, n2)) {
          continue;
      }

      if (n2.z >= EPS) {
          flip_orient[j] = false;
      } else if (n2.z <= -EPS) {
          flip_orient[j] = true;
      } else {
          continue;
      }
      findOrient = true;
        }
        if (flip_orient[j]){
      //New Triangulator preserves contour orientation. If contour
      //input is wound incorrectly, swap 2nd and 3rd points to
      //sure all triangles are wound correctly for j3d.
      q1.x = p2.x; q1.y = p2.y; q1.z = p2.z;
      p2.x = p3.x; p2.y = p3.y; p2.z = p3.z;
      p3.x = q1.x; p3.y = q1.y; p3.z = q1.z;
      n1.x = -n1.x; n1.y = -n1.y; n1.z = -n1.z;
        }


        if (fontExtrusion != null) {
      n2.x = -n1.x;n2.y = -n1.y;n2.z = -n1.z;

      triAry.setCoordinate(currCoordIndex, p1);
      triAry.setNormal(currCoordIndex, n2);
      triAry.setCoordinate(currCoordIndex+1, p3);
      triAry.setNormal(currCoordIndex+1, n2);
      triAry.setCoordinate(currCoordIndex+2, p2);
      triAry.setNormal(currCoordIndex+2, n2);

      q1.x = p1.x; q1.y = p1.y; q1.z = p1.z + fontExtrusion.length;
      q2.x = p2.x; q2.y = p2.y; q2.z = p2.z + fontExtrusion.length;
      q3.x = p3.x; q3.y = p3.y; q3.z = p3.z + fontExtrusion.length;

      triAry.setCoordinate(currCoordIndex+vertOffset, q1);
      triAry.setNormal(currCoordIndex+vertOffset, n1);
      triAry.setCoordinate(currCoordIndex+1+vertOffset, q2);
      triAry.setNormal(currCoordIndex+1+vertOffset, n1);
      triAry.setCoordinate(currCoordIndex+2+vertOffset, q3);
      triAry.setNormal(currCoordIndex+2+vertOffset, n1);
        } else {
      triAry.setCoordinate(currCoordIndex, p1);
      triAry.setNormal(currCoordIndex, n1);
      triAry.setCoordinate(currCoordIndex+1, p2);
      triAry.setNormal(currCoordIndex+1, n1);
      triAry.setCoordinate(currCoordIndex+2, p3);
      triAry.setNormal(currCoordIndex+2, n1);
        }

    }
    if (fontExtrusion != null) {
        currCoordIndex += vertOffset;
    }
      }

      //Now add side triangles in both cases.

      // Since we duplicated triangles with different Z, make sure
      // currCoordIndex points to correct location.
      if (fontExtrusion != null){
    if (fontExtrusion.shape == null){
        boolean smooth;
        // we'll put a crease if the angle between the normals is
        // greater than 44 degrees
        float threshold = (float) Math.cos(44.0*Math.PI/180.0);
        float cosine;
        // need the previous normals to check for smoothing
        Vector3f pn1 = null, pn2 = null;
        // need the next normals to check for smoothing
        Vector3f n3 = new Vector3f(), n4 = new Vector3f();
        //  store the normals for each point because they are
        // the same for both triangles
        Vector3f p1Normal = new Vector3f();
        Vector3f p2Normal = new Vector3f();
        Vector3f p3Normal = new Vector3f();
        Vector3f q1Normal = new Vector3f();
        Vector3f q2Normal = new Vector3f();
        Vector3f q3Normal = new Vector3f();

        for (i=0;i < islandCounts.length;i++){
      for (j=0, k=0, num =0;j < islandCounts[i].length;j++){
          num += islandCounts[i][j];
          p1.x = outVerts[i][num - 1].x;
          p1.y = outVerts[i][num - 1].y;
          p1.z = 0.0f;
          q1.x = p1.x; q1.y = p1.y; q1.z = p1.z+fontExtrusion.length;
          p2.z = 0.0f;
          q2.z = p2.z+fontExtrusion.length;
          for (int m=0; m < num;m++) {
        p2.x = outVerts[i][m].x;
        p2.y = outVerts[i][m].y;
        q2.x = p2.x;
        q2.y = p2.y;
        if (getNormal(p1, q1, p2, n1)) {

            if (!flip_side_orient) {
          n1.negate();
            }
            goodNormal.set(n1);
            break;
        }
          }

          for (;k < num;k++){
        p2.x = outVerts[i][k].x;p2.y = outVerts[i][k].y;p2.z = 0.0f;
        q2.x = p2.x; q2.y = p2.y; q2.z = p2.z+fontExtrusion.length;

        if (!getNormal(p1, q1, p2, n1)) {
            n1.set(goodNormal);
        } else {
            if (!flip_side_orient) {
          n1.negate();
            }
            goodNormal.set(n1);
        }

        if (!getNormal(p2, q1, q2, n2)) {
            n2.set(goodNormal);
        } else {
            if (!flip_side_orient) {
          n2.negate();
            }
            goodNormal.set(n2);
        }
        // if there is a previous normal, see if we need to smooth
        // this normal or make a crease

        if (pn1 != null) {
            cosine = n1.dot(pn2);
            smooth = cosine > threshold;
            if (smooth) {
          p1Normal.x = (pn1.x + pn2.x + n1.x);
          p1Normal.y = (pn1.y + pn2.y + n1.y);
          p1Normal.z = (pn1.z + pn2.z + n1.z);
          normalize(p1Normal);

          q1Normal.x = (pn2.x + n1.x + n2.x);
          q1Normal.y = (pn2.y + n1.y + n2.y);
          q1Normal.z = (pn2.z + n1.z + n2.z);
          normalize(q1Normal);
            } // if smooth
            else {
          p1Normal.x = n1.x; p1Normal.y = n1.y; p1Normal.z = n1.z;
          q1Normal.x = n1.x+n2.x;
          q1Normal.y = n1.y+n2.y;
          q1Normal.z = n1.z+ n2.z;
          normalize(q1Normal);
            } // else
        } // if pn1 != null
        else {
            pn1 = new Vector3f();
            pn2 = new Vector3f();
            p1Normal.x = n1.x;
            p1Normal.y = n1.y;
            p1Normal.z = n1.z;

            q1Normal.x = (n1.x + n2.x);
            q1Normal.y = (n1.y + n2.y);
            q1Normal.z = (n1.z + n2.z);
            normalize(q1Normal);
        } // else

        // if there is a next, check if we should smooth normal

        if (k+1 < num) {
            p3.x = outVerts[i][k+1].x; p3.y = outVerts[i][k+1].y;
            p3.z = 0.0f;
            q3.x = p3.x; q3.y = p3.y; q3.z = p3.z + fontExtrusion.length;

            if (!getNormal(p2, q2, p3, n3)) {
          n3.set(goodNormal);
            } else {
          if (!flip_side_orient) {
              n3.negate();
          }
          goodNormal.set(n3);
            }

            if (!getNormal(p3, q2, q3, n4)) {
          n4.set(goodNormal);
            } else {
          if (!flip_side_orient) {
              n4.negate();
          }
          goodNormal.set(n4);
            }

            cosine = n2.dot(n3);
            smooth = cosine > threshold;

            if (smooth) {
          p2Normal.x = (n1.x + n2.x + n3.x);
          p2Normal.y = (n1.y + n2.y + n3.y);
          p2Normal.z = (n1.z + n2.z + n3.z);
          normalize(p2Normal);

          q2Normal.x = (n2.x + n3.x + n4.x);
          q2Normal.y = (n2.y + n3.y + n4.y);
          q2Normal.z = (n2.z + n3.z + n4.z);
          normalize(q2Normal);
            } else { // if smooth
          p2Normal.x = n1.x + n2.x;
          p2Normal.y = n1.y + n2.y;
          p2Normal.z = n1.z + n2.z;
          normalize(p2Normal);
          q2Normal.x = n2.x; q2Normal.y = n2.y; q2Normal.z = n2.z;
            } // else
        } else { // if k+1 < num
            p2Normal.x = (n1.x + n2.x);
            p2Normal.y = (n1.y + n2.y);
            p2Normal.z = (n1.z + n2.z);
            normalize(p2Normal);

            q2Normal.x = n2.x;
            q2Normal.y = n2.y;
            q2Normal.z = n2.z;
        } // else

        // add pts for the 2 tris
        // p1, q1, p2 and p2, q1, q2

        if (flip_side_orient) {
            triAry.setCoordinate(currCoordIndex, p1);
            triAry.setNormal(currCoordIndex, p1Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, q1);
            triAry.setNormal(currCoordIndex, q1Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, p2);
            triAry.setNormal(currCoordIndex, p2Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, p2);
            triAry.setNormal(currCoordIndex, p2Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, q1);
            triAry.setNormal(currCoordIndex, q1Normal);
            currCoordIndex++;
        } else {
            triAry.setCoordinate(currCoordIndex, q1);
            triAry.setNormal(currCoordIndex, q1Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, p1);
            triAry.setNormal(currCoordIndex, p1Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, p2);
            triAry.setNormal(currCoordIndex, p2Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, q1);
            triAry.setNormal(currCoordIndex, q1Normal);
            currCoordIndex++;

            triAry.setCoordinate(currCoordIndex, p2);
            triAry.setNormal(currCoordIndex, p2Normal);
            currCoordIndex++;
        }
        triAry.setCoordinate(currCoordIndex, q2);
        triAry.setNormal(currCoordIndex, q2Normal);
        currCoordIndex++;
        pn1.x = n1.x; pn1.y = n1.y; pn1.z = n1.z;
        pn2.x = n2.x; pn2.y = n2.y; pn2.z = n2.z;
        p1.x = p2.x; p1.y = p2.y; p1.z = p2.z;
        q1.x = q2.x; q1.y = q2.y; q1.z = q2.z;

          }// for k

          // set the previous normals to null when we are done
          pn1 = null;
          pn2 = null;
      }// for j
        }//for i
    } else { // if shape
        int m, offset=0;
        Point3f P2 = new Point3f(), Q2 = new Point3f(), P1=new Point3f();
        Vector3f nn = new Vector3f(), nn1= new Vector3f(),
      nn2= new Vector3f(), nn3= new Vector3f();
        Vector3f nna = new Vector3f(), nnb=new Vector3f();
        float length;
        boolean validNormal = false;

        // fontExtrusion.shape is specified, and is NOT straight line
        for (i=0;i < islandCounts.length;i++){
View Full Code Here

  return geo;
    }


    static boolean getNormal(Point3f p1, Point3f p2, Point3f p3, Vector3f normal) {
  Vector3f v1 = new Vector3f();
  Vector3f v2 = new Vector3f();

  // Must compute normal
  v1.sub(p2, p1);
  v2.sub(p2, p3);
  normal.cross(v1, v2);
  normal.negate();

  float length = normal.length();
View Full Code Here

        (J3dI18N.getString("GeometryDecompressorRetained3")) ;

      vlist.setVertexFormat(vlist.vertexFormat | GeometryArray.NORMALS) ;
  }

  if (curNormal == null) curNormal = new Vector3f() ;
  curNormal.set(normal) ;
    }
View Full Code Here

      float xTransStart = navigationOffset.x;
      float xTransDelta = xTrans - xTransStart;
      float yTransStart = navigationOffset.y;
      float yTransDelta = yTrans - yTransStart;
      float degreeStep = degrees / totalSteps;
      Vector3f aaStepCenter = new Vector3f();
      aaStepCenter.set(ptMoveToCenter);
      aaStepCenter.sub(navigationCenter);
      aaStepCenter.scale(1f / totalSteps);
      Point3f centerStart = new Point3f(navigationCenter);
      for (int iStep = 1; iStep < totalSteps; ++iStep) {

        navigating = true;
        float fStep = iStep / (totalSteps - 1f);
View Full Code Here

  void alignZX(Point3f pt0, Point3f pt1, Point3f ptVectorWing) {
    Point3f pt0s = new Point3f();
    Point3f pt1s = new Point3f();
    matrixRotate.transform(pt0, pt0s);
    matrixRotate.transform(pt1, pt1s);
    Vector3f vPath = new Vector3f(pt0s);
    vPath.sub(pt1s);
    Vector3f v = new Vector3f(0, 0, 1);
    float angle = vPath.angle(v);
    v.cross(vPath, v);
    if (angle != 0)
      navigate(0, v, (float) (angle * degreesPerRadian));
    matrixRotate.transform(pt0, pt0s);
    Point3f pt2 = new Point3f(ptVectorWing);
    pt2.add(pt0);
    Point3f pt2s = new Point3f();
    matrixRotate.transform(pt2, pt2s);
    vPath.set(pt2s);
    vPath.sub(pt0s);
    vPath.z = 0; // just use projection
    v.set(-1, 0, 0); // puts alpha helix sidechain above
    angle = vPath.angle(v);
    if (vPath.y < 0)
      angle = -angle;
    v.set(0, 0, 1);
    if (angle != 0)
      navigate(0, v, (float) (angle * degreesPerRadian));
    if (viewer.getNavigateSurface()) {
      // set downward viewpoint 20 degrees to horizon
      v.set(1, 0, 0);
      navigate(0, v, 20);
    }
    matrixRotate.transform(pt0, pt0s);
    matrixRotate.transform(pt1, pt1s);
    matrixRotate.transform(ptVectorWing, pt2s);
View Full Code Here

    if ((translation == null || translation.length() < 0.001)
        && (!isSpin || endDegrees == 0 || Float.isNaN(degreesPerSecond) || degreesPerSecond == 0)
        && (isSpin || endDegrees == 0))
      return;

    Vector3f axis = new Vector3f(point2);
    axis.sub(point1);
    if (isClockwise)
      axis.scale(-1f);
    internalRotationCenter.set(point1);
    rotationAxis.set(axis);
    rotationRate = degreesPerSecond;
    if (translation == null) {
      internalTranslation = null;
    } else {
      internalTranslation = new Vector3f(translation);
      //System.out.println("TM TRANSLATE " + internalTranslation);
    }
    boolean isSelected = (bsAtoms != null);
    if (isSpin) {
      // we need to adjust the degreesPerSecond to match a multiple of the frame rate
View Full Code Here

              float degrees, Matrix3f matrixEnd, float zoom, float xTrans,
              float yTrans, float newRotationRadius, Point3f navCenter,
              float xNav, float yNav, float navDepth) {
    if (matrixEnd == null) {
      matrixEnd = new Matrix3f();
      Vector3f axis = new Vector3f(rotAxis);
      if (Float.isNaN(degrees)) {
        matrixEnd.m00 = Float.NaN;
      } else if (degrees < 0.01f && degrees > -0.01f) {
        // getRotation(matrixEnd);
        matrixEnd.setIdentity();
View Full Code Here

TOP

Related Classes of javax.vecmath.Vector3f

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.