I supose its not a big deal if i just write four instructions instead of using a loop:
1 2 3 4
| v.set0(x) v.set1(y) v.set2(z) v.set3(w) |
Does anyone know if its still worth to use fields instead of arrays for vectors?
This would simplify a lot of things:
1 2 3
| class floatTuple { float[] components; } |
Im making a python script to generate java source for tuples similar to the java.vecmath ones. Possible primitive types are byte, short, int, long, float, double combined with dimensions 1D,2D,3D,4D,9D (for 3x3 matrices), 16D (for 4x4 matrices). This gives a total of 6x6=36 different classes. What im doing is just using python to do what java templates don't do.
Each class supports basic tuple operations +, -, neg, abs, combine, literals, slicing, conversion, coercing, construction, import/export data from/to buffers and arrays, etc. All classes final for fastest access.
For linear algebra operations these would in a LinAlg final class factory with a method: LinAlg la = LinAlg.default() that works just like Math. Another class i would have to generate to work with 36 different tuples.
1 2 3 4 5 6 7
| LinAlg la = LinAlg.default(); float4D v1 = new float4D(1, 0, 0, 0); float4D v2 = new float4D(0, 1, 0, 0); float4D v3; float16D m; v3 = la.cross(v1,v2) rot = la.makeRotMatrix(alpha,v1,beta,v2,gama,v3) |
This stuff is almost like machine code instructions but it is the fast and better looking i can get, while keeping classes final.