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 (731)
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);
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;

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;

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!

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
  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,

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....


Pages: [1]
Mac70 (7 views)
2016-05-24 21:16:33

theagentd (39 views)
2016-05-14 18:38:35

theagentd (70 views)
2016-05-10 22:37:41

theagentd (74 views)
2016-05-10 22:33:46

IanParcs (106 views)
2016-04-18 14:18:53

KaiHH (99 views)
2016-04-18 08:35:41

KaiHH (126 views)
2016-04-15 12:43:58

theagentd (130 views)
2016-04-14 02:16:17

theagentd (152 views)
2016-04-14 02:15:43

IanParcs (246 views)
2016-04-12 03:51:16
FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50 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‑
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!