📄 matrix3d.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name: Matrix3D.java
package se.southend.drops.math;
import java.io.PrintStream;
public class Matrix3D
{
public Matrix3D()
{
}
public static double[] create()
{
double result[] = new double[16];
identity(result);
return result;
}
public static void identity(double matrix[])
{
matrix[1] = matrix[2] = matrix[3] = matrix[4] = matrix[6] = matrix[7] = matrix[8] = matrix[9] = matrix[11] = matrix[12] = matrix[13] = matrix[14] = 0.0D;
matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.0D;
}
public static void multiply(double matrixA[], double matrixB[])
{
for(int i = 0; i < 16; i += 4)
{
for(int j = 0; j < 4; j++)
tempMatrix[i + j] = matrixA[i + 0] * matrixB[0 + j] + matrixA[i + 1] * matrixB[4 + j] + matrixA[i + 2] * matrixB[8 + j] + matrixA[i + 3] * matrixB[12 + j];
}
System.arraycopy(tempMatrix, 0, matrixA, 0, matrixA.length);
}
public static void transform(double vector[], double matrix[])
{
tempVector[0] = matrix[0] * vector[0] + matrix[1] * vector[1] + matrix[2] * vector[2] + matrix[3];
tempVector[1] = matrix[4] * vector[0] + matrix[5] * vector[1] + matrix[6] * vector[2] + matrix[7];
tempVector[2] = matrix[8] * vector[0] + matrix[9] * vector[1] + matrix[10] * vector[2] + matrix[11];
tempVector[3] = 1.0D;
System.arraycopy(tempVector, 0, vector, 0, vector.length);
}
public static void translate(double matrix[], double a, double b, double c)
{
translationMatrix[3] = a;
translationMatrix[7] = b;
translationMatrix[11] = c;
multiply(matrix, translationMatrix);
}
public static void rotateX(double matrix[], double theta)
{
double c = Math.cos(theta);
double s = Math.sin(theta);
xRotationMatrix[5] = c;
xRotationMatrix[9] = s;
xRotationMatrix[6] = -s;
xRotationMatrix[10] = c;
multiply(matrix, xRotationMatrix);
}
public static void rotateY(double matrix[], double theta)
{
double c = Math.cos(theta);
double s = Math.sin(theta);
yRotationMatrix[0] = c;
yRotationMatrix[2] = s;
yRotationMatrix[8] = -s;
yRotationMatrix[10] = c;
multiply(matrix, yRotationMatrix);
}
public static void rotateZ(double matrix[], double theta)
{
double c = Math.cos(theta);
double s = Math.sin(theta);
zRotationMatrix[0] = c;
zRotationMatrix[1] = -s;
zRotationMatrix[4] = s;
zRotationMatrix[5] = c;
multiply(matrix, zRotationMatrix);
}
public static void scale(double matrix[], double a, double b, double c)
{
scalingMatrix[0] = a;
scalingMatrix[5] = b;
scalingMatrix[10] = c;
multiply(matrix, scalingMatrix);
}
public static void copy(double src[], double dest[])
{
System.arraycopy(src, 0, dest, 0, src.length);
}
public static void print(double matrix[])
{
for(int i = 0; i < 16; i += 4)
System.out.println("[" + matrix[i + 0] + " " + matrix[i + 1] + " " + matrix[i + 2] + " " + matrix[i + 3] + "]");
System.out.println("");
}
public static final int X = 1;
public static final int Y = 2;
public static final int Z = 4;
private static double translationMatrix[] = create();
private static double xRotationMatrix[] = create();
private static double yRotationMatrix[] = create();
private static double zRotationMatrix[] = create();
private static double scalingMatrix[] = create();
private static double tempMatrix[] = new double[16];
private static double tempVector[] = new double[4];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -