Panda3D

nurbsCurveResult.I

00001 // Filename: nurbsCurveResult.I
00002 // Created by:  drose (04Dec02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: NurbsCurveResult::Destructor
00018 //       Access: Published
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE NurbsCurveResult::
00022 ~NurbsCurveResult() {
00023 }
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: NurbsCurveResult::get_start_t
00027 //       Access: Published
00028 //  Description: Returns the first legal value of t on the curve.
00029 //               Usually this is 0.0.
00030 ////////////////////////////////////////////////////////////////////
00031 INLINE PN_stdfloat NurbsCurveResult::
00032 get_start_t() const {
00033   return _basis.get_start_t();
00034 }
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: NurbsCurveResult::get_end_t
00038 //       Access: Published
00039 //  Description: Returns the last legal value of t on the curve.
00040 ////////////////////////////////////////////////////////////////////
00041 INLINE PN_stdfloat NurbsCurveResult::
00042 get_end_t() const {
00043   return _basis.get_end_t();
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: NurbsCurveResult::eval_point
00048 //       Access: Published
00049 //  Description: Computes the point on the curve corresponding to the
00050 //               indicated value in parametric time.  Returns true if
00051 //               the t value is valid, false otherwise.
00052 ////////////////////////////////////////////////////////////////////
00053 INLINE bool NurbsCurveResult::
00054 eval_point(PN_stdfloat t, LVecBase3 &point) {
00055   int segment = find_segment(t);
00056   if (segment == -1) {
00057     return false;
00058   }
00059 
00060   eval_segment_point(segment, _basis.scale_t(segment, t), point);
00061   return true;
00062 }
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: NurbsCurveResult::eval_tangent
00066 //       Access: Published
00067 //  Description: Computes the tangent to the curve at the indicated
00068 //               point in parametric time.  This tangent vector will
00069 //               not necessarily be normalized, and could be zero.
00070 //               See also eval_point().
00071 ////////////////////////////////////////////////////////////////////
00072 INLINE bool NurbsCurveResult::
00073 eval_tangent(PN_stdfloat t, LVecBase3 &tangent) {
00074   int segment = find_segment(t);
00075   if (segment == -1) {
00076     return false;
00077   }
00078 
00079   eval_segment_tangent(segment, _basis.scale_t(segment, t), tangent);
00080   return true;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: NurbsCurveResult::eval_extended_point
00085 //       Access: Published
00086 //  Description: Evaluates the curve in n-dimensional space according
00087 //               to the extended vertices associated with the curve in
00088 //               the indicated dimension.
00089 ////////////////////////////////////////////////////////////////////
00090 INLINE PN_stdfloat NurbsCurveResult::
00091 eval_extended_point(PN_stdfloat t, int d) {
00092   int segment = find_segment(t);
00093   if (segment == -1) {
00094     return 0.0f;
00095   }
00096 
00097   return eval_segment_extended_point(segment, _basis.scale_t(segment, t), d);
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////
00101 //     Function: NurbsCurveResult::eval_extended_points
00102 //       Access: Published
00103 //  Description: Simultaneously performs eval_extended_point on a
00104 //               contiguous sequence of dimensions.  The dimensions
00105 //               evaluated are d through (d + num_values - 1); the
00106 //               results are filled into the num_values elements in
00107 //               the indicated result array.
00108 ////////////////////////////////////////////////////////////////////
00109 INLINE bool NurbsCurveResult::
00110 eval_extended_points(PN_stdfloat t, int d, PN_stdfloat result[], int num_values) {
00111   int segment = find_segment(t);
00112   if (segment == -1) {
00113     return false;
00114   }
00115 
00116   eval_segment_extended_points(segment, _basis.scale_t(segment, t), d,
00117                                result, num_values);
00118   return true;
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////
00122 //     Function: NurbsCurveResult::get_num_segments
00123 //       Access: Published
00124 //  Description: Returns the number of piecewise continuous segments
00125 //               within the curve.  This number is usually not
00126 //               important unless you plan to call
00127 //               eval_segment_point().
00128 ////////////////////////////////////////////////////////////////////
00129 INLINE int NurbsCurveResult::
00130 get_num_segments() const {
00131   return _basis.get_num_segments();
00132 }
00133 
00134 ////////////////////////////////////////////////////////////////////
00135 //     Function: NurbsCurveResult::get_segment_t
00136 //       Access: Published
00137 //  Description: Accepts a t value in the range [0, 1], and assumed to
00138 //               be relative to the indicated segment (as in
00139 //               eval_segment_point()), and returns the corresponding
00140 //               t value in the entire curve (as in eval_point()).
00141 ////////////////////////////////////////////////////////////////////
00142 INLINE PN_stdfloat NurbsCurveResult::
00143 get_segment_t(int segment, PN_stdfloat t) const {
00144   return t * (_basis.get_to(segment) - _basis.get_from(segment)) + _basis.get_from(segment);
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: NurbsCurveResult::get_num_samples
00149 //       Access: Published
00150 //  Description: Returns the number of sample points generated by the
00151 //               previous call to adaptive_sample().
00152 ////////////////////////////////////////////////////////////////////
00153 INLINE int NurbsCurveResult::
00154 get_num_samples() const {
00155   return (int)_adaptive_result.size();
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: NurbsCurveResult::get_sample_t
00160 //       Access: Published
00161 //  Description: Returns the t value of the nth sample point generated
00162 //               by the previous call to adaptive_sample().
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE PN_stdfloat NurbsCurveResult::
00165 get_sample_t(int n) const {
00166   nassertr(n >= 0 && n < (int)_adaptive_result.size(), 0.0f);
00167   return _adaptive_result[n]._t;
00168 }
00169 
00170 ////////////////////////////////////////////////////////////////////
00171 //     Function: NurbsCurveResult::get_sample_point
00172 //       Access: Published
00173 //  Description: Returns the point on the curve of the nth sample
00174 //               point generated by the previous call to
00175 //               adaptive_sample().
00176 //
00177 //               For tangents, or extended points, you should use
00178 //               get_sample_t() and pass it into eval_tangent() or
00179 //               eval_extended_point().
00180 ////////////////////////////////////////////////////////////////////
00181 INLINE const LPoint3 &NurbsCurveResult::
00182 get_sample_point(int n) const {
00183   nassertr(n >= 0 && n < (int)_adaptive_result.size(), LPoint3::zero());
00184   return _adaptive_result[n]._point;
00185 }
00186 
00187 ////////////////////////////////////////////////////////////////////
00188 //     Function: NurbsCurveResult::get_segment_t
00189 //       Access: Public
00190 //  Description: Accepts a t value in the range [0, 1], and assumed to
00191 //               be relative to the indicated segment (as in
00192 //               eval_segment_point()), and returns the corresponding
00193 //               t value in the entire curve (as in eval_point()).
00194 ////////////////////////////////////////////////////////////////////
00195 INLINE NurbsCurveResult::AdaptiveSample::
00196 AdaptiveSample(PN_stdfloat t, const LPoint3 &point) :
00197   _t(t),
00198   _point(point)
00199 {
00200 }
00201 
 All Classes Functions Variables Enumerations