how to get objects to point up

jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

how to get objects to point up

Post by jackskelyton »

What method or methods would be used to get an object to correct its roll or tilt to always point up? Like if a vehicle did a flip in the air, how to ensure it lands right-side-up?
jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

Re: how to get objects to point up

Post by jackskelyton »

*bump* need an answer on this.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: how to get objects to point up

Post by Erwin Coumans »

You can keep an objects _always_ up using a constraint. But that means removing degrees of freedom. This means the object will not freely 'tilt' as you call it.

If that is what you want, try adding a btHingeConstraint to the object, and set the hinge to angular only (void setAngularOnly(bool angularOnly)).

If you want to allow full rotation with 6DOFs(tilt), but recover to up, you can either manually set the orientation or add a soft rotational spring (soft hinge).

HTH,
Erwin
jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

Re: how to get objects to point up

Post by jackskelyton »

How do you add a soft hinge?
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: how to get objects to point up

Post by pico »

I had the same problem. None of the constraints from bullet did the job, and as Erwin said even if this would work you would need a soft constraint.

I used in the end a center of Mass shift to ensure my vehicle points upwards. As long as you don't have too steep streets the car won't tilt over. To change center of Mass you need to wrap your collision shape into a compound shape. I think the CCD demo has a define for centerOfMass. Check it out to see how it works.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: how to get objects to point up

Post by Erwin Coumans »

There are easier ways to get the vehicle pointing upwards, but we don't have time/resources to work on this.

We are very busy preparing for the game developers conference...

So please stay tuned, we'll get back to this later,
Thanks,
Erwin
RobW
Posts: 33
Joined: Fri Feb 01, 2008 9:44 am

Re: how to get objects to point up

Post by RobW »

What sort of thing did you have mind, Erwin?

I had the same problem; the generic6dof constraint cannot be configured to have free rotation around Y due to singularities when it comes to extracting Euler angles from the body's orientation. I couldn't see how the hinge constraint was useful because it it fixes 2 angular dof and limits another, but I wanted 2 limited and one free.

In the end, I wrote a new simple constraint which works in the world frame to limit x/z rotation, which makes it very simple with the downside that you can only specify a single limit value which defines a symmetric 'cone' of tolerated 'tilt' away from 'up'.

I can share this if it would help.
jackskelyton
Posts: 32
Joined: Mon Nov 05, 2007 3:52 pm

Re: how to get objects to point up

Post by jackskelyton »

Our needs are simple enough that we can make do with SetAngularFactor, but I would appreciate seeing your "tolerance cone" code, Rob. Thank you :)
RobW
Posts: 33
Joined: Fri Feb 01, 2008 9:44 am

Re: how to get objects to point up

Post by RobW »

pm me your email address and I'll send you the code :)
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: how to get objects to point up

Post by Erwin Coumans »

Hi Rob,

It would be great if you can zip the code and attach it to this issue.

Others might find this useful too,
Erwin
RobW
Posts: 33
Joined: Fri Feb 01, 2008 9:44 am

Re: how to get objects to point up

Post by RobW »

Here it is...It is a normal constraint with the same interface as Bullet's hinge, 6dof etc, so you could set it up something like this:

Code: Select all

btRigidBody *body = ... create abody
btUprightConstraint *upright = new btUprightConstraint( body, btTransform::getIdentity() );
m_dynamicsWorld->addConstraint( upright );
upright->setLimit( 0 );  // Stay completely upright
If you set a limit of 0, it should keep the object fully upright, SIMD_PI allows free rotation, you probably want something between 0 and about PI/4. There are various accessor functions to set the damping, bounce, error reduction etc.

It isn't particularly tested, but works well for us.
You do not have the required permissions to view the files attached to this post.
jcarew
Posts: 9
Joined: Sun Jul 13, 2008 8:31 pm

Re: how to get objects to point up

Post by jcarew »

How can I use it in the latest Bullet version? Currently code don't work properly. This is compatible tips with btRaycastVehicle?
RobW
Posts: 33
Joined: Fri Feb 01, 2008 9:44 am

Re: how to get objects to point up

Post by RobW »

I'm afraid I haven't been keeping up to date with Bullet lately, but yesterday I did try using the constraint on a vehicle, on Bullet 2.69 (the newest one I had on my machine).

It worked fine, but for some reason when increasing the simulation framerate to 240hz (which I imagine you would want to do with a fast vehicle simulation), it stopped working. To fix this I increased the force limiter in the constructor of the constraint by a factor of ten. This is a bit suspect, since it does seem to adjust it for the simulation rate elsewhere in the file.

I'll post some code later which will be a modification of the vehicle demo, which first turns the vehicle into something very easy to tip over, and then fixes it with the constraint. There are some other issues with the constraint, I might be able to post a fixed version of it too.

Cheers,
Rob
heeen
Posts: 6
Joined: Tue Feb 17, 2009 6:32 pm

Re: how to get objects to point up

Post by heeen »

It doesn't work in 2.74 anymore, its missing a few pure virtual functions from btTypedConstraint.
Does anyone know how to fix this? empty functions don't work apparently.

edit: I'm now using this:

Code: Select all

btGeneric6DofConstraint* c=new btGeneric6DofConstraint(*game.worldBody, *body, btTransform::getIdentity(), btTransform::getIdentity(), false);

	c->setLimit(0, -SIMD_INFINITY,SIMD_INFINITY);
	c->setLimit(1, -SIMD_INFINITY,SIMD_INFINITY);
	c->setLimit(2, -SIMD_INFINITY,SIMD_INFINITY);
	c->setLimit(3, 0,0);
	c->setLimit(4, 0,0);
	c->setLimit(5, -SIMD_PI,SIMD_PI);
Is this a better or worse solution than the UprightConstraint above?
hamster
Posts: 1
Joined: Sat Mar 21, 2009 6:19 am

Re: how to get objects to point up

Post by hamster »

The following changes make btUprightConstraint build again with bullet 2.74:
I renamed solveConstraint to solveConstraintObsolete and adapted its signature, and added getInfo1/2 stubs. I haven't tried the original code, but this one seems to work as expected.

Greetings,
Stefan
You do not have the required permissions to view the files attached to this post.