Jump to content

  • Log In with Google      Sign In   
  • Create Account


A Few OpenGL Collision Detection Questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 MrLolEthan   Members   -  Reputation: 106

Like
0Likes
Like

Posted 14 December 2012 - 06:05 PM

Is there any way I can make an invisible cube (Like a Bounding Box) and use .intersects() or something on it like a rectangle? If not then whats the easiest way to do Collision Detection (3D) in Java?

Thanks,
Ethan.

EDIT:
I got the collision detection working but now i'm wondering if anyone has an algorithm or way of doing the "stop letting me walk into the object on collision" stuff (what I tried made me go to the same spot each time (x -= x - 0.3749997f same for z really)).

Edited by MrLolEthan, 18 December 2012 - 04:35 PM.


Sponsor:

#2 VildNinja   Members   -  Reputation: 420

Like
0Likes
Like

Posted 14 December 2012 - 07:04 PM

This is not related to OpenGL

if you just want to detect if two AABBs overlaps, you can fairly easily code it yourself:

for (AABB other : allAABBs)
sweep for collisions on x-axis: if other.min.x < this.max.x && other.max.x > this.min.x
if true sweep for collisions on y-axis: -
if true sweep for collisions on y-axis: -
if true yes they do collide.

If you have an insane amount of objects you could put them into an oct-tree, but the above approach is very fast

If you want some thing more you should look into one of these: http://www.google.dk/search?q=3D+physics+java&aq=f&oq=3D+physics+java&sugexp=chrome,mod=9&sourceid=chrome&ie=UTF-8

or this: http://jbullet.advel.cz/

#3 MrLolEthan   Members   -  Reputation: 106

Like
0Likes
Like

Posted 15 December 2012 - 06:23 AM

This is not related to OpenGL

if you just want to detect if two AABBs overlaps, you can fairly easily code it yourself:

for (AABB other : allAABBs)
sweep for collisions on x-axis: if other.min.x < this.max.x &amp;&amp; other.max.x > this.min.x
if true sweep for collisions on y-axis: -
if true sweep for collisions on y-axis: -
if true yes they do collide.

If you have an insane amount of objects you could put them into an oct-tree, but the above approach is very fast

If you want some thing more you should look into one of these: http://www.google.dk...chrome&amp;ie=UTF-8

or this: http://jbullet.advel.cz/

Could you please give me a snippet of code to show how its done? (Sorry i'm new to Java Game Developement) (Btw i'm using Lwjgl and I looked into JBullet but JBullet didn't look like it's compatible with Lwjgl)

Edited by MrLolEthan, 15 December 2012 - 06:26 AM.


#4 VildNinja   Members   -  Reputation: 420

Like
0Likes
Like

Posted 15 December 2012 - 06:51 AM

Could you please give me a snippet of code to show how its done? (Sorry i'm new to Java Game Developement) (Btw i'm using Lwjgl and I looked into JBullet but JBullet didn't look like it's compatible with Lwjgl)

Yes it is. But you have to make the binding yourself, i.e. if you create a mesh of a cube in 3D, you need to get the position and rotation of it from an equivalent cube in your physics model. You can take a look on the source of the JBullet demos. It uses jogl, but the openGL code should be the same.

If you don´t want to do it yourself you can take a look at http://jmonkeyengine.com

#5 metsfan   Members   -  Reputation: 653

Like
0Likes
Like

Posted 16 December 2012 - 09:34 AM

You seem to have a fundamental misunderstanding of what OpenGL is. OpenGL is just a graphics driver. It provides an interface between your program and the pipeline used by your graphics card to output information to screen. Collision detection is a completely separate process that uses bounding volumes created from the geometry of your objects to find collisions. I would suggest learning more about game engines in general. Once you understand how game engines and subsystems work (collision detection is just one of many subsystems in a game), I would then focus your efforts on learning about collision detection. You may find that the best option for you is to use an already-made library.

As for Bullet and OpenGL not being compatible: once again, this is a fundamental misunderstanding of what these two pieces of software do. OpenGL and Bullet are completely separate entities that provides two completely different functions. However, the key between them is that you can use the same geometry to power both engines. They just process them differently: Bullet uses the geometry to create an abstraction of a physics simulation, and OpenGL uses the geometry to color pixels on the screen.

Here are some books on the subject that you may find interesting:
Game Coding Complete - This book will give you some insight into how game engines work.
http://www.amazon.com/Game-Coding-Complete-Fourth-Edition/dp/1133776574/ref=sr_1_1?ie=UTF8&qid=1355671800&sr=8-1&keywords=game+coding+complete

Game Engine Architecture - This book will teach you how to build a commercial-grade game engine.
http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135/ref=sr_1_1?s=books&ie=UTF8&qid=1355671868&sr=1-1&keywords=game+engine+architecture

Real Time Collision Detection - This book will become your bible for collision detection
http://www.amazon.com/Real-Time-Collision-Detection-Interactive-Technology/dp/1558607323/ref=sr_1_1?s=books&ie=UTF8&qid=1355671841&sr=1-1&keywords=real+time+collision+detection%5C

Good luck.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS