QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  , mVertexBuffer( new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, this ) )
24 {
25 
26  mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
27  mPositionAttribute->setBuffer( mVertexBuffer );
28  mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
29  mPositionAttribute->setVertexSize( 3 );
30  mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
31 
32  addAttribute( mPositionAttribute );
33 
34 }
35 
36 void QgsBillboardGeometry::setPoints( const QVector<QVector3D> &vertices )
37 {
38  QByteArray vertexBufferData;
39  vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
40  float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
41  int idx = 0;
42  for ( const auto &v : vertices )
43  {
44  rawVertexArray[idx++] = v.x();
45  rawVertexArray[idx++] = v.y();
46  rawVertexArray[idx++] = v.z();
47  }
48 
49  mVertexCount = vertices.count();
50  mVertexBuffer->setData( vertexBufferData );
51 
52  emit countChanged( mVertexCount );
53 
54 }
55 
57 {
58  return mVertexCount;
59 }
60 
61 
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.