summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-10-20 22:04:34 -0700
committerKenneth Graunke <kenneth@whitecape.org>2010-10-20 22:04:34 -0700
commitc6fdaaa42dc9c9365c260cc606df10f88425d479 (patch)
tree17065db1040eb784f71a7bca7aecdc3a42b40b42
parent1d09c245ab5758e9db30553f206f72b9a55edf43 (diff)
Implement the bezier position function.
-rwxr-xr-xsrc/bezier.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/bezier.cpp b/src/bezier.cpp
index e3fa37d..6f42a30 100755
--- a/src/bezier.cpp
+++ b/src/bezier.cpp
@@ -21,14 +21,29 @@
* DEALINGS IN THE SOFTWARE.
*/
+#include <cmath>
#include "bezier.h"
+static float fact(float n)
+{
+ return n == 0 ? 1 : n * fact(n - 1);
+}
+
+/* The bezier basis function, assuming n = 3 */
+static float b(int i, float t)
+{
+ return 6/(fact(i) * fact(3 - i)) * powf(t, i) * powf(1 - t, 3 - i);
+}
+
GLUvec4
bezier_curve::position(float t) const
{
- /* FINISHME: Implement this function.
- */
GLUvec4 result(0.0, 0.0, 0.0, 0.0);
+ /* Note that n = 3. */
+ for (int i = 0; i < 4; i++) {
+ result += b(i, t) * p[i];
+ }
+
return result;
}