00001 // Filename: builderVertexTempl.I 00002 // Created by: drose (11Sep97) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: BuilderVertexTempl::Constructor 00022 // Access: Public 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 template <class VT, class NT, class TT, class CT> 00026 INLINE BuilderVertexTempl<VT, NT, TT, CT>:: 00027 BuilderVertexTempl() { 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: BuilderVertexTempl::Constructor (with VType) 00032 // Access: Public 00033 // Description: Initializes the vertex coordinate with an initial 00034 // value. A handy constructor. 00035 //////////////////////////////////////////////////////////////////// 00036 template <class VT, class NT, class TT, class CT> 00037 INLINE BuilderVertexTempl<VT, NT, TT, CT>:: 00038 BuilderVertexTempl(const VType &c) { 00039 set_coord(c); 00040 } 00041 00042 //////////////////////////////////////////////////////////////////// 00043 // Function: BuilderVertexTempl::Copy constructor 00044 // Access: Public 00045 // Description: 00046 //////////////////////////////////////////////////////////////////// 00047 template <class VT, class NT, class TT, class CT> 00048 INLINE BuilderVertexTempl<VT, NT, TT, CT>:: 00049 BuilderVertexTempl(const BuilderVertexTempl ©) { 00050 (*this) = copy; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: BuilderVertexTempl::Copy assignment operator 00055 // Access: Public 00056 // Description: 00057 //////////////////////////////////////////////////////////////////// 00058 template <class VT, class NT, class TT, class CT> 00059 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00060 operator = (const BuilderVertexTempl<VT, NT, TT, CT> ©) { 00061 BuilderAttribTempl<VT, NT, TT, CT>::operator = (copy); 00062 _coord = copy._coord; 00063 _texcoord = copy._texcoord; 00064 _pixel_size = copy._pixel_size; 00065 00066 return *this; 00067 } 00068 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: BuilderVertexTempl::is_valid 00072 // Access: Public 00073 // Description: Returns true if the vertex is valid, i.e. if it has a 00074 // vertex coordinate. 00075 //////////////////////////////////////////////////////////////////// 00076 template <class VT, class NT, class TT, class CT> 00077 INLINE bool BuilderVertexTempl<VT, NT, TT, CT>:: 00078 is_valid() const { 00079 return has_coord(); 00080 } 00081 00082 00083 //////////////////////////////////////////////////////////////////// 00084 // Function: BuilderVertexTempl::clear 00085 // Access: Public 00086 // Description: Resets the vertex to its initial, empty state. 00087 //////////////////////////////////////////////////////////////////// 00088 template <class VT, class NT, class TT, class CT> 00089 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00090 clear() { 00091 BuilderAttribTempl<VT, NT, TT, CT>::clear(); 00092 return *this; 00093 } 00094 00095 00096 //////////////////////////////////////////////////////////////////// 00097 // Function: BuilderVertexTempl::has_coord 00098 // Access: Public 00099 // Description: Returns true if the vertex has a vertex coordinate. 00100 //////////////////////////////////////////////////////////////////// 00101 template <class VT, class NT, class TT, class CT> 00102 INLINE bool BuilderVertexTempl<VT, NT, TT, CT>:: 00103 has_coord() const { 00104 return _flags & BAF_coord; 00105 } 00106 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: BuilderVertexTempl::get_coord 00110 // Access: Public 00111 // Description: Returns the vertex's coordinate. It is an error to 00112 // call this without first verifying that has_coord() is 00113 // true. 00114 //////////////////////////////////////////////////////////////////// 00115 template <class VT, class NT, class TT, class CT> 00116 INLINE TYPENAME BuilderVertexTempl<VT, NT, TT, CT>::VType BuilderVertexTempl<VT, NT, TT, CT>:: 00117 get_coord() const { 00118 nassertr(has_coord(), _coord); 00119 return _coord; 00120 } 00121 00122 00123 //////////////////////////////////////////////////////////////////// 00124 // Function: BuilderVertexTempl::set_coord 00125 // Access: Public 00126 // Description: Resets the vertex's coordinate. 00127 //////////////////////////////////////////////////////////////////// 00128 template <class VT, class NT, class TT, class CT> 00129 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00130 set_coord(const VType &c) { 00131 _flags |= BAF_coord; 00132 _coord = c; 00133 return *this; 00134 } 00135 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: BuilderVertexTempl::set_normal 00139 // Access: Public 00140 // Description: Resets the vertex's normal. This is overridden from 00141 // BuilderAttrib just so we can typecast the return 00142 // value to BuilderVertex. The other functions, 00143 // has_normal() and get_normal(), are inherited 00144 // untouched from BuilderAttrib. 00145 //////////////////////////////////////////////////////////////////// 00146 template <class VT, class NT, class TT, class CT> 00147 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00148 set_normal(const NType &n) { 00149 BuilderAttribTempl<VT, NT, TT, CT>::set_normal(n); 00150 return *this; 00151 } 00152 00153 //////////////////////////////////////////////////////////////////// 00154 // Function: BuilderVertexTempl::clear_normal 00155 // Access: Public 00156 // Description: Removes the vertex's normal. 00157 //////////////////////////////////////////////////////////////////// 00158 template <class VT, class NT, class TT, class CT> 00159 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00160 clear_normal() { 00161 BuilderAttribTempl<VT, NT, TT, CT>::clear_normal(); 00162 return *this; 00163 } 00164 00165 00166 //////////////////////////////////////////////////////////////////// 00167 // Function: BuilderVertexTempl::has_texcoord 00168 // Access: Public 00169 // Description: Returns true if the vertex has a texture coordinate. 00170 //////////////////////////////////////////////////////////////////// 00171 template <class VT, class NT, class TT, class CT> 00172 INLINE bool BuilderVertexTempl<VT, NT, TT, CT>:: 00173 has_texcoord() const { 00174 return (_flags & BAF_texcoord) != 0; 00175 } 00176 00177 00178 //////////////////////////////////////////////////////////////////// 00179 // Function: BuilderVertexTempl::set_texcoord 00180 // Access: Public 00181 // Description: Resets the vertex's texture coordinate. 00182 //////////////////////////////////////////////////////////////////// 00183 template <class VT, class NT, class TT, class CT> 00184 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00185 set_texcoord(const TType &t) { 00186 _flags |= BAF_texcoord; 00187 _texcoord = t; 00188 return *this; 00189 } 00190 00191 //////////////////////////////////////////////////////////////////// 00192 // Function: BuilderVertexTempl::clear_texcoord 00193 // Access: Public 00194 // Description: Removes the vertex's texcoord. 00195 //////////////////////////////////////////////////////////////////// 00196 template <class VT, class NT, class TT, class CT> 00197 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00198 clear_texcoord() { 00199 _flags &= ~BAF_texcoord; 00200 return *this; 00201 } 00202 00203 00204 //////////////////////////////////////////////////////////////////// 00205 // Function: BuilderVertexTempl::get_texcoord 00206 // Access: Public 00207 // Description: Returns the vertex's texture coordinate. It is an 00208 // error to call this without first verifying that 00209 // has_texcoord() is true. 00210 //////////////////////////////////////////////////////////////////// 00211 template <class VT, class NT, class TT, class CT> 00212 INLINE TYPENAME BuilderVertexTempl<VT, NT, TT, CT>::TType BuilderVertexTempl<VT, NT, TT, CT>:: 00213 get_texcoord() const { 00214 nassertr(has_texcoord(), _texcoord); 00215 return _texcoord; 00216 } 00217 00218 00219 //////////////////////////////////////////////////////////////////// 00220 // Function: BuilderVertexTempl::set_color 00221 // Access: Public 00222 // Description: Resets the vertex's color. This is overridden from 00223 // BuilderAttrib just so we can typecast the return 00224 // value to BuilderVertex. The other functions, 00225 // has_color() and get_color(), are inherited 00226 // untouched from BuilderAttrib. 00227 //////////////////////////////////////////////////////////////////// 00228 template <class VT, class NT, class TT, class CT> 00229 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00230 set_color(const CType &c) { 00231 BuilderAttribTempl<VT, NT, TT, CT>::set_color(c); 00232 return *this; 00233 } 00234 00235 //////////////////////////////////////////////////////////////////// 00236 // Function: BuilderVertexTempl::clear_color 00237 // Access: Public 00238 // Description: Removes the vertex's color. 00239 //////////////////////////////////////////////////////////////////// 00240 template <class VT, class NT, class TT, class CT> 00241 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00242 clear_color() { 00243 BuilderAttribTempl<VT, NT, TT, CT>::clear_color(); 00244 return *this; 00245 } 00246 00247 00248 //////////////////////////////////////////////////////////////////// 00249 // Function: BuilderVertexTempl::set_pixel_size 00250 // Access: Public 00251 // Description: Resets the vertex's pixel_size. This is overridden 00252 // from BuilderAttrib just so we can typecast the return 00253 // value to BuilderVertex. The other functions, 00254 // has_pixel_size() and get_pixel_size(), are inherited 00255 // untouched from BuilderAttrib. 00256 //////////////////////////////////////////////////////////////////// 00257 template <class VT, class NT, class TT, class CT> 00258 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00259 set_pixel_size(float s) { 00260 BuilderAttribTempl<VT, NT, TT, CT>::set_pixel_size(s); 00261 return *this; 00262 } 00263 00264 //////////////////////////////////////////////////////////////////// 00265 // Function: BuilderVertexTempl::clear_pixel_size 00266 // Access: Public 00267 // Description: Removes the vertex's pixel_size. 00268 //////////////////////////////////////////////////////////////////// 00269 template <class VT, class NT, class TT, class CT> 00270 INLINE BuilderVertexTempl<VT, NT, TT, CT> &BuilderVertexTempl<VT, NT, TT, CT>:: 00271 clear_pixel_size() { 00272 BuilderAttribTempl<VT, NT, TT, CT>::clear_pixel_size(); 00273 return *this; 00274 } 00275 00276 00277 //////////////////////////////////////////////////////////////////// 00278 // Function: BuilderVertexTempl::operator == 00279 // Access: Public 00280 // Description: Assigns an ordering to the vertices. This is used by 00281 // the Mesher to group identical vertices. This assumes 00282 // that all vertices in the locus of consideration will 00283 // share the same state: with or without normals, 00284 // texcoords, etc. 00285 //////////////////////////////////////////////////////////////////// 00286 template <class VT, class NT, class TT, class CT> 00287 INLINE bool BuilderVertexTempl<VT, NT, TT, CT>:: 00288 operator == (const BuilderVertexTempl<VT, NT, TT, CT> &other) const { 00289 return compare_to(other) == 0; 00290 } 00291 00292 //////////////////////////////////////////////////////////////////// 00293 // Function: BuilderVertexTempl::operator != 00294 // Access: Public 00295 // Description: Assigns an ordering to the vertices. This is used by 00296 // the Mesher to group identical vertices. This assumes 00297 // that all vertices in the locus of consideration will 00298 // share the same state: with or without normals, 00299 // texcoords, etc. 00300 //////////////////////////////////////////////////////////////////// 00301 template <class VT, class NT, class TT, class CT> 00302 INLINE bool BuilderVertexTempl<VT, NT, TT, CT>:: 00303 operator != (const BuilderVertexTempl<VT, NT, TT, CT> &other) const { 00304 return !operator == (other); 00305 } 00306 00307 //////////////////////////////////////////////////////////////////// 00308 // Function: BuilderVertexTempl::operator < 00309 // Access: Public 00310 // Description: Assigns an ordering to the vertices. This is used by 00311 // the Mesher to group identical vertices. This assumes 00312 // that all vertices to be meshed together must share 00313 // the same state: with or without normals, texcoords, 00314 // etc. 00315 //////////////////////////////////////////////////////////////////// 00316 template <class VT, class NT, class TT, class CT> 00317 INLINE bool BuilderVertexTempl<VT, NT, TT, CT>:: 00318 operator < (const BuilderVertexTempl<VT, NT, TT, CT> &other) const { 00319 return compare_to(other) < 0; 00320 } 00321 00322 //////////////////////////////////////////////////////////////////// 00323 // Function: BuilderVertexTempl::compare_to 00324 // Access: Public 00325 // Description: Returns a number less than zero if this vertex sorts 00326 // before the indicated vertex, greater than zero if it 00327 // sorts after, and zero if the vertices are equivalent. 00328 //////////////////////////////////////////////////////////////////// 00329 template <class VT, class NT, class TT, class CT> 00330 int BuilderVertexTempl<VT, NT, TT, CT>:: 00331 compare_to(const BuilderVertexTempl<VT, NT, TT, CT> &other) const { 00332 if (has_coord()) { 00333 int coord_compare = builder_compare(_coord, other._coord); 00334 if (coord_compare != 0) { 00335 return coord_compare; 00336 } 00337 } 00338 00339 if (has_texcoord()) { 00340 int texcoord_compare = builder_compare(_texcoord, other._texcoord); 00341 if (texcoord_compare != 0) { 00342 return texcoord_compare; 00343 } 00344 } 00345 00346 return BuilderAttribTempl<VT, NT, TT, CT>::compare_to(other); 00347 } 00348 00349 //////////////////////////////////////////////////////////////////// 00350 // Function: BuilderVertexTempl::output 00351 // Access: Public 00352 // Description: Formats the vertex for output in some sensible way. 00353 //////////////////////////////////////////////////////////////////// 00354 template <class VT, class NT, class TT, class CT> 00355 ostream &BuilderVertexTempl<VT, NT, TT, CT>:: 00356 output(ostream &out) const { 00357 if (this!=NULL) { 00358 if (has_coord()) { 00359 out << get_coord(); 00360 } 00361 00362 if (has_normal()) { 00363 out << " normal " << get_normal(); 00364 } 00365 00366 if (has_texcoord()) { 00367 out << " texcoord " << get_texcoord(); 00368 } 00369 00370 if (has_color()) { 00371 out << " color " << get_color(); 00372 } 00373 00374 if (has_pixel_size()) { 00375 out << " pixel_size " << get_pixel_size(); 00376 } 00377 } 00378 return out; 00379 }