JV-ODE: Break my tables!

Blitz3D Forums/Blitz3D Userlibs/JV-ODE: Break my tables!

Danny(Posted 2006) [#1]
Hi All,

Just beginning with ODE and here a experiment with breakable tables (yes, based on code you guys did before, so nothing new). I'm curious to know if you guys know any other ways to 'get bodies to relax' and auto disable themselves.

In the demo you can see when you've got lots of objects stacked on top of each other they keep bouncing around amongst each other. Lowering angular&linear thresholds can only go so far untill bodies come to rest in an unrealistic pose...

cheers,
Danny
p.s. How do you post a small box with code in it? unlike this big chunk:



VIP3R(Posted 2006) [#2]
Try lowering the dWorldQuickStep() step size to '0.05' or less to help the objects 'relax' a bit more.

I've posted some more tips in the JV-ODE thread for you.

Code Box Tags:
[ codebox ] & [ /codebox ] without the spaces

;)


Wayne(Posted 2006) [#3]
More Table bashing!!
Used new ode functions:
dJointFeedbackEnable(joint)
dJointFeedbackDisable(joint) ; didn't try this one
dJointFeedbackIsEnabled(joint)
dJointSetFeedback(joint,feedback); didn't try this one
dJointGetFeedbackForce1(joint)
dJointGetFeedbackTorque1(joint)
dJointGetFeedbackForce2(joint)
dJointGetFeedbackTorque2(joint)

Set thresholds at world level to reduce code size.
Rebuilt jointlimit function.
Added the patented wayner fps physics timing.
Adjusted parameters, added mass, and improved stability.

Thanks for posting and allowing me to tinker.






Danny(Posted 2006) [#4]
Good stuff Wayne! :D

I just found out that there's a 'fixed joint'. For the table I'm using a hinge joint with it's Lo/HiStop set to 0 to prevent wobbly legs. But a 'fixed joint' would make more sense right since the table legs are not supposed to be just connected to each other and not move - JUST BREAK! eh eh...

BUT If I replace any 'dJointCreateHinge' with a 'dJointCreateFixed' then I get a MAV when ever I try to run it...

This normal? Wrapper bug? ode bug? me bugged?

cheers
Danny.


VIP3R(Posted 2006) [#5]
Fixed joints work ok, so it must be 'you bugged' :D

Take a look at the 'CarDemo-SphereWrapCylinder.bb' demo, it contains use of the fixed joint. It boils down to...

Joint=dJointCreateFixed(World,0)
dJointAttach(Joint,Body1,Body2)
dJointSetFixed(Joint)


I'd guess you've forgotten to remove some (or all) of the now redundant hinge functions... dJointSetHingeAnchor() / dJointSetHingeParam() etc.

If you're still getting errors, post some code and I'll try to help ;)


Danny(Posted 2006) [#6]
Yep, you're right. Tried it, works! cool! ....

I think one of the mayor differences between ode & tokamak (there more I'm sure) but is that you don't have Animated vs Rigid Bodies. And ODE rigid bodies behave more than you'd expect them to: when you move them around they affect their surroundings; with Tok you couldn't do that without losing colision & interaction.

A simple example is to create a door which you can open automatically (player presses spacebar, rotate door +90 degrees to open) BUT can get stuck when for example you've got a dozen heavy crates stacked on top of each other on the other side. This should block the door. But if the player pushes hard enough, he should be able to open the door AND shift the crates at the same time...
I'm gonna try that next! :)


Danny(Posted 2006) [#7]
Super cool! Check this out... Danny's Diner!

Hold down the left mousebutton to move the white player cube and move him through the doors, bump over tables, etc!

Wayne... If you're up for a tinker... Any idea HOW you can prevent that white player cube to go THROUGH walls and other bodies?! ;)




VIP3R(Posted 2006) [#8]
Ah, you're going to have severe problems forcing an objects position and rotation with ODE. The correct way is to add force/torque to the body or joint, ODE should be allowed to handle the position and rotation of all objects in the simulation.

Try adding the following to the Render Loop...

dBodyEnable(masterBody)
If KeyDown(59) Then dBodyAddForce(masterBody,-10,0,0)
If KeyDown(60) Then dBodyAddForce(masterBody,10,0,0)
If KeyDown(61) Then dBodyAddForce(masterBody,0,0,10)
If KeyDown(62) Then dBodyAddForce(masterBody,0,0,-10)

Use the F1-F4 keys to move the player box.

If you don't want the box to roll over, you can either lower its friction directly (see geom contacts) or create a sphere with a cube attached by a joint (encasing the sphere, except for its base). There are some demos showing the latter in the older JV-ODE threads, have a look for Psychic Parrots demo.


Danny(Posted 2006) [#9]
Cheers vip3r,

yes I realise forcing position & rotation is not the proper thing to do. But I'm pleasantly surprised how well ODE handles it nonetheless..

more to experiment...


Wayne(Posted 2006) [#10]
If you don't want the cube to roll you can dampen it's angular velocity along x,y, or z axis. using:
dBodySetAngularVel (dBodyID, dReal x, dReal y, dReal z)

With doors consider:
The ...ForceAtPos and ...ForceAtRelPos functions take an extra position vector (in global or body-relative coordinates respectively) that specifies the point at which the force is applied. All other functions apply the force at the center of mass.

Oh goodie a new progie to play with!


Danny(Posted 2006) [#11]
:)

Cheers Wayne. I'm now trying to figure out why the Hinge joint tries to go back to it's original orientation? When you push-open a door, it will close again - like those little doors they have in saloon's ;) In this case it works nice, but as a control freak, I'd like to determin that myself :)

Next progie on the menu... "Crowd surfing zombie makes it out the backdoor!"


Danny(Posted 2006) [#12]
Hmm... harder than I thought...

Sorry for harassing you guys, just tell me to shut up..

If not, How can you control the root (first) joint in a chain of joints?

Examples:
- If I create a rope made out of ball/socket joints, how can I move the start/top of the rope?
- More appropreate: Let's say my hierarchy of joints is used for a ragdoll. How can I MOVE the ragdoll by assigning one of the joints or bodies as a root and set it's position?

I've tried hacking away in the zombie demo, but either head remains in place while his body drops (sick neck stretch!) or he goes in some eleptic state.. I can't reposition the joint. So I've tried repositioning the root body or it's geometry only but all this don't work :(

any hints appreciated!

danny.


Wayne(Posted 2006) [#13]
Hows this:
Clamps player rotation.
Allows mouse to control the player.

I like the doors.

8)




Shifty Geezer(Posted 2006) [#14]
Danny. To move a ragdoll I move the head and then cycle through all the component objects and move them the same displacement (head's new positon - head's old position). I move the joints the same amount.

Rotating limbs gets a lot more tricky. It should be possible to create joint handlers that rotate joints based on an objects position (think a sphere placed at each joint that you can click and drag).

The tricky bit with ragdolls is keeping the object and joint alignments in sync when you want to save their posture. Object's rotation and positon is taken from the centre, while joints are at the end. If you think of a thigh bone (cube) hanging straight down, to rotate it so it sticks 90 degrees forwards, the joint at the hip is rotated 90 degrees easy enough. But the thigh cube is rotated 90 degrees AND moved up and out. If you just rotate the thigh cube it'll be all wrong. Hence for ragdolls there's cases where you need to destroy and rebuild the whole jointed model.

I haven't totally mastered joints. If I create a seesaw with motor forces so it spins around, I can move the seesaw and reposition the joint. eg. If I create a box (20,2,70) in size at (0,100,0) with a hinge joint at (0,0,0) on the x axis, with forces, it spins fine. If I then set the box's position to (30,100,0) and the joint's position to (30,100,0), the joint goes mental. I hack a workaround by saving the object and joint's new positions and then rebuilding the scene.

I haven't identified the cause of the problem. Checking the joint and body positons with dJoint...() and dBody...() functions show they align. As I've a workable solution for my needs I haven't looked further into it.


Danny(Posted 2006) [#15]
Thanks for the tips, and I hear what you're saying Shifty, I've made a key-frame animated / partially IK driven ragdoll before using Tokamak.
So I know how tricky it is to get a proper animation working in different circumstances;
I experimented with several different ways to keyframe limbs (in relation to another) etc. with mixed success. To makes things easier I also wanted to be able to re-use animations on different characters with different proportions! Again, mixed results; haven't found 'the perfect way' yet. I'll defenitly be spending some time trying to sort this out...

I'd like to experiment with motors as well. That WAS actually the whole reason why I switched to ODE, because I was trying to build little robots if your like, that propel themselves by building leg-type constructs with motors on them. Really funny stuff to watch those critters stumble around - but it was all too limited so in the end rather useless really.. :/

But first, I'll try and move that doll like you said. Sounds like there's no choice but to FORCE the position on ALL bodies (and thus inderectly the joints as well) using BodySetPosition as opposed to using Forces...

Danny-


Shifty Geezer(Posted 2006) [#16]
I don't understand ODE motors. I just applied forces to joints using

dJointSet...Param(dParamVel)
dJointSet...Param(dParamFMax)

At a guess, the joints have a motor object bydefault that's an angular motor, but it's not clear to me what and how the Motor functions are and should be used.


Danny(Posted 2006) [#17]
Hi Shifty,

I've managed to get some motor's working. Forget about using 'AMotor' - couldn't get that to work ;)
But create a HingeJoint, and like you set yourself, use the dParamVel and dParamFMax to add an angular velocity to the hinge joint.

I'll post a little example demo in a few minutes...
Danny

[edit] Shifty, check out http://www.blitzbasic.com/Community/posts.php?topic=56125 for the demo