   DirectX Breakout game problem
  Hey everybody I've been working very hard on a 2D Breakout clone and I'm having some problems with it that I can't quite figure out.  It is not erroring out when I compile it or when I run it, the problem is that there seems to be a problem with my collision detection occasionally when the ball hits the left or right side of the window it will occasionally not bounce and just continue moving off the screen and I just cant figure it out, and have nobody nearby that could look at it and see if the can figure it out. I would post the code on here but I'm not sure what is causing the issue so I posted a link on my portfolio website for the project, its just the code files and the images that it needs to run. If you go to this website http://www.jamiecooperportfolio.com its the only link on there.  The code is a bit messy but it should be fairly easy to follow what it does, any suggestions for fixing this issue please post or any suggestions of improvements to any areas of my code that would make it run better again please feel free to post.   
  Can you post just the code (using source tags) that does the collision detection?   ;  Does the ball "shakes/wobbles" for a short period when hitting the wall?My guess is that you have something like this:if( ball.x < SIDE )   ball.vx = -ball.vx;That means you reverse the velocity of the ball, that means it would bounce. But in the next iteration: the ball is still in the same ball.x position, so it will reverse its velocity again. And again...   ;  Ok I'm going to post some of the code for you guys on here and see if you can help me.  One note I will make quick about this is that this issue only seemed to come about after I updated my timing code from:while (!gameover){   if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)){TranslateMessage(&message);DispatchMessage(&message);}else{GameUpdate(window, dt);// process game loopGameRun(window);}}to__int64 cntsPerSec = 0;QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);float secsPerCnt = 1.0f / (float)cntsPerSec;__int64 prevTimeStamp = 0;QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);while (!gameover){   if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)){TranslateMessage(&message);DispatchMessage(&message);}else{__int64 currTimeStamp = 0;QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);float dt = (currTimeStamp - prevTimeStamp)*secsPerCnt;GameUpdate(window, dt);// process game loopGameRun(window);prevTimeStamp = currTimeStamp;}}My collisions detection code is:if (player.x &lt; 0)   player.x = 0;if (player.x &gt; SCREENW - player.width)player.x = SCREENW - player.width;ball.x += ball.velx * dt;ball.y += ball.vely * dt;if (ball.x &lt; 0 || ball.x &gt; SCREENW - ball.width)ball.velx *= -1;if (ball.y &lt; 0)ball.vely *= -1;if (ball.y &gt; SCREENH - ball.height){ResetBall();ballReset = true;playerLives--;if (playerLives &lt; 1)endGame = true;}if (Collision(player, ball) && (ball.y &lt; player.y)){if (MoveLeft)ball.vely *= -1;if (!MoveLeft){ball.vely *= -1;ball.velx *= -1;}}for (int a = 0; a &lt; BRICKCOUNT; a++){if (Collision(ball, bricks[a]) && bricks[a].Alive){bricks[a].Alive = false;ball.vely *= -1;ball.velx *= 1;playerScore += 100;}}The collision function code is:int Collision(SPRITE sprite1, SPRITE sprite2){RECT rect1;rect1.left = (long)sprite1.x;rect1.top = (long)sprite1.y;rect1.right = (long)sprite1.x + sprite1.width * sprite1.scaling;rect1.bottom = (long)sprite1.y + sprite1.height * sprite1.scaling;RECT rect2;rect2.left = (long)sprite2.x;rect2.top = (long)sprite2.y;rect2.right = (long)sprite2.x + sprite2.width * sprite2.scaling;rect2.bottom = (long)sprite2.y + sprite2.height * sprite2.scaling;RECT dest; // ignoredreturn IntersectRect(&dest, &rect1, &rect2);}Sprite is just a struct I built what has x, y, width, height, and a few other properties.Any help would be greatly appreciated.   ;  Anybody got any suggestions I can't figure this out?;  When the ball hits the wall you should:- change velocity- move the ball directly into the new directionball.x += ball.velx * dt;ball.y += ball.vely * dt;if (ball.x &lt; 0 || ball.x &gt; SCREENW - ball.width) {  ball.velx *= -1;  ball.x += ball.velx * dt;}if (ball.y &lt; 0) {  ball.vely *= -1;  ball.y += ball.vely * dt;};  You might also want to change your timing code slightly to average the frame time for the last few frames. Otherwise the frame time will fluctuate a lot (Because it's likely to be a small value), and your ball movement won't be smooth.I've written a timer class in one of my articles, feel free to use that if it helps.   ;Quote:Original post by Evil SteveYou might also want to change your timing code slightly to average the frame time for the last few frames. Otherwise the frame time will fluctuate a lot (Because it's likely to be a small value), and your ball movement won't be smooth.What do you mean by this? If you calculate the real dt (frame time) and use it to change position using the basic kinematics: pos_new = pos_prev + dt * velocity,smoothness of the motion cannot be affected by fluctuation of dt, can it?If the dt decreases, you are moving the object by smaller distance. If dt increaes, you are moving the object by larger distance. But the velocity is still the same.Moreover, imho, if you average dt over more frames, you are not getting the accurate and real dt for the particular frame anymore and this could lead to jerky motion. Imagine you have suddenly two frames with much lower dt than the previous frames. This means the calculations occurs more frequently now. But you take the averaged dt, which is higher than it should be => you increase the object's position quicker (shorter frames) but almost by the same distance you moved it when you were updating the position less frequently => the object moves faster without any reason.   