20 NurbsCurveEvaluator() {
30 ~NurbsCurveEvaluator() {
41 _vertices.reserve(num_vertices);
43 for (
int i = 0; i < num_vertices; i++) {
58 nassertr(i >= 0 && i < (
int)_vertices.size(), empty_node_path);
60 return _vertices[i].get_space(rel_to);
71 nassertv(i >= 0 && i < (
int)_vertices.size());
74 for (
int n = 0; n < num_values; n++) {
75 vertex.set_extended_vertex(d + n, values[n]);
89 nassertv(i >= 0 && i < (
int)_knots.size());
101 nassertr(i >= 0 && i < (
int)_knots.size(), 0.0f);
116 double min_value = _knots[_order - 1];
118 double range = (max_value - min_value);
120 for (Knots::iterator ki = _knots.begin(); ki != _knots.end(); ++ki) {
121 (*ki) = ((*ki) - min_value) / range;
133 evaluate(
const NodePath &rel_to)
const {
140 get_vertices(vecs, rel_to);
145 (
int)_vertices.size());
155 evaluate(
const NodePath &rel_to,
const LMatrix4 &mat)
const {
162 get_vertices(vecs, rel_to);
165 Vert4Array::iterator vi;
166 for (vi = vecs.begin(); vi != vecs.end(); ++vi) {
173 (
int)_vertices.size());
179 void NurbsCurveEvaluator::
180 output(std::ostream &out)
const {
190 void NurbsCurveEvaluator::
191 get_vertices(NurbsCurveEvaluator::Vert4Array &verts,
const NodePath &rel_to)
const {
192 int num_vertices = (int)_vertices.size();
193 verts.reserve(verts.size() + num_vertices);
195 for (vi = 0; vi < num_vertices; vi++) {
205 void NurbsCurveEvaluator::
207 int num_vertices = (int)_vertices.size();
208 verts.reserve(verts.size() + num_vertices);
210 for (vi = 0; vi < num_vertices; vi++) {
213 if (vertex[3] == 0.0) {
214 verts.push_back(LPoint3(vertex[0], vertex[1], vertex[2]));
216 LPoint3 v3(vertex[0] / vertex[3], vertex[1] / vertex[3], vertex[2] / vertex[3]);
225 void NurbsCurveEvaluator::
229 _knots.reserve(num_knots);
231 PN_stdfloat value = 0.0f;
235 _knots.push_back(value);
238 while (i < num_knots - _order) {
240 _knots.push_back(value);
244 while (i < num_knots) {
245 _knots.push_back(value);
249 _knots_dirty =
false;
255 void NurbsCurveEvaluator::
261 _basis.
clear(_order);
262 if ((
int)_vertices.size() > _order - 1) {
263 int min_knot = _order;
264 int max_knot = (int)_vertices.size();
266 for (
int i = min_knot; i <= max_knot; i++) {
267 nassertv(i - 1 >= 0 && i < (
int)_knots.size());
268 if (_knots[i - 1] < _knots[i]) {
275 _basis_dirty =
false;
void set_knot(int i, PN_stdfloat knot)
Sets the value of the nth knot.
get_num_knots
Returns the number of knot values in the curve.
void reset(int num_vertices)
Resets all the vertices and knots to their default values, and sets the curve up with the indicated n...
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.
This class is an abstraction for evaluating NURBS curves.
get_vertex
Returns the nth control vertex of the curve, relative to its indicated coordinate space.
NodePath get_vertex_space(int i, const NodePath &rel_to) const
Returns the coordinate space of the nth control vertex of the curve, expressed as a NodePath.
This represents a single control vertex in a NurbsEvaluator.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void clear(int order)
Removes all the segments from the curve.
get_knot
Returns the value of the nth knot.
void normalize_knots()
Normalizes the knot sequence so that the parametric range of the curve is 0
get_num_vertices
Returns the number of control vertices in the curve.
The result of a NurbsCurveEvaluator.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
PT(NurbsCurveResult) NurbsCurveEvaluator
Returns a NurbsCurveResult object that represents the result of applying the knots to all of the curr...
void set_extended_vertices(int i, int d, const PN_stdfloat values[], int num_values)
Simultaneously sets several extended values in the slots d through (d + num_values - 1) from the num_...