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

Function Lerp

engine/script/src/script_vmath.cpp:2113–2153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2111 */
2112
2113 static int Lerp(lua_State* L)
2114 {
2115 float t = (float) luaL_checknumber(L, 1);
2116 if (lua_isnumber(L, 2) && lua_isnumber(L, 3))
2117 {
2118 lua_Number n1 = (float) luaL_checknumber(L, 2);
2119 lua_Number n2 = (float) luaL_checknumber(L, 3);
2120 lua_pushnumber(L, n1 + t * (n2 - n1));
2121 return 1;
2122 }
2123
2124 void* argument1 = 0;
2125 void* argument2 = 0;
2126 const ScriptUserType type1 = CheckUserData(L, 2, &argument1);
2127 const ScriptUserType type2 = CheckUserData(L, 3, &argument2);
2128 if (type1 == type2 && type1 != SCRIPT_TYPE_UNKNOWN)
2129 {
2130 if (type1 == SCRIPT_TYPE_VECTOR3)
2131 {
2132 Vector3* v1 = (Vector3*)argument1;
2133 Vector3* v2 = (Vector3*)argument2;
2134 PushVector3(L, dmVMath::Lerp(t, *v1, *v2));
2135 return 1;
2136 }
2137 else if (type1 == SCRIPT_TYPE_VECTOR4)
2138 {
2139 Vector4* v1 = (Vector4*)argument1;
2140 Vector4* v2 = (Vector4*)argument2;
2141 PushVector4(L, dmVMath::Lerp(t, *v1, *v2));
2142 return 1;
2143 }
2144 else if (type1 == SCRIPT_TYPE_QUAT)
2145 {
2146 Quat* q1 = (Quat*)argument1;
2147 Quat* q2 = (Quat*)argument2;
2148 PushQuat(L, dmVMath::Lerp(t, *q1, *q2));
2149 return 1;
2150 }
2151 }
2152 return luaL_error(L, "%s.%s takes one number and a pair of either %s.%ss, %s.%ss, %s.%ss or numbers as arguments.", SCRIPT_LIB_NAME, "lerp", SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_VECTOR3, SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_VECTOR4, SCRIPT_LIB_NAME, SCRIPT_TYPE_NAME_QUAT);
2153 }
2154
2155 /*# slerps between two vectors
2156 *

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected