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

panda/src/egg/eggPrimitive.h

Go to the documentation of this file.
00001 // Filename: eggPrimitive.h
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 #ifndef EGGPRIMITIVE_H
00020 #define EGGPRIMITIVE_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "eggNode.h"
00025 #include "eggAttributes.h"
00026 #include "eggVertex.h"
00027 #include "eggTexture.h"
00028 #include "eggMaterial.h"
00029 #include "eggRenderMode.h"
00030 #include "pt_EggTexture.h"
00031 #include "pt_EggMaterial.h"
00032 #include "vector_PT_EggVertex.h"
00033 
00034 #include <pointerTo.h>
00035 #include "pvector.h"
00036 
00037 class EggVertexPool;
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //       Class : EggPrimitive
00041 // Description : A base class for any of a number of kinds of geometry
00042 //               primitives: polygons, point lights, nurbs patches,
00043 //               parametrics curves, etc.  Things with a set of
00044 //               vertices and some rendering properties like color.
00045 //
00046 //               An EggPrimitive is an STL-style container of pointers
00047 //               to EggVertex's.  In fact, it IS a vector, and can be
00048 //               manipulated in all the ways that vectors can.
00049 //               However, it is necessary that all vertices belong to
00050 //               the same vertex pool.
00051 ////////////////////////////////////////////////////////////////////
00052 class EXPCL_PANDAEGG EggPrimitive : public EggNode, public EggAttributes,
00053                      public EggRenderMode
00054 {
00055 
00056   // This is a bit of private interface stuff that must be here as a
00057   // forward reference.  This allows us to define the EggPrimitive as
00058   // an STL container.
00059 
00060 private:
00061   typedef vector_PT_EggVertex Vertices;
00062 
00063   // Here begins the actual public interface to EggPrimitive.
00064 
00065 public:
00066   INLINE EggPrimitive(const string &name = "");
00067   INLINE EggPrimitive(const EggPrimitive &copy);
00068   INLINE EggPrimitive &operator = (const EggPrimitive &copy);
00069   INLINE ~EggPrimitive();
00070 
00071   virtual EggRenderMode *determine_alpha_mode();
00072   virtual EggRenderMode *determine_depth_write_mode();
00073   virtual EggRenderMode *determine_depth_test_mode();
00074   virtual EggRenderMode *determine_draw_order();
00075   virtual EggRenderMode *determine_bin();
00076 
00077   INLINE void set_texture(EggTexture *texture);
00078   INLINE void clear_texture();
00079   INLINE EggTexture *get_texture() const;
00080   INLINE bool has_texture() const;
00081 
00082   INLINE void set_material(EggMaterial *material);
00083   INLINE void clear_material();
00084   INLINE EggMaterial *get_material() const;
00085   INLINE bool has_material() const;
00086 
00087   INLINE void set_bface_flag(bool flag);
00088   INLINE bool get_bface_flag() const;
00089 
00090   bool has_vertex_normal() const;
00091   bool has_vertex_color() const;
00092 
00093   virtual void reverse_vertex_ordering();
00094   virtual bool cleanup();
00095 
00096   void remove_doubled_verts(bool closed);
00097   void remove_nonunique_verts();
00098 
00099 
00100   // The EggPrimitive itself appears to be an STL container of
00101   // pointers to EggVertex objects.  The set of vertices is read-only,
00102   // however, except through the limited add_vertex/remove_vertex or
00103   // insert/erase interface.  The following implements this.
00104 
00105 #ifdef WIN32_VC
00106   typedef PT_EggVertex *pointer;
00107   typedef PT_EggVertex *const_pointer;
00108 #else
00109   typedef Vertices::const_pointer pointer;
00110   typedef Vertices::const_pointer const_pointer;
00111 #endif
00112   typedef Vertices::const_reference reference;
00113   typedef Vertices::const_reference const_reference;
00114   typedef Vertices::const_iterator iterator;
00115   typedef Vertices::const_iterator const_iterator;
00116   typedef Vertices::const_reverse_iterator reverse_iterator;
00117   typedef Vertices::const_reverse_iterator const_reverse_iterator;
00118   typedef Vertices::size_type size_type;
00119   typedef Vertices::difference_type difference_type;
00120 
00121   INLINE iterator begin() const;
00122   INLINE iterator end() const;
00123   INLINE reverse_iterator rbegin() const;
00124   INLINE reverse_iterator rend() const;
00125   INLINE bool empty() const;
00126   INLINE size_type size() const;
00127 
00128   INLINE EggVertex *operator [] (int index) const;
00129 
00130   INLINE iterator insert(iterator position, EggVertex *x);
00131   INLINE iterator erase(iterator position);
00132   iterator erase(iterator first, iterator last);
00133   INLINE void replace(iterator position, EggVertex *vertex);
00134   INLINE void clear();
00135 
00136   EggVertex *add_vertex(EggVertex *vertex);
00137   EggVertex *remove_vertex(EggVertex *vertex);
00138   void copy_vertices(const EggPrimitive &other);
00139 
00140   // These are shorthands if you don't want to use the iterators.
00141   INLINE void set_vertex(int index, EggVertex *vertex);
00142   INLINE EggVertex *get_vertex(int index) const;
00143 
00144   INLINE EggVertexPool *get_pool() const;
00145 
00146 #ifndef NDEBUG
00147   void test_vref_integrity() const;
00148 #else
00149   void test_vref_integrity() const { }
00150 #endif  // NDEBUG
00151 
00152 private:
00153   Vertices _vertices;
00154 
00155   // Don't try to use these private functions.  User code should add
00156   // and remove vertices via add_vertex()/remove_vertex(), or via the
00157   // STL-like push_back()/pop_back() or insert()/erase(), above.
00158   void prepare_add_vertex(EggVertex *vertex);
00159   void prepare_remove_vertex(EggVertex *vertex);
00160 
00161 
00162 protected:
00163   void write_body(ostream &out, int indent_level) const;
00164 
00165   virtual bool egg_start_parse_body();
00166   virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv,
00167                            CoordinateSystem to_cs);
00168   virtual void r_flatten_transforms();
00169   virtual void r_apply_texmats(EggTextureCollection &textures);
00170 
00171 
00172 private:
00173   PT_EggTexture _texture;
00174   PT_EggMaterial _material;
00175   bool _bface;
00176 
00177 public:
00178 
00179   static TypeHandle get_class_type() {
00180     return _type_handle;
00181   }
00182   static void init_type() {
00183     EggNode::init_type();
00184     EggAttributes::init_type();
00185     EggRenderMode::get_class_type();
00186     register_type(_type_handle, "EggPrimitive",
00187                   EggNode::get_class_type(),
00188                   EggAttributes::get_class_type(),
00189                   EggRenderMode::get_class_type());
00190   }
00191   virtual TypeHandle get_type() const {
00192     return get_class_type();
00193   }
00194   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00195 
00196 private:
00197   static TypeHandle _type_handle;
00198 };
00199 
00200 #include "eggPrimitive.I"
00201 
00202 #endif

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