Java Code Examples for org.lwjgl.util.vector.Vector3f#cross()

The following examples show how to use org.lwjgl.util.vector.Vector3f#cross() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
private void fillNormal(int[] faceData) {
	Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]);
	Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]);
	Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]);
	Vector3f result1 = new Vector3f();
	Vector3f result2 = new Vector3f();
	Vector3f result3 = new Vector3f();
	Vector3f.sub(v1, t, result1);
	t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]);
	Vector3f.sub(v2, t, result2);
	Vector3f.cross(result2, result1, result3);
	result3.normalise();

	int x = ((byte) (result3.x * 127)) & 0xFF;
	int y = ((byte) (result3.y * 127)) & 0xFF;
	int z = ((byte) (result3.z * 127)) & 0xFF;
	for (int i = 0; i < 4; i++) {
		faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10);
	}
}
 
Example 2
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
private void fillNormal(int[] faceData) {
	Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]);
	Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]);
	Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]);
	Vector3f result1 = new Vector3f();
	Vector3f result2 = new Vector3f();
	Vector3f result3 = new Vector3f();
	Vector3f.sub(v1, t, result1);
	t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]);
	Vector3f.sub(v2, t, result2);
	Vector3f.cross(result2, result1, result3);
	result3.normalise();

	int x = ((byte) (result3.x * 127)) & 0xFF;
	int y = ((byte) (result3.y * 127)) & 0xFF;
	int z = ((byte) (result3.z * 127)) & 0xFF;
	for (int i = 0; i < 4; i++) {
		faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10);
	}
}
 
Example 3
Source File: Trackball.java    From OpenModsLib with MIT License 6 votes vote down vote up
private Matrix4f getTransform(float mouseX, float mouseY) {
	Preconditions.checkNotNull(dragStart, "Draging not started");
	Vector3f current = calculateSpherePoint(mouseX, mouseY);

	float dot = Vector3f.dot(dragStart, current);
	if (Math.abs(dot - 1) < 0.0001) return lastTransform;

	Vector3f axis = Vector3f.cross(dragStart, current, null);

	try {
		axis.normalise();
	} catch (IllegalStateException e) { // Zero length vector
		return lastTransform;
	}

	float angle = 2 * (float)(Math.acos(dot));

	Matrix4f rotation = new Matrix4f();
	rotation.rotate(angle, axis);
	return Matrix4f.mul(rotation, lastTransform, null);

}
 
Example 4
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
private void fillNormal(int[] faceData) {
	Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]);
	Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]);
	Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]);
	Vector3f result1 = new Vector3f();
	Vector3f result2 = new Vector3f();
	Vector3f result3 = new Vector3f();
	Vector3f.sub(v1, t, result1);
	t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]);
	Vector3f.sub(v2, t, result2);
	Vector3f.cross(result2, result1, result3);
	result3.normalise();

	int x = ((byte) (result3.x * 127)) & 0xFF;
	int y = ((byte) (result3.y * 127)) & 0xFF;
	int z = ((byte) (result3.z * 127)) & 0xFF;
	for (int i = 0; i < 4; i++) {
		faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10);
	}
}
 
Example 5
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
private void fillNormal(int[] faceData) {
	Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]);
	Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]);
	Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]);
	Vector3f result1 = new Vector3f();
	Vector3f result2 = new Vector3f();
	Vector3f result3 = new Vector3f();
	Vector3f.sub(v1, t, result1);
	t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]);
	Vector3f.sub(v2, t, result2);
	Vector3f.cross(result2, result1, result3);
	result3.normalise();

	int x = ((byte) (result3.x * 127)) & 0xFF;
	int y = ((byte) (result3.y * 127)) & 0xFF;
	int z = ((byte) (result3.z * 127)) & 0xFF;
	for (int i = 0; i < 4; i++) {
		faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10);
	}
}
 
Example 6
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
private void fillNormal(int[] faceData) {
	Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]);
	Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]);
	Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]);
	Vector3f result1 = new Vector3f();
	Vector3f result2 = new Vector3f();
	Vector3f result3 = new Vector3f();
	Vector3f.sub(v1, t, result1);
	t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]);
	Vector3f.sub(v2, t, result2);
	Vector3f.cross(result2, result1, result3);
	result3.normalise();

	int x = ((byte) (result3.x * 127)) & 0xFF;
	int y = ((byte) (result3.y * 127)) & 0xFF;
	int z = ((byte) (result3.z * 127)) & 0xFF;
	for (int i = 0; i < 4; i++) {
		faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10);
	}
}
 
