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

panda/src/egg/eggPrimitive.I

Go to the documentation of this file.
00001 // Filename: eggPrimitive.I
00002 // Created by:  drose (16Jan99)
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 #include <algorithm>
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: EggPrimitive::Constructor
00023 //       Access: Public
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 INLINE EggPrimitive::
00027 EggPrimitive(const string &name): EggNode(name) {
00028   _bface = false;
00029 }
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //     Function: EggPrimitive::Copy constructor
00033 //       Access: Public
00034 //  Description:
00035 ////////////////////////////////////////////////////////////////////
00036 INLINE EggPrimitive::
00037 EggPrimitive(const EggPrimitive &copy) :
00038   EggNode(copy),
00039   EggAttributes(copy),
00040   _texture(copy._texture),
00041   _material(copy._material),
00042   _bface(copy._bface)
00043 {
00044   copy_vertices(copy);
00045 }
00046 
00047 ////////////////////////////////////////////////////////////////////
00048 //     Function: EggPrimitive::Copy assignment operator
00049 //       Access: Public
00050 //  Description:
00051 ////////////////////////////////////////////////////////////////////
00052 INLINE EggPrimitive &EggPrimitive::
00053 operator = (const EggPrimitive &copy) {
00054   EggNode::operator = (copy);
00055   EggAttributes::operator = (copy);
00056   copy_vertices(copy);
00057   _texture = copy._texture;
00058   _material = copy._material;
00059   _bface = copy._bface;
00060   return *this;
00061 }
00062 
00063 ////////////////////////////////////////////////////////////////////
00064 //     Function: EggPrimitive::Destructor
00065 //       Access: Public
00066 //  Description:
00067 ////////////////////////////////////////////////////////////////////
00068 INLINE EggPrimitive::
00069 ~EggPrimitive() {
00070   clear();
00071 }
00072 
00073 ////////////////////////////////////////////////////////////////////
00074 //     Function: EggPrimitive::set_texture
00075 //       Access: Public
00076 //  Description: Applies the indicated texture to the primitive.
00077 ////////////////////////////////////////////////////////////////////
00078 INLINE void EggPrimitive::
00079 set_texture(EggTexture *texture) {
00080   _texture = texture;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: EggPrimitive::clear_texture
00085 //       Access: Public
00086 //  Description: Removes any texturing from the primitive.
00087 ////////////////////////////////////////////////////////////////////
00088 INLINE void EggPrimitive::
00089 clear_texture() {
00090   _texture = (EggTexture *)NULL;
00091 }
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: EggPrimitive::get_texture
00095 //       Access: Public
00096 //  Description: Returns a pointer to the applied texture, or NULL if
00097 //               there is no texture applied.
00098 ////////////////////////////////////////////////////////////////////
00099 INLINE EggTexture *EggPrimitive::
00100 get_texture() const {
00101   return _texture;
00102 }
00103 
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: EggPrimitive::has_texture
00107 //       Access: Public
00108 //  Description: Returns true if the primitive is textured (and
00109 //               get_texture() will return a real pointer), false
00110 //               otherwise (and get_texture() will return NULL).
00111 ////////////////////////////////////////////////////////////////////
00112 INLINE bool EggPrimitive::
00113 has_texture() const {
00114   return _texture != (EggTexture*)NULL;
00115 }
00116 
00117 ////////////////////////////////////////////////////////////////////
00118 //     Function: EggPrimitive::set_material
00119 //       Access: Public
00120 //  Description: Applies the indicated material to the primitive.
00121 ////////////////////////////////////////////////////////////////////
00122 INLINE void EggPrimitive::
00123 set_material(EggMaterial *material) {
00124   _material = material;
00125 }
00126 
00127 ////////////////////////////////////////////////////////////////////
00128 //     Function: EggPrimitive::clear_material
00129 //       Access: Public
00130 //  Description: Removes any material from the primitive.
00131 ////////////////////////////////////////////////////////////////////
00132 INLINE void EggPrimitive::
00133 clear_material() {
00134   _material = (EggMaterial *)NULL;
00135 }
00136 
00137 ////////////////////////////////////////////////////////////////////
00138 //     Function: EggPrimitive::get_material
00139 //       Access: Public
00140 //  Description: Returns a pointer to the applied material, or NULL if
00141 //               there is no material applied.
00142 ////////////////////////////////////////////////////////////////////
00143 INLINE EggMaterial *EggPrimitive::
00144 get_material() const {
00145   return _material;
00146 }
00147 
00148 
00149 ////////////////////////////////////////////////////////////////////
00150 //     Function: EggPrimitive::has_material
00151 //       Access: Public
00152 //  Description: Returns true if the primitive is materiald (and
00153 //               get_material() will return a real pointer), false
00154 //               otherwise (and get_material() will return NULL).
00155 ////////////////////////////////////////////////////////////////////
00156 INLINE bool EggPrimitive::
00157 has_material() const {
00158   return _material != (EggMaterial *)NULL;
00159 }
00160 
00161 
00162 ////////////////////////////////////////////////////////////////////
00163 //     Function: EggPrimitive::set_bface_flag
00164 //       Access: Public
00165 //  Description: Sets the backfacing flag of the polygon.  If this is
00166 //               true, the polygon will be rendered so that both faces
00167 //               are visible; if it is false, only the front face of
00168 //               the polygon will be visible.
00169 ////////////////////////////////////////////////////////////////////
00170 INLINE void EggPrimitive::
00171 set_bface_flag(bool flag) {
00172   _bface = flag;
00173 }
00174 
00175 
00176 ////////////////////////////////////////////////////////////////////
00177 //     Function: EggPrimitive::get_bface_flag
00178 //       Access: Public
00179 //  Description: Retrieves the backfacing flag of the polygon.  See
00180 //               set_bface_flag().
00181 ////////////////////////////////////////////////////////////////////
00182 INLINE bool EggPrimitive::
00183 get_bface_flag() const {
00184   return _bface;
00185 }
00186 
00187 
00188 ////////////////////////////////////////////////////////////////////
00189 //     Function: EggPrimitive::begin
00190 //       Access: Public
00191 //  Description:
00192 ////////////////////////////////////////////////////////////////////
00193 INLINE EggPrimitive::iterator EggPrimitive::
00194 begin() const {
00195   return _vertices.begin();
00196 }
00197 
00198 ////////////////////////////////////////////////////////////////////
00199 //     Function: EggPrimitive::end
00200 //       Access: Public
00201 //  Description:
00202 ////////////////////////////////////////////////////////////////////
00203 INLINE EggPrimitive::iterator EggPrimitive::
00204 end() const {
00205   return _vertices.end();
00206 }
00207 
00208 ////////////////////////////////////////////////////////////////////
00209 //     Function: EggPrimitive::rbegin
00210 //       Access: Public
00211 //  Description:
00212 ////////////////////////////////////////////////////////////////////
00213 INLINE EggPrimitive::reverse_iterator EggPrimitive::
00214 rbegin() const {
00215   return _vertices.rbegin();
00216 }
00217 
00218 ////////////////////////////////////////////////////////////////////
00219 //     Function: EggPrimitive::rend
00220 //       Access: Public
00221 //  Description:
00222 ////////////////////////////////////////////////////////////////////
00223 INLINE EggPrimitive::reverse_iterator EggPrimitive::
00224 rend() const {
00225   return _vertices.rend();
00226 }
00227 
00228 ////////////////////////////////////////////////////////////////////
00229 //     Function: EggPrimitive::empty
00230 //       Access: Public
00231 //  Description:
00232 ////////////////////////////////////////////////////////////////////
00233 INLINE bool EggPrimitive::
00234 empty() const {
00235   return _vertices.empty();
00236 }
00237 
00238 ////////////////////////////////////////////////////////////////////
00239 //     Function: EggPrimitive::size
00240 //       Access: Public
00241 //  Description:
00242 ////////////////////////////////////////////////////////////////////
00243 INLINE EggPrimitive::size_type EggPrimitive::
00244 size() const {
00245   return _vertices.size();
00246 }
00247 
00248 ////////////////////////////////////////////////////////////////////
00249 //     Function: EggPrimitive::Indexing operator
00250 //       Access: Public
00251 //  Description: This is read-only: you can't assign directly to an
00252 //               indexed vertex.  See set_vertex() instead.
00253 ////////////////////////////////////////////////////////////////////
00254 INLINE EggVertex *EggPrimitive::
00255 operator [] (int index) const {
00256   nassertr(index >= 0 && index < (int)size(), NULL);
00257   return *(begin() + index);
00258 }
00259 
00260 ////////////////////////////////////////////////////////////////////
00261 //     Function: EggPrimitive::insert
00262 //       Access: Public
00263 //  Description:
00264 ////////////////////////////////////////////////////////////////////
00265 INLINE EggPrimitive::iterator EggPrimitive::
00266 insert(iterator position, EggVertex *x) {
00267   prepare_add_vertex(x);
00268   iterator i = _vertices.insert((Vertices::iterator &)position, x);
00269   x->test_pref_integrity();
00270   test_vref_integrity();
00271   return i;
00272 }
00273 
00274 ////////////////////////////////////////////////////////////////////
00275 //     Function: EggPrimitive::erase
00276 //       Access: Public
00277 //  Description:
00278 ////////////////////////////////////////////////////////////////////
00279 INLINE EggPrimitive::iterator EggPrimitive::
00280 erase(iterator position) {
00281   prepare_remove_vertex(*position);
00282   iterator i = _vertices.erase((Vertices::iterator &)position);
00283   test_vref_integrity();
00284   return i;
00285 }
00286 
00287 ////////////////////////////////////////////////////////////////////
00288 //     Function: EggPrimitive::replace
00289 //       Access: Public
00290 //  Description: Replaces the vertex at the indicated position with
00291 //               the indicated vertex.  It is an error to call this
00292 //               with an invalid position iterator (e.g. end()).
00293 ////////////////////////////////////////////////////////////////////
00294 INLINE void EggPrimitive::
00295 replace(iterator position, EggVertex *x) {
00296   nassertv(position != end());
00297 
00298   prepare_remove_vertex(*position);
00299   prepare_add_vertex(x);
00300   *(Vertices::iterator &)position = x;
00301 
00302   x->test_pref_integrity();
00303   test_vref_integrity();
00304 }
00305 
00306 ////////////////////////////////////////////////////////////////////
00307 //     Function: EggPrimitive::clear
00308 //       Access: Public
00309 //  Description:
00310 ////////////////////////////////////////////////////////////////////
00311 INLINE void EggPrimitive::
00312 clear() {
00313   erase(begin(), end());
00314 }
00315 
00316 ////////////////////////////////////////////////////////////////////
00317 //     Function: EggPrimitive::set_vertex
00318 //       Access: Public
00319 //  Description: Replaces a particular vertex based on its index
00320 //               number in the list of vertices.  This is just a
00321 //               convenience function for people who don't want to
00322 //               mess with the iterators.
00323 ////////////////////////////////////////////////////////////////////
00324 INLINE void EggPrimitive::
00325 set_vertex(int index, EggVertex *vertex) {
00326   nassertv(index >= 0 && index < (int)size());
00327   replace(begin() + index, vertex);
00328 }
00329 
00330 ////////////////////////////////////////////////////////////////////
00331 //     Function: EggPrimitive::get_vertex
00332 //       Access: Public
00333 //  Description: Returns a particular index based on its index number.
00334 ////////////////////////////////////////////////////////////////////
00335 INLINE EggVertex *EggPrimitive::
00336 get_vertex(int index) const {
00337   nassertr(index >= 0 && index < (int)size(), NULL);
00338   return *(begin() + index);
00339 }
00340 
00341 
00342 ////////////////////////////////////////////////////////////////////
00343 //     Function: EggPrimitive::get_pool
00344 //       Access: Public
00345 //  Description: Returns the vertex pool associated with the vertices
00346 //               of the primitive, or NULL if the primitive has no
00347 //               vertices.
00348 ////////////////////////////////////////////////////////////////////
00349 INLINE EggVertexPool *EggPrimitive::
00350 get_pool() const {
00351   return empty() ? (EggVertexPool *)0L : _vertices.front()->get_pool();
00352 }

Generated on Fri May 2 00:37:54 2003 for Panda by doxygen1.3