# Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 13 posts ]
 Print view Previous topic | Next topic
Author Message
 Posted: Sat Oct 13, 2007 1:59 am

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
Hello everyone,

I am enjoying my work with Bullet. What a great library.

I have a problem/question. I have an environment made up of a triangle mesh using a kinematic body. The environment moves (think of a room on a ship). I have dynamic bodies inside the environment (think people in the room on the ship). When I move the room (specifically, I am rotating it - so the room slowly spins), I want the people (dynamic bodies) to move with the floor. Right now, it doesn't work for me. I mean, collision and bounce work fine, but seems like no friction is applied.

Here's what I have:

My room, a triangle mesh with kinematic body.
A cube, which is a dynamic rigid body.
The room is (very) slowly rotating around it's vertical axis (like a carousel).

When I throw the cube in the room, It bounces off the walls and comes to rest as expected. However, it does not move with the floor (until it is hit by one of the walls, which then proceeds to push it). I am updating the room position/rotation using MotionState (same code as used in the ccdphysicsdemo) and both the room and the cube have friction coefficient of 0.8.

*EDIT* Is what I'm trying to do even possible?
*EDIT2* I forgot to mention that I am setting the kinematic body position directly, not setting a velocity or angular velocity through the motionState (well, I'm calculating a velocity myself, and then calculating the resulting position from that)... should I be using some function like setLinearVelocity or setAngularVelocity instead? Hmmm... I guess since there are no answers yet (I'm assuming because it's the weekend) people just haven't seen my question yet... Hopefully, someone can provide some insight...?

Chaster

Top

 Posted: Mon Oct 15, 2007 5:03 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
*ping*... Anybody have any input on the proper way to handle this? (imparting friction from kinematic moving bodies to dynamic rigid bodies properly)? A hint perhaps? Or am I just trying to do something which isn't really possible?

Chaster

Top

 Posted: Mon Oct 15, 2007 5:23 pm

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3746
Location: California, USA
This should just work. Can you check out a working example in the CcdPhysicsDemo: enable at the top of CcdPhysicsDemo.cpp the define
Code:
#define USE_KINEMATIC_GROUND 1

The floor kinematically moves, and stack of cylinders moves with it due to friction.

Make sure you are setting these properties for the kinematic object:
Code:
if (mass == 0.f)
{
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body->setActivationState(DISABLE_DEACTIVATION);
}

Hope this helps,
Erwin

Top

 Posted: Mon Oct 15, 2007 5:24 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
Update:

Okay, more testing reveals that linear motion seems to impart friction (although not quite sure how accurate) but angular motion of the kinematic body imparts very little (if any) friction force to the rigid body sitting on the kinematic body.

Is this a bug?

Chaster

Top

 Posted: Mon Oct 15, 2007 5:26 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
Erwin Coumans wrote:
This should just work. Can you check out a working example in the CcdPhysicsDemo: enable at the top of CcdPhysicsDemo.cpp the define
Code:
#define USE_KINEMATIC_GROUND 1

The floor kinematically moves, and stack of cylinders moves with it due to friction.

Make sure you are setting these properties for the kinematic object:
Code:
if (mass == 0.f)
{
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body->setActivationState(DISABLE_DEACTIVATION);
}

Hope this helps,
Erwin

Oh, we must have posted at the same time. Yes, I based my code on the kinematic floor demo, and while linear motion seems to impart friction, angular (rotational) motion doesn't (at least, if it is, it is a lot less than friction imparted by linear motion of the kinematic body)... I notice that the kinematic floor only moves up and down, with no rotation - perhaps this is a bug which is not revealed because the demo does not test it?

Chaster

Top

 Posted: Mon Oct 15, 2007 5:31 pm

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3746
Location: California, USA
Chaster wrote:
Erwin Coumans wrote:
Oh, we must have posted at the same time. Yes, I based my code on the kinematic floor demo, and while linear motion seems to impart friction, angular (rotational) motion doesn't (at least, if it is, it is a lot less than friction imparted by linear motion of the kinematic body)... I notice that the kinematic floor only moves up and down, with no rotation - perhaps this is a bug which is not revealed because the demo does not test it?

Chaster

Rotational kinematic objects have been tested to work. You can download Blender 2.4x which uses Bullet physics, with the regression physics demos. Those tests includes a kinematic cube that is slowly rotating, with a stack of boxes following properly. The CcdPhysicsDemo ground is supposed to move sidewards, not up/down. Are you using the latest version of Bullet (2.63 of now) ?

Can you reproduce the issue in the CcdPhysicsDemo?
Thanks for the feedback,
Erwin

Top

 Posted: Mon Oct 15, 2007 5:43 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
Thanks for taking the time to reply Erwin. Really appreciate it.

I am currently compiling 2.63 to compare with what is going on in my simulation. I am glad that it should work - that narrows it down to something I am doing wrong (not surprising since I am new to Bullet). I will report back with whatever I figure out. In the meantime, let's just assume it's something stupid I am doing which is causing the problem.

Chaster

Top

 Posted: Mon Oct 15, 2007 5:46 pm

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3746
Location: California, USA
Chaster wrote:
Thanks for taking the time to reply Erwin. Really appreciate it.

I am currently compiling 2.63 to compare with what is going on in my simulation. I am glad that it should work - that narrows it down to something I am doing wrong (not surprising since I am new to Bullet). I will report back with whatever I figure out. In the meantime, let's just assume it's something stupid I am doing which is causing the problem.

Chaster

What are the collision shapes, resting on the ground? If they have more then one contact point, it should work fine. Sphere and capsules only have one contact point, so there might be no rotational friction imposed on them. It is possible to improve the friction model (both performance and this rotational friction) if necessary.

Thanks,
Erwin

Top

 Posted: Mon Oct 15, 2007 5:59 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
The collision shape for the dynamic body is a cube. Although cones exhibit the same behavior. I am looking at the CCDPhysics demo right now with USE_KINEMATIC_GROUND 1 defined, and I see that the stack of cylinders is moving horizontally with the ground, but I don't see a rotational element to the movement. I assume there is no rotational element? Assuming not, I will add a rotational velocity and see what happens..

Chaster

Top

 Posted: Mon Oct 15, 2007 6:07 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
Update:

I modified the CCDApp demo to rotate instead of move linearly, and it works as expected (although not perfect, it's pretty good). The problem in my app is either something in my code or perhaps the inaccuracy is prominent because of the scale of the objects maybe...

Thanks again Erwin,

Chaster

Top

 Posted: Mon Oct 15, 2007 11:17 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
Update:

After a LOT of testing/tweaking/exploring I think I found the problem. My stepSimulation call is being called with timeDelta = 1/frame rate, maxSubSteps = 1. The kinematic object had it's rotation being updated according to frameRate (which varies anywhere from 80fps to 200fps). When I updated the kinematic object rotation using a fixed value (say, 0.001 radians), the dynamic rigid body (a cube) seemed to follow along pretty well. Once I tied it to the frame rate, the rotational friction went bye-bye..

So, it looks like I need to figure out how to properly update my kinematic objects to match with the simulation stepping...

Chaster

Top

 Posted: Tue Oct 16, 2007 7:26 am

Joined: Sun Jan 14, 2007 7:56 pm
Posts: 169
Location: Norway
Quote:
So, it looks like I need to figure out how to properly update my kinematic objects to match with the simulation stepping...

Hi, I've done this in the game I'm working on, by creating my own derived dynamics world class, something like this:
Code:
class MyBulletDynamicsWorld : public btDiscreteDynamicsWorld
{
protected:

virtual void   internalSingleStepSimulation( btScalar timeStep);

public:

MyBulletDynamicsWorld(  btDispatcher* dispatcher,
btConstraintSolver* constraintSolver);

virtual ~MyBulletDynamicsWorld();
};

and then you can re-implement internalSingleStepSimulation like this:

Code:
MyBulletDynamicsWorld::MyBulletDynamicsWorld(btDispatcher* dispatcher,
btConstraintSolver* constraintSolver)
:btDiscreteDynamicsWorld(dispatcher, pairCache, constraintSolver)
{
}

MyBulletDynamicsWorld::~MyBulletDynamicsWorld()
{
}

void MyBulletDynamicsWorld::internalSingleStepSimulation( btScalar timeStep)
{
btDiscreteDynamicsWorld::internalSingleStepSimulation(timeStep);

// then do your per-step code here, the timestep is the proper 1/60 one

}

Works very well for me

Cheers,
Ola

Top

 Posted: Tue Oct 16, 2007 1:19 pm

Joined: Mon Oct 01, 2007 7:24 pm
Posts: 19
Hi Ola,

Thanks! That's a very smart (obvious) thing to do. Of course, last night I found out that my REAL problems were:

1) OgreBullet (interface library I am using which sits between Ogre3D and Bullet) was using SimpleDynamicsWorld for simulation (Doh!). Fixed.
2) I was passing in milliseconds instead of seconds for timestep (doh!!). Fixed.

Now it works properly. However, your suggestion to derive my own dynamics world class is a good one. I'll see about doing that too.

Many thanks!

Chaster

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 13 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: Bing [Bot] and 5 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities