Initial commit

master
Ondřej Hruška 10 years ago
commit 074a25db88
  1. 41
      .classpath
  2. 5
      .gitignore
  3. 17
      .project
  4. 11
      .settings/org.eclipse.jdt.core.prefs
  5. BIN
      lib/OpenAL32.dll
  6. BIN
      lib/OpenAL64.dll
  7. BIN
      lib/jdom-2.0.3-sources.zip
  8. BIN
      lib/jdom-2.0.3.jar
  9. BIN
      lib/jinput-dx8.dll
  10. BIN
      lib/jinput-dx8_64.dll
  11. BIN
      lib/jinput-raw.dll
  12. BIN
      lib/jinput-raw_64.dll
  13. BIN
      lib/jinput.jar
  14. BIN
      lib/jogg-0.0.7.jar
  15. BIN
      lib/jorbis-0.0.15.jar
  16. BIN
      lib/libjinput-linux.so
  17. BIN
      lib/libjinput-linux64.so
  18. BIN
      lib/libjinput-osx.jnilib
  19. BIN
      lib/liblwjgl.jnilib
  20. BIN
      lib/liblwjgl.so
  21. BIN
      lib/liblwjgl64.so
  22. BIN
      lib/libopenal.so
  23. BIN
      lib/libopenal64.so
  24. BIN
      lib/lwjgl-source-2.8.4.zip
  25. BIN
      lib/lwjgl.dll
  26. BIN
      lib/lwjgl.jar
  27. BIN
      lib/lwjgl64.dll
  28. BIN
      lib/lwjgl_util.jar
  29. BIN
      lib/slick-util-src.zip
  30. BIN
      lib/slick-util.jar
  31. BIN
      res/fonts/4feb.ttf
  32. BIN
      res/images/gui/buttons_menu.png
  33. BIN
      res/images/gui/buttons_small.png
  34. BIN
      res/images/gui/icons.png
  35. BIN
      res/images/gui/logo.png
  36. BIN
      res/images/gui/widgets.png
  37. BIN
      res/images/particles/circle.png
  38. BIN
      res/images/particles/leaves.png
  39. BIN
      res/images/particles/rain.png
  40. BIN
      res/images/particles/snow.png
  41. BIN
      res/images/patterns/rivet_belts.png
  42. BIN
      res/images/patterns/steel.png
  43. BIN
      res/images/patterns/steel_big.png
  44. BIN
      res/images/patterns/steel_big_light.png
  45. BIN
      res/images/patterns/steel_big_scratched.png
  46. BIN
      res/images/patterns/steel_brushed.png
  47. BIN
      res/images/patterns/steel_light.png
  48. BIN
      res/images/patterns/water.png
  49. BIN
      res/images/program/program.png
  50. BIN
      res/images/sprites/HD-blue.png
  51. BIN
      res/images/sprites/HD-brown-dk.png
  52. BIN
      res/images/sprites/HD-brown-lt.png
  53. BIN
      res/images/sprites/HD-brown-ornamental.png
  54. BIN
      res/images/sprites/HD-green.png
  55. BIN
      res/images/sprites/HD-purple.png
  56. BIN
      res/images/sprites/HD-red.png
  57. BIN
      res/images/sprites/HD-shadow.png
  58. BIN
      res/images/sprites/HD-yellow.png
  59. BIN
      res/images/sprites/food-shadow.png
  60. BIN
      res/images/sprites/food.png
  61. BIN
      res/images/tiles/shading.png
  62. BIN
      res/images/tiles/tiles.png
  63. 9
      res/levels/manifest.xml
  64. BIN
      res/sounds/effects/bell.ogg
  65. BIN
      res/sounds/effects/block_drop.ogg
  66. BIN
      res/sounds/effects/block_pick.ogg
  67. BIN
      res/sounds/effects/block_put.ogg
  68. BIN
      res/sounds/effects/break_fruit.ogg
  69. BIN
      res/sounds/effects/click_button1.ogg
  70. BIN
      res/sounds/effects/click_button2.ogg
  71. BIN
      res/sounds/effects/click_open.ogg
  72. BIN
      res/sounds/effects/click_rattle.ogg
  73. BIN
      res/sounds/effects/click_switch.ogg
  74. BIN
      res/sounds/effects/click_tray.ogg
  75. BIN
      res/sounds/effects/click_typewriter1.ogg
  76. BIN
      res/sounds/effects/click_typewriter2.ogg
  77. BIN
      res/sounds/effects/eat.ogg
  78. BIN
      res/sounds/effects/error.ogg
  79. BIN
      res/sounds/effects/gear1.ogg
  80. BIN
      res/sounds/effects/gear2.ogg
  81. BIN
      res/sounds/effects/loop_drag.ogg
  82. BIN
      res/sounds/effects/loop_walking.ogg
  83. BIN
      res/sounds/effects/popup.ogg
  84. BIN
      res/sounds/effects/shutter.ogg
  85. BIN
      res/sounds/effects/splash.ogg
  86. BIN
      res/sounds/effects/turtle_drop.ogg
  87. BIN
      res/sounds/effects/waterdrops/drop1.ogg
  88. BIN
      res/sounds/effects/waterdrops/drop2.ogg
  89. BIN
      res/sounds/effects/waterdrops/drop3.ogg
  90. BIN
      res/sounds/effects/waterdrops/drop4.ogg
  91. BIN
      res/sounds/effects/waterdrops/drop5.ogg
  92. BIN
      res/sounds/effects/waterdrops/drop6.ogg
  93. BIN
      res/sounds/loops/crate_move.ogg
  94. BIN
      res/sounds/loops/rain.ogg
  95. BIN
      res/sounds/loops/stream.ogg
  96. BIN
      res/sounds/loops/turtle_walking.ogg
  97. BIN
      res/sounds/loops/wilderness.ogg
  98. 177
      src/com/porcupine/color/HSV.java
  99. 382
      src/com/porcupine/color/RGB.java
  100. 930
      src/com/porcupine/coord/Coord.java
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="lib/jinput.jar" sourcepath="lib/lwjgl-source-2.8.4.zip">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Tortuga-game/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/lwjgl_util.jar" sourcepath="lib/lwjgl-source-2.8.4.zip">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Tortuga-game/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/lwjgl.jar" sourcepath="lib/lwjgl-source-2.8.4.zip">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Tortuga-game/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/slick-util.jar" sourcepath="lib/slick-util-src.zip">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Tortuga-game/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/jogg-0.0.7.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Tortuga-game/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/jorbis-0.0.15.jar">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Tortuga-game/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/jdom-2.0.3.jar" sourcepath="lib/jdom-2.0.3-sources.zip">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Tortuga-game/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

