/**
   * Calculates the min and max boundaries of the structure after it has been transformed into its
   * canonical orientation.
   */
  private void calcBoundaries() {
    minBoundary.x = Double.MAX_VALUE;
    maxBoundary.x = Double.MIN_VALUE;
    minBoundary.y = Double.MAX_VALUE;
    maxBoundary.x = Double.MIN_VALUE;
    minBoundary.z = Double.MAX_VALUE;
    maxBoundary.z = Double.MIN_VALUE;
    xzRadiusMax = Double.MIN_VALUE;

    Point3d probe = new Point3d();

    for (Point3d[] list : subunits.getTraces()) {
      for (Point3d p : list) {
        probe.set(p);
        transformationMatrix.transform(probe);

        minBoundary.x = Math.min(minBoundary.x, probe.x);
        maxBoundary.x = Math.max(maxBoundary.x, probe.x);
        minBoundary.y = Math.min(minBoundary.y, probe.y);
        maxBoundary.y = Math.max(maxBoundary.y, probe.y);
        minBoundary.z = Math.min(minBoundary.z, probe.z);
        maxBoundary.z = Math.max(maxBoundary.z, probe.z);
        xzRadiusMax = Math.max(xzRadiusMax, Math.sqrt(probe.x * probe.x + probe.z * probe.z));
      }
    }
    //		System.out.println("MinBoundary: " + minBoundary);
    //		System.out.println("MaxBoundary: " + maxBoundary);
    //		System.out.println("zxRadius: " + xzRadiusMax);
  }
Exemple #2
0
 public void brighter() {
   float[] rgb = color.get().getRGBComponents(null);
   rgb[0] = (float) Math.min(rgb[0] + 0.1, 1.0);
   rgb[1] = (float) Math.min(rgb[1] + 0.1, 1.0);
   rgb[2] = (float) Math.min(rgb[2] + 0.1, 1.0);
   color = new Color3f(rgb);
   updateLight();
 }
Exemple #3
0
/**
 * Adjust the specified mins and maxs vectors so that they contain the specified point.
 * @param point Point being added
 * @param mins Min coordinates of the bounding box
 * @param maxs Max coordinates of the bounding box
 */
public static void addPointToBounds(Tuple3f point, Tuple3f mins, Tuple3f maxs) 
	{
	mins.x = Math.min(mins.x, point.x);
	mins.y = Math.min(mins.y, point.y);
	mins.z = Math.min(mins.z, point.z);
	
	maxs.x = Math.max(maxs.x, point.x);
	maxs.y = Math.max(maxs.y, point.y);
	maxs.z = Math.max(maxs.z, point.z);
	}
Exemple #4
0
    public void run() {
      adjustToScreenSize =
          (float)
              Math.min(
                  jframe.getWidth(),
                  jframe.getHeight()); // used here, since you can change the screen-Size

      Matrix4f newTranslation = new Matrix4f();
      newTranslation.setIdentity();

      Matrix4f oldcTranslation = new Matrix4f();
      oldcTranslation = camera.getCameraMatrix();

      // world z-Axis-turn
      if (mouseWorldTurn != null) {
        newTranslation.mul(mouseWorldTurn);
        mouseWorldTurn.setIdentity();
      }

      // camera x-Axis-turn
      if (mouseTurn != null) {
        newTranslation.mul(mouseTurn);
        mouseTurn.setIdentity();
      }

      // camera movement
      if (keyMove != null) {
        newTranslation.mul(keyMove);
        keyMove.setIdentity();
      }

      newTranslation.mul(oldcTranslation);

      camera.setCameraMatrix(newTranslation);
      // something still appears to be wrong while turning

      // Trigger redrawing of the render window
      renderPanel.getCanvas().repaint();
    }
