I'm deeply frustrated and intimitated by applying rotations

Don’t be. I am basically giving you advice on how to inspect the models you create with the C API.
The desktop editions can have extensions. The extension I told you about, will allow you to inspect the transformation matrices of the instances that you transform. Ie, it’s a self help avenue.

Firstly, again I remind you that SketchUp’s modeling axes are different from game engines.
Z is up, X is to the right (points toward east,) Y runs away from the viewer (and is north 0 degrees.)


A simple single rotation would be done by creating a rotational transform.
SUTransformationRotation

  • The point argument places the rotational axis vector somewhere in 3D space.
    This does not have to be (but can be) within or even near the instance itself.
  • The vector argument is the axis of rotation.
  • The angle argument will be the angle to rotate about the axis defined by the vector argument.

If you wish a compound rotation, then you’ll need to create 2 rotational transforms, and multiply them together, using the SUTransformationMultiply() function, and then apply the resultant transform to the instance.
You can also “mix in” translational and scaling transforms by multiplying them also.

But they are traditionally applied in a particular order. Translational first. Rotational second in (X, Y then Z order.) Then Scaling (X, Y then Z order.) Decomposing a transformation matrix must be done in reverse order. (See Aerilius’ code … link posted below.)

You could try this …

  1. You get the transform of the instance.
  2. from this you get the transform’s 3 axial vectors (X, Y and Z.) SUTransformationGetXAxis, etc.
  3. You get the model’s global Axes object … SUModelGetAxes
  4. from this you get the model’s 3 axial vectors (X, Y and Z.) SUAxesGetXAxis, etc.
  5. You compare each of the 3 corresponding instance transformation axis with the model’s corresponding axis.
    … ie X for X, Y for Y, etc. using SUVector3DAngleBetween

Note that the both (Ruby and C) API’s may have a limitation with the angle between method/function. I think it works using dot product for vectors which always returns a value between 0 and 180. (May not be a problem if the return value is signed.)

There are some ways to use trigonometry on the matrix values to get the axial rotations.
Aerilius posted code in Ruby here …

3 Likes