PDA

View Full Version : about OpenGL animation



endo
02-12-2002, 09:23 AM
I have been starting a simple breakout-style game and have now got a moving ball and paddle.

The paddle moves 2 units at a time which isn't very smooth when the programming is running, so my question is how to make it smoother without reducing the speed of movement?


And also, how can I keep my sphere looking spherical (its kinda distorted at the moment because of the window dimensions)? I looked at the code in the SuperBible but when I implemented that, the ball bounced before reaching the top of the window?

Oh yeah, its all done in OpenGL using GLUT if its of any relevance.

nexusone
02-12-2002, 10:07 AM
Are you using the glut time event function to control the speed of the game?

You can increase you event up date time and use maybe a movement rate of 0.5 or something like that to make the paddle movement smoother.

On the size issue need to see how your are setting up the window and your drawing routine.

Originally posted by endo:
I have been starting a simple breakout-style game and have now got a moving ball and paddle.

The paddle moves 2 units at a time which isn't very smooth when the programming is running, so my question is how to make it smoother without reducing the speed of movement?

As for the distorted ball, need to see how you setup the window and a little more on how you drawing routine works.


And also, how can I keep my sphere looking spherical (its kinda distorted at the moment because of the window dimensions)? I looked at the code in the SuperBible but when I implemented that, the ball bounced before reaching the top of the window?

Oh yeah, its all done in OpenGL using GLUT if its of any relevance.



[This message has been edited by nexusone (edited 02-12-2002).]

endo
02-12-2002, 03:53 PM
hmmm, difficult because its in various files.

this is the main code:


#include <GL/glut.h>
#include "ball.h"
#include "paddle.h"

Ball ball;
Paddle paddle;

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 ); //doesnt 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 ] = 1.0f;
ball.getMove( )->triple[ 2 ] = 0.0f;
}
break;

case GLUT_RIGHT_BUTTON:
if( state == GLUT_DOWN )
{
exit( 0 );
}
break;

default:
break;
}
glutPostRedisplay( );
}


void idle( )
{
ball.moveBall( );
glutPostRedisplay( );
}


void special( int key, int x, int y )
{
switch( key )
{
case GLUT_KEY_LEFT:
paddle.movePaddle( -2.5f );
break;

case GLUT_KEY_RIGHT:
paddle.movePaddle( 2.5f );
break;

default:
break;
}

glutPostRedisplay( );
}


void renderScene( )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f( 1.0f, 0.0f, 0.0f );

glLoadIdentity( );

ball.drawBall( );
paddle.drawPaddle( );

glutSwapBuffers( );
}


void init( )
{
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glEnable( GL_DEPTH_TEST );
}


int main( int argc, char**argv )
{
glutInit( &amp;argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
glutInitWindowSize( 350, 450 );
glutInitWindowPosition( 100, 100 );

glutCreateWindow( "balltest glut program" );

init( );
glutDisplayFunc( renderScene );
glutReshapeFunc( resize );
glutIdleFunc( idle );
glutMouseFunc( mouse );
glutSpecialFunc( special );
glutMainLoop( );

return 1;
}

endo
02-13-2002, 12:48 PM
still hoping for an answer regarding the distortions??