[Libreoffice-commits] core.git: Branch 'feature/chart-3d-chart' - 6 commits - chart2/source include/vcl vcl/source

Markus Mohrhard markus.mohrhard at collabora.co.uk
Sun May 11 18:02:25 PDT 2014


 chart2/source/view/charttypes/GL3DBarChart.cxx |    6 -
 chart2/source/view/inc/3DChartObjects.hxx      |    2 
 chart2/source/view/inc/GL3DRenderer.hxx        |    6 -
 chart2/source/view/inc/StaticGeometry.h        |   39 --------
 chart2/source/view/main/3DChartObjects.cxx     |   38 +-------
 chart2/source/view/main/GL3DRenderer.cxx       |  113 +++++++------------------
 include/vcl/opengl/OpenGLHelper.hxx            |    6 +
 vcl/source/opengl/OpenGLHelper.cxx             |   22 ++++
 8 files changed, 77 insertions(+), 155 deletions(-)

New commits:
commit 20fb711dc4b07f825a6c2f9622340659448e5d4f
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Mon May 12 02:57:51 2014 +0200

    Revert "separate rounded corner bar and normal bar rendering"
    
    This reverts commit 51d5062642189ff5a4330903253c012e83e5ef1f.
    
    Conflicts:
    	chart2/source/view/main/GL3DRenderer.cxx
    
    Change-Id: Id21e59d2cc605f0d7d637fb889725f0e91fa6cb3

diff --git a/chart2/source/view/inc/3DChartObjects.hxx b/chart2/source/view/inc/3DChartObjects.hxx
index f8138aa..8571fd8 100644
--- a/chart2/source/view/inc/3DChartObjects.hxx
+++ b/chart2/source/view/inc/3DChartObjects.hxx
@@ -37,7 +37,7 @@ protected:
 class Bar : public Renderable3DObject
 {
 public:
-    Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_uInt32 nColor, sal_uInt32 nId);
+    Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_Int32 nColor, sal_uInt32 nId);
 
     virtual void render() SAL_OVERRIDE;
 private:
diff --git a/chart2/source/view/inc/GL3DRenderer.hxx b/chart2/source/view/inc/GL3DRenderer.hxx
index 7840a02..5337384 100644
--- a/chart2/source/view/inc/GL3DRenderer.hxx
+++ b/chart2/source/view/inc/GL3DRenderer.hxx
@@ -90,6 +90,7 @@ struct Polygon3DInfo
 
 struct Extrude3DInfo
 {
+    bool rounded;
     bool twoSidesLighting;
     glm::vec4 extrudeColor;
     float xScale;
@@ -156,7 +157,7 @@ public:
     void EndAddPolygon3DObjectNormalPoint();
     void AddPolygon3DObjectPoint(float x, float y, float z);
     void EndAddPolygon3DObjectPoint();
-    void AddShape3DExtrudeObject(sal_Int32 color, sal_Int32 specular, glm::mat4 modelMatrix);
+    void AddShape3DExtrudeObject(bool roundedCorner, sal_Int32 color, sal_Int32 specular, glm::mat4 modelMatrix);
     void EndAddShape3DExtrudeObject();
     double GetTime();
     void SetFPS(float fps);
@@ -165,8 +166,6 @@ public:
     void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up);
     void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft);
     void ProcessUnrenderedShape();
-    void RenderNonRoundedBar(const glm::mat4& rModelMatrix, sal_uInt32 nColor);
-
 private:
     void MoveModelf(PosVecf3& trans,PosVecf3& angle,PosVecf3& scale);
 
@@ -190,6 +189,7 @@ private:
     void AddVertexData(GLuint vertexBuf);
     void AddNormalData(GLuint normalBuf);
     void AddIndexData(GLuint indexBuf);
