Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / Some help with collision detection on: 2007-07-06 23:51:54
Hi All,

I am having a lot of difficulty with collision detection. Actually, I'm not certain if it's a problem with collision detection specifically or something I just don't understand about OpenGL. Smiley I have adapted Oleg Dopertchouk's example from "Simple Bounding-Sphere Collision Detection" for a Java game using JOGL. ( Thanks to Oleg! ) Here is my method:
boolean sphereTest(AbstractGameObject obj1, AbstractGameObject obj2)
{
// Relative velocity
Vector3D dv = Vector3D.substract(obj2.getVelocity(),obj1.getVelocity());
// Relative position
Vector3D dp = Vector3D.substract(obj2.getPosition(),obj1.getPosition());
//Minimal distance squared
float r = (obj1.getWidth() / 2) + (obj2.getWidth() / 2);
//dP^2-r^2
float pp = dp.x * dp.x + dp.y * dp.y + dp.z * dp.z - r*r;
//(1)Check if the spheres are already intersecting
if ( pp < 0 ) return true;

//dP*dV
float pv = dp.x * dv.x + dp.y * dv.y + dp.z * dv.z;
//(2)Check if the spheres are moving away from each other
if ( pv >= 0 ) return false;

//dV^2
float vv = dv.x * dv.x + dv.y * dv.y + dv.z * dv.z;
//(3)Check if the spheres can intersect within 1 frame
if ( (pv + vv) <= 0 && (vv + 2 * pv + pp) >= 0 ) return false;

//tmin = -dP*dV/dV*2
//the time when the distance between the spheres is minimal
float tmin = -pv/vv;

//Discriminant/(4*dV^2) = -(dp^2-r^2+dP*dV*tmin)
return ( pp + pv * tmin > 0 );
}

Now this works like a charm if obj2 is sitting at 0.0f,0.0f,0.0f, but the further down on the screen obj2 is ( for example -.5f on the y axis ) obj1 collides sooner. Way to soon. And the further down it is the sooner it collides. If obj2 is further up the screen from the center ( for example .5f on the y axis ) then the collision happens way too late. It's very odd to me. The output of my tracing is:
Ball 0.0,-0.57959735,0.0 w=0.06 h=0.06 collided with TestBlocker 0.0,-0.5,0.0 w=0.1 h=0.05

Unless I am missing something, the above output looks correct, however the 2 objects are miles from each other. Can anyone give me hints as to what the problem might be?

Many thanks!

-B
2  Game Development / Newbie & Debugging Questions / Re: Game programming books on: 2004-04-08 19:05:21
Thanks for the link, but this in no way answers my questions.
3  Java Game APIs & Engines / Java 3D / Re: OpenGL or DirectX? on: 2004-04-08 14:19:38
So you're saying that it's a configuration option or a method call that specifies to use OpenGL or DirectX?

It would seem since Java 3D is not specific on the underlying API, it would be better to use something like JOGL if you want to strictly use OpenGL.  Am I wrong?
4  Game Development / Newbie & Debugging Questions / Game programming books on: 2004-04-08 14:14:14
Hello,
  I have just begun digging into Java games and I am trying to get all the information I can. Does anyone have suggestions for good books? I have heard many good things about "Developing Games in Java" by David Brackeen. This guy also has a web site with examples of games he has written which look pretty cool.  

  Also, which API's are most commonly used for Java game development. I have heard of this JOGL.  Has anyone here used it?  

many thanks,

Barry
5  Java Game APIs & Engines / Java 3D / OpenGL or DirectX? on: 2004-04-08 12:19:21
From the Java3D FAQ What is Java3D? "...It uses either DirectX or the OpenGL low level API to take advantage of 3D hardware acceleration."

Can someone tell me what this means? Does it use both? I thought you had to use one or the other.

I am a gaming beginner....

thanks,

Barry
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!