Collision Detection Libraries

Hello,

Does any one know of any collision detection libraries written in java? I would like to be able to perform OOB, AABB and ray intersections, at the moment I’m not too interested in going down to the individual triangle level in a model.

I would like to be able to do this independently of a rendering engine (I know that Java3D has some of these abilities) I would also not want to rely on native code ala odejava.

I’ve had a look around and there seem to be few of different libraries in C++ (opcode, RAPID, I-Collide etc.) I just wondered if anyone had written (or ported) a similar library in java.

I would attempt to have a go myself, but knowing nothing about the intricasies of collision detection and also feeling that someone must have faced this problem before I thought I’d ask here.

Cheers,
Dan.

Odejava uses ODE which uses OPCODE. It’s not “ported” to Java, we just use a wrapper to the native library (which means less work keeping the ported version current).

To use it - use the Space and Geom objects and ignore World and Body (the latter being for physics simulation).

Xith3D also has a collision API but I have not used it and apparently it is currently broken.

Will.

Hey, this looks pretty good, might port it to Java?

http://photoneffect.com/coldet/

EDIT: Looking through the C++ the code actually looks really tidy too :slight_smile:

Kev

it does look good - although it’s LGPL which isn’t the best license for use in Java programs.

Will.

Futher investigation shows it could do we a bit of refactoring. However, how would LGPL impact us?

Kev

Have a look at http://www.cs.ubc.ca/spider/lloyd/java/vclip.html.

Its a Java implementation of Mirtich’s V-Clip algorithm that you’ve probably seen the C++ version of. Not sure how well it works though.

If you wanted to get into writing your own java collision detection routines then I have heard good things about “Collision Detection in Interactive 3D Environments” which is by the guy who wrote SOLID.

Paul

Thank you all for your replies. I’ve been with out access to the forums since I posted the question so havn’t had time to reply yet.

wrt odejava using it to just do collision was one of my first ideas. Unfortunatly (and I could weel be wrong here) I got the impression that it was would work well to do a give me a list of everything that collides now (what you want for the physics aspect). But trying to do a one off query like “what does this interesct with” ie picking or line of sight would not be so easy. Is this assumption correct? I aslo had a problem with it crashing when I tried to remove an object from a space but I think that may have been sorted now. Does odejava/ode’s implementation of opcode automatically partition the space into a AABB? or should you decide the partition with spaces yourself? if it does partition how does it deal with movign objects?

wrt to coldet I have come across this before in my searching but from other forums (flipcode I think) I got eh impression that it wasn’t so good, plus I’m not sure that it has been updated in a few years. Having said that updates to opcode are going to be diffucult now as Pierre Terdiman now works for novadex.

wrt v-clip I’ve hread of it but didn’t realise that someone had implemented it in java, I’ll go and take a closer look. As for the book it’s a shame ordering off amazon is so easy now… I’m going to be in trouble when it arrives :wink:

Any one have any more thoughts? thanks again,
Dan.

i always like the source code on david elberlys site: www.magic-software.com, go to Source Code -> Intersection, he has some good stuff…

Btw, i am in the process of writing a rigid body physics engine in java using jogl for rendering and I have implemented collision detection and intersection tests with spheres, boxes, and triangle arrays.

P.S.: the magic-software source code is well structured but as a java programmer i found his naming conventions kind of annoying, he uses a lot of prefixes and suffixes, but once u understand them its easy to read.

Thanks,

I have actually seen his site and your right it’s got alot of good info in it.

At the moment I’m reading the book suggested above but my maths is a little rusty :wink: So it’s fun, but very challenging. Wether it will ever translatin into a Collision lib I doubt (even just a personal one) but I’ll see how I go, it would be a nice challange but most probably too demanding.

How’s your physics engine comming along? it sounds tempting :wink: Is it bespoke or based on somthing like ode? IMHO a pure java physics engine would be very good to see.*

Cheers again,

Dan.

  • I’m not disparaging odejava or all the good work that has been done on it, I think it’s a very valubale project :slight_smile:

well, right now im still working on tri-tri collision detection… but its not really necessary for some initial demos.

