From 2b7f0ca2e662751ffeefec1c288af4af6dab72b9 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 31 Jul 2001 17:07:57 +0000 Subject: [PATCH] fix obscure texcoord bug --- panda/src/builder/Sources.pp | 8 +++-- panda/src/builder/builderAttribTempl.I | 41 +++++++++++++++-------- panda/src/builder/builderAttribTempl.h | 3 +- panda/src/builder/builderVertexTempl.I | 46 ++++++++++++++++---------- panda/src/builder/builderVertexTempl.h | 10 +++--- panda/src/builder/builder_compare.I | 37 +++++++++++++++++++++ panda/src/builder/builder_compare.h | 40 ++++++++++++++++++++++ 7 files changed, 148 insertions(+), 37 deletions(-) create mode 100644 panda/src/builder/builder_compare.I create mode 100644 panda/src/builder/builder_compare.h diff --git a/panda/src/builder/Sources.pp b/panda/src/builder/Sources.pp index b04fb88e79..8589a6486f 100644 --- a/panda/src/builder/Sources.pp +++ b/panda/src/builder/Sources.pp @@ -10,7 +10,9 @@ #define COMBINED_SOURCES $[TARGET]_composite1.cxx $[TARGET]_composite2.cxx #define SOURCES \ - builder.I builder.h builderAttrib.I builderAttrib.h \ + builder.I builder.h \ + builder_compare.I builder_compare.h \ + builderAttrib.I builderAttrib.h \ builderAttribTempl.I builderAttribTempl.h builderBucket.I \ builderBucket.h builderBucketNode.I builderBucketNode.h \ builderFuncs.I builderFuncs.h builderMisc.h \ @@ -31,7 +33,9 @@ config_builder.cxx mesher.cxx #define INSTALL_HEADERS \ - builder.I builder.h builderAttrib.I builderAttrib.h \ + builder.I builder.h \ + builder_compare.I builder_compare.h \ + builderAttrib.I builderAttrib.h \ builderAttribTempl.I builderAttribTempl.h builderBucket.I \ builderBucket.h builderBucketNode.I builderBucketNode.h \ builderNormalVisualizer.I builderNormalVisualizer.h \ diff --git a/panda/src/builder/builderAttribTempl.I b/panda/src/builder/builderAttribTempl.I index 3f71a8d9ab..ffd6c8b6e4 100644 --- a/panda/src/builder/builderAttribTempl.I +++ b/panda/src/builder/builderAttribTempl.I @@ -242,13 +242,7 @@ clear_pixel_size() { template INLINE bool BuilderAttribTempl:: operator == (const BuilderAttribTempl &other) const { - if (has_normal() && !(_normal == other._normal)) - return false; - - if (has_color() && !(_color == other._color)) - return false; - - return true; + return compare_to(other) == 0; } //////////////////////////////////////////////////////////////////// @@ -278,13 +272,34 @@ operator != (const BuilderAttribTempl &other) const { template INLINE bool BuilderAttribTempl:: operator < (const BuilderAttribTempl &other) const { - if (has_normal() && !(_normal == other._normal)) - return _normal < other._normal; + return compare_to(other) < 0; +} - if (has_color() && !(_color == other._color)) - return _color < other._color; +//////////////////////////////////////////////////////////////////// +// Function: BuilderAttribTempl::compare_to +// Access: Public +// Description: Returns a number less than zero if this object sorts +// before the indicated object, greater than zero if it +// sorts after, and zero if the objects are equivalent. +//////////////////////////////////////////////////////////////////// +template +int BuilderAttribTempl:: +compare_to(const BuilderAttribTempl &other) const { + if (has_normal()) { + int normal_compare = builder_compare(_normal, other._normal); + if (normal_compare != 0) { + return normal_compare; + } + } - return false; + if (has_color()) { + int color_compare = builder_compare(_color, other._color); + if (color_compare != 0) { + return color_compare; + } + } + + return 0; } //////////////////////////////////////////////////////////////////// @@ -293,7 +308,7 @@ operator < (const BuilderAttribTempl &other) const { // Description: Formats the attribs for output in some sensible way. //////////////////////////////////////////////////////////////////// template -INLINE ostream &BuilderAttribTempl:: +ostream &BuilderAttribTempl:: output(ostream &out) const { if (this!=NULL) { if (has_normal()) { diff --git a/panda/src/builder/builderAttribTempl.h b/panda/src/builder/builderAttribTempl.h index fac527cad7..d5bbc44c78 100644 --- a/panda/src/builder/builderAttribTempl.h +++ b/panda/src/builder/builderAttribTempl.h @@ -65,8 +65,9 @@ public: INLINE bool operator == (const BuilderAttribTempl &other) const; INLINE bool operator != (const BuilderAttribTempl &other) const; INLINE bool operator < (const BuilderAttribTempl &other) const; + int compare_to(const BuilderAttribTempl &other) const; - INLINE ostream &output(ostream &out) const; + ostream &output(ostream &out) const; protected: NType _normal; diff --git a/panda/src/builder/builderVertexTempl.I b/panda/src/builder/builderVertexTempl.I index 4e49ee88a1..11a9256d11 100644 --- a/panda/src/builder/builderVertexTempl.I +++ b/panda/src/builder/builderVertexTempl.I @@ -16,7 +16,6 @@ // //////////////////////////////////////////////////////////////////// -#include //////////////////////////////////////////////////////////////////// // Function: BuilderVertexTempl::Constructor @@ -285,15 +284,9 @@ clear_pixel_size() { // texcoords, etc. //////////////////////////////////////////////////////////////////// template -bool BuilderVertexTempl:: +INLINE bool BuilderVertexTempl:: operator == (const BuilderVertexTempl &other) const { - if (has_coord() && !(_coord == other._coord)) - return false; - - if (has_texcoord() && !(_texcoord == other._texcoord)) - return false; - - return BuilderAttribTempl::operator == (other); + return compare_to(other) == 0; } //////////////////////////////////////////////////////////////////// @@ -321,15 +314,36 @@ operator != (const BuilderVertexTempl &other) const { // etc. //////////////////////////////////////////////////////////////////// template -bool BuilderVertexTempl:: +INLINE bool BuilderVertexTempl:: operator < (const BuilderVertexTempl &other) const { - if (has_coord() && !(_coord == other._coord)) - return _coord < other._coord; + return compare_to(other) < 0; +} - if (has_texcoord() && !(_texcoord == other._texcoord)) - return _texcoord < other._texcoord; +//////////////////////////////////////////////////////////////////// +// Function: BuilderVertexTempl::compare_to +// Access: Public +// Description: Returns a number less than zero if this vertex sorts +// before the indicated vertex, greater than zero if it +// sorts after, and zero if the vertices are equivalent. +//////////////////////////////////////////////////////////////////// +template +int BuilderVertexTempl:: +compare_to(const BuilderVertexTempl &other) const { + if (has_coord()) { + int coord_compare = builder_compare(_coord, other._coord); + if (coord_compare != 0) { + return coord_compare; + } + } - return BuilderAttribTempl::operator < (other); + if (has_texcoord()) { + int texcoord_compare = builder_compare(_texcoord, other._texcoord); + if (texcoord_compare != 0) { + return texcoord_compare; + } + } + + return BuilderAttribTempl::compare_to(other); } //////////////////////////////////////////////////////////////////// @@ -345,7 +359,6 @@ output(ostream &out) const { out << get_coord(); } - /* if (has_normal()) { out << " normal " << get_normal(); } @@ -361,7 +374,6 @@ output(ostream &out) const { if (has_pixel_size()) { out << " pixel_size " << get_pixel_size(); } - */ } return out; } diff --git a/panda/src/builder/builderVertexTempl.h b/panda/src/builder/builderVertexTempl.h index ab98310842..95d03037b6 100644 --- a/panda/src/builder/builderVertexTempl.h +++ b/panda/src/builder/builderVertexTempl.h @@ -19,14 +19,15 @@ #ifndef BUILDERVERTEXTEMPL_H #define BUILDERVERTEXTEMPL_H -#include +#include "pandabase.h" #include "builderTypes.h" #include "builderAttribTempl.h" +#include "builder_compare.h" +#include "notify.h" #include "pvector.h" - ///////////////////////////////////////////////////////////////////// // Class : BuilderVertexTempl // Description : The main body of BuilderVertex and BuilderVertexI. @@ -68,9 +69,10 @@ public: INLINE BuilderVertexTempl &set_pixel_size(float s); INLINE BuilderVertexTempl &clear_pixel_size(); - bool operator == (const BuilderVertexTempl &other) const; + INLINE bool operator == (const BuilderVertexTempl &other) const; INLINE bool operator != (const BuilderVertexTempl &other) const; - bool operator < (const BuilderVertexTempl &other) const; + INLINE bool operator < (const BuilderVertexTempl &other) const; + int compare_to(const BuilderVertexTempl &other) const; ostream &output(ostream &out) const; diff --git a/panda/src/builder/builder_compare.I b/panda/src/builder/builder_compare.I new file mode 100644 index 0000000000..884dbf8637 --- /dev/null +++ b/panda/src/builder/builder_compare.I @@ -0,0 +1,37 @@ +// Filename: builder_compare.I +// Created by: drose (31Jul01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +INLINE int +builder_compare(const LVecBase2f &a, const LVecBase2f &b) { + return a.compare_to(b); +} + +INLINE int +builder_compare(const LVecBase3f &a, const LVecBase3f &b) { + return a.compare_to(b); +} + +INLINE int +builder_compare(const LVecBase4f &a, const LVecBase4f &b) { + return a.compare_to(b); +} + +INLINE int +builder_compare(ushort a, ushort b) { + return (int)a - (int)b; +} diff --git a/panda/src/builder/builder_compare.h b/panda/src/builder/builder_compare.h new file mode 100644 index 0000000000..bf69bde35d --- /dev/null +++ b/panda/src/builder/builder_compare.h @@ -0,0 +1,40 @@ +// Filename: builder_compare.h +// Created by: drose (31Jul01) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef BUILDERCOMPARE_H +#define BUILDERCOMPARE_H + +#include "pandabase.h" + +#include "luse.h" + + +// This file defines some trivial functions that return strcmp-style +// comparisonresults for the major types of our vertices. This allows +// us to write type-independent template code to compare vertex +// values for equivalence or order relationships. + +INLINE int builder_compare(const LVecBase2f &a, const LVecBase2f &b); +INLINE int builder_compare(const LVecBase3f &a, const LVecBase3f &b); +INLINE int builder_compare(const LVecBase4f &a, const LVecBase4f &b); +INLINE int builder_compare(ushort a, ushort b); + +#include "builder_compare.I" + +#endif +