+    void RenderNonRoundedBar(const Extrude3DInfo& extrude3D);
     bool GetSimilarVertexIndex(PackedVertex & packed,
         std::map<PackedVertex,unsigned short> & VertexToOutIndex,
         unsigned short & result
diff --git a/chart2/source/view/inc/StaticGeometry.h b/chart2/source/view/inc/StaticGeometry.h
index d3d5926..bdc8fe7 100644
--- a/chart2/source/view/inc/StaticGeometry.h
+++ b/chart2/source/view/inc/StaticGeometry.h
@@ -130,45 +130,6 @@ static GLfloat squareVertices[] = {
     -1.0f,  1.0f, -1.0
 };
 
-static const GLfloat cubeVertices[] = {
-    -1.0f,-1.0f,-1.0f,
-    -1.0f,-1.0f, 1.0f,
-    -1.0f, 1.0f, 1.0f,
-    1.0f, 1.0f,-1.0f,
-    -1.0f,-1.0f,-1.0f,
-    -1.0f, 1.0f,-1.0f,
-    1.0f,-1.0f, 1.0f,
-    -1.0f,-1.0f,-1.0f,
-    1.0f,-1.0f,-1.0f,
-    1.0f, 1.0f,-1.0f,
-    1.0f,-1.0f,-1.0f,
-    -1.0f,-1.0f,-1.0f,
-    -1.0f,-1.0f,-1.0f,
-    -1.0f, 1.0f, 1.0f,
-    -1.0f, 1.0f,-1.0f,
-    1.0f,-1.0f, 1.0f,
-    -1.0f,-1.0f, 1.0f,
-    -1.0f,-1.0f,-1.0f,
-    -1.0f, 1.0f, 1.0f,
-    -1.0f,-1.0f, 1.0f,
-    1.0f,-1.0f, 1.0f,
-    1.0f, 1.0f, 1.0f,
-    1.0f,-1.0f,-1.0f,
-    1.0f, 1.0f,-1.0f,
-    1.0f,-1.0f,-1.0f,
-    1.0f, 1.0f, 1.0f,
-    1.0f,-1.0f, 1.0f,
-    1.0f, 1.0f, 1.0f,
-    1.0f, 1.0f,-1.0f,
-    -1.0f, 1.0f,-1.0f,
-    1.0f, 1.0f, 1.0f,
-    -1.0f, 1.0f,-1.0f,
-    -1.0f, 1.0f, 1.0f,
-    1.0f, 1.0f, 1.0f,
-    -1.0f, 1.0f, 1.0f,
-    1.0f,-1.0f, 1.0f
-};
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index aa5d3bc..1c46509 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -28,7 +28,7 @@ void Renderable3DObject::render()
     (void) mnUniqueId;
 }
 
-Bar::Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_uInt32 aColor, sal_uInt32 nId)
+Bar::Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_Int32 aColor, sal_uInt32 nId)
     : Renderable3DObject(pRenderer, nId)
     , mbRoundedCorners(true)
     , maPos(rPosition)
@@ -39,15 +39,8 @@ Bar::Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_uInt32 aCo
 
 void Bar::render()
 {
-    if(mbRoundedCorners)
-    {
-        mpRenderer->AddShape3DExtrudeObject((sal_Int32)maColor.GetColor(), 0xFFFFFF, maPos);
-        mpRenderer->EndAddShape3DExtrudeObject();
-    }
-    else
-    {
-        mpRenderer->RenderNonRoundedBar(maPos, maColor.GetColor());
-    }
+    mpRenderer->AddShape3DExtrudeObject(mbRoundedCorners, (sal_Int32)maColor.GetColor(), 0xFFFFFF, maPos);
+    mpRenderer->EndAddShape3DExtrudeObject();
 }
 
 Line::Line(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index e8a5f04..d60d64f 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -919,7 +919,7 @@ void OpenGL3DRenderer::EndAddPolygon3DObjectPoint()
     m_Polygon3DInfo.vertices = NULL;
 }
 