Example 7
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
private void fillNormal(int[] faceData) {
	Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]);
	Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]);
	Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]);
	Vector3f result1 = new Vector3f();
	Vector3f result2 = new Vector3f();
	Vector3f result3 = new Vector3f();
	Vector3f.sub(v1, t, result1);
	t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]);
	Vector3f.sub(v2, t, result2);
	Vector3f.cross(result2, result1, result3);
	result3.normalise();

	int x = ((byte) (result3.x * 127)) & 0xFF;
	int y = ((byte) (result3.y * 127)) & 0xFF;
	int z = ((byte) (result3.z * 127)) & 0xFF;
	for (int i = 0; i < 4; i++) {
		faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10);
	}
}
 
Example 8
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
public static ct a(int[] var) {
	Vector3f var1 = new Vector3f(Float.intBitsToFloat(var[0]), Float.intBitsToFloat(var[1]), Float.intBitsToFloat(var[2]));
	Vector3f var2 = new Vector3f(Float.intBitsToFloat(var[7]), Float.intBitsToFloat(var[8]), Float.intBitsToFloat(var[9]));
	Vector3f var3 = new Vector3f(Float.intBitsToFloat(var[14]), Float.intBitsToFloat(var[15]), Float.intBitsToFloat(var[16]));
	Vector3f var4 = new Vector3f();
	Vector3f var5 = new Vector3f();
	Vector3f var6 = new Vector3f();
	Vector3f.sub(var1, var2, var4);
	Vector3f.sub(var3, var2, var5);
	Vector3f.cross(var5, var4, var6);
	float var7 = (float) Math.sqrt((double) (var6.x * var6.x + var6.y * var6.y + var6.z * var6.z));
	var6.x /= var7;
	var6.y /= var7;
	var6.z /= var7;
	ct var8 = null;
	float var9 = 0.0F;
	ct[] var10 = ct.values();
	int var11 = var10.length;

	for (int var12 = 0; var12 < var11; ++var12) {
		ct var13 = var10[var12];
		di var14 = var13.n();
		Vector3f var15 = new Vector3f((float) var14.p(), (float) var14.q(), (float) var14.r());
		float var16 = Vector3f.dot(var6, var15);
		if (var16 >= 0.0F && var16 > var9) {
			var9 = var16;
			var8 = var13;
		}
	}

	if (var8 == null) {
		return ct.b;
	} else {
		return var8;
	}
}
 
Example 9
Source File: MatrixUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Matrix4f createLookAt(Vector3f eye, Vector3f lookAt, Vector3f up)
{
	Matrix4f matrix = new Matrix4f();
	matrix.setIdentity();
	
	// Create the basis vectors
	Vector3f forwards = Vector3f.sub(eye, lookAt, null);
	forwards.normalise();
	
	Vector3f right = Vector3f.cross(up, forwards, null);
	right.normalise();
	
	Vector3f actualUp = Vector3f.cross(forwards, right, null);
	actualUp.normalise();
	
	// Right vector across the top
	matrix.m00 = right.x;
	matrix.m10 = right.y;
	matrix.m20 = right.z;
	
	// Up vector across the middle row
	matrix.m01 = actualUp.x;
	matrix.m11 = actualUp.y;
	matrix.m21 = actualUp.z;
	
	// Forwards vector across the bottom row
	matrix.m02 = forwards.x;
	matrix.m12 = forwards.y;
	matrix.m22 = forwards.z;
	
	// Negative translation in the last column
	Matrix4f translation = new Matrix4f();
	translation.setIdentity();
	translation.translate(new Vector3f(-eye.x, -eye.y, -eye.z));
	
	return Matrix4f.mul(matrix, translation, null);
}
 
Example 10
Source File: Maths.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
/**
 * Calculates the normal of the triangle made from the 3 vertices. The vertices must be specified in counter-clockwise order.
 * @param vertex0
 * @param vertex1
 * @param vertex2
 * @return
 */
public static Vector3f calcNormal(Vector3f vertex0, Vector3f vertex1, Vector3f vertex2) {
	Vector3f tangentA = Vector3f.sub(vertex1, vertex0, null);
	Vector3f tangentB = Vector3f.sub(vertex2, vertex0, null);
	Vector3f normal = Vector3f.cross(tangentA, tangentB, null);
	normal.normalise();
	return normal;
}
 
