calculates the length of a vector or quaternion * * Returns the length of the supplied vector or quaternion. * * If you are comparing the lengths of vectors or quaternions, you should compare * the length squared instead as it is slightly more efficient to calculate * (it eliminates a square root calculation). * * @name vmath.length * @param v [type:vec
| 1910 | * ``` |
| 1911 | */ |
| 1912 | static int Length(lua_State* L) |
| 1913 | { |
| 1914 | void* argument = 0; |
| 1915 | const ScriptUserType type = CheckUserData(L, 1, &argument); |
| 1916 | if (type == SCRIPT_TYPE_VECTOR3) |
| 1917 | { |
| 1918 | Vector3* v = (Vector3*)argument; |
| 1919 | lua_pushnumber(L, dmVMath::Length(*v)); |
| 1920 | } |
| 1921 | else if (type == SCRIPT_TYPE_VECTOR4) |
| 1922 | { |
| 1923 | Vector4* v = (Vector4*)argument; |
| 1924 | lua_pushnumber(L, dmVMath::Length(*v)); |
| 1925 | } |
| 1926 | else if (type == SCRIPT_TYPE_QUAT) |
| 1927 | { |
| 1928 | Quat* value = (Quat*)argument; |
| 1929 | lua_pushnumber(L, dmVMath::Length(*value)); |
| 1930 | } |
| 1931 | else |
| 1932 | { |
| 1933 | return luaL_error(L, "%s.%s accepts (%s|%s|%s) as argument.", SCRIPT_LIB_NAME, "length", SCRIPT_TYPE_NAME_VECTOR3, SCRIPT_TYPE_NAME_VECTOR4, SCRIPT_TYPE_NAME_QUAT); |
| 1934 | } |
| 1935 | return 1; |
| 1936 | } |
| 1937 | |
| 1938 | /*# normalizes a vector |
| 1939 | * |