34 PN_stdfloat scaled_knots[8];
35 PN_stdfloat min_k = knots[_order - 1];
36 PN_stdfloat max_k = knots[_order];
38 nassertv(min_k != max_k);
39 for (i = 0; i < _order + _order; i++) {
40 scaled_knots[i] = (knots[i] - min_k) / (max_k - min_k);
44 segment._vertex_index = vertex_index;
45 segment._from = min_k;
48 for (i = 0; i < _order; i++) {
49 LVecBase4 b = nurbs_blending_function(_order, i, _order, scaled_knots);
50 segment._basis.set_col(i, b);
53 for (i = _order; i < 4; i++) {
54 segment._basis.set_col(i, LVecBase4::zero());
57 _segments.push_back(segment);
65 Segments::iterator si;
66 for (si = _segments.begin(); si != _segments.end(); ++si) {
67 (*si)._basis.transpose_in_place();
75 LVecBase4 NurbsBasisVector::
76 nurbs_blending_function(
int order,
int i,
int j,
const PN_stdfloat knots[]) {
81 if (i == order - 1 && knots[i] < knots[i + 1]) {
82 r.set(0.0f, 0.0f, 0.0f, 1.0f);
84 r.set(0.0f, 0.0f, 0.0f, 0.0f);
88 LVecBase4 bi0 = nurbs_blending_function(order, i, j - 1, knots);
89 LVecBase4 bi1 = nurbs_blending_function(order, i + 1, j - 1, knots);
91 PN_stdfloat d0 = knots[i + j - 1] - knots[i];
92 PN_stdfloat d1 = knots[i + j] - knots[i + 1];
97 r = bi0 / d0 - bi1 / d1;
102 }
else if (d1 != 0.0f) {
106 r.set(0.0f, 0.0f, 0.0f, 0.0f);
118 r += bi0 * (- knots[i] / d0) + bi1 * (knots[i + j] / d1);
120 r += bi0 * (- knots[i] / d0);
123 }
else if (d1 != 0.0f) {
124 r += bi1 * (knots[i + j] / d1);
void transpose()
Transposes the basis matrices stored in the vector.
void append_segment(int vertex_index, const PN_stdfloat knots[])
Computes a NURBS basis for one segment of the curve and appends it to the set of basis matrices.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear(int order)
Removes all the segments from the curve.