blob: e8db5bfb47c089cfa17237f88010ed59fff9414a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <GL/glew.h>
#include "3DBarChart.hxx"
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include "3DChartObjects.hxx"
namespace chart {
Bar3DChart::Bar3DChart(const std::vector<VDataSeries*>& rDataSeries):
maDataSeries(rDataSeries),
mxContext(new opengl3D::temporary::TemporaryContext())
{
}
Bar3DChart::~Bar3DChart()
{
}
void Bar3DChart::create3DShapes()
{
const float nBarSizeX = 10;
const float nBarSizeY = 10;
const float nBarDistanceX = nBarSizeX / 2;
const float nBarDistanceY = nBarSizeY / 2;
sal_Int32 nSeriesIndex = 0;
for(std::vector<VDataSeries*>::const_iterator itr = maDataSeries.begin(),
itrEnd = maDataSeries.end(); itr != itrEnd; ++itr)
{
VDataSeries* pDataSeries = *itr;
sal_Int32 nPointCount = pDataSeries->getTotalPointCount();
for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex)
{
float nVal = pDataSeries->getYValue(nIndex);
float nXPos = nIndex * (nBarSizeX + nBarDistanceX);
float nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY);
glm::mat4 aBarPosition;
glm::scale(aBarPosition, nBarSizeX, nBarSizeY, nVal);
glm::translate(aBarPosition, nXPos, nYPos, nVal/2);
maShapes.push_back(new opengl3D::Bar(aBarPosition));
}
++nSeriesIndex;
}
}
void Bar3DChart::render()
{
mxContext->init();
for(boost::ptr_vector<opengl3D::Renderable3DObject>::iterator itr = maShapes.begin(),
itrEnd = maShapes.end(); itr != itrEnd; ++itr)
{
itr->render();
}
mxContext->render();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|