
a few questions...
I have been writing the beginnings of a breakout-style game and am trying to get the ball bouncing around the screen. Now I have encountered a number of problems:
1. when the GLUT window is resized the ball vanishes from the screen never to reappear
2. my clipping volume is defined by:
glOrtho( -100, 100, -100, 100*height/width, 100, -100 );
This works fine in most cases but the ball bounces before it reaches the top of the window
3. Some values prevent the ball from bouncing at all if they are changed. For example, if the BALL_SIZE is 4 its fine, if its 5 it doesnt work. The same kind of thing occurs in the movement vector - 0.75 works and 0.7 doesnt. Any ideas why this might be?
Edited by - endo on February 8, 2002 1:51:32 PM

1: post your resize code? remember that if the window is resized you need to set the projection and the viewport again.
2: sounds like you arent changing the viewport?
3: are you checking with == rather than greater than, less than, etc... if you use something along the lines of if(bally == WINDOW_TOP), the balls position might "jump" over the boundary because of rounding errors or otherwise. if this is the case, do something like if(bally >= WINDOW_TOP) instead. if not, it could be an incorrect viewport or projection.
2: sounds like you arent changing the viewport?
3: are you checking with == rather than greater than, less than, etc... if you use something along the lines of if(bally == WINDOW_TOP), the balls position might "jump" over the boundary because of rounding errors or otherwise. if this is the case, do something like if(bally >= WINDOW_TOP) instead. if not, it could be an incorrect viewport or projection.
resize code:
3 is answered now, many thanks :D
void resize( int width, int height ){ glViewport( 0, 0 ,width, height ); if( width == 0 ) { width = 1; } glMatrixMode( GL_PROJECTION ); glOrtho( -100, 100, -100, 100*height/width, 100, -100 ); glMatrixMode( GL_MODELVIEW );}
3 is answered now, many thanks :D
Add a glLoadIdentity() after the glMatrixMode(), otherwise you are combining a new projection each time you resize the window.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
two down, one to go.
The only question left is why does the ball bounce before it reaches the top of the window? the code that moves the ball is:
where move and currentLoc are pointers to 3d vectors. The code that draws the ball just translates to the currentLoc and draws a sphere.
Cant think of anything other code that might be relevant, but if it is just ask.
The only question left is why does the ball bounce before it reaches the top of the window? the code that moves the ball is:
void Ball::moveBall( ){ *currentLoc = *currentLoc + *move; if( currentLoc->triple[ 0 ] >= 100.0 - BALL_RADIUS ) { move->triple[ 0 ] = -move->triple[ 0 ]; } else if( currentLoc->triple[ 0 ] <= -100.0 + BALL_RADIUS ) { move->triple[ 0 ] = -move->triple[ 0 ]; } else if( currentLoc->triple[ 1 ] >= 100 - BALL_RADIUS ) { move->triple[ 1 ] = -move->triple[ 1 ]; } else if( currentLoc->triple[ 1 ] <= -100 + BALL_RADIUS ) { move->triple[ 1 ] = -move->triple[ 1 ]; }}
where move and currentLoc are pointers to 3d vectors. The code that draws the ball just translates to the currentLoc and draws a sphere.
Cant think of anything other code that might be relevant, but if it is just ask.
This appears to be a problem with the glOrtho call. If I just call it like this:
glOrtho( -100, 100, -100, 100, 100, -100 );
the problem goes away. when I add the *height/width part the viewport does not appear to fill the window but now things can be distorted. How do I fix this, or should I not worry about it?
glOrtho( -100, 100, -100, 100, 100, -100 );
the problem goes away. when I add the *height/width part the viewport does not appear to fill the window but now things can be distorted. How do I fix this, or should I not worry about it?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement