OpenGL screen view coordinates
I am currently working on a project in OpenGL and was having a little trouble with rotation of my map. The way my map is setup is a hexagonal map, so each spot on the map is a hexagon. The base of the map is the lower left corner hexagon. In the entire matrix of hexagons, it is [0,0]. I then set the base hexagon to start out at coordinate (0, -1, 0) on the screen. The reason I am starting the y-coordinate at -1 is because if I started it at 0, the map would be in the center of the screen and would not be visible, because it is a flat map, but that is not the issue here.
Anyways, just like in several computer games, I use the left and right arrow keys to turn right and left, or in other words, to pivot on the y-axis. However, I am having a problem with the pivoting. The problem is that the base of the map stays at (0, -1, 0) at all times. But that is not what I want to happen. What I need to happen is for the map to conform to the user, in other words, the place in which my personage would be standing on the map if i were a character in the game always needs to be at (0, -1, 0), therefore making the map pivot around me.
Just in case you need to look at some of my code, I have included the two functions that would be of the most importance in this scenario, the function in which I set up OpenGL, and the function in which I do the drawing. Also notice that I am using OpenGL inside of SDL. I love SDL. :D
void setup_opengl( int width, int height )
float ratio = (float) width / (float) height;
/* Our shading model--Gouraud (smooth). */
glShadeModel( GL_SMOOTH );
/* Set the clear color. */
glClearColor( 0, 0, 0, 0 );
/* Setup our viewport. */
glViewport( 0, 0, width, height );
* Change to the projection matrix and set
* our viewing volume.
glMatrixMode( GL_PROJECTION );
gluPerspective( 60.0, ratio, 1.0, 1024.0 );
myMap = new HEXMAP_DTP( 5, 5, 1.0f ); //create a 5x5 hex map with each hex having a 1 unit radius
myMap->SetBase ( 0.0f, -1.0f, 0.0f ); //base coords of map
static void draw_screen( void )
/* Our angle of rotation. */
static float angle = 0.0f;
/* Clear the color and depth buffers. */
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
/* We don't want to modify the projection matrix. */
glMatrixMode( GL_MODELVIEW );
/* Move down the z-axis. */
glTranslatef( 0.0, 0.0, -5.0 );
glTranslatef( 0, movy, movz );
/* Rotate. */
glRotatef( movx, 0.0f, 1.0f, 0.0f );
//myHex->DrawHex ( );
* Swap the buffers. This this tells the driver to
* render the next frame from the contents of the
* back-buffer, and to set all rendering operations
* to occur on what was the front-buffer.
* Double buffering prevents nasty visual tearing
* from the application drawing on areas of the
* screen that are being updated at the same time.
Thanx for any help you can provide.