1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #ifndef INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
12 #define INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
14 #include <basegfx/numeric/ftools.hxx>
16 #include <glm/gtx/norm.hpp>
17 #include <tools/color.hxx>
24 inline void addRectangle(std::vector
<GLfloat
>& rVertices
, GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
);
27 inline void addRectangle
<GL_TRIANGLES
>(std::vector
<GLfloat
>& rVertices
, GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
29 rVertices
.insert(rVertices
.end(), {
30 x1
, y1
, x2
, y1
, x1
, y2
,
31 x1
, y2
, x2
, y1
, x2
, y2
36 inline void addRectangle
<GL_TRIANGLE_FAN
>(std::vector
<GLfloat
>& rVertices
, GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
38 rVertices
.insert(rVertices
.end(), {
44 inline void createColor(Color nColor
, GLfloat fTransparency
, GLubyte
& nR
, GLubyte
& nG
, GLubyte
& nB
, GLubyte
& nA
)
47 nG
= nColor
.GetGreen();
48 nB
= nColor
.GetBlue();
49 nA
= (1.0f
- fTransparency
) * 255.0f
;
53 inline void addQuadColors(std::vector
<GLubyte
>& rColors
, Color nColor
, GLfloat fTransparency
);
56 inline void addQuadColors
<GL_TRIANGLES
>(std::vector
<GLubyte
>& rColors
, Color nColor
, GLfloat fTransparency
)
58 GLubyte nR
, nG
, nB
, nA
;
59 createColor(nColor
, fTransparency
, nR
, nG
, nB
, nA
);
61 rColors
.insert(rColors
.end(), {
71 inline void addLineSegmentVertices(std::vector
<GLfloat
>& rVertices
, std::vector
<GLfloat
>& rExtrusionVectors
,
72 glm::vec2 prevPoint
, glm::vec2 prevExtrusionVector
, GLfloat prevLength
,
73 glm::vec2 currPoint
, glm::vec2 currExtrusionVector
, GLfloat currLength
)
75 rVertices
.insert(rVertices
.end(), {
76 prevPoint
.x
, prevPoint
.y
,
77 prevPoint
.x
, prevPoint
.y
,
78 currPoint
.x
, currPoint
.y
,
79 currPoint
.x
, currPoint
.y
,
80 prevPoint
.x
, prevPoint
.y
,
81 currPoint
.x
, currPoint
.y
,
84 rExtrusionVectors
.insert(rExtrusionVectors
.end(), {
85 -prevExtrusionVector
.x
, -prevExtrusionVector
.y
, -prevLength
,
86 prevExtrusionVector
.x
, prevExtrusionVector
.y
, prevLength
,
87 -currExtrusionVector
.x
, -currExtrusionVector
.y
, -currLength
,
88 -currExtrusionVector
.x
, -currExtrusionVector
.y
, -currLength
,
89 prevExtrusionVector
.x
, prevExtrusionVector
.y
, prevLength
,
90 currExtrusionVector
.x
, currExtrusionVector
.y
, currLength
,
94 inline glm::vec2
normalize(const glm::vec2
& vector
)
96 if (glm::length(vector
) > 0.0)
97 return glm::normalize(vector
);
101 inline glm::vec2
perpendicular(const glm::vec2
& vector
)
103 return glm::vec2(-vector
.y
, vector
.x
);
106 inline float lineVectorAngle(const glm::vec2
& previous
, const glm::vec2
& next
)
108 float angle
= std::atan2(previous
.x
* next
.y
- previous
.y
* next
.x
,
109 previous
.x
* next
.x
+ previous
.y
* next
.y
);
111 return F_PI
- std::fabs(angle
);
116 #endif // INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */