mirror of https://github.com/bjornbytes/lovr.git
Curve:getTangent;
This commit is contained in:
parent
2703192f1d
commit
76c2dc757a
|
@ -12,6 +12,17 @@ int l_lovrCurveEvaluate(lua_State* L) {
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrCurveGetTangent(lua_State* L) {
|
||||||
|
Curve* curve = luax_checktype(L, 1, Curve);
|
||||||
|
float t = luaL_checknumber(L, 2);
|
||||||
|
float point[3];
|
||||||
|
lovrCurveGetTangent(curve, t, point);
|
||||||
|
lua_pushnumber(L, point[0]);
|
||||||
|
lua_pushnumber(L, point[1]);
|
||||||
|
lua_pushnumber(L, point[2]);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
int l_lovrCurveRender(lua_State* L) {
|
int l_lovrCurveRender(lua_State* L) {
|
||||||
Curve* curve = luax_checktype(L, 1, Curve);
|
Curve* curve = luax_checktype(L, 1, Curve);
|
||||||
int n = luaL_optinteger(L, 2, 32);
|
int n = luaL_optinteger(L, 2, 32);
|
||||||
|
@ -89,6 +100,7 @@ int l_lovrCurveRemovePoint(lua_State* L) {
|
||||||
|
|
||||||
const luaL_Reg lovrCurve[] = {
|
const luaL_Reg lovrCurve[] = {
|
||||||
{ "evaluate", l_lovrCurveEvaluate },
|
{ "evaluate", l_lovrCurveEvaluate },
|
||||||
|
{ "getTangent", l_lovrCurveGetTangent },
|
||||||
{ "render", l_lovrCurveRender },
|
{ "render", l_lovrCurveRender },
|
||||||
{ "split", l_lovrCurveSplit },
|
{ "split", l_lovrCurveSplit },
|
||||||
{ "getPointCount", l_lovrCurveGetPointCount },
|
{ "getPointCount", l_lovrCurveGetPointCount },
|
||||||
|
|
|
@ -59,6 +59,15 @@ void lovrCurveEvaluate(Curve* curve, float t, vec3 p) {
|
||||||
evaluate(curve->points.data, curve->points.length / 3, t, p);
|
evaluate(curve->points.data, curve->points.length / 3, t, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lovrCurveGetTangent(Curve* curve, float t, vec3 p) {
|
||||||
|
float q[3];
|
||||||
|
int n = curve->points.length / 3;
|
||||||
|
evaluate(curve->points.data, n - 1, t, q);
|
||||||
|
evaluate(curve->points.data + 3, n - 1, t, p);
|
||||||
|
vec3_add(p, vec3_scale(q, -1));
|
||||||
|
vec3_normalize(p);
|
||||||
|
}
|
||||||
|
|
||||||
void lovrCurveRender(Curve* curve, float t1, float t2, vec3 points, int n) {
|
void lovrCurveRender(Curve* curve, float t1, float t2, vec3 points, int n) {
|
||||||
lovrAssert(curve->points.length >= 6, "Need at least 2 points to render a Curve");
|
lovrAssert(curve->points.length >= 6, "Need at least 2 points to render a Curve");
|
||||||
lovrAssert(t1 >= 0 && t2 <= 1, "Curve render interval must be within [0, 1]");
|
lovrAssert(t1 >= 0 && t2 <= 1, "Curve render interval must be within [0, 1]");
|
||||||
|
|
|
@ -10,6 +10,7 @@ typedef struct {
|
||||||
Curve* lovrCurveCreate(int sizeHint);
|
Curve* lovrCurveCreate(int sizeHint);
|
||||||
void lovrCurveDestroy(void* ref);
|
void lovrCurveDestroy(void* ref);
|
||||||
void lovrCurveEvaluate(Curve* curve, float t, vec3 point);
|
void lovrCurveEvaluate(Curve* curve, float t, vec3 point);
|
||||||
|
void lovrCurveGetTangent(Curve* curve, float t, vec3 point);
|
||||||
void lovrCurveRender(Curve* curve, float t1, float t2, vec3 points, int n);
|
void lovrCurveRender(Curve* curve, float t1, float t2, vec3 points, int n);
|
||||||
Curve* lovrCurveSplit(Curve* curve, float t1, float t2);
|
Curve* lovrCurveSplit(Curve* curve, float t1, float t2);
|
||||||
int lovrCurveGetPointCount(Curve* curve);
|
int lovrCurveGetPointCount(Curve* curve);
|
||||||
|
|
Loading…
Reference in New Issue