Skip to content

Instantly share code, notes, and snippets.

@yiwenl
Last active Jun 29, 2022
Embed
What would you like to do?
Bezier Curve with gl-matrix
import { vec2 } from "gl-matrix";
export const bezier = (mPoints, t) => {
if (mPoints.length === 2) {
const p = vec2.create();
vec2.lerp(p, mPoints[0], mPoints[1], t);
return p;
}
const a = [];
for (let i = 0; i < mPoints.length - 1; i++) {
const p = vec2.create();
vec2.lerp(p, mPoints[i], mPoints[i + 1], t);
a.push(p);
}
return bezier(a, t);
};
import { vec3 } from "gl-matrix";
export const bezier = (mPoints, t) => {
if (mPoints.length === 2) {
const p = vec3.create();
vec3.lerp(p, mPoints[0], mPoints[1], t);
return p;
}
const a = [];
for (let i = 0; i < mPoints.length - 1; i++) {
const p = vec3.create();
vec3.lerp(p, mPoints[i], mPoints[i + 1], t);
a.push(p);
}
return bezier(a, t);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment