View Full Version : How to get the camera's position in OpenGL ES?

01-07-2010, 08:17 AM
I need to get the cameras position in x,y and z coordinates. How can I get this information? I don't find
any method for this.

I am programming a 3d space game. It is possible to move around in the 3d space with the arrow keys. glTranslatef and glRotatef calls moves the camera when the user wants to move. So the camera 's x,y and z coordinates is changed when the user presses the arrow keys.

01-17-2010, 08:44 AM
I am afraid there is no such thing as camera in OpenGL. Actually there is but it is always at 0,0,0 coordinate.

01-17-2010, 09:29 AM
Hm ok if you have a class named camera, this class have a member "rotation" and a member "translation".
every frame you make a glRotatef and glTranslatef with these values and you change them on keyevent.

Then it is very easy to implement a member function like

vector const& getRotation() const;


vector const& getTranslation() const;

is'nt it?

this is the position of the camera.

Imagine at the beginning youre camera is initialized with rotation = {0.0f,0.0f,0.0f};translation = {0.0f,0.0f,0.0f};
Then the solution above is the right one.

A camera in opengl?
Is'nt opengl the "lowest level graphic API? So there is no need to simulate camera directly in OpenGL or?

Hope this helps :)


01-25-2010, 05:43 AM
Have you got it working with that approach? It is the same thing that I had implemented and it not working, I can not get the position in an easy wasy. This thread explains why:


01-25-2010, 08:49 PM
Hmm, the apple dev center says you should keep some rendering state duplicated locally, otherwise you can also retrieve the modelview matrix from GL and extract the camera location from it.

01-28-2010, 12:15 AM
I develop for Symbian, not for Apple.DO you mean that I can use this approach for Symbian also?

02-18-2010, 12:51 AM
I have hired a consultant company to fix this problem. I need the position in 3d space for implementing collision detection between the player and objects in 3d space.

The consultant company recommend placing a bound around an invicible object which is placed at the view point. They say that no detection is done using viewpoint coordinates. Instead it's always advisable to check the invicible objects bounds to the other objects bounds. Then you don't need to keep track of the camera's position, but just a check if the collision object ID's did collide.

The GLulookat method implementation is meant to to easy the use of Camera and its tracking, but you don't need any tracking for this if you use an invicible object which is placed at the view point. They say that this can be solved with the same movement that is implemented now, so the movement does not need to be changed.

Is the consultant company right about this? Should I really not use the GLulookat method? Should I place a bound around an invicible object which is placed at the view point and then compare the bounds? Can I keep the same movement that I have now?

02-18-2010, 09:27 AM
Just keep a few floats for the camera's position, so every time you translate update these variables. Do the same for pitch, heading, roll. Good Luck.