Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/examples/opengl/hellogl_es2/glwidget.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the examples of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4242#include "glwidget.h"
    4343#include <QPainter>
     44#include <QPaintEngine>
    4445#include <math.h>
    4546
     
    4849
    4950const int bubbleNum = 8;
    50 
    51 inline void CrossProduct(qreal &xOut, qreal &yOut, qreal &zOut, qreal x1, qreal y1, qreal z1, qreal x2, qreal y2, qreal z2)
    52 {
    53    xOut = y1 * z2 - z1 * y2;
    54    yOut = z1 * x2 - x1 * z2;
    55    zOut = x1 * y2 - y1 * x2;
    56 }
    57 
    58 inline void Normalize(qreal &x, qreal &y, qreal &z)
    59 {
    60     qreal l = sqrt(x*x + y*y + z*z);
    61     x = x / l;
    62     y = y / l;
    63     z = z / l;
    64 }
    65 
    66 inline void IdentityMatrix(GLfloat *m)
    67 {
    68     m[0 * 4 + 0] = 1.0f;
    69     m[1 * 4 + 0] = 0.0f;
    70     m[2 * 4 + 0] = 0.0f;
    71     m[3 * 4 + 0] = 0.0f;
    72     m[0 * 4 + 1] = 0.0f;
    73     m[1 * 4 + 1] = 1.0f;
    74     m[2 * 4 + 1] = 0.0f;
    75     m[3 * 4 + 1] = 0.0f;
    76     m[0 * 4 + 2] = 0.0f;
    77     m[1 * 4 + 2] = 0.0f;
    78     m[2 * 4 + 2] = 1.0f;
    79     m[3 * 4 + 2] = 0.0f;
    80     m[0 * 4 + 3] = 0.0f;
    81     m[1 * 4 + 3] = 0.0f;
    82     m[2 * 4 + 3] = 0.0f;
    83     m[3 * 4 + 3] = 1.0f;
    84 }
    85 
    86 // Adjust a 4x4 matrix to apply a scale.
    87 inline void ScaleMatrix(GLfloat *m, GLfloat scalex, GLfloat scaley, GLfloat scalez)
    88 {
    89     m[0 * 4 + 0] *= scalex;
    90     m[0 * 4 + 1] *= scalex;
    91     m[0 * 4 + 2] *= scalex;
    92     m[0 * 4 + 3] *= scalex;
    93     m[1 * 4 + 0] *= scaley;
    94     m[1 * 4 + 1] *= scaley;
    95     m[1 * 4 + 2] *= scaley;
    96     m[1 * 4 + 3] *= scaley;
    97     m[2 * 4 + 0] *= scalez;
    98     m[2 * 4 + 1] *= scalez;
    99     m[2 * 4 + 2] *= scalez;
    100     m[2 * 4 + 3] *= scalez;
    101 }
    102 
    103 // Adjust a 4x4 matrix to apply a translation.
    104 inline void TranslateMatrix(GLfloat *m, GLfloat translatex, GLfloat translatey, GLfloat translatez)
    105 {
    106     m[3 * 4 + 0] += m[0 * 4 + 0] * translatex + m[1 * 4 + 0] * translatey + m[2 * 4 + 0] * translatez;
    107     m[3 * 4 + 1] += m[0 * 4 + 1] * translatex + m[1 * 4 + 1] * translatey + m[2 * 4 + 1] * translatez;
    108     m[3 * 4 + 2] += m[0 * 4 + 2] * translatex + m[1 * 4 + 2] * translatey + m[2 * 4 + 2] * translatez;
    109     m[3 * 4 + 3] += m[0 * 4 + 3] * translatex + m[1 * 4 + 3] * translatey + m[2 * 4 + 3] * translatez;
    110 }
    111 
    112 #ifndef M_PI
    113 #define M_PI 3.14159265358979323846
    114 #endif
    115 
    116 // Adjust a 4x4 matrix to apply a rotation.
    117 inline void RotateMatrix(GLfloat *m, GLfloat angle, GLfloat vx, GLfloat vy, GLfloat vz)
    118 {
    119     GLfloat len = sqrt(vx * vx + vy * vy + vz * vz);
    120     if (len != 0) {
    121         vx /= len;
    122         vy /= len;
    123         vz /= len;
    124     }
    125 
    126     GLfloat c, s, ic;
    127     c = cos(angle * M_PI / 180.0);
    128     s = sin(angle * M_PI / 180.0);
    129     ic = 1.0f - c;
    130 
    131     GLfloat rot[16];
    132     rot[0 * 4 + 0] = vx * vx * ic + c;
    133     rot[1 * 4 + 0] = vx * vy * ic - vz * s;
    134     rot[2 * 4 + 0] = vx * vz * ic + vy * s;
    135     rot[3 * 4 + 0] = 0.0f;
    136     rot[0 * 4 + 1] = vy * vx * ic + vz * s;
    137     rot[1 * 4 + 1] = vy * vy * ic + c;
    138     rot[2 * 4 + 1] = vy * vz * ic - vx * s;
    139     rot[3 * 4 + 1] = 0.0f;
    140     rot[0 * 4 + 2] = vx * vz * ic - vy * s;
    141     rot[1 * 4 + 2] = vy * vz * ic + vx * s;
    142     rot[2 * 4 + 2] = vz * vz * ic + c;
    143     rot[3 * 4 + 2] = 0.0f;
    144     rot[0 * 4 + 3] = 0.0f;
    145     rot[1 * 4 + 3] = 0.0f;
    146     rot[2 * 4 + 3] = 0.0f;
    147     rot[3 * 4 + 3] = 1.0f;
    148 
    149     GLfloat temp[16];
    150     for (int i = 0; i < 4; ++i) {
    151         for (int j = 0; j < 4; ++j) {
    152             temp[j * 4 + i] = 0.0f;
    153             for (int k = 0; k < 4; ++k) {
    154                 temp[j * 4 + i] += m[k * 4 + i] * rot[j * 4 + k];
    155             }
    156         }
    157     }
    158 
    159     qMemCopy(m, temp, sizeof(temp));
    160 }
    16151
    16252GLWidget::GLWidget(QWidget *parent)
     
    16454{
    16555    qtLogo = true;
    166     createdVertices = 0;
    167     createdNormals = 0;
    168     m_vertexNumber = 0;
    16956    frames = 0;
    17057    setAttribute(Qt::WA_PaintOnScreen);
     
    17966GLWidget::~GLWidget()
    18067{
    181   if (createdVertices)
    182       delete[] createdVertices;
    183   if (createdNormals)
    184       delete[] createdNormals;
    18568}
    18669
     
    21093void GLWidget::paintQtLogo()
    21194{
    212     glDisable(GL_TEXTURE_2D);
    213     glVertexAttribPointer(vertexAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdVertices);
    214     glEnableVertexAttribArray(vertexAttr1);
    215     glVertexAttribPointer(normalAttr1, 3, GL_FLOAT, GL_FALSE, 0, createdNormals);
    216     glEnableVertexAttribArray(normalAttr1);
    217     glDrawArrays(GL_TRIANGLES, 0, m_vertexNumber / 3);
    218     glDisableVertexAttribArray(normalAttr1);
    219     glDisableVertexAttribArray(vertexAttr1);
     95    program1.enableAttributeArray(normalAttr1);
     96    program1.enableAttributeArray(vertexAttr1);
     97    program1.setAttributeArray(vertexAttr1, vertices.constData());
     98    program1.setAttributeArray(normalAttr1, normals.constData());
     99    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
     100    program1.disableAttributeArray(normalAttr1);
     101    program1.disableAttributeArray(vertexAttr1);
    220102}
    221103
    222104void GLWidget::paintTexturedCube()
    223105{
    224     glEnable(GL_TEXTURE_2D);
    225106    glBindTexture(GL_TEXTURE_2D, m_uiTexture);
    226107    GLfloat afVertices[] = {
     
    240121        0.5, -0.5, 0.5,  0.5,  -0.5, -0.5, -0.5,  -0.5, 0.5
    241122    };
    242     glVertexAttribPointer(vertexAttr2, 3, GL_FLOAT, GL_FALSE, 0, afVertices);
    243     glEnableVertexAttribArray(vertexAttr2);
     123    program2.setAttributeArray(vertexAttr2, afVertices, 3);
    244124
    245125    GLfloat afTexCoord[] = {
     
    259139        0.0f,1.0f, 0.0f,0.0f, 1.0f,1.0f
    260140    };
    261     glVertexAttribPointer(texCoordAttr2, 2, GL_FLOAT, GL_FALSE, 0, afTexCoord);
    262     glEnableVertexAttribArray(texCoordAttr2);
     141    program2.setAttributeArray(texCoordAttr2, afTexCoord, 2);
    263142
    264143    GLfloat afNormals[] = {
     
    279158        0,1,0, 0,1,0, 0,1,0
    280159    };
    281     glVertexAttribPointer(normalAttr2, 3, GL_FLOAT, GL_FALSE, 0, afNormals);
    282     glEnableVertexAttribArray(normalAttr2);
    283 
    284     glUniform1i(textureUniform2, 0);    // use texture unit 0
     160    program2.setAttributeArray(normalAttr2, afNormals, 3);
     161
     162    program2.setUniformValue(textureUniform2, 0);    // use texture unit 0
     163
     164    program2.enableAttributeArray(vertexAttr2);
     165    program2.enableAttributeArray(normalAttr2);
     166    program2.enableAttributeArray(texCoordAttr2);
    285167
    286168    glDrawArrays(GL_TRIANGLES, 0, 36);
    287169
    288     glDisableVertexAttribArray(vertexAttr2);
    289     glDisableVertexAttribArray(normalAttr2);
    290     glDisableVertexAttribArray(texCoordAttr2);
    291 }
    292 
    293 static void reportCompileErrors(GLuint shader, const char *src)
    294 {
    295     GLint value = 0;
    296     glGetShaderiv(shader, GL_COMPILE_STATUS, &value);
    297     bool compiled = (value != 0);
    298     value = 0;
    299     glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value);
    300     if (!compiled && value > 1) {
    301         char *log = new char [value];
    302         GLint len;
    303         glGetShaderInfoLog(shader, value, &len, log);
    304         qWarning("%s\n", log);
    305         qWarning("when compiling:\n%s\n", src);
    306         delete [] log;
    307     }
    308 }
    309 
    310 static void reportLinkErrors(GLuint program, const char *vsrc, const char *fsrc)
    311 {
    312     GLint value = 0;
    313     glGetProgramiv(program, GL_LINK_STATUS, &value);
    314     bool linked = (value != 0);
    315     value = 0;
    316     glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value);
    317     if (!linked && value > 1) {
    318         char *log = new char [value];
    319         GLint len;
    320         glGetProgramInfoLog(program, value, &len, log);
    321         qWarning("%s\n", log);
    322         qWarning("when linking:\n%s\nwith:\n%s\n", vsrc, fsrc);
    323         delete [] log;
    324     }
     170    program2.disableAttributeArray(vertexAttr2);
     171    program2.disableAttributeArray(normalAttr2);
     172    program2.disableAttributeArray(texCoordAttr2);
    325173}
    326174
     
    329177    glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
    330178
    331     glEnable(GL_TEXTURE_2D);
    332179    glGenTextures(1, &m_uiTexture);
    333180    m_uiTexture = bindTexture(QImage(":/qt.png"));
    334181
    335     GLuint vshader1 = glCreateShader(GL_VERTEX_SHADER);
    336     const char *vsrc1[1] = {
     182    QGLShader *vshader1 = new QGLShader(QGLShader::Vertex, this);
     183    const char *vsrc1 =
    337184        "attribute highp vec4 vertex;\n"
    338185        "attribute mediump vec3 normal;\n"
     
    347194        "    color = clamp(color, 0.0, 1.0);\n"
    348195        "    gl_Position = matrix * vertex;\n"
    349         "}\n"
    350     };
    351     glShaderSource(vshader1, 1, vsrc1, 0);
    352     glCompileShader(vshader1);
    353     reportCompileErrors(vshader1, vsrc1[0]);
    354 
    355     GLuint fshader1 = glCreateShader(GL_FRAGMENT_SHADER);
    356     const char *fsrc1[1] = {
     196        "}\n";
     197    vshader1->compileSourceCode(vsrc1);
     198
     199    QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
     200    const char *fsrc1 =
    357201        "varying mediump vec4 color;\n"
    358202        "void main(void)\n"
    359203        "{\n"
    360204        "    gl_FragColor = color;\n"
    361         "}\n"
    362     };
    363     glShaderSource(fshader1, 1, fsrc1, 0);
    364     glCompileShader(fshader1);
    365     reportCompileErrors(fshader1, fsrc1[0]);
    366 
    367     program1 = glCreateProgram();
    368     glAttachShader(program1, vshader1);
    369     glAttachShader(program1, fshader1);
    370     glLinkProgram(program1);
    371     reportLinkErrors(program1, vsrc1[0], fsrc1[0]);
    372 
    373     vertexAttr1 = glGetAttribLocation(program1, "vertex");
    374     normalAttr1 = glGetAttribLocation(program1, "normal");
    375     matrixUniform1 = glGetUniformLocation(program1, "matrix");
    376 
    377     GLuint vshader2 = glCreateShader(GL_VERTEX_SHADER);
    378     const char *vsrc2[1] = {
     205        "}\n";
     206    fshader1->compileSourceCode(fsrc1);
     207
     208    program1.addShader(vshader1);
     209    program1.addShader(fshader1);
     210    program1.link();
     211
     212    vertexAttr1 = program1.attributeLocation("vertex");
     213    normalAttr1 = program1.attributeLocation("normal");
     214    matrixUniform1 = program1.uniformLocation("matrix");
     215
     216    QGLShader *vshader2 = new QGLShader(QGLShader::Vertex);
     217    const char *vsrc2 =
    379218        "attribute highp vec4 vertex;\n"
    380219        "attribute highp vec4 texCoord;\n"
     
    389228        "    gl_Position = matrix * vertex;\n"
    390229        "    texc = texCoord;\n"
    391         "}\n"
    392     };
    393     glShaderSource(vshader2, 1, vsrc2, 0);
    394     glCompileShader(vshader2);
    395     reportCompileErrors(vshader2, vsrc2[0]);
    396 
    397     GLuint fshader2 = glCreateShader(GL_FRAGMENT_SHADER);
    398     const char *fsrc2[1] = {
     230        "}\n";
     231    vshader2->compileSourceCode(vsrc2);
     232
     233    QGLShader *fshader2 = new QGLShader(QGLShader::Fragment);
     234    const char *fsrc2 =
    399235        "varying highp vec4 texc;\n"
    400236        "uniform sampler2D tex;\n"
     
    405241        "    color = color * 0.2 + color * 0.8 * angle;\n"
    406242        "    gl_FragColor = vec4(clamp(color, 0.0, 1.0), 1.0);\n"
    407         "}\n"
    408     };
    409     glShaderSource(fshader2, 1, fsrc2, 0);
    410     glCompileShader(fshader2);
    411     reportCompileErrors(fshader2, fsrc2[0]);
    412 
    413     program2 = glCreateProgram();
    414     glAttachShader(program2, vshader2);
    415     glAttachShader(program2, fshader2);
    416     glLinkProgram(program2);
    417     reportLinkErrors(program2, vsrc2[0], fsrc2[0]);
    418 
    419     vertexAttr2 = glGetAttribLocation(program2, "vertex");
    420     normalAttr2 = glGetAttribLocation(program2, "normal");
    421     texCoordAttr2 = glGetAttribLocation(program2, "texCoord");
    422     matrixUniform2 = glGetUniformLocation(program2, "matrix");
    423     textureUniform2 = glGetUniformLocation(program2, "tex");
     243        "}\n";
     244    fshader2->compileSourceCode(fsrc2);
     245
     246    program2.addShader(vshader2);
     247    program2.addShader(fshader2);
     248    program2.link();
     249
     250    vertexAttr2 = program2.attributeLocation("vertex");
     251    normalAttr2 = program2.attributeLocation("normal");
     252    texCoordAttr2 = program2.attributeLocation("texCoord");
     253    matrixUniform2 = program2.uniformLocation("matrix");
     254    textureUniform2 = program2.uniformLocation("tex");
    424255
    425256    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
     
    439270    painter.begin(this);
    440271
     272    painter.beginNativePainting();
     273
    441274    glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
    442275    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    443     glEnable(GL_TEXTURE_2D);
    444276
    445277    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
     
    451283    glEnable(GL_DEPTH_TEST);
    452284
    453     GLfloat modelview[16];
    454     IdentityMatrix(modelview);
    455     RotateMatrix(modelview, m_fAngle, 0.0, 1.0, 0.0);
    456     RotateMatrix(modelview, m_fAngle, 1.0, 0.0, 0.0);
    457     RotateMatrix(modelview, m_fAngle, 0.0, 0.0, 1.0);
    458     ScaleMatrix(modelview, m_fScale, m_fScale, m_fScale);
    459     TranslateMatrix(modelview, 0, -0.2, 0);
     285    QMatrix4x4 modelview;
     286    modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
     287    modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
     288    modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
     289    modelview.scale(m_fScale);
     290    modelview.translate(0.0f, -0.2f, 0.0f);
    460291
    461292    if (qtLogo) {
    462         glUseProgram(program1);
    463         glUniformMatrix4fv(matrixUniform1, 1, GL_FALSE, modelview);
     293        program1.bind();
     294        program1.setUniformValue(matrixUniform1, modelview);
    464295        paintQtLogo();
    465         glUseProgram(0);
     296        program1.release();
    466297    } else {
    467         glUseProgram(program2);
    468         glUniformMatrix4fv(matrixUniform2, 1, GL_FALSE, modelview);
     298        program2.bind();
     299        program1.setUniformValue(matrixUniform2, modelview);
    469300        paintTexturedCube();
    470         glUseProgram(0);
     301        program2.release();
    471302    }
    472303
    473304    glDisable(GL_DEPTH_TEST);
    474305    glDisable(GL_CULL_FACE);
     306
     307    painter.endNativePainting();
    475308
    476309    if (m_showBubbles)
     
    564397    }
    565398
    566     m_vertexNumber = vertices.size();
    567     createdVertices = new GLfloat[m_vertexNumber];
    568     createdNormals = new GLfloat[m_vertexNumber];
    569     for (int i = 0;i < m_vertexNumber;i++) {
    570       createdVertices[i] = vertices.at(i) * 2;
    571       createdNormals[i] = normals.at(i);
    572     }
    573     vertices.clear();
    574     normals.clear();
     399    for (int i = 0;i < vertices.size();i++)
     400        vertices[i] *= 2.0f;
    575401}
    576402
    577403void GLWidget::quad(qreal x1, qreal y1, qreal x2, qreal y2, qreal x3, qreal y3, qreal x4, qreal y4)
    578404{
    579     qreal nx, ny, nz;
    580 
    581     vertices << x1 << y1 << -0.05f;
    582     vertices << x2 << y2 << -0.05f;
    583     vertices << x4 << y4 << -0.05f;
    584 
    585     vertices << x3 << y3 << -0.05f;
    586     vertices << x4 << y4 << -0.05f;
    587     vertices << x2 << y2 << -0.05f;
    588 
    589     CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0, x4 - x1, y4 - y1, 0);
    590     Normalize(nx, ny, nz);
    591 
    592     normals << nx << ny << nz;
    593     normals << nx << ny << nz;
    594     normals << nx << ny << nz;
    595 
    596     normals << nx << ny << nz;
    597     normals << nx << ny << nz;
    598     normals << nx << ny << nz;
    599 
    600     vertices << x4 << y4 << 0.05f;
    601     vertices << x2 << y2 << 0.05f;
    602     vertices << x1 << y1 << 0.05f;
    603 
    604     vertices << x2 << y2 << 0.05f;
    605     vertices << x4 << y4 << 0.05f;
    606     vertices << x3 << y3 << 0.05f;
    607 
    608     CrossProduct(nx, ny, nz, x2 - x4, y2 - y4, 0, x1 - x4, y1 - y4, 0);
    609     Normalize(nx, ny, nz);
    610 
    611     normals << nx << ny << nz;
    612     normals << nx << ny << nz;
    613     normals << nx << ny << nz;
    614 
    615     normals << nx << ny << nz;
    616     normals << nx << ny << nz;
    617     normals << nx << ny << nz;
     405    vertices << QVector3D(x1, y1, -0.05f);
     406    vertices << QVector3D(x2, y2, -0.05f);
     407    vertices << QVector3D(x4, y4, -0.05f);
     408
     409    vertices << QVector3D(x3, y3, -0.05f);
     410    vertices << QVector3D(x4, y4, -0.05f);
     411    vertices << QVector3D(x2, y2, -0.05f);
     412
     413    QVector3D n = QVector3D::normal
     414        (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(x4 - x1, y4 - y1, 0.0f));
     415
     416    normals << n;
     417    normals << n;
     418    normals << n;
     419
     420    normals << n;
     421    normals << n;
     422    normals << n;
     423
     424    vertices << QVector3D(x4, y4, 0.05f);
     425    vertices << QVector3D(x2, y2, 0.05f);
     426    vertices << QVector3D(x1, y1, 0.05f);
     427
     428    vertices << QVector3D(x2, y2, 0.05f);
     429    vertices << QVector3D(x4, y4, 0.05f);
     430    vertices << QVector3D(x3, y3, 0.05f);
     431
     432    n = QVector3D::normal
     433        (QVector3D(x2 - x4, y2 - y4, 0.0f), QVector3D(x1 - x4, y1 - y4, 0.0f));
     434
     435    normals << n;
     436    normals << n;
     437    normals << n;
     438
     439    normals << n;
     440    normals << n;
     441    normals << n;
    618442}
    619443
    620444void GLWidget::extrude(qreal x1, qreal y1, qreal x2, qreal y2)
    621445{
    622     qreal nx, ny, nz;
    623 
    624     vertices << x1 << y1 << +0.05f;
    625     vertices << x2 << y2 << +0.05f;
    626     vertices << x1 << y1 << -0.05f;
    627 
    628     vertices << x2 << y2 << -0.05f;
    629     vertices << x1 << y1 << -0.05f;
    630     vertices << x2 << y2 << +0.05f;
    631 
    632     CrossProduct(nx, ny, nz, x2 - x1, y2 - y1, 0.0f, 0.0f, 0.0f, -0.1f);
    633     Normalize(nx, ny, nz);
    634 
    635     normals << nx << ny << nz;
    636     normals << nx << ny << nz;
    637     normals << nx << ny << nz;
    638 
    639     normals << nx << ny << nz;
    640     normals << nx << ny << nz;
    641     normals << nx << ny << nz;
    642 }
     446    vertices << QVector3D(x1, y1, +0.05f);
     447    vertices << QVector3D(x2, y2, +0.05f);
     448    vertices << QVector3D(x1, y1, -0.05f);
     449
     450    vertices << QVector3D(x2, y2, -0.05f);
     451    vertices << QVector3D(x1, y1, -0.05f);
     452    vertices << QVector3D(x2, y2, +0.05f);
     453
     454    QVector3D n = QVector3D::normal
     455        (QVector3D(x2 - x1, y2 - y1, 0.0f), QVector3D(0.0f, 0.0f, -0.1f));
     456
     457    normals << n;
     458    normals << n;
     459    normals << n;
     460
     461    normals << n;
     462    normals << n;
     463    normals << n;
     464}
Note: See TracChangeset for help on using the changeset viewer.