Exemple #5
0
	public String getDeathmatchScoreboardMessage( GameObject victim, GameObject killer, boolean inIntermission ) 
	{
		int xOffset, statHeader, statCaps, headerIndex;
		String s;
		Team otherTeam;
		
		otherTeam   = ( this == TEAM1 ? TEAM2 : TEAM1 );
		xOffset     = ( this == TEAM1 ? 0 : 160 );
		statHeader  = ( this == TEAM1 ? STAT_CTF_TEAM1_HEADER          : STAT_CTF_TEAM2_HEADER          );
		headerIndex = ( this == TEAM1 ? Engine.getImageIndex("ctfsb1") : Engine.getImageIndex("ctfsb2") );
		statCaps    = ( this == TEAM1 ? STAT_CTF_TEAM1_CAPS            : STAT_CTF_TEAM2_CAPS            );

		// display our teamheader
		victim.fEntity.setPlayerStat( statHeader, (short)headerIndex );	

/*		// if during intermission, we must blink our header if we're the winning team (or tie)
		if ( inIntermission && ((int)Game.getGameTime()%2 == 0 ) )	// blink every second
		{
			if ( this.getCaptures() > otherTeam.getCaptures() )
				victim.fEntity.setPlayerStat( statHeader, (short)0 );	
			// Capture tie, check total frags
			else if ( this.getScore() >= otherTeam.getScore() )
				victim.fEntity.setPlayerStat( statHeader, (short)0 );	
		}
*/
		s = "if " + statHeader + " xv " + (8+xOffset) + " yv 8 pic " + statHeader + " endif " +
			"xv " + (40+xOffset) + " yv 28 string \"" + getScore() + "/" + fCaptures + "\" " +
			"xv " + (98+xOffset) + " yv 12 num 2 " + statCaps + " ";

		// TODO: sort players by score
		Player[] players = getPlayers();
	/*	int begin = 0;
		int i     = begin;
		while ( i < players.length-1 )
		{
			if ( players[i].getScore() < players[i+1].getScore() )
			{
				Player dummy = players[i];
				players[i]   = players[i+1];
				players[i+1] = dummy;
			}
			if ( i == players.length-2 )
				i = ++begin;
		}
*/
		for ( int i=0; i<8 && i<players.length; i++ )
		{
			Player p    = players[i];
			int    ping = Math.min( p.fEntity.getPlayerPing(), 999 );

			s += "ctf " + xOffset + " " + (42+i*8) + " " + p.fEntity.getPlayerNum() + " " +
			     p.getScore() + " " +
				 ping + " ";

			GenericFlag flag = (GenericFlag)p.getInventory( "flag" );

			if ( flag != null )	// flag IS other teams flag...
			{
				s += "xv " + (56+xOffset) + " picn " + flag.getSmallIconName() + " ";
			}
		}

		if ( players.length > 8 )
		{
			s += "xv " + (8+xOffset) + " yv " + (42+8*8) + " string \"...and " + (players.length-8) + " more\" ";
		}

		return s;
		
	}
  public static void zoomToFit(Viewport2 viewport) {
    ViewDefinition viewdef = viewport.getViewDefinition();
    // if (MainFrame.getInstance().getMeshToolBar().getMode() != MeshToolBar.VIEW_ZOOM) {
    //	MainFrame.getInstance().getJPatchScreen().removeAllMouseListeners();
    //	MainFrame.getInstance().getJPatchScreen().addMouseListeners(new
    // ChangeViewMouseListener(MouseEvent.BUTTON1,ChangeViewMouseListener.ZOOM));
    //	MainFrame.getInstance().getMeshToolBar().setMode(MeshToolBar.VIEW_ZOOM);
    // } else {
    //	MainFrame.getInstance().getMeshToolBar().reset();
    // }
    Selection selection = MainFrame.getInstance().getSelection();
    float left = Float.MAX_VALUE;
    float right = -Float.MAX_VALUE;
    float bottom = Float.MAX_VALUE;
    float top = -Float.MAX_VALUE;
    Point3f p3 = new Point3f();
    Matrix4f m4View = viewdef.getScreenMatrix();
    // Matrix3f m3RotScale = new Matrix3f();
    // m4View.getRotationScale(m3RotScale);
    boolean doit = true;
    if (selection != null && !selection.isSingle()) {
      for (Iterator it = selection.getObjects().iterator(); it.hasNext(); ) {
        Object object = it.next();
        if (object instanceof ControlPoint) {
          p3.set(((ControlPoint) object).getPosition());
          m4View.transform(p3);
          if (p3.x < left) left = p3.x;
          if (p3.x > right) right = p3.x;
          if (p3.y < bottom) bottom = p3.y;
          if (p3.y > top) top = p3.y;
        }
      }
    } else {
      ArrayList heads = MainFrame.getInstance().getModel().allHeads();
      int p = 0;
      for (Iterator it = heads.iterator(); it.hasNext(); ) {
        ControlPoint cp = (ControlPoint) it.next();
        if (!cp.isHidden()) {
          p3.set(cp.getPosition());
          m4View.transform(p3);
          if (p3.x < left) left = p3.x;
          if (p3.x > right) right = p3.x;
          if (p3.y < bottom) bottom = p3.y;
          if (p3.y > top) top = p3.y;
          p++;
        }
      }
      doit = (p >= 2);
    }
    if (doit) {
      // System.out.println(left + " " + right + " " + top + " " + bottom + " " +
      // viewdef.getScale());
      // System.out.println(viewdef.getTranslateX() + " " + viewdef.getTranslateY());
      float centerX = (left + right) / 2f;
      float centerY = (top + bottom) / 2f;
      float dimX = viewdef.getWidth() / 2f;
      float dimY = viewdef.getHeight() / 2f;
      float sizeX = right - centerX;
      float sizeY = top - centerY;
      if (sizeX > 0 || sizeY > 0) {
        // System.out.println(centerX + ":" + centerY);

        float scaleX = dimX / sizeX;
        float scaleY = dimY / sizeY;
        float scale = Math.min(scaleX, scaleY) * 0.9f;
        // viewdef.setScale(viewdef.getScale() * scale);
        viewdef.setLock(null);
        viewdef.moveView(-centerX / dimX + 1, (dimY - centerY) / dimX, false);
        viewdef.scaleView(scale);
        // viewdef.setTranslation(centerX, centerY);
        // viewdef.computeMatrix();
        // viewport.render();
      }
    }
  }
  public void update(int anim, int time) {
    float dt = (float) viewer.getDelta() * 0.001F;
    float grav = AnimatedFloat.getValue(gravity, anim, time);
    float deaccel = AnimatedFloat.getValue(gravity2, anim, time);
    if (emitterType == 1 || emitterType == 2) {
      float rate = AnimatedFloat.getValue(emissionRate, anim, time);
      float life = AnimatedFloat.getValue(lifespan, anim, time);
      float toSpawn = 0.0F;
      if (life != 0.0F) toSpawn = (dt * rate) / life + spawnRemainder;
      else toSpawn = spawnRemainder;
      if (toSpawn < 1.0F) {
        spawnRemainder = toSpawn;
        if (spawnRemainder < 0.0F) spawnRemainder = 0.0F;
      } else {
        int spawnCount = (int) toSpawn;
        if (spawnCount + particles.size() > 1000) spawnCount = 1000 - particles.size();
        spawnRemainder = toSpawn - (float) spawnCount;
        float w = AnimatedFloat.getValue(areaWidth, anim, time) * 0.5F;
        float l = AnimatedFloat.getValue(areaLength, anim, time) * 0.5F;
        float speed = AnimatedFloat.getValue(emissionSpeed, anim, time);
        float var = AnimatedFloat.getValue(speedVariation, anim, time);
        float spread = AnimatedFloat.getValue(verticalRange, anim, time);
        float spread2 = AnimatedFloat.getValue(horizontalRange, anim, time);
        boolean en = true;
        int thisAnim = anim;
        if (thisAnim >= enabled.length) thisAnim = 0;
        if (enabled.length > 0 && enabled[thisAnim].used)
          en = enabled[thisAnim].getValue(time) != 0;
        if (en) {
          for (int i = 0; i < spawnCount; i++) {
            Particle p;
            if (emitterType == 1)
              p = PlaneEmitter.newParticle(this, anim, time, w, l, speed, var, spread, spread2);
            else p = SphereEmitter.newParticle(this, anim, time, w, l, speed, var, spread, spread2);
            particles.add(p);
          }
        }
      }
    }
    float speed = 1.0F;
    Vec3 t1 = new Vec3();
    Vec3 t2 = new Vec3();
    Vec3 t3 = new Vec3();
    Point4f d = new Point4f();
    Point4f c[] = new Point4f[3];
    for (int i = 0; i < 3; i++) c[i] = new Point4f();

    for (int i = 0; i < particles.size(); ) {
      Particle p = (Particle) particles.get(i);
      p.speed.add(
          Vec3.sub(Vec3.scale(p.down, grav * dt, t1), Vec3.scale(p.dir, deaccel * dt, t2), t3));
      if (slowdown > 0.0F) speed = (float) Math.exp(-1F * slowdown * p.life);
      p.pos.add(Vec3.scale(p.speed, speed * dt, t1));
      p.life += dt;
      float lifePos = p.life / p.maxLife;
      float s1 = size.data[0].x;
      float s2 = 0.0F;
      float s3 = 0.0F;
      if (size.data.length > 1) s2 = size.data[1].x;
      else s2 = s1;
      if (size.data.length > 2) s3 = size.data[2].x;
      else s3 = s2;
      p.size = lifeInterp(lifePos, 0.5F, s1 * scale.x, s2 * scale.y, s3 * scale.z);
      int limit = Math.min(3, color.data.length);
      for (int j = 0; j < limit; j++) {
        Point3f t = color.data[j];
        c[j].set(t.x / 255F, t.y / 255F, t.z / 255F, (float) transparency.data[j] / 32767F);
      }

      if (limit < 3) {
        Point3f t = color.data[limit - 1];
        for (int j = limit - 1; j < 3; j++)
          c[j].set(t.x / 255F, t.y / 255F, t.z / 255F, (float) transparency.data[j] / 32767F);
      }
      lifeInterp(lifePos, 0.5F, c[0], c[1], c[2], d);
      p.color.set(d);
      if (lifePos >= 1.0F) particles.remove(i);
      else i++;
    }
  }
 public float getLowestZValue() {
   // just in case the length is negative...
   return Math.min(parameterList[2].value, parameterList[2].value + parameterList[5].value);
 };