5
.gitignore vendored

@ -0,0 +1,5 @@
/bin/
/target/
*.log
.attach_pid*
*~

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Tortuga-game</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 959 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1001 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<manifest>
<levels>
<file>01.xml</file>
</levels>
</manifest>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,177 @@
package com.porcupine.color;
import java.awt.Color;
import com.porcupine.math.Calc;
/**
* HSV color
*
* @author MightyPork
*/
public class HSV {
/** H */
public double h;
/** S */
public double s;
/** V */
public double v;
/**
* Create black color 0,0,0
*/
public HSV() {}
/**
* Color from HSV 0-1
*
* @param h
* @param s
* @param v
*/
public HSV(Number h, Number s, Number v) {
this.h = h.doubleValue();
this.s = s.doubleValue();
this.v = v.doubleValue();
norm();
}
/**
* @return hue 0-1
*/
public double h()
{
return h;
}
/**
* @return saturation 0-1
*/
public double s()
{
return s;
}
/**
* @return value/brightness 0-1
*/
public double v()
{
return v;
}
/**
* Set color to other color
*
* @param copied copied color
* @return this
*/
public HSV setTo(HSV copied)
{
h = copied.h;
s = copied.s;
v = copied.v;
norm();
return this;
}
/**
* Set to H,S,V 0-1
*
* @param h hue
* @param s saturation
* @param v value
* @return this
*/
public HSV setTo(Number h, Number s, Number v)
{
this.h = h.doubleValue();
this.s = s.doubleValue();
this.v = v.doubleValue();
norm();
return this;
}
/**
* Fix numbers out of range 0-1
*/
public void norm()
{
h = Calc.clampd(h, 0, 1);
s = Calc.clampd(s, 0, 1);
v = Calc.clampd(v, 0, 1);
}
/**
* Convert to RGB
*
* @return RGB representation
*/
public RGB toRGB()
{
norm();
int rgb = Color.HSBtoRGB((float) h, (float) s, (float) v);
return RGB.fromHex(rgb);
}
/**
* Make from RGB
*
* @param color RGB
* @return HSV
*/
public static HSV fromRGB(RGB color)
{
return color.toHSV();
}
@Override
public String toString()
{
return "HSV[" + h + ";" + s + ";" + v + "]";
}
@Override
public boolean equals(Object obj)
{
if (obj == null) return false;
if (!(obj instanceof HSV)) return false;
return ((HSV) obj).h == h && ((HSV) obj).s == s && ((HSV) obj).v == v;
}
@Override
public int hashCode()
{
return Double.valueOf(h).hashCode() ^ Double.valueOf(s).hashCode() ^ Double.valueOf(v).hashCode();
}
/**
* Get a copy
*
* @return copy
*/
public HSV copy()
{
return new HSV().setTo(this);
}
}

