Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (595) Games in Android Showcase (169) games submitted by our members Games in WIP (648) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 [SOLVED] {lwjgl} Recreate the "intersects" for Rectangle collision  (Read 2516 times) 0 Members and 1 Guest are viewing this topic.
alaslipknot
 « Posted 2013-04-30 20:28:10 »

Hello,
i've spend the last night reading examples from the lwjgl wiki, and getting started wasn't so hard like i thought
soooo i decided to make a simple pong and actually it was very easy to do, and now am trying to make a "Brick Breaker" game, and to make it happens, i need a collision detection method, for now i just want to recreate the Java2D intersects method,
and here is the way am doing it, it still doesn't work

calculate the distance between the 2 rectangle
 1  2  3 `float dx = x - x2;  float dy = y - y2; double dxy = Math.sqrt((dx * dx) + (dy * dy)); `

the white line represent the distance

after that, i thought that if the length of that line is less than the rectangle width, then there is a collision,
i tried it, it works, but only when the collision is from the sides and the rectangle have the same width .
so i thought maybe i'll need the sum of the 2 rectangles diagonals
 1  2  3 `double diago1 = Math.sqrt(w*w+h*h);double diago2 = Math.sqrt(w2*w2+h2*h2);double diagSum = diago1/2 + diago2/2 ;`

and the result was better than the previous one but still didn't work,
sooooo guys
any help   ??

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
wreed12345

JGO Knight

Medals: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « Reply #1 - Posted 2013-04-30 20:39:43 »

You could try a simple AABB collision method
Just google AABB collision detection theres sure to be numerous results

Axeman

Senior Devvie

Medals: 7

 « Reply #2 - Posted 2013-04-30 21:31:36 »

I posted a AABB method a couple of days back. Hope it helps.

http://www.java-gaming.org/topics/corner-collision-detection-need-help/29399/msg/269818/view.html#msg269818
HeroesGraveDev

JGO Kernel

Medals: 359
Projects: 11
Exp: 3 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #3 - Posted 2013-04-30 21:59:39 »

Seems to be the same technique as mine (the link wreed12345 posted) except you do this:
 1 `if(a - b < 0)`

Where I do this:
 1 `if(a < b)`

Doesn't make much of a difference though. Just noticed a little optimisation.

alaslipknot
 « Reply #4 - Posted 2013-04-30 22:02:43 »

"It's not at all important to get it right the first time. It's vitally important to get it right the last time."
Axeman

Senior Devvie

Medals: 7

 « Reply #5 - Posted 2013-04-30 22:35:35 »

Doesn't make much of a difference though. Just noticed a little optimisation.

Yeah, it´s the same idea. But since I also wrote some stuff about how to deal with a collision I thought it was worth the extra post.
Axeman

Senior Devvie

Medals: 7

 « Reply #6 - Posted 2013-05-01 14:24:54 »

You´re welcome! Feel free to press the "appreciate" buttons...
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 KaiHH (25 views) 2015-07-07 11:39:58 deepthought (55 views) 2015-06-30 15:39:44 deepthought (58 views) 2015-06-30 15:39:09 deepthought (67 views) 2015-06-30 15:36:52 Za\'Anzabar (45 views) 2015-06-29 05:44:54 TritonDreyja (51 views) 2015-06-24 17:10:40 CopyableCougar4 (53 views) 2015-06-23 00:34:45 BurntPizza (59 views) 2015-06-21 20:36:46 cookiecompiler (100 views) 2015-06-11 15:42:53 cookiecompiler (58 views) 2015-06-11 15:41:14
 princec 31x orangepascal 22x wessles 19x CopyableCougar4 19x EgonOlsen 18x theagentd 18x BurntPizza 17x opiop65 17x ags1 16x nsigma 15x Riven 14x KaiHH 13x KevinWorkman 11x sunburn 11x Jesse 11x Abuse 10x
 How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org