00001 package edu.tum.cs.vis.model.util; 00002 00003 import javax.vecmath.Point3f; 00004 00011 public abstract class DrawObject { 00015 public Point3f position[]; 00016 00027 public void translate(float x, float y, float z) { 00028 for (int v = 0; v < position.length; v++) { 00029 position[v].x += x; 00030 position[v].y += y; 00031 position[v].z += z; 00032 } 00033 } 00034 00041 public void scale(float factor) { 00042 for (int v = 0; v < position.length; v++) { 00043 position[v].x *= factor; 00044 position[v].y *= factor; 00045 position[v].z *= factor; 00046 } 00047 } 00048 00053 public void transform(float[][] matrix) { 00054 for (int v = 0; v < position.length; v++) { 00055 float[] newPos = new float[4]; 00056 for (int row = 0; row < 4; row++) { 00057 newPos[row] = position[v].x * matrix[row][0] + position[v].y 00058 * matrix[row][1] + position[v].z * matrix[row][2] 00059 + matrix[row][3]; 00060 } 00061 position[v].x = newPos[0] / newPos[3]; 00062 position[v].y = newPos[1] / newPos[3]; 00063 position[v].z = newPos[2] / newPos[3]; 00064 } 00065 } 00066 00072 public static float[][] MatrixMultiply(float mat1[][], float mat2[][]) 00073 { 00074 int x = mat1.length; 00075 int y = mat2.length; 00076 float result[][] = new float[x][y]; 00077 00078 for (int i = 0; i < x; i++) { 00079 for (int j = 0; j < y - 1; j++) { 00080 for (int k = 0; k < y; k++) { 00081 00082 result[i][j] += mat1[i][k] * mat2[k][j]; 00083 } 00084 } 00085 } 00086 00087 return result; 00088 } 00089 }