示例#1
0
  public static float noise(Tuple3f p) {
    Point3i pFloor = new Point3i();
    pFloor.x = ((int) Math.floor(p.x)) % 256;
    pFloor.y = ((int) Math.floor(p.y)) % 256;
    pFloor.z = ((int) Math.floor(p.z)) % 256;
    Point3f pFract = new Point3f(p);
    pFract.x = pFract.x % 1;
    pFract.y = pFract.y % 1;
    pFract.z = pFract.z % 1;
    if (pFract.x < 0) {
      pFract.x++;
    }
    if (pFract.y < 0) {
      pFract.y++;
    }
    if (pFract.z < 0) {
      pFract.z++;
    }
    Point3f faded = fade(pFract);
    int A = perm(pFloor.x) + pFloor.y;
    int AA = perm(A) + pFloor.z;
    int AB = perm(A + 1) + pFloor.z;
    int B = perm(pFloor.x + 1) + pFloor.y;
    int BA = perm(B) + pFloor.z;
    int BB = perm(B + 1) + pFloor.z;

    Point3f corner1 = new Point3f(pFract);
    Point3f corner2 = new Point3f(pFract);
    corner2.add(new Vector3f(-1, 0, 0));
    Point3f corner3 = new Point3f(pFract);
    corner3.add(new Vector3f(0, -1, 0));
    Point3f corner4 = new Point3f(pFract);
    corner4.add(new Vector3f(-1, -1, 0));
    Point3f corner5 = new Point3f(pFract);
    corner5.add(new Vector3f(0, 0, -1));
    Point3f corner6 = new Point3f(pFract);
    corner6.add(new Vector3f(-1, 0, -1));
    Point3f corner7 = new Point3f(pFract);
    corner7.add(new Vector3f(0, -1, -1));
    Point3f corner8 = new Point3f(pFract);
    corner8.add(new Vector3f(-1, -1, -1));

    float lerp1 = lerp(grad(perm(AA), corner1), grad(perm(BA), corner2), faded.x);
    float lerp2 = lerp(grad(perm(AB), corner3), grad(perm(BB), corner4), faded.x);
    float lerp3 = lerp(grad(perm(AA + 1), corner5), grad(perm(BA + 1), corner6), faded.x);
    float lerp4 = lerp(grad(perm(AB + 1), corner7), grad(perm(BB + 1), corner8), faded.x);

    float lerp12 = lerp(lerp1, lerp2, faded.y);
    float lerp34 = lerp(lerp3, lerp4, faded.y);

    return lerp(lerp12, lerp34, faded.z);
  }
 boolean transform(short mad, Atom atom, Vector3f vibrationVector) {
   float len = vibrationVector.length();
   // to have the vectors move when vibration is turned on
   if (Math.abs(len * vectorScale) < 0.01) return false;
   headScale = arrowHeadOffset;
   if (vectorScale < 0) headScale = -headScale;
   doShaft = (0.1 + Math.abs(headScale / len) < Math.abs(vectorScale));
   headOffsetVector.set(vibrationVector);
   headOffsetVector.scale(headScale / len);
   pointVectorEnd.scaleAdd(vectorScale, vibrationVector, atom);
   pointArrowHead.set(pointVectorEnd);
   pointArrowHead.add(headOffsetVector);
   screenArrowHead.set(viewer.transformPoint(pointArrowHead, vibrationVector));
   screenVectorEnd.set(viewer.transformPoint(pointVectorEnd, vibrationVector));
   diameter = (mad < 1 ? 1 : mad <= 20 ? mad : viewer.scaleToScreen(screenVectorEnd.z, mad));
   headWidthPixels = (int) (diameter * 2.0f);
   if (headWidthPixels < diameter + 2) headWidthPixels = diameter + 2;
   if (isGenerator) diameter = (mad < 1 ? 1 : mad); // may need tweaking
   return true;
 }