
I'd be very greatful if someone could explain what to put where in my GLUT program which looks basically like this at the moment
/* balltest.cpp - glut program for testing the ball class to be used with the breakout game */#include <ctime>#include <GL/glut.h>#include <windows.h>#include "ball.h"#include "paddle.h"#include "polygon.h"#include "collisions.h"#include "block.h"#include "timer.h"typedef std::vector< GenericBlock* > BlockPtrVector;//globals will go into a game running class laterBall ball;Paddle paddle;TexturedBlock test( 7, 20 );Timer gameTimer;float framesPerSec; void calcFps( float& fps ){ static int frames = 0; float currentTime = gameTimer.getTime( ); frames++; if( frames > 100 ) { fps = (double)frames/(currentTime/1000); frames = 0; gameTimer.reset( ); cout << "FPS : " << fps << endl; }}void resize( int width, int height ){ if( width == 0 ) { width = 1; } glViewport( 0, 0 , width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); glOrtho( -100, 100, -100, 100, 100, -100 ); //doesn't keep anything square glMatrixMode( GL_MODELVIEW ); glLoadIdentity( );}void mouse( int button, int state, int x, int y ){ switch( button ) { case GLUT_LEFT_BUTTON: if( state == GLUT_DOWN ) { ball.getMove( )->triple[ 0 ] = 0.0f; ball.getMove( )->triple[ 1 ] = 2.0f; ball.getMove( )->triple[ 2 ] = 0.0f; } break; case GLUT_RIGHT_BUTTON: if( state == GLUT_DOWN ) { exit( 0 ); } break; default: break; } glutPostRedisplay( );}void special( int key, int x, int y ){ switch( key ) { case GLUT_KEY_LEFT: paddle.movePaddle( 3.0f, LEFT ); glutPostRedisplay( ); break; case GLUT_KEY_RIGHT: paddle.movePaddle( 3.0f, RIGHT ); glutPostRedisplay( ); break; case GLUT_KEY_UP: switch( paddle.type ) { case FLAT: paddle.type = CONVEX; break; case CONVEX: paddle.type = CONCAVE; break; case CONCAVE: paddle.type = FLAT; break; default: break; } paddle.buildPaddles( ); break; case GLUT_KEY_DOWN: switch( paddle.type ) { case FLAT: paddle.type = CONCAVE; break; case CONVEX: paddle.type = FLAT; break; case CONCAVE: paddle.type = CONVEX; break; default: break; } paddle.buildPaddles( ); break; default: break; } glutPostRedisplay( );}void renderScene( ){ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity( ); glColor3f( 1.0f, 0.0f, 0.0f ); //testing a block drawing Vector3d loc; test.setLocation( loc ); test.drawBlock( ); ball.drawBall( ); paddle.drawPaddle( ); glutSwapBuffers( ); calcFps( framesPerSec );}void init( ){ glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glEnable( GL_DEPTH_TEST );}//runs the game, updates the animation, checks for collisions etc.void idle( ){ //moving the paddle first bool left = false, right = false; GLfloat offset; switch( paddle.type ) { case FLAT: offset = paddle.width/2; break; case CONCAVE: case CONVEX: offset = paddle.width*0.75; break; default: break; } if( paddle.move > 0 ) { if( paddle.currentLoc->triple[ 0 ] <= (-100 + offset) ) { paddle.currentLoc->triple[ 0 ] = -100 + offset; //clamps it to the edge left = true; } else if( paddle.currentLoc->triple[ 0 ] >= (100 - offset) ) { paddle.currentLoc->triple[ 0 ] = 100 - offset; //clamps to edge right = true; } if( !left || !right ) { paddle.currentLoc->triple[ 0 ] = paddle.currentLoc->triple[ 0 ] + (paddle.move * paddle.direction); paddle.move -= 0.2f; //the lower this value the more momentum is present on paddle } } if( ball.getActive( ) ) //if false ball is drawn but doesnt move { ball.moveBall( ); MyPolygon hit; if( ballPaddleCollision( paddle, *ball.getLoc( ), ball.getRadius( ), hit ) ) { Vector3d newVector; Vector3d hitNormal = *hit.getNormal( ); Vector3d ballMovement = *ball.getMove( ); //reflected = incoming - 2*dotproduct(normal,incoming)*normal newVector = ballMovement - (hitNormal * 2 * dotProduct( hitNormal, ballMovement )); ball.setMove( newVector ); } } glutPostRedisplay( );}int main( int argc, char** argv ){ glutInit( &argc, argv ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowSize( 350, 450 ); glutInitWindowPosition( 300, 300 ); glutCreateWindow( "balltest program" ); init( ); glutDisplayFunc( renderScene ); glutReshapeFunc( resize ); glutIdleFunc( idle ); glutMouseFunc( mouse ); glutSpecialFunc( special ); glutMainLoop( ); return 1;}
ps I really need to sort this out, it has been the bane of my life for the past few months so I ignored it and wrote other bits of the program

[edited by - endo on May 15, 2002 9:45:38 AM]
[edited by - endo on May 15, 2002 9:57:21 AM]