Hi,
I’m using GLUquadricObj *quadric; to create a sphere that moves. I’ve used glTranslated(x,y,z) in order to make it move but am having trouble reversing direction. I’ve tried some variations of this code using x*-1 instead but still it doesn’t bounce and reverse.
Thanks for your help.
from Ball.cpp :
void Ball::update() {
x+=1;
y+=1;
z+=1;
glTranslated(x, y, z);
}
void Ball:: bounceX () {
x-=1;
glTranslated(x,y,z);
}
void Ball::bounceY(){
y-=1;
glTranslated(x, y, z);
}
void Ball::bounceZ (){
z-=1;
glTranslated(x,y,z);
}
From test app.cpp:
if(ball.x - ball.rad < 0 || ball.x + ball.rad >= ofGetWidth()) {ball.bounceX();}
if( ball.y - ball.rad < 0 || ball.y + ball.rad >= ofGetHeight()){ ball.bounceY();}
if( ball.z >=ofGetHeight() || ball.z + ball.rad >= ofGetWidth()){ ball.bounceZ();}