Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (575) Games in Android Showcase (154) games submitted by our members Games in WIP (623) 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 2384 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: 354
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.

 BurntPizza (29 views) 2015-04-23 03:42:11 theagentd (35 views) 2015-04-22 16:23:07 Riven (48 views) 2015-04-16 10:48:47 Duke0200 (59 views) 2015-04-16 01:59:01 Fairy Tailz (41 views) 2015-04-14 20:13:12 Riven (43 views) 2015-04-12 21:36:37 bus hotdog (60 views) 2015-04-10 02:39:32 CopyableCougar4 (66 views) 2015-04-10 00:51:04 BurntPizza (69 views) 2015-04-06 22:06:58 ags1 (67 views) 2015-04-02 10:58:48
 theagentd 23x BurntPizza 17x wessles 15x kingroka123 11x alwex 11x 65K 11x kevglass 8x Rayvolution 8x Roquen 7x chrislo27 7x Hanksha 7x Riven 7x Olo 7x Ecumene 7x ra4king 7x KevinWorkman 6x
 How 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:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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