home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-05 | 1.9 KB | 67 lines |
- // Rotation Matrix class
-
- // Written by Bernie Roehl, November 1996
-
- package utility;
-
- public class Matrix {
- protected float[][] values;
-
- public float getElement(int row, int column) { return values[row][column]; }
-
- public Matrix() {
- values = new float[3][3];
- identity();
- }
-
- public void dump() {
- for (int i = 0; i < 3; ++i) {
- for (int j = 0; j < 3; ++j)
- System.out.print("\t" + values[i][j]);
- System.out.println();
- }
- }
-
- public void identity() {
- for (int i = 0; i < 3; ++i)
- for (int j = 0; j < 3; ++j)
- values[i][j] = (i == j) ? 1 : 0;
- }
-
- public Matrix multiply(Matrix mat) {
- Matrix result = new Matrix();
- for (int i = 0; i < 3; ++i)
- for (int j = 0; j < 3; ++j) {
- result.values[i][j] = 0;
- for (int k = 0; k < 3; ++k)
- result.values[i][j] += values[i][k] * mat.values[k][j];
- }
- return result;
- }
-
- public static Matrix xrot(float angle) {
- Matrix result = new Matrix();
- float a = angle * (float) Math.PI / 180;
- result.values[1][1] = result.values[2][2] = (float) Math.cos(a);
- result.values[1][2] = -(result.values[2][1] = (float) Math.sin(a));
- return result;
- }
-
- public static Matrix yrot(float angle) {
- Matrix result = new Matrix();
- float a = angle * (float) Math.PI / 180;
- result.values[0][0] = result.values[2][2] = (float) Math.cos(a);
- result.values[0][2] = -(result.values[2][0] = (float) Math.sin(a));
- return result;
- }
-
- public static Matrix zrot(float angle) {
- Matrix result = new Matrix();
- float a = angle * (float) Math.PI / 180;
- result.values[0][0] = result.values[1][1] = (float) Math.cos(a);
- result.values[1][0] = -(result.values[0][1] = (float) Math.sin(a));
- return result;
- }
-
- }
-