QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgsbillboardgeometry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbillboardgeometry.cpp
3  --------------------------------------
4  Date : Jul 2019
5  Copyright : (C) 2019 by Ismail Sunni
6  Email : imajimatika at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include <QVector3D>
17 
18 #include "qgsbillboardgeometry.h"
19 
21  : Qt3DRender::QGeometry( parent )
22  , mPositionAttribute( new Qt3DRender::QAttribute( this ) )
23 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
24  , mVertexBuffer( new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, this ) )
25 #else
26  , mVertexBuffer( new Qt3DRender::QBuffer( this ) )
27 #endif
28 {
29 
30  mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
31  mPositionAttribute->setBuffer( mVertexBuffer );
32  mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
33  mPositionAttribute->setVertexSize( 3 );
34  mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
35 
36  addAttribute( mPositionAttribute );
37 
38 }
39 
40 void QgsBillboardGeometry::setPoints( const QVector<QVector3D> &vertices )
41 {
42  QByteArray vertexBufferData;
43  vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
44  float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
45  int idx = 0;
46  for ( const auto &v : vertices )
47  {
48  rawVertexArray[idx++] = v.x();
49  rawVertexArray[idx++] = v.y();
50  rawVertexArray[idx++] = v.z();
51  }
52 
53  mVertexCount = vertices.count();
54  mVertexBuffer->setData( vertexBufferData );
55 
56  emit countChanged( mVertexCount );
57 
58 }
59 
61 {
62  return mVertexCount;
63 }
64 
65 
void countChanged(int count)
Signal when the number of points changed.
int count() const
Returns the number of points.
void setPoints(const QVector< QVector3D > &vertices)
Set the points for the billboard with vertices.
QgsBillboardGeometry(Qt3DCore::QNode *parent=nullptr)
Constructor of QgsBillboardGeometry.