Moving physics objects manually

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
coms0108
Posts: 2
Joined: Sun Feb 24, 2008 1:27 am

Moving physics objects manually

Post by coms0108 »

Hi,

I'm just doing my first experiments with the BEPU library with a view to using it in an fps. So far it's all going quite well - looks like a great piece of software - congratulations and many thanks for making it available.

The issue I have is this: I need to move physics objects in code from time to time, then let the physics engine resume control. At the time I grab it, an object may be moving. After movement I usually want it to be stationary - and usually begin to fall under gravity. I developed the instructions to do this as follows.

Step 1: Use the moveTo method. This moves the object, but doesn't change its orientation or linear or angular velocity - so it retains orientation and its motion resumes when it is released.

Step 2: I discovered that setting linear or angular velocity had no effect. Following the demo I set linear and angular momentum to zero instead. That worked - the object is now stationary when released and physics takes over properly.

Step 3: To restore orientation to the object's default, I also set the rotationMatrix to be the Identity. Everthing now looks good.

In summary - to change position on a physics object I do:

kapow.moveTo(new Vector3(0, 8, 3));
kapow.rotationMatrix = Matrix.Identity;
kapow.angularMomentum = Vector3.Zero;
kapow.linearMomentum = Vector3.Zero;

(Note - I tested this on the demo with kapow changed to be a rectangular solid so I could see its rotation)

This is all fine except I get the following odd behaviour:

On release, the object is in the right place, not turning or moving, and physics resumes. However, when the object next collides with something it suddenly jumps in orientation - I think to the orientation that it had just before I moved it. I'm not sure if anything happens to its angular or linear momentum at that point. It is as though the collision system had somehow cached the object's orientation. It makes me think that I am not setting everything that I should when moving the object - or that I am doing the settings in the wrong way.

Any help would be appreciated.

Regards
Bill
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Moving physics objects manually

Post by Norbo »

Thanks for trying it out :D

The rotation matrix field of entities is actually a derived value based on the rotation quaternion; changing it will adjust a display relying on the rotation matrix for information but leave the actual simulation largely unaffected.

Instead, you can change the orientation of the object by setting its quaternion by calling (Entity).applyQuaternion(Quaternion.Identity). This will update all the necessary data and set its orientation to the default of the object.

Right now all of this isn't terribly clear (a lack of documentation on some public fields, amongst other things), so I'll see what I can do to make it more intuitive for future versions.
coms0108
Posts: 2
Joined: Sun Feb 24, 2008 1:27 am

Re: Moving physics objects manually

Post by coms0108 »

Hi Norbo,

Excellent - worked perfectly.

Many thanks
Bill
Post Reply