I am sorting thought your code.
I need more of an idea what you are trying to do…
From what you have stated you are wanting to write a tank battle game?
Am I currect that the tank does not move with your code right now?
Now do you want to have the screen look as if you where the driver or if you where looking from behind the tank as it moves forward?
I have edited your code, there are a few things that you should change in how you handle your object movement.
#include <Gl/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h> // Don’t need
#include <gl\gl.h> // do you get a error or warning here?
#include <gl\glu.h> // same here?
#include <iostream> // Don’t need
#include <cmath> // Don’t need
#include <cstdlib> // Don’t need
#include <iomanip> // Don’t need
using std::cout; // Don’t need
using std::cin; // Don’t need
using std::endl; // Don’t need
using std::setw; // Don’t need
using std::setiosflags; // Don’t need
using std::setprecision; // Don’t need
void display(void);
void exits(int);
void moveright(void);
void moveleft(void);
void moveup(void);
void movedown(void);
void shoot(void);
void update_objects(void);
static void key(unsigned char key, int x, int y);
void spinright(void);
void spinleft(void);
//void DrawCircle( double r );
//void DrawEllipse( double a, double b );
void reshape(int, int);
void init(void);
bool tank2 = true;
bool bullet = false;
float e;
int main (int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(450, 450);
glutInitWindowPosition(200, 100);
glutCreateWindow(“Tank Attempt”);
init();
glutDisplayFunc(display);
glutIdleFunc(update_objects);
glutReshapeFunc(reshape);
glutKeyboardFunc(key);
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(0.1, 0.5, 0.1, 0.0);
glShadeModel(GL_SMOOTH);
glutCreateMenu(exits);
glutAddMenuEntry(“Exit”, 1);
glutAddMenuEntry(“Willy P.”, 2);
glutAddMenuEntry(“Tank # 2”, 4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
//DrawCircle(5.0);
if (tank2 == true)
{
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-8.0, -20.0);
glVertex2f(-10.0, 5.0);
glVertex2f(10.0, 5.0);
glVertex2f(8.0, -20.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-10.0, 5.0);
glVertex2f(-8.0, 10.0);
glVertex2f(8.0, 10.0);
glVertex2f(10.0, 5.0);
glEnd();
glBegin(GL_QUADS);
glColor3f(0.5, 0.1, 0.2);
glVertex2f(-1.0, 10.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 10.0);
glEnd();
glBegin(GL_LINE_LOOP);
glColor3f(0.0, 0.1, 0.0);
glVertex2f(-4.0, 0.0);
glVertex2f(-1.5, 0.0);
glVertex2f(0.0, 3.0);
glVertex2f(1.5, 0.0);
glVertex2f(4.0, 0.0);
glVertex2f(2.25, -3.0);
glVertex2f(3.0, -6.5);
glVertex2f(0.0, -4.0);
glVertex2f(-3.0, -6.5);
glVertex2f(-2.25, -3.0);
glEnd();
}
if(bullet == true)
{
glTranslatef(0.0, e, 0.0);
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
}
/*if(bullet == true)
{
for(e = 0.0; e<=25; e = e + .001)
{
glTranslatef(0.0, e, 0.0);
glBegin(GL_QUADS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(-1.0, 21.0);
glVertex2f(1.0, 21.0);
glVertex2f(1.0, 20.0);
glVertex2f(-1.0, 20.0);
glEnd();
glutPostRedisplay();
}
bullet = false;
}*/
glPopMatrix();
glutSwapBuffers();
}
void reshape (int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void exits(int value)
{
if(value==1) exit(0);
if(value==2)
{
tank2 = false;
bullet = false;
glutPostRedisplay();
glClearColor(1.0, 1.0, 1.0, 0.0);
}
if(value==4)
{
tank2 = true;
glutPostRedisplay();
}
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case ‘Q’: // This does nothing, none of you Cap. letters do anything.
case ‘q’:
exit(0); // Program quits here next line does nothing!
glutPostRedisplay(); // Don’t need
break;
case ‘H’:
case ‘h’:
moveright();
glutPostRedisplay(); // Don’t need
break;
case ‘F’:
case ‘f’:
moveleft();
glutPostRedisplay(); // Don’t need
break;
case ‘T’:
case ‘t’:
moveup();
glutPostRedisplay(); // Don’t need
break;
case ‘G’:
case ‘g’:
movedown();
glutPostRedisplay(); // Don’t need
break;
case 32:
shoot();// replace shoot with bullet = true;
glutPostRedisplay(); // Don’t need
break;
case ‘O’:
case ‘o’:
spinleft();
glutPostRedisplay(); // Don’t need
break;
case ‘P’:
case ‘p’:
spinright();
glutPostRedisplay();
break;
default:
break;
}
cout << key << static_cast<int>(key) << endl; // Don’t need
}
void moveright(void)
{
for(int b = 0; b<=1; b++)
{
glTranslatef(b, 0.0, 0.0);
glutPostRedisplay(); // Don’t need
}
}
void moveleft(void)
{
for(int a = 0; a>=-1; a–)
{
glTranslatef(a, 0.0, 0.0);
glutPostRedisplay(); // Don’t need
}
}
void moveup(void)
{
for(int c = 0; c<=1; c++)
{
glTranslatef(0.0, c, 0.0);
glutPostRedisplay(); // Don’t need
}
}
void movedown(void)
{
for(int d = 0; d>=-1; d–)
{
glTranslatef(0.0, d, 0.0);
glutPostRedisplay(); // Don’t need
}
}
void shoot(void) // See my note
{
bullet = true; // I would just put this in the keyboard input switch statement
cout << "shooting
" << endl; // Don’t need
}
void spinleft(void)
{
glRotatef(22.5, 0.0, 0.0, 1.0);
glutPostRedisplay(); // Don’t need
}
void spinright(void)
{
glRotatef(-22.5, 0.0, 0.0, 1.0);
glutPostRedisplay(); // Don’t need
}
void update_objects(void)
{
if (bullet == true)
{
e = e + .25;
if (e > 60 ) bullet = false;
}
glutPostRedisplay();
}
[This message has been edited by nexusone (edited 04-04-2002).]