I am trying to make a simple game with a character who walks round however I am having a problem with it. In order for the player to have a different experience each time the character starts in a random position each time. However when I am doing the movement and making the character turn I have the problem of not having a point to rotate round as the character is made using a display list. To make it simpler I will post the code in question:
[quote]
int mouse_x=0, mouse_y=0;
bool LeftPressed = false;
int screenWidth=480, screenHeight=480;
bool keys[256];
float spin=0;
const double PI = 3.1415926535897932384626433832795;
void drawChar(float c);
GLuint Character;
GLuint texName;
const int checkImageHeight = 64;
const int checkImageWidth = 64;
GLubyte checkImage[checkImageHeight][checkImageWidth][4];
/********************************************************/
//variables for moving object
float Xtri = 0;
float Ytri = 0;
float Vtri = 0;
float heading = 0;
void display();
void reshape();
void init();
void processKeys();
/************* START OF OPENGL FUNCTIONS ****************/
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(Xtri, Ytri, 0.0);
glRotatef(heading, 0,0,1);
glCallList(Character);
glPopMatrix();
spin+=0.1f;
if(spin>360)
spin=0;
Xtri += Vtri*cos((90+heading)*(PI/180.0f));
Ytri += Vtri*sin((90+heading)*(PI/180.0f));
}
void drawChar(float c)
{
float Hpos[12];
float u = 36;
for ( int i = 0; i < 12; i++ )
{
Hpos[i] = u;
u = u - 6.5;
}
float Vpos[4];
Vpos[0] = 10.5;
Vpos[1] = -7;
Vpos[2] = -24.5;
Vpos[3] = -42;
srand(time(NULL));
float Hno1 = Hpos[rand() % 12];
srand(time(NULL));
float Vno1 = Vpos[rand() % 4];
float Hno2 = Hno1 - 2.5;
float Vno2 = Vno1-2.5;
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex2f((Hno1-3),(Vno1+0.7));
glVertex2f((Hno1+3),(Vno1+0.7));
glVertex2f((Hno1+3),(Vno1-0.7));
glVertex2f((Hno1-3),(Vno1-0.7));
glEnd();
glFlush();
}
void reshape(int width, int height)
{
screenWidth=width; screenHeight = height;
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-50,50,-50,50);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
Character = glGenLists(1);
glNewList(Character, GL_COMPILE);
drawChar(10);
glEndList();
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
}
void processKeys()
{
if(keys[VK_LEFT])
{
heading+=0.1f;
}
if(keys[VK_RIGHT])
{
heading-=0.1f;
}
if(keys[VK_UP])
{
Vtri+=0.001f;
}
if(keys[VK_DOWN])
{
Vtri-=0.001f;
}
}/quote]
I know quite a bit is unneeded it is going to be used later.