Skip to content

Commit

Permalink
allow setting x, y, z components of translate and scale nodes indepen…
Browse files Browse the repository at this point in the history
…dently
  • Loading branch information
ianmaclarty committed Sep 18, 2016
1 parent 8ec4912 commit 46c515b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/scene_nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ Fields:

- `position`: The translation position as a `vec3`. Updatable.
- `position2d`: The translation position as a `vec2`. Updatable.
- `x`, `y`, `z`: The `x`, `y` and `z` components of the position. Updatable.

Default tag: `"translate"`.

Expand All @@ -553,6 +554,8 @@ local node2 = am.translate(vec2(10, 20))
local node3 = am.translate("MyModelViewMatrix", 1, 2, -3.5)
local node4 = am.translate(vec3(1, 2, 3))
node1.position2d = vec2(30, 40)
node2.x = 40
node2.y = 50
node3.position = vec3(1, 2, -3)
~~~

Expand All @@ -574,6 +577,7 @@ Fields:

- `scale`: The scale as a `vec3`. Updatable.
- `scale2d`: The scale as a `vec2`. Updatable.
- `x`, `y`, `z`: The `x`, `y` and `z` components of the scale. Updatable.

Default tag: `"scale"`.

Expand All @@ -585,6 +589,7 @@ local node2 = am.scale(2, 1)
local node3 = am.scale(vec2(1, 2))
local node4 = am.scale("MyModelViewMatrix", vec3(0.5, 2, 3))
node1.scale2d = vec2(1)
node2.x = 3
node4.scale = vec3(1, 3, 2)
~~~

Expand Down
78 changes: 78 additions & 0 deletions src/am_transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,42 @@ static void set_position2d(lua_State *L, void *obj) {

static am_property position2d_property = {get_position2d, set_position2d};

static void get_position_x(lua_State *L, void *obj) {
am_translate_node *node = (am_translate_node*)obj;
lua_pushnumber(L, node->v.x);
}

static void set_position_x(lua_State *L, void *obj) {
am_translate_node *node = (am_translate_node*)obj;
node->v.x = luaL_checknumber(L, 3);
}

static am_property position_x_property = {get_position_x, set_position_x};

static void get_position_y(lua_State *L, void *obj) {
am_translate_node *node = (am_translate_node*)obj;
lua_pushnumber(L, node->v.y);
}

static void set_position_y(lua_State *L, void *obj) {
am_translate_node *node = (am_translate_node*)obj;
node->v.y = luaL_checknumber(L, 3);
}

static am_property position_y_property = {get_position_y, set_position_y};

static void get_position_z(lua_State *L, void *obj) {
am_translate_node *node = (am_translate_node*)obj;
lua_pushnumber(L, node->v.z);
}

static void set_position_z(lua_State *L, void *obj) {
am_translate_node *node = (am_translate_node*)obj;
node->v.z = luaL_checknumber(L, 3);
}

static am_property position_z_property = {get_position_z, set_position_z};

static void register_translate_node_mt(lua_State *L) {
lua_newtable(L);
lua_pushcclosure(L, am_scene_node_index, 0);
Expand All @@ -98,6 +134,9 @@ static void register_translate_node_mt(lua_State *L) {

am_register_property(L, "position", &position_property);
am_register_property(L, "position2d", &position2d_property);
am_register_property(L, "x", &position_x_property);
am_register_property(L, "y", &position_y_property);
am_register_property(L, "z", &position_z_property);

am_register_metatable(L, "translate", MT_am_translate_node, MT_am_scene_node);
}
Expand Down Expand Up @@ -177,6 +216,42 @@ static void set_scale2d(lua_State *L, void *obj) {

static am_property scale2d_property = {get_scale2d, set_scale2d};

static void get_scale_x(lua_State *L, void *obj) {
am_scale_node *node = (am_scale_node*)obj;
lua_pushnumber(L, node->v.x);
}

static void set_scale_x(lua_State *L, void *obj) {
am_scale_node *node = (am_scale_node*)obj;
node->v.x = luaL_checknumber(L, 3);
}

static am_property scale_x_property = {get_scale_x, set_scale_x};

static void get_scale_y(lua_State *L, void *obj) {
am_scale_node *node = (am_scale_node*)obj;
lua_pushnumber(L, node->v.y);
}

static void set_scale_y(lua_State *L, void *obj) {
am_scale_node *node = (am_scale_node*)obj;
node->v.y = luaL_checknumber(L, 3);
}

static am_property scale_y_property = {get_scale_y, set_scale_y};

static void get_scale_z(lua_State *L, void *obj) {
am_scale_node *node = (am_scale_node*)obj;
lua_pushnumber(L, node->v.z);
}

static void set_scale_z(lua_State *L, void *obj) {
am_scale_node *node = (am_scale_node*)obj;
node->v.z = luaL_checknumber(L, 3);
}

static am_property scale_z_property = {get_scale_z, set_scale_z};

static void register_scale_node_mt(lua_State *L) {
lua_newtable(L);
lua_pushcclosure(L, am_scene_node_index, 0);
Expand All @@ -186,6 +261,9 @@ static void register_scale_node_mt(lua_State *L) {

am_register_property(L, "scale", &scale_property);
am_register_property(L, "scale2d", &scale2d_property);
am_register_property(L, "x", &scale_x_property);
am_register_property(L, "y", &scale_y_property);
am_register_property(L, "z", &scale_z_property);

am_register_metatable(L, "scale", MT_am_scale_node, MT_am_scene_node);
}
Expand Down

0 comments on commit 46c515b

Please sign in to comment.