Panda3D
Classes | Public Member Functions | List of all members
LineSegs Class Reference

Encapsulates creation of a series of connected or disconnected line segments or points, for drawing paths or rays. More...

#include "lineSegs.h"

Inheritance diagram for LineSegs:
Namable MemoryBase

Public Member Functions

 LineSegs (const string &name="lines")
 Constructs a LineSegs object, which can be used to create any number of disconnected lines or points of various thicknesses and colors through the visible scene. More...
 
GeomNodecreate (bool dynamic=false)
 Creates a new GeomNode that will render the series of line segments and points described via calls to move_to() and draw_to(). More...
 
GeomNodecreate (GeomNode *previous, bool dynamic=false)
 Appends to an existing GeomNode a new Geom that will render the series of line segments and points described via calls to move_to() and draw_to(). More...
 
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 indicated point. More...
 
void draw_to (const LVecBase3 &v)
 Draws a line segment from the pen's last position (the last call to move_to or draw_to) to the indicated point. More...
 
const LVertex & get_current_position ()
 Returns the pen's current position. More...
 
int get_num_vertices () const
 Returns the total number of line segment and point vertices generated by the last call to create(). More...
 
LVertex get_vertex (int n) const
 Returns the nth point or vertex of the line segment sequence generated by the last call to create(). More...
 
LColor get_vertex_color (int vertex) const
 Returns the color of the nth point or vertex. More...
 
bool is_empty ()
 Returns true if move_to() or draw_to() have not been called since the last reset() or create(), false otherwise. More...
 
 MAKE_SEQ (get_vertices, get_num_vertices, get_vertex)
 
 MAKE_SEQ (get_vertex_colors, get_num_vertices, get_vertex_color)
 
