Panda3D
eggPolygon.I
1 // Filename: eggPolygon.I
2 // Created by: drose (10Feb99)
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: EggPolygon::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE EggPolygon::
22 EggPolygon(const string &name) : EggPrimitive(name) {
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: EggPolygon::Copy constructor
27 // Access: Published
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 INLINE EggPolygon::
31 EggPolygon(const EggPolygon &copy) : EggPrimitive(copy) {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: EggPolygon::Copy assignment operator
36 // Access: Published
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 INLINE EggPolygon &EggPolygon::
40 operator = (const EggPolygon &copy) {
41  EggPrimitive::operator = (copy);
42  return *this;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: EggPolygon::recompute_polygon_normal
47 // Access: Published
48 // Description: Recalculates the normal according to the order of the
49 // vertices, and sets it. Returns true if the normal is
50 // computed correctly, or false if the polygon is
51 // degenerate and does not have a normal.
52 ////////////////////////////////////////////////////////////////////
53 INLINE bool EggPolygon::
54 recompute_polygon_normal(CoordinateSystem cs) {
55  LNormald normal;
56  if (calculate_normal(normal, cs)) {
57  set_normal(normal);
58  return true;
59  }
60  clear_normal();
61  return false;
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: EggPolygon::triangulate_into
66 // Access: Published
67 // Description: Subdivides the polygon into triangles and adds each
68 // one to the indicated container. If the polygon is
69 // already a triangle, adds an exact copy of the polygon
70 // to the container. Does not remove the polygon from
71 // its existing parent or modify it in any way.
72 //
73 // Returns true if the triangulation is successful, or
74 // false if there was some error (in which case the
75 // container may contain some partial triangulation).
76 //
77 // If convex_also is true, both concave and convex
78 // polygons will be subdivided into triangles;
79 // otherwise, only concave polygons will be subdivided,
80 // and convex polygons will be copied unchanged into the
81 // container.
82 ////////////////////////////////////////////////////////////////////
83 INLINE bool EggPolygon::
84 triangulate_into(EggGroupNode *container, bool convex_also) const {
85  PT(EggPolygon) copy = new EggPolygon(*this);
86  return copy->triangulate_poly(container, convex_also);
87 }
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
Definition: eggPrimitive.h:51
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
bool triangulate_into(EggGroupNode *container, bool convex_also) const
Subdivides the polygon into triangles and adds each one to the indicated container.
Definition: eggPolygon.I:84
A single polygon.
Definition: eggPolygon.h:26
bool recompute_polygon_normal(CoordinateSystem cs=CS_default)
Recalculates the normal according to the order of the vertices, and sets it.
Definition: eggPolygon.I:54
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:760
bool calculate_normal(LNormald &result, CoordinateSystem cs=CS_default) const
Calculates the true polygon normal–the vector pointing out of the front of the polygon–based on the...
Definition: eggPolygon.cxx:57