Is there any way to tell if a shape collides with another shape im trying to make a simple game to test things. Im drawing circles with fillpie.
Simplest collision detection.
Circle to circle for 2D.
Sphere to Sphere for 3D
Radius of sphere???? (r)
Radius of Sphere A = rA
Radius of Sphere B = rB
Center position of Sphere A = vA
Center position of Sphere B = vB
You mentioned a circle, but for 2D or 3D but same principle applies.
Calculate distance between two points! (Pythagorean Thereom)
vD = vB - vA; vD.x = vB.x - vA.x vD.y = vB.y - vA.y vD.z = vB.z - vA.z // If 3D fDist = sqrt( (vD.x * vD.x) + (vD.y * vD.y) ); // 2D fDist = sqrt( (vD.x * vD.x) + (vD.y * vD.y) + (vD.z * vD.z) ); // 3D
So fDist is distance between the two points.
If distance between the two sphere centers is equal to rA + rB then you are touching. Less then that then you're merged!
So if (fDist < rA+rB) collided else if (fDist == rA+rB) touching else not collision
If you have a lot of objects doing the square root takes time so instead do the distance calculation but skip the square root.
Then calculate but square the radius distance
r = rA + rB
r = r * r;
So now do the same comparison, but no need to spend processor time doing the square root operation.
thanks. I really should have thought of that.
There are many ways to optimize this, however, implementing those in script is difficult. Does anyone have any suggestions?
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...