calculates the dot-product of two vectors * * The returned value is a scalar defined as: * * P ⋅ Q = |P| |Q| cos θ * * where θ is the angle between the vectors P and Q. * * - If the dot product is positive then the angle between the vectors is below 90 degrees. * - If the dot product is zero the vectors are perpendicula
| 1815 | * ``` |
| 1816 | */ |
| 1817 | static int Dot(lua_State* L) |
| 1818 | { |
| 1819 | void* argument1 = 0; |
| 1820 | void* argument2 = 0; |
| 1821 | const ScriptUserType type1 = CheckUserData(L, 1, &argument1); |
| 1822 | const ScriptUserType type2 = CheckUserData(L, 2, &argument2); |
| 1823 | |
| 1824 | if (type1 != type2) |
| 1825 | { |
| 1826 | return luaL_error(L, "%s.%s Arguments needs to be of same type!", SCRIPT_LIB_NAME, "dot"); |
| 1827 | } |
| 1828 | if (type1 == SCRIPT_TYPE_VECTOR3) |
| 1829 | { |
| 1830 | Vector3* v1 = (Vector3*)argument1; |
| 1831 | Vector3* v2 = (Vector3*)argument2; |
| 1832 | lua_pushnumber(L, dmVMath::Dot(*v1, *v2)); |
| 1833 | } |
| 1834 | else if (type1 == SCRIPT_TYPE_VECTOR4) |
| 1835 | { |
| 1836 | Vector4* v1 = (Vector4*)argument1; |
| 1837 | Vector4* v2 = (Vector4*)argument2; |
| 1838 | lua_pushnumber(L, dmVMath::Dot(*v1, *v2)); |
| 1839 | } |
| 1840 | else |
| 1841 | { |
| 1842 | return luaL_error(L, "%s.%s accepts (%s|%s) as arguments.", SCRIPT_LIB_NAME, "dot", SCRIPT_TYPE_NAME_VECTOR3, SCRIPT_TYPE_NAME_VECTOR4); |
| 1843 | } |
| 1844 | return 1; |
| 1845 | } |
| 1846 | |
| 1847 | /*# calculates the squared length of a vector or quaternion |
| 1848 | * |
no test coverage detected