-void OpenGL3DRenderer::AddShape3DExtrudeObject(sal_Int32 color,sal_Int32 specular, glm::mat4 modelMatrix)
+void OpenGL3DRenderer::AddShape3DExtrudeObject(bool roundedCorner, sal_Int32 color,sal_Int32 specular, glm::mat4 modelMatrix)
 {
     glm::vec4 tranform = modelMatrix * glm::vec4(0.0, 0.0, 0.0, 1.0);
     glm::vec4 DirX = modelMatrix * glm::vec4(1.0, 0.0, 0.0, 0.0);
@@ -954,7 +954,8 @@ void OpenGL3DRenderer::AddShape3DExtrudeObject(sal_Int32 color,sal_Int32 specula
     m_Extrude3DInfo.yTransform = tranform.y;
     m_Extrude3DInfo.zTransform = tranform.z;
 //    m_Extrude3DInfo.zTransform = 0;
-    if (m_RoundBarMesh.iMeshSizes == 0)
+    m_Extrude3DInfo.rounded = roundedCorner;
+    if (m_Extrude3DInfo.rounded && (m_RoundBarMesh.iMeshSizes == 0))
     {
         CreateActualRoundedCube(0.1f, 30, 30, 1.0f, 1.2f, m_Extrude3DInfo.zScale / m_Extrude3DInfo.xScale);
         AddVertexData(m_CubeVertexBuf);
@@ -1144,54 +1145,26 @@ void OpenGL3DRenderer::RenderExtrudeTopSurface(const Extrude3DInfo& extrude3D)
     RenderExtrudeFlatSurface(extrude3D, FLAT_BOTTOM_SURFACE);
 }
 
-namespace {
-
-glm::vec4 getColorAsVector(sal_uInt32 nColor)
+void OpenGL3DRenderer::RenderNonRoundedBar(const Extrude3DInfo& extrude3D)
 {
-    sal_uInt8 nRed = sal_uInt8((nColor & 0xFF0000) >> 16);
-    sal_uInt8 nGreen = sal_uInt8((nColor & 0xFF00) >> 8);
-    sal_uInt8 nBlue = sal_uInt8((nColor & 0xFF));
-    sal_uInt8 nAlpha = sal_uInt8((nColor & 0xFF000000) >> 24);
-    return glm::vec4(nRed/255.0, nGreen/255.0, nBlue/255.0, nAlpha/255.0);
-}
-
-}
-
-void OpenGL3DRenderer::RenderNonRoundedBar(const glm::mat4& modelMatrix, sal_uInt32 nColor)
-{
-    glm::mat4 aMVP = m_3DProjection * m_3DView * modelMatrix;
-    SAL_INFO("chart2.3dopengl", "render new bar");
-    SAL_INFO("chart2.3dopengl", aMVP);
-
-    for(size_t i = 0; i < SAL_N_ELEMENTS(cubeVertices); i += 3)
+    float xScale = extrude3D.xScale;
+    float yScale = extrude3D.yScale;
+    float zScale = extrude3D.zScale;
+    glUniformMatrix4fv(m_3DViewID, 1, GL_FALSE, &m_3DView[0][0]);
+    glUniformMatrix4fv(m_3DProjectionID, 1, GL_FALSE, &m_3DProjection[0][0]);
+    glm::mat4 transformMatrix = glm::translate(glm::vec3(extrude3D.xTransform, -extrude3D.yTransform, extrude3D.zTransform));
+    glm::mat4 scaleMatrix = glm::scale(xScale, yScale, zScale);
+    m_Model = transformMatrix * extrude3D.rotation * scaleMatrix;
+    if (extrude3D.reverse)
     {
-        glm::vec4 aPos(cubeVertices[i*3], cubeVertices[i*3+1], cubeVertices[i*3+2], 1.0);
-        glm::vec4 aNewPos = aMVP * aPos;
-        SAL_INFO("chart2.3dopengl", aNewPos);
+        glm::mat4 reverseMatrix = glm::translate(glm::vec3(0.0, -1.0, 0.0));
+        m_Model = m_Model * reverseMatrix;
     }
-
-    glm::vec4 aColor = getColorAsVector(nColor);
-    glUseProgram(m_CommonProID);
-    //fill vertex buffer
-    glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
-    glBufferData(GL_ARRAY_BUFFER, sizeof(cubeVertices), cubeVertices, GL_STATIC_DRAW);
-    glUniform4fv(m_2DColorID, 1, &aColor[0]);
-    glUniformMatrix4fv(m_MatrixID, 1, GL_FALSE, &aMVP[0][0]);
-    // 1rst attribute buffer : vertices
-    glEnableVertexAttribArray(m_2DVertexID);
-    glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
-    glVertexAttribPointer(m_2DVertexID,
-            3,                  // size
-            GL_FLOAT,           // type
-            GL_FALSE,           // normalized?
-            0,                  // stride
-            (void*)0            // array buffer offset
-            );
-
+    glm::mat3 normalMatrix(m_Model);
+    glm::mat3 normalInverseTranspos = glm::inverseTranspose(normalMatrix);
+    glUniformMatrix4fv(m_3DModelID, 1, GL_FALSE, &m_Model[0][0]);
+    glUniformMatrix3fv(m_3DNormalMatrixID, 1, GL_FALSE, &normalInverseTranspos[0][0]);
     glDrawArrays(GL_TRIANGLES, 0, 36);
-    glDisableVertexAttribArray(m_2DVertexID);
-    glBindBuffer(GL_ARRAY_BUFFER, 0);
-    glUseProgram(0);
 }
 
 void OpenGL3DRenderer::RenderExtrudeSurface(const Extrude3DInfo& extrude3D)
@@ -1225,8 +1198,8 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
     for (size_t i = 0; i < extrude3DNum; i++)
     {
         Extrude3DInfo extrude3DInfo = m_Extrude3DList[i];
-        GLuint vertexBuf = m_CubeVertexBuf;
-        GLuint normalBuf = m_CubeNormalBuf;
+        GLuint vertexBuf = extrude3DInfo.rounded ? m_CubeVertexBuf : m_BoundBox;
+        GLuint normalBuf = extrude3DInfo.rounded ? m_CubeNormalBuf : m_BoundBoxNormal;
         // 1st attribute buffer : vertices
         glEnableVertexAttribArray(m_3DVertexID);
         glBindBuffer(GL_ARRAY_BUFFER, vertexBuf);
@@ -1254,8 +1227,15 @@ void OpenGL3DRenderer::RenderExtrude3DObject()
         CHECK_GL_ERROR();
         glBindBuffer(GL_UNIFORM_BUFFER, 0);
         extrude3DInfo.reverse = 0;
-        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CubeElementBuf);
-        RenderExtrudeSurface(extrude3DInfo);
+        if (extrude3DInfo.rounded)
+        {
+            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_CubeElementBuf);
+            RenderExtrudeSurface(extrude3DInfo);
+        }
+        else
+        {
+            RenderNonRoundedBar(extrude3DInfo);
+        }
         glDisableVertexAttribArray(m_3DVertexID);
         glDisableVertexAttribArray(m_3DNormalID);
     }
