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

panda/src/builder/builderNormalVisualizer.cxx

Go to the documentation of this file.
00001 // Filename: builderNormalVisualizer.cxx
00002 // Created by:  drose (08Sep99)
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 "builderFuncs.h"
00020 #include "builderNormalVisualizer.h"
00021 #include "geomNode.h"
00022 
00023 #ifdef SUPPORT_SHOW_NORMALS
00024 
00025 void BuilderNormalVisualizer::
00026 add_prim(const BuilderPrim &prim) {
00027   if (prim.has_overall_normal()) {
00028     // Average up all the vertex values to get the primitive center.
00029     BuilderV net_vertex;
00030     net_vertex.set(0.0, 0.0, 0.0);
00031     int num_verts = prim.get_num_verts();
00032     for (int i = 0; i < num_verts; i++) {
00033       net_vertex += prim.get_vertex(i).get_coord();
00034     }
00035     net_vertex /= num_verts;
00036     add_normal(net_vertex, prim.get_normal());
00037 
00038   } else if (prim.has_vertex_normal()) {
00039     // Each vertex gets its own normal.
00040     int num_verts = prim.get_num_verts();
00041     for (int i = 0; i < num_verts; i++) {
00042       add_normal(prim.get_vertex(i).get_coord(), prim.get_vertex(i).get_normal());
00043     }
00044   } else if (prim.has_component_normal()) {
00045     // Each component gets its own normal.  We don't presently handle
00046     // this, as it should only happen when the user passes
00047     // already-meshed tristrips into the builder, an unusual
00048     // situation.
00049   }
00050 }
00051 
00052 void BuilderNormalVisualizer::
00053 add_prim(const BuilderPrimI &prim) {
00054   BuilderPrim prim_ni;
00055   prim_ni.nonindexed_copy(prim, _bucket);
00056   add_prim(prim_ni);
00057 }
00058 
00059 void BuilderNormalVisualizer::
00060 show_normals(GeomNode *node) {
00061   // Ok, now we've got a bunch of normals saved up; create some geometry.
00062   mesh_and_build(_lines.begin(), _lines.end(), _bucket, node, (BuilderPrim *)0);
00063 }
00064 
00065 void BuilderNormalVisualizer::
00066 add_normal(const BuilderV &center, const BuilderN &normal) {
00067   BuilderV to = center + normal * _bucket._normal_scale;
00068 
00069   BuilderPrim line;
00070   line.set_type(BPT_line);
00071   line.set_color(_bucket._normal_color);
00072   line.add_vertex(BuilderVertex(center));
00073   line.add_vertex(BuilderVertex(to));
00074 
00075   _lines.push_back(line);
00076 }
00077 
00078 #endif
00079 

Generated on Fri May 2 00:34:43 2003 for Panda by doxygen1.3