creates a new vector from its coordinates * * Creates a new vector with the components set to the * supplied values. * * @name vmath.vector3 * @param x [type:number] x coordinate * @param y [type:number] y coordinate * @param z [type:number] z coordinate * @return v [type:vector3] new vector * @examples * * ```lua * local vec = vmath
| 997 | * ``` |
| 998 | */ |
| 999 | static int Vector3_new(lua_State* L) |
| 1000 | { |
| 1001 | Vector3 v; |
| 1002 | if (lua_gettop(L) == 0) |
| 1003 | { |
| 1004 | v = Vector3(0.0f, 0.0f, 0.0f); |
| 1005 | } |
| 1006 | else if (lua_gettop(L) == 1) |
| 1007 | { |
| 1008 | int type = lua_type(L, -1); |
| 1009 | if (type == LUA_TNUMBER) |
| 1010 | { |
| 1011 | float x = (float) lua_tonumber(L, -1); |
| 1012 | v = Vector3(x, x, x); |
| 1013 | } |
| 1014 | else |
| 1015 | { |
| 1016 | // If not number assume vector3 |
| 1017 | v = *CheckVector3(L, -1); |
| 1018 | } |
| 1019 | } |
| 1020 | else |
| 1021 | { |
| 1022 | v.setX((float) luaL_checknumber(L, 1)); |
| 1023 | v.setY((float) luaL_checknumber(L, 2)); |
| 1024 | v.setZ((float) luaL_checknumber(L, 3)); |
| 1025 | } |
| 1026 | PushVector3(L, v); |
| 1027 | return 1; |
| 1028 | } |
| 1029 | |
| 1030 | /*# creates a new zero vector |
| 1031 | * |
nothing calls this directly
no test coverage detected