interactive scene

I’ve implemented the selection buffer which detects which objects I’ve selected - I’m using glPickMatrixs - how can I now move them around the scene also how could I obtain the coordinates - x, y and z for them

any ideas

thanx in advance

good question, I would like to know too. I think we’ll have to use some sort of a collision detection to establish which entity was selected, I’d rather not though, I’m trying to find another way around it

Say what are these objects, what do you want to do with them and what you have implemented in details.

Well basically I have three cubes in a scene which when I click with the mouse a message box appears saying which box I have clicked on - this is achieved with the selection code - what I would now like to do is when I click a box rather than a message box appearing I can select and drag that particular box in the scene - I would also like to know how I could obtain its coordinates

Thanx

I’m assuming you know the coordinates of the original position of the cubes in order to draw them. To do what you want, simply change those coordinates on a mouse move for the selected object, then redraw the scene.

To redraw the scene do I need a ReDrawScene() function?

Cheers

Pretty much. If you setup your current display function right you can just call that again. Just as a quick example for a single object you could do something like so…

// Initialize these to current position
float g_posX, g_PosY, g_posZ;

void Display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Push matrix so you can restore it after rendering this object
glPushMatrix();
glTranslatef(g_posX, g_posY, g_posZ);
drawObject();
glPopMatrix();
}

// on the mouse move you could update the position by using a function like so
void MoveObject(float x, float y, float z)
{
g_posX = x;
g_posY = y;
g_posZ = z;

Display();
}

Originally posted by fox:
[b]I’ve implemented the selection buffer which detects which objects I’ve selected - I’m using glPickMatrixs - how can I now move them around the scene also how could I obtain the coordinates - x, y and z for them

any ideas

thanx in advance[/b]

For interacting with your scene you should try another method:
First shot a ray into the scene that lies under the x/y position you need.
For doing this you can use gluUnProject using the x/y position and z = 0/1
The matrices you can retrieve by calling glGetDoublev the viewport by glGetIntergev

You now will retrieve 2 World positions where the mouse would be with having z = 0 and with having z = 1
Building the difference vertex you will get a ray that would go directly into the screen.
So when trying to draw this line you just could notice a point where your x/y pos was.

The next step to do is to check out for any collision with any objects. (hope you know how to do this)
When having more than one object under your mouse, you can check which one is near to it (is laying top most) by finding that intersection point that is nearest to the projected mousevertex with z = 0
|Intersection-MouseVertex0| ist minimal for the most top object.

The last thing you now need to do is to project the collision Vertex back to Screen coordinates using gluProject, you’ll receive the x/y coords your mouse is on but also a third component, the z component which you will need later on.
By doing all this you just get out how far your object is laying under your mouspointer. With this information you can move the object by just having 2 mouse coordinates.

The next step follwing now is just one more gluUnProject call using your new mousecoord your mouse moved to, using the z value retrieved by the steps before et voila: you’ll get the new world position of your object.