9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-25 10:09:14 +00:00
This commit is contained in:
Daniel Mills
2020-08-25 15:55:46 -04:00
parent 44b6396b78
commit 01fd89f60c
48 changed files with 36919 additions and 38591 deletions

View File

@@ -100,7 +100,6 @@ public class Iris extends MortarPlugin implements BoardProvider
postProcessors = loadPostProcessors();
proj = new ProjectManager();
manager = new BoardManager(this, BoardSettings.builder().boardProvider(this).scoreDirection(ScoreDirection.UP).build());
super.onEnable();
}

View File

@@ -226,11 +226,18 @@ public class ProjectManager
KSet<IrisBiome> biomes = new KSet<>();
KSet<IrisStructure> structures = new KSet<>();
KSet<IrisGenerator> generators = new KSet<>();
KSet<IrisLootTable> loot = new KSet<>();
dimension.getRegions().forEach((i) -> regions.add(Iris.globaldata.getRegionLoader().load(i)));
dimension.getLoot().getTables().forEach((i) -> loot.add(Iris.globaldata.getLootLoader().load(i)));
regions.forEach((i) -> biomes.addAll(i.getAllBiomes(null)));
biomes.forEach((i) -> i.getGenerators().forEach((j) -> generators.add(j.getCachedGenerator(null))));
regions.forEach((i) -> i.getStructures().forEach((j) -> structures.add(j.getStructure(null))));
biomes.forEach((i) -> i.getStructures().forEach((j) -> structures.add(j.getStructure(null))));
regions.forEach((r) -> r.getLoot().getTables().forEach((i) -> loot.add(Iris.globaldata.getLootLoader().load(i))));
biomes.forEach((r) -> r.getLoot().getTables().forEach((i) -> loot.add(Iris.globaldata.getLootLoader().load(i))));
structures.forEach((r) -> r.getLoot().getTables().forEach((i) -> loot.add(Iris.globaldata.getLootLoader().load(i))));
structures.forEach((b) -> b.getTiles().forEach((r) -> r.getLoot().getTables().forEach((i) -> loot.add(Iris.globaldata.getLootLoader().load(i)))));
KMap<String, String> renameObjects = new KMap<>();
String a = "";
StringBuilder b = new StringBuilder();
@@ -429,6 +436,13 @@ public class ProjectManager
b.append(IO.hash(a));
}
for(IrisLootTable i : loot)
{
a = new JSONObject(new Gson().toJson(i)).toString(0);
IO.writeAll(new File(folder, "loot/" + i.getLoadKey() + ".json"), a);
b.append(IO.hash(a));
}
c.append(IO.hash(b.toString()));
b = new StringBuilder();
String finalHash = IO.hash(c.toString());

View File

@@ -11,6 +11,7 @@ import com.volmit.iris.gen.atomics.AtomicSliver;
import com.volmit.iris.gen.atomics.AtomicSliverMap;
import com.volmit.iris.gen.atomics.AtomicWorldData;
import com.volmit.iris.gen.atomics.MasterLock;
import com.volmit.iris.gen.layer.GenLayerText;
import com.volmit.iris.gen.layer.GenLayerUpdate;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisBiomeMutation;
@@ -44,6 +45,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
private IrisLock lock = new IrisLock("ParallaxLock");
private IrisLock lockq = new IrisLock("ParallaxQueueLock");
private GenLayerUpdate glUpdate;
private GenLayerText glText;
private int sliverBuffer;
public ParallaxChunkGenerator(String dimensionName, int threads)
@@ -58,6 +60,7 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
{
super.onInit(world, rng);
parallaxMap = new AtomicWorldData(world, "floor");
glText = new GenLayerText(this, rng.nextParallelRNG(32485));
}
protected KMap<ChunkPosition, AtomicSliver> getSliverCache()

View File

@@ -25,7 +25,7 @@ public class BiomeDataProvider
public BiomeResult generatePureData(ContextualChunkGenerator g, double bx, double bz, int rawX, int rawZ, IrisRegion regionData)
{
return layer.generateBiomeData(bx, bz, regionData, getGenerator(), regionData.getBiomes(g, getType()), getType());
return layer.generateBiomeData(bx, bz, regionData, getGenerator(), regionData.getBiomes(g, getType()), getType(), rawX, rawZ);
}
public BiomeResult generateData(ContextualChunkGenerator g, double bx, double bz, int rawX, int rawZ, IrisRegion regionData)

View File

@@ -121,8 +121,24 @@ public class GenLayerBiome extends GenLayer
return bridge;
}
public BiomeResult generateBiomeData(double bx, double bz, IrisRegion regionData, CNG cell, KList<IrisBiome> biomes, InferredType inferredType)
public BiomeResult generateBiomeData(double bx, double bz, IrisRegion regionData, CNG cell, KList<IrisBiome> biomes, InferredType inferredType, int rx, int rz)
{
for(IrisRegionRidge i : regionData.getRidgeBiomes())
{
if(i.getType().equals(inferredType) && i.isRidge(rng, rx, rz))
{
return new BiomeResult(iris.loadBiome(i.getBiome()).infer(i.getAs(), inferredType), 0.5);
}
}
for(IrisRegionSpot i : regionData.getSpotBiomes())
{
if(i.getType().equals(inferredType) && i.isSpot(rng, rx, rz))
{
return new BiomeResult(iris.loadBiome(i.getBiome()).infer(i.getAs(), inferredType), 0.5);
}
}
if(biomes.isEmpty())
{
return new BiomeResult(null, 0);
@@ -138,22 +154,6 @@ public class GenLayerBiome extends GenLayer
public BiomeResult generateImpureData(int rawX, int rawZ, InferredType type, IrisRegion regionData, BiomeResult pureResult)
{
for(IrisRegionRidge i : regionData.getRidgeBiomes())
{
if(i.getType().equals(type) && i.isRidge(rng, rawX, rawZ))
{
return new BiomeResult(iris.loadBiome(i.getBiome()).infer(i.getAs(), type), 0.5);
}
}
for(IrisRegionSpot i : regionData.getSpotBiomes())
{
if(i.getType().equals(type) && i.isSpot(rng, rawX, rawZ))
{
return new BiomeResult(iris.loadBiome(i.getBiome()).infer(i.getAs(), type), 0.5);
}
}
return pureResult;
}

View File

@@ -0,0 +1,68 @@
package com.volmit.iris.gen.layer;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.DimensionChunkGenerator;
import com.volmit.iris.gen.atomics.AtomicCache;
import com.volmit.iris.object.IrisObject;
import com.volmit.iris.util.B;
import com.volmit.iris.util.GenLayer;
import com.volmit.iris.util.RNG;
public class GenLayerText extends GenLayer
{
public static final BlockData AIR = B.getBlockData("AIR");
private AtomicCache<IrisObject> debug = new AtomicCache<>();
public GenLayerText(DimensionChunkGenerator iris, RNG rng)
{
super(iris, rng);
}
public IrisObject getDebug()
{
return debug.aquire(() ->
{
return createTextObject("Test", "Impact", 24, B.get("STONE"));
});
}
public IrisObject createTextObject(String text, String font, int size, BlockData b)
{
Font f = new Font(font, Font.PLAIN, size);
int w = ((Graphics2D) new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB).getGraphics()).getFontMetrics(f).stringWidth(text);
int h = size;
Iris.info("WH is " + w + " " + h);
BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics gs = bufferedImage.getGraphics();
Graphics2D g = (Graphics2D) gs;
g.setFont(f);
g.drawString(text, 0, h);
IrisObject o = new IrisObject(w, 1, h);
for(int y = 0; y < h; y++)
{
for(int x = 0; x < w; x++)
{
if(bufferedImage.getRGB(x, y) != -16777216)
{
o.setUnsigned(x, 0, y, b);
}
}
}
return o;
}
@Override
public double generate(double x, double z)
{
return 0;
}
}

View File

@@ -27,8 +27,8 @@
//
package com.volmit.iris.noise;
import javax.vecmath.Vector2f;
import javax.vecmath.Vector3f;
import com.volmit.iris.util.vec.Vector2f;
import com.volmit.iris.util.vec.Vector3f;
public class FastNoise
{

View File

@@ -675,4 +675,12 @@ public class KList<T> extends ArrayList<T> implements List<T>
m.addAll(v);
return m;
}
public void addIfMissing(T t)
{
if(!contains(t))
{
add(t);
}
}
}

View File

@@ -0,0 +1,149 @@
package com.volmit.iris.util;
import java.util.ArrayList;
import java.util.List;
public enum NMSVersion
{
R1_16,
R1_15,
R1_14,
R1_13,
R1_13_1,
R1_12,
R1_11,
R1_10,
R1_9_4,
R1_9_2,
R1_8;
public List<NMSVersion> getAboveInclusive()
{
List<NMSVersion> n = new ArrayList<>();
for(NMSVersion i : values())
{
if(i.ordinal() >= ordinal())
{
n.add(i);
}
}
return n;
}
public List<NMSVersion> betweenInclusive(NMSVersion other)
{
List<NMSVersion> n = new ArrayList<>();
for(NMSVersion i : values())
{
if(i.ordinal() <= Math.max(other.ordinal(), ordinal()) && i.ordinal() >= Math.min(ordinal(), other.ordinal()))
{
n.add(i);
}
}
return n;
}
public List<NMSVersion> getBelowInclusive()
{
List<NMSVersion> n = new ArrayList<>();
for(NMSVersion i : values())
{
if(i.ordinal() <= ordinal())
{
n.add(i);
}
}
return n;
}
public static NMSVersion getMinimum()
{
return values()[values().length - 1];
}
public static NMSVersion getMaximum()
{
return values()[0];
}
public static NMSVersion current()
{
if(tryVersion("1_8_R3"))
{
return R1_8;
}
if(tryVersion("1_9_R1"))
{
return R1_9_2;
}
if(tryVersion("1_9_R2"))
{
return R1_9_4;
}
if(tryVersion("1_10_R1"))
{
return R1_10;
}
if(tryVersion("1_11_R1"))
{
return R1_11;
}
if(tryVersion("1_12_R1"))
{
return R1_12;
}
if(tryVersion("1_13_R1"))
{
return R1_13;
}
if(tryVersion("1_13_R2"))
{
return R1_13_1;
}
if(tryVersion("1_14_R1"))
{
return R1_14;
}
if(tryVersion("1_15_R1"))
{
return R1_15;
}
if(tryVersion("1_16_R1"))
{
return R1_16;
}
return null;
}
private static boolean tryVersion(String v)
{
try
{
Class.forName("org.bukkit.craftbukkit.v" + v + ".CraftWorld");
return true;
}
catch(Throwable e)
{
}
return false;
}
}

View File

@@ -171,6 +171,7 @@ public class StructureTemplate implements Listener, IObjectPlacer
for(String k : j.getObjects())
{
int v = hijacked.getForceObjects().size() + 1;
Iris.globaldata.dump();
IrisObject o = Iris.globaldata.getObjectLoader().load(k).copy();
String b = o.getLoadKey();
o.setLoadKey(realType + "-" + v);
@@ -464,7 +465,13 @@ public class StructureTemplate implements Listener, IObjectPlacer
Location center = getTileBounds(l).getCenter();
TileResult r = structure.getTile(rng, center.getX(), center.getY(), center.getZ());
if(r == null || !r.getTile().getForceObjects().get(getVariant(getTileBounds(l), r.getTile())).getLoadKey().equals(tileType.getForceObjects().get(getVariant(getTileBounds(l), r.getTile())).getLoadKey()))
int v1 = getVariant(getTileBounds(l), r.getTile());
int v2 = getVariant(getTileBounds(l), tileType);
if(r == null || !r.getTile().getForceObjects().get(v1).getLoadKey().equals(
tileType.getForceObjects().get(v2)
.getLoadKey()))
{
continue;
}

View File

@@ -0,0 +1,194 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 3 element point that is represented by double precision floating point
* x,y,z coordinates.
*
*/
public class Point3d extends Tuple3d implements java.io.Serializable {
// Compatible with 1.1
static final long serialVersionUID = 5718062286069042927L;
/**
* Constructs and initializes a Point3d from the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public Point3d(double x, double y, double z)
{
super(x,y,z);
}
/**
* Constructs and initializes a Point3d from the array of length 3.
* @param p the array of length 3 containing xyz in order
*/
public Point3d(double[] p)
{
super(p);
}
/**
* Constructs and initializes a Point3d from the specified Point3d.
* @param p1 the Point3d containing the initialization x y z data
*/
public Point3d(Point3d p1)
{
super(p1);
}
/**
* Constructs and initializes a Point3d from the specified Point3f.
* @param p1 the Point3f containing the initialization x y z data
*/
public Point3d(Point3f p1)
{
super(p1);
}
/**
* Constructs and initializes a Point3d from the specified Tuple3f.
* @param t1 the Tuple3f containing the initialization x y z data
*/
public Point3d(Tuple3f t1)
{
super(t1);
}
/**
* Constructs and initializes a Point3d from the specified Tuple3d.
* @param t1 the Tuple3d containing the initialization x y z data
*/
public Point3d(Tuple3d t1)
{
super(t1);
}
/**
* Constructs and initializes a Point3d to (0,0,0).
*/
public Point3d()
{
super();
}
/**
* Returns the square of the distance between this point and point p1.
* @param p1 the other point
* @return the square of the distance
*/
public final double distanceSquared(Point3d p1)
{
double dx, dy, dz;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
return (dx*dx+dy*dy+dz*dz);
}
/**
* Returns the distance between this point and point p1.
* @param p1 the other point
* @return the distance
*/
public final double distance(Point3d p1)
{
double dx, dy, dz;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
return Math.sqrt(dx*dx+dy*dy+dz*dz);
}
/**
* Computes the L-1 (Manhattan) distance between this point and
* point p1. The L-1 distance is equal to:
* abs(x1-x2) + abs(y1-y2) + abs(z1-z2).
* @param p1 the other point
* @return the L-1 distance
*/
public final double distanceL1(Point3d p1) {
return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) +
Math.abs(this.z-p1.z);
}
/**
* Computes the L-infinite distance between this point and
* point p1. The L-infinite distance is equal to
* MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)].
* @param p1 the other point
* @return the L-infinite distance
*/
public final double distanceLinf(Point3d p1) {
double tmp;
tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
return Math.max(tmp,Math.abs(this.z-p1.z));
}
/**
* Multiplies each of the x,y,z components of the Point4d parameter
* by 1/w and places the projected values into this point.
* @param p1 the source Point4d, which is not modified
*/
public final void project(Point4d p1)
{
double oneOw;
oneOw = 1/p1.w;
x = p1.x*oneOw;
y = p1.y*oneOw;
z = p1.z*oneOw;
}
}

