MCPcopy Create free account
hub / github.com/defold/defold / Vector3_new

Function Vector3_new

engine/script/src/script_vmath.cpp:999–1028  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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 *

Callers

nothing calls this directly

Calls 10

lua_gettopFunction · 0.85
lua_typeFunction · 0.85
lua_tonumberFunction · 0.85
CheckVector3Function · 0.85
luaL_checknumberFunction · 0.85
PushVector3Function · 0.85
setZMethod · 0.80
Vector3Class · 0.50
setXMethod · 0.45
setYMethod · 0.45

Tested by

no test coverage detected