commit ab3dc7c2576af9ed0fd7f4c4f0148790bd7abec6
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Mon May 12 02:55:06 2014 +0200

    Revert "fix alpha calculation"
    
    This reverts commit 204efb6a1723f98ff53a61ed249dbff8cb391bb3.
    
    Change-Id: I1756c399adbf0dd3371e8aab1d8021931203c49e

diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 58e5e20..e8a5f04 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -327,12 +327,10 @@ void OpenGL3DRenderer::CreateActualRoundedCube(float fRadius, int iSubDivY, int
     m_RoundBarMesh.topThreshold = topThreshold;
     m_RoundBarMesh.bottomThreshold = bottomThreshold;
     m_RoundBarMesh.iMeshStartIndices = m_Vertices.size();
-
     for (int k = 0; k < 5; k++)
     {
         m_RoundBarMesh.iElementStartIndices[k] = indeices[k].size();
     }
-
     for (size_t i = 0; i < vertices.size(); i += 3)
     {
         for (int k = 0; k < 3; k++)
@@ -409,12 +407,9 @@ int OpenGL3DRenderer::GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, s
         {
             fNextAngleY = 360.0f;
         }
-        float fSineY = sin(fCurAngleY/180.0f*PI);
-        float fCosY = cos(fCurAngleY/180.0f*PI);
-        float fNextSineY = sin(fNextAngleY/180.0f*PI);
-        float fNextCosY = cos(fNextAngleY/180.0f*PI);
-        glm::vec3 vDirY(fCosY, 0.0f, -fSineY);
-        glm::vec3 vNextDirY(fNextCosY, 0.0f, -fNextSineY);
+        float fSineY = sin(fCurAngleY/180.0f*PI), fCosY = cos(fCurAngleY/180.0f*PI);
+        float fNextSineY = sin(fNextAngleY/180.0f*PI), fNextCosY = cos(fNextAngleY/180.0f*PI);
+        glm::vec3 vDirY(fCosY, 0.0f, -fSineY), vNextDirY(fNextCosY, 0.0f, -fNextSineY);
         float fCurAngleZ = 0.0f;
         int iStepsZ = 1;
         int xzIndex = 0;
@@ -434,7 +429,6 @@ int OpenGL3DRenderer::GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, s
         {
             xzIndex = 3;
         }
-
         while(iStepsZ <= iSubDivZ)
         {
             int yIndex = 0;
@@ -481,7 +475,6 @@ int OpenGL3DRenderer::GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, s
                 glm::normalize(vQuadPoints[2]),
                 glm::normalize(vQuadPoints[3])
             };
-
             for (int i = 0; i < 6; i++)
             {
                 int index = iIndices[i];
@@ -1159,7 +1152,7 @@ glm::vec4 getColorAsVector(sal_uInt32 nColor)
     sal_uInt8 nGreen = sal_uInt8((nColor & 0xFF00) >> 8);
     sal_uInt8 nBlue = sal_uInt8((nColor & 0xFF));
     sal_uInt8 nAlpha = sal_uInt8((nColor & 0xFF000000) >> 24);
-    return glm::vec4(nRed/255.0, nGreen/255.0, nBlue/255.0, (0xFF - nAlpha)/255.0);
+    return glm::vec4(nRed/255.0, nGreen/255.0, nBlue/255.0, nAlpha/255.0);
 }
 
 }
@@ -1172,16 +1165,12 @@ void OpenGL3DRenderer::RenderNonRoundedBar(const glm::mat4& modelMatrix, sal_uIn
 
     for(size_t i = 0; i < SAL_N_ELEMENTS(cubeVertices); i += 3)
     {
-        glm::vec4 aPos(cubeVertices[i], cubeVertices[i+1], cubeVertices[i+2], 1.0);
-        SAL_INFO("chart2.3dopengl", aPos);
-        glm::vec4 aWorldPos = modelMatrix * aPos;
-        SAL_INFO("chart2.3dopengl", aWorldPos);
+        glm::vec4 aPos(cubeVertices[i*3], cubeVertices[i*3+1], cubeVertices[i*3+2], 1.0);
         glm::vec4 aNewPos = aMVP * aPos;
         SAL_INFO("chart2.3dopengl", aNewPos);
     }
 
     glm::vec4 aColor = getColorAsVector(nColor);
-    SAL_INFO("chart2.3dopengl", "Color: " << aColor);
     glUseProgram(m_CommonProID);
     //fill vertex buffer
     glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
commit 80bdca98d45522c197e8d4b42abeb2d518a66b45
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun May 11 18:04:01 2014 +0200

    move glm operator<< for debugging to OpenGLHelper
    
    Change-Id: Ia529badffe08507d593f494230d2e504b68ff477

diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 202eb97..aa5d3bc 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -11,31 +11,12 @@
 #include <vcl/virdev.hxx>
 #include <vcl/svapp.hxx>
 
-#include <ostream>
+#include <vcl/opengl/OpenGLHelper.hxx>
 
 namespace chart {
 
 namespace opengl3D {
 
-namespace {
-
-std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
-{
-    for(int i = 0; i < 4; ++i)
-    {
-        rStrm << "( ";
-        for(int j = 0; j < 4; ++j)
-        {
-            rStrm << rMatrix[j][i];
-            rStrm << " ";
-        }
-        rStrm << ")\n";
-    }
-    return rStrm;
-}
-
-}
-
 Renderable3DObject::Renderable3DObject(OpenGL3DRenderer* pRenderer, sal_uInt32 nId):
     mpRenderer(pRenderer),
     mnUniqueId(nId)
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 56a421e..58e5e20 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1162,27 +1162,6 @@ glm::vec4 getColorAsVector(sal_uInt32 nColor)
     return glm::vec4(nRed/255.0, nGreen/255.0, nBlue/255.0, (0xFF - nAlpha)/255.0);
 }
 
-std::ostream& operator<<(std::ostream& rStrm, const glm::vec4& rPos)
-{
-    rStrm << "( " << rPos[0] << ", " << rPos[1] << ", " << rPos[2] << ", " << rPos[3] << ")";
-    return rStrm;
-}
-
-std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
-{
-    for(int i = 0; i < 4; ++i)
-    {
-        rStrm << "\n( ";
-        for(int j = 0; j < 4; ++j)
-        {
-            rStrm << rMatrix[j][i];
-            rStrm << " ";
-        }
-        rStrm << ")\n";
-    }
-    return rStrm;
-}
-
 }
 
 void OpenGL3DRenderer::RenderNonRoundedBar(const glm::mat4& modelMatrix, sal_uInt32 nColor)
diff --git a/include/vcl/opengl/OpenGLHelper.hxx b/include/vcl/opengl/OpenGLHelper.hxx
index 4afeae4..3cb482b 100644
--- a/include/vcl/opengl/OpenGLHelper.hxx
+++ b/include/vcl/opengl/OpenGLHelper.hxx
@@ -11,11 +11,14 @@
 #define INCLUDED_VCL_OPENGL_OPENGLHELPER_HXX
 
 #include <GL/glew.h>
+#include "glm/glm.hpp"
 #include <vcl/vclopengl_dllapi.hxx>
 #include <vcl/bitmapex.hxx>
 
 #include <rtl/ustring.hxx>
 
+#include <ostream>
+
 class VCLOPENGL_DLLPUBLIC OpenGLHelper
 {
 public:
@@ -28,6 +31,9 @@ public:
     static const char* GLErrorString(GLenum errorCode);
 };
 
+VCLOPENGL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix);
+VCLOPENGL_DLLPUBLIC std::ostream& operator<<(std::ostream& rStrm, const glm::vec4& rPos);
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx
index 4ef2ce0..0e9d710 100644
--- a/vcl/source/opengl/OpenGLHelper.cxx
+++ b/vcl/source/opengl/OpenGLHelper.cxx
@@ -247,4 +247,26 @@ const char* OpenGLHelper::GLErrorString(GLenum errorCode)
     return NULL;
 }
 
