diff options
author | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-05-24 17:35:41 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2014-05-24 17:38:06 +0200 |
commit | 9ef8f82cb933f598d6bc9641f6bb937fce103ec9 (patch) | |
tree | 26cedc41502bb0cc1537794cb93945aff03b20e6 | |
parent | 20e4e65b656e3c47d2a0115ed3f17dabcb8d30da (diff) |
much improved camera control for 3D chart
Change-Id: I5acc481db01e2ea66c11933ec05f222858ba36f9
-rw-r--r-- | chart2/source/view/charttypes/GL3DBarChart.cxx | 27 | ||||
-rw-r--r-- | chart2/source/view/inc/3DChartObjects.hxx | 3 | ||||
-rw-r--r-- | chart2/source/view/inc/GL3DBarChart.hxx | 4 | ||||
-rw-r--r-- | chart2/source/view/main/3DChartObjects.cxx | 10 |
4 files changed, 42 insertions, 2 deletions
diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx index dbf0310b15c3..db1dc5b3be5c 100644 --- a/chart2/source/view/charttypes/GL3DBarChart.cxx +++ b/chart2/source/view/charttypes/GL3DBarChart.cxx @@ -54,6 +54,23 @@ float calculateTextWidth(const OUString& rText) return rText.getLength() * 10; } +double findMaxValue(const boost::ptr_vector<VDataSeries>& rDataSeriesContainer) +{ + double nMax = 0.0; + for (boost::ptr_vector<VDataSeries>::const_iterator itr = rDataSeriesContainer.begin(), + itrEnd = rDataSeriesContainer.end(); itr != itrEnd; ++itr) + { + const VDataSeries& rDataSeries = *itr; + sal_Int32 nPointCount = rDataSeries.getTotalPointCount(); + for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex) + { + double nVal = rDataSeries.getYValue(nIndex); + nMax = std::max(nMax, nVal); + } + } + return nMax; +} + } void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSeriesContainer, @@ -85,6 +102,8 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer mpCamera = static_cast<opengl3D::Camera*>(&maShapes.back()); sal_Int32 nSeriesIndex = 0; + sal_Int32 nMaxPointCount = 0; + double nMaxVal = findMaxValue(rDataSeriesContainer)/100; for (boost::ptr_vector<VDataSeries>::const_iterator itr = rDataSeriesContainer.begin(), itrEnd = rDataSeriesContainer.end(); itr != itrEnd; ++itr) { @@ -92,6 +111,7 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer const VDataSeries& rDataSeries = *itr; sal_Int32 nPointCount = rDataSeries.getTotalPointCount(); + nMaxPointCount = std::max(nMaxPointCount, nPointCount); bool bMappedFillProperty = rDataSeries.hasPropertyMapping("FillColor"); @@ -126,8 +146,7 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer float nVal = rDataSeries.getYValue(nIndex); float nXPos = nIndex * (nBarSizeX + nBarDistanceX) + nBarDistanceX; - - glm::mat4 aScaleMatrix = glm::scale(nBarSizeX, nBarSizeY, nVal); + glm::mat4 aScaleMatrix = glm::scale(nBarSizeX, nBarSizeY, float(nVal/nMaxVal)); glm::mat4 aTranslationMatrix = glm::translate(nXPos, nYPos, 0.0f); glm::mat4 aBarPosition = aTranslationMatrix * aScaleMatrix; @@ -207,6 +226,10 @@ void GL3DBarChart::create3DShapes(const boost::ptr_vector<VDataSeries>& rDataSer aBottomRight.y = -calculateTextWidth(aCats[i]) - 0.5 * nBarDistanceY; p->setPosition(aTopLeft, aTopRight, aBottomRight); } + + maCameraPosition = glm::vec3(-30, -30, 200); + mpCamera->setPosition(maCameraPosition); + mpCamera->setDirection(glm::vec3(nMaxPointCount*(nBarSizeX+ nBarDistanceX), nSeriesIndex*(nBarSizeY+nBarDistanceY), 0)); } void GL3DBarChart::render() diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx index c92a435d4797..1530dfce0979 100644 --- a/chart2/source/view/inc/3DChartObjects.hxx +++ b/chart2/source/view/inc/3DChartObjects.hxx @@ -115,6 +115,9 @@ public: Camera(OpenGL3DRenderer* pRenderer); virtual void render() SAL_OVERRIDE; + void setPosition(const glm::vec3& rPos); + void setDirection(const glm::vec3& rPos); + /// Zooms the camera towards the bar with Unique Id nId. void zoom(sal_uInt32 nId); diff --git a/chart2/source/view/inc/GL3DBarChart.hxx b/chart2/source/view/inc/GL3DBarChart.hxx index 15fffde7c6fb..0ca4e232d81b 100644 --- a/chart2/source/view/inc/GL3DBarChart.hxx +++ b/chart2/source/view/inc/GL3DBarChart.hxx @@ -16,6 +16,8 @@ #include <boost/ptr_container/ptr_vector.hpp> #include "VDataSeries.hxx" +#include <glm/glm.hpp> + #include <vcl/openglwin.hxx> namespace chart { @@ -61,6 +63,8 @@ private: bool mbValidContext; boost::scoped_ptr<opengl3D::TextCache> mpTextCache; + + glm::vec3 maCameraPosition; }; } diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx index ea20774720c8..c77a273df5c0 100644 --- a/chart2/source/view/main/3DChartObjects.cxx +++ b/chart2/source/view/main/3DChartObjects.cxx @@ -186,6 +186,16 @@ void Camera::render() mpRenderer->SetCameraInfo(maPos, maDirection, maUp); } +void Camera::setPosition(const glm::vec3& rPos) +{ + maPos = rPos; +} + +void Camera::setDirection(const glm::vec3& rDir) +{ + maDirection = rDir; +} + void Camera::zoom(sal_uInt32 /*nId*/) { // TODO here |