Example 11
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
public static ct a(int[] var) {
	Vector3f var1 = new Vector3f(Float.intBitsToFloat(var[0]), Float.intBitsToFloat(var[1]), Float.intBitsToFloat(var[2]));
	Vector3f var2 = new Vector3f(Float.intBitsToFloat(var[7]), Float.intBitsToFloat(var[8]), Float.intBitsToFloat(var[9]));
	Vector3f var3 = new Vector3f(Float.intBitsToFloat(var[14]), Float.intBitsToFloat(var[15]), Float.intBitsToFloat(var[16]));
	Vector3f var4 = new Vector3f();
	Vector3f var5 = new Vector3f();
	Vector3f var6 = new Vector3f();
	Vector3f.sub(var1, var2, var4);
	Vector3f.sub(var3, var2, var5);
	Vector3f.cross(var5, var4, var6);
	float var7 = (float) Math.sqrt((double) (var6.x * var6.x + var6.y * var6.y + var6.z * var6.z));
	var6.x /= var7;
	var6.y /= var7;
	var6.z /= var7;
	ct var8 = null;
	float var9 = 0.0F;
	ct[] var10 = ct.values();
	int var11 = var10.length;

	for (int var12 = 0; var12 < var11; ++var12) {
		ct var13 = var10[var12];
		di var14 = var13.n();
		Vector3f var15 = new Vector3f((float) var14.p(), (float) var14.q(), (float) var14.r());
		float var16 = Vector3f.dot(var6, var15);
		if (var16 >= 0.0F && var16 > var9) {
			var9 = var16;
			var8 = var13;
		}
	}

	if (var8 == null) {
		return ct.b;
	} else {
		return var8;
	}
}
 
Example 12
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
public static cq a(int[] var) {
	Vector3f var1 = new Vector3f(Float.intBitsToFloat(var[0]), Float.intBitsToFloat(var[1]), Float.intBitsToFloat(var[2]));
	Vector3f var2 = new Vector3f(Float.intBitsToFloat(var[7]), Float.intBitsToFloat(var[8]), Float.intBitsToFloat(var[9]));
	Vector3f var3 = new Vector3f(Float.intBitsToFloat(var[14]), Float.intBitsToFloat(var[15]), Float.intBitsToFloat(var[16]));
	Vector3f var4 = new Vector3f();
	Vector3f var5 = new Vector3f();
	Vector3f var6 = new Vector3f();
	Vector3f.sub(var1, var2, var4);
	Vector3f.sub(var3, var2, var5);
	Vector3f.cross(var5, var4, var6);
	float var7 = (float) Math.sqrt((double) (var6.x * var6.x + var6.y * var6.y + var6.z * var6.z));
	var6.x /= var7;
	var6.y /= var7;
	var6.z /= var7;
	cq var8 = null;
	float var9 = 0.0F;
	cq[] var10 = cq.values();
	int var11 = var10.length;

	for (int var12 = 0; var12 < var11; ++var12) {
		cq var13 = var10[var12];
		df var14 = var13.m();
		Vector3f var15 = new Vector3f((float) var14.n(), (float) var14.o(), (float) var14.p());
		float var16 = Vector3f.dot(var6, var15);
		if (var16 >= 0.0F && var16 > var9) {
			var9 = var16;
			var8 = var13;
		}
	}

	if (var8 == null) {
		return cq.b;
	} else {
		return var8;
	}
}
 
Example 13
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
public static fa a(int[] var) {
	Vector3f var1 = new Vector3f(Float.intBitsToFloat(var[0]), Float.intBitsToFloat(var[1]), Float.intBitsToFloat(var[2]));
	Vector3f var2 = new Vector3f(Float.intBitsToFloat(var[7]), Float.intBitsToFloat(var[8]), Float.intBitsToFloat(var[9]));
	Vector3f var3 = new Vector3f(Float.intBitsToFloat(var[14]), Float.intBitsToFloat(var[15]), Float.intBitsToFloat(var[16]));
	Vector3f var4 = new Vector3f();
	Vector3f var5 = new Vector3f();
	Vector3f var6 = new Vector3f();
	Vector3f.sub(var1, var2, var4);
	Vector3f.sub(var3, var2, var5);
	Vector3f.cross(var5, var4, var6);
	float var7 = (float) Math.sqrt((double) (var6.x * var6.x + var6.y * var6.y + var6.z * var6.z));
	var6.x /= var7;
	var6.y /= var7;
	var6.z /= var7;
	fa var8 = null;
	float var9 = 0.0F;
	fa[] var10 = fa.values();
	int var11 = var10.length;

	for (int var12 = 0; var12 < var11; ++var12) {
		fa var13 = var10[var12];
		fq var14 = var13.n();
		Vector3f var15 = new Vector3f((float) var14.p(), (float) var14.q(), (float) var14.r());
		float var16 = Vector3f.dot(var6, var15);
		if (var16 >= 0.0F && var16 > var9) {
			var9 = var16;
			var8 = var13;
		}
	}

	if (var8 == null) {
		return fa.b;
	} else {
		return var8;
	}
}
 
