Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  Java 3D Collision Detection Library?  (Read 7217 times)
0 Members and 1 Guest are viewing this topic.
Offline elias4444

Junior Member





« Posted 2010-02-23 19:25:01 »

Collision detection is becoming the bane of my existence. I can do the simple stuff (spheres and AABBs), but I'm always running into loopholes and problems. I was wondering, is there a native Java 3D collision detection library out there that I can just use and that just works?

It looks like JBullet has just about anything I could want for collision detection, but can you use it separate from the physics? Is JBullet even still active?

Are there other options?

Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #1 - Posted 2010-02-23 20:09:54 »

It probably comes down to how you are stepping your simulation. Maybe expand more about what problems you are having doing your own collision detection.

Offline elias4444

Junior Member





« Reply #2 - Posted 2010-02-23 20:38:27 »

I'm sure there are numerous issues with my own collision detection code. I'm really more interested in using a library if it's available though. This is one of those mathematically intensive things that libraries should readily exist for anyway (IMHO). It seems like everyone is just reinventing the wheel each time they need it. There's numerous options out there for C and C++, so I'm just looking for a Java option.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jezek2
« Reply #3 - Posted 2010-02-23 21:14:43 »

Yes, JBullet can be used just for collision detection. Use CollisionWorld and CollisionObjects instead of DynamicsWorld/RigidBodies, or even concrete algorithm classes directly. Beware though that the collision part is optimized towards dynamic objects (eg. objects have some margin by default) and made with more universal interface, there are better approaches for static geometry (like specialized KDTree implementation with direct access to your data or having own internal optimized representation).

JBullet is active though the development is quite slow these days. But it's actively maintained and supported and it will be for years.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #4 - Posted 2010-02-23 21:24:19 »

Part of the issue of just a collision system is that in order to avoid a lot of those loopholes and things you need to know a lot about how, where, and how fast an object is moving. Simple static collision testing will not usually cover everything.

See my work:
OTC Software
Offline elias4444

Junior Member





« Reply #5 - Posted 2010-02-23 22:09:38 »

Thanks for the info on JBullet Jezek! I'll dig into the JBullet source code and see if I can find where the algorithms are hiding.

Demon and Nate, I have a solid implementation for spheres, capsules, and AABBs (using swept spheres and corner rays for movement), but my biggest issue comes into play with (of all stupid things) walls. As long as my walls are axis aligned I'm fine, but once I rotate something or setup a diagonal it all falls apart.  Then, when I go to add something more like OBBs, I start having troubles with OBB vs capsule detection, not to mention the whole issue of figuring out the best size and rotation of the OBB in the first place. And just when I think I've got it, players let me know that a few of them (odd that it's only a few) can fall through the walls. I'm sure I would have an optimized collision detection system if I could build my own, but I'm getting frustrated with how one little thing turns into a dozen extra classes I have to write from a bunch of math algorithms that I still don't totally understand... ouch, my head hurts.

Offline DzzD
« Reply #6 - Posted 2010-02-24 00:05:40 »

... And just when I think I've got it, players let me know that a few of them (odd that it's only a few) can fall through the walls. I'm sure I would have an optimized collision detection system if I could build my own, but I'm getting frustrated with how one little thing turns into a dozen extra classes I have to write from a bunch of math algorithms that I still don't totally understand...

falling throught wall can be due to the lack of precision of double/float, something like that you compute the position after collision and think it is still in front or just touching the wall (same for edges) but in realty it is a little behind and if you dont manage this case you go throught the wall, even if it happen rarely this is not soemthing that you can let player esperience too much

Offline jezek2
« Reply #7 - Posted 2010-02-24 00:13:31 »

One advantage of JBullet's collision system is that it has convex sweep tests (but use them with GhostObject for better performance). In my game I use these for FPS character. It just uses two sweep tests of capsule against static geometry. First towards the direction it's moving and when it hits a wall it uses second to achieve sliding along the wall. There is also another sphere sweep test for vertical movement.

