Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/gobj/geom.I

Go to the documentation of this file.
00001 // Filename: geom.I
00002 // Created by:  drose (04Feb99)
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: Geom::get_binding
00022 //       Access: Published
00023 //  Description: Returns the GeomBindType which indicates the
00024 //               assignment of colors (or normals, etc.) to the
00025 //               primitives.
00026 ////////////////////////////////////////////////////////////////////
00027 INLINE GeomBindType Geom::
00028 get_binding(int attr) const {
00029   return _bind[attr];
00030 }
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: Geom::get_coords_array
00034 //       Access: Published
00035 //  Description: Returns the array of vertex coordinates associated
00036 //               with the Geom.  This must have binding type
00037 //               G_PER_VERTEX.  It may either be indexed or
00038 //               nonindexed, depending on whether get_coords_index()
00039 //               returns a NULL array.
00040 ////////////////////////////////////////////////////////////////////
00041 INLINE const PTA_Vertexf &Geom::
00042 get_coords_array() const {
00043   return _coords;
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: Geom::get_normals_array
00048 //       Access: Published
00049 //  Description: Returns the array of normals associated with the
00050 //               Geom.  This may have any binding type.  It may either
00051 //               be indexed or nonindexed, depending on whether
00052 //               get_normals_index() returns a NULL array.
00053 ////////////////////////////////////////////////////////////////////
00054 INLINE const PTA_Normalf &Geom::
00055 get_normals_array() const {
00056   return _norms;
00057 }
00058 
00059 ////////////////////////////////////////////////////////////////////
00060 //     Function: Geom::get_colors_array
00061 //       Access: Published
00062 //  Description: Returns the array of colors associated with the
00063 //               Geom.  This may have any binding type.  It may either
00064 //               be indexed or nonindexed, depending on whether
00065 //               get_colors_index() returns a NULL array.
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE const PTA_Colorf &Geom::
00068 get_colors_array() const {
00069   return _colors;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: Geom::get_texcoords_array
00074 //       Access: Published
00075 //  Description: Returns the array of texcoords associated with the
00076 //               Geom.  This may have a binding type of G_PER_VERTEX
00077 //               or G_OFF.  It may either be indexed or nonindexed,
00078 //               depending on whether get_texcoords_index() returns a
00079 //               NULL array.
00080 ////////////////////////////////////////////////////////////////////
00081 INLINE const PTA_TexCoordf &Geom::
00082 get_texcoords_array() const {
00083   return _texcoords;
00084 }
00085 
00086 ////////////////////////////////////////////////////////////////////
00087 //     Function: Geom::get_coords_index
00088 //       Access: Published
00089 //  Description: Returns the array of indices that, if nonempty, will
00090 //               be used to traverse the vertices in coords_array.
00091 ////////////////////////////////////////////////////////////////////
00092 INLINE const PTA_ushort &Geom::
00093 get_coords_index() const {
00094   return _vindex;
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: Geom::get_normals_index
00099 //       Access: Published
00100 //  Description: Returns the array of indices that, if nonempty, will
00101 //               be used to traverse the vertices in normals_array.
00102 ////////////////////////////////////////////////////////////////////
00103 INLINE const PTA_ushort &Geom::
00104 get_normals_index() const {
00105   return _nindex;
00106 }
00107 
00108 ////////////////////////////////////////////////////////////////////
00109 //     Function: Geom::get_colors_index
00110 //       Access: Published
00111 //  Description: Returns the array of indices that, if nonempty, will
00112 //               be used to traverse the vertices in colors_array.
00113 ////////////////////////////////////////////////////////////////////
00114 INLINE const PTA_ushort &Geom::
00115 get_colors_index() const {
00116   return _cindex;
00117 }
00118 
00119 ////////////////////////////////////////////////////////////////////
00120 //     Function: Geom::get_texcoords_index
00121 //       Access: Published
00122 //  Description: Returns the array of indices that, if nonempty, will
00123 //               be used to traverse the vertices in texcoords_array.
00124 ////////////////////////////////////////////////////////////////////
00125 INLINE const PTA_ushort &Geom::
00126 get_texcoords_index() const {
00127   return _tindex;
00128 }
00129 
00130 ////////////////////////////////////////////////////////////////////
00131 //     Function: Geom::set_num_prims
00132 //       Access: Public
00133 //  Description: Sets the number of primitives in the Geom.  The
00134 //               meaning of this depends on the precise type of Geom;
00135 //               generally, each prim is one triangle in a GeomTri, or
00136 //               one tristrip in a GeomTristrip.
00137 ////////////////////////////////////////////////////////////////////
00138 INLINE void Geom::
00139 set_num_prims(int num) {
00140   _numprims = num;
00141   if (!uses_components()) {
00142     // except for strips & fans with the length arrays, total verts will be simply this
00143     _num_vertices = _numprims*get_num_vertices_per_prim();
00144   }
00145   make_dirty();
00146 }
00147 
00148 ////////////////////////////////////////////////////////////////////
00149 //     Function: Geom::get_num_prims
00150 //       Access: Public
00151 //  Description: Returns the number of primitives in the Geom.
00152 ////////////////////////////////////////////////////////////////////
00153 INLINE int Geom::
00154 get_num_prims(void) const {
00155   return _numprims;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: Geom::get_num_vertices
00160 //       Access: Public
00161 //  Description: Returns the number of vertices required by all all
00162 //               the prims in the Geom.
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE int Geom::
00165 get_num_vertices() const {
00166   return _num_vertices;
00167 }
00168 
00169 INLINE int PTA_int_arraysum(const PTA_int &lengths) {
00170     assert(lengths.size()>0);
00171     
00172     int *pLen=&lengths[0];
00173     int *pArrayEnd=pLen+lengths.size();
00174     int nVerts = 0;
00175     for (;pLen<pArrayEnd;pLen++) {
00176       nVerts += *pLen;
00177     }
00178     return nVerts;
00179 }
00180 
00181 
00182 ////////////////////////////////////////////////////////////////////
00183 //     Function: Geom::set_lengths
00184 //       Access: Public
00185 //  Description: Sets the array that indicates the length (number of
00186 //               vertices) of each primitive.  This array should have
00187 //               get_num_prims() entries.  This only has meaning for
00188 //               composite type Geoms, like a GeomTristrip; it is
00189 //               ignored for simple Geoms, like a GeomTri.
00190 ////////////////////////////////////////////////////////////////////
00191 INLINE void Geom::
00192 set_lengths(const PTA_int &lengths) {
00193   _primlengths = lengths;
00194   _num_vertices = PTA_int_arraysum(lengths);
00195   make_dirty();
00196 }
00197 
00198 ////////////////////////////////////////////////////////////////////
00199 //     Function: Geom::get_lengths
00200 //       Access: Public
00201 //  Description: Returns the array the indicates the length (number of
00202 //               vertices) of each primitive.  This array will
00203 //               generally only be defined for composite type Geoms,
00204 //               like a GeomTristrip; it is meaningless for simple
00205 //               Geoms.
00206 ////////////////////////////////////////////////////////////////////
00207 INLINE PTA_int Geom::
00208 get_lengths() const {
00209   return _primlengths;
00210 }
00211 
00212 
00213 
00214 ////////////////////////////////////////////////////////////////////
00215 //
00216 // make_vertex_iterator(), get_next_vertex()
00217 // make_normal_iterator(), get_next_normal()
00218 // make_texcoord_iterator(), get_next_texcoord()
00219 // make_color_iterator(), get_next_color()
00220 //
00221 // These functions all work together to walk through the vertex (or
00222 // normal, etc.) values associated with the Geom.  Begin with a call
00223 // to make_vertex_iterator(), which returns an iterator value suitable
00224 // for passing to get_next_vertex().  The first call to
00225 // get_next_vertex() returns a const Vertexf &, which is the value of
00226 // the first vertex.  Each subsequent call to get_next_vertex() will
00227 // return the value of the next following vertex.
00228 //
00229 // The actual value of the vertex is returned, regardless of whether
00230 // the vertex array is indexed or nonindexed.
00231 //
00232 // There is no end-of-array indicator.  It is up to the caller to know
00233 // the length of the vertex array, and stop when the end is reached.
00234 //
00235 // Similar behavior is exhibited for normals, texcoords, and colors.
00236 //
00237 ////////////////////////////////////////////////////////////////////
00238 
00239 ////////////////////////////////////////////////////////////////////
00240 //     Function: Geom::make_vertex_iterator
00241 //       Access: Public
00242 //  Description:
00243 ////////////////////////////////////////////////////////////////////
00244 INLINE Geom::VertexIterator Geom::
00245 make_vertex_iterator() const {
00246   check_config();
00247   VertexIterator i;
00248   i._array = _coords;
00249   i._index = _vindex;
00250   return i;
00251 }
00252 
00253 ////////////////////////////////////////////////////////////////////
00254 //     Function: Geom::get_next_vertex
00255 //       Access: Public
00256 //  Description:
00257 ////////////////////////////////////////////////////////////////////
00258 INLINE const Vertexf &Geom::
00259 get_next_vertex(VertexIterator &viterator) const {
00260   return _get_vertex(viterator);
00261 }
00262 
00263 ////////////////////////////////////////////////////////////////////
00264 //     Function: Geom::make_normal_iterator
00265 //       Access: Public
00266 //  Description:
00267 ////////////////////////////////////////////////////////////////////
00268 INLINE Geom::NormalIterator Geom::
00269 make_normal_iterator() const {
00270   check_config();
00271   NormalIterator i;
00272   i._array = _norms;
00273   i._index = _nindex;
00274   return i;
00275 }
00276 
00277 ////////////////////////////////////////////////////////////////////
00278 //     Function: Geom::get_next_normal
00279 //       Access: Public
00280 //  Description:
00281 ////////////////////////////////////////////////////////////////////
00282 INLINE const Normalf &Geom::
00283 get_next_normal(NormalIterator &niterator) const {
00284   return _get_normal(niterator);
00285 }
00286 
00287 ////////////////////////////////////////////////////////////////////
00288 //     Function: Geom::make_texcoord_iterator
00289 //       Access: Public
00290 //  Description:
00291 ////////////////////////////////////////////////////////////////////
00292 INLINE Geom::TexCoordIterator Geom::
00293 make_texcoord_iterator() const {
00294   check_config();
00295   TexCoordIterator i;
00296   i._array = _texcoords;
00297   i._index = _tindex;
00298   return i;
00299 }
00300 
00301 ////////////////////////////////////////////////////////////////////
00302 //     Function: Geom::get_next_texcoord
00303 //       Access: Public
00304 //  Description:
00305 ////////////////////////////////////////////////////////////////////
00306 INLINE const TexCoordf &Geom::
00307 get_next_texcoord(TexCoordIterator &tciterator) const {
00308   return _get_texcoord(tciterator);
00309 }
00310 
00311 ////////////////////////////////////////////////////////////////////
00312 //     Function: Geom::make_color_iterator
00313 //       Access: Public
00314 //  Description:
00315 ////////////////////////////////////////////////////////////////////
00316 INLINE Geom::ColorIterator Geom::
00317 make_color_iterator() const {
00318   check_config();
00319   ColorIterator i;
00320   i._array = _colors;
00321   i._index = _cindex;
00322   return i;
00323 }
00324 
00325 ////////////////////////////////////////////////////////////////////
00326 //     Function: Geom::get_next_color
00327 //       Access: Public
00328 //  Description:
00329 ////////////////////////////////////////////////////////////////////
00330 INLINE const Colorf &Geom::
00331 get_next_color(ColorIterator &citerator) const {
00332   return _get_color(citerator);
00333 }

Generated on Fri May 2 00:39:21 2003 for Panda by doxygen1.3