View File

@@ -0,0 +1,197 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 3 element point that is represented by single precision floating point
* x,y,z coordinates.
*
*/
public class Point3f extends Tuple3f implements java.io.Serializable {
// Compatible with 1.1
static final long serialVersionUID = -8689337816398030143L;
/**
* Constructs and initializes a Point3f from the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public Point3f(float x, float y, float z)
{
super(x,y,z);
}
/**
* Constructs and initializes a Point3f from the array of length 3.
* @param p the array of length 3 containing xyz in order
*/
public Point3f(float[] p)
{
super(p);
}
/**
* Constructs and initializes a Point3f from the specified Point3f.
* @param p1 the Point3f containing the initialization x y z data
*/
public Point3f(Point3f p1)
{
super(p1);
}
/**
* Constructs and initializes a Point3f from the specified Point3d.
* @param p1 the Point3d containing the initialization x y z data
*/
public Point3f(Point3d p1)
{
super(p1);
}
/**
* Constructs and initializes a Point3f from the specified Tuple3f.
* @param t1 the Tuple3f containing the initialization x y z data
*/
public Point3f(Tuple3f t1)
{
super(t1);
}
/**
* Constructs and initializes a Point3f from the specified Tuple3d.
* @param t1 the Tuple3d containing the initialization x y z data
*/
public Point3f(Tuple3d t1)
{
super(t1);
}
/**
* Constructs and initializes a Point3f to (0,0,0).
*/
public Point3f()
{
super();
}
/**
* Computes the square of the distance between this point and
* point p1.
* @param p1 the other point
* @return the square of the distance
*/
public final float distanceSquared(Point3f p1)
{
float dx, dy, dz;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
return dx*dx+dy*dy+dz*dz;
}
/**
* Computes the distance between this point and point p1.
* @param p1 the other point
* @return the distance
*/
public final float distance(Point3f p1)
{
float dx, dy, dz;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
return (float) Math.sqrt(dx*dx+dy*dy+dz*dz);
}
/**
* Computes the L-1 (Manhattan) distance between this point and
* point p1. The L-1 distance is equal to:
* abs(x1-x2) + abs(y1-y2) + abs(z1-z2).
* @param p1 the other point
* @return the L-1 distance
*/
public final float distanceL1(Point3f p1)
{
return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z));
}
/**
* Computes the L-infinite distance between this point and
* point p1. The L-infinite distance is equal to
* MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)].
* @param p1 the other point
* @return the L-infinite distance
*/
public final float distanceLinf(Point3f p1)
{
float tmp;
tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
return(Math.max(tmp,Math.abs(this.z-p1.z)));
}
/**
* Multiplies each of the x,y,z components of the Point4f parameter
* by 1/w and places the projected values into this point.
* @param p1 the source Point4f, which is not modified
*/
public final void project(Point4f p1)
{
float oneOw;
oneOw = 1/p1.w;
x = p1.x*oneOw;
y = p1.y*oneOw;
z = p1.z*oneOw;
}
}

View File

@@ -0,0 +1,229 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 4 element vector represented by double precision floating point
* x,y,z,w coordinates.
*
*/
public class Point4d extends Tuple4d implements java.io.Serializable {
// Compatible with 1.1
static final long serialVersionUID = 1733471895962736949L;
/**
* Constructs and initializes a Point4d from the specified xyzw coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param w the w coordinate
*/
public Point4d(double x, double y, double z, double w)
{
super(x,y,z,w);
}
/**
* Constructs and initializes a Point4d from the coordinates contained
* in the array.
* @param p the array of length 4 containing xyzw in order
*/
public Point4d(double[] p)
{
super(p);
}
/**
* Constructs and initializes a Point4d from the specified Point4d.
* @param p1 the Point4d containing the initialization x y z w data
*/
public Point4d(Point4d p1)
{
super(p1);
}
/**
* Constructs and initializes a Point4d from the specified Point4f.
* @param p1 the Point4f containing the initialization x y z w data
*/
public Point4d(Point4f p1)
{
super(p1);
}
/**
* Constructs and initializes a Point4d from the specified Tuple4f.
* @param t1 the Tuple4f containing the initialization x y z w data
*/
public Point4d(Tuple4f t1)
{
super(t1);
}
/**
* Constructs and initializes a Point4d from the specified Tuple4d.
* @param t1 the Tuple4d containing the initialization x y z w data
*/
public Point4d(Tuple4d t1)
{
super(t1);
}
/**
* Constructs and initializes a Point4d from the specified Tuple3d.
* The x,y,z components of this point are set to the corresponding
* components of tuple t1. The w component of this point
* is set to 1.
* @param t1 the tuple to be copied
*
* @since vecmath 1.2
*/
public Point4d(Tuple3d t1) {
super(t1.x, t1.y, t1.z, 1.0);
}
/**
* Constructs and initializes a Point4d to (0,0,0,0).
*/
public Point4d()
{
super();
}
/**
* Sets the x,y,z components of this point to the corresponding
* components of tuple t1. The w component of this point
* is set to 1.
* @param t1 the tuple to be copied
*
* @since vecmath 1.2
*/
public final void set(Tuple3d t1) {
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = 1.0;
}
/**
* Returns the square of the distance between this point and point p1.
* @param p1 the first point
* @return the square of distance between this point and point p1
*/
public final double distanceSquared(Point4d p1)
{
double dx, dy, dz, dw;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
dw = this.w-p1.w;
return (dx*dx+dy*dy+dz*dz+dw*dw);
}
/**
* Returns the distance between this point and point p1.
* @param p1 the first point
* @return the distance between these this point and point p1.
*/
public final double distance(Point4d p1)
{
double dx, dy, dz, dw;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
dw = this.w-p1.w;
return Math.sqrt(dx*dx+dy*dy+dz*dz+dw*dw);
}
/**
* Computes the L-1 (Manhattan) distance between this point and
* point p1. The L-1 distance is equal to:
* abs(x1-x2) + abs(y1-y2) + abs(z1-z2) + abs(w1-w2).
* @param p1 the other point
* @return the L-1 distance
*/
public final double distanceL1(Point4d p1) {
return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) +
Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w);
}
/**
* Computes the L-infinite distance between this point and
* point p1. The L-infinite distance is equal to
* MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)].
* @param p1 the other point
* @return the L-infinite distance
*/
public final double distanceLinf(Point4d p1) {
double t1, t2;
t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w));
return Math.max(t1,t2);
}
/**
* Multiplies each of the x,y,z components of the Point4d parameter
* by 1/w, places the projected values into this point, and places
* a 1 as the w parameter of this point.
* @param p1 the source Point4d, which is not modified
*/
public final void project(Point4d p1)
{
double oneOw;
oneOw = 1/p1.w;
x = p1.x*oneOw;
y = p1.y*oneOw;
z = p1.z*oneOw;
w = 1.0;
}
}

View File

@@ -0,0 +1,231 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 4 element point represented by single precision floating point x,y,z,w
* coordinates.
*
*/
public class Point4f extends Tuple4f implements java.io.Serializable {
// Compatible with 1.1
static final long serialVersionUID = 4643134103185764459L;
/**
* Constructs and initializes a Point4f from the specified xyzw coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param w the w coordinate
*/
public Point4f(float x, float y, float z, float w)
{
super(x,y,z,w);
}
/**
* Constructs and initializes a Point4f from the array of length 4.
* @param p the array of length 4 containing xyzw in order
*/
public Point4f(float[] p)
{
super(p);
}
/**
* Constructs and initializes a Point4f from the specified Point4f.
* @param p1 the Point4f containing the initialization x y z w data
*/
public Point4f(Point4f p1)
{
super(p1);
}
/**
* Constructs and initializes a Point4f from the specified Point4d.
* @param p1 the Point4d containing the initialization x y z w data
*/
public Point4f(Point4d p1)
{
super(p1);
}
/**
* Constructs and initializes a Point4f from the specified Tuple4f.
* @param t1 the Tuple4f containing the initialization x y z w data
*/
public Point4f(Tuple4f t1)
{
super(t1);
}
/**
* Constructs and initializes a Point4f from the specified Tuple4d.
* @param t1 the Tuple4d containing the initialization x y z w data
*/
public Point4f(Tuple4d t1)
{
super(t1);
}
/**
* Constructs and initializes a Point4f from the specified Tuple3f.
* The x,y,z components of this point are set to the corresponding
* components of tuple t1. The w component of this point
* is set to 1.
* @param t1 the tuple to be copied
*
* @since vecmath 1.2
*/
public Point4f(Tuple3f t1) {
super(t1.x, t1.y, t1.z, 1.0f);
}
/**
* Constructs and initializes a Point4f to (0,0,0,0).
*/
public Point4f()
{
super();
}
/**
* Sets the x,y,z components of this point to the corresponding
* components of tuple t1. The w component of this point
* is set to 1.
* @param t1 the tuple to be copied
*
* @since vecmath 1.2
*/
public final void set(Tuple3f t1) {
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = 1.0f;
}
/**
* Computes the square of the distance between this point and point p1.
* @param p1 the other point
* @return the square of distance between these two points as a float
*/
public final float distanceSquared(Point4f p1)
{
float dx, dy, dz, dw;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
dw = this.w-p1.w;
return (dx*dx+dy*dy+dz*dz+dw*dw);
}
/**
* Computes the distance between this point and point p1.
* @param p1 the other point
* @return the distance between the two points
*/
public final float distance(Point4f p1)
{
float dx, dy, dz, dw;
dx = this.x-p1.x;
dy = this.y-p1.y;
dz = this.z-p1.z;
dw = this.w-p1.w;
return (float) Math.sqrt(dx*dx+dy*dy+dz*dz+dw*dw);
}
/**
* Computes the L-1 (Manhattan) distance between this point and
* point p1. The L-1 distance is equal to:
* abs(x1-x2) + abs(y1-y2) + abs(z1-z2) + abs(w1-w2).
* @param p1 the other point
* @return the L-1 distance
*/
public final float distanceL1(Point4f p1)
{
return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w));
}
/**
* Computes the L-infinite distance between this point and
* point p1. The L-infinite distance is equal to
* MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)].
* @param p1 the other point
* @return the L-infinite distance
*/
public final float distanceLinf(Point4f p1)
{
float t1, t2;
t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y));
t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w));
return(Math.max(t1,t2));
}
/**
* Multiplies each of the x,y,z components of the Point4f parameter
* by 1/w, places the projected values into this point, and places
* a 1 as the w parameter of this point.
* @param p1 the source Point4f, which is not modified
*/
public final void project(Point4f p1)
{
float oneOw;
oneOw = 1/p1.w;
x = p1.x*oneOw;
y = p1.y*oneOw;
z = p1.z*oneOw;
w = 1.0f;
}
}

View File