basically right now its just a very nice framework with collision detection and response implemented. what i think is really cool about it is that its very modular and very extendable. like i have an interface SceneGraph that anyone can implement to do any kind of optimizations for culling or collision detection that they want. and all the UI stuff will still work really simply. the intersection/collision tests are not part of the scenegraph but part of the Geometry library and can be called completely separately.

so i still have a ways to go for a full featured physics engine. i need to do friction and resting contact next. and then, if i ever get to it, joints. the end goal is a car physics, which i find really cool.

btw, im sorry, but i really hate the idea of using that java binding for ode. why not license the unreal engine and do a java binding for that?

anyway, what do u think would be a good name for my engine. i recently thought of Absorb, which loosely stands for A Beautiful Simulation of Rigid Bodies, and also just sounds decent. but for now its unamed, and the package is called simply “engine”

Im gonna try to work hard in the near future to get a nice demo of the engine (maybe a couple)… thats really my goal. my dream, really the reason i started looking into building an engine, is car physics.

i probably will stop tri-tri collisions and just do some stuff with boxes and spheres, get some friction and contact going. after that get collision done. then maybe improve my integration techniques. then maybe some particle stuff. somewhere along the way ill get to adding some lighting to the scene graph. then other effects like fog, multi-texturing, shaders, bump-mapping…

Care to explain why? Perhaps the next time I’ve got a spare US$350,000, an unreal binding would be fun, but until then I think I’ll stick with free as in beer engines.

Sounds like you are re-inventing the wheel creating yet another physics engine/scenegraph combination. I guess you must be doing it for the coding experience or is there some deficiency in what is currently available?

Will.

[quote]Futher investigation shows it could do we a bit of refactoring. However, how would LGPL impact us?

Kev
[/quote]
Well there’s a lot of confusion with how the LGPL applies to Java. There’s been some talk in these forums on this and a slashdot story at one stage. *GPL was designed from a narrow minded C-centric point of view which may cause problems. A google search provides more detail, there is one java weblog on the topic

Based on this confusion, I try and avoid using LGPL code as integral parts of my projects. Peripheral things like sound is ok, but I would hesitate basing a whole engine on it. ODE fortunately is licensed under a BSD-like license. Apparently (according to the update on the slashdot story) it is ok to use the LGPL with java but whatever way you look at it, there is an added risk in doing so.

Will.

i am sorry, i was a bit harsh, and you are probably right. i am doing this entirely because i love physics and java. i guess if the goal is to focus on developing a real game, then using a binding of ode is cool.

but, if there was a physics engine written entirely in java that had support for the same features as ode, would you use it over ode?

anyway, what are most of the people in here actually doing with like lwjgl or xith3d or j3d? are they writing games? if they are trying to actually create a full game, then i guess by using another library they are saving themselves a lot of time.

ive looked at ode a couple of times, its pretty cool. does it support any liquid dynamics?

also, i was wondering, by using a separate library for physics stuff, dont u have to store all of your geometry information twice? does that affect performance at all? or can you do something cool with pointers to get around that?

–eric

[quote]i am sorry, i was a bit harsh, and you are probably right. i am doing this entirely because i love physics and java. i guess if the goal is to focus on developing a real game, then using a binding of ode is cool.

but, if there was a physics engine written entirely in java that had support for the same features as ode, would you use it over ode?
[/quote]
Yes I would use it.

There has been talk of porting ODE to Java, however it is a large upfront effort and requires an ongoing commitment to ensure the port doesn’t get out of date. This commitment is quite large and would take up a lot of time which otherwise could be spent making a game.

For me now, any engine would have to be fairly ODE compatible as I have invested a lot of time defining an XML file format (XODE) and creating my game objects using that.

most people are I think

not that I know of

There is some info that is stored twice, but not a lot. For example my display (Xith3D) engine has a several thousand polygon tank mesh to represent the tank while my physics engine (Odejava) has three rectangular boxes to approximate the tank (hull, turret and gun). While I could use a TriMesh and have exact collision, there is little need - three boxes gives me a very good approximation as it is. For the terrain however, yes the information is stored twice plain and simple.

Will.

i dont really read these forums much, but u sound like a pretty serious contributor. your tank project seems pretty cool, do u have any screenshots?