Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  collision detection for round objects  (Read 2333 times)
0 Members and 1 Guest are viewing this topic.
Offline wireless_whiz

Junior Newbie




Java games rock!


« Posted 2004-01-30 03:59:13 »

Hi, What would be the best way to handle collisions between circular images  i.e when the images are actually rectangular .png. I am looking at angular deflections based on the point of contact.

thanks
Offline JasonB

Junior Duke





« Reply #1 - Posted 2004-01-30 08:22:03 »

This seems relevant:

http://forum.java.sun.com/thread.jsp?forum=406&thread=476425&message=2216155

Offline wireless_whiz

Junior Newbie




Java games rock!


« Reply #2 - Posted 2004-01-30 09:49:57 »

Thanks. I have actually worked out the physics mainly. I was wondering how to get the pixel coordinates on the circle for collision detection.

if geometrically calculating the collision how do you deal with the transparent region of the image.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2004-01-30 20:00:12 »

one traditional way to do this is with shadow masks.

You create one mask that is the projection of the pixels down to a line and do a shifted bitwise comapre aganst the other obejcts mask.  if it collids you then either use masks for each line or go straight to pixel comparison.

Most games however don't bother as collision within a few pixels is often good enough...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #4 - Posted 2004-02-05 03:20:05 »

If these are perfect circles then a simple test of the square distance between the center of the circles is enough.
(dx*dx + dy*dy) <= (r1*r1 + r2*r2)

Offline Abuse

JGO Knight


Medals: 13


falling into the abyss of reality


« Reply #5 - Posted 2004-02-05 06:34:28 »

something like this? :-

http://www.pkl.net/~rsc/downloads/Balls2.jar

:warning:

This isn't a perfect solution (infact, a perfect solution is damn near impossible to obtain)
It isn't particularly performance optimised either.
All the source is in there though - the bit you will prolly be interested in is the Particle.checkCollisions().

my reference for some of the code was here :-

http://www.gamasutra.com/features/20020118/vandenhuevel_01.htm


Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline clevengr

Senior Newbie




Java games rock!


« Reply #6 - Posted 2004-03-19 21:58:59 »


Quote
Posted by: swpalmer Posted on: Feb 5th, 2004, 1:20am
If these are perfect circles then a simple test of the square distance between the center of the circles is enough.  
(dx*dx + dy*dy) <= (r1*r1 + r2*r2)


Actually I think this may be off by a bit.  You want to check if the distance between the centers is less than the sum of the radii, and do so by comparing their squares to avoid taking roots for efficiency. The left side is the square of the distance, but the right side is the sum of the squares of the radii -- not the square of the sum of the radii.
Somebody correct me if I'm wrong, but I think the RHS should be  (r1*r1 + 2*r1*r2 + r2*r2).

Minor point... unless your objects are penetrating each other and making your application look bad....
Offline polybios

Innocent Bystander




Java games rock!


« Reply #7 - Posted 2004-04-15 06:56:53 »

you're right, primary school math  Smiley Smiley Smiley Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (14 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (45 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!