Changeset 561 for trunk/demos/boxes


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:
3 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/demos/boxes/basic.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/basic.vsh

    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 demonstration applications 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**
  • trunk/demos/boxes/boxes.pro

    r2 r561  
    1212           glbuffers.h \
    1313           glextensions.h \
    14            glshaders.h \
    1514           gltrianglemesh.h \
    1615           qtbox.h \
    1716           roundedbox.h \
    1817           scene.h \
    19            trackball.h \
    20            vector.h
     18           trackball.h
    2119SOURCES += 3rdparty/fbm.c \
    2220           glbuffers.cpp \
    2321           glextensions.cpp \
    24            glshaders.cpp \
    2522           main.cpp \
    2623           qtbox.cpp \
     
    4643
    4744win32-msvc* {
    48     QMAKE_CXXFLAGS += /Zm1200
    49     QMAKE_CFLAGS += /Zm1200
     45    QMAKE_CXXFLAGS -= -Zm200
     46    QMAKE_CFLAGS -= -Zm200
     47    QMAKE_CXXFLAGS += -Zm500
     48    QMAKE_CFLAGS += -Zm500
    5049}
  • trunk/demos/boxes/dotted.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/fresnel.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/glass.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/glbuffers.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 demonstration applications 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**
     
    4141
    4242#include "glbuffers.h"
     43#include <QtGui/qmatrix4x4.h>
    4344
    4445//============================================================================//
     
    347348}
    348349
    349 void GLRenderTargetCube::getViewMatrix(gfx::Matrix4x4f& mat, int face)
     350void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face)
    350351{
    351352    if (face < 0 || face >= 6) {
     
    372373    };
    373374
    374     memset(mat.bits(), 0, sizeof(float) * 16);
     375    mat.fill(0.0f);
    375376    for (int i = 0; i < 3; ++i)
    376         mat(perm[face][i], i) = signs[face][i];
     377        mat(i, perm[face][i]) = signs[face][i];
    377378    mat(3, 3) = 1.0f;
    378379}
    379380
    380 void GLRenderTargetCube::getProjectionMatrix(gfx::Matrix4x4f& mat, float nearZ, float farZ)
    381 {
    382     float proj[] = {
    383         1.0f, 0.0f, 0.0f, 0.0f,
    384         0.0f, 1.0f, 0.0f, 0.0f,
    385         0.0f, 0.0f, (nearZ+farZ)/(nearZ-farZ), -1.0f,
    386         0.0f, 0.0f, 2.0f*nearZ*farZ/(nearZ-farZ), 0.0f,
    387     };
    388 
    389     memcpy(mat.bits(), proj, sizeof(float) * 16);
    390 }
     381void GLRenderTargetCube::getProjectionMatrix(QMatrix4x4& mat, float nearZ, float farZ)
     382{
     383    static const QMatrix4x4 reference(
     384            1.0f, 0.0f, 0.0f, 0.0f,
     385            0.0f, 1.0f, 0.0f, 0.0f,
     386            0.0f, 0.0f, 0.0f, 0.0f,
     387            0.0f, 0.0f, -1.0f, 0.0f);
     388
     389    mat = reference;
     390    mat(2, 2) = (nearZ+farZ)/(nearZ-farZ);
     391    mat(2, 3) = 2.0f*nearZ*farZ/(nearZ-farZ);
     392}
  • trunk/demos/boxes/glbuffers.h

    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 demonstration applications 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**
     
    4848#include <QtGui>
    4949#include <QtOpenGL>
    50 
    51 #include "vector.h"
    5250
    5351#define BUFFER_OFFSET(i) ((char*)0 + (i))
     
    6058    returnStatement;                                                                        \
    6159}
     60
     61QT_BEGIN_NAMESPACE
     62class QMatrix4x4;
     63QT_END_NAMESPACE
    6264
    6365class GLTexture
     
    136138    virtual bool failed() {return m_failed || m_fbo.failed();}
    137139
    138     static void getViewMatrix(gfx::Matrix4x4f& mat, int face);
    139     static void getProjectionMatrix(gfx::Matrix4x4f& mat, float nearZ, float farZ);
     140    static void getViewMatrix(QMatrix4x4& mat, int face);
     141    static void getProjectionMatrix(QMatrix4x4& mat, float nearZ, float farZ);
    140142private:
    141143    GLFrameBufferObject m_fbo;
  • trunk/demos/boxes/glextensions.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 demonstration applications 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**
     
    4747{
    4848        bool ok = true;
    49 
    50         RESOLVE_GL_FUNC(CreateShaderObjectARB)
    51         RESOLVE_GL_FUNC(ShaderSourceARB)
    52         RESOLVE_GL_FUNC(CompileShaderARB)
    53         RESOLVE_GL_FUNC(GetObjectParameterivARB)
    54         RESOLVE_GL_FUNC(DeleteObjectARB)
    55         RESOLVE_GL_FUNC(GetInfoLogARB)
    56         RESOLVE_GL_FUNC(CreateProgramObjectARB)
    57         RESOLVE_GL_FUNC(AttachObjectARB)
    58         RESOLVE_GL_FUNC(DetachObjectARB)
    59         RESOLVE_GL_FUNC(LinkProgramARB)
    60         RESOLVE_GL_FUNC(UseProgramObjectARB)
    61         RESOLVE_GL_FUNC(GetUniformLocationARB)
    62         RESOLVE_GL_FUNC(Uniform1iARB)
    63         RESOLVE_GL_FUNC(Uniform1fARB)
    64         RESOLVE_GL_FUNC(Uniform4fARB)
    65         RESOLVE_GL_FUNC(UniformMatrix4fvARB)
    6649
    6750        RESOLVE_GL_FUNC(GenFramebuffersEXT)
     
    8770
    8871        return ok;
    89 }
    90 
    91 bool GLExtensionFunctions::glslSupported() {
    92     return CreateShaderObjectARB
    93             && CreateShaderObjectARB
    94             && ShaderSourceARB
    95             && CompileShaderARB
    96             && GetObjectParameterivARB
    97             && DeleteObjectARB
    98             && GetInfoLogARB
    99             && CreateProgramObjectARB
    100             && AttachObjectARB
    101             && DetachObjectARB
    102             && LinkProgramARB
    103             && UseProgramObjectARB
    104             && GetUniformLocationARB
    105             && Uniform1iARB
    106             && Uniform1fARB
    107             && Uniform4fARB
    108             && UniformMatrix4fvARB;
    10972}
    11073
  • trunk/demos/boxes/glextensions.h

    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 demonstration applications 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**
     
    4747/*
    4848Functions resolved:
    49 
    50 glCreateShaderObjectARB
    51 glShaderSourceARB
    52 glCompileShaderARB
    53 glGetObjectParameterivARB
    54 glDeleteObjectARB
    55 glGetInfoLogARB
    56 glCreateProgramObjectARB
    57 glAttachObjectARB
    58 glDetachObjectARB
    59 glLinkProgramARB
    60 glUseProgramObjectARB
    61 glGetUniformLocationARB
    62 glUniform1iARB
    63 glUniform1fARB
    64 glUniform4fARB
    65 glUniformMatrix4fvARB
    6649
    6750glGenFramebuffersEXT
     
    121104#endif
    122105
     106#ifndef GL_ARB_vertex_buffer_object
     107typedef ptrdiff_t GLsizeiptrARB;
     108#endif
     109
    123110#ifndef GL_VERSION_1_5
    124 typedef ptrdiff_t GLsizeiptr;
    125111#define GL_ARRAY_BUFFER 0x8892
    126112#define GL_ELEMENT_ARRAY_BUFFER 0x8893
     
    136122#define GL_DEPTH_ATTACHMENT_EXT 0x8D00
    137123#endif
    138 
    139 #ifndef GL_ARB_vertex_shader
    140 #define GL_VERTEX_SHADER_ARB 0x8B31
    141 #endif
    142 
    143 #ifndef GL_ARB_fragment_shader
    144 #define GL_FRAGMENT_SHADER_ARB 0x8B30
    145 #endif
    146 
    147 #ifndef GL_ARB_shader_objects
    148 typedef char GLcharARB;
    149 typedef unsigned int GLhandleARB;
    150 #define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81
    151 #define GL_OBJECT_LINK_STATUS_ARB 0x8B82
    152 #define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84
    153 #endif
    154 
    155 typedef GLhandleARB (APIENTRY *_glCreateShaderObjectARB) (GLenum);
    156 typedef void (APIENTRY *_glShaderSourceARB) (GLhandleARB, GLuint, const GLcharARB**, GLint *);
    157 typedef void (APIENTRY *_glCompileShaderARB) (GLhandleARB);
    158 typedef void (APIENTRY *_glGetObjectParameterivARB) (GLhandleARB, GLenum, int *);
    159 typedef void (APIENTRY *_glDeleteObjectARB) (GLhandleARB);
    160 typedef void (APIENTRY *_glGetInfoLogARB) (GLhandleARB, GLsizei, GLsizei *, GLcharARB *);
    161 typedef GLhandleARB (APIENTRY *_glCreateProgramObjectARB) ();
    162 typedef void (APIENTRY *_glAttachObjectARB) (GLhandleARB, GLhandleARB);
    163 typedef void (APIENTRY *_glDetachObjectARB) (GLhandleARB, GLhandleARB);
    164 typedef void (APIENTRY *_glLinkProgramARB) (GLhandleARB);
    165 typedef void (APIENTRY *_glUseProgramObjectARB) (GLhandleARB);
    166 typedef GLint (APIENTRY *_glGetUniformLocationARB) (GLhandleARB, const GLcharARB *);
    167 typedef void (APIENTRY *_glUniform1iARB) (GLint, GLint);
    168 typedef void (APIENTRY *_glUniform1fARB) (GLint, GLfloat);
    169 typedef void (APIENTRY *_glUniform4fARB) (GLint, GLfloat, GLfloat, GLfloat, GLfloat);
    170 typedef void (APIENTRY *_glUniformMatrix4fvARB) (GLint, GLuint, GLboolean, const GLfloat *);
    171124
    172125typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei, GLuint *);
     
    186139typedef void (APIENTRY *_glGenBuffers) (GLsizei, GLuint *);
    187140typedef void (APIENTRY *_glBindBuffer) (GLenum, GLuint);
    188 typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptr, const GLvoid *, GLenum);
     141typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum);
    189142typedef void (APIENTRY *_glDeleteBuffers) (GLsizei, const GLuint *);
    190143typedef void *(APIENTRY *_glMapBuffer) (GLenum, GLenum);
     
    195148        bool resolve(const QGLContext *context);
    196149
    197     bool glslSupported();
    198150    bool fboSupported();
    199151    bool openGL15Supported(); // the rest: multi-texture, 3D-texture, vertex buffer objects
    200 
    201         _glCreateShaderObjectARB CreateShaderObjectARB;
    202         _glShaderSourceARB ShaderSourceARB;
    203         _glCompileShaderARB CompileShaderARB;
    204         _glGetObjectParameterivARB GetObjectParameterivARB;
    205         _glDeleteObjectARB DeleteObjectARB;
    206         _glGetInfoLogARB GetInfoLogARB;
    207         _glCreateProgramObjectARB CreateProgramObjectARB;
    208         _glAttachObjectARB AttachObjectARB;
    209         _glDetachObjectARB DetachObjectARB;
    210         _glLinkProgramARB LinkProgramARB;
    211         _glUseProgramObjectARB UseProgramObjectARB;
    212         _glGetUniformLocationARB GetUniformLocationARB;
    213         _glUniform1iARB Uniform1iARB;
    214         _glUniform1fARB Uniform1fARB;
    215         _glUniform4fARB Uniform4fARB;
    216         _glUniformMatrix4fvARB UniformMatrix4fvARB;
    217152
    218153        _glGenFramebuffersEXT GenFramebuffersEXT;
     
    244179}
    245180
    246 #define glCreateShaderObjectARB getGLExtensionFunctions().CreateShaderObjectARB
    247 #define glShaderSourceARB getGLExtensionFunctions().ShaderSourceARB
    248 #define glCompileShaderARB getGLExtensionFunctions().CompileShaderARB
    249 #define glGetObjectParameterivARB getGLExtensionFunctions().GetObjectParameterivARB
    250 #define glDeleteObjectARB getGLExtensionFunctions().DeleteObjectARB
    251 #define glGetInfoLogARB getGLExtensionFunctions().GetInfoLogARB
    252 #define glCreateProgramObjectARB getGLExtensionFunctions().CreateProgramObjectARB
    253 #define glAttachObjectARB getGLExtensionFunctions().AttachObjectARB
    254 #define glDetachObjectARB getGLExtensionFunctions().DetachObjectARB
    255 #define glLinkProgramARB getGLExtensionFunctions().LinkProgramARB
    256 #define glUseProgramObjectARB getGLExtensionFunctions().UseProgramObjectARB
    257 #define glGetUniformLocationARB getGLExtensionFunctions().GetUniformLocationARB
    258 #define glUniform1iARB getGLExtensionFunctions().Uniform1iARB
    259 #define glUniform1fARB getGLExtensionFunctions().Uniform1fARB
    260 #define glUniform4fARB getGLExtensionFunctions().Uniform4fARB
    261 #define glUniformMatrix4fvARB getGLExtensionFunctions().UniformMatrix4fvARB
    262 
    263181#define glGenFramebuffersEXT getGLExtensionFunctions().GenFramebuffersEXT
    264182#define glGenRenderbuffersEXT getGLExtensionFunctions().GenRenderbuffersEXT
  • trunk/demos/boxes/gltrianglemesh.h

    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 demonstration applications 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**
  • trunk/demos/boxes/granite.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/main.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 demonstration applications 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**
     
    6969{
    7070    int subStringLength = strlen(subString);
    71     return (strncmp(extensionString, subString, subStringLength) == 0) 
     71    return (strncmp(extensionString, subString, subStringLength) == 0)
    7272        && ((extensionString[subStringLength] == ' ') || (extensionString[subStringLength] == '\0'));
    7373}
     
    138138        "work poorly or not at all on your system.");
    139139
     140    widget->makeCurrent(); // The current context must be set before calling Scene's constructor
     141    Scene scene(1024, 768, maxTextureSize);
    140142    GraphicsView view;
    141143    view.setViewport(widget);
    142144    view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    143     widget->makeCurrent(); // The current context must be set before calling Scene's constructor
    144     view.setScene(new Scene(1024, 768, maxTextureSize));
     145    view.setScene(&scene);
    145146    view.show();
    146147
  • trunk/demos/boxes/marble.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/qtbox.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 demonstration applications 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**
     
    123123
    124124    foreach (QGraphicsItem *item, selected) {
    125         ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
     125        ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
    126126        if (itemBase)
    127127            scene->addItem(itemBase->createNew(itemBase->m_size, itemBase->pos().x() + itemBase->m_size, itemBase->pos().y()));
     
    138138
    139139    foreach (QGraphicsItem *item, selected) {
    140         ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
     140        ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
    141141        if (itemBase)
    142142            delete itemBase;
     
    153153
    154154    foreach (QGraphicsItem *item, selected) {
    155         ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
     155        ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
    156156        if (itemBase) {
    157157            itemBase->prepareGeometryChange();
     
    172172
    173173    foreach (QGraphicsItem *item, selected) {
    174         ItemBase *itemBase = dynamic_cast<ItemBase *>(item);
     174        ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item);
    175175        if (itemBase) {
    176176            itemBase->prepareGeometryChange();
     
    258258}
    259259
     260int ItemBase::type() const
     261{
     262    return Type;
     263}
     264
     265
    260266bool ItemBase::isInResizeArea(const QPointF &pos)
    261267{
     
    270276{
    271277    for (int i = 0; i < 8; ++i) {
    272         m_vertices[i][0] = (i & 1 ? 0.5f : -0.5f);
    273         m_vertices[i][1] = (i & 2 ? 0.5f : -0.5f);
    274         m_vertices[i][2] = (i & 4 ? 0.5f : -0.5f);
     278        m_vertices[i].setX(i & 1 ? 0.5f : -0.5f);
     279        m_vertices[i].setY(i & 2 ? 0.5f : -0.5f);
     280        m_vertices[i].setZ(i & 4 ? 0.5f : -0.5f);
    275281    }
    276282    for (int i = 0; i < 4; ++i) {
    277         m_texCoords[i][0] = (i & 1 ? 1.0f : 0.0f);
    278         m_texCoords[i][1] = (i & 2 ? 1.0f : 0.0f);
    279     }
    280     memset(m_normals, 0, sizeof(m_normals));
    281     for (int i = 0; i < 3; ++i) {
    282         m_normals[2 * i + 0][i] = -1.0f;
    283         m_normals[2 * i + 1][i] = 1.0f;
    284     }
     283        m_texCoords[i].setX(i & 1 ? 1.0f : 0.0f);
     284        m_texCoords[i].setY(i & 2 ? 1.0f : 0.0f);
     285    }
     286    m_normals[0] = QVector3D(-1.0f, 0.0f, 0.0f);
     287    m_normals[1] = QVector3D(1.0f, 0.0f, 0.0f);
     288    m_normals[2] = QVector3D(0.0f, -1.0f, 0.0f);
     289    m_normals[3] = QVector3D(0.0f, 1.0f, 0.0f);
     290    m_normals[4] = QVector3D(0.0f, 0.0f, -1.0f);
     291    m_normals[5] = QVector3D(0.0f, 0.0f, 1.0f);
    285292}
    286293
     
    313320    };
    314321
     322    painter->beginNativePainting();
     323
    315324    glMatrixMode(GL_PROJECTION);
    316325    glPushMatrix();
     
    352361
    353362        glBegin(GL_TRIANGLE_STRIP);
    354         glNormal3fv(m_normals[2 * dir + 0].bits());
     363        glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 0]));
    355364        for (int i = 0; i < 2; ++i) {
    356365            for (int j = 0; j < 2; ++j) {
    357                 glTexCoord2fv(m_texCoords[(j << 1) | i].bits());
    358                 glVertex3fv(m_vertices[(i << ((dir + 2) % 3)) | (j << ((dir + 1) % 3))].bits());
     366                glTexCoord2fv(reinterpret_cast<float *>(&m_texCoords[(j << 1) | i]));
     367                glVertex3fv(reinterpret_cast<float *>(&m_vertices[(i << ((dir + 2) % 3)) | (j << ((dir + 1) % 3))]));
    359368            }
    360369        }
     
    362371
    363372        glBegin(GL_TRIANGLE_STRIP);
    364         glNormal3fv(m_normals[2 * dir + 1].bits());
     373        glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 1]));
    365374        for (int i = 0; i < 2; ++i) {
    366375            for (int j = 0; j < 2; ++j) {
    367                 glTexCoord2fv(m_texCoords[(j << 1) | i].bits());
    368                 glVertex3fv(m_vertices[(1 << dir) | (i << ((dir + 1) % 3)) | (j << ((dir + 2) % 3))].bits());
     376                glTexCoord2fv(reinterpret_cast<float *>(&m_texCoords[(j << 1) | i]));
     377                glVertex3fv(reinterpret_cast<float *>(&m_vertices[(1 << dir) | (i << ((dir + 1) % 3)) | (j << ((dir + 2) % 3))]));
    369378            }
    370379        }
     
    385394    glMatrixMode(GL_PROJECTION);
    386395    glPopMatrix();
     396
     397    painter->endNativePainting();
    387398
    388399    ItemBase::paint(painter, option, widget);
  • trunk/demos/boxes/qtbox.h

    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 demonstration applications 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**
     
    4545#include <QtGui>
    4646
    47 #include "vector.h"
     47#include <QtGui/qvector3d.h>
    4848#include "glbuffers.h"
    4949
    50 class ItemBase : public QObject, public QGraphicsItem
     50class ItemBase : public QGraphicsItem
    5151{
    52     Q_OBJECT
    5352public:
     53    enum { Type = UserType + 1 };
     54
    5455    ItemBase(int size, int x, int y);
    5556    virtual ~ItemBase();
     
    6566    virtual void keyPressEvent(QKeyEvent *event);
    6667    virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
     68    virtual int type() const;
    6769    bool isInResizeArea(const QPointF &pos);
    6870
     
    8688    virtual ItemBase *createNew(int size, int x, int y);
    8789private:
    88     gfx::Vector3f m_vertices[8];
    89     gfx::Vector2f m_texCoords[4];
    90     gfx::Vector3f m_normals[6];
     90    QVector3D m_vertices[8];
     91    QVector3D m_texCoords[4];
     92    QVector3D m_normals[6];
    9193    GLTexture *m_texture;
    9294};
  • trunk/demos/boxes/reflection.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/refraction.fsh

    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 demonstration applications 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**
  • trunk/demos/boxes/roundedbox.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 demonstration applications 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**
     
    4747
    4848VertexDescription P3T2N3Vertex::description[] = {
    49     {VertexDescription::Position, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, position) / sizeof(float), offsetof(P3T2N3Vertex, position), 0},
    50     {VertexDescription::TexCoord, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, texCoord) / sizeof(float), offsetof(P3T2N3Vertex, texCoord), 0},
    51     {VertexDescription::Normal, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, normal) / sizeof(float), offsetof(P3T2N3Vertex, normal), 0},
     49    {VertexDescription::Position, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, position) / sizeof(float), 0, 0},
     50    {VertexDescription::TexCoord, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, texCoord) / sizeof(float), sizeof(QVector3D), 0},
     51    {VertexDescription::Normal, GL_FLOAT, SIZE_OF_MEMBER(P3T2N3Vertex, normal) / sizeof(float), sizeof(QVector3D) + sizeof(QVector2D), 0},
     52
    5253    {VertexDescription::Null, 0, 0, 0, 0},
    5354};
     
    7980
    8081    for (int corner = 0; corner < 8; ++corner) {
    81         gfx::Vector3f centre;
    82         centre[0] = (corner & 1 ? 1.0f : -1.0f);
    83         centre[1] = (corner & 2 ? 1.0f : -1.0f);
    84         centre[2] = (corner & 4 ? 1.0f : -1.0f);
     82        QVector3D centre(corner & 1 ? 1.0f : -1.0f,
     83                corner & 2 ? 1.0f : -1.0f,
     84                corner & 4 ? 1.0f : -1.0f);
    8585        int winding = (corner & 1) ^ ((corner >> 1) & 1) ^ (corner >> 2);
    8686        int offsX = ((corner ^ 1) - corner) * vertexCountPerCorner;
     
    130130
    131131            for (int j = 0; j <= i; ++j) {
    132                 gfx::Vector3f normal = gfx::Vector3f::vector(i - j, j, n + 1 - i).normalized();
    133                 gfx::Vector3f pos = centre * (0.5f - r + r * normal);
     132                QVector3D normal = QVector3D(i - j, j, n + 1 - i).normalized();
     133                QVector3D offset(0.5f - r, 0.5f - r, 0.5f - r);
     134                QVector3D pos = centre * (offset + r * normal);
    134135
    135136                vp[vidx].position = scale * pos;
    136137                vp[vidx].normal = centre * normal;
    137                 vp[vidx].texCoord = gfx::Vector2f::vector(pos[0], pos[1]) + 0.5f;
     138                vp[vidx].texCoord = QVector2D(pos.x() + 0.5f, pos.y() + 0.5f);
    138139
    139140                // Corner polygons
  • trunk/demos/boxes/roundedbox.h

    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 demonstration applications 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**
     
    5050
    5151#include "gltrianglemesh.h"
    52 #include "vector.h"
     52#include <QtGui/qvector3d.h>
     53#include <QtGui/qvector2d.h>
    5354#include "glbuffers.h"
    5455
    5556struct P3T2N3Vertex
    5657{
    57     gfx::Vector3f position;
    58     gfx::Vector2f texCoord;
    59     gfx::Vector3f normal;
     58    QVector3D position;
     59    QVector2D texCoord;
     60    QVector3D normal;
    6061    static VertexDescription description[];
    6162};
  • trunk/demos/boxes/scene.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 demonstration applications 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**
    4040****************************************************************************/
    4141
     42#include <QDebug>
    4243#include "scene.h"
     44#include <QtGui/qmatrix4x4.h>
     45#include <QtGui/qvector3d.h>
    4346
    4447#include "3rdparty/fbm.h"
     
    343346                        m_parameterEdits << colorEdit;
    344347                        layout->addWidget(colorEdit);
    345                         connect(colorEdit, SIGNAL(colorChanged(QRgb, int)), this, SLOT(setColorParameter(QRgb, int)));
     348                        connect(colorEdit, SIGNAL(colorChanged(QRgb,int)), this, SLOT(setColorParameter(QRgb,int)));
    346349                        ++row;
    347350                    } else if (type == "float") {
     
    351354                        m_parameterEdits << floatEdit;
    352355                        layout->addWidget(floatEdit);
    353                         connect(floatEdit, SIGNAL(valueChanged(float, int)), this, SLOT(setFloatParameter(float, int)));
     356                        connect(floatEdit, SIGNAL(valueChanged(float,int)), this, SLOT(setFloatParameter(float,int)));
    354357                        ++row;
    355358                    }
     
    485488    setSceneRect(0, 0, width, height);
    486489
    487     m_trackBalls[0] = TrackBall(0.0005f, gfx::Vector3f::vector(0, 1, 0), TrackBall::Sphere);
    488     m_trackBalls[1] = TrackBall(0.0001f, gfx::Vector3f::vector(0, 0, 1), TrackBall::Sphere);
    489     m_trackBalls[2] = TrackBall(0.0f, gfx::Vector3f::vector(0, 1, 0), TrackBall::Plane);
     490    m_trackBalls[0] = TrackBall(0.05f, QVector3D(0, 1, 0), TrackBall::Sphere);
     491    m_trackBalls[1] = TrackBall(0.005f, QVector3D(0, 0, 1), TrackBall::Sphere);
     492    m_trackBalls[2] = TrackBall(0.0f, QVector3D(0, 1, 0), TrackBall::Plane);
    490493
    491494    m_renderOptions = new RenderOptionsDialog;
     
    494497
    495498    connect(m_renderOptions, SIGNAL(dynamicCubemapToggled(int)), this, SLOT(toggleDynamicCubemap(int)));
    496     connect(m_renderOptions, SIGNAL(colorParameterChanged(const QString &, QRgb)), this, SLOT(setColorParameter(const QString &, QRgb)));
    497     connect(m_renderOptions, SIGNAL(floatParameterChanged(const QString &, float)), this, SLOT(setFloatParameter(const QString &, float)));
     499    connect(m_renderOptions, SIGNAL(colorParameterChanged(QString,QRgb)), this, SLOT(setColorParameter(QString,QRgb)));
     500    connect(m_renderOptions, SIGNAL(floatParameterChanged(QString,float)), this, SLOT(setFloatParameter(QString,float)));
    498501    connect(m_renderOptions, SIGNAL(textureChanged(int)), this, SLOT(setTexture(int)));
    499502    connect(m_renderOptions, SIGNAL(shaderChanged(int)), this, SLOT(setShader(int)));
     
    532535    if (m_mainCubemap)
    533536        delete m_mainCubemap;
    534     foreach (GLProgram *program, m_programs)
     537    foreach (QGLShaderProgram *program, m_programs)
    535538        if (program) delete program;
    536539    if (m_vertexShader)
    537540        delete m_vertexShader;
    538     foreach (GLFragmentShader *shader, m_fragmentShaders)
     541    foreach (QGLShader *shader, m_fragmentShaders)
    539542        if (shader) delete shader;
    540543    foreach (GLRenderTargetCube *rt, m_cubemaps)
     
    550553    m_box = new GLRoundedBox(0.25f, 1.0f, 10);
    551554
    552     m_vertexShader = new GLVertexShader(":/res/boxes/basic.vsh");
     555    m_vertexShader = new QGLShader(QGLShader::Vertex);
     556    m_vertexShader->compileSourceFile(QLatin1String(":/res/boxes/basic.vsh"));
    553557
    554558    QStringList list;
     
    556560         << ":/res/boxes/cubemap_negy.jpg" << ":/res/boxes/cubemap_posz.jpg" << ":/res/boxes/cubemap_negz.jpg";
    557561    m_environment = new GLTextureCube(list, qMin(1024, m_maxTextureSize));
    558     m_environmentShader = new GLFragmentShader(environmentShaderText, strlen(environmentShaderText));
    559     m_environmentProgram = new GLProgram;
    560     m_environmentProgram->attach(*m_vertexShader);
    561     m_environmentProgram->attach(*m_environmentShader);
     562    m_environmentShader = new QGLShader(QGLShader::Fragment);
     563    m_environmentShader->compileSourceCode(environmentShaderText);
     564    m_environmentProgram = new QGLShaderProgram;
     565    m_environmentProgram->addShader(m_vertexShader);
     566    m_environmentProgram->addShader(m_environmentShader);
     567    m_environmentProgram->link();
    562568
    563569    const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed
     
    611617    files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable);
    612618    foreach (QFileInfo file, files) {
    613         GLProgram *program = new GLProgram;
    614         GLFragmentShader* shader = new GLFragmentShader(file.absoluteFilePath());
     619        QGLShaderProgram *program = new QGLShaderProgram;
     620        QGLShader* shader = new QGLShader(QGLShader::Fragment);
     621        shader->compileSourceFile(file.absoluteFilePath());
    615622        // The program does not take ownership over the shaders, so store them in a vector so they can be deleted afterwards.
    616         program->attach(*m_vertexShader);
    617         program->attach(*shader);
    618         if (program->failed()) {
     623        program->addShader(m_vertexShader);
     624        program->addShader(shader);
     625        if (!program->link()) {
    619626            qWarning("Failed to compile and link shader program");
    620627            qWarning("Vertex shader log:");
     
    635642
    636643        program->bind();
    637         m_cubemaps << (program->hasParameter("env") ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
    638         program->unbind();
     644        m_cubemaps << ((program->uniformLocation("env") != -1) ? new GLRenderTargetCube(qMin(256, m_maxTextureSize)) : 0);
     645        program->release();
    639646    }
    640647
    641648    if (m_programs.size() == 0)
    642         m_programs << new GLProgram;
     649        m_programs << new QGLShaderProgram;
    643650
    644651    m_renderOptions->emitParameterChanged();
     652}
     653
     654static void loadMatrix(const QMatrix4x4& m)
     655{
     656    GLfloat mat[16];
     657    const qreal *data = m.constData();
     658    for (int index = 0; index < 16; ++index)
     659        mat[index] = data[index];
     660    glLoadMatrixf(mat);
     661}
     662
     663static void multMatrix(const QMatrix4x4& m)
     664{
     665    GLfloat mat[16];
     666    const qreal *data = m.constData();
     667    for (int index = 0; index < 16; ++index)
     668        mat[index] = data[index];
     669    glMultMatrixf(mat);
    645670}
    646671
    647672// If one of the boxes should not be rendered, set excludeBox to its index.
    648673// If the main box should not be rendered, set excludeBox to -1.
    649 void Scene::renderBoxes(const gfx::Matrix4x4f &view, int excludeBox)
    650 {
    651     gfx::Matrix4x4f invView = view.inverse();
     674void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
     675{
     676    QMatrix4x4 invView = view.inverted();
    652677
    653678    // If multi-texturing is supported, use three saplers.
     
    665690    glDisable(GL_CULL_FACE);
    666691
    667     gfx::Matrix4x4f viewRotation(view);
     692    QMatrix4x4 viewRotation(view);
    668693    viewRotation(3, 0) = viewRotation(3, 1) = viewRotation(3, 2) = 0.0f;
    669694    viewRotation(0, 3) = viewRotation(1, 3) = viewRotation(2, 3) = 0.0f;
    670695    viewRotation(3, 3) = 1.0f;
    671     glLoadMatrixf(viewRotation.bits());
     696    loadMatrix(viewRotation);
    672697    glScalef(20.0f, 20.0f, 20.0f);
    673698
     
    676701        m_environment->bind();
    677702        m_environmentProgram->bind();
    678         m_environmentProgram->setInt("tex", 0);
    679         m_environmentProgram->setInt("env", 1);
    680         m_environmentProgram->setInt("noise", 2);
     703        m_environmentProgram->setUniformValue("tex", GLint(0));
     704        m_environmentProgram->setUniformValue("env", GLint(1));
     705        m_environmentProgram->setUniformValue("noise", GLint(2));
    681706        m_box->draw();
    682         m_environmentProgram->unbind();
     707        m_environmentProgram->release();
    683708        m_environment->unbind();
    684709    }
    685710
    686     glLoadMatrixf(view.bits());
     711    loadMatrix(view);
    687712
    688713    glEnable(GL_CULL_FACE);
     
    694719
    695720        glPushMatrix();
    696         gfx::Matrix4x4f m;
    697         m_trackBalls[1].rotation().matrix(m);
    698         glMultMatrixf(m.bits());
     721        QMatrix4x4 m;
     722        m.rotate(m_trackBalls[1].rotation());
     723        multMatrix(m);
    699724
    700725        glRotatef(360.0f * i / m_programs.size(), 0.0f, 0.0f, 1.0f);
     
    709734        }
    710735        m_programs[i]->bind();
    711         m_programs[i]->setInt("tex", 0);
    712         m_programs[i]->setInt("env", 1);
    713         m_programs[i]->setInt("noise", 2);
    714         m_programs[i]->setMatrix("view", view);
    715         m_programs[i]->setMatrix("invView", invView);
     736        m_programs[i]->setUniformValue("tex", GLint(0));
     737        m_programs[i]->setUniformValue("env", GLint(1));
     738        m_programs[i]->setUniformValue("noise", GLint(2));
     739        m_programs[i]->setUniformValue("view", view);
     740        m_programs[i]->setUniformValue("invView", invView);
    716741        m_box->draw();
    717         m_programs[i]->unbind();
     742        m_programs[i]->release();
    718743
    719744        if (glActiveTexture) {
     
    727752
    728753    if (-1 != excludeBox) {
    729         gfx::Matrix4x4f m;
    730         m_trackBalls[0].rotation().matrix(m);
    731         glMultMatrixf(m.bits());
     754        QMatrix4x4 m;
     755        m.rotate(m_trackBalls[0].rotation());
     756        multMatrix(m);
    732757
    733758        if (glActiveTexture) {
     
    739764
    740765        m_programs[m_currentShader]->bind();
    741         m_programs[m_currentShader]->setInt("tex", 0);
    742         m_programs[m_currentShader]->setInt("env", 1);
    743         m_programs[m_currentShader]->setInt("noise", 2);
    744         m_programs[m_currentShader]->setMatrix("view", view);
    745         m_programs[m_currentShader]->setMatrix("invView", invView);
     766        m_programs[m_currentShader]->setUniformValue("tex", GLint(0));
     767        m_programs[m_currentShader]->setUniformValue("env", GLint(1));
     768        m_programs[m_currentShader]->setUniformValue("noise", GLint(2));
     769        m_programs[m_currentShader]->setUniformValue("view", view);
     770        m_programs[m_currentShader]->setUniformValue("invView", invView);
    746771        m_box->draw();
    747         m_programs[m_currentShader]->unbind();
     772        m_programs[m_currentShader]->release();
    748773
    749774        if (glActiveTexture) {
     
    830855    const int N = (m_updateAllCubemaps ? 1 : 3);
    831856
    832     gfx::Matrix4x4f mat;
     857    QMatrix4x4 mat;
    833858    GLRenderTargetCube::getProjectionMatrix(mat, 0.1f, 100.0f);
    834859
    835860    glMatrixMode(GL_PROJECTION);
    836861    glPushMatrix();
    837     glLoadMatrixf(mat.bits());
     862    loadMatrix(mat);
    838863
    839864    glMatrixMode(GL_MODELVIEW);
    840865    glPushMatrix();
    841866
    842     gfx::Vector3f center;
     867    QVector3D center;
    843868
    844869    for (int i = m_frame % N; i < m_cubemaps.size(); i += N) {
     
    847872
    848873        float angle = 2.0f * PI * i / m_cubemaps.size();
    849         center = m_trackBalls[1].rotation().transform(gfx::Vector3f::vector(cos(angle), sin(angle), 0));
     874
     875        center = m_trackBalls[1].rotation().rotatedVector(QVector3D(cos(angle), sin(angle), 0.0f));
    850876
    851877        for (int face = 0; face < 6; ++face) {
     
    853879
    854880            GLRenderTargetCube::getViewMatrix(mat, face);
    855             gfx::Vector4f v = gfx::Vector4f::vector(-center[0], -center[1], -center[2], 1.0);
    856             mat[3] = v * mat;
     881            QVector4D v = QVector4D(-center.x(), -center.y(), -center.z(), 1.0);
     882            mat.setColumn(3, mat * v);
    857883
    858884            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    886912    float height = float(painter->device()->height());
    887913
     914    painter->beginNativePainting();
    888915    setStates();
    889916
     
    898925    glMatrixMode(GL_MODELVIEW);
    899926
    900     //gfx::Matrix4x4f view = gfx::Matrix4x4f::identity();
    901     //view(3, 2) -= 2.0f * exp(m_distExp / 1200.0f);
    902 
    903     gfx::Matrix4x4f view;
    904     m_trackBalls[2].rotation().matrix(view);
    905     view(3, 2) -= 2.0f * exp(m_distExp / 1200.0f);
     927    QMatrix4x4 view;
     928    view.rotate(m_trackBalls[2].rotation());
     929    view(2, 3) -= 2.0f * exp(m_distExp / 1200.0f);
    906930    renderBoxes(view);
    907931
    908932    defaultStates();
    909933    ++m_frame;
     934
     935    painter->endNativePainting();
    910936}
    911937
     
    937963
    938964    if (event->buttons() & Qt::MidButton) {
    939         m_trackBalls[2].move(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
     965        m_trackBalls[2].move(pixelPosToViewPos(event->scenePos()), QQuaternion());
    940966        event->accept();
    941967    } else {
    942         m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
     968        m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), QQuaternion());
    943969    }
    944970}
     
    961987
    962988    if (event->buttons() & Qt::MidButton) {
    963         m_trackBalls[2].push(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
     989        m_trackBalls[2].push(pixelPosToViewPos(event->scenePos()), QQuaternion());
    964990        event->accept();
    965991    }
     
    9831009
    9841010    if (event->button() == Qt::MidButton) {
    985         m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());
     1011        m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), QQuaternion());
    9861012        event->accept();
    9871013    }
     
    10221048{
    10231049    // set the color in all programs
    1024     foreach (GLProgram *program, m_programs) {
     1050    foreach (QGLShaderProgram *program, m_programs) {
    10251051        program->bind();
    1026         program->setColor(name, color);
    1027         program->unbind();
     1052        program->setUniformValue(program->uniformLocation(name), QColor(color));
     1053        program->release();
    10281054    }
    10291055}
     
    10321058{
    10331059    // set the color in all programs
    1034     foreach (GLProgram *program, m_programs) {
     1060    foreach (QGLShaderProgram *program, m_programs) {
    10351061        program->bind();
    1036         program->setFloat(name, value);
    1037         program->unbind();
     1062        program->setUniformValue(program->uniformLocation(name), value);
     1063        program->release();
    10381064    }
    10391065}
  • trunk/demos/boxes/scene.h

    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 demonstration applications 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**
     
    5151#include "roundedbox.h"
    5252#include "gltrianglemesh.h"
    53 #include "vector.h"
    5453#include "trackball.h"
    5554#include "glbuffers.h"
    56 #include "glshaders.h"
    5755#include "qtbox.h"
    5856
    5957#define PI 3.14159265358979
     58
     59QT_BEGIN_NAMESPACE
     60class QMatrix4x4;
     61QT_END_NAMESPACE
    6062
    6163class ParameterEdit : public QWidget
     
    107109class GraphicsWidget : public QGraphicsProxyWidget
    108110{
     111public:
     112    GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {}
    109113protected:
    110114    virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
     
    196200    void newItem(ItemDialog::ItemType type);
    197201protected:
    198     void renderBoxes(const gfx::Matrix4x4f &view, int excludeBox = -2);
     202    void renderBoxes(const QMatrix4x4 &view, int excludeBox = -2);
    199203    void setStates();
    200204    void setLights();
     
    232236    GLRenderTargetCube *m_mainCubemap;
    233237    QVector<GLRenderTargetCube *> m_cubemaps;
    234     QVector<GLProgram *> m_programs;
    235     GLVertexShader *m_vertexShader;
    236     QVector<GLFragmentShader *> m_fragmentShaders;
    237     GLFragmentShader *m_environmentShader;
    238     GLProgram *m_environmentProgram;
    239 };
    240 
    241 
     238    QVector<QGLShaderProgram *> m_programs;
     239    QGLShader *m_vertexShader;
     240    QVector<QGLShader *> m_fragmentShaders;
     241    QGLShader *m_environmentShader;
     242    QGLShaderProgram *m_environmentProgram;
     243};
    242244
    243245#endif
  • trunk/demos/boxes/trackball.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 demonstration applications 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**
     
    4141
    4242#include "trackball.h"
     43#include "scene.h"
    4344
    4445//============================================================================//
     
    5253    , m_mode(mode)
    5354{
    54     m_axis = gfx::Vector3f::vector(0, 1, 0);
    55     m_rotation = gfx::Quaternionf::quaternion(1.0f, 0.0f, 0.0f, 0.0f);
     55    m_axis = QVector3D(0, 1, 0);
     56    m_rotation = QQuaternion();
    5657    m_lastTime = QTime::currentTime();
    5758}
    5859
    59 TrackBall::TrackBall(float angularVelocity, const gfx::Vector3f& axis, TrackMode mode)
     60TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode)
    6061    : m_axis(axis)
    6162    , m_angularVelocity(angularVelocity)
     
    6465    , m_mode(mode)
    6566{
    66     m_rotation = gfx::Quaternionf::quaternion(1.0f, 0.0f, 0.0f, 0.0f);
     67    m_rotation = QQuaternion();
    6768    m_lastTime = QTime::currentTime();
    6869}
    6970
    70 void TrackBall::push(const QPointF& p, const gfx::Quaternionf &)
     71void TrackBall::push(const QPointF& p, const QQuaternion &)
    7172{
    7273    m_rotation = rotation();
     
    7778}
    7879
    79 void TrackBall::move(const QPointF& p, const gfx::Quaternionf &transformation)
     80void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
    8081{
    8182    if (!m_pressed)
     
    9192        {
    9293            QLineF delta(m_lastPos, p);
    93             m_angularVelocity = delta.length() / msecs;
    94             m_axis = gfx::Vector3f::vector(delta.dy(), -delta.dx(), 0.0f).normalized();
    95             m_axis = transformation.transform(m_axis);
    96             m_rotation *= gfx::Quaternionf::rotation(delta.length(), m_axis);
     94            m_angularVelocity = 180*delta.length() / (PI*msecs);
     95            m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized();
     96            m_axis = transformation.rotatedVector(m_axis);
     97            m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * delta.length()) * m_rotation;
    9798        }
    9899        break;
    99100    case Sphere:
    100101        {
    101             gfx::Vector3f lastPos3D = gfx::Vector3f::vector(m_lastPos.x(), m_lastPos.y(), 0);
    102             float sqrZ = 1 - lastPos3D.sqrNorm();
     102            QVector3D lastPos3D = QVector3D(m_lastPos.x(), m_lastPos.y(), 0.0f);
     103            float sqrZ = 1 - QVector3D::dotProduct(lastPos3D, lastPos3D);
    103104            if (sqrZ > 0)
    104                 lastPos3D[2] = sqrt(sqrZ);
     105                lastPos3D.setZ(sqrt(sqrZ));
    105106            else
    106107                lastPos3D.normalize();
    107108
    108             gfx::Vector3f currentPos3D = gfx::Vector3f::vector(p.x(), p.y(), 0);
    109             sqrZ = 1 - currentPos3D.sqrNorm();
     109            QVector3D currentPos3D = QVector3D(p.x(), p.y(), 0.0f);
     110            sqrZ = 1 - QVector3D::dotProduct(currentPos3D, currentPos3D);
    110111            if (sqrZ > 0)
    111                 currentPos3D[2] = sqrt(sqrZ);
     112                currentPos3D.setZ(sqrt(sqrZ));
    112113            else
    113114                currentPos3D.normalize();
    114115
    115             m_axis = gfx::Vector3f::cross(currentPos3D, lastPos3D);
    116             float angle = asin(sqrt(m_axis.sqrNorm()));
     116            m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
     117            float angle = 180 / PI * asin(sqrt(QVector3D::dotProduct(m_axis, m_axis)));
    117118
    118119            m_angularVelocity = angle / msecs;
    119120            m_axis.normalize();
    120             m_axis = transformation.transform(m_axis);
    121             m_rotation *= gfx::Quaternionf::rotation(angle, m_axis);
     121            m_axis = transformation.rotatedVector(m_axis);
     122            m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
    122123        }
    123124        break;
    124125    }
     126
    125127
    126128    m_lastPos = p;
     
    128130}
    129131
    130 void TrackBall::release(const QPointF& p, const gfx::Quaternionf &transformation)
     132void TrackBall::release(const QPointF& p, const QQuaternion &transformation)
    131133{
    132134    // Calling move() caused the rotation to stop if the framerate was too low.
     
    147149}
    148150
    149 gfx::Quaternionf TrackBall::rotation() const
     151QQuaternion TrackBall::rotation() const
    150152{
    151153    if (m_paused || m_pressed)
     
    154156    QTime currentTime = QTime::currentTime();
    155157    float angle = m_angularVelocity * m_lastTime.msecsTo(currentTime);
    156     return m_rotation * gfx::Quaternionf::rotation(angle, m_axis);
     158    return QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
    157159}
    158160
  • trunk/demos/boxes/trackball.h

    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 demonstration applications 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**
     
    4545#include <QtGui>
    4646
    47 #include "vector.h"
     47#include <QtGui/qvector3d.h>
     48#include <QtGui/qquaternion.h>
    4849
    4950class TrackBall
     
    5657    };
    5758    TrackBall(TrackMode mode = Sphere);
    58     TrackBall(float angularVelocity, const gfx::Vector3f& axis, TrackMode mode = Sphere);
     59    TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode = Sphere);
    5960    // coordinates in [-1,1]x[-1,1]
    60     void push(const QPointF& p, const gfx::Quaternionf &transformation);
    61     void move(const QPointF& p, const gfx::Quaternionf &transformation);
    62     void release(const QPointF& p, const gfx::Quaternionf &transformation);
     61    void push(const QPointF& p, const QQuaternion &transformation);
     62    void move(const QPointF& p, const QQuaternion &transformation);
     63    void release(const QPointF& p, const QQuaternion &transformation);
    6364    void start(); // starts clock
    6465    void stop(); // stops clock
    65     gfx::Quaternionf rotation() const;
     66    QQuaternion rotation() const;
    6667private:
    67     gfx::Quaternionf m_rotation;
    68     gfx::Vector3f m_axis;
     68    QQuaternion m_rotation;
     69    QVector3D m_axis;
    6970    float m_angularVelocity;
    7071
  • trunk/demos/boxes/wood.fsh

    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 demonstration applications 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**
Note: See TracChangeset for help on using the changeset viewer.