+std::ostream& operator<<(std::ostream& rStrm, const glm::vec4& rPos)
+{
+    rStrm << "( " << rPos[0] << ", " << rPos[1] << ", " << rPos[2] << ", " << rPos[3] << ")";
+    return rStrm;
+}
+
+std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
+{
+    for(int i = 0; i < 4; ++i)
+    {
+        rStrm << "\n( ";
+        for(int j = 0; j < 4; ++j)
+        {
+            rStrm << rMatrix[j][i];
+            rStrm << " ";
+        }
+        rStrm << ")\n";
+    }
+    return rStrm;
+}
+
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 204efb6a1723f98ff53a61ed249dbff8cb391bb3
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun May 11 17:57:54 2014 +0200

    fix alpha calculation
    
    Change-Id: Ic0734ef9a079196d9a0a523dac7726937ed2155f

diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 9afd1b7..56a421e 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -1159,7 +1159,7 @@ glm::vec4 getColorAsVector(sal_uInt32 nColor)
     sal_uInt8 nGreen = sal_uInt8((nColor & 0xFF00) >> 8);
     sal_uInt8 nBlue = sal_uInt8((nColor & 0xFF));
     sal_uInt8 nAlpha = sal_uInt8((nColor & 0xFF000000) >> 24);
-    return glm::vec4(nRed/255.0, nGreen/255.0, nBlue/255.0, nAlpha/255.0);
+    return glm::vec4(nRed/255.0, nGreen/255.0, nBlue/255.0, (0xFF - nAlpha)/255.0);
 }
 
 std::ostream& operator<<(std::ostream& rStrm, const glm::vec4& rPos)
