   My billard ball's collision with billar's table
  Guys, I got a new problem, I'm testing my white ball's collision with my table's size but the ball isn't colliding with it, when that was to collide. Here is the all code: http://codepad.org/bAQisVCK . and the following code is the part that tests the collision, I'm making it with OpenGL:if(myBalls[15].y + myBalls[15].height >= myTable->y + myTable->height){myBalls[15].yVelocity = -myBalls[15].yVelocity;}I tried to change this code position to another, before the velocity test, but the ball shakes if it collides. If someone here knows the solution, please help me. Thank you.   
  Why do you think it shakes?You mirror the velocity, the ball stays in collision so you mirror again and again.And in your code: why do you change the 'x' velocity when colliding with the 'y' walls?It's very simple to solve: you know, that the ball can't go into the edge of the table, thus you know its new direction: away from the edge.if(myBalls[15].y + myBalls[15].height >= myTable->y + myTable->height){    myBalls[15].yVelocity = -abs(myBalls[15].yVelocity);//so it's sure to move down}else if(myBalls[15].y + myBalls[15].height <= myTable->y )//or whatever the other side is{    myBalls[15].yVelocity = abs(myBalls[15].yVelocity);}if(myBalls[15].x + myBalls[15].width >= myTable->x + myTable->width){    myBalls[15].xVelocity = -abs(myBalls[15].xVelocity);//so it's sure to move left}else if(myBalls[15].x + myBalls[15].widht <= myTable->x )//or whatever the other side is{    myBalls[15].xVelocity = abs(myBalls[15].xVelocity);}I don't want to offent you, but you haven't thought of the problem too much have you? You run into a problem, and posted here...   ;  Look, I really tried to solve this problem, I changed to abs function but it' didn't work, I really need a help.   ;  thiagonagaoka,szecs's reply did have some harsh words, but underneath the words there was a sentiment I agree with...that for you to best solve the problem, you must first understand it yourself. I'd rather help you learn to fix it yourself than give you an answer. There is a saying, "Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime."Your original post was brief, and looking at your code, it is not very well structured or designed. The code you wrote to try and handle the collision...as shown in your codepad page, has no effect whatsoever! This is because you always recompute velocity then immediately update position before doing the collision...you always lose the change in velocity and you never, ever use the flipped velocity. That is why you don't get a collision response.It's okay that your code isn't great. You are learning. You're coding, and that's fantastic! I'd like to help you to understand what is happening, so that you can solve the problem yourself.You mentioned a problem with shaking when you changed the code a bit. I want you to learn for yourself why that happens. So....how can you learn...?Here is what I'd like to suggest. I am a big fan of "debug visualization"...drawing things on the screen that help figure out what the algorithm is doing. So, to help you to understand what your algorithm (with the change that causes the shaking) is doing, try this:  - Make the change to your code that causes the shaking  - Change your loop that draws the balls so that it draws ball 15    at the place where you update myBalls[15].x/y...just after you    update .x/.y  - Its okay to draw balls 0 - 14 in the original loop, since you do    not appear to be attempting physics for those  - In addition to drawing ball 15 right at the point where you update    the position, draw an additional vector, a line segment,    drawn using: glBegin(GL_LINES);   glVertex3f(0.0, 0.0, 0.0);   glVertex3f(myBalls[15].xVelocity, myBalls[15].yVelocity, 0); glEnd();    It is best that you do that inside the DrawBalls function (so you    will be able to draw the debug velocity vector for all the balls    once you do physics for all of them).    This line segment is the velocity vector...this bit is the "debug    visualization" feature I mentioned, which will help you see what    the algorithm is doing.What that code will do is draw a line segment from the center of the ball towards the direction the ball is moving, e.g., it will show you where the ball is trying to go.Once you do that, modify your code so that you can run it stepwise, e.g., so that you have to press the space bar to get the ball to move one step. This way, you are effectively paused...Look at the velocity of the ball just as it is about to collide with the wall, then look at it after the collision, and for a few steps after that....see how the velocity flips back and forth...you should be able to see the trend, to visually see what is going wrong with the algorithm.Once you see the velocity vector being drawn on your screen, I think you'll be in a better position to try and solve the problem for yourself!I hope that helps.Oh, a minor spelling thing...It is "Billiard", with a second "i", not "Billar" or "Billard"   ;  Your helping helped me to fix a litle bit my code, now it's easy to see the values that my ball 15 velocity is receiving, now I'll try to fix it to myself. Thanks a lot.   ;Quote:Original post by szecsIt's very simple to solve: you know, that the ball can't go into the edge of the table, thus you know its new direction: away from the edge. pitiful removed I don't want to offent youHere's a much better way to solve this problem://rectify positionrb.Position += c->Normal * c->Penetration;float vDotN = Dot(rb.Velocity, c->Normal);if (vDotN < 0){//moving towards contact, apply impulseVector deltaV = c->Normal * vDotN * (-1 - rb.CoefRestitution);rb.Velocity += deltaV;}From: http://www.gamedev.net/community/forums/viewreply.asp?ID=3549796;  problem solved, That wasn't working because I was changing the cue ball's velocity inside the display method, I have to change it outside. Thanks a lot guys.   ;  That's awesome news! Post some screen shots!;  I didn't finish the game yet.   ;  I have been wondering about this issue, The same problem I faced two days ago. so thanks for posting.http://www.chevillotte.com/