creates a new vector from its coordinates * * Creates a new vector with the components set to the * supplied values. * * @name vmath.vector4 * @param x [type:number] x coordinate * @param y [type:number] y coordinate * @param z [type:number] z coordinate * @param w [type:number] w coordinate * @return v [type:vector4] new vector * @examples
| 1103 | * ``` |
| 1104 | */ |
| 1105 | static int Vector4_new(lua_State* L) |
| 1106 | { |
| 1107 | Vector4 v; |
| 1108 | // NOTE: The following comment is obsolete |
| 1109 | // "No empty constructor, since the value of w matters" |
| 1110 | // Don't understand why. Every component matters :-) |
| 1111 | // Empty constructor added. |
| 1112 | if (lua_gettop(L) == 0) |
| 1113 | { |
| 1114 | v = Vector4(0.0f, 0.0f, 0.0f, 0.0f); |
| 1115 | } |
| 1116 | else if (lua_gettop(L) == 1) |
| 1117 | { |
| 1118 | int type = lua_type(L, -1); |
| 1119 | if (type == LUA_TNUMBER) |
| 1120 | { |
| 1121 | float x = (float) lua_tonumber(L, -1); |
| 1122 | v = Vector4(x, x, x, x); |
| 1123 | } |
| 1124 | else |
| 1125 | { |
| 1126 | // If not number assume vector4 |
| 1127 | v = *CheckVector4(L, -1); |
| 1128 | } |
| 1129 | } |
| 1130 | else |
| 1131 | { |
| 1132 | v.setX((float) luaL_checknumber(L, 1)); |
| 1133 | v.setY((float) luaL_checknumber(L, 2)); |
| 1134 | v.setZ((float) luaL_checknumber(L, 3)); |
| 1135 | v.setW((float) luaL_checknumber(L, 4)); |
| 1136 | } |
| 1137 | PushVector4(L, v); |
| 1138 | return 1; |
| 1139 | } |
| 1140 | |
| 1141 | /*# creates a new identity quaternion |
| 1142 | * |
nothing calls this directly
no test coverage detected