Static Objects

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Piers
Posts: 8
Joined: Tue Sep 16, 2008 9:53 pm

Static Objects

Post by Piers »

Is there a way, to reposition a static object? If I made a static triangle group out of a city building, is it possible to move the object, and the physics calculations to a different spot?

If so, any examples or code you could give me?


Thanks,


-Piers
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Objects

Post by Norbo »

A StaticTriangleGroup's world matrix can be changed to rotate, scale, and translate the mesh.

For example, to move the mesh down 10 meters, you could use this code:

Code: Select all

group.worldMatrix *= Matrix.CreateTranslation(0, -10, 0);
In the demos, there is a line in the Playground simulation that rotates the mesh 180 degrees and then moves it down as well:

Code: Select all

group.worldMatrix = Matrix.CreateFromYawPitchRoll((float)Math.PI, 0, 0) * Matrix.CreateTranslation(0, -10, 0);
Piers
Posts: 8
Joined: Tue Sep 16, 2008 9:53 pm

Re: Static Objects

Post by Piers »

Hmm... any idea why it wouldn't work in the update, and/or draw function?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Objects

Post by Norbo »

Not that I can think of; is it possible that the collision mesh is moving but not the associated graphics?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Objects

Post by Norbo »

Just thought of one reason. If it's being called every frame, the worldMatrix change will clear out the currently active objects. If they aren't remade in time, no collision occurs. I'm currently trying to find a way to allow continued modifications.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Objects

Post by Norbo »

The solution is to call group.updateAtEndOfUpdate(space.simulationSettings.timeStep, space.simulationSettings.timeScale, 0); manually after adjusting the group's world matrix. Doing so forces the recreation of any missing triangles. This isn't an ideal way for it to work, and I would like to make it quicker and more obvious in the next version.
Piers
Posts: 8
Joined: Tue Sep 16, 2008 9:53 pm

Re: Static Objects

Post by Piers »

Thank you very much. : ) I'll be sure to try that as soon as I get my source back.


Edit:

Actually, I now have a sort of new problem. It appears that my object, no matter the radius I put the sphere at, never touches the ground. It physically moves across the ground, but it is always above it.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Objects

Post by Norbo »

If the sphere is successfully generating contacts, then what you are observing is the margin of the sphere. If your graphics are designed to show the sphere with the sphere's radius rather than the sphere's radius added to the margin, there will be a gap.

In the demos, I deal with this by expanding all graphical representations by the margin (minus the allowed penetration). Subtracting the allowed penetration can leave gaps, though objects won't be graphically penetrating while at rest. If you'd rather not have any visible gap in favor of a little penetration, then just expanding simply by the margin would be fine. Modifying the radius of the sphere until it matches the preexisting graphics would work too.

Now if is actually bobbing along as if it were under antigravitational effects or something, then I'm not quite sure.
Piers
Posts: 8
Joined: Tue Sep 16, 2008 9:53 pm

Re: Static Objects

Post by Piers »

Right... another problem. I made a character, who has a cylinder to affect it's gravity/collisions. Main problem is, the moveTo command seems to be stopping this object from interacting with any other object. I can run around on my terrain.. but running into a sphere just makes me move over it.

Help please?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Objects

Post by Norbo »

moveTo teleports the entity, so you will phase through any objects you do not manually detect collisions against (though any moveable entity will try get away from you, provided that your cylinder is handled by the space). In the demos' character controller, this is resolved by using a dynamic rigid body which detects collisions with the environment and moves due to velocities rather than teleportation. Another common method is to use swept collision tests to see how far an entity can move, or to detect penetration with discrete tests and resolve it after the fact.

Personally, I find working on the impulse/velocity level more intuitive, hence the usage of a physically simulated rigid body.
Piers
Posts: 8
Joined: Tue Sep 16, 2008 9:53 pm

Re: Static Objects

Post by Piers »

How would I go about velocities and shit in Bepu? If moveTo teleports, then what actually moves the object?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Static Objects

Post by Norbo »

You can change momentums and velocities using the linearMomentum/angularMomentum/linearVelocity/angularVelocity fields. There's also applyImpulse. You can see in the demos' character controller how I handle a character's movement using velocities.

Here's a simple way to convert a position based system to a velocity based system. If you have a goal displacement vector (current position to goal position), you can divide it by the timestep to get the velocity (in units per second) that the entity would need to move that direction. Setting the entity's velocity to that value would cause it to move in the same way, but it would be changed by collisions and therefore wouldn't phase through stuff.

In the demos, I don't use goal positions or anything like that though. I simply create a movement direction based on the keyboard/mouse input and accelerate in that direction by changing the body's velocity and let the collision detection and response systems figure out the limitations.
J2T
Posts: 48
Joined: Sat Sep 20, 2008 6:20 pm
Contact:

Re: Static Objects

Post by J2T »

Hello,

i also had have the problems with a moveTo() under JigLibX. I need some hours to check that such methods aren't useable if u like a physical response!somehow also logically...

So i saw that u also have such a method in your character controller!It should be usefull when u make it private!So a person who is new to the topic(like i was then) is using first such methods cuz they don't know that its going on with forces, impuleses etc..

Just my 2 cents
Post Reply