Convex sweep tests are really great because they can't miss and if you maintain some little margin you can't run into float imprecision either.
Offline elias4444

Junior Member





« Reply #8 - Posted 2010-02-24 00:36:15 »

Does JBullet optimize large terrain objects at all? Meaning: if I feed the collisionworld a large mesh made up of numerous triangles (let's use an ugly example of the entire interior of a building all as one mesh), will JBullet be testing whatever dynamic object I put inside against every single triangle for the mesh every update? Or does it break it down using something like an octree?

Not that I would do that mind you! I'm just trying to get an idea of how JBullet handles things.


Offline Momoko_Fan

Junior Member


Medals: 2



« Reply #9 - Posted 2010-02-24 00:52:10 »

Quote
Does JBullet optimize large terrain objects at all? Meaning: if I feed the collisionworld a large mesh made up of numerous triangles (let's use an ugly example of the entire interior of a building all as one mesh), will JBullet be testing whatever dynamic object I put inside against every single triangle for the mesh every update? Or does it break it down using something like an octree?
Yes it does. Triangle tests are very expansive and partitioning them gives a very good boost in speed.

jME3 currently has a collision system that implements what you want, it might be possible to separate it so it becomes a general purpose collision system that can be used in any java game.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline elias4444

Junior Member





« Reply #10 - Posted 2010-02-24 00:54:45 »

Guess I should have asked a singular question. Sorry.

Quote
Yes it does.
Yes to which one? It tests the object against every single triangle each update? Or it organizes it into an octree (or something similar)?


Edit: BTW, is jME3 available anywhere? I can only find info for downloading jME2 (which I tried a year or so ago).

Offline DzzD
« Reply #11 - Posted 2010-02-24 01:11:32 »

One advantage of JBullet's collision system is that it has convex sweep tests (but use them with GhostObject for better performance). In my game I use these for FPS character. It just uses two sweep tests of capsule against static geometry. First towards the direction it's moving and when it hits a wall it uses second to achieve sliding along the wall. There is also another sphere sweep test for vertical movement.

Convex sweep tests are really great because they can't miss and if you maintain some little margin you can't run into float imprecision either.
I love this game, and the physisc engine looks very nice, last time you post about your game I bring  the link to my job and we all play your game for one hour instead of unreal ! this was pretty fun

as you told about static geometric/mesh collision I would like to point something out (just in case nobody think of this yet) :

computing sphere collision to static mesh is exacly the same as computing sphere collision to moving/rotating mesh it
 just requiere to change the frame of reference for the moving sphere
 this barbare word just means to works in the object local axis, this way the moving/rotating object/mesh appear static to the moving sphere
 and enable things like elevators / solid moving doors /etc...  with no cost and without any collision engine modification.
 
 how ? not really difficult but hard to explain...
  - keep somewhere the position of the sphere in mesh local axis coordinate system (pos A)
  - once object has been moved compute the new pos of the sphere in the mesh local axis coordinate system (pos B => maybe inside the mesh)
  - substract those two pos, you then get a displacement vector from pos A to pos B in the mesh local axis system
  - convert it back to world (using the current/moved mesh axis ) move your sphere from AWorld to BWorld
the mesh dont move any more from the point of view of the sphere its displacment has been reported/added to the sphere displacment and it appear as a static object
 
 here is an online applet demo => click on the image at the top of the website, (there is an invisible glasses/plane on the top of the table so the ball cannot fall) as you can see both sphere and mesh are moving and colisions/phsics works using the above technic. you can zoom with right button and rotate with the left one.

 EDIT : typos, also sorry but the top glasses make the demo not really well explaning I will try to put a sample online with a different 3d model to better show the result

Offline jezek2
« Reply #12 - Posted 2010-02-24 01:12:00 »

Does JBullet optimize large terrain objects at all? Meaning: if I feed the collisionworld a large mesh made up of numerous triangles (let's use an ugly example of the entire interior of a building all as one mesh), will JBullet be testing whatever dynamic object I put inside against every single triangle for the mesh every update? Or does it break it down using something like an octree?

Not that I would do that mind you! I'm just trying to get an idea of how JBullet handles things.

BvhTriangleMeshShape uses BVH (Bounding Volume Hierarchy) for culling. BvhTriangleMeshShape is for static geometry only, but there is also GImpactMeshShape for any type of geometry (also uses BVH). Not sure if that distinction matter in non-physics usage, but GImpactMeshShape has ability for trimesh to trimesh collision detection. Though it's best to use convex shapes for dynamic objects (or compound of them), as they have full volume so there is a lot less chance for tunelling effect.

The BVH must be build before use, it might take some time for big meshes. There is support for serialization in original Bullet, I think it's not ported in JBullet, I can port it if you need it.

Offline Momoko_Fan

Junior Member


Medals: 2



« Reply #13 - Posted 2010-02-24 01:19:25 »

Quote
BTW, is jME3 available anywhere? I can only find info for downloading jME2 (which I tried a year or so ago).
jME3 is still in active development and has not been officially released yet. You can get it from SVN in the jme3 branch:
http://code.google.com/p/jmonkeyengine/source/browse/#svn/branches/jme3
Offline DzzD
« Reply #14 - Posted 2010-02-24 01:31:13 »

EDIT: heu... sorry... this is following a post a little above (this thread has been going too fast for me...)

sometime code better explain.... below is the full physics code of the method moving the ball in the demo
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
public void moveBall(IScene3D s)
{
   s.setScene3DObjectToWorld();
   IMesh3D table=s.getMesh3DByName("TABLE");
   IMesh3D ball=s.getMesh3DByName("BALL");
   if(table==null || ball==null)
      return;
     
   gravity.set(0,-0.4,0);  
   force.add(gravity);
   
   ballPosTable.toAxis(table.getAxis3D());
   solid.getSource().copy(ballPosTable);
   solid.getDestination().copy(ball.getPosition());
   solid.getDestination().add(force);
   solid.moveSlide(4);
   
   ball.getPosition().copy(solid.getSource());
   
   force.add(ball.getPosition());
   force.sub(oldBallPos);
   force.mul(0.475);
   
   oldBallPos.copy(ball.getPosition());
   
   ballPosTable.copy(ball.getPosition());
   ballPosTable.toLocalAxis(table.getAxis3D());
   
   s.setScene3DObjectToWorld();
}

Offline Momoko_Fan

Junior Member


Medals: 2



« Reply #15 - Posted 2010-02-24 04:37:43 »

DzzD: The code is kinda useless without the moveSlide method. Can you post it as well?
Offline DzzD
« Reply #16 - Posted 2010-02-24 10:32:43 »

DzzD: The code is kinda useless without the moveSlide method. Can you post it as well?
It may be a bit long source code and related to the 3dzzd 3d data storage, but anyway this one is just a "standard" sphere to mesh collision , it just means to move a sphere from its source postion to its desitnation position (with a maximum of 4 bounds), the full source code is available in the shared source code section in the 3DzzDDevKit thread (in net.dzzd.core.colsion) but sorry it is a pretty messy source code.

for example for static collision to mesh I would do :
1  
2  
3  
4  
solid.setSource(startposition)
solid.setDestination(endPosition)
solid.moveSlide()
thenewposaftercolision=solid.getSource();


the above source code show then how to do the same when the mesh is moving/rotating by saving the solid sphere location in its local axis before moving the mesh and then using this saved local position the next game cycle to perform colision of moveing mesh on sphere

Offline tom
« Reply #17 - Posted 2010-02-24 12:14:40 »

Does JBullet optimize large terrain objects at all?
I've tested it using the KinematicCharacterController against a mesh with 850 000 triangles. Takes around 40 seconds to load. Can walk around without problems for the most part. Slows down where there are concentrated areas of triangles.

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.

Riven (7 views)
2014-07-29 12:53:52

Dwinin (7 views)
2014-07-29 10:59:34

E.R. Fleming (23 views)
2014-07-29 03:07:13

E.R. Fleming (9 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (51 views)
2014-07-17 23:47:54
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!