Class confusion with ball animation
Aug 20, 2014 at 11:24pm UTC
I'm trying to create a class for my simple point animation. I want the user to be able to input a speed for the ball to go and I want the speed to be restricted to between 0.01 and 1.0. I want them to be able to input two velocities: one for xvel and for yvel. Is this possible? I've only included the main parts of the code and also part of the class, but im not sure if its correct. Any help will be greatful! Thank you.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
#include "stdafx.h"
//Point Position
float xpos = 0;
float ypos = 0;
//Point Velocity
float xvel = 0.025;
float yvel = 0.02;
//Class
class cAnimation
{
public :
void setSpeed(x float ,y float );
private :
float speed; //values between 0.01 and 1.0
};
// renderScene() - render the scene
void drawScene()
{
// clear the back buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Create Point
glPointSize(20);
glBegin(GL_POINTS);
//Point Colour
glColor3f( 1.0f, 1.0f, 1.0f );
glVertex2f( xpos, ypos );
//Point Bounce (x,y axis)
xpos = xpos + xvel;
ypos = ypos + yvel;
if (xpos >= 500)
{
xvel = -xvel;
}
if (xpos <= -500)
{
xvel = -xvel;
}
if (ypos >= 500)
{
yvel = -yvel;
}
if (ypos <= -500)
{
yvel = -yvel;
}
glEnd();
// swap the buffers of the current window
glutSwapBuffers();
}
// _tmain() - program entry point
int _tmain(int argc, _TCHAR* argv[])
{
// initialise the glut library
glutInit(&argc, argv);
// set up the initial display mode
// need both double buffering and z-buffering
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
// set the initial window position
glutInitWindowPosition(100, 100);
// set the initial window size
glutInitWindowSize(500, 500);
// create and name the window
glutCreateWindow("Motion Blur Swipe Trails!" );
// reshape callback for current window
glutReshapeFunc(winReshapeFunc);
// set display callback for current window
glutDisplayFunc(drawScene);
// set up the global idle callback
glutIdleFunc(update);
// enter the glut event processing loop
glutMainLoop();
return 0;
}
Topic archived. No new replies allowed.