Example 14
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
public static cv a(int[] var) {
	Vector3f var1 = new Vector3f(Float.intBitsToFloat(var[0]), Float.intBitsToFloat(var[1]), Float.intBitsToFloat(var[2]));
	Vector3f var2 = new Vector3f(Float.intBitsToFloat(var[7]), Float.intBitsToFloat(var[8]), Float.intBitsToFloat(var[9]));
	Vector3f var3 = new Vector3f(Float.intBitsToFloat(var[14]), Float.intBitsToFloat(var[15]), Float.intBitsToFloat(var[16]));
	Vector3f var4 = new Vector3f();
	Vector3f var5 = new Vector3f();
	Vector3f var6 = new Vector3f();
	Vector3f.sub(var1, var2, var4);
	Vector3f.sub(var3, var2, var5);
	Vector3f.cross(var5, var4, var6);
	float var7 = (float) Math.sqrt((double) (var6.x * var6.x + var6.y * var6.y + var6.z * var6.z));
	var6.x /= var7;
	var6.y /= var7;
	var6.z /= var7;
	cv var8 = null;
	float var9 = 0.0F;
	cv[] var10 = cv.values();
	int var11 = var10.length;

	for (int var12 = 0; var12 < var11; ++var12) {
		cv var13 = var10[var12];
		dl var14 = var13.n();
		Vector3f var15 = new Vector3f((float) var14.p(), (float) var14.q(), (float) var14.r());
		float var16 = Vector3f.dot(var6, var15);
		if (var16 >= 0.0F && var16 > var9) {
			var9 = var16;
			var8 = var13;
		}
	}

	if (var8 == null) {
		return cv.b;
	} else {
		return var8;
	}
}
 
Example 15
Source File: WaveAnimation.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final void computeRotation() {
	Vector3f.cross(wave_dir, up_vec, rot_axis);
	float length = rot_axis.length();
	rot_angle = (float)StrictMath.asin(length);
	float inv_length = 1f/length;
	rot_axis.scale(inv_length);
}
 
Example 16
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
public static cq a(int[] var) {
	Vector3f var1 = new Vector3f(Float.intBitsToFloat(var[0]), Float.intBitsToFloat(var[1]), Float.intBitsToFloat(var[2]));
	Vector3f var2 = new Vector3f(Float.intBitsToFloat(var[7]), Float.intBitsToFloat(var[8]), Float.intBitsToFloat(var[9]));
	Vector3f var3 = new Vector3f(Float.intBitsToFloat(var[14]), Float.intBitsToFloat(var[15]), Float.intBitsToFloat(var[16]));
	Vector3f var4 = new Vector3f();
	Vector3f var5 = new Vector3f();
	Vector3f var6 = new Vector3f();
	Vector3f.sub(var1, var2, var4);
	Vector3f.sub(var3, var2, var5);
	Vector3f.cross(var5, var4, var6);
	float var7 = (float) Math.sqrt((double) (var6.x * var6.x + var6.y * var6.y + var6.z * var6.z));
	var6.x /= var7;
	var6.y /= var7;
	var6.z /= var7;
	cq var8 = null;
	float var9 = 0.0F;
	cq[] var10 = cq.values();
	int var11 = var10.length;

	for (int var12 = 0; var12 < var11; ++var12) {
		cq var13 = var10[var12];
		df var14 = var13.m();
		Vector3f var15 = new Vector3f((float) var14.n(), (float) var14.o(), (float) var14.p());
		float var16 = Vector3f.dot(var6, var15);
		if (var16 >= 0.0F && var16 > var9) {
			var9 = var16;
			var8 = var13;
		}
	}

	if (var8 == null) {
		return cq.b;
	} else {
		return var8;
	}
}
 
