Panda3D
 All Classes Functions Variables Enumerations
eggMesherStrip.I
1 // Filename: eggMesherStrip.I
2 // Created by: drose (13Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: EggMesherStrip::Copy Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE EggMesherStrip::
22 EggMesherStrip(const EggMesherStrip &copy) :
23  _prims(copy._prims),
24  _edges(copy._edges),
25  _verts(copy._verts),
26  _type(copy._type),
27  _index(copy._index),
28  _status(copy._status),
29  _planar(copy._planar),
30  _plane_normal(copy._plane_normal),
31  _plane_offset(copy._plane_offset),
32  _row_id(copy._row_id),
33  _flat_shaded(copy._flat_shaded)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: EggMesherStrip::is_coplanar_with
39 // Access: Public
40 // Description: Returns true if the strip and the other strip are
41 // coplanar, within the indicated threshold. See
42 // coplanarity().
43 ////////////////////////////////////////////////////////////////////
44 INLINE bool EggMesherStrip::
45 is_coplanar_with(const EggMesherStrip &other, PN_stdfloat threshold) const {
46  return (coplanarity(other) <= threshold);
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: EggMesherStrip::coplanarity
51 // Access: Public
52 // Description: Returns the degree to which the two strips are
53 // coplanar. 0.0 is exactly coplanar; numbers somewhat
54 // larger than zero indicate less coplanar. 1.0 is
55 // at right angles; 2.0 is exactly backfacing. If
56 // either strip is not itself planar, 3.0 is returned.
57 ////////////////////////////////////////////////////////////////////
58 INLINE PN_stdfloat EggMesherStrip::
59 coplanarity(const EggMesherStrip &other) const {
60  if (_planar && other._planar) {
61  return 1.0 - dot(_plane_normal, other._plane_normal);
62  }
63  return 3.0;
64 }
65 
66 ////////////////////////////////////////////////////////////////////
67 // Function: EggMesherStrip::type_category
68 // Access: Public
69 // Description: Returns an integer which gives a heuristic about the
70 // similarity of different strip types. In general,
71 // closer numbers are more similar.
72 ////////////////////////////////////////////////////////////////////
73 INLINE int EggMesherStrip::
74 type_category() const {
75  switch (_type) {
76  case PT_tri:
77  return 1;
78 
79  case PT_tristrip:
80  return 2;
81 
82  case PT_quad:
83  case PT_quadstrip:
84  return 5;
85 
86  default:
87  return 10;
88  }
89 }
90 
91 
92 ////////////////////////////////////////////////////////////////////
93 // Function: EggMesherStrip::rotate_forward
94 // Access: Public
95 // Description: Rotates a triangle or quad by bringing its first
96 // vertex to the back.
97 ////////////////////////////////////////////////////////////////////
98 INLINE void EggMesherStrip::
100  _verts.push_back(_verts.front());
101  _verts.pop_front();
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: EggMesherStrip::rotate_back
106 // Access: Public
107 // Description: Rotates a triangle or quad by bringing its last
108 // vertex to the front.
109 ////////////////////////////////////////////////////////////////////
110 INLINE void EggMesherStrip::
112  _verts.push_front(_verts.back());
113  _verts.pop_back();
114 }
115 
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: EggMesherStrip::get_head_edge
119 // Access: Public
120 // Description: Returns an EggMesherEdge which represents the leading
121 // edge in the quadstrip or tristrip. This
122 // EggMesherEdge will not have pointer equality with any
123 // shared EggMesherEdge.
124 ////////////////////////////////////////////////////////////////////
126 get_head_edge() const {
127  Verts::const_iterator vi = _verts.begin();
128  nassertr(vi != _verts.end(), EggMesherEdge(0, 0));
129  ++vi;
130  return EggMesherEdge(_verts.front(), *vi);
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: EggMesherStrip::get_tail_edge
135 // Access: Public
136 // Description: Returns an EggMesherEdge which represents the
137 // trailing edge in the quadstrip or tristrip. This
138 // EggMesherEdge will not have pointer equality with any
139 // shared EggMesherEdge.
140 ////////////////////////////////////////////////////////////////////
142 get_tail_edge() const {
143  Verts::const_reverse_iterator vi = _verts.rbegin();
144  nassertr(vi != _verts.rend(), EggMesherEdge(0, 0));
145  ++vi;
146  return EggMesherEdge(*vi, _verts.back());
147 }
148 
149 ////////////////////////////////////////////////////////////////////
150 // Function: EggMesherStrip::operator ==
151 // Access: Public
152 // Description: Defines equality for strips. This actually tests
153 // only pointer equality; it's used only when removing a
154 // strip from the list.
155 ////////////////////////////////////////////////////////////////////
156 INLINE bool EggMesherStrip::
157 operator == (const EggMesherStrip &other) const {
158  return this == &other;
159 }
160 
161 ////////////////////////////////////////////////////////////////////
162 // Function: EggMesherStrip::operator !=
163 // Access: Public
164 // Description:
165 ////////////////////////////////////////////////////////////////////
166 INLINE bool EggMesherStrip::
167 operator != (const EggMesherStrip &other) const {
168  return !operator == (other);
169 }
bool operator==(const EggMesherStrip &other) const
Defines equality for strips.
void rotate_forward()
Rotates a triangle or quad by bringing its first vertex to the back.
void rotate_back()
Rotates a triangle or quad by bringing its last vertex to the front.
EggMesherEdge get_tail_edge() const
Returns an EggMesherEdge which represents the trailing edge in the quadstrip or tristrip.
Represents one edge of a triangle, as used by the EggMesher to discover connected triangles...
Definition: eggMesherEdge.h:32
bool is_coplanar_with(const EggMesherStrip &other, PN_stdfloat threshold) const
Returns true if the strip and the other strip are coplanar, within the indicated threshold.
Represents a triangle strip or quad strip in progress, as assembled by the mesher.
EggMesherEdge get_head_edge() const
Returns an EggMesherEdge which represents the leading edge in the quadstrip or tristrip.
PN_stdfloat coplanarity(const EggMesherStrip &other) const
Returns the degree to which the two strips are coplanar.
int type_category() const
Returns an integer which gives a heuristic about the similarity of different strip types...