Panda3D
Loading...
Searching...
No Matches
nurbsCurveResult.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 nurbsCurveResult.I
10 * @author drose
11 * @date 2002-12-04
12 */
13
14/**
15 *
16 */
17INLINE NurbsCurveResult::
18~NurbsCurveResult() {
19}
20
21/**
22 * Returns the first legal value of t on the curve. Usually this is 0.0.
23 */
24INLINE PN_stdfloat NurbsCurveResult::
25get_start_t() const {
26 return _basis.get_start_t();
27}
28
29/**
30 * Returns the last legal value of t on the curve.
31 */
32INLINE PN_stdfloat NurbsCurveResult::
33get_end_t() const {
34 return _basis.get_end_t();
35}
36
37/**
38 * Computes the point on the curve corresponding to the indicated value in
39 * parametric time. Returns true if the t value is valid, false otherwise.
40 */
42eval_point(PN_stdfloat t, LVecBase3 &point) {
43 int segment = find_segment(t);
44 if (segment == -1) {
45 return false;
46 }
47
48 eval_segment_point(segment, _basis.scale_t(segment, t), point);
49 return true;
50}
51
52/**
53 * Computes the tangent to the curve at the indicated point in parametric
54 * time. This tangent vector will not necessarily be normalized, and could be
55 * zero. See also eval_point().
56 */
58eval_tangent(PN_stdfloat t, LVecBase3 &tangent) {
59 int segment = find_segment(t);
60 if (segment == -1) {
61 return false;
62 }
63
64 eval_segment_tangent(segment, _basis.scale_t(segment, t), tangent);
65 return true;
66}
67
68/**
69 * Evaluates the curve in n-dimensional space according to the extended
70 * vertices associated with the curve in the indicated dimension.
71 */
72INLINE PN_stdfloat NurbsCurveResult::
73eval_extended_point(PN_stdfloat t, int d) {
74 int segment = find_segment(t);
75 if (segment == -1) {
76 return 0.0f;
77 }
78
79 return eval_segment_extended_point(segment, _basis.scale_t(segment, t), d);
80}
81
82/**
83 * Simultaneously performs eval_extended_point on a contiguous sequence of
84 * dimensions. The dimensions evaluated are d through (d + num_values - 1);
85 * the results are filled into the num_values elements in the indicated result
86 * array.
87 */
89eval_extended_points(PN_stdfloat t, int d, PN_stdfloat result[], int num_values) {
90 int segment = find_segment(t);
91 if (segment == -1) {
92 return false;
93 }
94
95 eval_segment_extended_points(segment, _basis.scale_t(segment, t), d,
96 result, num_values);
97 return true;
98}
99
100/**
101 * Returns the number of piecewise continuous segments within the curve. This
102 * number is usually not important unless you plan to call
103 * eval_segment_point().
104 */
106get_num_segments() const {
107 return _basis.get_num_segments();
108}
109
110/**
111 * Accepts a t value in the range [0, 1], and assumed to be relative to the
112 * indicated segment (as in eval_segment_point()), and returns the
113 * corresponding t value in the entire curve (as in eval_point()).
114 */
115INLINE PN_stdfloat NurbsCurveResult::
116get_segment_t(int segment, PN_stdfloat t) const {
117 return t * (_basis.get_to(segment) - _basis.get_from(segment)) + _basis.get_from(segment);
118}
119
120/**
121 * Returns the number of sample points generated by the previous call to
122 * adaptive_sample().
123 */
124INLINE int NurbsCurveResult::
125get_num_samples() const {
126 return (int)_adaptive_result.size();
127}
128
129/**
130 * Returns the t value of the nth sample point generated by the previous call
131 * to adaptive_sample().
132 */
133INLINE PN_stdfloat NurbsCurveResult::
134get_sample_t(int n) const {
135 nassertr(n >= 0 && n < (int)_adaptive_result.size(), 0.0f);
136 return _adaptive_result[n]._t;
137}
138
139/**
140 * Returns the point on the curve of the nth sample point generated by the
141 * previous call to adaptive_sample().
142 *
143 * For tangents, or extended points, you should use get_sample_t() and pass it
144 * into eval_tangent() or eval_extended_point().
145 */
146INLINE const LPoint3 &NurbsCurveResult::
147get_sample_point(int n) const {
148 nassertr(n >= 0 && n < (int)_adaptive_result.size(), LPoint3::zero());
149 return _adaptive_result[n]._point;
150}
151
152/**
153 * Accepts a t value in the range [0, 1], and assumed to be relative to the
154 * indicated segment (as in eval_segment_point()), and returns the
155 * corresponding t value in the entire curve (as in eval_point()).
156 */
157INLINE NurbsCurveResult::AdaptiveSample::
158AdaptiveSample(PN_stdfloat t, const LPoint3 &point) :
159 _t(t),
160 _point(point)
161{
162}
int get_num_segments() const
Returns the number of piecewise continuous segments in the curve.
PN_stdfloat get_start_t() const
Returns the first legal value of t on the curve.
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.
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].
void eval_segment_tangent(int segment, PN_stdfloat t, LVecBase3 &tangent) const
As eval_segment_point, but computes the tangent to the curve at the indicated point.
bool eval_tangent(PN_stdfloat t, LVecBase3 &tangent)
Computes the tangent to the curve at the indicated point in parametric time.
PN_stdfloat get_segment_t(int segment, PN_stdfloat t) const
Accepts a t value in the range [0, 1], and assumed to be relative to the indicated segment (as in eva...
get_sample_point
Returns the point on the curve of the nth sample point generated by the previous call to adaptive_sam...
int get_num_segments() const
Returns the number of piecewise continuous segments within the curve.
get_sample_t
Returns the t value of the nth sample point generated by the previous call to adaptive_sample().
PN_stdfloat get_end_t() const
Returns the last legal value of t on the curve.
bool eval_point(PN_stdfloat t, LVecBase3 &point)
Computes the point on the curve corresponding to the indicated value in parametric time.
PN_stdfloat get_start_t() const
Returns the first legal value of t on the curve.
PN_stdfloat eval_extended_point(PN_stdfloat t, int d)
Evaluates the curve in n-dimensional space according to the extended vertices associated with the cur...
void eval_segment_extended_points(int segment, PN_stdfloat t, int d, PN_stdfloat result[], int num_values) const
Simultaneously performs eval_extended_point on a contiguous sequence of dimensions.
void eval_segment_point(int segment, PN_stdfloat t, LVecBase3 &point) const
Evaluates the point on the curve corresponding to the indicated value in parametric time within the i...
PN_stdfloat eval_segment_extended_point(int segment, PN_stdfloat t, int d) const
Evaluates the curve in n-dimensional space according to the extended vertices associated with the cur...
bool eval_extended_points(PN_stdfloat t, int d, PN_stdfloat result[], int num_values)
Simultaneously performs eval_extended_point on a contiguous sequence of dimensions.
get_num_samples
Returns the number of sample points generated by the previous call to adaptive_sample().