Panda3D
nurbsBasisVector.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file nurbsBasisVector.I
10  * @author drose
11  * @date 2002-12-04
12  */
13 
14 /**
15  *
16  */
17 INLINE NurbsBasisVector::
18 NurbsBasisVector() {
19  _order = 0;
20 }
21 
22 /**
23  *
24  */
25 INLINE NurbsBasisVector::
26 ~NurbsBasisVector() {
27 }
28 
29 /**
30  * Returns the order of the segments in the curve.
31  */
32 INLINE int NurbsBasisVector::
33 get_order() const {
34  return _order;
35 }
36 
37 /**
38  * Returns the number of piecewise continuous segments in the curve.
39  */
40 INLINE int NurbsBasisVector::
42  return _segments.size();
43 }
44 
45 /**
46  * Returns the first legal value of t on the curve. Usually this is 0.0.
47  */
48 INLINE PN_stdfloat NurbsBasisVector::
49 get_start_t() const {
50  nassertr(!_segments.empty(), 0.0f);
51  return _segments.front()._from;
52 }
53 
54 /**
55  * Returns the last legal value of t on the curve.
56  */
57 INLINE PN_stdfloat NurbsBasisVector::
58 get_end_t() const {
59  nassertr(!_segments.empty(), 0.0f);
60  return _segments.back()._to;
61 }
62 
63 /**
64  * Returns the vertex index of the nth segment. This is the index number of
65  * the first associated control vertex within the source NurbsCurveEvaluator
66  * object.
67  */
68 INLINE int NurbsBasisVector::
69 get_vertex_index(int segment) const {
70  nassertr(segment >= 0 && segment < (int)_segments.size(), 0);
71  return _segments[segment]._vertex_index;
72 }
73 
74 /**
75  * Returns the t value of the beginning of this segment.
76  */
77 INLINE PN_stdfloat NurbsBasisVector::
78 get_from(int segment) const {
79  nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f);
80  return _segments[segment]._from;
81 }
82 
83 /**
84  * Returns the t value of the end of this segment.
85  */
86 INLINE PN_stdfloat NurbsBasisVector::
87 get_to(int segment) const {
88  nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f);
89  return _segments[segment]._to;
90 }
91 
92 /**
93  * Returns the basis matrix associated with the nth segment. This is the pure
94  * matrix based on the knot vector over the segment; it does not depend on the
95  * control vertices.
96  */
97 INLINE const LMatrix4 &NurbsBasisVector::
98 get_basis(int segment) const {
99  nassertr(segment >= 0 && segment < (int)_segments.size(), LMatrix4::ident_mat());
100  return _segments[segment]._basis;
101 }
102 
103 /**
104  * Scales the value of t into the range [0, 1] corresponding to [from, to].
105  * Returns the scaled value.
106  */
107 INLINE PN_stdfloat NurbsBasisVector::
108 scale_t(int segment, PN_stdfloat t) const {
109  nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f);
110  PN_stdfloat from = _segments[segment]._from;
111  PN_stdfloat to = _segments[segment]._to;
112  t = (t - from) / (to - from);
113  return std::min(std::max(t, (PN_stdfloat)0.0), (PN_stdfloat)1.0);
114 }
const LMatrix4 & get_basis(int segment) const
Returns the basis matrix associated with the nth segment.
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
PN_stdfloat get_from(int segment) const
Returns the t value of the beginning of this segment.
int get_vertex_index(int segment) const
Returns the vertex index of the nth segment.
PN_stdfloat get_to(int segment) const
Returns the t value of the end of this segment.
PN_stdfloat get_start_t() const
Returns the first legal value of t on the curve.
int get_order() const
Returns the order of the segments in the curve.
PN_stdfloat scale_t(int segment, PN_stdfloat t) const
Scales the value of t into the range [0, 1] corresponding to [from, to].
PN_stdfloat get_end_t() const
Returns the last legal value of t on the curve.