Center on point


I have an OpenGL view, and I want to center the view
on point where the user click.

Example :

If I click on Point(50,50) -> I want to center on point(50,50).

Someone can help me ?

Hi !

It’s not that simple, if you are using 2D only it’s no big geal, but in 3D, what are you clicking on ? the X,Y coordinates for the point depends on the depth.

So normally you need “something” to click on so you can get a depth value (have a look at gluProject and gluUnProject).


I have an object for clicking on it.

I use both 2D and 3D.

I use “gluUnProject” for obtain my position when
I click.

But if I set the Pan with the position, it don’t
center correctly my object.