void move_to (PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
 Moves the pen to the given point without drawing a line. More...
 
void move_to (const LVecBase3 &v)
 Moves the pen to the given point without drawing a line. More...
 
void reset ()
 Removes any lines in progress and resets to the initial empty state. More...
 
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 draw_to(). More...
 
void set_color (const LColor &color)
 Establishes the color that will be assigned to all vertices created by future calls to move_to() and draw_to(). More...
 
void set_thickness (PN_stdfloat thick)
 Establishes the line thickness or point size in pixels that will be assigned to all lines and points created by future calls to create(). More...
 
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(). More...
 
void set_vertex (int vertex, PN_stdfloat x, PN_stdfloat y, PN_stdfloat z)
 Moves the nth point or vertex of the line segment sequence generated by the last call to create(). More...
 
void set_vertex_color (int vertex, const LColor &c)
 Changes the vertex color of the nth point or vertex. More...
 
void set_vertex_color (int vertex, PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a=1.0f)
 Changes the vertex color of the nth point or vertex. More...
 
- Public Member Functions inherited from Namable
 Namable (const string &initial_name="")
 
 Namable (const Namable &copy)
 
void clear_name ()
 Resets the Namable's name to empty. More...
 
const string & get_name () const
 
bool has_name () const
 Returns true if the Namable has a nonempty name set, false if the name is empty. More...
 
Namableoperator= (const Namable &other)
 
void output (ostream &out) const
 Outputs the Namable. More...
 
void set_name (const string &name)
 

Additional Inherited Members

- Static Public Member Functions inherited from Namable
static TypeHandle get_class_type ()
 
static void init_type ()
 

Detailed Description

Encapsulates creation of a series of connected or disconnected line segments or points, for drawing paths or rays.

This class doesn't attempt to be the smartest it could possibly be; it's intended primarily as a visualization and editing tool.

Definition at line 36 of file lineSegs.h.

Constructor & Destructor Documentation

◆ LineSegs()

LineSegs::LineSegs ( const string &  name = "lines")

Constructs a LineSegs object, which can be used to create any number of disconnected lines or points of various thicknesses and colors through the visible scene.

After creating the object, call move_to() and draw_to() repeatedly to describe the path, then call create() to create a GeomNode which will render the described path.

Definition at line 37 of file lineSegs.cxx.

References reset().

Member Function Documentation

◆ create() [1/2]

GeomNode * LineSegs::create ( bool  dynamic = false)
inline

Creates a new GeomNode that will render the series of line segments and points described via calls to move_to() and draw_to().

The lines and points are created with the color and thickness established by calls to set_color() and set_thick().

If dynamic is true, the line segments will be created with the dynamic Geom setting, optimizing them for runtime vertex animation.

Definition at line 137 of file lineSegs.I.

References get_num_vertices().

Referenced by draw_to(), get_current_position(), PGEntry::setup_minimal(), and PathFind::trace_path().

◆ create() [2/2]

GeomNode * LineSegs::create ( GeomNode previous,
bool  dynamic = false 
)

Appends to an existing GeomNode a new Geom that will render the series of line segments and points described via calls to move_to() and draw_to().

The lines and points are created with the color and thickness established by calls to set_color() and set_thick().

If dynamic is true, the line segments will be created with the dynamic Geom setting, optimizing them for runtime vertex animation.

Definition at line 211 of file lineSegs.cxx.

References GeomVertexWriter::add_data3(), GeomVertexWriter::add_data4(), GeomNode::add_geom(), and reset().

◆ draw_to() [1/2]

void LineSegs::draw_to ( PN_stdfloat  x,
PN_stdfloat  y,
PN_stdfloat  z 
)
inline

Draws a line segment from the pen's last position (the last call to move_to or draw_to) to the indicated point.

move_to() and draw_to() only update tables; the actual drawing is performed when create() is called.

Definition at line 119 of file lineSegs.I.

References create().

Referenced by move_to(), PGEntry::setup_minimal(), and PathFind::trace_path().

◆ draw_to() [2/2]

void LineSegs::draw_to ( const LVecBase3 v)

Draws a line segment from the pen's last position (the last call to move_to or draw_to) to the indicated point.

move_to() and draw_to() only update tables; the actual drawing is performed when create() is called.

Definition at line 92 of file lineSegs.cxx.

References is_empty(), and move_to().

◆ get_current_position()

const LVertex & LineSegs::get_current_position ( )

Returns the pen's current position.

The next call to draw_to() will draw a line segment from this point.

Definition at line 187 of file lineSegs.cxx.

References create(), and move_to().

Referenced by set_vertex_color().

◆ get_num_vertices()

int LineSegs::get_num_vertices ( ) const
inline

Returns the total number of line segment and point vertices generated by the last call to create().

The positions of these vertices may be read and adjusted through get_vertex() and set_vertex().

Definition at line 151 of file lineSegs.I.

References set_vertex().

Referenced by create().

◆ get_vertex()

LVertex LineSegs::get_vertex ( int  n) const

Returns the nth point or vertex of the line segment sequence generated by the last call to create().

The first move_to() generates vertex 0; subsequent move_to() and draw_to() calls generate consecutively higher vertex numbers.

Definition at line 129 of file lineSegs.cxx.

References GeomVertexReader::get_data3(), GeomVertexReader::set_row_unsafe(), and set_vertex().

Referenced by is_empty().

◆ get_vertex_color()

LColor LineSegs::get_vertex_color ( int  vertex) const

Returns the color of the nth point or vertex.

Definition at line 159 of file lineSegs.cxx.

References GeomVertexReader::get_data4(), GeomVertexReader::set_row_unsafe(), set_vertex_color(), and LVecBase4f::zero().

Referenced by set_vertex().

◆ is_empty()

bool LineSegs::is_empty ( )

Returns true if move_to() or draw_to() have not been called since the last reset() or create(), false otherwise.

Definition at line 115 of file lineSegs.cxx.

References get_vertex().

Referenced by draw_to().

◆ move_to() [1/2]

void LineSegs::move_to ( PN_stdfloat  x,
PN_stdfloat  y,
PN_stdfloat  z 
)
inline

Moves the pen to the given point without drawing a line.

When followed by draw_to(), this marks the first point of a line segment; when followed by move_to() or create(), this creates a single point.

Definition at line 105 of file lineSegs.I.

References draw_to().

Referenced by draw_to(), get_current_position(), reset(), set_thickness(), PGEntry::setup_minimal(), and PathFind::trace_path().

◆ move_to() [2/2]

void LineSegs::move_to ( const LVecBase3 v)

Moves the pen to the given point without drawing a line.

When followed by draw_to(), this marks the first point of a line segment; when followed by move_to() or create(), this creates a single point.

Definition at line 73 of file lineSegs.cxx.

References draw_to().

◆ reset()

void LineSegs::reset ( )

Removes any lines in progress and resets to the initial empty state.

Definition at line 59 of file lineSegs.cxx.

References move_to().

Referenced by create(), and LineSegs().

◆ set_color() [1/2]

void LineSegs::set_color ( PN_stdfloat  r,
PN_stdfloat  g,
PN_stdfloat  b,
PN_stdfloat  a = 1.0f 
)
inline

Establishes the color that will be assigned to all vertices created by future calls to move_to() and draw_to().

Definition at line 68 of file lineSegs.I.

Referenced by PGEntry::setup_minimal().

◆ set_color() [2/2]

void LineSegs::set_color ( const LColor color)
inline

Establishes the color that will be assigned to all vertices created by future calls to move_to() and draw_to().

Definition at line 80 of file lineSegs.I.

References set_thickness().

◆ set_thickness()

void LineSegs::set_thickness ( PN_stdfloat  thick)
inline

Establishes the line thickness or point size in pixels that will be assigned to all lines and points created by future calls to create().

Definition at line 92 of file lineSegs.I.

References move_to().

Referenced by set_color().

◆ set_vertex() [1/2]

void LineSegs::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().

The first move_to() generates vertex 0; subsequent move_to() and draw_to() calls generate consecutively higher vertex numbers.

Definition at line 146 of file lineSegs.cxx.

References get_vertex_color(), GeomVertexWriter::set_data3(), and GeomVertexWriter::set_row_unsafe().

Referenced by get_num_vertices(), get_vertex(), and set_vertex().

◆ set_vertex() [2/2]

void LineSegs::set_vertex ( int  n,
PN_stdfloat  x,
PN_stdfloat  y,
PN_stdfloat  z 
)
inline

Moves the nth point or vertex of the line segment sequence generated by the last call to create().

The first move_to() generates vertex 0; subsequent move_to() and draw_to() calls generate consecutively higher vertex numbers.

Definition at line 168 of file lineSegs.I.

References set_vertex(), and set_vertex_color().

◆ set_vertex_color() [1/2]

void LineSegs::set_vertex_color ( int  n,
const LColor c 
)

Changes the vertex color of the nth point or vertex.

See set_vertex().

Definition at line 173 of file lineSegs.cxx.

References get_current_position(), GeomVertexWriter::set_data4(), and GeomVertexWriter::set_row_unsafe().

Referenced by get_vertex_color(), set_vertex(), and set_vertex_color().

◆ set_vertex_color() [2/2]

void LineSegs::set_vertex_color ( int  n,
PN_stdfloat  r,
PN_stdfloat  g,
PN_stdfloat  b,
PN_stdfloat  a = 1.0f 
)
inline

Changes the vertex color of the nth point or vertex.

See set_vertex().

Definition at line 179 of file lineSegs.I.

References set_vertex_color().


The documentation for this class was generated from the following files: