normalizes a vector * * Normalizes a vector, i.e. returns a new vector with the same * direction as the input vector, but with length 1. * * [icon:attention] The length of the vector must be above 0, otherwise a * division-by-zero will occur. * * @name vmath.normalize * @param v1 [type:vector3|vector4|quaternion] vector to normalize * @return v [ty
| 1956 | * ``` |
| 1957 | */ |
| 1958 | static int Normalize(lua_State* L) |
| 1959 | { |
| 1960 | void* argument = 0; |
| 1961 | const ScriptUserType type = CheckUserData(L, 1, &argument); |
| 1962 | if (type == SCRIPT_TYPE_VECTOR3) |
| 1963 | { |
| 1964 | Vector3* v = (Vector3*)argument; |
| 1965 | PushVector3(L, dmVMath::Normalize(*v)); |
| 1966 | } |
| 1967 | else if (type == SCRIPT_TYPE_VECTOR4) |
| 1968 | { |
| 1969 | Vector4* v = (Vector4*)argument; |
| 1970 | PushVector4(L, dmVMath::Normalize(*v)); |
| 1971 | } |
| 1972 | else if (type == SCRIPT_TYPE_QUAT) |
| 1973 | { |
| 1974 | Quat* value = (Quat*)argument; |
| 1975 | PushQuat(L, dmVMath::Normalize(*value)); |
| 1976 | } |
| 1977 | else |
| 1978 | { |
| 1979 | return luaL_error(L, "%s.%s accepts (%s|%s|%s) as argument.", SCRIPT_LIB_NAME, "normalize", SCRIPT_TYPE_NAME_VECTOR3, SCRIPT_TYPE_NAME_VECTOR4, SCRIPT_TYPE_NAME_QUAT); |
| 1980 | } |
| 1981 | return 1; |
| 1982 | } |
| 1983 | |
| 1984 | /*# calculates the cross-product of two vectors |
| 1985 | * |
nothing calls this directly
no test coverage detected