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

Function Slerp

engine/script/src/script_vmath.cpp:2227–2260  ·  view source on GitHub ↗

slerps between two quaternions * * Slerp travels the torque-minimal path maintaining constant * velocity, which means it travels along the straightest path along * the rounded surface of a sphere. Slerp is useful for interpolation * of rotations. * * Slerp travels the torque-minimal path, which means it travels * along the straightest path the rounded surfac

Source from the content-addressed store, hash-verified

2225 * ```
2226 */
2227 static int Slerp(lua_State* L)
2228 {
2229 void* argument1 = 0;
2230 void* argument2 = 0;
2231 const ScriptUserType type1 = CheckUserData(L, 2, &argument1);
2232 const ScriptUserType type2 = CheckUserData(L, 3, &argument2);
2233
2234 if (type1 == type2)
2235 {
2236 float t = (float) luaL_checknumber(L, 1);
2237 if (type1 == SCRIPT_TYPE_QUAT)
2238 {
2239 Quat* q1 = (Quat*)argument1;
2240 Quat* q2 = (Quat*)argument2;
2241 PushQuat(L, dmVMath::Slerp(t, *q1, *q2));
2242 return 1;
2243 }
2244 else if (type1 == SCRIPT_TYPE_VECTOR4)
2245 {
2246 Vector4* v1 = (Vector4*)argument1;
2247 Vector4* v2 = (Vector4*)argument2;
2248 PushVector4(L, dmVMath::Slerp(t, *v1, *v2));
2249 return 1;
2250 }
2251 else if (type1 == SCRIPT_TYPE_VECTOR3)
2252 {
2253 Vector3* v1 = (Vector3*)argument1;
2254 Vector3* v2 = (Vector3*)argument2;
2255 PushVector3(L, dmVMath::Slerp(t, *v1, *v2));
2256 return 1;
2257 }
2258 }
2259 return luaL_error(L, "%s.%s takes one number and either two %s.%s or two %s.%s as arguments.", SCRIPT_LIB_NAME, "slerp", SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_VECTOR3, SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_QUAT);
2260 }
2261
2262 /*# calculates the conjugate of a quaternion
2263 *

Callers

nothing calls this directly

Calls 6

CheckUserDataFunction · 0.85
luaL_checknumberFunction · 0.85
PushQuatFunction · 0.85
PushVector4Function · 0.85
PushVector3Function · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected