SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLPolyline.h
Go to the documentation of this file.
1 /**
2  * \file SLPolyline.h
3  * \date July 2016
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLPOLYLINE_H
11 #define SLPOLYLINE_H
12 
13 #include <SLMesh.h>
14 
15 #include <utility>
16 
17 //-----------------------------------------------------------------------------
18 //! SLPolyline creates a polyline object
19 /*!
20 The SLPolyline node draws a polyline object
21 */
22 class SLPolyline : public SLMesh
23 {
24 public:
25  explicit SLPolyline(SLAssetManager* assetMgr,
26  const SLstring& name = "Polyline") : SLMesh(assetMgr, name){};
27 
28  //! ctor for polyline with a vector of points
30  const SLVVec3f& points,
31  SLbool closed = false,
32  const SLstring& name = "Polyline",
33  SLMaterial* material = nullptr) : SLMesh(assetMgr, name)
34  {
35  buildMesh(points, closed, material);
36  }
37 
38  void buildMesh(const SLVVec3f& points,
39  SLbool closed = false,
40  SLMaterial* material = nullptr)
41  {
42  assert(points.size() > 1);
43  P = points;
44  _primitive = closed ? PT_lineLoop : PT_lines;
45  mat(material);
46  if (P.size() < 65535)
47  for (SLuint i = 0; i < P.size(); ++i)
48  I16.push_back((SLushort)i);
49  else
50  for (SLuint i = 0; i < P.size(); ++i)
51  I32.push_back(i);
52  }
53 };
54 //-----------------------------------------------------------------------------
55 #endif
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
unsigned short SLushort
Definition: SL.h:169
string SLstring
Definition: SL.h:158
@ PT_lines
Definition: SLGLEnums.h:32
@ PT_lineLoop
Definition: SLGLEnums.h:33
vector< SLVec3f > SLVVec3f
Definition: SLVec3.h:325
Toplevel holder of the assets meshes, materials, textures and shaders.
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLVuint I32
Vector of vertex indices 32 bit.
Definition: SLMesh.h:215
SLVushort I16
Vector of vertex indices 16 bit.
Definition: SLMesh.h:214
SLGLPrimitiveType _primitive
Primitive type (default triangles)
Definition: SLMesh.h:231
SLVVec3f P
Vector for vertex positions layout (location = 0)
Definition: SLMesh.h:203
SLMaterial * mat() const
Definition: SLMesh.h:177
const SLstring & name() const
Definition: SLObject.h:38
SLPolyline creates a polyline object.
Definition: SLPolyline.h:23
SLPolyline(SLAssetManager *assetMgr, const SLstring &name="Polyline")
Definition: SLPolyline.h:25
void buildMesh(const SLVVec3f &points, SLbool closed=false, SLMaterial *material=nullptr)
Definition: SLPolyline.h:38
SLPolyline(SLAssetManager *assetMgr, const SLVVec3f &points, SLbool closed=false, const SLstring &name="Polyline", SLMaterial *material=nullptr)
ctor for polyline with a vector of points
Definition: SLPolyline.h:29