totebo
June 21, 2021, 8:46am
1
Here is an old chestnut that continues to confuse me. Let’s make this Enlightenment Monday!
From the documentation :
gui.set_rotation()
gui.set_rotation(node,rotation)
Sets the rotation of the supplied node. The rotation is expressed in degree Euler angles.
Using a euler z number throws an error:
local euler_z = math.atan2(unlocked_level_node_position.y-level_node_position.y, unlocked_level_node_position.x-level_node_position.x)
--gui.set_rotation(node, euler_z) -- ERROR:SCRIPT: /screens/map/map.gui_script:36: bad argument #2 to 'set_rotation' (quat expected, got number)
local rotation = vmath.quat_rotation_z(euler_z)
gui.set_rotation(node, rotation)
Converting the euler z to a quaternion works. Two questions:
Does “degree Euler angles” actually mean a quaternion?
Wouldn’t it make sense to use a number, either euler z or radians, in gui, since it’s in 2D space only?
4 Likes
For consistency, we should change the documentation to mention a quaternion.
1 Like
britzl
June 21, 2021, 9:02am
3
The API reference doesn’t say what type rotation should be in when calling gui.set_rotation(node, rotation) (I’ll fix this!).
The code does however enlighten us:
And if we look at the implementation there’s three code paths:
if ((v3 = dmScript::ToVector3(L, 2)))
{
Scene* scene = GetScene(L);
Vector4 original = dmGui::GetNodeProperty(scene, hnode, PROPERTY_ROTATION);
v = Vector4(*v3, original.getW());
} else if ((v4 = dmScript::ToVector4(L, 2))) {
v = *v4;
} else {
Scene* scene = GetScene(L);
Vector4 original = dmGui::GetNodeProperty(scene, hnode, PROPERTY_ROTATION);
Quat* q = dmScript::CheckQuat(L, 2);
v = Vector4(dmVMath::QuatToEuler(q->getX(), q->getY(), q->getZ(), q->getW()), original.getW());
}
So rotation is either a vector3, vector4 or a quaternion. And in the case of a quaternion it is converted to a v4 with euler angles.
2 Likes
totebo
June 21, 2021, 9:23am
4
Nice, thanks for that, I feel much more enlightened.
One final note, I’m a bit jealous of gui.animate() since it accepts a “rotation.z” number as an argument, as well as vectors:
gui.animate(node, "rotation.z", 180, gui.EASING_INOUTSINE, 1)
gui.animate(node, "rotation", vmath.vector3(0,0,180), gui.EASING_INOUTSINE, 1)
gui.animate(node, "rotation", vmath.vector4(0,0,180,0), gui.EASING_INOUTSINE, 1)
In the go space I tend to use go.set(".", "euler.z", 180)
, but this is not possible in gui space because there is no gui.set(). I think this is related to the gui.property() issue here .
Needless to say, I’m a fan of numbers.
britzl
June 21, 2021, 9:58am
5
totebo
June 21, 2021, 10:23am
6
Yeah, I mention is because of the lack of a gui.set() which you sent an even better link to. Upvote!
1 Like
…even though I read this yesterday, I still ran headfirst into it myself.
On a more general note, it would be great if all the parameters and return values in the API docs had their types specified. The current names and descriptions are not very helpful.
Like gui.get_layer() :
RETURNS
layer
layer id
You still have no idea what layer
is! String? Number? Hash? (it’s a hash.)
I’d be happy to help work on this, but I don’t know anything about where the API docs are written or how they’re generated, etc.
2 Likes
The reason is that the type currently isn’t shown for some reason. Not sure when that broke. Here is the actual source documentation:
2 Likes
britzl
June 23, 2021, 6:21am
10
britzl:
I’ll look into this!
The API reference has now been updated to include types for all parameters
4 Likes