Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (739)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (820)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Riven (posted 2013-03-25 16:01:11, viewed 287 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19  
public class Text {
   public static final String[] splitPair(String input, char delim) {
      int io = input.indexOf(delim);
      if (io == -1) {
         return null;
      }
      return new String[] { input.substring(0, io), input.substring(io + 1) };
   }

   public static final List<String> split(String input, char delim) {
      List<String> parts = new ArrayList<String>();
      for (int index; (index = input.indexOf(delim)) != -1;) {
         parts.add(input.substring(0, index));
         input = input.substring(index + 1);
      }
      parts.add(input);
      return parts;
   }
}


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154   155   156   157   158   159   160   161   162   163   164   165   166   167   168   169   170   171   172   173   174   175   176   177   178   179   180   181   182   183   184   185   186   187   188   189   190   191   192   193   194   195   196   197   198   199   200   201   202   203   204   205   206   207   208   209   210   211   212   213   214   215   216   217   218   219   220   221   222   223   224   225   226   227   228   229   230   231   232   233   234   235   236   237   238   239   240   241   242   243   244   245   246   247   248   249   250   251   252   253   254   255   256   257   258   259   260   261   262   263   264   265   266   267   268   269   270   271   272   273   274   275   276   277   278   279   280   281   282   283   284   285   286  
public class Vec3 {
   public static final Vec3 ZERO = new Vec3();

   public float x, y, z;

   //

   public Vec3() {
      load(0.0f);
   }

   public Vec3(float xyz) {
      load(xyz);
   }

   public Vec3(float x, float y, float z) {
      load(x, y, z);
   }

   public Vec3(float[] v, int pos) {
      load(v, pos);
   }

   public Vec3(Vec3 v) {
      load(v);
   }

   public boolean isZero() {
      return x == 0.0f && y == 0.0f && z == 0.0f;
   }

   /**
    * LOAD
    */

   public Vec3 load(Vec3 v) {
      this.x = v.x;
      this.y = v.y;
      this.z = v.z;

      return this;
   }

   public Vec3 load(float val) {
      this.x = val;
      this.y = val;
      this.z = val;

      return this;
   }

   public Vec3 load(float x, float y, float z) {
      this.x = x;
      this.y = y;
      this.z = z;

      return this;
   }

   public Vec3 load(float[] arr, int pos) {
      this.x = arr[pos + 0];
      this.y = arr[pos + 1];
      this.z = arr[pos + 2];

      return this;
   }

   /**
    * STORE
    */

   public final float[] store(float[] arr, int off) {
      arr[off + 0] = x;
      arr[off + 1] = y;
      arr[off + 2] = z;
      return arr;
   }

   /**
    * CALC
    */
   public float squaredDistance(Vec3 that) {
      float dx = this.x - that.x;
      float dy = this.y - that.y;
      float dz = this.z - that.z;
      return (dx * dx) + (dy * dy) + (dz * dz);
   }

   public float distance(Vec3 that) {
      return (float) Math.sqrt(this.squaredDistance(that));
   }

   public float squaredLength() {
      return (x * x) + (y * y) + (z * z);
   }

   public float length() {
      return (float) Math.sqrt(this.squaredLength());
   }

   private static final float minimal = Math.ulp(0.0f);

   public Vec3 length(float val) {
      float sqlen = this.squaredLength();
      if (sqlen <= minimal) {
         return this;
      }
      float li = val / (float) Math.sqrt(sqlen);

      this.x *= li;
      this.y *= li;
      this.z *= li;

      return this;
   }

   public Vec3 normalize() {
      float li = 1.0f / (float) Math.sqrt(this.squaredLength());

      this.x *= li;
      this.y *= li;
      this.z *= li;

      return this;
   }

   public Vec3 inv() {
      this.x *= -1.0f;
      this.y *= -1.0f;
      this.z *= -1.0f;

      return this;
   }

   public Vec3 abs() {
      if (x < 0.0F) {
         x = -x;
      }
      if (y < 0.0F) {
         y = -y;
      }
      if (z < 0.0F) {
         z = -z;
      }

      return this;
   }

   //

   public Vec3 add(float x, float y, float z) {
      this.x += x;
      this.y += y;
      this.z += z;

      return this;
   }

   public Vec3 sub(float x, float y, float z) {
      this.x -= x;
      this.y -= y;
      this.z -= z;

      return this;
   }

   public Vec3 mul(float x, float y, float z) {
      this.x *= x;
      this.y *= y;
      this.z *= z;

      return this;
   }

   public Vec3 div(float x, float y, float z) {
      this.x /= x;
      this.y /= y;
      this.z /= z;

      return this;
   }

   //

   public Vec3 add(float xyz) {
      return add(xyz, xyz, xyz);
   }

   public Vec3 sub(float xyz) {
      return sub(xyz, xyz, xyz);
   }

   public Vec3 mul(float xyz) {
      return mul(xyz, xyz, xyz);
   }

   public Vec3 div(float xyz) {
      return div(xyz, xyz, xyz);
   }

   //

   public Vec3 add(Vec3 vec) {
      return add(vec.x, vec.y, vec.z);
   }

   public Vec3 sub(Vec3 vec) {
      return sub(vec.x, vec.y, vec.z);
   }

   public Vec3 mul(Vec3 vec) {
      return mul(vec.x, vec.y, vec.z);
   }

   public Vec3 div(Vec3 vec) {
      return div(vec.x, vec.y, vec.z);
   }

   //

   public Vec3 min(Vec3 vec) {
      if (vec.x < x) {
         x = (vec.x);
      }
      if (vec.y < y) {
         y = (vec.y);
      }
      if (vec.z < z) {
         z = (vec.z);
      }

      return this;
   }

   public Vec3 max(Vec3 vec) {
      if (vec.x > x) {
         x = (vec.x);
      }
      if (vec.y > y) {
         y = (vec.y);
      }
      if (vec.z > z) {
         z = (vec.z);
      }

      return this;
   }

   /**
    * EQUALS
    */

   public boolean equals(Vec3 vec, float margin) {
      boolean bX = Math.abs(x - vec.x) <= margin;
      boolean bY = Math.abs(y - vec.y) <= margin;
      boolean bZ = Math.abs(z - vec.z) <= margin;

      return bX && bY && bZ;
   }

   @Override
   public boolean equals(Object obj) {
      if (obj == null || !(obj instanceof Vec3)) {
         return false;
      }
      return this.equals((Vec3) obj, 0.001f);
   }

   @Override
   public int hashCode() {
      int hashCode = 0;
      hashCode ^= 13 * Float.floatToRawIntBits(x);
      hashCode ^= 17 * Float.floatToRawIntBits(y);
      hashCode ^= 29 * Float.floatToRawIntBits(z);
      return hashCode;
   }

   /**
    * TO STRING
    */

   @Override
   public String toString() {
      return "Vec3[" + x + ", " + y + ", " + z + "]";
   }
}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
Ecumene (56 views)
2017-09-30 02:57:34

theagentd (79 views)
2017-09-26 18:23:31

cybrmynd (187 views)
2017-08-02 12:28:51

cybrmynd (185 views)
2017-08-02 12:19:43

cybrmynd (192 views)
2017-08-02 12:18:09

Sralse (203 views)
2017-07-25 17:13:48

Archive (767 views)
2017-04-27 17:45:51

buddyBro (901 views)
2017-04-05 03:38:00

CopyableCougar4 (1451 views)
2017-03-24 15:39:42

theagentd (1326 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!