0

My object can have any(unknown) rotation in the world.

I need to interpolate this object's local UP-axis, towards the World's UP-axis, without touching the object's other local rotations (imagine a buoy righting itself after a wave-hit).

But, I only manage to interpolate all the object's axis' towards all the World's axis' at the same time, effectively aligning my object to the World, like a hard drilled North Korean parade soldier.

I'm using this code to accomplish my failure:

var TopQuat:Quat = Quat(0,0,0,1)
transform.basis = Basis(Quat(transform.basis).slerp(TopQuat,delta))

Any hints for isolating this interpolation to my object's local UP-axis?

Ole Sauffaus
  • 534
  • 3
  • 13

1 Answers1

1

Quaternion SLERP will interpolate between the two orientation quaternions - i.e., when the interpolation weight reaches 1.0, your object's frame will match the world frame.

What you are looking for is a quaternion that represents axis-angle rotation between the two UP vectors. This can be computed using a cross-product of the two vectors to compute the axis of rotation, dot-product to compute (the cosine of) the angle between the two vectors and the formula to create a quaternion of an axis and an angle.

Depending on which framework you are using for your implementation, you might have a method like this already implemented on the quaternion class. For example, OpenEXR's Imath::Quaternion class includes a setRotation() method, implementing a slightly more advanced version of the algorithm described above.

Martin Prazak
  • 1,476
  • 12
  • 20
  • Thank you for this answer, that looks to be perfect. However, I suddenly got busy with other things, and will test it out at some later date, and then accept, if it answers my question. – Ole Sauffaus May 08 '19 at 07:27