@@ -0,0 +1,606 @@
/*
* $RCSfile$
*
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A generic 2-element tuple that is represented by double-precision
* floating point x,y coordinates.
*
*/
public abstract class Tuple2d implements java.io.Serializable, Cloneable {
static final long serialVersionUID = 6205762482756093838L;
/**
* The x coordinate.
*/
public double x;
/**
* The y coordinate.
*/
public double y;
/**
* Constructs and initializes a Tuple2d from the specified xy coordinates.
* @param x the x coordinate
* @param y the y coordinate
*/
public Tuple2d(double x, double y)
{
this.x = x;
this.y = y;
}
/**
* Constructs and initializes a Tuple2d from the specified array.
* @param t the array of length 2 containing xy in order
*/
public Tuple2d(double[] t)
{
this.x = t[0];
this.y = t[1];
}
/**
* Constructs and initializes a Tuple2d from the specified Tuple2d.
* @param t1 the Tuple2d containing the initialization x y data
*/
public Tuple2d(Tuple2d t1)
{
this.x = t1.x;
this.y = t1.y;
}
/**
* Constructs and initializes a Tuple2d from the specified Tuple2f.
* @param t1 the Tuple2f containing the initialization x y data
*/
public Tuple2d(Tuple2f t1)
{
this.x = (double) t1.x;
this.y = (double) t1.y;
}
/**
* Constructs and initializes a Tuple2d to (0,0).
*/
public Tuple2d()
{
this.x = 0.0;
this.y = 0.0;
}
/**
* Sets the value of this tuple to the specified xy coordinates.
* @param x the x coordinate
* @param y the y coordinate
*/
public final void set(double x, double y)
{
this.x = x;
this.y = y;
}
/**
* Sets the value of this tuple from the 2 values specified in
* the array.
* @param t the array of length 2 containing xy in order
*/
public final void set(double[] t)
{
this.x = t[0];
this.y = t[1];
}
/**
* Sets the value of this tuple to the value of the Tuple2d argument.
* @param t1 the tuple to be copied
*/
public final void set(Tuple2d t1)
{
this.x = t1.x;
this.y = t1.y;
}
/**
* Sets the value of this tuple to the value of Tuple2f t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple2f t1)
{
this.x = (double) t1.x;
this.y = (double) t1.y;
}
/**
* Copies the value of the elements of this tuple into the array t.
* @param t the array that will contain the values of the vector
*/
public final void get(double[] t)
{
t[0] = this.x;
t[1] = this.y;
}
/**
* Sets the value of this tuple to the vector sum of tuples t1 and t2.
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void add(Tuple2d t1, Tuple2d t2)
{
this.x = t1.x + t2.x;
this.y = t1.y + t2.y;
}
/**
* Sets the value of this tuple to the vector sum of itself and tuple t1.
* @param t1 the other tuple
*/
public final void add(Tuple2d t1)
{
this.x += t1.x;
this.y += t1.y;
}
/**
* Sets the value of this tuple to the vector difference of
* tuple t1 and t2 (this = t1 - t2).
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void sub(Tuple2d t1, Tuple2d t2)
{
this.x = t1.x - t2.x;
this.y = t1.y - t2.y;
}
/**
* Sets the value of this tuple to the vector difference of
* itself and tuple t1 (this = this - t1).
* @param t1 the other vector
*/
public final void sub(Tuple2d t1)
{
this.x -= t1.x;
this.y -= t1.y;
}
/**
* Sets the value of this tuple to the negation of tuple t1.
* @param t1 the source vector
*/
public final void negate(Tuple2d t1)
{
this.x = -t1.x;
this.y = -t1.y;
}
/**
* Negates the value of this vector in place.
*/
public final void negate()
{
this.x = -this.x;
this.y = -this.y;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1.
* @param s the scalar value
* @param t1 the source tuple
*/
public final void scale(double s, Tuple2d t1)
{
this.x = s*t1.x;
this.y = s*t1.y;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself.
* @param s the scalar value
*/
public final void scale(double s)
{
this.x *= s;
this.y *= s;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1 and then adds tuple t2 (this = s*t1 + t2).
* @param s the scalar value
* @param t1 the tuple to be multipled
* @param t2 the tuple to be added
*/
public final void scaleAdd(double s, Tuple2d t1, Tuple2d t2)
{
this.x = s*t1.x + t2.x;
this.y = s*t1.y + t2.y;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself and then adds tuple t1 (this = s*this + t1).
* @param s the scalar value
* @param t1 the tuple to be added
*/
public final void scaleAdd(double s, Tuple2d t1)
{
this.x = s*this.x + t1.x;
this.y = s*this.y + t1.y;
}
/**
* Returns a hash code value based on the data values in this
* object. Two different Tuple2d objects with identical data values
* (i.e., Tuple2d.equals returns true) will return the same hash
* code value. Two objects with different data members may return the
* same hash value, although this is not likely.
* @return the integer hash code value
*/
public int hashCode() {
long bits = 1L;
bits = 31L * bits + VecMathUtil.doubleToLongBits(x);
bits = 31L * bits + VecMathUtil.doubleToLongBits(y);
return (int) (bits ^ (bits >> 32));
}
/**
* Returns true if all of the data members of Tuple2d t1 are
* equal to the corresponding data members in this Tuple2d.
* @param t1 the vector with which the comparison is made
* @return true or false
*/
public boolean equals(Tuple2d t1)
{
try {
return(this.x == t1.x && this.y == t1.y);
}
catch (NullPointerException e2) {return false;}
}
/**
* Returns true if the Object t1 is of type Tuple2d and all of the
* data members of t1 are equal to the corresponding data members in
* this Tuple2d.
* @param t1 the object with which the comparison is made
* @return true or false
*/
public boolean equals(Object t1)
{
try {
Tuple2d t2 = (Tuple2d) t1;
return(this.x == t2.x && this.y == t2.y);
}
catch (NullPointerException e2) {return false;}
catch (ClassCastException e1) {return false;}
}
/**
* Returns true if the L-infinite distance between this tuple
* and tuple t1 is less than or equal to the epsilon parameter,
* otherwise returns false. The L-infinite
* distance is equal to MAX[abs(x1-x2), abs(y1-y2)].
* @param t1 the tuple to be compared to this tuple
* @param epsilon the threshold value
* @return true or false
*/
public boolean epsilonEquals(Tuple2d t1, double epsilon)
{
double diff;
diff = x - t1.x;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = y - t1.y;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
return true;
}
/**
* Returns a string that contains the values of this Tuple2d.
* The form is (x,y).
* @return the String representation
*/
public String toString()
{
return("(" + this.x + ", " + this.y + ")");
}
/**
* Clamps the tuple parameter to the range [low, high] and
* places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clamp(double min, double max, Tuple2d t)
{
if( t.x > max ) {
x = max;
} else if( t.x < min ){
x = min;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else if( t.y < min ){
y = min;
} else {
y = t.y;
}
}
/**
* Clamps the minimum value of the tuple parameter to the min
* parameter and places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMin(double min, Tuple2d t)
{
if( t.x < min ) {
x = min;
} else {
x = t.x;
}
if( t.y < min ) {
y = min;
} else {
y = t.y;
}
}
/**
* Clamps the maximum value of the tuple parameter to the max
* parameter and places the values into this tuple.
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMax(double max, Tuple2d t)
{
if( t.x > max ) {
x = max;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else {
y = t.y;
}
}
/**
* Sets each component of the tuple parameter to its absolute
* value and places the modified values into this tuple.
* @param t the source tuple, which will not be modified
*/
public final void absolute(Tuple2d t)
{
x = Math.abs(t.x);
y = Math.abs(t.y);
}
/**
* Clamps this tuple to the range [low, high].
* @param min the lowest value in this tuple after clamping
* @param max the highest value in this tuple after clamping
*/
public final void clamp(double min, double max)
{
if( x > max ) {
x = max;
} else if( x < min ){
x = min;
}
if( y > max ) {
y = max;
} else if( y < min ){
y = min;
}
}
/**
* Clamps the minimum value of this tuple to the min parameter.
* @param min the lowest value in this tuple after clamping
*/
public final void clampMin(double min)
{
if( x < min ) x=min;
if( y < min ) y=min;
}
/**
* Clamps the maximum value of this tuple to the max parameter.
* @param max the highest value in the tuple after clamping
*/
public final void clampMax(double max)
{
if( x > max ) x=max;
if( y > max ) y=max;
}
/**
* Sets each component of this tuple to its absolute value.
*/
public final void absolute()
{
x = Math.abs(x);
y = Math.abs(y);
}
/**
* Linearly interpolates between tuples t1 and t2 and places the
* result into this tuple: this = (1-alpha)*t1 + alpha*t2.
* @param t1 the first tuple
* @param t2 the second tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple2d t1, Tuple2d t2, double alpha)
{
this.x = (1-alpha)*t1.x + alpha*t2.x;
this.y = (1-alpha)*t1.y + alpha*t2.y;
}
/**
* Linearly interpolates between this tuple and tuple t1 and
* places the result into this tuple: this = (1-alpha)*this + alpha*t1.
* @param t1 the first tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple2d t1, double alpha)
{
this.x = (1-alpha)*this.x + alpha*t1.x;
this.y = (1-alpha)*this.y + alpha*t1.y;
}
/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
/**
* Get the <i>x</i> coordinate.
*
* @return the <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getX() {
return x;
}
/**
* Set the <i>x</i> coordinate.
*
* @param x value to <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setX(double x) {
this.x = x;
}
/**
* Get the <i>y</i> coordinate.
*
* @return the <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getY() {
return y;
}
/**
* Set the <i>y</i> coordinate.
*
* @param y value to <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setY(double y) {
this.y = y;
}
}

View File

@@ -0,0 +1,609 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A generic 2-element tuple that is represented by single-precision
* floating point x,y coordinates.
*
*/
public abstract class Tuple2f implements java.io.Serializable, Cloneable {
static final long serialVersionUID = 9011180388985266884L;
/**
* The x coordinate.
*/
public float x;
/**
* The y coordinate.
*/
public float y;
/**
* Constructs and initializes a Tuple2f from the specified xy coordinates.
* @param x the x coordinate
* @param y the y coordinate
*/
public Tuple2f(float x, float y)
{
this.x = x;
this.y = y;
}
/**
* Constructs and initializes a Tuple2f from the specified array.
* @param t the array of length 2 containing xy in order
*/
public Tuple2f(float[] t)
{
this.x = t[0];
this.y = t[1];
}
/**
* Constructs and initializes a Tuple2f from the specified Tuple2f.
* @param t1 the Tuple2f containing the initialization x y data
*/
public Tuple2f(Tuple2f t1)
{
this.x = t1.x;
this.y = t1.y;
}
/**
* Constructs and initializes a Tuple2f from the specified Tuple2d.
* @param t1 the Tuple2d containing the initialization x y data
*/
public Tuple2f(Tuple2d t1)
{
this.x = (float) t1.x;
this.y = (float) t1.y;
}
/**
* Constructs and initializes a Tuple2f to (0,0).
*/
public Tuple2f()
{
this.x = (float) 0.0;
this.y = (float) 0.0;
}
/**
* Sets the value of this tuple to the specified xy coordinates.
* @param x the x coordinate
* @param y the y coordinate
*/
public final void set(float x, float y)
{
this.x = x;
this.y = y;
}
/**
* Sets the value of this tuple from the 2 values specified in
* the array.
* @param t the array of length 2 containing xy in order
*/
public final void set(float[] t)
{
this.x = t[0];
this.y = t[1];
}
/**
* Sets the value of this tuple to the value of the Tuple2f argument.
* @param t1 the tuple to be copied
*/
public final void set(Tuple2f t1)
{
this.x = t1.x;
this.y = t1.y;
}
/**
* Sets the value of this tuple to the value of the Tuple2d argument.
* @param t1 the tuple to be copied
*/
public final void set(Tuple2d t1)
{
this.x = (float) t1.x;
this.y = (float) t1.y;
}
/**
* Copies the value of the elements of this tuple into the array t.
* @param t the array that will contain the values of the vector
*/
public final void get(float[] t)
{
t[0] = this.x;
t[1] = this.y;
}
/**
* Sets the value of this tuple to the vector sum of tuples t1 and t2.
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void add(Tuple2f t1, Tuple2f t2)
{
this.x = t1.x + t2.x;
this.y = t1.y + t2.y;
}
/**
* Sets the value of this tuple to the vector sum of itself and tuple t1.
* @param t1 the other tuple
*/
public final void add(Tuple2f t1)
{
this.x += t1.x;
this.y += t1.y;
}
/**
* Sets the value of this tuple to the vector difference of
* tuple t1 and t2 (this = t1 - t2).
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void sub(Tuple2f t1, Tuple2f t2)
{
this.x = t1.x - t2.x;
this.y = t1.y - t2.y;
}
/**
* Sets the value of this tuple to the vector difference of
* itself and tuple t1 (this = this - t1).
* @param t1 the other tuple
*/
public final void sub(Tuple2f t1)
{
this.x -= t1.x;
this.y -= t1.y;
}
/**
* Sets the value of this tuple to the negation of tuple t1.
* @param t1 the source tuple
*/
public final void negate(Tuple2f t1)
{
this.x = -t1.x;
this.y = -t1.y;
}
/**
* Negates the value of this vector in place.
*/
public final void negate()
{
this.x = -this.x;
this.y = -this.y;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1.
* @param s the scalar value
* @param t1 the source tuple
*/
public final void scale(float s, Tuple2f t1)
{
this.x = s*t1.x;
this.y = s*t1.y;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself.
* @param s the scalar value
*/
public final void scale(float s)
{
this.x *= s;
this.y *= s;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1 and then adds tuple t2 (this = s*t1 + t2).
* @param s the scalar value
* @param t1 the tuple to be multipled
* @param t2 the tuple to be added
*/
public final void scaleAdd(float s, Tuple2f t1, Tuple2f t2)
{
this.x = s*t1.x + t2.x;
this.y = s*t1.y + t2.y;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself and then adds tuple t1 (this = s*this + t1).
* @param s the scalar value
* @param t1 the tuple to be added
*/
public final void scaleAdd(float s, Tuple2f t1)
{
this.x = s*this.x + t1.x;
this.y = s*this.y + t1.y;
}
/**
* Returns a hash code value based on the data values in this
* object. Two different Tuple2f objects with identical data values
* (i.e., Tuple2f.equals returns true) will return the same hash
* code value. Two objects with different data members may return the
* same hash value, although this is not likely.
* @return the integer hash code value
*/
public int hashCode() {
long bits = 1L;
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(x);
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(y);
return (int) (bits ^ (bits >> 32));
}
/**
* Returns true if all of the data members of Tuple2f t1 are
* equal to the corresponding data members in this Tuple2f.
* @param t1 the vector with which the comparison is made
* @return true or false
*/
public boolean equals(Tuple2f t1)
{
try {
return(this.x == t1.x && this.y == t1.y);
}
catch (NullPointerException e2) {return false;}
}
/**
* Returns true if the Object t1 is of type Tuple2f and all of the
* data members of t1 are equal to the corresponding data members in
* this Tuple2f.
* @param t1 the object with which the comparison is made
* @return true or false
*/
public boolean equals(Object t1)
{
try {
Tuple2f t2 = (Tuple2f) t1;
return(this.x == t2.x && this.y == t2.y);
}
catch (NullPointerException e2) {return false;}
catch (ClassCastException e1) {return false;}
}
/**
* Returns true if the L-infinite distance between this tuple
* and tuple t1 is less than or equal to the epsilon parameter,
* otherwise returns false. The L-infinite
* distance is equal to MAX[abs(x1-x2), abs(y1-y2)].
* @param t1 the tuple to be compared to this tuple
* @param epsilon the threshold value
* @return true or false
*/
public boolean epsilonEquals(Tuple2f t1, float epsilon)
{
float diff;
diff = x - t1.x;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = y - t1.y;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
return true;
}
/**
* Returns a string that contains the values of this Tuple2f.
* The form is (x,y).
* @return the String representation
*/
public String toString()
{
return("(" + this.x + ", " + this.y + ")");
}
/**
* Clamps the tuple parameter to the range [low, high] and
* places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clamp(float min, float max, Tuple2f t)
{
if( t.x > max ) {
x = max;
} else if( t.x < min ){
x = min;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else if( t.y < min ){
y = min;
} else {
y = t.y;
}
}
/**
* Clamps the minimum value of the tuple parameter to the min
* parameter and places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMin(float min, Tuple2f t)
{
if( t.x < min ) {
x = min;
} else {
x = t.x;
}
if( t.y < min ) {
y = min;
} else {
y = t.y;
}
}
/**
* Clamps the maximum value of the tuple parameter to the max
* parameter and places the values into this tuple.
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMax(float max, Tuple2f t)
{
if( t.x > max ) {
x = max;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else {
y = t.y;
}
}
/**
* Sets each component of the tuple parameter to its absolute
* value and places the modified values into this tuple.
* @param t the source tuple, which will not be modified
*/
public final void absolute(Tuple2f t)
{
x = Math.abs(t.x);
y = Math.abs(t.y);
}
/**
* Clamps this tuple to the range [low, high].
* @param min the lowest value in this tuple after clamping
* @param max the highest value in this tuple after clamping
*/
public final void clamp(float min, float max)
{
if( x > max ) {
x = max;
} else if( x < min ){
x = min;
}
if( y > max ) {
y = max;
} else if( y < min ){
y = min;
}
}
/**
* Clamps the minimum value of this tuple to the min parameter.
* @param min the lowest value in this tuple after clamping
*/
public final void clampMin(float min)
{
if( x < min ) x=min;
if( y < min ) y=min;
}
/**
* Clamps the maximum value of this tuple to the max parameter.
* @param max the highest value in the tuple after clamping
*/
public final void clampMax(float max)
{
if( x > max ) x=max;
if( y > max ) y=max;
}
/**
* Sets each component of this tuple to its absolute value.
*/
public final void absolute()
{
x = Math.abs(x);
y = Math.abs(y);
}
/**
* Linearly interpolates between tuples t1 and t2 and places the
* result into this tuple: this = (1-alpha)*t1 + alpha*t2.
* @param t1 the first tuple
* @param t2 the second tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple2f t1, Tuple2f t2, float alpha)
{
this.x = (1-alpha)*t1.x + alpha*t2.x;
this.y = (1-alpha)*t1.y + alpha*t2.y;
}
/**
* Linearly interpolates between this tuple and tuple t1 and
* places the result into this tuple: this = (1-alpha)*this + alpha*t1.
* @param t1 the first tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple2f t1, float alpha)
{
this.x = (1-alpha)*this.x + alpha*t1.x;
this.y = (1-alpha)*this.y + alpha*t1.y;
}
/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
/**
* Get the <i>x</i> coordinate.
*
* @return the <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getX() {
return x;
}
/**
* Set the <i>x</i> coordinate.
*
* @param x value to <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setX(float x) {
this.x = x;
}
/**
* Get the <i>y</i> coordinate.
*
* @return the <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getY() {
return y;
}
/**
* Set the <i>y</i> coordinate.
*
* @param y value to <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setY(float y) {
this.y = y;
}
}

View File

@@ -0,0 +1,758 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A generic 3-element tuple that is represented by double-precision
* floating point x,y,z coordinates.
*
*/
public abstract class Tuple3d implements java.io.Serializable, Cloneable {
static final long serialVersionUID = 5542096614926168415L;
/**
* The x coordinate.
*/
public double x;
/**
* The y coordinate.
*/
public double y;
/**
* The z coordinate.
*/
public double z;
/**
* Constructs and initializes a Tuple3d from the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public Tuple3d(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
/**
* Constructs and initializes a Tuple3d from the array of length 3.
* @param t the array of length 3 containing xyz in order
*/
public Tuple3d(double[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
}
/**
* Constructs and initializes a Tuple3d from the specified Tuple3d.
* @param t1 the Tuple3d containing the initialization x y z data
*/
public Tuple3d(Tuple3d t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
}
/**
* Constructs and initializes a Tuple3d from the specified Tuple3f.
* @param t1 the Tuple3f containing the initialization x y z data
*/
public Tuple3d(Tuple3f t1)
{
this.x = (double) t1.x;
this.y = (double) t1.y;
this.z = (double) t1.z;
}
/**
* Constructs and initializes a Tuple3d to (0,0,0).
*/
public Tuple3d()
{
this.x = (double) 0.0;
this.y = (double) 0.0;
this.z = (double) 0.0;
}
/**
* Sets the value of this tuple to the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public final void set(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
/**
* Sets the value of this tuple to the value of the xyz coordinates
* located in the array of length 3.
* @param t the array of length 3 containing xyz in order
*/
public final void set(double[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple3d t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple3f t1)
{
this.x = (double) t1.x;
this.y = (double) t1.y;
this.z = (double) t1.z;
}
/**
* Copies the x,y,z coordinates of this tuple into the array t
* of length 3.
* @param t the target array
*/
public final void get(double[] t)
{
t[0] = this.x;
t[1] = this.y;
t[2] = this.z;
}
/**
* Copies the x,y,z coordinates of this tuple into the tuple t.
* @param t the Tuple3d object into which the values of this object are copied
*/
public final void get(Tuple3d t)
{
t.x = this.x;
t.y = this.y;
t.z = this.z;
}
/**
* Sets the value of this tuple to the sum of tuples t1 and t2.
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void add(Tuple3d t1, Tuple3d t2)
{
this.x = t1.x + t2.x;
this.y = t1.y + t2.y;
this.z = t1.z + t2.z;
}
/**
* Sets the value of this tuple to the sum of itself and t1.
* @param t1 the other tuple
*/
public final void add(Tuple3d t1)
{
this.x += t1.x;
this.y += t1.y;
this.z += t1.z;
}
/**
* Sets the value of this tuple to the difference of tuples
* t1 and t2 (this = t1 - t2).
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void sub(Tuple3d t1, Tuple3d t2)
{
this.x = t1.x - t2.x;
this.y = t1.y - t2.y;
this.z = t1.z - t2.z;
}
/**
* Sets the value of this tuple to the difference
* of itself and t1 (this = this - t1).
* @param t1 the other tuple
*/
public final void sub(Tuple3d t1)
{
this.x -= t1.x;
this.y -= t1.y;
this.z -= t1.z;
}
/**
* Sets the value of this tuple to the negation of tuple t1.
* @param t1 the source tuple
*/
public final void negate(Tuple3d t1)
{
this.x = -t1.x;
this.y = -t1.y;
this.z = -t1.z;
}
/**
* Negates the value of this tuple in place.
*/
public final void negate()
{
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1.
* @param s the scalar value
* @param t1 the source tuple
*/
public final void scale(double s, Tuple3d t1)
{
this.x = s*t1.x;
this.y = s*t1.y;
this.z = s*t1.z;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself.
* @param s the scalar value
*/
public final void scale(double s)
{
this.x *= s;
this.y *= s;
this.z *= s;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1 and then adds tuple t2 (this = s*t1 + t2).
* @param s the scalar value
* @param t1 the tuple to be multipled
* @param t2 the tuple to be added
*/
public final void scaleAdd(double s, Tuple3d t1, Tuple3d t2)
{
this.x = s*t1.x + t2.x;
this.y = s*t1.y + t2.y;
this.z = s*t1.z + t2.z;
}
/**
* @deprecated Use scaleAdd(double,Tuple3d) instead
*/
public final void scaleAdd(double s, Tuple3f t1) {
scaleAdd(s, new Point3d(t1));
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself and then adds tuple t1 (this = s*this + t1).
* @param s the scalar value
* @param t1 the tuple to be added
*/
public final void scaleAdd(double s, Tuple3d t1) {
this.x = s*this.x + t1.x;
this.y = s*this.y + t1.y;
this.z = s*this.z + t1.z;
}
/**
* Returns a string that contains the values of this Tuple3d.
* The form is (x,y,z).
* @return the String representation
*/
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ")";
}
/**
* Returns a hash code value based on the data values in this
* object. Two different Tuple3d objects with identical data values
* (i.e., Tuple3d.equals returns true) will return the same hash
* code value. Two objects with different data members may return the
* same hash value, although this is not likely.
* @return the integer hash code value
*/
public int hashCode() {
long bits = 1L;
bits = 31L * bits + VecMathUtil.doubleToLongBits(x);
bits = 31L * bits + VecMathUtil.doubleToLongBits(y);
bits = 31L * bits + VecMathUtil.doubleToLongBits(z);
return (int) (bits ^ (bits >> 32));
}
/**
* Returns true if all of the data members of Tuple3d t1 are
* equal to the corresponding data members in this Tuple3d.
* @param t1 the tuple with which the comparison is made
* @return true or false
*/
public boolean equals(Tuple3d t1)
{
try {
return(this.x == t1.x && this.y == t1.y && this.z == t1.z);
}
catch (NullPointerException e2) {return false;}
}
/**
* Returns true if the Object t1 is of type Tuple3d and all of the
* data members of t1 are equal to the corresponding data members in
* this Tuple3d.
* @param t1 the Object with which the comparison is made
* @return true or false
*/
public boolean equals(Object t1)
{
try {
Tuple3d t2 = (Tuple3d) t1;
return(this.x == t2.x && this.y == t2.y && this.z == t2.z);
}
catch (ClassCastException e1) {return false;}
catch (NullPointerException e2) {return false;}
}
/**
* Returns true if the L-infinite distance between this tuple
* and tuple t1 is less than or equal to the epsilon parameter,
* otherwise returns false. The L-infinite
* distance is equal to MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)].
* @param t1 the tuple to be compared to this tuple
* @param epsilon the threshold value
* @return true or false
*/
public boolean epsilonEquals(Tuple3d t1, double epsilon)
{
double diff;
diff = x - t1.x;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = y - t1.y;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = z - t1.z;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
return true;
}
/**
* @deprecated Use clamp(double,double,Tuple3d) instead
*/
public final void clamp(float min, float max, Tuple3d t) {
clamp((double)min, (double)max, t);
}
/**
* Clamps the tuple parameter to the range [low, high] and
* places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clamp(double min, double max, Tuple3d t) {
if( t.x > max ) {
x = max;
} else if( t.x < min ){
x = min;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else if( t.y < min ){
y = min;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else if( t.z < min ){
z = min;
} else {
z = t.z;
}
}
/**
* @deprecated Use clampMin(double,Tuple3d) instead
*/
public final void clampMin(float min, Tuple3d t) {
clampMin((double)min, t);
}
/**
* Clamps the minimum value of the tuple parameter to the min
* parameter and places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMin(double min, Tuple3d t) {
if( t.x < min ) {
x = min;
} else {
x = t.x;
}
if( t.y < min ) {
y = min;
} else {
y = t.y;
}
if( t.z < min ) {
z = min;
} else {
z = t.z;
}
}
/**
* @deprecated Use clampMax(double,Tuple3d) instead
*/
public final void clampMax(float max, Tuple3d t) {
clampMax((double)max, t);
}
/**
* Clamps the maximum value of the tuple parameter to the max
* parameter and places the values into this tuple.
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMax(double max, Tuple3d t) {
if( t.x > max ) {
x = max;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else {
z = t.z;
}
}
/**
* Sets each component of the tuple parameter to its absolute
* value and places the modified values into this tuple.
* @param t the source tuple, which will not be modified
*/
public final void absolute(Tuple3d t)
{
x = Math.abs(t.x);
y = Math.abs(t.y);
z = Math.abs(t.z);
}
/**
* @deprecated Use clamp(double,double) instead
*/
public final void clamp(float min, float max) {
clamp((double)min, (double)max);
}
/**
* Clamps this tuple to the range [low, high].
* @param min the lowest value in this tuple after clamping
* @param max the highest value in this tuple after clamping
*/
public final void clamp(double min, double max) {
if( x > max ) {
x = max;
} else if( x < min ){
x = min;
}
if( y > max ) {
y = max;
} else if( y < min ){
y = min;
}
if( z > max ) {
z = max;
} else if( z < min ){
z = min;
}
}
/**
* @deprecated Use clampMin(double) instead
*/
public final void clampMin(float min) {
clampMin((double)min);
}
/**
* Clamps the minimum value of this tuple to the min parameter.
* @param min the lowest value in this tuple after clamping
*/
public final void clampMin(double min) {
if( x < min ) x=min;
if( y < min ) y=min;
if( z < min ) z=min;
}
/**
* @deprecated Use clampMax(double) instead
*/
public final void clampMax(float max) {
clampMax((double)max);
}
/**
* Clamps the maximum value of this tuple to the max parameter.
* @param max the highest value in the tuple after clamping
*/
public final void clampMax(double max) {
if( x > max ) x=max;
if( y > max ) y=max;
if( z > max ) z=max;
}
/**
* Sets each component of this tuple to its absolute value.
*/
public final void absolute()
{
x = Math.abs(x);
y = Math.abs(y);
z = Math.abs(z);
}
/**
* @deprecated Use interpolate(Tuple3d,Tuple3d,double) instead
*/
public final void interpolate(Tuple3d t1, Tuple3d t2, float alpha) {
interpolate(t1, t2, (double)alpha);
}
/**
* Linearly interpolates between tuples t1 and t2 and places the
* result into this tuple: this = (1-alpha)*t1 + alpha*t2.
* @param t1 the first tuple
* @param t2 the second tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple3d t1, Tuple3d t2, double alpha) {
this.x = (1-alpha)*t1.x + alpha*t2.x;
this.y = (1-alpha)*t1.y + alpha*t2.y;
this.z = (1-alpha)*t1.z + alpha*t2.z;
}
/**
* @deprecated Use interpolate(Tuple3d,double) instead
*/
public final void interpolate(Tuple3d t1, float alpha) {
interpolate(t1, (double)alpha);
}
/**
* Linearly interpolates between this tuple and tuple t1 and
* places the result into this tuple: this = (1-alpha)*this + alpha*t1.
* @param t1 the first tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple3d t1, double alpha) {
this.x = (1-alpha)*this.x + alpha*t1.x;
this.y = (1-alpha)*this.y + alpha*t1.y;
this.z = (1-alpha)*this.z + alpha*t1.z;
}
/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
/**
* Get the <i>x</i> coordinate.
*
* @return the <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getX() {
return x;
}
/**
* Set the <i>x</i> coordinate.
*
* @param x value to <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setX(double x) {
this.x = x;
}
/**
* Get the <i>y</i> coordinate.
*
* @return the <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getY() {
return y;
}
/**
* Set the <i>y</i> coordinate.
*
* @param y value to <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setY(double y) {
this.y = y;
}
/**
* Get the <i>z</i> coordinate.
*
* @return the <i>z</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getZ() {
return z;
}
/**
* Set the <i>z</i> coordinate.
*
* @param z value to <i>z</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setZ(double z) {
this.z = z;
}
}

View File

@@ -0,0 +1,713 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A generic 3-element tuple that is represented by single precision-floating
* point x,y,z coordinates.
*
*/
public abstract class Tuple3f implements java.io.Serializable, Cloneable {
static final long serialVersionUID=5019834619484343712L;
/**
* The x coordinate.
*/
public float x;
/**
* The y coordinate.
*/
public float y;
/**
* The z coordinate.
*/
public float z;
/**
* Constructs and initializes a Tuple3f from the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public Tuple3f(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
/**
* Constructs and initializes a Tuple3f from the array of length 3.
* @param t the array of length 3 containing xyz in order
*/
public Tuple3f(float[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
}
/**
* Constructs and initializes a Tuple3f from the specified Tuple3f.
* @param t1 the Tuple3f containing the initialization x y z data
*/
public Tuple3f(Tuple3f t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
}
/**
* Constructs and initializes a Tuple3f from the specified Tuple3d.
* @param t1 the Tuple3d containing the initialization x y z data
*/
public Tuple3f(Tuple3d t1)
{
this.x = (float) t1.x;
this.y = (float) t1.y;
this.z = (float) t1.z;
}
/**
* Constructs and initializes a Tuple3f to (0,0,0).
*/
public Tuple3f()
{
this.x = 0.0f;
this.y = 0.0f;
this.z = 0.0f;
}
/**
* Returns a string that contains the values of this Tuple3f.
* The form is (x,y,z).
* @return the String representation
*/
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ")";
}
/**
* Sets the value of this tuple to the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public final void set(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}
/**
* Sets the value of this tuple to the xyz coordinates specified in
* the array of length 3.
* @param t the array of length 3 containing xyz in order
*/
public final void set(float[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple3f t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple3d t1)
{
this.x = (float) t1.x;
this.y = (float) t1.y;
this.z = (float) t1.z;
}
/**
* Gets the value of this tuple and copies the values into t.
* @param t the array of length 3 into which the values are copied
*/
public final void get(float[] t)
{
t[0] = this.x;
t[1] = this.y;
t[2] = this.z;
}
/**
* Gets the value of this tuple and copies the values into t.
* @param t the Tuple3f object into which the values of this object are copied
*/
public final void get(Tuple3f t)
{
t.x = this.x;
t.y = this.y;
t.z = this.z;
}
/**
* Sets the value of this tuple to the vector sum of tuples t1 and t2.
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void add(Tuple3f t1, Tuple3f t2)
{
this.x = t1.x + t2.x;
this.y = t1.y + t2.y;
this.z = t1.z + t2.z;
}
/**
* Sets the value of this tuple to the vector sum of itself and tuple t1.
* @param t1 the other tuple
*/
public final void add(Tuple3f t1)
{
this.x += t1.x;
this.y += t1.y;
this.z += t1.z;
}
/**
* Sets the value of this tuple to the vector difference
* of tuples t1 and t2 (this = t1 - t2).
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void sub(Tuple3f t1, Tuple3f t2)
{
this.x = t1.x - t2.x;
this.y = t1.y - t2.y;
this.z = t1.z - t2.z;
}
/**
* Sets the value of this tuple to the vector difference of
* itself and tuple t1 (this = this - t1) .
* @param t1 the other tuple
*/
public final void sub(Tuple3f t1)
{
this.x -= t1.x;
this.y -= t1.y;
this.z -= t1.z;
}
/**
* Sets the value of this tuple to the negation of tuple t1.
* @param t1 the source tuple
*/
public final void negate(Tuple3f t1)
{
this.x = -t1.x;
this.y = -t1.y;
this.z = -t1.z;
}
/**
* Negates the value of this tuple in place.
*/
public final void negate()
{
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
}
/**
* Sets the value of this vector to the scalar multiplication
* of tuple t1.
* @param s the scalar value
* @param t1 the source tuple
*/
public final void scale(float s, Tuple3f t1)
{
this.x = s*t1.x;
this.y = s*t1.y;
this.z = s*t1.z;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of the scale factor with this.
* @param s the scalar value
*/
public final void scale(float s)
{
this.x *= s;
this.y *= s;
this.z *= s;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1 and then adds tuple t2 (this = s*t1 + t2).
* @param s the scalar value
* @param t1 the tuple to be scaled and added
* @param t2 the tuple to be added without a scale
*/
public final void scaleAdd(float s, Tuple3f t1, Tuple3f t2)
{
this.x = s*t1.x + t2.x;
this.y = s*t1.y + t2.y;
this.z = s*t1.z + t2.z;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself and then adds tuple t1 (this = s*this + t1).
* @param s the scalar value
* @param t1 the tuple to be added
*/
public final void scaleAdd(float s, Tuple3f t1)
{
this.x = s*this.x + t1.x;
this.y = s*this.y + t1.y;
this.z = s*this.z + t1.z;
}
/**
* Returns true if the Object t1 is of type Tuple3f and all of the
* data members of t1 are equal to the corresponding data members in
* this Tuple3f.
* @param t1 the vector with which the comparison is made
* @return true or false
*/
public boolean equals(Tuple3f t1)
{
try {
return(this.x == t1.x && this.y == t1.y && this.z == t1.z);
}
catch (NullPointerException e2) {return false;}
}
/**
* Returns true if the Object t1 is of type Tuple3f and all of the
* data members of t1 are equal to the corresponding data members in
* this Tuple3f.
* @param t1 the Object with which the comparison is made
* @return true or false
*/
public boolean equals(Object t1)
{
try {
Tuple3f t2 = (Tuple3f) t1;
return(this.x == t2.x && this.y == t2.y && this.z == t2.z);
}
catch (NullPointerException e2) {return false;}
catch (ClassCastException e1) {return false;}
}
/**
* Returns true if the L-infinite distance between this tuple
* and tuple t1 is less than or equal to the epsilon parameter,
* otherwise returns false. The L-infinite
* distance is equal to MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)].
* @param t1 the tuple to be compared to this tuple
* @param epsilon the threshold value
* @return true or false
*/
public boolean epsilonEquals(Tuple3f t1, float epsilon)
{
float diff;
diff = x - t1.x;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = y - t1.y;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = z - t1.z;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
return true;
}
/**
* Returns a hash code value based on the data values in this
* object. Two different Tuple3f objects with identical data values
* (i.e., Tuple3f.equals returns true) will return the same hash
* code value. Two objects with different data members may return the
* same hash value, although this is not likely.
* @return the integer hash code value
*/
public int hashCode() {
long bits = 1L;
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(x);
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(y);
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(z);
return (int) (bits ^ (bits >> 32));
}
/**
* Clamps the tuple parameter to the range [low, high] and
* places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clamp(float min, float max, Tuple3f t)
{
if( t.x > max ) {
x = max;
} else if( t.x < min ){
x = min;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else if( t.y < min ){
y = min;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else if( t.z < min ){
z = min;
} else {
z = t.z;
}
}
/**
* Clamps the minimum value of the tuple parameter to the min
* parameter and places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMin(float min, Tuple3f t)
{
if( t.x < min ) {
x = min;
} else {
x = t.x;
}
if( t.y < min ) {
y = min;
} else {
y = t.y;
}
if( t.z < min ) {
z = min;
} else {
z = t.z;
}
}
/**
* Clamps the maximum value of the tuple parameter to the max
* parameter and places the values into this tuple.
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMax(float max, Tuple3f t)
{
if( t.x > max ) {
x = max;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else {
z = t.z;
}
}
/**
* Sets each component of the tuple parameter to its absolute
* value and places the modified values into this tuple.
* @param t the source tuple, which will not be modified
*/
public final void absolute(Tuple3f t)
{
x = Math.abs(t.x);
y = Math.abs(t.y);
z = Math.abs(t.z);
}
/**
* Clamps this tuple to the range [low, high].
* @param min the lowest value in this tuple after clamping
* @param max the highest value in this tuple after clamping
*/
public final void clamp(float min, float max)
{
if( x > max ) {
x = max;
} else if( x < min ){
x = min;
}
if( y > max ) {
y = max;
} else if( y < min ){
y = min;
}
if( z > max ) {
z = max;
} else if( z < min ){
z = min;
}
}
/**
* Clamps the minimum value of this tuple to the min parameter.
* @param min the lowest value in this tuple after clamping
*/
public final void clampMin(float min)
{
if( x < min ) x=min;
if( y < min ) y=min;
if( z < min ) z=min;
}
/**
* Clamps the maximum value of this tuple to the max parameter.
* @param max the highest value in the tuple after clamping
*/
public final void clampMax(float max)
{
if( x > max ) x=max;
if( y > max ) y=max;
if( z > max ) z=max;
}
/**
* Sets each component of this tuple to its absolute value.
*/
public final void absolute()
{
x = Math.abs(x);
y = Math.abs(y);
z = Math.abs(z);
}
/**
* Linearly interpolates between tuples t1 and t2 and places the
* result into this tuple: this = (1-alpha)*t1 + alpha*t2.
* @param t1 the first tuple
* @param t2 the second tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple3f t1, Tuple3f t2, float alpha)
{
this.x = (1-alpha)*t1.x + alpha*t2.x;
this.y = (1-alpha)*t1.y + alpha*t2.y;
this.z = (1-alpha)*t1.z + alpha*t2.z;
}
/**
* Linearly interpolates between this tuple and tuple t1 and
* places the result into this tuple: this = (1-alpha)*this + alpha*t1.
* @param t1 the first tuple
* @param alpha the alpha interpolation parameter
*/
public final void interpolate(Tuple3f t1, float alpha)
{
this.x = (1-alpha)*this.x + alpha*t1.x;
this.y = (1-alpha)*this.y + alpha*t1.y;
this.z = (1-alpha)*this.z + alpha*t1.z;
}
/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
/**
* Get the <i>x</i> coordinate.
*
* @return the <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getX() {
return x;
}
/**
* Set the <i>x</i> coordinate.
*
* @param x value to <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setX(float x) {
this.x = x;
}
/**
* Get the <i>y</i> coordinate.
*
* @return the <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getY() {
return y;
}
/**
* Set the <i>y</i> coordinate.
*
* @param y value to <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setY(float y) {
this.y = y;
}
/**
* Get the <i>z</i> coordinate.
*
* @return the <i>z</i> coordinate
*
* @since vecmath 1.5
*/
public final float getZ() {
return z;
}
/**
* Set the <i>Z</i> coordinate.
*
* @param z value to <i>z</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setZ(float z) {
this.z = z;
}
}

View File

@@ -0,0 +1,867 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 4 element tuple represented by double precision floating point
* x,y,z,w coordinates.
*
*/
public abstract class Tuple4d implements java.io.Serializable, Cloneable {
static final long serialVersionUID = -4748953690425311052L;
/**
* The x coordinate.
*/
public double x;
/**
* The y coordinate.
*/
public double y;
/**
* The z coordinate.
*/
public double z;
/**
* The w coordinate.
*/
public double w;
/**
* Constructs and initializes a Tuple4d from the specified xyzw coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param w the w coordinate
*/
public Tuple4d(double x, double y, double z, double w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
/**
* Constructs and initializes a Tuple4d from the coordinates contained
* in the array.
* @param t the array of length 4 containing xyzw in order
*/
public Tuple4d(double[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
this.w = t[3];
}
/**
* Constructs and initializes a Tuple4d from the specified Tuple4d.
* @param t1 the Tuple4d containing the initialization x y z w data
*/
public Tuple4d(Tuple4d t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = t1.w;
}
/**
* Constructs and initializes a Tuple4d from the specified Tuple4f.
* @param t1 the Tuple4f containing the initialization x y z w data
*/
public Tuple4d(Tuple4f t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = t1.w;
}
/**
* Constructs and initializes a Tuple4d to (0,0,0,0).
*/
public Tuple4d()
{
this.x = 0.0;
this.y = 0.0;
this.z = 0.0;
this.w = 0.0;
}
/**
* Sets the value of this tuple to the specified xyzw coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param w the w coordinate
*/
public final void set(double x, double y, double z, double w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
/**
* Sets the value of this tuple to the specified xyzw coordinates.
* @param t the array of length 4 containing xyzw in order
*/
public final void set(double[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
this.w = t[3];
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple4d t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = t1.w;
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple4f t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = t1.w;
}
/**
* Gets the value of this tuple and places it into the array t of
* length four in x,y,z,w order.
* @param t the array of length four
*/
public final void get(double[] t)
{
t[0] = this.x;
t[1] = this.y;
t[2] = this.z;
t[3] = this.w;
}
/**
* Gets the value of this tuple and places it into the Tuple4d
* argument of
* length four in x,y,z,w order.
* @param t the Tuple into which the values will be copied
*/
public final void get(Tuple4d t)
{
t.x = this.x;
t.y = this.y;
t.z = this.z;
t.w = this.w;
}
/**
* Sets the value of this tuple to the tuple sum of tuples t1 and t2.
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void add(Tuple4d t1, Tuple4d t2)
{
this.x = t1.x + t2.x;
this.y = t1.y + t2.y;
this.z = t1.z + t2.z;
this.w = t1.w + t2.w;
}
/**
* Sets the value of this tuple to the sum of itself and tuple t1.
* @param t1 the other tuple
*/
public final void add(Tuple4d t1)
{
this.x += t1.x;
this.y += t1.y;
this.z += t1.z;
this.w += t1.w;
}
/**
* Sets the value of this tuple to the difference
* of tuples t1 and t2 (this = t1 - t2).
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void sub(Tuple4d t1, Tuple4d t2)
{
this.x = t1.x - t2.x;
this.y = t1.y - t2.y;
this.z = t1.z - t2.z;
this.w = t1.w - t2.w;
}
/**
* Sets the value of this tuple to the difference of itself
* and tuple t1 (this = this - t1).
* @param t1 the other tuple
*/
public final void sub(Tuple4d t1)
{
this.x -= t1.x;
this.y -= t1.y;
this.z -= t1.z;
this.w -= t1.w;
}
/**
* Sets the value of this tuple to the negation of tuple t1.
* @param t1 the source tuple
*/
public final void negate(Tuple4d t1)
{
this.x = -t1.x;
this.y = -t1.y;
this.z = -t1.z;
this.w = -t1.w;
}
/**
* Negates the value of this tuple in place.
*/
public final void negate()
{
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
this.w = -this.w;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of the scale factor with the tuple t1.
* @param s the scalar value
* @param t1 the source tuple
*/
public final void scale(double s, Tuple4d t1)
{
this.x = s*t1.x;
this.y = s*t1.y;
this.z = s*t1.z;
this.w = s*t1.w;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of the scale factor with this.
* @param s the scalar value
*/
public final void scale(double s)
{
this.x *= s;
this.y *= s;
this.z *= s;
this.w *= s;
}
/**
* Sets the value of this tuple to the scalar multiplication by s
* of tuple t1 plus tuple t2 (this = s*t1 + t2).
* @param s the scalar value
* @param t1 the tuple to be multipled
* @param t2 the tuple to be added
*/
public final void scaleAdd(double s, Tuple4d t1, Tuple4d t2)
{
this.x = s*t1.x + t2.x;
this.y = s*t1.y + t2.y;
this.z = s*t1.z + t2.z;
this.w = s*t1.w + t2.w;
}
/**
* @deprecated Use scaleAdd(double,Tuple4d) instead
*/
public final void scaleAdd(float s, Tuple4d t1) {
scaleAdd((double)s, t1);
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself and then adds tuple t1 (this = s*this + t1).
* @param s the scalar value
* @param t1 the tuple to be added
*/
public final void scaleAdd(double s, Tuple4d t1) {
this.x = s*this.x + t1.x;
this.y = s*this.y + t1.y;
this.z = s*this.z + t1.z;
this.w = s*this.w + t1.w;
}
/**
* Returns a string that contains the values of this Tuple4d.
* The form is (x,y,z,w).
* @return the String representation
*/
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")";
}
/**
* Returns true if all of the data members of Tuple4d t1 are
* equal to the corresponding data members in this Tuple4d.
* @param t1 the tuple with which the comparison is made
* @return true or false
*/
public boolean equals(Tuple4d t1)
{
try {
return(this.x == t1.x && this.y == t1.y && this.z == t1.z
&& this.w == t1.w);
}
catch (NullPointerException e2) {return false;}
}
/**
* Returns true if the Object t1 is of type Tuple4d and all of the
* data members of t1 are equal to the corresponding data members in
* this Tuple4d.
* @param t1 the object with which the comparison is made
* @return true or false
*/
public boolean equals(Object t1)
{
try {
Tuple4d t2 = (Tuple4d) t1;
return(this.x == t2.x && this.y == t2.y &&
this.z == t2.z && this.w == t2.w);
}
catch (NullPointerException e2) {return false;}
catch (ClassCastException e1) {return false;}
}
/**
* Returns true if the L-infinite distance between this tuple
* and tuple t1 is less than or equal to the epsilon parameter,
* otherwise returns false. The L-infinite
* distance is equal to
* MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)].
* @param t1 the tuple to be compared to this tuple
* @param epsilon the threshold value
* @return true or false
*/
public boolean epsilonEquals(Tuple4d t1, double epsilon)
{
double diff;
diff = x - t1.x;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = y - t1.y;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = z - t1.z;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = w - t1.w;
if(Double.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
return true;
}
/**
* Returns a hash code value based on the data values in this
* object. Two different Tuple4d objects with identical data values
* (i.e., Tuple4d.equals returns true) will return the same hash
* code value. Two objects with different data members may return the
* same hash value, although this is not likely.
* @return the integer hash code value
*/
public int hashCode() {
long bits = 1L;
bits = 31L * bits + VecMathUtil.doubleToLongBits(x);
bits = 31L * bits + VecMathUtil.doubleToLongBits(y);
bits = 31L * bits + VecMathUtil.doubleToLongBits(z);
bits = 31L * bits + VecMathUtil.doubleToLongBits(w);
return (int) (bits ^ (bits >> 32));
}
/**
* @deprecated Use clamp(double,double,Tuple4d) instead
*/
public final void clamp(float min, float max, Tuple4d t) {
clamp((double)min, (double)max, t);
}
/**
* Clamps the tuple parameter to the range [low, high] and
* places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clamp(double min, double max, Tuple4d t) {
if( t.x > max ) {
x = max;
} else if( t.x < min ){
x = min;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else if( t.y < min ){
y = min;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else if( t.z < min ){
z = min;
} else {
z = t.z;
}
if( t.w > max ) {
w = max;
} else if( t.w < min ){
w = min;
} else {
w = t.w;
}
}
/**
* @deprecated Use clampMin(double,Tuple4d) instead
*/
public final void clampMin(float min, Tuple4d t) {
clampMin((double)min, t);
}
/**
* Clamps the minimum value of the tuple parameter to the min
* parameter and places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMin(double min, Tuple4d t) {
if( t.x < min ) {
x = min;
} else {
x = t.x;
}
if( t.y < min ) {
y = min;
} else {
y = t.y;
}
if( t.z < min ) {
z = min;
} else {
z = t.z;
}
if( t.w < min ) {
w = min;
} else {
w = t.w;
}
}
/**
* @deprecated Use clampMax(double,Tuple4d) instead
*/
public final void clampMax(float max, Tuple4d t) {
clampMax((double)max, t);
}
/**
* Clamps the maximum value of the tuple parameter to the max
* parameter and places the values into this tuple.
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMax(double max, Tuple4d t) {
if( t.x > max ) {
x = max;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else {
z = t.z;
}
if( t.w > max ) {
w = max;
} else {
w = t.z;
}
}
/**
* Sets each component of the tuple parameter to its absolute
* value and places the modified values into this tuple.
* @param t the source tuple, which will not be modified
*/
public final void absolute(Tuple4d t)
{
x = Math.abs(t.x);
y = Math.abs(t.y);
z = Math.abs(t.z);
w = Math.abs(t.w);
}
/**
* @deprecated Use clamp(double,double) instead
*/
public final void clamp(float min, float max) {
clamp((double)min, (double)max);
}
/**
* Clamps this tuple to the range [low, high].
* @param min the lowest value in this tuple after clamping
* @param max the highest value in this tuple after clamping
*/
public final void clamp(double min, double max) {
if( x > max ) {
x = max;
} else if( x < min ){
x = min;
}
if( y > max ) {
y = max;
} else if( y < min ){
y = min;
}
if( z > max ) {
z = max;
} else if( z < min ){
z = min;
}
if( w > max ) {
w = max;
} else if( w < min ){
w = min;
}
}
/**
* @deprecated Use clampMin(double) instead
*/
public final void clampMin(float min) {
clampMin((double)min);
}
/**
* Clamps the minimum value of this tuple to the min parameter.
* @param min the lowest value in this tuple after clamping
*/
public final void clampMin(double min) {
if( x < min ) x=min;
if( y < min ) y=min;
if( z < min ) z=min;
if( w < min ) w=min;
}
/**
* @deprecated Use clampMax(double) instead
*/
public final void clampMax(float max) {
clampMax((double)max);
}
/**
* Clamps the maximum value of this tuple to the max parameter.
* @param max the highest value in the tuple after clamping
*/
public final void clampMax(double max) {
if( x > max ) x=max;
if( y > max ) y=max;
if( z > max ) z=max;
if( w > max ) w=max;
}
/**
* Sets each component of this tuple to its absolute value.
*/
public final void absolute()
{
x = Math.abs(x);
y = Math.abs(y);
z = Math.abs(z);
w = Math.abs(w);
}
/**
* @deprecated Use interpolate(Tuple4d,Tuple4d,double) instead
*/
public void interpolate(Tuple4d t1, Tuple4d t2, float alpha) {
interpolate(t1, t2, (double)alpha);
}
/**
* Linearly interpolates between tuples t1 and t2 and places the
* result into this tuple: this = (1-alpha)*t1 + alpha*t2.
* @param t1 the first tuple
* @param t2 the second tuple
* @param alpha the alpha interpolation parameter
*/
public void interpolate(Tuple4d t1, Tuple4d t2, double alpha) {
this.x = (1-alpha)*t1.x + alpha*t2.x;
this.y = (1-alpha)*t1.y + alpha*t2.y;
this.z = (1-alpha)*t1.z + alpha*t2.z;
this.w = (1-alpha)*t1.w + alpha*t2.w;
}
/**
* @deprecated Use interpolate(Tuple4d,double) instead
*/
public void interpolate(Tuple4d t1, float alpha) {
interpolate(t1, (double)alpha);
}
/**
* Linearly interpolates between this tuple and tuple t1 and
* places the result into this tuple: this = (1-alpha)*this + alpha*t1.
* @param t1 the first tuple
* @param alpha the alpha interpolation parameter
*/
public void interpolate(Tuple4d t1, double alpha) {
this.x = (1-alpha)*this.x + alpha*t1.x;
this.y = (1-alpha)*this.y + alpha*t1.y;
this.z = (1-alpha)*this.z + alpha*t1.z;
this.w = (1-alpha)*this.w + alpha*t1.w;
}
/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
/**
* Get the <i>x</i> coordinate.
*
* @return the x coordinate.
*
* @since vecmath 1.5
*/
public final double getX() {
return x;
}
/**
* Set the <i>x</i> coordinate.
*
* @param x value to <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setX(double x) {
this.x = x;
}
/**
* Get the <i>y</i> coordinate.
*
* @return the <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getY() {
return y;
}
/**
* Set the <i>y</i> coordinate.
*
* @param y value to <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setY(double y) {
this.y = y;
}
/**
* Get the <i>z</i> coordinate.
*
* @return the <i>z</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getZ() {
return z;
}
/**
* Set the <i>z</i> coordinate.
*
* @param z value to <i>z</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setZ(double z) {
this.z = z;
}
/**
* Get the <i>w</i> coordinate.
*
* @return the <i>w</i> coordinate.
*
* @since vecmath 1.5
*/
public final double getW() {
return w;
}
/**
* Set the <i>w</i> coordinate.
*
* @param w value to <i>w</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setW(double w) {
this.w = w;
}
}

View File

@@ -0,0 +1,798 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 4-element tuple represented by single-precision floating point x,y,z,w
* coordinates.
*
*/
public abstract class Tuple4f implements java.io.Serializable, Cloneable {
static final long serialVersionUID = 7068460319248845763L;
/**
* The x coordinate.
*/
public float x;
/**
* The y coordinate.
*/
public float y;
/**
* The z coordinate.
*/
public float z;
/**
* The w coordinate.
*/
public float w;
/**
* Constructs and initializes a Tuple4f from the specified xyzw coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param w the w coordinate
*/
public Tuple4f(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
/**
* Constructs and initializes a Tuple4f from the array of length 4.
* @param t the array of length 4 containing xyzw in order
*/
public Tuple4f(float[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
this.w = t[3];
}
/**
* Constructs and initializes a Tuple4f from the specified Tuple4f.
* @param t1 the Tuple4f containing the initialization x y z w data
*/
public Tuple4f(Tuple4f t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = t1.w;
}
/**
* Constructs and initializes a Tuple4f from the specified Tuple4d.
* @param t1 the Tuple4d containing the initialization x y z w data
*/
public Tuple4f(Tuple4d t1)
{
this.x = (float) t1.x;
this.y = (float) t1.y;
this.z = (float) t1.z;
this.w = (float) t1.w;
}
/**
* Constructs and initializes a Tuple4f to (0,0,0,0).
*/
public Tuple4f()
{
this.x = 0.0f;
this.y = 0.0f;
this.z = 0.0f;
this.w = 0.0f;
}
/**
* Sets the value of this tuple to the specified xyzw coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
* @param w the w coordinate
*/
public final void set(float x, float y, float z, float w)
{
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
/**
* Sets the value of this tuple to the specified coordinates in the
* array of length 4.
* @param t the array of length 4 containing xyzw in order
*/
public final void set(float[] t)
{
this.x = t[0];
this.y = t[1];
this.z = t[2];
this.w = t[3];
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple4f t1)
{
this.x = t1.x;
this.y = t1.y;
this.z = t1.z;
this.w = t1.w;
}
/**
* Sets the value of this tuple to the value of tuple t1.
* @param t1 the tuple to be copied
*/
public final void set(Tuple4d t1)
{
this.x = (float) t1.x;
this.y = (float) t1.y;
this.z = (float) t1.z;
this.w = (float) t1.w;
}
/**
* Copies the values of this tuple into the array t.
* @param t the array
*/
public final void get(float[] t)
{
t[0] = this.x;
t[1] = this.y;
t[2] = this.z;
t[3] = this.w;
}
/**
* Copies the values of this tuple into the tuple t.
* @param t the target tuple
*/
public final void get(Tuple4f t)
{
t.x = this.x;
t.y = this.y;
t.z = this.z;
t.w = this.w;
}
/**
* Sets the value of this tuple to the sum of tuples t1 and t2.
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void add(Tuple4f t1, Tuple4f t2)
{
this.x = t1.x + t2.x;
this.y = t1.y + t2.y;
this.z = t1.z + t2.z;
this.w = t1.w + t2.w;
}
/**
* Sets the value of this tuple to the sum of itself and t1.
* @param t1 the other tuple
*/
public final void add(Tuple4f t1)
{
this.x += t1.x;
this.y += t1.y;
this.z += t1.z;
this.w += t1.w;
}
/**
* Sets the value of this tuple to the difference
* of tuples t1 and t2 (this = t1 - t2).
* @param t1 the first tuple
* @param t2 the second tuple
*/
public final void sub(Tuple4f t1, Tuple4f t2)
{
this.x = t1.x - t2.x;
this.y = t1.y - t2.y;
this.z = t1.z - t2.z;
this.w = t1.w - t2.w;
}
/**
* Sets the value of this tuple to the difference
* of itself and t1 (this = this - t1).
* @param t1 the other tuple
*/
public final void sub(Tuple4f t1)
{
this.x -= t1.x;
this.y -= t1.y;
this.z -= t1.z;
this.w -= t1.w;
}
/**
* Sets the value of this tuple to the negation of tuple t1.
* @param t1 the source tuple
*/
public final void negate(Tuple4f t1)
{
this.x = -t1.x;
this.y = -t1.y;
this.z = -t1.z;
this.w = -t1.w;
}
/**
* Negates the value of this tuple in place.
*/
public final void negate()
{
this.x = -this.x;
this.y = -this.y;
this.z = -this.z;
this.w = -this.w;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1.
* @param s the scalar value
* @param t1 the source tuple
*/
public final void scale(float s, Tuple4f t1)
{
this.x = s*t1.x;
this.y = s*t1.y;
this.z = s*t1.z;
this.w = s*t1.w;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of the scale factor with this.
* @param s the scalar value
*/
public final void scale(float s)
{
this.x *= s;
this.y *= s;
this.z *= s;
this.w *= s;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of tuple t1 plus tuple t2 (this = s*t1 + t2).
* @param s the scalar value
* @param t1 the tuple to be multipled
* @param t2 the tuple to be added
*/
public final void scaleAdd(float s, Tuple4f t1, Tuple4f t2)
{
this.x = s*t1.x + t2.x;
this.y = s*t1.y + t2.y;
this.z = s*t1.z + t2.z;
this.w = s*t1.w + t2.w;
}
/**
* Sets the value of this tuple to the scalar multiplication
* of itself and then adds tuple t1 (this = s*this + t1).
* @param s the scalar value
* @param t1 the tuple to be added
*/
public final void scaleAdd(float s, Tuple4f t1)
{
this.x = s*this.x + t1.x;
this.y = s*this.y + t1.y;
this.z = s*this.z + t1.z;
this.w = s*this.w + t1.w;
}
/**
* Returns a string that contains the values of this Tuple4f.
* The form is (x,y,z,w).
* @return the String representation
*/
public String toString() {
return "(" + this.x + ", " + this.y + ", " + this.z + ", " + this.w + ")";
}
/**
* Returns true if all of the data members of Tuple4f t1 are
* equal to the corresponding data members in this Tuple4f.
* @param t1 the vector with which the comparison is made
* @return true or false
*/
public boolean equals(Tuple4f t1)
{
try {
return(this.x == t1.x && this.y == t1.y && this.z == t1.z
&& this.w == t1.w);
}
catch (NullPointerException e2) {return false;}
}
/**
* Returns true if the Object t1 is of type Tuple4f and all of the
* data members of t1 are equal to the corresponding data members in
* this Tuple4f.
* @param t1 the object with which the comparison is made
* @return true or false
*/
public boolean equals(Object t1)
{
try {
Tuple4f t2 = (Tuple4f) t1;
return(this.x == t2.x && this.y == t2.y &&
this.z == t2.z && this.w == t2.w);
}
catch (NullPointerException e2) {return false;}
catch (ClassCastException e1) {return false;}
}
/**
* Returns true if the L-infinite distance between this tuple
* and tuple t1 is less than or equal to the epsilon parameter,
* otherwise returns false. The L-infinite
* distance is equal to
* MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)].
* @param t1 the tuple to be compared to this tuple
* @param epsilon the threshold value
* @return true or false
*/
public boolean epsilonEquals(Tuple4f t1, float epsilon)
{
float diff;
diff = x - t1.x;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = y - t1.y;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = z - t1.z;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
diff = w - t1.w;
if(Float.isNaN(diff)) return false;
if((diff<0?-diff:diff) > epsilon) return false;
return true;
}
/**
* Returns a hash code value based on the data values in this
* object. Two different Tuple4f objects with identical data values
* (i.e., Tuple4f.equals returns true) will return the same hash
* code value. Two objects with different data members may return the
* same hash value, although this is not likely.
* @return the integer hash code value
*/
public int hashCode() {
long bits = 1L;
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(x);
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(y);
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(z);
bits = 31L * bits + (long)VecMathUtil.floatToIntBits(w);
return (int) (bits ^ (bits >> 32));
}
/**
* Clamps the tuple parameter to the range [low, high] and
* places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clamp(float min, float max, Tuple4f t)
{
if( t.x > max ) {
x = max;
} else if( t.x < min ){
x = min;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else if( t.y < min ){
y = min;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else if( t.z < min ){
z = min;
} else {
z = t.z;
}
if( t.w > max ) {
w = max;
} else if( t.w < min ){
w = min;
} else {
w = t.w;
}
}
/**
* Clamps the minimum value of the tuple parameter to the min
* parameter and places the values into this tuple.
* @param min the lowest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMin(float min, Tuple4f t)
{
if( t.x < min ) {
x = min;
} else {
x = t.x;
}
if( t.y < min ) {
y = min;
} else {
y = t.y;
}
if( t.z < min ) {
z = min;
} else {
z = t.z;
}
if( t.w < min ) {
w = min;
} else {
w = t.w;
}
}
/**
* Clamps the maximum value of the tuple parameter to the max
* parameter and places the values into this tuple.
* @param max the highest value in the tuple after clamping
* @param t the source tuple, which will not be modified
*/
public final void clampMax(float max, Tuple4f t)
{
if( t.x > max ) {
x = max;
} else {
x = t.x;
}
if( t.y > max ) {
y = max;
} else {
y = t.y;
}
if( t.z > max ) {
z = max;
} else {
z = t.z;
}
if( t.w > max ) {
w = max;
} else {
w = t.z;
}
}
/**
* Sets each component of the tuple parameter to its absolute
* value and places the modified values into this tuple.
* @param t the source tuple, which will not be modified
*/
public final void absolute(Tuple4f t)
{
x = Math.abs(t.x);
y = Math.abs(t.y);
z = Math.abs(t.z);
w = Math.abs(t.w);
}
/**
* Clamps this tuple to the range [low, high].
* @param min the lowest value in this tuple after clamping
* @param max the highest value in this tuple after clamping
*/
public final void clamp(float min, float max)
{
if( x > max ) {
x = max;
} else if( x < min ){
x = min;
}
if( y > max ) {
y = max;
} else if( y < min ){
y = min;
}
if( z > max ) {
z = max;
} else if( z < min ){
z = min;
}
if( w > max ) {
w = max;
} else if( w < min ){
w = min;
}
}
/**
* Clamps the minimum value of this tuple to the min parameter.
* @param min the lowest value in this tuple after clamping
*/
public final void clampMin(float min)
{
if( x < min ) x=min;
if( y < min ) y=min;
if( z < min ) z=min;
if( w < min ) w=min;
}
/**
* Clamps the maximum value of this tuple to the max parameter.
* @param max the highest value in the tuple after clamping
*/
public final void clampMax(float max)
{
if( x > max ) x=max;
if( y > max ) y=max;
if( z > max ) z=max;
if( w > max ) w=max;
}
/**
* Sets each component of this tuple to its absolute value.
*/
public final void absolute()
{
x = Math.abs(x);
y = Math.abs(y);
z = Math.abs(z);
w = Math.abs(w);
}
/**
* Linearly interpolates between tuples t1 and t2 and places the
* result into this tuple: this = (1-alpha)*t1 + alpha*t2.
* @param t1 the first tuple
* @param t2 the second tuple
* @param alpha the alpha interpolation parameter
*/
public void interpolate(Tuple4f t1, Tuple4f t2, float alpha)
{
this.x = (1-alpha)*t1.x + alpha*t2.x;
this.y = (1-alpha)*t1.y + alpha*t2.y;
this.z = (1-alpha)*t1.z + alpha*t2.z;
this.w = (1-alpha)*t1.w + alpha*t2.w;
}
/**
* Linearly interpolates between this tuple and tuple t1 and
* places the result into this tuple: this = (1-alpha)*this + alpha*t1.
* @param t1 the first tuple
* @param alpha the alpha interpolation parameter
*/
public void interpolate(Tuple4f t1, float alpha)
{
this.x = (1-alpha)*this.x + alpha*t1.x;
this.y = (1-alpha)*this.y + alpha*t1.y;
this.z = (1-alpha)*this.z + alpha*t1.z;
this.w = (1-alpha)*this.w + alpha*t1.w;
}
/**
* Creates a new object of the same class as this object.
*
* @return a clone of this instance.
* @exception OutOfMemoryError if there is not enough memory.
* @see java.lang.Cloneable
* @since vecmath 1.3
*/
public Object clone() {
// Since there are no arrays we can just use Object.clone()
try {
return super.clone();
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError();
}
}
/**
* Get the <i>x</i> coordinate.
*
* @return the <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getX() {
return x;
}
/**
* Set the <i>x</i> coordinate.
*
* @param x value to <i>x</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setX(float x) {
this.x = x;
}
/**
* Get the <i>y</i> coordinate.
*
* @return the <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getY() {
return y;
}
/**
* Set the <i>y</i> coordinate.
*
* @param y value to <i>y</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setY(float y) {
this.y = y;
}
/**
* Get the <i>z</i> coordinate.
*
* @return the <i>z</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getZ() {
return z;
}
/**
* Set the <i>z</i> coordinate.
*
* @param z value to <i>z</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setZ(float z) {
this.z = z;
}
/**
* Get the <i>w</i> coordinate.
*
* @return the <i>w</i> coordinate.
*
* @since vecmath 1.5
*/
public final float getW() {
return w;
}
/**
* Set the <i>w</i> coordinate.
*
* @param w value to <i>w</i> coordinate.
*
* @since vecmath 1.5
*/
public final void setW(float w) {
this.w = w;
}
}

View File

@@ -0,0 +1,103 @@
/*
* $RCSfile$
*
* Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
/**
* Utility vecmath class used when computing the hash code for vecmath
* objects containing float or double values. This fixes Issue 36.
*/
class VecMathUtil {
/**
* Returns the representation of the specified floating-point
* value according to the IEEE 754 floating-point "single format"
* bit layout, after first mapping -0.0 to 0.0. This method is
* identical to Float.floatToIntBits(float) except that an integer
* value of 0 is returned for a floating-point value of
* -0.0f. This is done for the purpose of computing a hash code
* that satisfies the contract of hashCode() and equals(). The
* equals() method in each vecmath class does a pair-wise "=="
* test on each floating-point field in the class (e.g., x, y, and
* z for a Tuple3f). Since 0.0f&nbsp;==&nbsp;-0.0f returns true,
* we must also return the same hash code for two objects, one of
* which has a field with a value of -0.0f and the other of which
* has a cooresponding field with a value of 0.0f.
*
* @param f an input floating-point number
* @return the integer bits representing that floating-point
* number, after first mapping -0.0f to 0.0f
*/
static int floatToIntBits(float f) {
// Check for +0 or -0
if (f == 0.0f) {
return 0;
}
else {
return Float.floatToIntBits(f);
}
}
/**
* Returns the representation of the specified floating-point
* value according to the IEEE 754 floating-point "double format"
* bit layout, after first mapping -0.0 to 0.0. This method is
* identical to Double.doubleToLongBits(double) except that an
* integer value of 0L is returned for a floating-point value of
* -0.0. This is done for the purpose of computing a hash code
* that satisfies the contract of hashCode() and equals(). The
* equals() method in each vecmath class does a pair-wise "=="
* test on each floating-point field in the class (e.g., x, y, and
* z for a Tuple3d). Since 0.0&nbsp;==&nbsp;-0.0 returns true, we
* must also return the same hash code for two objects, one of
* which has a field with a value of -0.0 and the other of which
* has a cooresponding field with a value of 0.0.
*
* @param d an input double precision floating-point number
* @return the integer bits representing that floating-point
* number, after first mapping -0.0f to 0.0f
*/
static long doubleToLongBits(double d) {
// Check for +0 or -0
if (d == 0.0) {
return 0L;
}
else {
return Double.doubleToLongBits(d);
}
}
/**
* Do not construct an instance of this class.
*/
private VecMathUtil() {
}
}

View File

@@ -0,0 +1,187 @@
/*
* $RCSfile$
*
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 2-element vector that is represented by double-precision floating
* point x,y coordinates.
*
*/
public class Vector2d extends Tuple2d implements java.io.Serializable {
// Combatible with 1.1
static final long serialVersionUID = 8572646365302599857L;
/**
* Constructs and initializes a Vector2d from the specified xy coordinates.
* @param x the x coordinate
* @param y the y coordinate
*/
public Vector2d(double x, double y)
{
super(x,y);
}
/**
* Constructs and initializes a Vector2d from the specified array.
* @param v the array of length 2 containing xy in order
*/
public Vector2d(double[] v)
{
super(v);
}
/**
* Constructs and initializes a Vector2d from the specified Vector2d.
* @param v1 the Vector2d containing the initialization x y data
*/
public Vector2d(Vector2d v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector2d from the specified Vector2f.
* @param v1 the Vector2f containing the initialization x y data
*/
public Vector2d(Vector2f v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector2d from the specified Tuple2d.
* @param t1 the Tuple2d containing the initialization x y data
*/
public Vector2d(Tuple2d t1)
{
super(t1);
}
/**
* Constructs and initializes a Vector2d from the specified Tuple2f.
* @param t1 the Tuple2f containing the initialization x y data
*/
public Vector2d(Tuple2f t1)
{
super(t1);
}
/**
* Constructs and initializes a Vector2d to (0,0).
*/
public Vector2d()
{
super();
}
/**
* Computes the dot product of the this vector and vector v1.
* @param v1 the other vector
*/
public final double dot(Vector2d v1)
{
return (this.x*v1.x + this.y*v1.y);
}
/**
* Returns the length of this vector.
* @return the length of this vector
*/
public final double length()
{
return (double) Math.sqrt(this.x*this.x + this.y*this.y);
}
/**
* Returns the squared length of this vector.
* @return the squared length of this vector
*/
public final double lengthSquared()
{
return (this.x*this.x + this.y*this.y);
}
/**
* Sets the value of this vector to the normalization of vector v1.
* @param v1 the un-normalized vector
*/
public final void normalize(Vector2d v1)
{
double norm;
norm = (double) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y));
this.x = v1.x*norm;
this.y = v1.y*norm;
}
/**
* Normalizes this vector in place.
*/
public final void normalize()
{
double norm;
norm = (double)
(1.0/Math.sqrt(this.x*this.x + this.y*this.y));
this.x *= norm;
this.y *= norm;
}
/**
* Returns the angle in radians between this vector and the vector
* parameter; the return value is constrained to the range [0,PI].
* @param v1 the other vector
* @return the angle in radians in the range [0,PI]
*/
public final double angle(Vector2d v1)
{
double vDot = this.dot(v1) / ( this.length()*v1.length() );
if( vDot < -1.0) vDot = -1.0;
if( vDot > 1.0) vDot = 1.0;
return((double) (Math.acos( vDot )));
}
}

View File

@@ -0,0 +1,187 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 2-element vector that is represented by single-precision floating
* point x,y coordinates.
*
*/
public class Vector2f extends Tuple2f implements java.io.Serializable {
// Combatible with 1.1
static final long serialVersionUID = -2168194326883512320L;
/**
* Constructs and initializes a Vector2f from the specified xy coordinates.
* @param x the x coordinate
* @param y the y coordinate
*/
public Vector2f(float x, float y)
{
super(x,y);
}
/**
* Constructs and initializes a Vector2f from the specified array.
* @param v the array of length 2 containing xy in order
*/
public Vector2f(float[] v)
{
super(v);
}
/**
* Constructs and initializes a Vector2f from the specified Vector2f.
* @param v1 the Vector2f containing the initialization x y data
*/
public Vector2f(Vector2f v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector2f from the specified Vector2d.
* @param v1 the Vector2d containing the initialization x y data
*/
public Vector2f(Vector2d v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector2f from the specified Tuple2f.
* @param t1 the Tuple2f containing the initialization x y data
*/
public Vector2f(Tuple2f t1)
{
super(t1);
}
/**
* Constructs and initializes a Vector2f from the specified Tuple2d.
* @param t1 the Tuple2d containing the initialization x y data
*/
public Vector2f(Tuple2d t1)
{
super(t1);
}
/**
* Constructs and initializes a Vector2f to (0,0).
*/
public Vector2f()
{
super();
}
/**
* Computes the dot product of the this vector and vector v1.
* @param v1 the other vector
*/
public final float dot(Vector2f v1)
{
return (this.x*v1.x + this.y*v1.y);
}
/**
* Returns the length of this vector.
* @return the length of this vector
*/
public final float length()
{
return (float) Math.sqrt(this.x*this.x + this.y*this.y);
}
/**
* Returns the squared length of this vector.
* @return the squared length of this vector
*/
public final float lengthSquared()
{
return (this.x*this.x + this.y*this.y);
}
/**
* Sets the value of this vector to the normalization of vector v1.
* @param v1 the un-normalized vector
*/
public final void normalize(Vector2f v1)
{
float norm;
norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y));
this.x = v1.x*norm;
this.y = v1.y*norm;
}
/**
* Normalizes this vector in place.
*/
public final void normalize()
{
float norm;
norm = (float)
(1.0/Math.sqrt(this.x*this.x + this.y*this.y));
this.x *= norm;
this.y *= norm;
}
/**
* Returns the angle in radians between this vector and the vector
* parameter; the return value is constrained to the range [0,PI].
* @param v1 the other vector
* @return the angle in radians in the range [0,PI]
*/
public final float angle(Vector2f v1)
{
double vDot = this.dot(v1) / ( this.length()*v1.length() );
if( vDot < -1.0) vDot = -1.0;
if( vDot > 1.0) vDot = 1.0;
return((float) (Math.acos( vDot )));
}
}

View File

@@ -0,0 +1,210 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 3-element vector that is represented by double-precision floating point
* x,y,z coordinates. If this value represents a normal, then it should
* be normalized.
*
*/
public class Vector3d extends Tuple3d implements java.io.Serializable {
// Combatible with 1.1
static final long serialVersionUID = 3761969948420550442L;
/**
* Constructs and initializes a Vector3d from the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public Vector3d(double x, double y, double z)
{
super(x,y,z);
}
/**
* Constructs and initializes a Vector3d from the array of length 3.
* @param v the array of length 3 containing xyz in order
*/
public Vector3d(double[] v)
{
super(v);
}
/**
* Constructs and initializes a Vector3d from the specified Vector3d.
* @param v1 the Vector3d containing the initialization x y z data
*/
public Vector3d(Vector3d v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector3d from the specified Vector3f.
* @param v1 the Vector3f containing the initialization x y z data
*/
public Vector3d(Vector3f v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector3d from the specified Tuple3f.
* @param t1 the Tuple3f containing the initialization x y z data
*/
public Vector3d(Tuple3f t1)
{
super(t1);
}
/**
* Constructs and initializes a Vector3d from the specified Tuple3d.
* @param t1 the Tuple3d containing the initialization x y z data
*/
public Vector3d(Tuple3d t1)
{
super(t1);
}
/**
* Constructs and initializes a Vector3d to (0,0,0).
*/
public Vector3d()
{
super();
}
/**
* Sets this vector to the vector cross product of vectors v1 and v2.
* @param v1 the first vector
* @param v2 the second vector
*/
public final void cross(Vector3d v1, Vector3d v2)
{
double x,y;
x = v1.y*v2.z - v1.z*v2.y;
y = v2.x*v1.z - v2.z*v1.x;
this.z = v1.x*v2.y - v1.y*v2.x;
this.x = x;
this.y = y;
}
/**
* Sets the value of this vector to the normalization of vector v1.
* @param v1 the un-normalized vector
*/
public final void normalize(Vector3d v1)
{
double norm;
norm = 1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z);
this.x = v1.x*norm;
this.y = v1.y*norm;
this.z = v1.z*norm;
}
/**
* Normalizes this vector in place.
*/
public final void normalize()
{
double norm;
norm = 1.0/Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
this.x *= norm;
this.y *= norm;
this.z *= norm;
}
/**
* Returns the dot product of this vector and vector v1.
* @param v1 the other vector
* @return the dot product of this and v1
*/
public final double dot(Vector3d v1)
{
return (this.x*v1.x + this.y*v1.y + this.z*v1.z);
}
/**
* Returns the squared length of this vector.
* @return the squared length of this vector
*/
public final double lengthSquared()
{
return (this.x*this.x + this.y*this.y + this.z*this.z);
}
/**
* Returns the length of this vector.
* @return the length of this vector
*/
public final double length()
{
return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
}
/**
* Returns the angle in radians between this vector and the vector
* parameter; the return value is constrained to the range [0,PI].
* @param v1 the other vector
* @return the angle in radians in the range [0,PI]
*/
public final double angle(Vector3d v1)
{
double vDot = this.dot(v1) / ( this.length()*v1.length() );
if( vDot < -1.0) vDot = -1.0;
if( vDot > 1.0) vDot = 1.0;
return((double) (Math.acos( vDot )));
}
}

View File

@@ -0,0 +1,205 @@
/*
* $RCSfile$
*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
* $Revision: 127 $
* $Date: 2008-02-28 21:18:51 +0100 (Thu, 28 Feb 2008) $
* $State$
*/
package com.volmit.iris.util.vec;
import java.lang.Math;
/**
* A 3-element vector that is represented by single-precision floating point
* x,y,z coordinates. If this value represents a normal, then it should
* be normalized.
*
*/
public class Vector3f extends Tuple3f implements java.io.Serializable {
// Combatible with 1.1
static final long serialVersionUID = -7031930069184524614L;
/**
* Constructs and initializes a Vector3f from the specified xyz coordinates.
* @param x the x coordinate
* @param y the y coordinate
* @param z the z coordinate
*/
public Vector3f(float x, float y, float z)
{
super(x,y,z);
}
/**
* Constructs and initializes a Vector3f from the array of length 3.
* @param v the array of length 3 containing xyz in order
*/
public Vector3f(float[] v)
{
super(v);
}
/**
* Constructs and initializes a Vector3f from the specified Vector3f.
* @param v1 the Vector3f containing the initialization x y z data
*/
public Vector3f(Vector3f v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector3f from the specified Vector3d.
* @param v1 the Vector3d containing the initialization x y z data
*/
public Vector3f(Vector3d v1)
{
super(v1);
}
/**
* Constructs and initializes a Vector3f from the specified Tuple3f.
* @param t1 the Tuple3f containing the initialization x y z data
*/
public Vector3f(Tuple3f t1) {
super(t1);
}
/**
* Constructs and initializes a Vector3f from the specified Tuple3d.
* @param t1 the Tuple3d containing the initialization x y z data
*/
public Vector3f(Tuple3d t1) {
super(t1);
}
/**
* Constructs and initializes a Vector3f to (0,0,0).
*/
public Vector3f()
{
super();
}
/**
* Returns the squared length of this vector.
* @return the squared length of this vector
*/
public final float lengthSquared()
{
return (this.x*this.x + this.y*this.y + this.z*this.z);
}
/**
* Returns the length of this vector.
* @return the length of this vector
*/
public final float length()
{
return (float)
Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
}
/**
* Sets this vector to be the vector cross product of vectors v1 and v2.
* @param v1 the first vector
* @param v2 the second vector
*/
public final void cross(Vector3f v1, Vector3f v2)
{
float x,y;
x = v1.y*v2.z - v1.z*v2.y;
y = v2.x*v1.z - v2.z*v1.x;
this.z = v1.x*v2.y - v1.y*v2.x;
this.x = x;
this.y = y;
}
/**
* Computes the dot product of this vector and vector v1.
* @param v1 the other vector
* @return the dot product of this vector and v1
*/
public final float dot(Vector3f v1)
{
return (this.x*v1.x + this.y*v1.y + this.z*v1.z);
}
/**
* Sets the value of this vector to the normalization of vector v1.
* @param v1 the un-normalized vector
*/
public final void normalize(Vector3f v1)
{
float norm;
norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z));
this.x = v1.x*norm;
this.y = v1.y*norm;
this.z = v1.z*norm;
}
/**
* Normalizes this vector in place.
*/
public final void normalize()
{
float norm;
norm = (float)
(1.0/Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z));
this.x *= norm;
this.y *= norm;
this.z *= norm;
}
/**
* Returns the angle in radians between this vector and the vector
* parameter; the return value is constrained to the range [0,PI].
* @param v1 the other vector
* @return the angle in radians in the range [0,PI]
*/
public final float angle(Vector3f v1)
{
double vDot = this.dot(v1) / ( this.length()*v1.length() );
if( vDot < -1.0) vDot = -1.0;
if( vDot > 1.0) vDot = 1.0;
return((float) (Math.acos( vDot )));
}
}