commit 9822c1b970d21770af60f0853de0f302ebd423d8
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun May 11 17:56:12 2014 +0200

    a few debug statements and cosmetic clean-up
    
    Change-Id: I78cc73cc792f1182abcac0b81e97b948206a11d8

diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index 636b015..9afd1b7 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -327,10 +327,12 @@ void OpenGL3DRenderer::CreateActualRoundedCube(float fRadius, int iSubDivY, int
     m_RoundBarMesh.topThreshold = topThreshold;
     m_RoundBarMesh.bottomThreshold = bottomThreshold;
     m_RoundBarMesh.iMeshStartIndices = m_Vertices.size();
+
     for (int k = 0; k < 5; k++)
     {
         m_RoundBarMesh.iElementStartIndices[k] = indeices[k].size();
     }
+
     for (size_t i = 0; i < vertices.size(); i += 3)
     {
         for (int k = 0; k < 3; k++)
@@ -407,9 +409,12 @@ int OpenGL3DRenderer::GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, s
         {
             fNextAngleY = 360.0f;
         }
-        float fSineY = sin(fCurAngleY/180.0f*PI), fCosY = cos(fCurAngleY/180.0f*PI);
-        float fNextSineY = sin(fNextAngleY/180.0f*PI), fNextCosY = cos(fNextAngleY/180.0f*PI);
-        glm::vec3 vDirY(fCosY, 0.0f, -fSineY), vNextDirY(fNextCosY, 0.0f, -fNextSineY);
+        float fSineY = sin(fCurAngleY/180.0f*PI);
+        float fCosY = cos(fCurAngleY/180.0f*PI);
+        float fNextSineY = sin(fNextAngleY/180.0f*PI);
+        float fNextCosY = cos(fNextAngleY/180.0f*PI);
+        glm::vec3 vDirY(fCosY, 0.0f, -fSineY);
+        glm::vec3 vNextDirY(fNextCosY, 0.0f, -fNextSineY);
         float fCurAngleZ = 0.0f;
         int iStepsZ = 1;
         int xzIndex = 0;
@@ -429,6 +434,7 @@ int OpenGL3DRenderer::GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, s
         {
             xzIndex = 3;
         }
+
         while(iStepsZ <= iSubDivZ)
         {
             int yIndex = 0;
@@ -475,6 +481,7 @@ int OpenGL3DRenderer::GenerateRoundCornerBar(std::vector<glm::vec3> &vertices, s
                 glm::normalize(vQuadPoints[2]),
                 glm::normalize(vQuadPoints[3])
             };
+
             for (int i = 0; i < 6; i++)
             {
                 int index = iIndices[i];
@@ -930,7 +937,7 @@ void OpenGL3DRenderer::AddShape3DExtrudeObject(sal_Int32 color,sal_Int32 specula
     m_Extrude3DInfo.zScale = glm::length(DirY);
     glm::mat4 transformMatrixInverse = glm::inverse(glm::translate(glm::vec3(tranform)));
     glm::mat4 scaleMatrixInverse = glm::inverse(glm::scale(m_Extrude3DInfo.xScale, m_Extrude3DInfo.zScale, m_Extrude3DInfo.yScale));
-    //m_Extrude3DInfo.rotation = transformMatrixInverse * modelMatrix * scaleMatrixInverse;
+    m_Extrude3DInfo.rotation = transformMatrixInverse * modelMatrix * scaleMatrixInverse;
 
     //color
     m_Extrude3DInfo.extrudeColor = glm::vec4((float)(((color) & 0x00FF0000) >> 16) / 255.0f,
@@ -1165,7 +1172,7 @@ std::ostream& operator<<(std::ostream& rStrm, const glm::mat4& rMatrix)
 {
     for(int i = 0; i < 4; ++i)
     {
-        rStrm << "( ";
+        rStrm << "\n( ";
         for(int j = 0; j < 4; ++j)
         {
             rStrm << rMatrix[j][i];
@@ -1186,12 +1193,16 @@ void OpenGL3DRenderer::RenderNonRoundedBar(const glm::mat4& modelMatrix, sal_uIn
 
     for(size_t i = 0; i < SAL_N_ELEMENTS(cubeVertices); i += 3)
     {
-        glm::vec4 aPos(cubeVertices[i*3], cubeVertices[i*3+1], cubeVertices[i*3+2], 1.0);
+        glm::vec4 aPos(cubeVertices[i], cubeVertices[i+1], cubeVertices[i+2], 1.0);
+        SAL_INFO("chart2.3dopengl", aPos);
+        glm::vec4 aWorldPos = modelMatrix * aPos;
+        SAL_INFO("chart2.3dopengl", aWorldPos);
         glm::vec4 aNewPos = aMVP * aPos;
         SAL_INFO("chart2.3dopengl", aNewPos);
     }
 
     glm::vec4 aColor = getColorAsVector(nColor);
+    SAL_INFO("chart2.3dopengl", "Color: " << aColor);
     glUseProgram(m_CommonProID);
     //fill vertex buffer
     glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);
commit faf11cb0fc5fb6f4847f39ce7be2c99348e5f77b
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sun May 11 17:55:16 2014 +0200

    a few changes to camera position and bar positioning
    
    Change-Id: I256e6855735bea050507c894f91ed895da0e13ba

diff --git a/chart2/source/view/charttypes/GL3DBarChart.cxx b/chart2/source/view/charttypes/GL3DBarChart.cxx
index eabc36a..a5d4a36 100644
--- a/chart2/source/view/charttypes/GL3DBarChart.cxx
+++ b/chart2/source/view/charttypes/GL3DBarChart.cxx
@@ -68,7 +68,7 @@ void GL3DBarChart::create3DShapes()
     for (boost::ptr_vector<VDataSeries>::const_iterator itr = maDataSeries.begin(),
             itrEnd = maDataSeries.end(); itr != itrEnd; ++itr)
     {
-        nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY);
+        nYPos = nSeriesIndex * (nBarSizeY + nBarDistanceY) + nBarSizeY;
 
         const VDataSeries& rDataSeries = *itr;
         sal_Int32 nPointCount = rDataSeries.getTotalPointCount();
@@ -93,11 +93,11 @@ void GL3DBarChart::create3DShapes()
         for(sal_Int32 nIndex = 0; nIndex < nPointCount; ++nIndex)
         {
             float nVal = rDataSeries.getYValue(nIndex);
-            float nXPos = nIndex * (nBarSizeX + nBarDistanceX);
+            float nXPos = nIndex * (nBarSizeX + nBarDistanceX) + nBarSizeX;
 
 
             glm::mat4 aScaleMatrix = glm::scale(nBarSizeX, nBarSizeY, nVal);
-            glm::mat4 aTranslationMatrix = glm::translate(nXPos, nYPos, nVal/2);
+            glm::mat4 aTranslationMatrix = glm::translate(nXPos, nYPos, nVal);
             glm::mat4 aBarPosition = aTranslationMatrix * aScaleMatrix;
 
             maShapes.push_back(new opengl3D::Bar(mpRenderer.get(), aBarPosition, nColor, nId++));
diff --git a/chart2/source/view/main/3DChartObjects.cxx b/chart2/source/view/main/3DChartObjects.cxx
index 0aeec40..202eb97 100644
--- a/chart2/source/view/main/3DChartObjects.cxx
+++ b/chart2/source/view/main/3DChartObjects.cxx
@@ -49,7 +49,7 @@ void Renderable3DObject::render()
 
 Bar::Bar(OpenGL3DRenderer* pRenderer, const glm::mat4& rPosition, sal_uInt32 aColor, sal_uInt32 nId)
     : Renderable3DObject(pRenderer, nId)
-    , mbRoundedCorners(false)
+    , mbRoundedCorners(true)
     , maPos(rPosition)
     , maColor(aColor)
 {
@@ -185,7 +185,7 @@ Camera::Camera(OpenGL3DRenderer* pRenderer):
     Renderable3DObject(pRenderer, 0),
     maPos(10,-50,20),
     maUp(0, 0, 1),
-    maDirection(glm::vec3(0,1,-0.5))
+    maDirection(glm::vec3(0,0,0))
 {
 }
 
diff --git a/chart2/source/view/main/GL3DRenderer.cxx b/chart2/source/view/main/GL3DRenderer.cxx
index c92d878..636b015 100644
--- a/chart2/source/view/main/GL3DRenderer.cxx
+++ b/chart2/source/view/main/GL3DRenderer.cxx
@@ -136,7 +136,7 @@ void OpenGL3DRenderer::LoadShaders()
 void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up)
 {
     m_CameraInfo.cameraPos = pos;
-    m_CameraInfo.cameraOrg = pos + direction;
+    m_CameraInfo.cameraOrg = direction;
     m_CameraInfo.cameraUp = up;
 }
 
@@ -212,7 +212,7 @@ void OpenGL3DRenderer::init()
     glBufferData(GL_ARRAY_BUFFER, sizeof(boundBoxNormal), boundBoxNormal, GL_STATIC_DRAW);
     glBindBuffer(GL_ARRAY_BUFFER, 0);
 
-    m_fViewAngle = 30.0f;
+    m_fViewAngle = 60.0f;
     m_3DProjection = glm::perspective(m_fViewAngle, (float)m_iWidth / (float)m_iHeight, 0.01f, 2000.0f);
     LoadShaders();
     glGenBuffers(1, &m_TextTexCoordBuf);
@@ -930,7 +930,8 @@ void OpenGL3DRenderer::AddShape3DExtrudeObject(sal_Int32 color,sal_Int32 specula
     m_Extrude3DInfo.zScale = glm::length(DirY);
     glm::mat4 transformMatrixInverse = glm::inverse(glm::translate(glm::vec3(tranform)));
     glm::mat4 scaleMatrixInverse = glm::inverse(glm::scale(m_Extrude3DInfo.xScale, m_Extrude3DInfo.zScale, m_Extrude3DInfo.yScale));
-    m_Extrude3DInfo.rotation = transformMatrixInverse * modelMatrix * scaleMatrixInverse;
+    //m_Extrude3DInfo.rotation = transformMatrixInverse * modelMatrix * scaleMatrixInverse;
+
     //color
     m_Extrude3DInfo.extrudeColor = glm::vec4((float)(((color) & 0x00FF0000) >> 16) / 255.0f,
                                              (float)(((color) & 0x0000FF00) >> 8) / 255.0f,
@@ -1443,10 +1444,9 @@ void OpenGL3DRenderer::RenderClickPos(Point aMPos)
 
 void OpenGL3DRenderer::CreateSceneBoxView()
 {
-    m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space
-               m_CameraInfo.cameraOrg, // and looks at the origin
-               m_CameraInfo.cameraUp  // Head is up (set to 0,-1,0 to look upside-down)
-               );
+    m_3DView = glm::lookAt(m_CameraInfo.cameraPos,
+               m_CameraInfo.cameraOrg,
+               m_CameraInfo.cameraUp);
 }
 
 void OpenGL3DRenderer::ProcessUnrenderedShape()


More information about the Libreoffice-commits mailing list