Exemple #9
0
 public void normalize(double range) {
   double scale = range;
   float min = 1000f;
   float max = -1000f;
   for (int k = 0; k < size; k++) {
     //    	System.out.println(f[k]);
     /*
      * if (f[k] == Float.NaN) { System.out.println("NaN at k= "+k);
      * f[k] = 0f; }
      */
     if (Float.isNaN(f[k])) {
       System.out.println("NaN at k= " + k);
       f[k] = 0f;
       continue;
     }
     if (Float.isInfinite(f[k])) {
       if (f[k] < 0) {
         System.out.println("-Infinity at k= " + k);
         f[k] = 0f; // -1000f;
       } else {
         System.out.println("+Infinity at k= " + k);
         f[k] = 0f; // +1000f;
       }
       continue;
     }
     // System.out.print(k +"="+f[k]+ ", ");
     min = Math.min(min, f[k]);
     max = Math.max(max, f[k]);
   }
   // System.out.println();
   double offset = 0. - min;
   if ((max - min) != 0f) {
     scale /= (max - min);
     offset *= scale;
     rescale(scale, offset);
   }
   System.out.println(
       "Normalizing using: min= "
           + min
           + " max= "
           + max
           + ", through scaleAdd("
           + scale
           + ", "
           + offset
           + ").");
   min = 1000f;
   max = -1000f;
   for (int k = 0; k < size; k++) {
     /*			if (f[k] == Float.NaN) {
     				System.out.println("NaN at k= " + k);
     				f[k] = 0f;
     			}
     */
     if (Float.isNaN(f[k])) {
       System.out.println("NaN at k= " + k + " after normalization.");
       f[k] = 0f;
       continue;
     }
     // System.out.print(k +"="+f[k]+ ", ");
     min = Math.min(min, f[k]);
     max = Math.max(max, f[k]);
   }
   System.out.println("After normalization: min= " + min + " max= " + max);
 }
