Panda3D

eggVertex.I

00001 // Filename: eggVertex.I
00002 // Created by:  drose (16Jan99)
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 ////////////////////////////////////////////////////////////////////
00018 //     Function: EggVertex::get_pool
00019 //       Access: Published
00020 //  Description: Returns the vertex pool this vertex belongs in.  This
00021 //               may be NULL if the vertex has not been added to a
00022 //               pool.
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE EggVertexPool *EggVertex::
00025 get_pool() const {
00026   return _pool;
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: EggVertex::is_forward_reference
00031 //       Access: Published
00032 //  Description: Returns true if the vertex is a forward reference to
00033 //               some vertex that hasn't been defined yet.  In this
00034 //               case, the vertex may not have any properties filled
00035 //               in yet.
00036 //
00037 //               This can only happen if you implicitly create a
00038 //               vertex via EggVertexPool::get_forward_vertex().
00039 //               Presumably, when the vertex pool is later filled in,
00040 //               this vertex will be replaced with real data.
00041 ////////////////////////////////////////////////////////////////////
00042 INLINE bool EggVertex::
00043 is_forward_reference() const {
00044   return _forward_reference;
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: EggVertex::set_pos
00049 //       Access: Published
00050 //  Description: Sets the vertex position.  This variant sets the
00051 //               vertex to a one-dimensional value.
00052 ////////////////////////////////////////////////////////////////////
00053 INLINE void EggVertex::
00054 set_pos(double pos) {
00055   _num_dimensions = 1;
00056   _pos.set(pos, 0.0, 0.0, 1.0);
00057 }
00058 
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: EggVertex::set_pos
00062 //       Access: Published
00063 //  Description: Sets the vertex position.  This variant sets the
00064 //               vertex to a two-dimensional value.
00065 ////////////////////////////////////////////////////////////////////
00066 INLINE void EggVertex::
00067 set_pos(const LPoint2d &pos) {
00068   _num_dimensions = 2;
00069   _pos.set(pos[0], pos[1], 0.0, 1.0);
00070 }
00071 
00072 
00073 ////////////////////////////////////////////////////////////////////
00074 //     Function: EggVertex::set_pos
00075 //       Access: Published
00076 //  Description: Sets the vertex position.  This variant sets the
00077 //               vertex to a three-dimensional value.
00078 ////////////////////////////////////////////////////////////////////
00079 INLINE void EggVertex::
00080 set_pos(const LPoint3d &pos) {
00081   _num_dimensions = 3;
00082   _pos.set(pos[0], pos[1], pos[2], 1.0);
00083 }
00084 
00085 
00086 ////////////////////////////////////////////////////////////////////
00087 //     Function: EggVertex::set_pos
00088 //       Access: Published
00089 //  Description: Sets the vertex position.  This variant sets the
00090 //               vertex to a four-dimensional value.
00091 ////////////////////////////////////////////////////////////////////
00092 INLINE void EggVertex::
00093 set_pos(const LPoint4d &pos) {
00094   _num_dimensions = 4;
00095   _pos = pos;
00096 }
00097 
00098 
00099 ////////////////////////////////////////////////////////////////////
00100 //     Function: EggVertex::set_pos4
00101 //       Access: Published
00102 //  Description: This special flavor of set_pos() sets the vertex as a
00103 //               four-component value, but does not change the set
00104 //               number of dimensions.  It's handy for retrieving the
00105 //               vertex position via get_pos4, manipulating it, then
00106 //               storing it back again, without worrying about the
00107 //               number of dimensions it actually had.
00108 ////////////////////////////////////////////////////////////////////
00109 INLINE void EggVertex::
00110 set_pos4(const LPoint4d &pos) {
00111   _pos = pos;
00112 }
00113 
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: EggVertex::get_num_dimensions
00117 //       Access: Published
00118 //  Description: Returns the number of dimensions the vertex uses.
00119 //               Usually this will be 3, but it may be 1, 2, 3, or 4.
00120 ////////////////////////////////////////////////////////////////////
00121 INLINE int EggVertex::
00122 get_num_dimensions() const {
00123   return _num_dimensions;
00124 }
00125 
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: EggVertex::get_pos1
00129 //       Access: Published
00130 //  Description: Only valid if get_num_dimensions() returns 1.
00131 //               Returns the position as a one-dimensional value.
00132 ////////////////////////////////////////////////////////////////////
00133 INLINE double EggVertex::
00134 get_pos1() const {
00135   nassertr(_num_dimensions == 1, 0.0);
00136   return _pos[0];
00137 }
00138 
00139 
00140 ////////////////////////////////////////////////////////////////////
00141 //     Function: EggVertex::get_pos2
00142 //       Access: Published
00143 //  Description: Only valid if get_num_dimensions() returns 2.
00144 //               Returns the position as a two-dimensional value.
00145 ////////////////////////////////////////////////////////////////////
00146 INLINE LPoint2d EggVertex::
00147 get_pos2() const {
00148   nassertr(_num_dimensions == 2, LPoint2d(0.0, 0.0));
00149   return LPoint2d(_pos[0], _pos[1]);
00150 }
00151 
00152 
00153 ////////////////////////////////////////////////////////////////////
00154 //     Function: EggVertex::get_pos3
00155 //       Access: Published
00156 //  Description: Valid if get_num_dimensions() returns 3 or 4.
00157 //               Returns the position as a three-dimensional value.
00158 ////////////////////////////////////////////////////////////////////
00159 INLINE Vertexd EggVertex::
00160 get_pos3() const {
00161   nassertr(_num_dimensions == 3 || _num_dimensions == 4,
00162            LPoint3d(0.0, 0.0, 0.0));
00163   return Vertexd(_pos[0] / _pos[3], _pos[1] / _pos[3], _pos[2] / _pos[3]);
00164 }
00165 
00166 
00167 ////////////////////////////////////////////////////////////////////
00168 //     Function: EggVertex::get_pos4
00169 //       Access: Published
00170 //  Description: This is always valid, regardless of the value of
00171 //               get_num_dimensions.  It returns the position as a
00172 //               four-dimensional value.  If the pos has fewer than
00173 //               four dimensions, this value represents the pos
00174 //               extended into four-dimensional homogenous space,
00175 //               e.g. by adding 1 as the fourth component.
00176 ////////////////////////////////////////////////////////////////////
00177 INLINE LPoint4d EggVertex::
00178 get_pos4() const {
00179   return _pos;
00180 }
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: EggVertex::has_uv
00184 //       Access: Published
00185 //  Description: Returns true if the vertex has an unnamed UV
00186 //               coordinate pair, false otherwise.
00187 //
00188 //               This is the more restrictive interface, and is
00189 //               generally useful only in the absence of
00190 //               multitexturing; see has_uv(name) for the interface
00191 //               that supports multitexturing.
00192 ////////////////////////////////////////////////////////////////////
00193 INLINE bool EggVertex::
00194 has_uv() const {
00195   return has_uv("");
00196 }
00197 
00198 ////////////////////////////////////////////////////////////////////
00199 //     Function: EggVertex::get_uv
00200 //       Access: Published
00201 //  Description: Returns the unnamed UV coordinate pair on the
00202 //               vertex.  It is an error to call this if has_uv() has
00203 //               returned false.
00204 //
00205 //               This is the more restrictive interface, and is
00206 //               generally useful only in the absence of
00207 //               multitexturing; see get_uv(name) for the interface
00208 //               that supports multitexturing.
00209 ////////////////////////////////////////////////////////////////////
00210 INLINE TexCoordd EggVertex::
00211 get_uv() const {
00212   nassertr(has_uv(), TexCoordd::zero());
00213   return get_uv("");
00214 }
00215 
00216 ////////////////////////////////////////////////////////////////////
00217 //     Function: EggVertex::set_uv
00218 //       Access: Published
00219 //  Description: Replaces the unnamed UV coordinate pair on the vertex
00220 //               with the indicated value.
00221 //
00222 //               This is the more restrictive interface, and is
00223 //               generally useful only in the absence of
00224 //               multitexturing; see set_uv(name, uv) for the
00225 //               interface that supports multitexturing.
00226 ////////////////////////////////////////////////////////////////////
00227 INLINE void EggVertex::
00228 set_uv(const TexCoordd &uv) {
00229   set_uv("", uv);
00230 }
00231 
00232 ////////////////////////////////////////////////////////////////////
00233 //     Function: EggVertex::clear_uv
00234 //       Access: Published
00235 //  Description: Removes all UV coordinate pairs from the vertex.
00236 ////////////////////////////////////////////////////////////////////
00237 INLINE void EggVertex::
00238 clear_uv() {
00239   _uv_map.clear();
00240 }
00241 
00242 ////////////////////////////////////////////////////////////////////
00243 //     Function: EggVertex::uv_begin
00244 //       Access: Public
00245 //  Description: Returns an iterator that allows walking through the
00246 //               complete set of named UV's on the vertex.
00247 //
00248 //               This interface is not safe to use outside of
00249 //               PANDAEGG.DLL.
00250 ////////////////////////////////////////////////////////////////////
00251 INLINE EggVertex::const_uv_iterator EggVertex::
00252 uv_begin() const {
00253   return _uv_map.begin();
00254 }
00255 
00256 ////////////////////////////////////////////////////////////////////
00257 //     Function: EggVertex::uv_end
00258 //       Access: Public
00259 //  Description: Returns an iterator that allows walking through the
00260 //               complete set of named UV's on the vertex.
00261 //
00262 //               This interface is not safe to use outside of
00263 //               PANDAEGG.DLL.
00264 ////////////////////////////////////////////////////////////////////
00265 INLINE EggVertex::const_uv_iterator EggVertex::
00266 uv_end() const {
00267   return _uv_map.end();
00268 }
00269 
00270 ////////////////////////////////////////////////////////////////////
00271 //     Function: EggVertex::uv_size
00272 //       Access: Public
00273 //  Description: Returns the number of named UV's on the vertex.
00274 ////////////////////////////////////////////////////////////////////
00275 INLINE EggVertex::uv_size_type EggVertex::
00276 uv_size() const {
00277   return _uv_map.size();
00278 }
00279 
00280 ////////////////////////////////////////////////////////////////////
00281 //     Function: EggVertex::get_index
00282 //       Access: Published
00283 //  Description: Returns the index number of the vertex within its
00284 //               pool.
00285 ////////////////////////////////////////////////////////////////////
00286 INLINE int EggVertex::
00287 get_index() const {
00288   return _index;
00289 }
00290 
00291 ////////////////////////////////////////////////////////////////////
00292 //     Function: EggVertex::set_external_index
00293 //       Access: Published
00294 //  Description: Sets a special index number that is associated with
00295 //               the EggVertex (but is not written to the egg file).
00296 //               This number is not interpreted by any egg code; it is
00297 //               simply maintained along with the vertex.  It *is*
00298 //               used to differentiate otherwise identical vertices in
00299 //               EggVertexPool::create_unique_vertex(), however.
00300 //
00301 //               The intention of this number is as an aid for file
00302 //               converters, to associate an EggVertex back to the
00303 //               index number of the original source vertex.
00304 ////////////////////////////////////////////////////////////////////
00305 INLINE void EggVertex::
00306 set_external_index(int external_index) {
00307   _external_index = external_index;
00308 }
00309 
00310 ////////////////////////////////////////////////////////////////////
00311 //     Function: EggVertex::get_external_index
00312 //       Access: Published
00313 //  Description: Returns the number set by set_external_index().  See
00314 //               set_external_index().
00315 ////////////////////////////////////////////////////////////////////
00316 INLINE int EggVertex::
00317 get_external_index() const {
00318   return _external_index;
00319 }
00320 
00321 ////////////////////////////////////////////////////////////////////
00322 //     Function: EggVertex::sorts_less_than
00323 //       Access: Published
00324 //  Description: An ordering operator to compare two vertices for
00325 //               sorting order.  This imposes an arbitrary ordering
00326 //               useful to identify unique vertices.
00327 ////////////////////////////////////////////////////////////////////
00328 INLINE bool EggVertex::
00329 sorts_less_than(const EggVertex &other) const {
00330   return (compare_to(other) < 0);
00331 }
00332 
00333 
00334 
00335 
00336 
00337 ////////////////////////////////////////////////////////////////////
00338 //     Function: UniqueEggVertices::Function operator
00339 //       Access: Public
00340 //  Description:
00341 ////////////////////////////////////////////////////////////////////
00342 INLINE bool UniqueEggVertices::
00343 operator ()(const EggVertex *v1, const EggVertex *v2) const {
00344   return v1->sorts_less_than(*v2);
00345 }
00346 
 All Classes Functions Variables Enumerations