
-----------------------------------
Aange10
Mon Jan 16, 2012 12:54 am

[Module] Collision
-----------------------------------
Features
This module does collision, so you don't have to! It takes all the stress out of collision, by allowing you to simply input the co-ordinates, and that's it. *Relatively no math involved.
Specifically, checking rectangular collisions becomes easier because this module checks 14 points, increasing accuracy, and keeping you from running needless perimeterfors. *Shutters*

How it Works
Here's a simple breakdown:

CircleToCircle : The module finds the distance between the centers of the two circles and compares it the the sum of the radii.
RectangeToRectangle : The module distinguishes a plane for the Rectangle, and detects 14 key points and looks for plane interception.
RectangleToCircle : The module fabricates a box to represent the Circle, and detects its 14 points along with the Rectangles.

Syntax

The syntax is super simple. 

Collision.circleToCircle (Ball_1_x, Ball_1_y, Ball_1_xr, Ball_1_yr, Ball_2_x, Ball_2_y, Ball_2_xr, Ball_2_yr) 

Collision.rectangleToRectangle (Rect_1_x1, Rect_1_y1, Rect_1_x2, Rect_1_y2, Rect_2_x1, Rect_2_y1, Rect_2_x2, Rect_2_y2)

Collision.rectangleToCircle (Rect_x1, Rect_y1, Rect_x2, Rect_y2, Ball_x, Ball_y, Ball_xr, Ball_yr)


The syntax is very self explanatory, and all of the functions output a Boolean that indicates collision.

The parameters are also all integers.

Instructions

1) Import Collision.tu
2) Call the functions with their appropriate syntaxs.
3) Done!

The Module
Just copy and paste this in a Turing File, and name it "Collision.tu"!

unit
% David H


module Collision
    export circleToCircle, rectangleToCircle, rectangleToRectangle
    
    var distance : real
    
    %==========================================================================%
    % = == = == = == = == = == = == Circle To Circle == = == = == = == = == = =%
    %==========================================================================%
    fcn circleToCircle (x1, y1, xr1, yr1, x2, y2, xr2, yr2 : int) : boolean
        distance := sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
        if distance :]

>:D Good, I've learned a lot already xD

-----------------------------------
Aange10
Tue Jan 24, 2012 10:21 pm

RE:[Module] Collision
-----------------------------------
A response would be appreciated :)

-----------------------------------
Zren
Wed Jan 25, 2012 12:35 am

Re: RE:[Module] Collision
-----------------------------------
Hmmm oh right.


I like the part where you didn't even use your own functions for the new CircleRectangle collision test...


What do you mean?


I mean you redid rectangle and circle collision tests instead of using your own functions... Just look at your circleXrect function:


if circleX >= recX1 - radius and circleY >= recY1 - radius and circleX 