Try this…
It’s Borland…
Press + once or twice to move in Z and play with arrow…you can rotate and move back and forth
…/*
OpenGL by Marc-Antoine Lemay
1- Learning Process
*/
#include <windows.h>
#include <GL/Gl.h>
#include <GL/GLUT.h>
#include <math.h>
#include <iostream.h>
#include <conio.h>
float EFax=1;
float fCam=10;
float fHeading=0;
float fMHead;
float xpos=0;
float ypos=0;
float zpos=2;
float xmpos=0;
float ympos=0;
double PI=3.1415;
int Mis=0;
float dist=1;
void init ( void )
{
glEnable ( GL_DEPTH_TEST );
glShadeModel ( GL_SMOOTH );
glClearColor ( 0.20, 0.20, 0.20,1.0 );
}
/* Main display function called by GLUT main loop */
void display( void )
{
// Clear previous screen and depth buffer
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
/* Add Everything to display*/
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity();
glRotatef(-90,1,0,0); /* Rotation Around X to have Z as real world /
glRotatef(fHeading,0,0,1); / Heading of you */
glTranslatef(-xpos,-ypos,-zpos); /POsition de toi/
glPushMatrix();
glColor4f(1,0,0,1); // X axis is RED
glBegin(GL_LINES);
glVertex3f(-10,0,0);
glVertex3f(10,0,0);
glEnd();
glColor4f(0,1,0,1); // Y axis is GREEN
glBegin(GL_LINES);
glVertex3f(0,10,0);
glVertex3f(0,-10,0);
glEnd();
glColor4f(0,0,1,1); // Z axis is BLUE
glBegin(GL_LINES);
glVertex3f(0,0,10);
glVertex3f(0,0,-10);
glEnd();
glPopMatrix();
glColor4f(1.0,1.0,1.0,1.0);
glPushMatrix();
glutWireSphere(2,16,16);
glPopMatrix();
glColor4f(1.0,0.0,1.0,1.0);
glPushMatrix();
glTranslatef(0,8,1);
glutWireSphere(2,16,16);
glPopMatrix();
glColor4f(0.0,1.0,1.0,1.0);
glPushMatrix();
glTranslatef(8,8,1);
glutWireSphere(2,10,10);
glPopMatrix();
glColor4f(0.0,0.0,1.0,1.0);
glPushMatrix();
glTranslatef(12,20,1);
glutSolidSphere(2,10,10);
glPopMatrix();
glColor4f(0.7,1.0,1.0,1.0);
glPushMatrix();
glBegin(GL_POLYGON);
glNormal3f(0,0,1.0);
glVertex3f(0,100,0);
glVertex3f(50,100,0);
glVertex3f(50,0,0);
glVertex3f(0,0,0);
glEnd();
glPopMatrix();
if (Mis==1)
{
ympos+=cos(2PIfMHead/360)(dist/4);
xmpos+=sin(2PIfMHead/360)(dist/4);
glColor4f(1.0,0.0,0.0,1.0);
glPushMatrix();
glTranslatef(xmpos,ympos,zpos);
//glRotatef(fMHead,0,0,1);
glutWireSphere(1,16,16);
// Sleep(250);
clrscr();
cout << xmpos << " " << ympos << "
";
cout << xpos << " " << ypos << "
";
cout << fHeading << " " << fMHead << "
";
cout << dist << " " << Mis;
glPopMatrix();
}
glutSwapBuffers ();
if (dist>=2.5)
Mis=0;
}
void explosion (void)
{
for (EFax=1;EFax<500;EFax+=1.5)
{
display ( );
}
EFax=.1;
}
/* Idle callback from GLUT main loop.
/
void idling ( void )
{
/ Variable to Increment */
if (Mis==1)
dist+=.000001;
if (dist>=100)
{dist=1;
Mis=0;
xmpos=xpos;
ympos=ypos;
}
glutPostRedisplay ( );
}
/*
Standard reshape function, also sets the viewing volume the first time
its called
*/
void reshape ( int w, int h )
{
glViewport ( 0, 0, w, h );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
if ( h==0 )
gluPerspective ( 100, ( float ) w, 1.0, 5000.0 );
else
gluPerspective ( 100, ( float ) w / ( float ) h, 1.0, 5000.0 );
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( );
}
#pragma argsused
void mouse ( int button, int state, int x, int y )
{
}
#pragma argsused
void motion ( int x, int y )
{
display ( );
idling ( );
}
#pragma argsused
/* Standard GLUT keyboard call back function. */
void keyboard ( unsigned char key, int x, int y )
{
clrscr();
cout << xmpos << " " << ympos << "
";
cout << xpos << " " << ypos << "
";
cout << fHeading << " " << fMHead << "
";
switch ( key ) {
case 27: // Escape key
exit ( 0 );
break;
case ‘+’:
zpos+=.25;
glutPostRedisplay ( );
break;
case ‘-’:
zpos-=.25;
glutPostRedisplay ( );
break;
case ‘f’:
Mis=1;
xmpos=xpos;
ympos=ypos;
fMHead=fHeading;
dist=1;
glutPostRedisplay ( );
break;
case 'r':
glutPostRedisplay ( );
break;
default:
break;
}
}
#pragma argsused
/* Standard GLUT keyboard call back function. */
void Skeyboard ( int key, int x, int y )
{
clrscr();
cout << xmpos << " " << ympos << "
";
cout << xpos << " " << ypos << "
";
cout << fHeading << " " << fMHead << "
";
switch ( key ) {
case GLUT_KEY_UP:
ypos+=cos(2PIfHeading/360);
xpos+=sin(2PIfHeading/360);
glutPostRedisplay ( );
break;
case GLUT_KEY_DOWN:
ypos-=cos(2*PI*fHeading/360);
xpos-=sin(2*PI*fHeading/360);
glutPostRedisplay ( );
break;
case GLUT_KEY_RIGHT:
fHeading+=5;
glutPostRedisplay ( );
break;
case GLUT_KEY_LEFT:
fHeading-=5;
glutPostRedisplay ( );
break;
default:
break;
}
}
/* Main Loop
- Open window with initial window size, title bar,
- RGB display mode, and handle input events.
/
int main ( int argc, char* argv )
{
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE );
glutInitWindowSize ( 300, 300 );
glutCreateWindow ( “OpenGL Learning Process For Stupid Bored Students” );
init ( );
glutReshapeFunc ( reshape );
glutMouseFunc ( mouse );
glutMotionFunc ( motion );
glutKeyboardFunc ( keyboard );
glutSpecialFunc ( Skeyboard );
glutDisplayFunc ( display );
glutIdleFunc ( idling );
glutMainLoop ( );
return 0;
}