Example 17
Source File: Arrow.java    From ldparteditor with MIT License 4 votes vote down vote up
private Matrix4f makeRotationDir(Vector3f direction) {
    final Vector3f direction2 = new Vector3f();
    Matrix4f arrowRotation = new Matrix4f();
    direction.normalise();

    // Calculate point from hesse normal plane

    int rank = 0;
    if (Math.abs(direction.x) < EPSILON)
        rank++;
    if (Math.abs(direction.y) < EPSILON)
        rank++;
    if (Math.abs(direction.z) < EPSILON)
        rank++;

    if (rank == 1) {
        if (Math.abs(direction.x) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.y) < EPSILON)
            direction2.set(0f, 1f, 0f);
        else if (Math.abs(direction.z) < EPSILON)
            direction2.set(0f, 0f, 1f);
    } else if (rank == 2) {
        if (Math.abs(direction.x) < EPSILON && Math.abs(direction.y) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.x) < EPSILON && Math.abs(direction.z) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.y) < EPSILON && Math.abs(direction.z) < EPSILON)
            direction2.set(0f, 1f, 0f);
    } else {
        direction2.setX(0f);
        direction2.setY(direction.y * 10f);
        direction2.setZ(-direction.y * 10f / direction.z);
        ;
    }

    final Vector3f xbase;
    final Vector3f ybase = new Vector3f(direction);
    final Vector3f zbase;

    xbase = Vector3f.cross(direction2, direction, null);
    zbase = Vector3f.cross(direction, xbase, null);

    xbase.normalise();
    zbase.normalise();

    arrowRotation.m00 = xbase.x;
    arrowRotation.m10 = ybase.x;
    arrowRotation.m20 = zbase.x;

    arrowRotation.m01 = xbase.y;
    arrowRotation.m11 = ybase.y;
    arrowRotation.m21 = zbase.y;

    arrowRotation.m02 = xbase.z;
    arrowRotation.m12 = ybase.z;
    arrowRotation.m22 = zbase.z;

    arrowRotation.m33 = 1f;

    return arrowRotation;
}
 
Example 18
Source File: Arc.java    From ldparteditor with MIT License 4 votes vote down vote up
private Matrix4f makeRotationDir(Vector3f direction) {
    final Vector3f direction2 = new Vector3f();
    Matrix4f arrowRotation = new Matrix4f();
    direction.normalise();

    // Calculate point from hesse normal plane

    int rank = 0;
    if (Math.abs(direction.x) < EPSILON)
        rank++;
    if (Math.abs(direction.y) < EPSILON)
        rank++;
    if (Math.abs(direction.z) < EPSILON)
        rank++;

    if (rank == 1) {
        if (Math.abs(direction.x) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.y) < EPSILON)
            direction2.set(0f, 1f, 0f);
        else if (Math.abs(direction.z) < EPSILON)
            direction2.set(0f, 0f, 1f);
    } else if (rank == 2) {
        if (Math.abs(direction.x) < EPSILON && Math.abs(direction.y) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.x) < EPSILON && Math.abs(direction.z) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.y) < EPSILON && Math.abs(direction.z) < EPSILON)
            direction2.set(0f, 1f, 0f);
    } else {
        direction2.setX(0f);
        direction2.setY(direction.y * 10f);
        direction2.setZ(-direction.y * 10f / direction.z);
        ;
    }

    final Vector3f xbase;
    final Vector3f ybase = new Vector3f(direction);
    final Vector3f zbase;

    xbase = Vector3f.cross(direction2, direction, null);
    zbase = Vector3f.cross(direction, xbase, null);

    xbase.normalise();
    zbase.normalise();

    arrowRotation.m00 = xbase.x;
    arrowRotation.m10 = ybase.x;
    arrowRotation.m20 = zbase.x;

    arrowRotation.m01 = xbase.y;
    arrowRotation.m11 = ybase.y;
    arrowRotation.m21 = zbase.y;

    arrowRotation.m02 = xbase.z;
    arrowRotation.m12 = ybase.z;
    arrowRotation.m22 = zbase.z;

    arrowRotation.m33 = 1f;

    return arrowRotation;
}
 
Example 19
Source File: GData4.java    From ldparteditor with MIT License 4 votes vote down vote up
/**
 * FOR Cut, Copy, Paste and TEXMAP ONLY!
 *
 * @param v1
 * @param v2
 * @param v3
 * @param v4
 * @param xn
 * @param yn
 * @param zn
 * @param parent
 * @param c
 */
