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.
So in other words, I want to BE the y-axis, so everything will rotate around me as I turn. But for some reason it’s not working out that way.
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.
Be advised, you might not see some variables declared inside of these two functions, but you will see them used inside of these two functions. They are declared globally elsewhere.
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 ); glLoadIdentity( ); 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 )
{
/* 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 ); glLoadIdentity( ); /* Move down the z-axis. */ glTranslatef( 0.0, 0.0, -5.0 );
glTranslatef( 0, movy, movz );
/* Rotate. */
glRotatef( angle, 0.0f, 1.0f, 0.0f );
myMap->DrawMap();
/* * 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. */ SDL_GL_SwapBuffers( );
}
Thanx for any help you can provide. If you are confused about my explanation, instant message me or reply to this and ask me to try and explain further, and I will try to. If you want to see any more of my code I can do that also.
[This message has been edited by ilKhanKerensky (edited 03-12-2003).]
[This message has been edited by ilKhanKerensky (edited 03-12-2003).]
[This message has been edited by ilKhanKerensky (edited 03-12-2003).]