Exemple #10
0
  public Tuple4f getDynamics() {
    Tuple4f dynamics = new Vector4f();
    long count = 0;
    double total = 0;

    float min = Float.POSITIVE_INFINITY;
    float max = Float.NEGATIVE_INFINITY;

    for (int k = 0; k < size; k++) {
      // Do not include NAN or isInfinite in dynamics
      if (!((Float.isNaN(f[k])) || (Float.isInfinite(f[k])))) {

        // System.out.print(k +"="+f[k]+ ", ");
        min = Math.min(min, f[k]);
        max = Math.max(max, f[k]);
        total += (double) f[k];
        count++;
      }
    }
    dynamics.w = min;
    dynamics.x = max;
    dynamics.y = (float) (total / (double) count);
    float range = max - min;
    int N = 256;
    System.out.println("min: " + min + " Max: " + max + " Range: " + range);
    int[] histogram = new int[N];
    int level = 0;
    float quant = N * 0.999f;
    for (int k = 0; k < size; k++) {
      if (!((Float.isNaN(f[k])) || (Float.isInfinite(f[k])))) {
        level = (int) (quant * ((f[k] - min) / range));
        try {
          histogram[level]++;
        } catch (ArrayIndexOutOfBoundsException e) {
          System.out.println("ArrayIndexOutOfBoundsException in ScalarImage.analyze(double) [A].");
        }
      }
    }
    for (int j = 0; j < N; j++) {
      System.out.println(
          "Level: "
              + j
              + " count: "
              + histogram[j]
              + " value: "
              + (float) ((j / quant * (max - min)) + min));
    }
    int target = (int) (count * 0.9);
    int cum = 0;
    for (int i = 0; i < N; i++) {
      cum += histogram[i];
      System.out.println(
          "target: "
              + target
              + " cum: "
              + cum
              + " Level: "
              + i
              + " value: "
              + ((i / quant * (max - min)) + min));
      if (cum >= target) {
        System.out.println(
            "target: " + target + " Level: " + i + " value: " + ((i * (max - min)) + min));
        dynamics.z = (float) ((i / quant * (max - min)) + min);
        break;
      }
    }
    return dynamics;
  }