public GData4(Vertex v1, Vertex v2, Vertex v3, Vertex v4, GData1 parent, GColour c) {

    super(parent);
    this.colourNumber = c.getColourNumber();
    this.r = c.getR();
    this.g = c.getG();
    this.b = c.getB();
    this.a = c.getA();
    this.x1 = v1.x;
    this.y1 = v1.y;
    this.z1 = v1.z;
    this.x2 = v2.x;
    this.y2 = v2.y;
    this.z2 = v2.z;
    this.x3 = v3.x;
    this.y3 = v3.y;
    this.z3 = v3.z;
    this.x4 = v4.x;
    this.y4 = v4.y;
    this.z4 = v4.z;
    this.X1 = v1.X;
    this.Y1 = v1.Y;
    this.Z1 = v1.Z;
    this.X2 = v2.X;
    this.Y2 = v2.Y;
    this.Z2 = v2.Z;
    this.X3 = v3.X;
    this.Y3 = v3.Y;
    this.Z3 = v3.Z;
    this.X4 = v4.X;
    this.Y4 = v4.Y;
    this.Z4 = v4.Z;
    final Vector3f[] normals = new Vector3f[] { new Vector3f(), new Vector3f(), new Vector3f(), new Vector3f() };
    {
        final Vector3f[] lineVectors = new Vector3f[] { new Vector3f(), new Vector3f(), new Vector3f(), new Vector3f() };
        Vector3f.sub(new Vector3f(v2.x, v2.y, v2.z), new Vector3f(v1.x, v1.y, v1.z), lineVectors[0]);
        Vector3f.sub(new Vector3f(v3.x, v3.y, v3.z), new Vector3f(v2.x, v2.y, v2.z), lineVectors[1]);
        Vector3f.sub(new Vector3f(v4.x, v4.y, v4.z), new Vector3f(v3.x, v3.y, v3.z), lineVectors[2]);
        Vector3f.sub(new Vector3f(v1.x, v1.y, v1.z), new Vector3f(v4.x, v4.y, v4.z), lineVectors[3]);
        Vector3f.cross(lineVectors[0], lineVectors[1], normals[0]);
        Vector3f.cross(lineVectors[1], lineVectors[2], normals[1]);
        Vector3f.cross(lineVectors[2], lineVectors[3], normals[2]);
        Vector3f.cross(lineVectors[3], lineVectors[0], normals[3]);
    }
    Vector3f normal = new Vector3f();
    for (int i = 0; i < 4; i++) {
        Vector3f.add(normals[i], normal, normal);
    }
    this.xn = -normal.x;
    this.yn = -normal.y;
    this.zn = -normal.z;

}
 
Example 20
Source File: ArcInv.java    From ldparteditor with MIT License 4 votes vote down vote up
private Matrix4f makeRotationDir(Vector3f direction) {
    final Vector3f direction2 = new Vector3f();
    Matrix4f arrowRotation = new Matrix4f();
    direction.normalise();

    // Calculate point from hesse normal plane

    int rank = 0;
    if (Math.abs(direction.x) < EPSILON)
        rank++;
    if (Math.abs(direction.y) < EPSILON)
        rank++;
    if (Math.abs(direction.z) < EPSILON)
        rank++;

    if (rank == 1) {
        if (Math.abs(direction.x) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.y) < EPSILON)
            direction2.set(0f, 1f, 0f);
        else if (Math.abs(direction.z) < EPSILON)
            direction2.set(0f, 0f, 1f);
    } else if (rank == 2) {
        if (Math.abs(direction.x) < EPSILON && Math.abs(direction.y) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.x) < EPSILON && Math.abs(direction.z) < EPSILON)
            direction2.set(1f, 0f, 0f);
        else if (Math.abs(direction.y) < EPSILON && Math.abs(direction.z) < EPSILON)
            direction2.set(0f, 1f, 0f);
    } else {
        direction2.setX(0f);
        direction2.setY(direction.y * 10f);
        direction2.setZ(-direction.y * 10f / direction.z);
        ;
    }

    final Vector3f xbase;
    final Vector3f ybase = new Vector3f(direction);
    final Vector3f zbase;

    xbase = Vector3f.cross(direction2, direction, null);
    zbase = Vector3f.cross(direction, xbase, null);

    xbase.normalise();
    zbase.normalise();

    arrowRotation.m00 = xbase.x;
    arrowRotation.m10 = ybase.x;
    arrowRotation.m20 = zbase.x;

    arrowRotation.m01 = xbase.y;
    arrowRotation.m11 = ybase.y;
    arrowRotation.m21 = zbase.y;

    arrowRotation.m02 = xbase.z;
    arrowRotation.m12 = ybase.z;
    arrowRotation.m22 = zbase.z;

    arrowRotation.m33 = 1f;

    return arrowRotation;
}