Calculate omega needed for local rotation.

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Calculate omega needed for local rotation.

Postby mlfarrell » Sun Aug 23, 2015 10:52 pm

So I have some code that uses NewtonBodySetOmega to quickly orient a body to face a certain direction, but it doesn't do what I want exactly

The Y component of the omega vector is about the world-space Y vector. What I WANT to do is provide a rotation about an arbitrary vector (which will be the object-local up vector) to spin the vehicle around its own up axis.

Given a dTheta and an arbitrary world-space vector, now do I derive the 3 separate omega values about the fixed orthogonal global axes?
mlfarrell
 
Posts: 14
Joined: Mon Aug 23, 2010 3:39 am

Re: Calculate omega needed for local rotation.

Postby JoeJ » Mon Aug 24, 2015 7:06 am

mlfarrell wrote:Given a dTheta and an arbitrary world-space vector, now do I derive the 3 separate omega values about the fixed orthogonal global axes?


Assuming your world space vector is the normalized axis of the desired rotation,
and theta is the angle of the desired rotation,
and the duration of rotation should be 1 time unit,

angular velocity (= omega) would be simply:
vec3 targetAngvel = axis * angle

If you want the rotation happen in one step it becomes
targetAngvel = axis * angle / timestep

The Problem is, it will hit the target at the next step, but it also has high velocity so it will drive away from the target after further timesteps ("overspin").
So you may use a small factor like 0.3 to prevent this.

After you got used to this, you may want to set torque instead of velocity for better results.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Calculate omega needed for local rotation.

Postby mlfarrell » Mon Aug 24, 2015 6:01 pm

This worked beautifully, thanks. Another one of those times in linear algebra where the solution is simpler than I thought it would be.

I use a albeit hacky solution to set the omega angle to ever-decreasing angles at the difference between the desired heading and actual heading (extracted from quaternion) becomes smaller. The result is a rapid but smoothly-animated change in heading that doesn't get held up by things like friction and gravity.

works great!
mlfarrell
 
Posts: 14
Joined: Mon Aug 23, 2010 3:39 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron