Panda3D
lineSegs.I
1 // Filename: lineSegs.I
2 // Created by: drose (16Mar02)
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 // Function: LineSegs::Point::Constructor
17 // Access: Public
18 // Description:
19 ////////////////////////////////////////////////////////////////////
20 INLINE LineSegs::Point::
21 Point() {
22 }
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: LineSegs::Point::Constructor
26 // Access: Public
27 // Description:
28 ////////////////////////////////////////////////////////////////////
29 INLINE LineSegs::Point::
30 Point(const LVecBase3 &point, const LColor &color) :
31  _point(point[0], point[1], point[2]),
32  _color(color)
33 {
34 }
35 
36 ////////////////////////////////////////////////////////////////////
37 // Function: LineSegs::Point::Copy Constructor
38 // Access: Public
39 // Description:
40 ////////////////////////////////////////////////////////////////////
41 INLINE LineSegs::Point::
42 Point(const LineSegs::Point &copy) :
43  _point(copy._point),
44  _color(copy._color)
45 {
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: LineSegs::Point::Copy Assignment Operator
50 // Access: Public
51 // Description:
52 ////////////////////////////////////////////////////////////////////
53 INLINE void LineSegs::Point::
54 operator = (const LineSegs::Point &copy) {
55  _point = copy._point;
56  _color = copy._color;
57 }
58 
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: LineSegs::set_color
62 // Access: Public
63 // Description: Establishes the color that will be assigned to all
64 // vertices created by future calls to move_to() and
65 // draw_to().
66 ////////////////////////////////////////////////////////////////////
67 INLINE void LineSegs::
68 set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
69  _color.set(r, g, b, a);
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: LineSegs::set_color
74 // Access: Public
75 // Description: Establishes the color that will be assigned to all
76 // vertices created by future calls to move_to() and
77 // draw_to().
78 ////////////////////////////////////////////////////////////////////
79 INLINE void LineSegs::
81  _color = color;
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: LineSegs::set_thickness
86 // Access: Public
87 // Description: Establishes the line thickness or point size in
88 // pixels that will be assigned to all lines and points
89 // created by future calls to create().
90 ////////////////////////////////////////////////////////////////////
91 INLINE void LineSegs::
92 set_thickness(PN_stdfloat thick) {
93  _thick = thick;
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: LineSegs::move_to
98 // Access: Public
99 // Description: Moves the pen to the given point without drawing a
100 // line. When followed by draw_to(), this marks the
101 // first point of a line segment; when followed by
102 // move_to() or create(), this creates a single point.
103 ////////////////////////////////////////////////////////////////////
104 INLINE void LineSegs::
105 move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
106  move_to(LVertex(x, y, z));
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function: LineSegs::draw_to
111 // Access: Public
112 // Description: Draws a line segment from the pen's last position
113 // (the last call to move_to or draw_to) to the
114 // indicated point. move_to() and draw_to() only update
115 // tables; the actual drawing is performed when create()
116 // is called.
117 ////////////////////////////////////////////////////////////////////
118 INLINE void LineSegs::
119 draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
120  draw_to(LVertex(x, y, z));
121 }
122 
123 ////////////////////////////////////////////////////////////////////
124 // Function: LineSegs::create
125 // Access: Public
126 // Description: Creates a new GeomNode that will render the series of
127 // line segments and points described via calls to
128 // move_to() and draw_to(). The lines and points are
129 // created with the color and thickness established by
130 // calls to set_color() and set_thick().
131 //
132 // If dynamic is true, the line segments will be created
133 // with the dynamic Geom setting, optimizing them for
134 // runtime vertex animation.
135 ////////////////////////////////////////////////////////////////////
136 INLINE GeomNode *LineSegs::
137 create(bool dynamic) {
138  GeomNode *gnode = new GeomNode(get_name());
139  return create(gnode, dynamic);
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: LineSegs::get_num_vertices
144 // Access: Public
145 // Description: Returns the total number of line segment and point
146 // vertices generated by the last call to create(). The
147 // positions of these vertices may be read and adjusted
148 // through get_vertex() and set_vertex().
149 ////////////////////////////////////////////////////////////////////
150 INLINE int LineSegs::
152  if (_created_data == (GeomVertexData *)NULL) {
153  return 0;
154  }
155  return _created_data->get_num_rows();
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: LineSegs::set_vertex
160 // Access: Public
161 // Description: Moves the nth point or vertex of the line segment
162 // sequence generated by the last call to create(). The
163 // first move_to() generates vertex 0; subsequent
164 // move_to() and draw_to() calls generate consecutively
165 // higher vertex numbers.
166 ////////////////////////////////////////////////////////////////////
167 INLINE void LineSegs::
168 set_vertex(int n, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z) {
169  set_vertex(n, LVertex(x, y, z));
170 }
171 
172 ////////////////////////////////////////////////////////////////////
173 // Function: LineSegs::set_vertex_color
174 // Access: Public
175 // Description: Changes the vertex color of the nth point or vertex.
176 // See set_vertex().
177 ////////////////////////////////////////////////////////////////////
178 INLINE void LineSegs::
179 set_vertex_color(int n, PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
180  set_vertex_color(n, LColor(r, g, b, a));
181 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
GeomNode * create(bool dynamic=false)
Creates a new GeomNode that will render the series of line segments and points described via calls to...
Definition: lineSegs.I:137
void set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a=1.0f)
Establishes the color that will be assigned to all vertices created by future calls to move_to() and ...
Definition: lineSegs.I:68
void set_thickness(PN_stdfloat thick)
Establishes the line thickness or point size in pixels that will be assigned to all lines and points ...
Definition: lineSegs.I:92
void move_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Moves the pen to the given point without drawing a line.
Definition: lineSegs.I:105
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
void draw_to(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
Draws a line segment from the pen's last position (the last call to move_to or draw_to) to the indica...
Definition: lineSegs.I:119
void set_vertex(int n, const LVertex &vert)
Moves the nth point or vertex of the line segment sequence generated by the last call to create()...
Definition: lineSegs.cxx:146
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
int get_num_vertices() const
Returns the total number of line segment and point vertices generated by the last call to create()...
Definition: lineSegs.I:151
void set_vertex_color(int vertex, const LColor &c)
Changes the vertex color of the nth point or vertex.
Definition: lineSegs.cxx:173
A node that holds Geom objects, renderable pieces of geometry.
Definition: geomNode.h:37