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

panda/src/gobj/geomQuad.cxx

Go to the documentation of this file.
00001 // Filename: geomQuad.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 #include "geomQuad.h"
00030 
00031 TypeHandle GeomQuad::_type_handle;
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //     Function: GeomQuad::make_copy
00035 //       Access: Public, Virtual
00036 //  Description: Returns a newly-allocated Geom that is a shallow copy
00037 //               of this one.  It will be a different Geom pointer,
00038 //               but its internal data may or may not be shared with
00039 //               that of the original Geom.
00040 ////////////////////////////////////////////////////////////////////
00041 Geom *GeomQuad::
00042 make_copy() const {
00043   return new GeomQuad(*this);
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: GeomQuad::print_draw_immediate
00048 //       Access: Public
00049 //  Description:
00050 ////////////////////////////////////////////////////////////////////
00051 void GeomQuad::
00052 print_draw_immediate(void) const {
00053 }
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //     Function: GeomQuad::draw_immediate
00057 //       Access: Public
00058 //  Description:
00059 ////////////////////////////////////////////////////////////////////
00060 void GeomQuad::
00061 draw_immediate(GraphicsStateGuardianBase *gsg, GeomContext *gc) {
00062   gsg->draw_quad(this, gc);
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: GeomQuad::get_tris
00067 //       Access: Public, Virtual
00068 //  Description: This is similar in principle to explode(), except it
00069 //               returns only a list of triangle vertex indices, with
00070 //               no information about color or whatever.  The array
00071 //               returned is a set of indices into the geom's _coords
00072 //               array, as retrieve by get_coords(); there will be 3*n
00073 //               elements in the array, where n is the number of
00074 //               triangles described by the geometry.  This is useful
00075 //               when it's important to determine the physical
00076 //               structure of the geometry, without necessarily
00077 //               worrying about its rendering properties, and when
00078 //               performance considerations are not overwhelming.
00079 ////////////////////////////////////////////////////////////////////
00080 PTA_ushort GeomQuad::
00081 get_tris() const {
00082   int num_tris = _numprims * 2;
00083   PTA_ushort tris;
00084   tris.reserve(num_tris * 3);
00085 
00086   int k = 0;
00087 
00088   for (int i = 0; i < _numprims; i++) {
00089     ushort indices[4];
00090     if (_vindex.empty()) {
00091       for (int j = 0; j < 4; j++) {
00092         indices[j] = k++;
00093       }
00094     } else {
00095       for (int j = 0; j < 4; j++) {
00096         indices[j] = _vindex[k++];
00097       }
00098     }
00099 
00100     // First tri.  Vertices 0, 1, 2.
00101     tris.push_back(indices[0]);
00102     tris.push_back(indices[1]);
00103     tris.push_back(indices[2]);
00104 
00105     // Second tri.  Vertices 0, 2, 3.
00106     tris.push_back(indices[0]);
00107     tris.push_back(indices[2]);
00108     tris.push_back(indices[3]);
00109   }
00110 
00111   nassertr((int)tris.size() == num_tris * 3, PTA_ushort());
00112   return tris;
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: GeomQuad::make_GeomQuad
00117 //       Access: Protected
00118 //  Description: Factory method to generate a GeomQuad object
00119 ////////////////////////////////////////////////////////////////////
00120 TypedWritable* GeomQuad::
00121 make_GeomQuad(const FactoryParams &params) {
00122   GeomQuad *me = new GeomQuad;
00123   DatagramIterator scan;
00124   BamReader *manager;
00125 
00126   parse_params(params, scan, manager);
00127   me->fillin(scan, manager);
00128   me->make_dirty();
00129   me->config();
00130   return me;
00131 }
00132 
00133 ////////////////////////////////////////////////////////////////////
00134 //     Function: GeomQuad::register_with_factory
00135 //       Access: Public, Static
00136 //  Description: Factory method to generate a GeomQuad object
00137 ////////////////////////////////////////////////////////////////////
00138 void GeomQuad::
00139 register_with_read_factory(void) {
00140   BamReader::get_factory()->register_factory(get_class_type(), make_GeomQuad);
00141 }

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