Say I want to use the following method:
unProject(double winx, double winy, double winz, int modelMatrix, int projMatrix, int viewport, int objx, int objy, int objz);
The last 3 parameters and pointers to doubles. One way to use this method is to create 3 different one double long buffers, get their addresses and give them to unProject. Is there a way to use just one? For example, do something like this:
DoubleBuffer xyz = ByteBuffer.allocateDirect(3 * 8).order(ByteOrder.nativeOrder()).asDoubleBuffer();
int xyzP = Sys.getDirectBufferAddress(xyz);
and then:
unProject(winx, winy, winz, modelMatrix, projMatrix, viewport, xyzP, xyzP + 2, xyzP + 4);
where xyzP, the address of the first double
where xyzP + 2, the address of the second double
where xyzP + 4, the address of the third double
I have tested this and of course it didn’t work. Actually, it run, but it didn’t work correctly. Could something like this work, use one buffer’s starting address to get offsets on the same buffer? Am I correct to assume that the second double is 2 addresses (2 * 32 bits = 64 bits) away from the first one? I’m asking this because I’m afraid of the overhead of many Buffers (should I?) and besides my code gets really ugly. It would be a lot easier and cleaner to use xyz.get(double_array[3]) than have three different buffers and use buffer.get() three times. It would be faster too. Any suggestions?