Sign in to follow this  
Unzip Attack

collision response prob

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 : 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 = -;" <- 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, is the middle point of the ball. Vector addition and subtraction are component-wise, so this code:

Vector n = -;

Does this:

Vector n;
n.x = -;
n.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 :

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this