1
/****************************************************************************
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the examples of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:BSD$
9
** You may use this file under the terms of the BSD license as follows:
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
14
** * Redistributions of source code must retain the above copyright
15
** notice, this list of conditions and the following disclaimer.
16
** * Redistributions in binary form must reproduce the above copyright
17
** notice, this list of conditions and the following disclaimer in
18
** the documentation and/or other materials provided with the
20
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21
** of its contributors may be used to endorse or promote products derived
22
** from this software without specific prior written permission.
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39
****************************************************************************/
47
m_data.resize(2500 * 6);
49
const GLfloat x1 = +0.06f;
50
const GLfloat y1 = -0.14f;
51
const GLfloat x2 = +0.14f;
52
const GLfloat y2 = -0.06f;
53
const GLfloat x3 = +0.08f;
54
const GLfloat y3 = +0.00f;
55
const GLfloat x4 = +0.30f;
56
const GLfloat y4 = +0.22f;
58
quad(x1, y1, x2, y2, y2, x2, y1, x1);
59
quad(x3, y3, x4, y4, y4, x4, y3, x3);
61
extrude(x1, y1, x2, y2);
62
extrude(x2, y2, y2, x2);
63
extrude(y2, x2, y1, x1);
64
extrude(y1, x1, x1, y1);
65
extrude(x3, y3, x4, y4);
66
extrude(x4, y4, y4, x4);
67
extrude(y4, x4, y3, x3);
69
const int NumSectors = 100;
71
for (int i = 0; i < NumSectors; ++i) {
72
GLfloat angle = (i * 2 * M_PI) / NumSectors;
73
GLfloat angleSin = qSin(angle);
74
GLfloat angleCos = qCos(angle);
75
const GLfloat x5 = 0.30f * angleSin;
76
const GLfloat y5 = 0.30f * angleCos;
77
const GLfloat x6 = 0.20f * angleSin;
78
const GLfloat y6 = 0.20f * angleCos;
80
angle = ((i + 1) * 2 * M_PI) / NumSectors;
81
angleSin = qSin(angle);
82
angleCos = qCos(angle);
83
const GLfloat x7 = 0.20f * angleSin;
84
const GLfloat y7 = 0.20f * angleCos;
85
const GLfloat x8 = 0.30f * angleSin;
86
const GLfloat y8 = 0.30f * angleCos;
88
quad(x5, y5, x6, y6, x7, y7, x8, y8);
90
extrude(x6, y6, x7, y7);
91
extrude(x8, y8, x5, y5);
95
void Logo::add(const QVector3D &v, const QVector3D &n)
97
GLfloat *p = m_data.data() + m_count;
107
void Logo::quad(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3, GLfloat x4, GLfloat y4)
109
QVector3D n = QVector3D::normal(QVector3D(x4 - x1, y4 - y1, 0.0f), QVector3D(x2 - x1, y2 - y1, 0.0f));
111
add(QVector3D(x1, y1, -0.05f), n);
112
add(QVector3D(x4, y4, -0.05f), n);
113
add(QVector3D(x2, y2, -0.05f), n);
115
add(QVector3D(x3, y3, -0.05f), n);
116
add(QVector3D(x2, y2, -0.05f), n);
117
add(QVector3D(x4, y4, -0.05f), n);
119
n = QVector3D::normal(QVector3D(x1 - x4, y1 - y4, 0.0f), QVector3D(x2 - x4, y2 - y4, 0.0f));
121
add(QVector3D(x4, y4, 0.05f), n);
122
add(QVector3D(x1, y1, 0.05f), n);
123
add(QVector3D(x2, y2, 0.05f), n);
125
add(QVector3D(x2, y2, 0.05f), n);
126
add(QVector3D(x3, y3, 0.05f), n);
127
add(QVector3D(x4, y4, 0.05f), n);
130
void Logo::extrude(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
132
QVector3D n = QVector3D::normal(QVector3D(0.0f, 0.0f, -0.1f), QVector3D(x2 - x1, y2 - y1, 0.0f));
134
add(QVector3D(x1, y1, +0.05f), n);
135
add(QVector3D(x1, y1, -0.05f), n);
136
add(QVector3D(x2, y2, +0.05f), n);
138
add(QVector3D(x2, y2, -0.05f), n);
139
add(QVector3D(x2, y2, +0.05f), n);
140
add(QVector3D(x1, y1, -0.05f), n);