PDA

View Full Version : Change velocity at a particular point



Abdul
03-17-2012, 08:58 AM
I have created a body that moves in the windows of size 800,600
which moves with velocity(10,10). and that's the init graphics function code
////////////////////////////////////////////////////////////
void InitGraphics(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutInitWindowPosition(100, 100); //pass (-1, -1) for Window-Manager defaults
glutInitWindowSize(800, 800);
glutCreateWindow("OpenGL Lab");
glutDisplayFunc(OnDisplay);
body.P.Set(0, 0);

body.V.Set(10,10);
body.Update(0.01);

glutMainLoop();}
///////////////////////////////////////////////////////////
i want to change the velocity of the body to move in the o ppisite direction when it reach the point y=30

tonyo_au
03-17-2012, 07:23 PM
just check the offset of the body inside the function OnDisplay and change the velocity to the opposite direction when y = 30.

Make sure you call body.Update(0.01); inside OnDisplay as well (I assume this updates the position)