Created
December 30, 2011 16:34
-
-
Save fjolnir/1540537 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static vec3_t *bezier_getPoints(bezier_t curve, float dirChangeThreshold, int *outCount) | |
{ | |
dirChangeThreshold /= 100.0f; | |
int capacity = 32; | |
int count = 0; | |
float t = 0.0f; | |
float interval = 0.05; | |
vec3_t *out = malloc(sizeof(vec3_t)*capacity); | |
out[count++] = bezier_getPoint(curve, t); | |
vec3_t lastTangent = vec3_normalize(bezier_firstDerivative(curve, t)); | |
vec3_t tangent; | |
t += interval; | |
while(t < 1.0f) { | |
tangent = vec3_normalize(bezier_firstDerivative(curve, t)); | |
if(vec3_dot(tangent, lastTangent) < 1.0f - dirChangeThreshold) { | |
if(count+1 > capacity) { | |
capacity += 16; | |
out = realloc(out, sizeof(vec3_t)*(count+1)); | |
} | |
out[count++] = bezier_getPoint(curve, t); | |
} | |
lastTangent = tangent; | |
t += interval; | |
} | |
out[count++] = bezier_getPoint(curve, 1.0f); | |
if(count < capacity) out = realloc(out, sizeof(vec3_t)*count); | |
if(outCount) *outCount = count; | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment