Topic:   Shape Collision Detections   (Read 39298 times)


0 Members and 1 Guest are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Shape Collision Detections
« on: January 01, 2010, 11:21:04 PM »
This thread is to host code to detect collisions of different shapes such as lines, rectangles, and ovals.
This is very needed in Sc with the drawing commands as people will want to take them higher and further then ever before. It'll also become popular in Gm as Al will implement them eventually.
Now I am in search of such code/formulas and shall post them when I find/figure them out. Here is the code for collision with these shapes:
Line - Line:
Code: [Select]
Unknown
Line - Rect:
Code: [Select]
Unknown
Line - Oval:
Code: [Select]
Unknown
Rect - Rect:
Code: [Select]
Unknown
Rect - Oval:
Code: [Select]
Unknown
Oval - Oval:
Code: [Select]
Unknown

If any of you know how to get intersection/collision points of either shapes, please post!

-Gandolf
« Last Edit: January 01, 2010, 11:22:26 PM by Gandolf »

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Shape Collision Detections
« Reply #1 on: January 01, 2010, 11:38:42 PM »
Whoa, check this link out:
http://www.geometrictools.com/Documentation/Documentation.html
It's as if it has everything you'll ever need to build a collision/physics/other game.


-Gandolf

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Shape Collision Detections
« Reply #2 on: February 10, 2010, 12:34:23 PM »
I've figured out a fast an easy method for finding the intersection point of two lines. :)
With this I can get all kinds of collision detections between lines and line shapes such as triangles, rectangles, ect...
I can now make perfect and fast collision detection between shapes and even sprites.
Here's the formula:
Code: [Select]
//Line 1
int x1 = 10;
int y1 = 210;
int x2 = 200;
int y2 = 10;

//Line 2
int x3 = 10;
int y3 = 200;
int x4 = 200;
int y4 = 10;

//Now let us find x and y of intersection point

float x = ( (x1*y2-y1*x2)*(x3-x4) - (x1 - x2)*(x3*y4 - y3*x4) ) / ( (x1-x2)*(y3-y4)-(y1-y2)*(x3-x4) );
float y = ( (x1*y2-y1*x2)*(y3-y4) - (y1 - y2)*(x3*y4 - y3*x4) ) / ( (x1-x2)*(y3-y4)-(y1-y2)*(x3-x4) );


-Gan
« Last Edit: February 10, 2010, 12:34:34 PM by Gandolf »

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: Shape Collision Detections
« Reply #3 on: February 10, 2010, 02:17:22 PM »
So much for not being able to type :P

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: Shape Collision Detections
« Reply #4 on: February 10, 2010, 03:39:06 PM »
Oh, I can still type but only with my left hand.


-Gan