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>
26 inline void addRectangle(std::vector
<GLfloat
>& rVertices
, GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
);
29 inline void addRectangle
<GL_TRIANGLES
>(std::vector
<GLfloat
>& rVertices
, GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
31 rVertices
.insert(rVertices
.end(), {
32 x1
, y1
, x2
, y1
, x1
, y2
,
33 x1
, y2
, x2
, y1
, x2
, y2
38 inline void addRectangle
<GL_TRIANGLE_FAN
>(std::vector
<GLfloat
>& rVertices
, GLfloat x1
, GLfloat y1
, GLfloat x2
, GLfloat y2
)
40 rVertices
.insert(rVertices
.end(), {
46 inline void createColor(Color nColor
, GLfloat fTransparency
, GLubyte
& nR
, GLubyte
& nG
, GLubyte
& nB
, GLubyte
& nA
)
49 nG
= nColor
.GetGreen();
50 nB
= nColor
.GetBlue();
51 nA
= (1.0f
- fTransparency
) * 255.0f
;
55 inline void addQuadColors(std::vector
<GLubyte
>& rColors
, Color nColor
, GLfloat fTransparency
);
58 inline void addQuadColors
<GL_TRIANGLES
>(std::vector
<GLubyte
>& rColors
, Color nColor
, GLfloat fTransparency
)
60 GLubyte nR
, nG
, nB
, nA
;
61 createColor(nColor
, fTransparency
, nR
, nG
, nB
, nA
);
63 rColors
.insert(rColors
.end(), {
73 inline void addLineSegmentVertices(std::vector
<GLfloat
>& rVertices
, std::vector
<GLfloat
>& rExtrusionVectors
,
74 glm::vec2 prevPoint
, glm::vec2 prevExtrusionVector
, GLfloat prevLength
,
75 glm::vec2 currPoint
, glm::vec2 currExtrusionVector
, GLfloat currLength
)
77 rVertices
.insert(rVertices
.end(), {
78 prevPoint
.x
, prevPoint
.y
,
79 prevPoint
.x
, prevPoint
.y
,
80 currPoint
.x
, currPoint
.y
,
81 currPoint
.x
, currPoint
.y
,
82 prevPoint
.x
, prevPoint
.y
,
83 currPoint
.x
, currPoint
.y
,
86 rExtrusionVectors
.insert(rExtrusionVectors
.end(), {
87 -prevExtrusionVector
.x
, -prevExtrusionVector
.y
, -prevLength
,
88 prevExtrusionVector
.x
, prevExtrusionVector
.y
, prevLength
,
89 -currExtrusionVector
.x
, -currExtrusionVector
.y
, -currLength
,
90 -currExtrusionVector
.x
, -currExtrusionVector
.y
, -currLength
,
91 prevExtrusionVector
.x
, prevExtrusionVector
.y
, prevLength
,
92 currExtrusionVector
.x
, currExtrusionVector
.y
, currLength
,
96 inline glm::vec2
normalize(const glm::vec2
& vector
)
98 if (glm::length(vector
) > 0.0)
99 return glm::normalize(vector
);
103 inline glm::vec2
perpendicular(const glm::vec2
& vector
)
105 return glm::vec2(-vector
.y
, vector
.x
);
108 inline float lineVectorAngle(const glm::vec2
& previous
, const glm::vec2
& next
)
110 float angle
= std::atan2(previous
.x
* next
.y
- previous
.y
* next
.x
,
111 previous
.x
* next
.x
+ previous
.y
* next
.y
);
113 return F_PI
- std::fabs(angle
);
116 }} // end vcl::vertex
118 #endif // INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */