Panda3D
 All Classes Functions Variables Enumerations
eggMesherStrip.I
00001 // Filename: eggMesherStrip.I
00002 // Created by:  drose (13Mar05)
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: EggMesherStrip::Copy Constructor
00018 //       Access: Public
00019 //  Description: 
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE EggMesherStrip::
00022 EggMesherStrip(const EggMesherStrip &copy) :
00023   _prims(copy._prims),
00024   _edges(copy._edges),
00025   _verts(copy._verts),
00026   _type(copy._type),
00027   _index(copy._index),
00028   _status(copy._status),
00029   _planar(copy._planar),
00030   _plane_normal(copy._plane_normal),
00031   _plane_offset(copy._plane_offset),
00032   _row_id(copy._row_id),
00033   _flat_shaded(copy._flat_shaded)
00034 {
00035 }
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //     Function: EggMesherStrip::is_coplanar_with
00039 //       Access: Public
00040 //  Description: Returns true if the strip and the other strip are
00041 //               coplanar, within the indicated threshold.  See
00042 //               coplanarity().
00043 ////////////////////////////////////////////////////////////////////
00044 INLINE bool EggMesherStrip::
00045 is_coplanar_with(const EggMesherStrip &other, PN_stdfloat threshold) const {
00046   return (coplanarity(other) <= threshold);
00047 }
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: EggMesherStrip::coplanarity
00051 //       Access: Public
00052 //  Description: Returns the degree to which the two strips are
00053 //               coplanar.  0.0 is exactly coplanar; numbers somewhat
00054 //               larger than zero indicate less coplanar.  1.0 is
00055 //               at right angles; 2.0 is exactly backfacing.  If
00056 //               either strip is not itself planar, 3.0 is returned.
00057 ////////////////////////////////////////////////////////////////////
00058 INLINE PN_stdfloat EggMesherStrip::
00059 coplanarity(const EggMesherStrip &other) const {
00060   if (_planar && other._planar) {
00061     return 1.0 - dot(_plane_normal, other._plane_normal);
00062   }
00063   return 3.0;
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: EggMesherStrip::type_category
00068 //       Access: Public
00069 //  Description: Returns an integer which gives a heuristic about the
00070 //               similarity of different strip types.  In general,
00071 //               closer numbers are more similar.
00072 ////////////////////////////////////////////////////////////////////
00073 INLINE int EggMesherStrip::
00074 type_category() const {
00075   switch (_type) {
00076   case PT_tri:
00077     return 1;
00078 
00079   case PT_tristrip:
00080     return 2;
00081 
00082   case PT_quad:
00083   case PT_quadstrip:
00084     return 5;
00085 
00086   default:
00087     return 10;
00088   }
00089 }
00090 
00091 
00092 ////////////////////////////////////////////////////////////////////
00093 //     Function: EggMesherStrip::rotate_forward
00094 //       Access: Public
00095 //  Description: Rotates a triangle or quad by bringing its first
00096 //               vertex to the back.
00097 ////////////////////////////////////////////////////////////////////
00098 INLINE void EggMesherStrip::
00099 rotate_forward() {
00100   _verts.push_back(_verts.front());
00101   _verts.pop_front();
00102 }
00103 
00104 ////////////////////////////////////////////////////////////////////
00105 //     Function: EggMesherStrip::rotate_back
00106 //       Access: Public
00107 //  Description: Rotates a triangle or quad by bringing its last
00108 //               vertex to the front.
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE void EggMesherStrip::
00111 rotate_back() {
00112   _verts.push_front(_verts.back());
00113   _verts.pop_back();
00114 }
00115 
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: EggMesherStrip::get_head_edge
00119 //       Access: Public
00120 //  Description: Returns an EggMesherEdge which represents the leading
00121 //               edge in the quadstrip or tristrip.  This
00122 //               EggMesherEdge will not have pointer equality with any
00123 //               shared EggMesherEdge.
00124 ////////////////////////////////////////////////////////////////////
00125 INLINE EggMesherEdge EggMesherStrip::
00126 get_head_edge() const {
00127   Verts::const_iterator vi = _verts.begin();
00128   nassertr(vi != _verts.end(), EggMesherEdge(0, 0));
00129   ++vi;
00130   return EggMesherEdge(_verts.front(), *vi);
00131 }
00132 
00133 ////////////////////////////////////////////////////////////////////
00134 //     Function: EggMesherStrip::get_tail_edge
00135 //       Access: Public
00136 //  Description: Returns an EggMesherEdge which represents the
00137 //               trailing edge in the quadstrip or tristrip.  This
00138 //               EggMesherEdge will not have pointer equality with any
00139 //               shared EggMesherEdge.
00140 ////////////////////////////////////////////////////////////////////
00141 INLINE EggMesherEdge EggMesherStrip::
00142 get_tail_edge() const {
00143   Verts::const_reverse_iterator vi = _verts.rbegin();
00144   nassertr(vi != _verts.rend(), EggMesherEdge(0, 0));
00145   ++vi;
00146   return EggMesherEdge(*vi, _verts.back());
00147 }
00148 
00149 ////////////////////////////////////////////////////////////////////
00150 //     Function: EggMesherStrip::operator ==
00151 //       Access: Public
00152 //  Description: Defines equality for strips.  This actually tests
00153 //               only pointer equality; it's used only when removing a
00154 //               strip from the list.
00155 ////////////////////////////////////////////////////////////////////
00156 INLINE bool EggMesherStrip::
00157 operator == (const EggMesherStrip &other) const {
00158   return this == &other;
00159 }
00160 
00161 ////////////////////////////////////////////////////////////////////
00162 //     Function: EggMesherStrip::operator !=
00163 //       Access: Public
00164 //  Description:
00165 ////////////////////////////////////////////////////////////////////
00166 INLINE bool EggMesherStrip::
00167 operator != (const EggMesherStrip &other) const {
00168   return !operator == (other);
00169 }
 All Classes Functions Variables Enumerations