Freezing a scene

PhilB
Posts: 11
Joined: Thu Aug 28, 2008 3:01 pm

Freezing a scene

Post by PhilB »

Hello all,
I would like to create a program in which the user first sets a 3D scene with the objects being "frozen" (i.e. no forces, not even gravity, are applied to them). Then when the user is done, he can click on a button to start animating the scene by applying all the forces. Thus there are two parts: first a scene's set-up and then the animated scene. The user may also want to freeze the animation and return to the set-up mode to modify the scene. Well you've got the idea I guess.
My question is: what is the best way to switch between the two parts ?
BTW, I am using JBullet (the Java port of Bullet based on Bullet 2.70-beta1), but an explanation using Bullet is OK.
TIA,
PhilB
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: Freezing a scene

Post by ola »

Hi PhilB,

just don't call stepSimulation when you want to freeze the simulation, and you should be all set. I've made a similar editor and that works well. When I move an object (rigid body), i remove it from the physics world first and add it back in with it's new position.

Best regards,
Ola
PhilB
Posts: 11
Joined: Thu Aug 28, 2008 3:01 pm

Re: Freezing a scene

Post by PhilB »

Thanks! sounds an excellent solution.
Phil
PhilB
Posts: 11
Joined: Thu Aug 28, 2008 3:01 pm

Re: Freezing a scene

Post by PhilB »

Hi Ola,
Your solution is easy to implement, but when the scene is frozen, the objects cannot be moved...
In this case, the user has no feed back regarding where the object will be when releasing the mouse button ?
Phil
ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Re: Freezing a scene

Post by ola »

Well, it depends how you decide to move it.

In my application there are 3d mesh models that you actually see (cars, obstacles, props, etc). Their positions are updated from the rigid body motion state when the simulation is running. When freezing the scene and moving the objects, only the 3d mesh is dragged/moved with the mouse. I only update the new rigid body position when the mouse is released. So it is more like a "teleport" in bullet, but the user doesn't notice.

I also use convex sweep tests at every mouse move event, to check if the new position causes a collision.

If you are using the physics drawer to draw the actual collision shapes, then maybe you can try to remove/update position/add the rigid body position for each mouse move event when dragging instead of only when releasing the button?

best regards,
Ola
radubolovan
Posts: 7
Joined: Mon Dec 22, 2008 3:13 pm

Re: Freezing a scene

Post by radubolovan »

It is possible to freeze/unfreeze only one object?
I can set mass to 0 to freeze it then when I want to unfreeze it put the mass back ... but I don't like the ideea verry much!
Is there any other way to do this?

Thank you!
Tristan
Posts: 5
Joined: Fri Jan 02, 2009 1:56 pm

Re: Freezing a scene

Post by Tristan »

Hi, just dealing with a similar problem of toggling the physics of individual objects within a scene.

You can do the following...

Code: Select all

//off
pbody->setCollisionFlags(pbody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
//on
pbody->setCollisionFlags(pbody->getCollisionFlags() & (~btCollisionObject::CF_STATIC_OBJECT));
Setting the mass does the same.
Tristan
Posts: 5
Joined: Fri Jan 02, 2009 1:56 pm

Re: Freezing a scene

Post by Tristan »

Apologies, I take that back.

Just by setting those flags I've found that the collision detection goes a bit strange.
Setting the mass works.