Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2d Collision Detection With Rotating Rectangles... anyone?
#2
Did I understand you right?
In your program, there are some objects (rotating rectangles). As they're rotating, treat them as circles.
So you only had to calculate the distance of any point to the middle of your object:

Code:
TYPE Object
x1 AS INTEGER
y1 AS INTEGER
x2 AS INTEGER
y2 AS INTEGER
END TYPE
DIM abc AS Object

...

'Calulate middle of your object
'Perhaps you'd like to use Integer-Divs...
xm = (abc.x1 + abc.x2) / 2
ym = (abc.y1 + abc.y2) / 2

'Now calculate the radius of the circle:
tmpDistX = xm - abc.x1
tmpDistY = ym - abc.y1
radius = SQR(xm^2 + ym^2) 'Phythagoras

Now, you only need to check, if any point (x|y) is inside the radius.
For this, you have to calculate the distance of (x|y) to (xm|ym) by using the Phythagoras.

Hope it helped you!
PS:
I'm 16, UNDER the age of 25 8)


Have a nice day!
Ciao


/Edit:
Of course, your object will have much more elements in the TYPE-Block. For simplicity, I only postet the coordinates of the opposite corners.
It could be something like this:

Code:
Q
          / \
         /   -
(x1|y1) P     \
         \ M   R (x2| y2)
          -   /
           \ /
            S

(I know, It doesn't really look like a rectangle...)

Q and S must be definded by the angle, or by own coordinates. In this case, R should have the coordinates (x3| y3), to give it mathematical correctnes 8)

The disadvantage of this method is, that the Collision is detected, although the two elements aren't touching. Big rectangles will have a big "dummy-Space"...
But: It's QUITE easy to implement, and the size of the dummy-space should be abidable...

Example:
x1 = 100
y1 = 100
x2 = 150
y2 = 150

=>
xm = 125
ym = 125
radius = 35.36
dummySpace = ~10


Users won't detect this little mistake, if the game is only fast enough *g*
ometimes, i think it is not logical to say
x = x + 1


This post is fully recycleable
Reply


Messages In This Thread
2d Collision Detection With Rotating Rectangles... anyone? - by Dusky_Joe - 04-06-2005, 07:34 PM
Line - Line Intersection - by keeling - 04-08-2005, 09:18 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)