Archived

This topic is now archived and is closed to further replies.

endo

help me please??

Recommended Posts

I am confused by the structure of my OpenGL (with GLUT) program. I am hoping to create a breakout-style game but have run into problems animating things. If someone could provide some guidance as to how I smoothly animate the paddle it''d be a great help. So far the Paddle class looks like this:
enum PADDLES
{
	flat,
	convex,
	concave
};


class Paddle
{
public:
	//constructors
	Paddle( );
	Paddle( PADDLES );
	~Paddle( );

	//functions
	void drawPaddle( );
	void movePaddle( GLfloat movement );

//private:
	PADDLES type;
	Vector3d* currentLoc;
	GLint width;
};
 
At present the paddle moves, but in noticable increments of 2 (the value passed to movePaddle() ). How should I go about making it move smoothly? Do I need a fine movement variable like Nehe used in tutorial 21? The renderScene function only calls the drawPaddle() function and movePaddle() is called in response to the key presses, is this correct? Some advice would be greatly appreciated, I have been stuck for ages and its killing my love of programming

Share this post


Link to post
Share on other sites
You need to use a timer and update positions of your objects based on the time passed between current and previous frames. You also need to use DirectInput or check for keys being up/down, as opposed to handling Windows messages. Take a look at GetAsyncKeyState.

BTW: NeHe''s code relies on v-sync being on. As soon as I turned it off and framerate jumped from 85 to 300 fps, all his cubes have been spinning like crazy.

Share this post


Link to post
Share on other sites
1. Fix your driver settings. For NVIDIA: display settings-settings-advanced-geforce 3 or whatever-additional properties-opengl.

2. WGL_EXT_swap_control extension.

Share this post


Link to post
Share on other sites
I am still a little cofused. Can someone post some example code showing how to use frames in my GLUT program. My current timer callback function looks like this:

void timer( int i )
{
ball.moveBall( );
glutTimerFunc( 20, timer, 1 ); //resets the timer function
glutPostRedisplay( );
}


Is this all I need to create a constant refresh rate?? This doesn''t looks as good as when I used the idle function either. And still the paddles isn''t being moved smoothly!!

Share this post


Link to post
Share on other sites