Advertisement

Can someone give me a hand with this code?

Started by January 16, 2003 01:26 PM
1 comment, last by LostBoy 22 years, 1 month ago
My dilema is that i cannot keep the ball from moving again once it has stopped. I cannot just use - if (bYvel <= 0) then bYvel=0, because it will stop the ball in it''s tracks when the collision occurs and bYvel and decay are inverted (the values will be negative, and therefor less than 0).
  
gluSphere(quadratic,radius,32,32);// Draw a sphere (our ball)

glColor3f(1.0f,1.0f,1.0f);        // Reset color

    
    
obX=bX;//update old ball position to current position

obY=bY;

delay=delay-5.0f; //Initial delay = 1000.0f

if (delay<=0)//This is a temporary pause to let screen load   

	     //before ball launch

      {	
	delay=0; // When delay reaches 0, we launch ball upward

	    
        bY=bY+bYvel;// update ballY position

	    
        //This lets our ball gradually stop

	bYvel=bYvel-decay;//Decrement ballY velocity

		          //(decay=.00001f)

      }
	
//This is our collision and redirection for the top left 45  

//degree angle

//c3X,c3Y is coordinate for bottom left corner of top left 45 	

//degree angle

//c3X,c3Y is our refference point for collision

	
            if (bY >=c3Y)//Are we past c3Y ? 

		if (c3X-(bX-.02f) > c3Y-(bY+.02f))
		{
			bYvel=-bYvel;
			decay=-decay;
		}
  
Well my suggestion would be:

Whenn you slow down the balls check there if the value is then zero or less make it zero

e.g

if(value <= 0.0f)
value = 0.0f;

or if the value is negative if(value >= 0.0f)
Advertisement
Can''t you just use fabs (bYvel); to get the absolute value (i.e. it removes the minus sign if there is one).

This topic is closed to new replies.

Advertisement