View Full Version : bringing object closer/further

03-24-2011, 09:08 PM
I am trying to bring my object closer like this. This function gets executed on every press of key

void bringCloser(){

printf("Closer \n");
glTranslated(1000-myMove.closer , 1000-myMove.closer ,1000-myMove.closer);


And that works just as it should...Now i want on different press of the key to bring this same object further like this....

void bringFurther(){

printf("Further \n");
glTranslated(1000+myMove.further , 1000+myMove.further , 1000+myMove.further);


But instead of moving object further this bringFurther function does exactly same thing as bringCloser. It keeps bringing object closer and closer.

I obviosly did something silly here so can anyone point me in some direction how to accomplish this please

03-25-2011, 02:11 AM
Have you debugged the values of myMove.closer and myMove.further ?
If they are both visually doing the same things then it's likey that 1000 +- myMove.xxxx contain the same values.

Why not simplify this? Just use one variable myMove.position to specify the absolute world space position of the object?
Then you could just use this when rendering the object:

glTranslated(myMove.poistion.x , myMove.poistion.y,myMove.poistion.z);

and your functions to move the object can be decoupled from rendering by updating the position variable, for eample:

void bringCloser(){

myMove.position.x -= somevalue
myMove.position.y -= somevalue
myMove.position.z -= somevalue