Forum

Rotation around any pivot point

03 September 2015 15:32 #3640
I don't know whether this is already solved, but I couldn't find similar posts here.

Is there a ready made way to rotate an object by API around a pivot point that's not the center of origin of the object?
I know I can accomplish this by using rotation matrix and translations but I'll try doing it a simpler way first.

Thanks for the help!
03 September 2015 16:18 #3641
right now I am trying to solve this with an inserted empty. The empty sits at the pivot point and is parented to the rotation object by this API call:
m_cons.append_stiff_trans_rot(child, target, trans_offset);

This seems to work out well, but the translatory offset isn't respected properly
03 September 2015 19:04 #3644

This seems to work out well, but the translatory offset isn't respected properly
trans_offset should be set in the parent's local space. So the parent transforms (e.g non-unit scale) can additionally affect child position in the world space.

Actually you don't need any constraint to achieve such rotation. If you have the pivot and the rotation axis it can be done in the following way:

1) get the vector directed from the object position to the pivot
2) rotate it around specific axis using a quaternion
3) calculate destination point by adding transformed vector to the pivot point

Something similar is calculated in the rotate_point_pivot function.

You can get the appropriate quaternion from this function:
setAxisAngle.
Blend4Web Team
07 September 2015 16:09 #3662
Methematically this is everything that needs to be done, I was just wondering whether there is a readymade function for this already in the API. I don't see rotate_point_pivot() somewhere documented in v15.08.
07 September 2015 17:06 #3663
Methematically this is everything that needs to be done, I was just wondering whether there is a readymade function for this already in the API.

We don't have an API function like this, because such transform is a specific case - one among many, and it can be done by a developer himself using the API of the vec3, vec4, mat3, mat4 and quat modules. So it's just a bit low-level at the moment . Perhaps, we'll cover the most common cases in the future and will make the API easier.


I don't see rotate_point_pivot() somewhere documented in v15.08.
Sorry for confusing you. This is not an API function. I mentioned it as an example how we do it inside the engine. Here is the link to source: rotate_point_pivot

Blend4Web Team
 
Please register or log in to leave a reply.