Robert, first of all thanks for your time and kindness. The problem
for me is not drawing my scene. In fact, the scene is done. I'm going
to try being more explicit:

First of all, I set the projection matrix with:
  near_height = 1;
  zNear = 1;
  zFar = 100;
  window_height = height;
  window_width = width;

  gl.glViewport(0, 0, width, height);   //Reset The Current Viewport
  gl.glMatrixMode(GL10.GL_PROJECTION);  //Select The Projection Matrix
  gl.glLoadIdentity();                                  //Reset The Projection 
Matrix
  ratio = (float) width / height;
  Matrix.orthoM(orthoProjectionMatrix, 0, -near_height * ratio,
near_height * ratio, -near_height, near_height, zNear, zFar); //I get
the Projection Matrix here
  gl.glOrthof(-near_height * ratio, near_height * ratio, -near_height,
near_height, zNear, zFar);

Later, I get the rotation matrix and remap it with the lines:
  SensorManager.getRotationMatrix(rotationMatrix, null,
mAccelerometerValues, mMagneticValues);
  SensorManager.remapCoordinateSystem(rotationMatrix,
SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X,
remappedRotationMatrix);
  gl.glMatrixMode(GL10.GL_MODELVIEW);
  gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  gl.glLoadIdentity();                                  //Reset The Current 
Modelview Matrix
  gl.glLoadMatrixf(remappedRotationMatrix, 0);

Then, I draw all wich I want. Don't worry about the ray, it is well
done. I followed this page instructions <http://www.opengl.org/
resources/faq/technical/selection.htm>. I use glPushMatrix and
glPopMatrix, but as you can think it is not necessary. I have the
modelview untouched in remappedRotationMatrix.

My problem: Once I have finished drawing objects, I want to know if
there is some of them painted in the screen when I point an exact
place with the phone. I'm OK to choose an only one object if it is so
easier. With the next instruction:

GLU.gluProject(pos3DdelPuntoInteres[0], pos3DdelPuntoInteres[1],
pos3DdelPuntoInteres[2], remappedRotationMatrix, 0,
orthoProjectionMatrix, 0,new int[] {0,0,window_width,window_height},
0, prueba, 0);

I should get the screen coords of the pos3DdelPuntoInteres vector in
the prueba one. But if I see it with a Log, I can't deduce any
connection between this values and the screen. In the poing signed by
pos3DdelPuntoInteres there is an icon, if I move the phone so place
the icon in the upper left corner, then the first coord of prueba is
0, but no one else. In fact, it is impossible get an 0,0 position in
prueba.

Alternatively, I've found that if I multiply the modelview by
pos3DdelPuntoInteres, one of the components of prueba takes values
from 1 to -1 if the icon is displayed on the screen and out of this
range if not. The problem is that this value only refers to the x axis
of the screen and not to the y one. The others two values of prueba
seems to refer the angle of the yaw. Knows someone about a way of
calculate the position of the y axis like with de x ones using the
modelview matrix, so I can control if the object is on the screen?

Thanks.

The problem

On 10 mayo, 22:13, Robert Green <rbgrn....@gmail.com> wrote:
> If you're doing this to set up and draw your scene:
>
> gl.glMatrixMode(GL10.GL_PROJECTION);
> gl.glLoadIdentity();
> GLU.gluPerspective(gl, FOV, viewAspectRatio, zNear, zFar);
> // **get or recreate this matrix for the unproject projection
> gl.glMatrixMode(GL10.GL_MODELVIEW);
> gl.glLoadIdentity();
> GLU.gluLookAt(gl, pos.x, pos.y, pos.z, lookAt.x, lookAt.y, lookAt.z,
> upVec.x, upVec.y, upVec.z);
> // **get or recreate this matrix for the unproject modelview
>
> // for each object
> gl.glPushMatrix();
> // transform/rotate/scale to match collision data - do not use this
> matrix for unproject.
> // draw
> gl.glPopMatrix();
>
> then using GLU.gluUnProject with those same matrices that I pointed
> out (projection and modelview) will return the correct point in world
> space which should be the same coordinate system as your collision
> data.   After that you just need to use ((normalize(lookAt - pos) *
> farZ) + the unproject point) and you have your ray.
>
> On May 10, 1:24 pm, Alfonso <alfonsocris...@gmail.com> wrote:
>
>
>
> > I've got that collision detection system implemented, yet. And I'm
> > agree to use glUnproject as the best achoice. My problem is that I
> > remap the modelview matrix with the sensors and when I rotate the
> > phone, change the coords of the screen returned by glUnproject. Even
> > if I keep the object in the same place of the screen. Furthermore, I
> > don't understand why it doesn't return values according to the given
> > viewport. Because of all this I was looking for alternatives, but if
> > you explain me what's the matter with glUnproject, I'll be really
> > pleasent.
>
> > Thanks you very much for this answer and (I hope) for the next one.
>
> > On 10 mayo, 19:11, Robert Green <rbgrn....@gmail.com> wrote:
>
> > > What are you trying to do?
>
> > > glReadPixels is a pipeline stall - it will slow everything down.  If
> > > you want to check to see if an object has been touched, use a
> > > collision detection system, unproject the touch point into a ray and
> > > get the closest item that intersects with that ray.  It's actually
> > > easier, more reliable and faster.
>
> > > On May 10, 10:16 am, Alfonso <alfonsocris...@gmail.com> wrote:
>
> > > > glReadPixels is too slow, so I need another way. Without testing
> > > > object by object, Is there any other way?
>
> > > > Thanks you very much
>
> > > > --
> > > > 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 
> > > > athttp://groups.google.com/group/android-developers?hl=en
>
> > > --
> > > 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 
> > > athttp://groups.google.com/group/android-developers?hl=en
>
> > --
> > 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 
> > athttp://groups.google.com/group/android-developers?hl=en
>
> --
> 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 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
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

Reply via email to