Trigger Volumes, Ray Casting, Networking and Streaming

aqnuep
Posts: 4
Joined: Sun Jan 09, 2011 4:31 pm

Trigger Volumes, Ray Casting, Networking and Streaming

Post by aqnuep »

Hi,

I know the basics of how to use Bullet for collision detection and rigid body dynamics but I have some questions about some more specific features, whether and how they are supported by Bullet, so you can think of me a noob to Bullet.

Trigger Volumes
Just to clarify what I mean by trigger volumes: collision shapes (optionally attached to rigid bodies) that can be used to drive different game logic, e.g. one is able to detect when objects (rigid bodies) overlap (collide to) a particular trigger volume. Such a trigger volume does detect collisions with other primitives but does not generate contact points or contact joints thus are more efficient than usual collision primitives but makes it able to detect if an object enters/exits a trigger volume.
Is there such functionality in Bullet and if yes, then how they work?

Ray Casting
Does Bullet support custom raycasts that can be used for various game logic/AI? E.g. detecting whether one object can "see" another, that means no object is between the two that "hides" one from another using ray casting.

Networking
How does Bullet support networking? I know that Bullet uses fixed sized time steps internally and only interpolate the transforms to mimic custom frame rates. My question is whether this is enough to assume that if Bullet gets the same inputs on one computer like on another then I can take it for sure that it will get the same output on both computers, or in a networked environment do I have to dedicate physics calculations to the server and send transformation data down to clients instead?

Streaming
Have anybody tried to stream objects on-the-fly to Bullet? Does it work stable?

Thanks in advance for your answers!
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Trigger Volumes, Ray Casting, Networking and Streaming

Post by lulzfish »

Trigger Volumes
There is a way to do this, but currently my implementation is messed up. >:( There are GhostObjects and PairCachingGhostObjects which are supposed to be dedicated for this, but I just iterate over all collision pairs and if one of the objects is a trigger, it gets activated.

Ray Casting
Yes, there is a btCollisionWorld::rayTest or something like that, I have successfully used it to pick objects with the mouse. For some reason it requires you to also setup a RayResultCallback with the ray's start and end points, so you enter those twice. (Why?) I think I actually use RayClosestResultCallback or something.

Of course, that is an infinitely thin ray. If you want to know if anything at all could be between two objects, or if one is completely occluded from the other, you might need something like bounding spheres and a sphere sweep. I think Bullet supports this, but I haven't looked into it since I'm also a noob.

Networking
I don't think Bullet supports networking at all, you'll have to do it yourself. The usual method is to run the physics completely on the server, since you can't trust the client at all (It might be hacked) You can run some interpolation / extrapolation on the client, so that if the server only sends updates 50 times a second, you can still have smooth motion at 100 or 200 FPS. You might also think about lag compensation. On any kind of general Internet connection, it would be impossible to do a straight-up physics simulation for something like a shooter, because the player would have to lead their shots by a random amount that varies with network quality.

You can read some of Valve's publications on all that, but in short, they have the server keep track of the last 500 milliseconds or so of physics state, and when a client reports a shot, it also reports the time (or the server figures it out, not sure which) and the server rewinds the physics state to determine whether the shot would have hit if it was fired at the time the client sent the command.

Oh, almost forgot, you asked if running the same simulation on multiple computers would give the same results. It should in most cases, but you don't want to count on it, especially not in a multiplayer game where one client might be hacked.
The phenomenon is called "determinism" and there's a wiki page on it: http://bulletphysics.org/mediawiki-1.5. ... eterminism

By default, I don't think Bullet does anything randomly, so it should be deterministic, at least within the same floating-point precision, same stepping rate, and same library version. Someone more experienced can tell you more about this.

If you were planning to run one simulation on each computer and have them synchronize somehow, that probably will not work. Because of lag, any kind of user input will end up arriving at different times, and the simulations will immediately have vastly different results. Again, look up Valve's publications on Source Engine networking. Basically, you want the server to do as much as possible, and the client can do a little interpolation to make it better. The server must decide all the physics and scores and shots based on the simplest information from the client ("I shot at this angle") to avoid any kind of hacking. ("I shot at this angle, but I was standing 50 feet away from where I am") ("I hit this guy, even though he was on the other side of the map, trust me")

Streaming
I'm not sure what you mean by streaming. Like loading the static world objects from disk? Like streaming physics over the network to many clients? Like having a permanent physics world that automatically loads new areas as the player approaches, and saves old areas to disk as the player leaves them?

Any of those techniques should be possible, but Bullet only provides collision detection, physics response, and serialization. You'll have to specify what to "stream" and how to stream it, whatever you mean.
aqnuep
Posts: 4
Joined: Sun Jan 09, 2011 4:31 pm

Re: Trigger Volumes, Ray Casting, Networking and Streaming

Post by aqnuep »

Trigger Volumes
That GhostObject thing sounds kind of what I'm looking for. Can you tell more about it?

Ray Casting
Thanks, that's exactly what I'm looking for. Obviously for non-infinite thin rays simple ray casts are not enough, but anyway, that's what I expected.

Networking
I know that I have to do all the network stuff myself, however, don't have too much experience with that so far.
Actually I was thinking about determinism, I'll check the wiki page you've linked.
About the hacked client, yes, I'm aware of that issue and I know that a completely safe way is to do the physics on a dedicated server. Anyway, it would still come handy if I can assume that the same simulation with same precision and library version would be deterministic then there would be way to synchronize actions on all clients thus avoiding sending too much data over the network. Of course, some synchronization would be still needed.
Also thanks for advising to take a look at Valve's publications. I'll check them out as well.

Streaming
Sorry if I wasn't precise enough. I was thinking about streaming physics data based on the player movement so that huge worlds can be used even if the whole doesn't fit into memory at once. Here I'm pretty sure that everything depends on how I do things, I was just interested in any experience you have with doing so.

Anyway, thanks a lot for your answer and any further information would be welcome about the topic.
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Trigger Volumes, Ray Casting, Networking and Streaming

Post by lulzfish »

aqnuep wrote:Trigger Volumes
That GhostObject thing sounds kind of what I'm looking for. Can you tell more about it?
Yeah, I forgot there's a wiki page for that, too: http://bulletphysics.org/mediawiki-1.5. ... d_Triggers
Of course, I used that code for my ghost object and then it didn't work, and then I got the same quality without a ghost object.

The 3rd post on my thread asking about ghost objects has example code from Flix: http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=6195
I haven't looked through it yet, maybe it fixes my issue (Which was with mobile ghost objects seeming to cache their collisions inappropriately)
Toadcop
Posts: 11
Joined: Mon Feb 22, 2010 10:13 pm

Re: Trigger Volumes, Ray Casting, Networking and Streaming

Post by Toadcop »

Actually I was thinking about determinism, I'll check the wiki page you've linked.
if you have setuped the same floating point precision for your application (clients), and create the same world with same objects and with same velocities/forces, bullet will produce the same results. i have tested it on network and the other "player" have tunneled through trimesh =) on all clients at the "same time" and other cases were also reproduced equal among all "players". so kind a bullet is determenistic, if you know how to setup required environment. (there are some randomiser in solver which can mess up, but by default it's disabled.)