Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (601) Games in Android Showcase (171) games submitted by our members Games in WIP (649) 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 2552 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: 360
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.

 Jesse (11 views) 2015-07-29 04:35:27 Riven (33 views) 2015-07-27 16:38:00 Riven (16 views) 2015-07-27 15:35:20 Riven (20 views) 2015-07-27 12:26:13 Riven (10 views) 2015-07-27 12:23:39 BurntPizza (28 views) 2015-07-25 00:14:37 BurntPizza (39 views) 2015-07-24 22:06:39 BurntPizza (22 views) 2015-07-24 06:06:53 NoxInc (26 views) 2015-07-22 22:16:53 NoxInc (17 views) 2015-07-22 22:13:39
 wessles 49x theagentd 45x basil_ 35x orangepascal 28x KaiHH 27x ags1 20x Riven 20x mooman219 17x princec 16x KudoDEV 13x bornander 12x klaus 11x Jesse 10x philfrei 9x Zaneris 9x deepthought 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How 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:21
 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