How to Get Rotation in Radians from BEPU Entity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Skara
Posts: 3
Joined: Sun Jul 15, 2012 4:04 pm

How to Get Rotation in Radians from BEPU Entity

Post by Skara »

Hi,

I was wondering what is the best way to get the radian rotation in one axis of BEPU entity to use for sprite rendering of visuals?

Thanks,

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

Re: How to Get Rotation in Radians from BEPU Entity

Post by Norbo »

There does not exist a unique angle around an axis for a given orientation. Some extra information is needed to construct the basis for measurement.

For example, if the entity only has one angular degree of freedom because the inertia tensor was partially locked or the entity is otherwise constrained, then you can conceptually attach a 'measurement axis' to the entity and use Math.Atan2 on the axis's horizontal plane components to determine the angle.
Skara
Posts: 3
Joined: Sun Jul 15, 2012 4:04 pm

Re: How to Get Rotation in Radians from BEPU Entity

Post by Skara »

Norbo wrote:There does not exist a unique angle around an axis for a given orientation. Some extra information is needed to construct the basis for measurement.

For example, if the entity only has one angular degree of freedom because the inertia tensor was partially locked or the entity is otherwise constrained, then you can conceptually attach a 'measurement axis' to the entity and use Math.Atan2 on the axis's horizontal plane components to determine the angle.
I have tried converting the Quaternion to YawPitchRoll but I am not sure how to deal with wrapping that was occuring.

Could you detail how you would add a measurement axis, please?

Thanks,

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

Re: How to Get Rotation in Radians from BEPU Entity

Post by Norbo »

Could you detail how you would add a measurement axis, please?
Assuming that the only allowed rotation was around the Z axis:

Code: Select all

            //This is the axis in the local space of the entity shape which we will transform and use as our measurement axis.
            Vector3 localMeasurementAxis = new Vector3(1, 0, 0);
... then, in each angle test ...
            //Transform the local axis into world space
            var worldMeasurementAxis = Vector3.Transform(localMeasurementAxis, entity.Orientation);
            //Compute the angle on the horizontal plane.
            var angle = Math.Atan2(worldMeasurementAxis.Y, worldMeasurementAxis.X);
Since the localMeasurementAxis above is aligned perfectly to one of the local space basis axes, it can be reduced to:

Code: Select all

            var worldMeasurementAxis = entity.OrientationMatrix.Right;
            var angle = Math.Atan2(worldMeasurementAxis.Y, worldMeasurementAxis.X);
If rotation is allowed around any axis, then the process is much less well defined. At that point, an arbitrary decomposition of the orientation must be chosen- and even then, it will be difficult to interpret the results meaningfully.

For a game where the graphics are 2d, it would be simplest to constrain the rotation of objects to one axis by setting two of the three rows in the LocalInertiaTensorInverse to zeroes to allow you to use the above measurement axis approach. To allow rotation only around the Z axis, the inertia tensor modification looks like this:

Code: Select all

                    var inertiaInverse = entity.LocalInertiaTensorInverse;
                    inertiaInverse.M11 = 0; 
                    inertiaInverse.M12 = 0;
                    inertiaInverse.M13 = 0;
                    inertiaInverse.M21 = 0;
                    inertiaInverse.M22 = 0;
                    inertiaInverse.M23 = 0;
                    entity.LocalInertiaTensorInverse = inertiaInverse;
Skara
Posts: 3
Joined: Sun Jul 15, 2012 4:04 pm

Re: How to Get Rotation in Radians from BEPU Entity

Post by Skara »

Hi,

I got the YawPitchRoll methodology to work - I was using an invalid method to convert from Quaternion to Yaw, Pitch, Roll. I then saw your reply and methodology and switched to that, it is more compact and eloquent. Thank you Norbo for the great response time and depth of knowledge. I am really starting to enjoy using BEPU.

Regards,

Skara.
Post Reply