@ -0,0 +1,382 @@
package com.porcupine.color;
import java.awt.Color;
import com.porcupine.math.Calc;
/**
* RGB color
*
* @author MightyPork
*/
public class RGB {
/** White */
public static final RGB WHITE = new RGB(1, 1, 1);
/** Black */
public static final RGB BLACK = new RGB(0, 0, 0);
/** Red */
public static final RGB RED = new RGB(1, 0, 0);
/** Lime green */
public static final RGB GREEN = new RGB(0, 1, 0);
/** Blue */
public static final RGB BLUE = new RGB(0, 0, 1);
/** Yellow */
public static final RGB YELLOW = new RGB(1, 1, 0);
/** Purple */
public static final RGB PURPLE = new RGB(1, 0, 1);
/** Cyan */
public static final RGB CYAN = new RGB(0, 1, 1);
/** orange */
public static final RGB ORANGE = new RGB(1, 0.6, 0);
/** no color (alpha=0) */
public static final RGB TRANSPARENT = new RGB(0, 0, 0, 0);
/** R */
public double r;
/** G */
public double g;
/** B */
public double b;
/** ALPHA */
public double a = 1;
/**
* Create black color 0,0,0
*/
public RGB() {}
/**
* Get copy with custom alpha
*
* @param alpha alpha to set
* @return copy w/ alpha
*/
public RGB setAlpha(double alpha)
{
return copy().setAlpha_ip(alpha);
}
/**
* set alpha IP
*
* @param alpha alpha to set
* @return this
*/
public RGB setAlpha_ip(double alpha)
{
a = alpha;
norm();
return this;
}
/**
* Get copy.
*
* @return copy
*/
public RGB copy()
{
return new RGB(r, g, b, a);
}
/**
* Get copy with alpha multiplied by custom value
*
* @param alpha alpha to set
* @return copy w/ alpha
*/
public RGB mulAlpha(double alpha)
{
return copy().mulAlpha_ip(alpha);
}
/**
* Multiply alpha by given number
*
* @param alpha alpha multiplier
* @return this
*/
public RGB mulAlpha_ip(double alpha)
{
a *= alpha;
norm();
return this;
}
/**
* Color from RGB 0-1
*
* @param r red
* @param g green
* @param b blue
*/
public RGB(Number r, Number g, Number b) {
this.r = r.doubleValue();
this.g = g.doubleValue();
this.b = b.doubleValue();
norm();
}
/**
* Color from RGB 0-1
*
* @param r red
* @param g green
* @param b blue
* @param a alpha
*/
public RGB(Number r, Number g, Number b, Number a) {
this.r = r.doubleValue();
this.g = g.doubleValue();
this.b = b.doubleValue();
this.a = a.doubleValue();
norm();
}
/**
* Color from hex 0xRRGGBB
*
* @param hex hex integer
*/
public RGB(int hex) {
setTo(RGB.fromHex(hex));
norm();
}
/**
* Color from hex 0xRRGGBB
*
* @param hex hex integer
* @param alpha alpha color
*/
public RGB(int hex, double alpha) {
setTo(RGB.fromHex(hex));
a = alpha;
norm();
}
/**
* Color from other RGB and alpha channel
*
* @param color other RGB color
* @param alpha new alpha channel
*/
public RGB(RGB color, double alpha) {
setTo(color);
setAlpha_ip(alpha);
}
/**
* @return red channel 0-1
*/
public double r()
{
return r;
}
/**
* @return green channel 0-1
*/
public double g()
{
return g;
}
/**
* @return blue channel 0-1
*/
public double b()
{
return b;
}
/**
* @return alpha 0-1
*/
public double a()
{
return a;
}
/**
* Set color to other color
*
* @param copied copied color
* @return this
*/
public RGB setTo(RGB copied)
{
r = copied.r;
g = copied.g;
b = copied.b;
a = copied.a;
norm();
return this;
}
/**
* Set to represent hex color
*
* @param hex hex integer RRGGBB
* @return this
*/
public RGB setTo(int hex)
{
setTo(RGB.fromHex(hex));
norm();
return this;
}
/**
* Set to R,G,B 0-1
*
* @param r red
* @param g green
* @param b blue
* @param a alpha
* @return this
*/
public RGB setTo(Number r, Number g, Number b, Number a)
{
this.r = r.doubleValue();
this.g = g.doubleValue();
this.b = b.doubleValue();
this.a = a.doubleValue();
norm();
return this;
}
/**
* Set to R,G,B 0-1
*
* @param r red
* @param g green
* @param b blue
* @return this
*/
public RGB setTo(Number r, Number g, Number b)
{
this.r = r.doubleValue();
this.g = g.doubleValue();
this.b = b.doubleValue();
this.a = 1;
norm();
return this;
}
/**
* Fix numbers out of range 0-1
*
* @return this
*/
public RGB norm()
{
r = Calc.clampd(r, 0, 1);
g = Calc.clampd(g, 0, 1);
b = Calc.clampd(b, 0, 1);
a = Calc.clampd(a, 0, 1);
return this;
}
/**
* Get hex value 0xRRGGBB
*
* @return hex value RRGGBB
*/
public int getHex()
{
int ri = (int) Math.round(r * 255);
int gi = (int) Math.round(g * 255);
int bi = (int) Math.round(b * 255);
return (ri << 16) | (gi << 8) | bi;
}
/**
* Convert to HSV
*
* @return HSV representation
*/
public HSV toHSV()
{
float[] hsv = { 0, 0, 0 };
Color.RGBtoHSB((int) (r * 255), (int) (g * 255), (int) (b * 255), hsv);
return new HSV(hsv[0], hsv[1], hsv[2]);
}
/**
* Create color from hex 0xRRGGBB
*
* @param hex hex RRGGBB
* @return the new color
*/
public static RGB fromHex(int hex)
{
int bi = hex & 0xff;
int gi = (hex >> 8) & 0xff;
int ri = (hex >> 16) & 0xff;
return new RGB(ri / 255D, gi / 255D, bi / 255D);
}
/**
* Make from HSV
*
* @param color HSV color
* @return RGB
*/
public static RGB fromHSV(HSV color)
{
return color.toRGB();
}
@Override
public String toString()
{
return "RGB[" + r + ";" + g + ";" + b + ";" + a + "]";
}
@Override
public boolean equals(Object obj)
{
if (obj == null) return false;
if (!(obj instanceof RGB)) return false;
return ((RGB) obj).r == r && ((RGB) obj).g == g && ((RGB) obj).b == b && ((RGB) obj).a == a;
}
@Override
public int hashCode()
{
return Double.valueOf(r).hashCode() ^ Double.valueOf(g).hashCode() ^ Double.valueOf(b).hashCode() ^ Double.valueOf(a).hashCode();
}
}

