Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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]
nelsongames (5 views)
2018-04-24 18:15:36

nelsongames (5 views)
2018-04-24 18:14:32

ivj94 (586 views)
2018-03-24 14:47:39

ivj94 (49 views)
2018-03-24 14:46:31

ivj94 (383 views)
2018-03-24 14:43:53

Solater (63 views)
2018-03-17 05:04:08

nelsongames (110 views)
2018-03-05 17:56:34

Gornova (159 views)
2018-03-02 22:15:33

buddyBro (704 views)
2018-02-28 16:59:18

buddyBro (93 views)
2018-02-28 16:45:17
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!