View previous topic - View next topic |
Author |
Message |
Ninkazu Demon Hunter
Joined: 08 Aug 2002 Posts: 945 Location: Location:
|
Posted: Sun May 09, 2004 9:05 pm Post subject: 2D collision detection problems |
[quote] |
|
I'm making a game for my Computer Science II class, and I have everything done, but there's a bug in the segment-segment collision detection routine (class name - independent). Just check it out.
Warning: Java.
http://www.venosoft.com/ninkazu/stuff/ship.zip
The problem I'm seeing is the line right above the beginning position... you can go right through it, but not any other line.
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Sun May 09, 2004 11:02 pm Post subject: |
[quote] |
|
I notice a few other problems, like flickering (you didn't get double buffering to work yet?) and when I press up, the ship accelerates so much I keep slamming into some wall instantly and die. I didn't really get a chance to notice the problem you mention.
BTW, I think it is better to put each class in its own file and make them public than to put all those classes in each file...
Edit: Ah, with the other ship I indeed pass right through the first line...
|
|
Back to top |
|
|
Ninkazu Demon Hunter
Joined: 08 Aug 2002 Posts: 945 Location: Location:
|
Posted: Sun May 09, 2004 11:18 pm Post subject: |
[quote] |
|
Ya, I've just been using Jett for debugging purposes. Also, I've tried many, MANY different buffering techniques, all of which didn't work. This is the closest to no flicker as is possible.
|
|
Back to top |
|
|
BigManJones Scholar
Joined: 22 Mar 2003 Posts: 196
|
Posted: Mon May 10, 2004 12:03 am Post subject: |
[quote] |
|
There is a problem with the 4 yr old/out of date jre 1.3 where applications flicker like mad. So as long as your *not* using that there should be no problem.
Quote: | Also, I've tried many, MANY different buffering techniques, all of which didn't work. |
Edit; you must have tried the wrong ones.
Check out the space invaders tutorials on this page.
|
|
Back to top |
|
|
Ninkazu Demon Hunter
Joined: 08 Aug 2002 Posts: 945 Location: Location:
|
Posted: Mon May 10, 2004 12:34 am Post subject: |
[quote] |
|
Thanks man, that really helped. No flicker, but now there's one new imposing problem.... everything's offset by -20 y. It's easy to apply the changes yourself, but here's the updated code if you're lazy :P
http://www.venosoft.com/ninkazu/stuff/ship2.zip
::EDIT::
more like -40 y, but I still have no clue how to change this.
|
|
Back to top |
|
|
Ninkazu Demon Hunter
Joined: 08 Aug 2002 Posts: 945 Location: Location:
|
Posted: Tue May 11, 2004 2:39 am Post subject: |
[quote] |
|
Ok, I just offset all my stuff a few pixels and it works fine. The collision was giving me shit hard times, but now I have a sound algorithm. If you guys make a game like this in the future, REMEMBER THIS DAMNED ALGO!
Code: |
public static boolean collision (CPoint2D e1, CPoint2D e2, CPoint2D e3, CPoint2D e4)
{
long a1, a2, b1, b2, c1, c2; /* Coefficients of line eqns. */
long r1, r2, r3, r4; /* 'Sign' values */
long denom;
/* Compute a1, b1, c1, where line joining points 1 and 2
* is "a1 x + b1 y + c1 = 0".
*/
a1 = e2.Y() - e1.Y();
b1 = e1.X() - e2.X();
c1 = e2.X() * e1.Y() - e1.X() * e2.Y();
/* Compute r3 and r4.
*/
r3 = a1 * e3.X() + b1 * e3.Y() + c1;
r4 = a1 * e4.X() + b1 * e4.Y() + c1;
/* Check signs of r3 and r4. If both point 3 and point 4 lie on
* same side of line 1, the line segments do not intersect.
*/
if ( r3 != 0 && r4 != 0 && ( (r3^ r4)>=0 ))
return false;
/* Compute a2, b2, c2 */
a2 = e4.Y() - e3.Y();
b2 = e3.X() - e4.X();
c2 = e4.X() * e3.Y() - e3.X() * e4.Y();
/* Compute r1 and r2 */
r1 = a2 * e1.X() + b2 * e1.Y() + c2;
r2 = a2 * e2.X() + b2 * e2.Y() + c2;
/* Check signs of r1 and r2. If both point 1 and point 2 lie
* on same side of second line segment, the line segments do
* not intersect.
*/
if ( r1 != 0 && r2 != 0 && ((r1^ r2)>=0))
return false;
denom = a1 * b2 - a2 * b1;
if ( denom == 0 )
return false; //collinear
return true;
}
|
|
|
Back to top |
|
|
Adam Mage
Joined: 30 Dec 2002 Posts: 416 Location: Australia
|
Posted: Tue May 11, 2004 2:46 am Post subject: |
[quote] |
|
was this one by you or lifted from somewhere else? _________________ https://numbatlogic.com
|
|
Back to top |
|
|
Ninkazu Demon Hunter
Joined: 08 Aug 2002 Posts: 945 Location: Location:
|
Posted: Tue May 11, 2004 11:05 am Post subject: |
[quote] |
|
Lifted :P
|
|
Back to top |
|
|