Here is the code. This code uses arrays that are declared static (less memory allocations). It is not thread-safe at all. You could infer the thread- safe version of this method through the comments.
private static final float[] _tempGluUnProjectData = new float[40]; private static final int _temp_m = 0; private static final int _temp_A = 16; private static final int _temp_in = 32; private static final int _temp_out = 36; public static int gluUnProject(float winx, float winy, float winz, float model[], int offsetM, float proj[], int offsetP, int viewport[], int offsetV, float[] xyz, int offset) { /* Transformation matrices */ // float[] m = new float[16], A = new float[16]; // float[] in = new float[4], out = new float[4]; /* Normalize between -1 and 1 */ _tempGluUnProjectData[_temp_in] = (winx - viewport[offsetV]) * 2f / viewport[offsetV+2] - 1.0f; _tempGluUnProjectData[_temp_in+1] = (winy - viewport[offsetV+1]) * 2f / viewport[offsetV+3] - 1.0f; _tempGluUnProjectData[_temp_in+2] = 2f * winz - 1.0f; _tempGluUnProjectData[_temp_in+3] = 1.0f; /* Get the inverse */ android.opengl.Matrix.multiplyMM(_tempGluUnProjectData, _temp_A, proj, offsetP, model, offsetM); android.opengl.Matrix.invertM(_tempGluUnProjectData, _temp_m, _tempGluUnProjectData, _temp_A); android.opengl.Matrix.multiplyMV(_tempGluUnProjectData, _temp_out, _tempGluUnProjectData, _temp_m, _tempGluUnProjectData, _temp_in); if (_tempGluUnProjectData[_temp_out+3] == 0.0) return GL10.GL_FALSE; xyz[offset] = _tempGluUnProjectData[_temp_out ] / _tempGluUnProjectData[_temp_out+3]; xyz[offset+1] = _tempGluUnProjectData[_temp_out+1] / _tempGluUnProjectData[_temp_out+3]; xyz[offset+2] = _tempGluUnProjectData[_temp_out+2] / _tempGluUnProjectData[_temp_out+3]; return GL10.GL_TRUE; } On Feb 26, 1:22 pm, focuser <linto...@gmail.com> wrote: > hmm, thanks a lot for replies from both of you! > > It's surprising though that gluUnProject didn't work. > > There is a comment in MatrixTrackingGL.java > > * Note: the actual matrix may differ from the retrieved matrix, due > * to differences in the way the math is implemented by > GLMatrixWrapper > * as compared to the way the math is implemented by the OpenGL ES > * driver. > > Maybe that's why? > > On Feb 26, 8:59 am, Streets Of Boston <flyingdutc...@gmail.com> wrote: > > > > > I had similar issues: > > - Where to obtain the model-view and the project-view matrices. > > - gluUnProject did not seem to work... it returned results i did not > > expect. > > > I solved these issues: > > - I borrowed code from the MatrixGrabber.java you can find in the "API > > Demos" examples. This class contains methods to obtain the project and > > model view matrices. > > - I wrote my own gluUnProject, based upon a C-implementation i found > > on the internet. > > > Gotohttp://soft.antonspaans.comandleave me a message there and i > > can send you the java source code for gluUnProject. > > > On Feb 24, 8:10 pm, focuser <linto...@gmail.com> wrote: > > > > Hi, > > > > I'm trying to convert window coordinates to object coordinates. > > > There's a gluUnProject in GLU class, which requires current modelview, > > > projection matrices and viewport. > > > > My question is how to get those matrices? I tried gl.glGetIntegerv > > > (GL11.GL_MODELVIEW_MATRIX_FLOAT_AS_INT_BITS_OES, model, 0); and > > > ((GL11) gl).glGetFloatv(GL11.GL_MODELVIEW_MATRIX, modelf, 0); > > > > but the first one returns an array of zeros, and the other one just > > > shows an "method not implemented" error. > > > > Is gluUnProject the correct method for this purpose (i.e. window > > > coordinates --> object coordinates) ?- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---