Gui.set_rotation() documentation

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?

3 Likes

For consistency, we should change the documentation to mention a quaternion.

1 Like

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:

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

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. :slight_smile:

But go.animate() does this as well?

Yes, and this: go.set equivalent in gui namespace · Issue #5090 · defold/defold · GitHub

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. :man_facepalming:

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.

1 Like

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

I’ll look into this!

1 Like

The API reference has now been updated to include types for all parameters

4 Likes