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
How to Get Rotation in Radians from BEPU Entity
Re: How to Get Rotation in Radians from BEPU Entity
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.
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.
Re: How to Get Rotation in Radians from BEPU Entity
I have tried converting the Quaternion to YawPitchRoll but I am not sure how to deal with wrapping that was occuring.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.
Could you detail how you would add a measurement axis, please?
Thanks,
Skara
Re: How to Get Rotation in Radians from BEPU Entity
Assuming that the only allowed rotation was around the Z axis:Could you detail how you would add a measurement axis, please?
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);
Code: Select all
var worldMeasurementAxis = entity.OrientationMatrix.Right;
var angle = Math.Atan2(worldMeasurementAxis.Y, worldMeasurementAxis.X);
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;
Re: How to Get Rotation in Radians from BEPU Entity
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.
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.