Exemple #11
0
  public void analyze(boolean doit) {

    float min = Float.POSITIVE_INFINITY;
    float max = Float.NEGATIVE_INFINITY;
    for (int k = 0; k < size; k++) {
      //    	System.out.println(f[k]);
      /*
       * if (f[k] == Float.NaN) { System.out.println("NaN at k= "+k);
       * f[k] = 0f; }
       */
      if (Float.isNaN(f[k])) {
        System.out.println("NaN at k= " + k);
        f[k] = 0f;
        continue;
      }
      if (Float.isInfinite(f[k])) {
        if (f[k] < 0) {
          System.out.println("-Infinity at k= " + k);
          f[k] = 0f; // -1000f;
        } else {
          System.out.println("+Infinity at k= " + k);
          f[k] = 0f; // +1000f;
        }
        continue;
      }
      // System.out.print(k +"="+f[k]+ ", ");
      min = Math.min(min, f[k]);
      max = Math.max(max, f[k]);
    }

    int N = 256;
    float[] histogram = new float[N];

    for (int k = 0; k < size; k++) {
      int level = (int) (0.999f * (float) N * (f[k] - min) / (max - min));
      try {
        histogram[level]++;
      } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("ArrayIndexOutOfBoundsException in ScalarImage.analyze(double) [A].");
      }
    }

    float[] cumulative = new float[N];
    if (histogram[0] > 0) {
      if (doit) {
        cumulative[0] = histogram[0];
      } else {
        cumulative[0] = 1; // histogram[0];
      }
    }
    for (int i = 1; i < N; i++) {
      if (histogram[i] > 0) {
        if (doit) {
          cumulative[i] = cumulative[i - 1] + histogram[i];
        } else {
          cumulative[i] = cumulative[i - 1] + 1; // histogram[i];
        }
      } else {
        cumulative[i] = cumulative[i - 1];
      }
    }

    /*		for(int k=0; k<size; k++) {
    			int level = (int) ( 0.999f*(float)N*(f[k]-min)/(max-min) );
    			try {
    				f[k]=(cumulative[level]-cumulative[0])/(cumulative[N-1]-cumulative[0]);
    			} catch( ArrayIndexOutOfBoundsException e) {
    				System.out.println("ArrayIndexOutOfBoundsException in ScalarImage.analyze(double) [B].");
    			}
    		}
    */
    for (int k = 0; k < size; k++) {
      float x, x1, x2, f1, f2;
      try {
        x = Math.abs((f[k] - min) / (max - min));
        x1 = (float) Math.floor((float) (N - 1) * x * 0.999f) / (float) (N - 1);
        x2 = (float) Math.ceil((float) (N - 1) * x * 0.999f) / (float) (N - 1);
        f1 =
            (cumulative[(int) Math.floor((float) (N - 1) * x * 0.999f)] - cumulative[0])
                / (cumulative[N - 1] - cumulative[0]);
        f2 =
            (cumulative[(int) Math.ceil((float) (N - 1) * x * 0.999f)] - cumulative[0])
                / (cumulative[N - 1] - cumulative[0]);
        f[k] = (f2 - f1) * (x - x1) / (x2 - x1) + f1;
      } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(
            "ArrayIndexOutOfBoundsException in ScalarImage.analyze(double) [C]. " + e.getMessage());
      }
    }

    return;

    /*
    		double offset = 0. - min;
    		if ((max - min) != 0f) {
    			scale /= (max - min);
    			offset *= scale;
    			rescale(scale, offset);
    		}
    		System.out.println("Normalizing using: min= " + min + " max= " + max
    				+ ", through scaleAdd(" + scale + ", " + offset + ").");
    		min = 1000f;
    		max = -1000f;
    		for (int k = 0; k < size; k++) {
    			if (Float.isNaN(f[k])) {
    				System.out.println("NaN at k= " + k + " after normalization.");
    				f[k] = 0f;
    				continue;
    			}
    			min = Math.min(min, f[k]);
    			max = Math.max(max, f[k]);
    		}
    		System.out.println("After normalization: min= " + min + " max= " + max);
    */
  }