Implementing transformations fot Selection

Hi All

I am writting a program that presents some 3D objects. It allows the user to rotate and translate object in space and also to select an object. Currently I use selection and feedback.
I thought if I could know the location in space of each primitive after transformation, i can gluUnProject the mouse (with winz = 0) and find the closest object without select buffer.

For this i need to implement the transformations myself. I implemented all exacept rotation around the Z global axis. I tried but it doens’t work and i don’t know why.
My questions are:

  1. Do you think my idea for the selection can work?
  2. Does anyone have a reference for implemented transformations?

Thank you All

The problem here is that you need to transform all objects, including your mouse to some space where you can test them.

You will probably need gluProject for your object which gives “window space” vertices.

You will just need the x, y of the mouse then to test if it is inside the object. No need for gluUnProject.

Another way is to transform all objects to eye space. Then pretend the mouse shoots a ray into the scene. So the ray may start from (x, y, 0) and go to (x, y, -1000)
Transform this to eye space with gluUnproject (modelview set to identity).
Then test.

You can do bounding box testing and spatial partioning to optimize.

Once your modelview and project matrices are set up, you can use glGetDoublev() to get the modelview matrix and the projection matrix, to feed into gluUnProject(). You don’t need to do the matrix math yourself, unless you really want to.