~ubuntu-branches/ubuntu/vivid/qtdeclarative-opensource-src-gles/vivid

« back to all changes in this revision

Viewing changes to examples/quick/quickwidgets/qquickviewcomparison/logo.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2014-10-29 07:54:05 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20141029075405-gq1uzomnw3but9g2
Tags: 5.3.2-0ubuntu1
Sync package with qtdeclarative-opensource-src - 5.3.2-3ubuntu1 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the examples of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
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
 
19
**     distribution.
 
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.
 
23
**
 
24
**
 
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."
 
36
**
 
37
** $QT_END_LICENSE$
 
38
**
 
39
****************************************************************************/
 
40
 
 
41
#include "logo.h"
 
42
#include <qmath.h>
 
43
 
 
44
Logo::Logo()
 
45
    : m_count(0)
 
46
{
 
47
    m_data.resize(2500 * 6);
 
48
 
 
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;
 
57
 
 
58
    quad(x1, y1, x2, y2, y2, x2, y1, x1);
 
59
    quad(x3, y3, x4, y4, y4, x4, y3, x3);
 
60
 
 
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);
 
68
 
 
69
    const int NumSectors = 100;
 
70
 
 
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;
 
79
 
 
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;
 
87
 
 
88
        quad(x5, y5, x6, y6, x7, y7, x8, y8);
 
89
 
 
90
        extrude(x6, y6, x7, y7);
 
91
        extrude(x8, y8, x5, y5);
 
92
    }
 
93
}
 
94
 
 
95
void Logo::add(const QVector3D &v, const QVector3D &n)
 
96
{
 
97
    GLfloat *p = m_data.data() + m_count;
 
98
    *p++ = v.x();
 
99
    *p++ = v.y();
 
100
    *p++ = v.z();
 
101
    *p++ = n.x();
 
102
    *p++ = n.y();
 
103
    *p++ = n.z();
 
104
    m_count += 6;
 
105
}
 
106
 
 
107
void Logo::quad(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat x3, GLfloat y3, GLfloat x4, GLfloat y4)
 
108
{
 
109
    QVector3D n = QVector3D::normal(QVector3D(x4 - x1, y4 - y1, 0.0f), QVector3D(x2 - x1, y2 - y1, 0.0f));
 
110
 
 
111
    add(QVector3D(x1, y1, -0.05f), n);
 
112
    add(QVector3D(x4, y4, -0.05f), n);
 
113
    add(QVector3D(x2, y2, -0.05f), n);
 
114
 
 
115
    add(QVector3D(x3, y3, -0.05f), n);
 
116
    add(QVector3D(x2, y2, -0.05f), n);
 
117
    add(QVector3D(x4, y4, -0.05f), n);
 
118
 
 
119
    n = QVector3D::normal(QVector3D(x1 - x4, y1 - y4, 0.0f), QVector3D(x2 - x4, y2 - y4, 0.0f));
 
120
 
 
121
    add(QVector3D(x4, y4, 0.05f), n);
 
122
    add(QVector3D(x1, y1, 0.05f), n);
 
123
    add(QVector3D(x2, y2, 0.05f), n);
 
124
 
 
125
    add(QVector3D(x2, y2, 0.05f), n);
 
126
    add(QVector3D(x3, y3, 0.05f), n);
 
127
    add(QVector3D(x4, y4, 0.05f), n);
 
128
}
 
129
 
 
130
void Logo::extrude(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
 
131
{
 
132
    QVector3D n = QVector3D::normal(QVector3D(0.0f, 0.0f, -0.1f), QVector3D(x2 - x1, y2 - y1, 0.0f));
 
133
 
 
134
    add(QVector3D(x1, y1, +0.05f), n);
 
135
    add(QVector3D(x1, y1, -0.05f), n);
 
136
    add(QVector3D(x2, y2, +0.05f), n);
 
137
 
 
138
    add(QVector3D(x2, y2, -0.05f), n);
 
139
    add(QVector3D(x2, y2, +0.05f), n);
 
140
    add(QVector3D(x1, y1, -0.05f), n);
 
141
}