{"id":259,"date":"2009-07-12T23:24:22","date_gmt":"2009-07-12T17:54:22","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=259"},"modified":"2011-04-12T23:24:50","modified_gmt":"2011-04-12T17:54:50","slug":"bouncingcolliding-marbles-directdraw-part-8","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2009\/07\/12\/bouncingcolliding-marbles-directdraw-part-8\/","title":{"rendered":"Bouncing\/Colliding marbles, DirectDraw, Part 8"},"content":{"rendered":"<div style=\"text-align: justify; font-family: Comic Sans MS;\">The code for colliding marbles is built on top of earlier changes to the <span style=\"font-family: Verdana;\">DDEX3<\/span> sample. Look <a href=\"http:\/\/geekswithblogs.net\/TechTwaddle\/archive\/2009\/06\/29\/lets-make-the-spaceship-move-directdraw-part-3.aspx\">here<\/a>, <a href=\"http:\/\/geekswithblogs.net\/TechTwaddle\/archive\/2009\/06\/30\/lets-make-the-spaceship-move-directdraw-part-4.aspx\">here<\/a> and <a href=\"geekswithblogs.net\/TechTwaddle\/archive\/2009\/07\/13\/lets-make-the-spaceship-move-directdraw-part-6.aspx\">here<\/a> for more information. There are a few changes I made in the code for making the marbles collide and I hope you have already gone through Prof. Fu-Kwun Hwang <a href=\"http:\/\/www.phy.ntnu.edu.tw\/ntnujava\/index.php?topic=4.0\">post<\/a> on how to make stuff bounce off each other.<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">Create a structure to store the information about a marble:<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">\/*<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">This structure stores the info related to a ball.<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">Its center (xPos, yPos)<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">Its velocity along both axes (dwVelX, dwVelY)<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">Its radius in pixels<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">*\/<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">typedef struct _ballinfo<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int xPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int yPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int dwVelX;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int dwVelY;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int radius;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">} BALLINFO;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/>\n<\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">And here are the globals we use in the source file:<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">#define MAX_BALLS 3<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">\/\/we&#8217;ll be bouncing 3 balls around here.<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">BALLINFO g_BallInfo[MAX_BALLS];<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">\/\/to store the rects of each ball<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">RECT g_Rect[MAX_BALLS];<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/>\n<\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">To add more marbles to the program you just need to change the <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">MAX_BALLS<\/span> macro and recompile the code. Well, the terms balls and marbles are used interchangeably (:<\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">We initialize our global data in <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">InitApp()<\/span> function, we call <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">InitializeData()<\/span> just before <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">InitApp()<\/span> returns:<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">void InitializeData()<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int radius = 22;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; for (int i=0; i &lt; MAX_BALLS; i++)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].xPos = RandInt(radius, 216);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \/\/switch on i to decide on yPos so that the balls dont overlap when they are created<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; switch(i)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \/\/dividing the screen into 3 horizontal sections with one ball in each<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 0:<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].yPos = RandInt(radius, 100-radius);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 1:<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].yPos = RandInt(100+radius, 200-radius);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; case 2:<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].yPos = RandInt(200+radius, 300-radius);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; default:<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].yPos = RandInt(radius, 320-radius);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].dwVelX = RandInt(-6, 6);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].dwVelY = RandInt(-6, 6);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].radius = radius;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;Ball %d details:\\n&quot;, i+1);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;X=%d&nbsp; Y=%d&nbsp; VelX=%d&nbsp; VelY=%d\\r\\n&quot;, g_BallInfo[i].xPos, g_BallInfo[i].yPos,<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].dwVelX, g_BallInfo[i].dwVelY);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">Here we initialize all the data related to each marble, its center, velocity and the radius. The switch case makes sure that the balls do not overlap initially, currently I am only checking for three marbles in the switch. So if there are more than 3, there is still some possibility of the balls overlapping. I&#8217;ll leave that part for later and lets focus on more important things.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">The <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">RandInt()<\/span> function is simple, it returns a random value between the two ranges specified:<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">DWORD RandInt(DWORD low, DWORD high)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; DWORD range = high &#8211; low;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; DWORD num = Random() % range;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; return (num + low);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Comic Sans MS;\">Next, we look at the<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\"> UpdateFrame()<\/span> function:<\/span><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">static void UpdateFrame(HWND hWnd)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; HRESULT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hRet;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; DDBLTFX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ddbltfx;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int i = 0, j = 0;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; memset(&amp;ddbltfx, 0, sizeof(ddbltfx));<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ddbltfx.dwSize = sizeof(ddbltfx);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ddbltfx.dwFillColor = 0;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ddbltfx.dwROP = SRCCOPY;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/clear the back buffer (color fil with black)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; g_pDDSBack-&gt;Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAITNOTBUSY, &amp;ddbltfx);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; MAX_BALLS; i++)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_Rect[i].top = g_BallInfo[i].yPos &#8211; 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_Rect[i].left = g_BallInfo[i].xPos &#8211; 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_Rect[i].bottom = g_BallInfo[i].yPos + 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_Rect[i].right = g_BallInfo[i].xPos + 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ddbltfx.ddckSrcColorkey.dwColorSpaceLowValue = RGB(0, 0, 0);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ddbltfx.ddckSrcColorkey.dwColorSpaceHighValue = RGB(0, 0, 0);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/blt all the balls on the screen<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; for (i = 0; i&lt;MAX_BALLS; i++)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (TRUE)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; hRet = g_pDDSBack-&gt;Blt(&amp;g_Rect[i], g_pDDSOne, NULL, DDBLT_ROP | DDBLT_KEYSRCOVERRIDE, &amp;ddbltfx);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (hRet == DD_OK)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (hRet == DDERR_SURFACELOST)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; hRet = RestoreAll();<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (hRet != DD_OK)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (hRet != DDERR_WASSTILLDRAWING)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; break;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/update the balls positions and check for bounds<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; for (i = 0; i&lt;MAX_BALLS; i++)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].xPos = g_BallInfo[i].xPos + g_BallInfo[i].dwVelX;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].yPos = g_BallInfo[i].yPos + g_BallInfo[i].dwVelY;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(g_BallInfo[i].xPos &lt;= 24)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].xPos = 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].dwVelX = -g_BallInfo[i].dwVelX;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(g_BallInfo[i].xPos &gt;= (240 &#8211; 24))<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].xPos = 240 &#8211; 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].dwVelX = -g_BallInfo[i].dwVelX;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(g_BallInfo[i].yPos &lt;= 24)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].yPos = 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].dwVelY = -g_BallInfo[i].dwVelY;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (g_BallInfo[i].yPos &gt;= (320 &#8211; 24))<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].yPos = 320 &#8211; 24;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; g_BallInfo[i].dwVelY = -g_BallInfo[i].dwVelY;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/check for collisions between all the balls<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; for (i = 0; i &lt; MAX_BALLS-1; i++)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for (j = i+1; j &lt; MAX_BALLS; j++)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(Collision(&amp;g_BallInfo[i], &amp;g_BallInfo[j]))<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printf(&quot;Balls HIT!\\n&quot;);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CalculateNewVelocities(&amp;g_BallInfo[i], &amp;g_BallInfo[j]);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MessageBeep(MB_OK);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">This is more or less the same as before except that the same things are done for all the three marbles here. Calculate the <span style=\"font-family: Verdana;\">RECTs<\/span> for each marble in <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">g_Rect[]<\/span>. Blt the marbles, update the marbles&#8217; position and check for collisions between marbles. This is the interesting part.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">Let me digress a bit here. How do you find out if the marbles are colliding? The presence of <span style=\"font-family: Verdana;\">RECTs<\/span> tricks your mind into thinking that you can check if the two <span style=\"font-family: Verdana;\">RECTs<\/span> overlap, which is what I did initially and which was really dumb, really. I used <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd145001(VS.85).aspx\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">IntersectRect()<\/span><\/a> api to find out if the two <span style=\"font-family: Verdana;\">RECTs<\/span> overlap, and if they did I decided its a collision! The problem here is that the two <span style=\"font-family: Verdana;\">RECTs<\/span> may overlap but there might actually be no collision for example when only the corners of the two <span style=\"font-family: Verdana;\">RECTs<\/span> intersect. And that happens way too many times, and watching the program run like that leaves you baffled, things dont make sense! It didn&#8217;t take me long to figure out a better way, instead of checking for overlapping <span style=\"font-family: Verdana;\">RECTs<\/span>, you had to check if the two circles (marbles) overlapped. Let the radius of the two circles be <span style=\"font-family: Verdana;\">R1<\/span> and <span style=\"font-family: Verdana;\">R2<\/span>, calculate the distance between the centers of the two marbles, lets call it <span style=\"font-family: Verdana;\">D<\/span>. The marbles collide when <span style=\"font-family: Verdana; font-weight: bold;\">D &lt;= R1 + R2<\/span>. Well, they actually collide when <span style=\"font-family: Verdana; font-weight: bold;\">D = R1 + R2<\/span>, but because our program updates the frames by a certain delta everytime we need to check for <span style=\"font-family: Verdana; font-weight: bold;\">D &lt;= R1 + R2<\/span>.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">The <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">Collision()<\/span> function takes two <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">BALLINFO<\/span> structures as input and determines if they collide, returns <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">TRUE<\/span> if they do and <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">FALSE<\/span> otherwise:<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">BOOL Collision(const BALLINFO *ball1, const BALLINFO *ball2)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int distance = 0, temp = 0;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int MinDistance = ball1-&gt;radius + ball2-&gt;radius;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/calculate the distance between the centers of the two balls<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int dx = ball2-&gt;xPos &#8211; ball1-&gt;xPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int dy = ball2-&gt;yPos &#8211; ball1-&gt;yPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; temp = dx*dx + dy*dy;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; distance = sqrt(temp);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/printf(&quot;COLLISION: distance=%d, 2*R=%d\\n&quot;, distance, MinDistance);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; if(distance &lt;= MinDistance)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return TRUE;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; }<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; return FALSE;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">We use the standard formula to calculate the distance between two points,<span style=\"font-family: Verdana; font-weight: bold; color: rgb(0, 0, 128);\"> Distance = SQRT((x2-x1)<\/span><sup style=\"font-family: Verdana; font-weight: bold; color: rgb(0, 0, 128);\">2<\/sup><span style=\"font-family: Verdana; font-weight: bold; color: rgb(0, 0, 128);\"> + (y2-y1)<\/span><sup style=\"font-family: Verdana; font-weight: bold; color: rgb(0, 0, 128);\">2<\/sup><span style=\"font-family: Verdana; font-weight: bold; color: rgb(0, 0, 128);\">)<\/span>. If the marbles do collide then we have to calculate the new velocities for the marbles, and this is how we do it:<\/div>\n<p><br style=\"font-family: Comic Sans MS;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">void CalculateNewVelocities(BALLINFO *ball1, BALLINFO *ball2)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; int ed = 1, mass1 = 20, mass2 = 20;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double velX1, velY1, velX2, velY2;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double dx = ball2-&gt;xPos &#8211; ball1-&gt;xPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double dy = ball2-&gt;yPos &#8211; ball1-&gt;yPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/calculate the distance between their centers<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double distance = sqrt(dx*dx+dy*dy);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double vp1 = ball1-&gt;dwVelX*dx\/distance + ball1-&gt;dwVelY*dy\/distance;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double vp2 = ball2-&gt;dwVelX*dx\/distance + ball2-&gt;dwVelY*dy\/distance;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double dt = (ball1-&gt;radius + ball2-&gt;radius &#8211; distance)\/(vp1 &#8211; vp2);<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/printf(&quot;CENTERS BEFORE: X1=%d, Y1=%d&nbsp;&nbsp;&nbsp;&nbsp; X2=%d, Y2=%d\\n&quot;, xPos1, yPos1, xPos2, yPos2);<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/the centers of the ball when they actually collided<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball1-&gt;xPos = ball1-&gt;xPos &#8211; floor(ball1-&gt;dwVelX*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball1-&gt;yPos = ball1-&gt;yPos &#8211; floor(ball1-&gt;dwVelY*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball2-&gt;xPos = ball2-&gt;xPos &#8211; floor(ball2-&gt;dwVelX*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball2-&gt;yPos = ball2-&gt;yPos &#8211; floor(ball2-&gt;dwVelY*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/now calulate the distance between centers (this should be very close to the sum of their radii)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; dx = ball2-&gt;xPos &#8211; ball1-&gt;xPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; dy = ball2-&gt;yPos &#8211; ball1-&gt;yPos;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; distance = sqrt(dx*dx+dy*dy);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/ Unit vector in the direction of the collision<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double ax = dx\/distance, ay=dy\/distance;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/ Projection of the velocities in these axes<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double va1 = (ball1-&gt;dwVelX*ax + ball1-&gt;dwVelY*ay);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double vb1 = (-ball1-&gt;dwVelX*ay + ball1-&gt;dwVelY*ax);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double va2 = (ball2-&gt;dwVelX*ax + ball2-&gt;dwVelY*ay);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double vb2 = (-ball2-&gt;dwVelX*ay + ball2-&gt;dwVelY*ax);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/ New velocities in these axes (after collision): ed&lt;=1,&nbsp; for elastic collision ed=1<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double vaP1 = va1 + (1+ed)*(va2-va1)\/(1 + mass1\/mass2);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; double vaP2 = va2 + (1+ed)*(va1-va2)\/(1 + mass2\/mass1);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/ Undo the projections<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; velX1 = vaP1*ax-vb1*ay;&nbsp; velY1 = vaP1*ay+vb1*ax;\/\/ new vx,vy for ball 1 after collision<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; velX2 = vaP2*ax-vb2*ay;&nbsp; velY2 = vaP2*ay+vb2*ax;\/\/ new vx,vy for ball 2 after collision<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/printf(&quot;CENTERS AFTER: X1=%d, Y1=%d&nbsp;&nbsp;&nbsp;&nbsp; X2=%d, Y2=%d\\n&quot;, xPos1, yPos1, xPos2, yPos2);<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/printf(&quot;Old Vel: velX1=%d, velY1=%d&nbsp;&nbsp;&nbsp;&nbsp; velX2=%d, velY2=%d\\n&quot;, dwVelX1, dwVelY1, dwVelX2, dwVelY2);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/new velocities of the balls<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball1-&gt;dwVelX = floor(velX1 + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball1-&gt;dwVelY = floor(velY1 + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball2-&gt;dwVelX = floor(velX2 + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball2-&gt;dwVelY = floor(velY2 + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/undo the correction done before<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball1-&gt;xPos = ball1-&gt;xPos + floor(ball1-&gt;dwVelX*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball1-&gt;yPos = ball1-&gt;yPos + floor(ball1-&gt;dwVelY*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball2-&gt;xPos = ball2-&gt;xPos + floor(ball2-&gt;dwVelX*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ball2-&gt;yPos = ball2-&gt;yPos + floor(ball2-&gt;dwVelY*dt + 0.5);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 128, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 128, 128);\">&nbsp;&nbsp;&nbsp; \/\/printf(&quot;New Vel: velX1=%d, velY1=%d&nbsp;&nbsp;&nbsp;&nbsp; velX2=%d, velY2=%d\\n&quot;, dwVelX1, dwVelY1, dwVelX2, dwVelY2);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\">This function is taken directly from <a href=\"http:\/\/www.phy.ntnu.edu.tw\/ntnujava\/index.php?topic=4.0\">Professor Fu-Kwun Hwang&#8217;s explanation<\/a> on 2D collisions. Changes made to the velocities and positions in <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">CalculateNewVelocities()<\/span> will be reflected back in the caller.<\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify; font-family: Comic Sans MS;\"><span style=\"font-weight: bold;\">Note<\/span>: I ran this program quite many times and sometimes it does fail. Maybe something like once in 30 runs. The marbles stick to each other and don&#8217;t let go. The problem is in the calculation of &#8216;<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">dt<\/span>&#8216;, where it tries to calculate where the balls would have been when they were about to collide (i.e. <span style=\"font-family: Verdana;\">D = R1 + R2<\/span>), but since even this is an approximation, it fails sometimes. One fix for this problem is to check if&nbsp; the balls collide after calculating the new position and velocities. If they do then adjust the position values such that new <span style=\"font-family: Verdana;\">D &gt; R1 + R2<\/span>. The problem mentioned above happens when after calculating the new positions and velocities for both marbles they still overlap.<\/div>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The code for colliding marbles is built on top of earlier changes to the DDEX3 sample. Look here, here and here for more information. There are a few changes I made in the code for making the marbles collide and I hope you have already gone through Prof. Fu-Kwun Hwang post on how to make &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2009\/07\/12\/bouncingcolliding-marbles-directdraw-part-8\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Bouncing\/Colliding marbles, DirectDraw, Part 8<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ktFF-4b","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/259"}],"collection":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/comments?post=259"}],"version-history":[{"count":1,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions"}],"predecessor-version":[{"id":260,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions\/260"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}