@ -0,0 +1,930 @@
package com.porcupine.coord;
import java.util.Random;
import com.porcupine.math.Calc;
/**
* Coordinate class, object with three or two double coordinates.<br>
*
* @author MightyPork
*/
public class Coord {
/** Coord [1;1;1] */
public static final Coord ONE = new Coord(1, 1, 1);
/** Zero Coord */
public static final Coord ZERO = new Coord(0, 0);
/** RNG */
protected static Random rand = new Random();
/**
* Get distance to other point
*
* @param a point a
* @param b point b
* @return distance in units
*/
public static double dist(Coord a, Coord b)
{
return a.distTo(b);
}
/**
* Generate random coord (gaussian)
*
* @param max max distance from 0
* @return new coord
*/
public static Coord random(double max)
{
return new Coord(Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2), Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2),
Calc.clampd(rand.nextGaussian() * max, -max * 2, max * 2));
}
/**
* Generate random coord (min-max)
*
* @param min min offset
* @param max max offset
* @return new coord
*/
public static Coord random(double min, double max)
{
return new Coord((rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)), (rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)),
(rand.nextBoolean() ? -1 : 1) * (min + rand.nextDouble() * (max - min)));
}
private double animTime = 0;
private Vec offs;
private Coord start;
private double time = 0;
/** X coordinate */
public double x = 0;
/** Y coordinate */
public double y = 0;
/** Z coordinate */
public double z = 0;
/**
* Create zero coord
*/
public Coord() {}
/**
* Create coord as a copy of another
*
* @param copied copied coord
*/
public Coord(Coord copied) {
this.x = copied.x;
this.y = copied.y;
this.z = copied.z;
}
/**
* Create 2D coord
*
* @param x x coordinate
* @param y y coordinate
*/
public Coord(Number x, Number y) {
setTo(x, y);
}
/**
* Create 3D coord
*
* @param x x coordinate
* @param y y coordinate
* @param z z coordinate
*/
public Coord(Number x, Number y, Number z) {
setTo(x, y, z);
}
/**
* Get a copy offset by vector
*
* @param vec offset
* @return the offset copy
*/
public Coord add(Coord vec)
{
return copy().add_ip(vec);
}
/**
* Get a copy offset by 2D coordinate
*
* @param x x offset
* @param y y offset
* @return the offset copy
*/
public Coord add(Number x, Number y)
{
return copy().add_ip(x, y);
}
/**
* Get a copy offset by 3D coordinate
*
* @param x x offset
* @param y y offset
* @param z z offset
* @return the offset copy
*/
public Coord add(Number x, Number y, Number z)
{
return copy().add_ip(x, y, z);
}
/**
* Offset by vector in place
*
* @param vec offset
* @return this
*/
public Coord add_ip(Coord vec)
{
this.x += vec.x;
this.y += vec.y;
this.z += vec.z;
return this;
}
/**
* Offset by 2D coordinate in place
*
* @param x x offset
* @param y y offset
* @return this
*/
public Coord add_ip(Number x, Number y)
{
this.x += x.doubleValue();
this.y += y.doubleValue();
return this;
}
/**
* Offset by 3D coordinate in place
*
* @param x x offset
* @param y y offset
* @param z z offset
* @return this
*/
public Coord add_ip(Number x, Number y, Number z)
{
this.x += x.doubleValue();
this.y += y.doubleValue();
this.z += z.doubleValue();
return this;
}
/**
* Start animation
*
* @param time anim length
*/
public void animate(double time)
{
if (start == null) start = new Coord();
if (offs == null) offs = new Vec();
this.time = time;
animTime = 0;
offs = start.vecTo(this);
}
/**
* @return copy of this vector
*/
public Coord copy()
{
return new Coord(x, y, z);
}
/**
* Get distance to other point
*
* @param point other point
* @return distance in units
*/
public double distTo(Coord point)
{
return Math.sqrt((point.x - x) * (point.x - x) + (point.y - y) * (point.y - y) + (point.z - z) * (point.z - z));
}
/**
* Get copy divided by number
*
* @param d number to divide by
* @return divided copy
*/
public Coord div(double d)
{
return copy().div_ip(d);
}
/**
* Divide by number in place
*
* @param d number to divide by
* @return this
*/
public Coord div_ip(double d)
{
if (d == 0) return this;
x /= d;
y /= d;
z /= d;
return this;
}
@Override
public boolean equals(Object obj)
{
if (obj == null) return false;
if (!obj.getClass().isAssignableFrom(Coord.class)) return false;
Coord other = (Coord) obj;
return x == other.x && y == other.y && z == other.z;
}
/**
* Get current value (animated)
*
* @return curent value
*/
public Coord getDelta()
{
if (start == null) start = new Coord();
if (offs == null) offs = new Vec();
if (isFinished()) return this;
return new Coord(start.add(offs.scale(animTime / time)));
}
@Override
public int hashCode()
{
return Double.valueOf(x).hashCode() ^ Double.valueOf(y).hashCode() ^ Double.valueOf(z).hashCode();
}
/**
* Get if animation is finished
*
* @return is finished
*/
public boolean isFinished()
{
return animTime >= time;
}
/**
* Check if this rectangle in inside a rectangular zone
*
* @param min min coord
* @param max max coord
* @return is inside
*/
public boolean isInRect(Coord min, Coord max)
{
return (x >= min.x && x <= max.x) && (y >= min.y && y <= max.y) && (z >= min.z && z <= max.z);
}
/**
* Check if this rectangle in inside a rectangular zone
*
* @param rect checked rect.
* @return is inside
*/
public boolean isInRect(Rect rect)
{
return isInRect(rect.min, rect.max);
}
/**
* Get middle of line to other point
*
* @param other other point
* @return middle
*/
public Coord midTo(Coord other)
{
return add(vecTo(other).scale(0.5));
}
/**
* Multiply by number
*
* @param d number
* @return multiplied copy
*/
public Coord mul(double d)
{
return copy().mul_ip(d);
}
/**
* Multiply coords by number
*
* @param xd x multiplier
* @param yd y multiplier
* @param zd z multiplier
* @return multiplied copy
*/
public Coord mul(double xd, double yd, double zd)
{
return copy().mul_ip(xd, yd, zd);
}
/**
* Multiply by number in place
*
* @param d multiplier
* @return this
*/
public Coord mul_ip(double d)
{
x *= d;
y *= d;
z *= d;
return this;
}
/**
* Multiply coords by number in place
*
* @param xd x multiplier
* @param yd y multiplier
* @param zd z multiplier
* @return this
*/
public Coord mul_ip(double xd, double yd, double zd)
{
x *= xd;
y *= yd;
z *= zd;
return this;
}
/**
* offset randomly
*
* @param max max +- offset
* @return offset coord
*/
public Coord random_offset(double max)
{
Coord r = random(1);
Vec v = new Vec(r);
v.norm_ip(0.00001 + rand.nextDouble() * max);
return copy().add_ip(v);
}
/**
* offset randomly
*
* @param min min offset
* @param max max offset
* @return offset coord
*/
public Coord random_offset(double min, double max)
{
return copy().add_ip(random(min, max));
}