Fixed some math functions
This commit is contained in:
parent
14f6927357
commit
636f3353ac
|
|
@ -19,6 +19,7 @@ import static org.lwjgl.opengl.GL11.glEnable;
|
||||||
import static org.lwjgl.opengl.GL11.glViewport;
|
import static org.lwjgl.opengl.GL11.glViewport;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
|
import org.lwjgl.opengl.GL33;
|
||||||
|
|
||||||
public class GraphicsHelpers
|
public class GraphicsHelpers
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -102,13 +102,12 @@ public class Matrix4 implements IBdfClassManager
|
||||||
|
|
||||||
public static Vec3d multiply(Matrix4 mat, Vec3d vec)
|
public static Vec3d multiply(Matrix4 mat, Vec3d vec)
|
||||||
{
|
{
|
||||||
Vec3d result = new Vec3d(0, 0, 0);
|
double x = mat.get(0, 0) * vec.x + mat.get(1, 0) * vec.y + mat.get(2, 0) * vec.z + mat.get(3, 0);
|
||||||
|
double y = mat.get(0, 1) * vec.x + mat.get(1, 1) * vec.y + mat.get(2, 1) * vec.z + mat.get(3, 1);
|
||||||
|
double z = mat.get(0, 2) * vec.x + mat.get(1, 2) * vec.y + mat.get(2, 2) * vec.z + mat.get(3, 2);
|
||||||
|
double m = mat.get(0, 3) * vec.x + mat.get(1, 3) * vec.y + mat.get(2, 3) * vec.z + mat.get(3, 3);
|
||||||
|
|
||||||
result.x = mat.get(0, 0) * vec.x + mat.get(1, 0) * vec.y + mat.get(2, 0) * vec.z + mat.get(3, 0);
|
return new Vec3d(x / m, y / m, z / m);
|
||||||
result.y = mat.get(0, 1) * vec.x + mat.get(1, 1) * vec.y + mat.get(2, 1) * vec.z + mat.get(3, 1);
|
|
||||||
result.z = mat.get(0, 2) * vec.x + mat.get(1, 2) * vec.y + mat.get(2, 2) * vec.z + mat.get(3, 2);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Matrix4 transform(Vec3d position, Vec3d rotation, Vec3d scale)
|
public static Matrix4 transform(Vec3d position, Vec3d rotation, Vec3d scale)
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,8 @@ public class Vec2d implements IBdfClassManager
|
||||||
return new Vec2d(x, y);
|
return new Vec2d(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double squareDistance(Vec2d other)
|
public double squareDistance(Vec2d other) {
|
||||||
{
|
return Math.abs(other.x - x) + Math.abs(other.y - y);
|
||||||
double dx = MathHelpers.positive(other.x - x);
|
|
||||||
double dy = MathHelpers.positive(other.y - y);
|
|
||||||
return MathHelpers.biggest(dx, dy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec2i toInt() {
|
public Vec2i toInt() {
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,8 @@ public class Vec2i implements IBdfClassManager
|
||||||
return new Vec2i(x, y);
|
return new Vec2i(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double squareDistance(Vec2i other)
|
public double squareDistance(Vec2i other) {
|
||||||
{
|
return Math.abs(other.x - x) + Math.abs(other.y - y);
|
||||||
int dx = MathHelpers.positive(other.x - x);
|
|
||||||
int dy = MathHelpers.positive(other.y - y);
|
|
||||||
return MathHelpers.biggest(dx, dy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec2d toDouble() {
|
public Vec2d toDouble() {
|
||||||
|
|
|
||||||
|
|
@ -86,15 +86,8 @@ public class Vec3d implements IBdfClassManager
|
||||||
return new Vec3d(x, y, z);
|
return new Vec3d(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double squareDistance(Vec3d other)
|
public double squareDistance(Vec3d other) {
|
||||||
{
|
return Math.abs(other.x - x) + Math.abs(other.y - y) + Math.abs(other.z - z);
|
||||||
double dx = MathHelpers.positive(other.x - x);
|
|
||||||
double dy = MathHelpers.positive(other.y - y);
|
|
||||||
double dz = MathHelpers.positive(other.z - z);
|
|
||||||
|
|
||||||
if(dx > dy) return dx;
|
|
||||||
if(dy > dz) return dy;
|
|
||||||
else return dz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3i toInt() {
|
public Vec3i toInt() {
|
||||||
|
|
|
||||||
|
|
@ -105,15 +105,8 @@ public class Vec3i implements IBdfClassManager
|
||||||
return new Vec3i(x, y, z);
|
return new Vec3i(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int squareDistance(Vec3i other)
|
public int squareDistance(Vec3i other) {
|
||||||
{
|
return Math.abs(other.x - x) + Math.abs(other.y - y) + Math.abs(other.z - z);
|
||||||
int dx = MathHelpers.positive(other.x - x);
|
|
||||||
int dy = MathHelpers.positive(other.y - y);
|
|
||||||
int dz = MathHelpers.positive(other.z - z);
|
|
||||||
|
|
||||||
if(dx > dy) return dx;
|
|
||||||
if(dy > dz) return dy;
|
|
||||||
else return dz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3d toDouble() {
|
public Vec3d toDouble() {
|
||||||
|
|
|
||||||
|
|
@ -108,17 +108,8 @@ public class Vec4d implements IBdfClassManager
|
||||||
return new Vec4d(x, y, z, m);
|
return new Vec4d(x, y, z, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double squareDistance(Vec4d other)
|
public double squareDistance(Vec4d other) {
|
||||||
{
|
return Math.abs(other.x - x) + Math.abs(other.y - y) + Math.abs(other.z - z) + Math.abs(other.m - m);
|
||||||
double dx = MathHelpers.positive(other.x - x);
|
|
||||||
double dy = MathHelpers.positive(other.y - y);
|
|
||||||
double dz = MathHelpers.positive(other.z - z);
|
|
||||||
double dm = MathHelpers.positive(other.m - m);
|
|
||||||
|
|
||||||
if(dx > dy) return dx;
|
|
||||||
if(dy > dz) return dy;
|
|
||||||
if(dz > dm) return dz;
|
|
||||||
else return dm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec4i toInt() {
|
public Vec4i toInt() {
|
||||||
|
|
|
||||||
|
|
@ -133,17 +133,8 @@ public class Vec4i implements IBdfClassManager
|
||||||
return new Vec4i(x, y, z, m);
|
return new Vec4i(x, y, z, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int squareDistance(Vec4i other)
|
public int squareDistance(Vec4i other) {
|
||||||
{
|
return Math.abs(other.x - x) + Math.abs(other.y - y) + Math.abs(other.z - z) + Math.abs(other.m - m);
|
||||||
int dx = MathHelpers.positive(other.x - x);
|
|
||||||
int dy = MathHelpers.positive(other.y - y);
|
|
||||||
int dz = MathHelpers.positive(other.z - z);
|
|
||||||
int dm = MathHelpers.positive(other.m - m);
|
|
||||||
|
|
||||||
if(dx > dy) return dx;
|
|
||||||
if(dy > dz) return dy;
|
|
||||||
if(dz > dm) return dz;
|
|
||||||
else return dm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec4d toDouble() {
|
public Vec4d toDouble() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue