Jump to content
  • Advertisement
Sign in to follow this  
Unzip Attack

collision response prob

This topic is 4969 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys, I'm working on a poolgame in C++ and Qt. It's a 2d pool game and i use a QCanvas with QCanvasitems on (just a painting of a table with sprites as objects). Every QCanvasitem does have a XVelocity() and YVelocity(), together they form a resulting vector... For now my collisions with walls work fine. Now I have some troubles with the collision between 2 balls... I've read a lot and found this : http://www.gamasutra.com/features/20020118/vandenhuevel_03.htm. Now my question : can someone explain me how I have to work with Xvelocity and Yvelocity , in the article they use things like : "Vector n = circle1.center - circle2.center;" <- do they mean the (x,y) middlepoints of the 2 balls ? And the resulting vector is both the sum of X,YVelocity's ? If somebody could help me with this , I would be very thankfull ! Greetz and thx in advance ! Unzip *don't mind my bad english*

Share this post

Link to post
Share on other sites
Sounds like you just need to brush up on vector math a little, and this will start to make more sense.

Yes, circle.center is the middle point of the ball. Vector addition and subtraction are component-wise, so this code:

Vector n = circle1.center - circle2.center;

Does this:

Vector n;
n.x = circle1.center.x - circle2.center.x;
n.y = circle1.center.y - circle2.center.y;

Same for addition.

'Hope that helps.

Share this post

Link to post
Share on other sites

How do I calculate the Xvelocity and YVelocity when I've got the circle1's middlepoint and the new vector V1 (with X en Y -points) ?

Somebody know a good site where I can learn a bit more about useful vectorcalculations ? thx

Share this post

Link to post
Share on other sites
Hi , can anyone plz help me with this code !?

I have a "this"-item vector with a xVelocity(), yVelocity() and x() & y()-coordinate.

The code is based on this : http://www.gamasutra.com/features/20020118/vandenhuevel_03.htm

I really have to know if my fault is in this code or elsewhere !
Thx in advance !

code :

// get the second ball from a collision list
CBal* bal2 = (CBal*) lijst.last();

// make a new vector n
CBal* n = new CBal();

// set the X and Y value of the vector n (substract point of the 2 ball-vectors)
n->setX(x() - bal2->x());
n->setY(y() - bal2->y());

// normalize the n-vector
double t = sqrt(n->x()*n->x() + n->y()*n->y());

// do the dot-product between the movement-vectors and the n-vector
float a1 = (x() * n->x() + y() * n->y());
float a2 = (bal2->x() * n->x() + bal2->y() * n->y());

// calculate the optimized p
float optimizedP = (2.0 * (a1 - a2)) / (giveMass() + bal2->giveMass());

// calculate the new movement vectors
// from ball 1
setXVelocity(xVelocity() - optimizedP * bal2->giveMass() * n->x());
setYVelocity(yVelocity() - optimizedP * bal2->giveMass() * n->y());

// from ball 2
bal2->setXVelocity(bal2->xVelocity() - optimizedP * giveMass() * n->x());
bal2->setYVelocity(bal2->yVelocity() - optimizedP * giveMass() * n->y());

// move ball 1 with a xVelocity and yVelocity

// move ball 2 with a xVeloctity and yVelocity

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!