Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

There is a thing I don't understand about game engines: why it is so common to use physics engines to do raycasting or collision testing?

Say that you have a 3D scene loaded in your scene manager (Ogre or whatever) and you have to do some raycasting. Is it really efficient to load all your objects in the physical or collision world just to test them for intersection? Why do game engines don't implement the same structures so you don't need to load a physics engine? This sounds like a waste of resources, especially if you don't need physics.

share|improve this question
    
well in my case, I'm trying to do collisions only with bullet and ogre3d, and it's not that easy to make those two work together. –  jokoon Feb 9 '12 at 12:23

3 Answers 3

up vote 5 down vote accepted

Is it really efficient to load all your objects in the physical or collision world just to test them for intersection?

Yes it is efficient... for the programmer. There are lots of physics engines around and it's far easier to just use one - than to strip one down, or implement raycasting yourself.

Talking about code (in fairly rough terms):

You've got the code to create physics objects (you're not going to coldet/raycast against fully triangulated models, are you?) in a data structure that is efficient for doing coldet/raycast (you're not going to bruteforce it, are you?). And then some wasted code for various physical properties (and depending on the physics engine you can probably avoid much of this). Plus the CPU and memory requirements for the same (relatively small).

Then you've got the raycasting code. You need that in any case.

And finally the rest of the physics simulation code - which just sits in its binaries, never executed, never loaded to cache. Code doesn't take up much space anyway.

So the "wastage" here is utterly minuscule. Especially compared to the massive effort involved in replacing or stripping down half a physics engine.

share|improve this answer
    
You still need some of the code for physical properties ("this is one-sided", "this causes a sound when collided with") regardless of whether you use a "not physics engine" or a physics engine, unless your game is really boring. As for the physics simulation code, you will need some of that in order to perform stably when resolving collisions, unless the only thing that happens on collision in your game is death. –  user744 Sep 15 '10 at 15:11
3  
We used the GPU on the (first) PlayStation to do our raycasts. Render the scene real quick from the "shooter", each entity a different color. Whatever color the center pixel is tells you the thing you hit... :) –  dash-tom-bang Sep 15 '10 at 18:48

(Rigid-body) Physics is collision testing, raycasting, and response. There's no magic pixie dust that changes that combination into "physics engine" - if you need collision testing and raycasting, you need some kind of physics engine, whether you use an existing one or roll your own.

share|improve this answer
    
That doesn't answer my question. Raycasting is a geometric technique, why it is implemented in Bullet, but not in Ogre? Why should I load Bullet to do raycasting on an Ogre scene? I guess this has to do with how the scene is represented in Bullet, so why this representation is not implemented directly in Ogre? –  tunnuz Sep 15 '10 at 11:54
    
I mean, the representation could be a BSP, which is also useful in Ogre for back-to-front polygon sorting in order to do polygon-precise transparencies. –  tunnuz Sep 15 '10 at 11:55
4  
All you are asking is "Why doesn't OGRE include a physics engine?" or maybe "Why doesn't OGRE include a bad physics engine?" The answer is because plenty of physics engines already exist. –  user744 Sep 15 '10 at 12:21
    
This is a bold statement, and not true. If you need raycasting and collision testing you need a collision detection engine. If you want the to simulate rigid bodies that respond to collisions you need a physics engine. The only reason people use physics engines for collision testing is that (a)you can have it resolve collisions for you to prevent penetrations and (b) since collision detection is such a huge and important part of any physics simulation the implementation is likely more optimal than something you could whip up yourself. –  Kaj Sep 15 '10 at 20:25
1  
@Kaj: Like I said unless you are making a game where the only response to collision is deletion, here's where the asker's thought process invariably takes you: "I don't need physics, just collisions and raycasts!" -> "But my objects move, so I need something aware of all the objects' motions each frame or I'll get tunnelling" -> "Oh crap I have penetration, now I need the collision code to move objects" -> "Now it's not stable, I need it to manage forces and inertia, not just flat-out move stuff" -> This is a rigid-body physics engine. –  user744 Sep 16 '10 at 9:26

Raycasting and collision detection is a smaller subset of a physics engine. Therefore most people use physics engines for this task and they generally have a good implementation of these functions.

You can use the the collisions detection and raycasting features of a physics engine without using the Rigid Body dynamics part. For example Bullet has a btCollisionWorld class that just does the basic collision and raycasting. btDynamicsWorld is built on top of that.

ODE (another popular but older physics engine) uses OPCODE (downloadable as a separate library) for its collision and raycasting.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.