Java-Gaming.org Hi !
 Featured games (88) games approved by the League of Dukes Games in Showcase (679) Games in Android Showcase (194) games submitted by our members Games in WIP (732) 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 2973 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: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « 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: 373
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.

 Hydroque (17 views) 2016-05-26 14:45:46 Mac70 (39 views) 2016-05-24 21:16:33 theagentd (42 views) 2016-05-14 18:38:35 theagentd (76 views) 2016-05-10 22:37:41 theagentd (83 views) 2016-05-10 22:33:46 IanParcs (110 views) 2016-04-18 14:18:53 KaiHH (107 views) 2016-04-18 08:35:41 KaiHH (130 views) 2016-04-15 12:43:58 theagentd (134 views) 2016-04-14 02:16:17 theagentd (157 views) 2016-04-14 02:15:43
 orange451 27x purenickery 26x theagentd 25x SHC 21x ags1 17x SilverTiger 15x chrislo27 15x Roquen 13x Spasi 12x DarkCart 12x Slyth2727 12x h.pernpeintner 12x everythingever 12x Mac70 11x Riven 10x Opiop 10x
 FPS Camera Tutorialby Hydroque2016-05-22 05:40:58Website offering 3D Models specifically for games for freeby vusman2016-05-18 17:23:09Website offering 3D Models specifically for games for freeby vusman2016-05-09 08:50:56Website offering 3D Models specifically for games for freeby vusman2016-05-06 11:10:21Website offering 3D Models specifically for games for freeby vusman2016-04-29 12:56:17List of Learning Resources2016-02-05 09:39:47List of Learning Resources2016-02-05 09:38:38List of Learning Resources2016-02-05 09:35:50
 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