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

panda/src/gobj/geomTri.cxx

Go to the documentation of this file.
00001 // Filename: geomTri.cxx
00002 // Created by:  charles (13Jul00)
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 <datagram.h>
00020 #include <datagramIterator.h>
00021 #include <bamReader.h>
00022 #include <bamWriter.h>
00023 #include <ioPtaDatagramShort.h>
00024 #include <ioPtaDatagramInt.h>
00025 #include <ioPtaDatagramLinMath.h>
00026 #include <graphicsStateGuardianBase.h>
00027 
00028 #include "geomTri.h"
00029 
00030 TypeHandle GeomTri::_type_handle;
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: GeomTri::make_copy
00034 //       Access: Public, Virtual
00035 //  Description: Returns a newly-allocated Geom that is a shallow copy
00036 //               of this one.  It will be a different Geom pointer,
00037 //               but its internal data may or may not be shared with
00038 //               that of the original Geom.
00039 ////////////////////////////////////////////////////////////////////
00040 Geom *GeomTri::
00041 make_copy() const {
00042   return new GeomTri(*this);
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: GeomTri::print_draw_immediate
00047 //       Access:
00048 //  Description:
00049 ////////////////////////////////////////////////////////////////////
00050 void GeomTri::
00051 print_draw_immediate(void) const
00052 {
00053   /*
00054     int i;
00055     int j;
00056     int nprims = _numprims;
00057     Vertexf* tcoords = _coords;
00058     Normalf* tnorms = _norms;
00059     Colorf* tcolors = _colors;
00060     TexCoordf* ttexcoords = _texcoords;
00061     ushort* tvindex = _vindex;
00062     ushort* tnindex = _nindex;
00063     ushort* tcindex = _cindex;
00064     ushort* ttindex = _tindex;
00065 
00066     // Draw overall
00067     if ( _color_command[G_OVERALL] != _issue_color_noop )
00068     {
00069         nout << "Color (Overall): ";
00070         if ( tcindex )
00071         {
00072             nout << "idx: " << *tcindex << " ";
00073             nout << tcolors[*(tcindex++)];
00074         }
00075         else
00076             nout << *(tcolors++);
00077         nout << endl;
00078     }
00079     if ( _normal_command[G_OVERALL] != _issue_normal_noop )
00080     {
00081         nout << "Normal (Overall): ";
00082         if ( tnindex )
00083         {
00084             nout << "idx: " << *tnindex << " ";
00085             nout << tnorms[*(tnindex++)];
00086         }
00087         else
00088             nout << *(tnorms++);
00089         nout << endl;
00090     }
00091 
00092     nout << "BeginGfx()" << endl;
00093 
00094     for ( i = nprims; i > 0; i-- )
00095     {
00096         // Draw per primitive
00097         if ( _color_command[G_PER_PRIM] != _issue_color_noop )
00098         {
00099             nout << "Color (Per Prim): ";
00100             if ( tcindex )
00101             {
00102                 nout << "idx: " << *tcindex << " ";
00103                 nout << tcolors[*(tcindex++)];
00104             }
00105             else
00106                 nout << *(tcolors++);
00107             nout << endl;
00108         }
00109         if ( _normal_command[G_PER_PRIM] != _issue_normal_noop )
00110         {
00111             nout << "Normal (Per Prim): ";
00112             if ( tnindex )
00113             {
00114                 nout << "idx: " << *tnindex << " ";
00115                 nout << tnorms[*(tnindex++)];
00116             }
00117             else
00118                 nout << *(tnorms++);
00119             nout << endl;
00120         }
00121 
00122         for ( j = 0; j < 3; j++ )
00123         {
00124             // Draw per vertex
00125             if ( _color_command[G_PER_VERTEX] != _issue_color_noop )
00126             {
00127                 nout << "Color (Per Vertex): ";
00128                 if ( tcindex )
00129                 {
00130                     nout << "idx: " << *tcindex << " ";
00131                     nout << tcolors[*(tcindex++)];
00132                 }
00133                 else
00134                     nout << *(tcolors++);
00135                 nout << endl;
00136             }
00137             if ( _normal_command[G_PER_VERTEX] != _issue_normal_noop )
00138             {
00139                 nout << "Normal (Per Vertex): ";
00140                 if ( tnindex )
00141                 {
00142                     nout << "idx: " << *tnindex << " ";
00143                     nout << tnorms[*(tnindex++)];
00144                 }
00145                 else
00146                     nout << *(tnorms++);
00147                 nout << endl;
00148             }
00149             if ( _texcoord_command[G_PER_VERTEX] != _issue_texcoord_noop )
00150             {
00151                 nout << "TexCoord (Per Vertex): ";
00152                 if ( ttindex )
00153                 {
00154                     nout << "idx: " << *ttindex << " ";
00155                     nout << ttexcoords[*(ttindex++)];
00156                 }
00157                 else
00158                     nout << *(ttexcoords++);
00159                 nout << endl;
00160             }
00161             if ( _vertex_command[G_PER_VERTEX] != _issue_vertex_noop )
00162             {
00163                 nout << "Vertex (Per Vertex): ";
00164                 if ( tvindex )
00165                 {
00166                     nout << "idx: " << *tvindex << " ";
00167                     nout << tcoords[*(tvindex++)];
00168                 }
00169                 else
00170                     nout << *(tcoords++);
00171                 nout << endl;
00172             }
00173         }
00174     }
00175 
00176     nout << "EndGfx()" << endl;
00177     */
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: GeomTri::draw_immediate
00182 //       Access:
00183 //  Description:
00184 ////////////////////////////////////////////////////////////////////
00185 void GeomTri::
00186 draw_immediate(GraphicsStateGuardianBase *gsg, GeomContext *gc) {
00187   gsg->draw_tri(this, gc);
00188 }
00189 
00190 ////////////////////////////////////////////////////////////////////
00191 //     Function: GeomTri::get_tris
00192 //       Access: Public, Virtual
00193 //  Description: This is similar in principle to explode(), except it
00194 //               returns only a list of triangle vertex indices, with
00195 //               no information about color or whatever.  The array
00196 //               returned is a set of indices into the geom's _coords
00197 //               array, as retrieve by get_coords(); there will be 3*n
00198 //               elements in the array, where n is the number of
00199 //               triangles described by the geometry.  This is useful
00200 //               when it's important to determine the physical
00201 //               structure of the geometry, without necessarily
00202 //               worrying about its rendering properties, and when
00203 //               performance considerations are not overwhelming.
00204 ////////////////////////////////////////////////////////////////////
00205 PTA_ushort GeomTri::
00206 get_tris() const {
00207   int num_tris = _numprims;
00208   PTA_ushort tris;
00209   tris.reserve(num_tris * 3);
00210 
00211   int k = 0;
00212 
00213   for (int i = 0; i < _numprims; i++) {
00214     if (_vindex.empty()) {
00215       for (int j = 0; j < 3; j++) {
00216         tris.push_back(k++);
00217       }
00218     } else {
00219       for (int j = 0; j < 3; j++) {
00220         tris.push_back(_vindex[k++]);
00221       }
00222     }
00223   }
00224 
00225   nassertr((int)tris.size() == num_tris * 3, PTA_ushort());
00226   return tris;
00227 }
00228 
00229 ////////////////////////////////////////////////////////////////////
00230 //     Function: GeomTri::make_GeomTri
00231 //       Access: Protected
00232 //  Description: Factory method to generate a GeomTri object
00233 ////////////////////////////////////////////////////////////////////
00234 TypedWritable* GeomTri::
00235 make_GeomTri(const FactoryParams &params) {
00236   GeomTri *me = new GeomTri;
00237   DatagramIterator scan;
00238   BamReader *manager;
00239 
00240   parse_params(params, scan, manager);
00241   me->fillin(scan, manager);
00242   me->make_dirty();
00243   me->config();
00244   return me;
00245 }
00246 
00247 ////////////////////////////////////////////////////////////////////
00248 //     Function: GeomTri::register_with_factory
00249 //       Access: Public, Static
00250 //  Description: Factory method to generate a GeomTri object
00251 ////////////////////////////////////////////////////////////////////
00252 void GeomTri::
00253 register_with_read_factory(void) {
00254   BamReader::get_factory()->register_factory(get_class_type(), make_GeomTri);
00255 }

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