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

Function Project

engine/script/src/script_vmath.cpp:2334–2343  ·  view source on GitHub ↗

projects a vector onto another vector * * Calculates the extent the projection of the first vector onto the second. * The returned value is a scalar p defined as: * * p = |P| cos θ / |Q| * * where θ is the angle between the vectors P and Q. * * @name vmath.project * @param v1 [type:vector3] vector to be projected on the s

Source from the content-addressed store, hash-verified

2332 * ```
2333 */
2334 static int Project(lua_State* L)
2335 {
2336 Vector3* v1 = CheckVector3(L, 1);
2337 Vector3* v2 = CheckVector3(L, 2);
2338 float sq_len = dmVMath::LengthSqr(*v2);
2339 if (sq_len == 0.0f)
2340 return luaL_error(L, "The second %s.%s to %s.%s must have a length bigger than 0.", SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_VECTOR3, SCRIPT_LIB_NAME, "project");
2341 lua_pushnumber(L, dmVMath::Dot(*v1, *v2) / sq_len);
2342 return 1;
2343 }
2344
2345 /*# performs an element wise multiplication of two vectors
2346 *

Callers

nothing calls this directly

Calls 5

CheckVector3Function · 0.85
luaL_errorFunction · 0.85
lua_pushnumberFunction · 0.85
LengthSqrFunction · 0.70
DotFunction · 0.70

Tested by

no test coverage detected