Panda3D
 All Classes Functions Variables Enumerations
nurbsBasisVector.I
1 // Filename: nurbsBasisVector.I
2 // Created by: drose (04Dec02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: NurbsBasisVector::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE NurbsBasisVector::
22 NurbsBasisVector() {
23  _order = 0;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: NurbsBasisVector::Destructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 INLINE NurbsBasisVector::
32 ~NurbsBasisVector() {
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: NurbsBasisVector::get_order
37 // Access: Public
38 // Description: Returns the order of the segments in the curve.
39 ////////////////////////////////////////////////////////////////////
40 INLINE int NurbsBasisVector::
41 get_order() const {
42  return _order;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: NurbsBasisVector::get_num_segments
47 // Access: Public
48 // Description: Returns the number of piecewise continuous segments
49 // in the curve.
50 ////////////////////////////////////////////////////////////////////
51 INLINE int NurbsBasisVector::
53  return _segments.size();
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: NurbsBasisVector::get_start_t
58 // Access: Public
59 // Description: Returns the first legal value of t on the curve.
60 // Usually this is 0.0.
61 ////////////////////////////////////////////////////////////////////
62 INLINE PN_stdfloat NurbsBasisVector::
63 get_start_t() const {
64  nassertr(!_segments.empty(), 0.0f);
65  return _segments.front()._from;
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: NurbsBasisVector::get_end_t
70 // Access: Public
71 // Description: Returns the last legal value of t on the curve.
72 ////////////////////////////////////////////////////////////////////
73 INLINE PN_stdfloat NurbsBasisVector::
74 get_end_t() const {
75  nassertr(!_segments.empty(), 0.0f);
76  return _segments.back()._to;
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: NurbsBasisVector::get_vertex_index
81 // Access: Public
82 // Description: Returns the vertex index of the nth segment. This is
83 // the index number of the first associated control
84 // vertex within the source NurbsCurveEvaluator object.
85 ////////////////////////////////////////////////////////////////////
86 INLINE int NurbsBasisVector::
87 get_vertex_index(int segment) const {
88  nassertr(segment >= 0 && segment < (int)_segments.size(), 0);
89  return _segments[segment]._vertex_index;
90 }
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: NurbsBasisVector::get_from
94 // Access: Public
95 // Description: Returns the t value of the beginning of this segment.
96 ////////////////////////////////////////////////////////////////////
97 INLINE PN_stdfloat NurbsBasisVector::
98 get_from(int segment) const {
99  nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f);
100  return _segments[segment]._from;
101 }
102 
103 ////////////////////////////////////////////////////////////////////
104 // Function: NurbsBasisVector::get_to
105 // Access: Public
106 // Description: Returns the t value of the end of this segment.
107 ////////////////////////////////////////////////////////////////////
108 INLINE PN_stdfloat NurbsBasisVector::
109 get_to(int segment) const {
110  nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f);
111  return _segments[segment]._to;
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: NurbsBasisVector::get_basis
116 // Access: Public
117 // Description: Returns the basis matrix associated with the nth
118 // segment. This is the pure matrix based on the knot
119 // vector over the segment; it does not depend on the
120 // control vertices.
121 ////////////////////////////////////////////////////////////////////
122 INLINE const LMatrix4 &NurbsBasisVector::
123 get_basis(int segment) const {
124  nassertr(segment >= 0 && segment < (int)_segments.size(), LMatrix4::ident_mat());
125  return _segments[segment]._basis;
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: NurbsBasisVector::scale_t
130 // Access: Public
131 // Description: Scales the value of t into the range [0, 1]
132 // corresponding to [from, to]. Returns the scaled
133 // value.
134 ////////////////////////////////////////////////////////////////////
135 INLINE PN_stdfloat NurbsBasisVector::
136 scale_t(int segment, PN_stdfloat t) const {
137  nassertr(segment >= 0 && segment < (int)_segments.size(), 0.0f);
138  PN_stdfloat from = _segments[segment]._from;
139  PN_stdfloat to = _segments[segment]._to;
140  t = (t - from) / (to - from);
141  return min(max(t, (PN_stdfloat)0.0), (PN_stdfloat)1.0);
142 }
static const LMatrix4f & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:903
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.
PN_stdfloat scale_t(int segment, PN_stdfloat t) const
Scales the value of t into the range [0, 1] corresponding to [from, to].
int get_order() const
Returns the order of the segments in the curve.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
PN_stdfloat get_start_t() const
Returns the first legal value of t on the curve.
const LMatrix4 & get_basis(int segment) const
Returns the basis matrix associated with the nth segment.
int get_vertex_index(int segment) const
Returns the vertex index of the nth segment.
PN_stdfloat get_end_t() const
Returns the last legal value of t on the curve.
PN_stdfloat get_to(int segment) const
Returns the t value of the end of this segment.