Jump to content

  • Log In with Google      Sign In   
  • Create Account


too_many_stars

Member Since 29 May 2013
Offline Last Active Jun 12 2014 10:08 AM
-----

#5149094 2D physics, random line geometry, many balls, and jitter problem

Posted by too_many_stars on 23 April 2014 - 08:58 PM

Sorry for the belated reply.

 

Here are the bounce functions, one's for ball vs ball, the other ball vs line respectively

void Ball::bounce(RigidBody &rigid, V2 &coll_vect){
	
	V2 difference=rigid.getVelocity()-velocity;
	V2 contact_normal=coll_vect;
	contact_normal.normalize();
	float dot=contact_normal.dot(difference);
	
	float mass_rat=(1+e)*(rigid.getMass()/(rigid.getMass()+mass));
	if(dot>0){//if they are moving in the same direction
		c.p.x=c.p.x-mass_rat*contact_normal.x;
		c.p.y=c.p.y-mass_rat*contact_normal.y;
	}
	else{//bounce here
		correction.x=correction.x+(mass_rat*dot)*contact_normal.x;
		correction.y=correction.y+(mass_rat*dot)*contact_normal.y;
	}


}
void Ball::bounceLine(V2 &point){

	V2 coll_normal=c.p-point;
	float coll_n_len=coll_normal.mag();
	coll_normal.normalize();

	c.p.x+=coll_normal.x*(c.r-coll_n_len);
	c.p.y+=coll_normal.y*(c.r-coll_n_len);

	
	float dot=velocity.dot(coll_normal);
	correction.x-=(1+e)*(dot)*coll_normal.x;
	correction.y-=(1+e)*(dot)*coll_normal.y;
}

As you can see it's the first function that's causing the jittering problem as it's impulse based while the other one ball vs line is after the fact position correction, that's why it's not jittering on the lines.

 

Any help would be greatly appreciated,

 

Thanks

 

Mike




#5148724 2D physics, random line geometry, many balls, and jitter problem

Posted by too_many_stars on 22 April 2014 - 07:45 AM

Hi Stainless,

 

Sure, I will post the code tonight (I am at work now and can't do so until the evening)

 

Mike




#5148656 2D physics, random line geometry, many balls, and jitter problem

Posted by too_many_stars on 21 April 2014 - 11:21 PM

Hi Ultramailmain,

 

I have spent many hours on Paul's site ( I even purchased some of his code) but speculative contacts is out of comprehension right now I am afraid.




#5148651 2D physics, random line geometry, many balls, and jitter problem

Posted by too_many_stars on 21 April 2014 - 10:55 PM

Hi guys,

 

I have managed to cobble together a simple phyiscs simulation with random line geometry, and as many balls as I wish to create, all of which posses mass, resitituion and friction properties,

 

Collision and all of the physical properties seem to work fine, but I can't get the balls to settle, once they are close to rest, they keep jittering and bouncing slightly, and it's really unappealing. I tried implementing a threshold, but it did not solve my problem. Here's a section of the main loop.

		for(int i=0;i<balls.size();i++)
			balls[i]->update((float)(SDL_GetTicks()-time));
		time=SDL_GetTicks();

		for(int i=0;i<balls.size();i++){//balls vs balls
			for(int j=i+1;j<balls.size();j++){
				V2 coll_normal;
				if(balls[i]->checkBallColl(*balls[j],coll_normal)){
					balls[i]->handleBallColl(*balls[j],coll_normal);
					coll_normal.x*=-1;
					coll_normal.y*=-1;
					balls[j]->handleBallColl(*balls[i],coll_normal);
				}	
			}	
		}
		for(int i=0;i<lines.size();i++){//lines vs balls
			for(int j=0;j<balls.size();j++){
				V2 point(0,0);
				
				if(balls[j]->checkLineColl(*lines[i],point)){
					balls[j]->bounce(point);
				
				}		
			}
			
		}

I was wondering if anyone has a good perspective on settling the balls to a resting state.

 

Thanks,

 

Mike




#5129215 measuring efficiency in a game

Posted by too_many_stars on 05 February 2014 - 10:29 PM

Thanks for the advice guys, I will check out this profiler. It's incredible how much there is to learn in game programing.

 

Mike




#5129172 measuring efficiency in a game

Posted by too_many_stars on 05 February 2014 - 05:11 PM

Hello everyone,

 

I have a general question I have been thinking about for some time. My gaming experience so far has involved 2D side scrollers. Every now and then I read up on statements such as "trig ratio functions are resource expensive" and "SDL rotozoom should not be used as it's too costly."

 

I am sure that these statements are true, but how does a newbie game developer measure or keep track of how resource intensive a game is? Obviously when the application slows down I know too many resource are being used, but are there are programs, strategies or advice that someone can tell me about which will point me in the right direction in measuring program efficiency?

 

Thanks,

 

Mike




#5113414 Help with wait function in fps game please

Posted by too_many_stars on 30 November 2013 - 10:32 PM

Thanks for the input guys, I will do some work with it in a while, as I am trying to create a random dungeon generator right now.

 

The reason I limit the fps is because all noob tutorials do it that way, to keep things as simple as possible. Alghough I have seen plenty of examples using delta time it has not occured to me to apply it in a simply dungeon crawl.




#5066592 box collision detection help needed

Posted by too_many_stars on 31 May 2013 - 09:26 PM

Thanks BeerNuts,

 

I have heard of these libraries but thought it would be important to learn everthing from the bottom up (collision is the worst). I have also read that professional game studios and developers don't bother make their own code for physics etc, they just use 3rd party libraries. Do you think it's worth the time to and frustration to struggle with the collision and physics or should I not bother wasting time and just switch to the library you recommended?

 

Mike




#5066353 box collision detection help needed

Posted by too_many_stars on 31 May 2013 - 02:53 AM

Thanks for the help guys, Jdean300 has managed to solve my problem. I do understand your code now BeerNuts, and will try to rewrite it your way and see if I can get the same result as Jdean300 (which is working correctly).

 

Thanks again guys, you've been great help!

 

Mike




#5066139 box collision detection help needed

Posted by too_many_stars on 30 May 2013 - 08:22 AM

Thanks JDean300. I won't be back home until very late tonight and then I will definetly try out your change. Of course, I will let you know what happened. Thanks a lot for the help.

 

Is there some generally accepted, well written box collision code that 2D gamers use for different sides hitting? I would think something like that gets used all the time.

 

Thanks,

 

Mike




#5066066 box collision detection help needed

Posted by too_many_stars on 30 May 2013 - 01:22 AM

Thanks for the aid Jdean300, but it's still not working. The ball keeps bouncing back in the same direction.

 

This collision detection is a nightmare.




PARTNERS