Changeset 561 for trunk/demos/boxes
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/demos/boxes/basic.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/basic.vsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/boxes.pro
r2 r561 12 12 glbuffers.h \ 13 13 glextensions.h \ 14 glshaders.h \15 14 gltrianglemesh.h \ 16 15 qtbox.h \ 17 16 roundedbox.h \ 18 17 scene.h \ 19 trackball.h \ 20 vector.h 18 trackball.h 21 19 SOURCES += 3rdparty/fbm.c \ 22 20 glbuffers.cpp \ 23 21 glextensions.cpp \ 24 glshaders.cpp \25 22 main.cpp \ 26 23 qtbox.cpp \ … … 46 43 47 44 win32-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 50 49 } -
trunk/demos/boxes/dotted.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/fresnel.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/glass.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/glbuffers.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include "glbuffers.h" 43 #include <QtGui/qmatrix4x4.h> 43 44 44 45 //============================================================================// … … 347 348 } 348 349 349 void GLRenderTargetCube::getViewMatrix( gfx::Matrix4x4f& mat, int face)350 void GLRenderTargetCube::getViewMatrix(QMatrix4x4& mat, int face) 350 351 { 351 352 if (face < 0 || face >= 6) { … … 372 373 }; 373 374 374 m emset(mat.bits(), 0, sizeof(float) * 16);375 mat.fill(0.0f); 375 376 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]; 377 378 mat(3, 3) = 1.0f; 378 379 } 379 380 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 } 381 void 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 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 48 48 #include <QtGui> 49 49 #include <QtOpenGL> 50 51 #include "vector.h"52 50 53 51 #define BUFFER_OFFSET(i) ((char*)0 + (i)) … … 60 58 returnStatement; \ 61 59 } 60 61 QT_BEGIN_NAMESPACE 62 class QMatrix4x4; 63 QT_END_NAMESPACE 62 64 63 65 class GLTexture … … 136 138 virtual bool failed() {return m_failed || m_fbo.failed();} 137 139 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); 140 142 private: 141 143 GLFrameBufferObject m_fbo; -
trunk/demos/boxes/glextensions.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 47 47 { 48 48 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)66 49 67 50 RESOLVE_GL_FUNC(GenFramebuffersEXT) … … 87 70 88 71 return ok; 89 }90 91 bool GLExtensionFunctions::glslSupported() {92 return CreateShaderObjectARB93 && CreateShaderObjectARB94 && ShaderSourceARB95 && CompileShaderARB96 && GetObjectParameterivARB97 && DeleteObjectARB98 && GetInfoLogARB99 && CreateProgramObjectARB100 && AttachObjectARB101 && DetachObjectARB102 && LinkProgramARB103 && UseProgramObjectARB104 && GetUniformLocationARB105 && Uniform1iARB106 && Uniform1fARB107 && Uniform4fARB108 && UniformMatrix4fvARB;109 72 } 110 73 -
trunk/demos/boxes/glextensions.h
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 47 47 /* 48 48 Functions resolved: 49 50 glCreateShaderObjectARB51 glShaderSourceARB52 glCompileShaderARB53 glGetObjectParameterivARB54 glDeleteObjectARB55 glGetInfoLogARB56 glCreateProgramObjectARB57 glAttachObjectARB58 glDetachObjectARB59 glLinkProgramARB60 glUseProgramObjectARB61 glGetUniformLocationARB62 glUniform1iARB63 glUniform1fARB64 glUniform4fARB65 glUniformMatrix4fvARB66 49 67 50 glGenFramebuffersEXT … … 121 104 #endif 122 105 106 #ifndef GL_ARB_vertex_buffer_object 107 typedef ptrdiff_t GLsizeiptrARB; 108 #endif 109 123 110 #ifndef GL_VERSION_1_5 124 typedef ptrdiff_t GLsizeiptr;125 111 #define GL_ARRAY_BUFFER 0x8892 126 112 #define GL_ELEMENT_ARRAY_BUFFER 0x8893 … … 136 122 #define GL_DEPTH_ATTACHMENT_EXT 0x8D00 137 123 #endif 138 139 #ifndef GL_ARB_vertex_shader140 #define GL_VERTEX_SHADER_ARB 0x8B31141 #endif142 143 #ifndef GL_ARB_fragment_shader144 #define GL_FRAGMENT_SHADER_ARB 0x8B30145 #endif146 147 #ifndef GL_ARB_shader_objects148 typedef char GLcharARB;149 typedef unsigned int GLhandleARB;150 #define GL_OBJECT_COMPILE_STATUS_ARB 0x8B81151 #define GL_OBJECT_LINK_STATUS_ARB 0x8B82152 #define GL_OBJECT_INFO_LOG_LENGTH_ARB 0x8B84153 #endif154 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 *);171 124 172 125 typedef void (APIENTRY *_glGenFramebuffersEXT) (GLsizei, GLuint *); … … 186 139 typedef void (APIENTRY *_glGenBuffers) (GLsizei, GLuint *); 187 140 typedef void (APIENTRY *_glBindBuffer) (GLenum, GLuint); 188 typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptr , const GLvoid *, GLenum);141 typedef void (APIENTRY *_glBufferData) (GLenum, GLsizeiptrARB, const GLvoid *, GLenum); 189 142 typedef void (APIENTRY *_glDeleteBuffers) (GLsizei, const GLuint *); 190 143 typedef void *(APIENTRY *_glMapBuffer) (GLenum, GLenum); … … 195 148 bool resolve(const QGLContext *context); 196 149 197 bool glslSupported();198 150 bool fboSupported(); 199 151 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;217 152 218 153 _glGenFramebuffersEXT GenFramebuffersEXT; … … 244 179 } 245 180 246 #define glCreateShaderObjectARB getGLExtensionFunctions().CreateShaderObjectARB247 #define glShaderSourceARB getGLExtensionFunctions().ShaderSourceARB248 #define glCompileShaderARB getGLExtensionFunctions().CompileShaderARB249 #define glGetObjectParameterivARB getGLExtensionFunctions().GetObjectParameterivARB250 #define glDeleteObjectARB getGLExtensionFunctions().DeleteObjectARB251 #define glGetInfoLogARB getGLExtensionFunctions().GetInfoLogARB252 #define glCreateProgramObjectARB getGLExtensionFunctions().CreateProgramObjectARB253 #define glAttachObjectARB getGLExtensionFunctions().AttachObjectARB254 #define glDetachObjectARB getGLExtensionFunctions().DetachObjectARB255 #define glLinkProgramARB getGLExtensionFunctions().LinkProgramARB256 #define glUseProgramObjectARB getGLExtensionFunctions().UseProgramObjectARB257 #define glGetUniformLocationARB getGLExtensionFunctions().GetUniformLocationARB258 #define glUniform1iARB getGLExtensionFunctions().Uniform1iARB259 #define glUniform1fARB getGLExtensionFunctions().Uniform1fARB260 #define glUniform4fARB getGLExtensionFunctions().Uniform4fARB261 #define glUniformMatrix4fvARB getGLExtensionFunctions().UniformMatrix4fvARB262 263 181 #define glGenFramebuffersEXT getGLExtensionFunctions().GenFramebuffersEXT 264 182 #define glGenRenderbuffersEXT getGLExtensionFunctions().GenRenderbuffersEXT -
trunk/demos/boxes/gltrianglemesh.h
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/granite.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/main.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 69 69 { 70 70 int subStringLength = strlen(subString); 71 return (strncmp(extensionString, subString, subStringLength) == 0) 71 return (strncmp(extensionString, subString, subStringLength) == 0) 72 72 && ((extensionString[subStringLength] == ' ') || (extensionString[subStringLength] == '\0')); 73 73 } … … 138 138 "work poorly or not at all on your system."); 139 139 140 widget->makeCurrent(); // The current context must be set before calling Scene's constructor 141 Scene scene(1024, 768, maxTextureSize); 140 142 GraphicsView view; 141 143 view.setViewport(widget); 142 144 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); 145 146 view.show(); 146 147 -
trunk/demos/boxes/marble.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/qtbox.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 123 123 124 124 foreach (QGraphicsItem *item, selected) { 125 ItemBase *itemBase = dynamic_cast<ItemBase *>(item);125 ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); 126 126 if (itemBase) 127 127 scene->addItem(itemBase->createNew(itemBase->m_size, itemBase->pos().x() + itemBase->m_size, itemBase->pos().y())); … … 138 138 139 139 foreach (QGraphicsItem *item, selected) { 140 ItemBase *itemBase = dynamic_cast<ItemBase *>(item);140 ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); 141 141 if (itemBase) 142 142 delete itemBase; … … 153 153 154 154 foreach (QGraphicsItem *item, selected) { 155 ItemBase *itemBase = dynamic_cast<ItemBase *>(item);155 ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); 156 156 if (itemBase) { 157 157 itemBase->prepareGeometryChange(); … … 172 172 173 173 foreach (QGraphicsItem *item, selected) { 174 ItemBase *itemBase = dynamic_cast<ItemBase *>(item);174 ItemBase *itemBase = qgraphicsitem_cast<ItemBase *>(item); 175 175 if (itemBase) { 176 176 itemBase->prepareGeometryChange(); … … 258 258 } 259 259 260 int ItemBase::type() const 261 { 262 return Type; 263 } 264 265 260 266 bool ItemBase::isInResizeArea(const QPointF &pos) 261 267 { … … 270 276 { 271 277 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); 275 281 } 276 282 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); 285 292 } 286 293 … … 313 320 }; 314 321 322 painter->beginNativePainting(); 323 315 324 glMatrixMode(GL_PROJECTION); 316 325 glPushMatrix(); … … 352 361 353 362 glBegin(GL_TRIANGLE_STRIP); 354 glNormal3fv( m_normals[2 * dir + 0].bits());363 glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 0])); 355 364 for (int i = 0; i < 2; ++i) { 356 365 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))])); 359 368 } 360 369 } … … 362 371 363 372 glBegin(GL_TRIANGLE_STRIP); 364 glNormal3fv( m_normals[2 * dir + 1].bits());373 glNormal3fv(reinterpret_cast<float *>(&m_normals[2 * dir + 1])); 365 374 for (int i = 0; i < 2; ++i) { 366 375 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))])); 369 378 } 370 379 } … … 385 394 glMatrixMode(GL_PROJECTION); 386 395 glPopMatrix(); 396 397 painter->endNativePainting(); 387 398 388 399 ItemBase::paint(painter, option, widget); -
trunk/demos/boxes/qtbox.h
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 45 45 #include <QtGui> 46 46 47 #include "vector.h"47 #include <QtGui/qvector3d.h> 48 48 #include "glbuffers.h" 49 49 50 class ItemBase : public Q Object, public QGraphicsItem50 class ItemBase : public QGraphicsItem 51 51 { 52 Q_OBJECT53 52 public: 53 enum { Type = UserType + 1 }; 54 54 55 ItemBase(int size, int x, int y); 55 56 virtual ~ItemBase(); … … 65 66 virtual void keyPressEvent(QKeyEvent *event); 66 67 virtual void wheelEvent(QGraphicsSceneWheelEvent *event); 68 virtual int type() const; 67 69 bool isInResizeArea(const QPointF &pos); 68 70 … … 86 88 virtual ItemBase *createNew(int size, int x, int y); 87 89 private: 88 gfx::Vector3fm_vertices[8];89 gfx::Vector2fm_texCoords[4];90 gfx::Vector3fm_normals[6];90 QVector3D m_vertices[8]; 91 QVector3D m_texCoords[4]; 92 QVector3D m_normals[6]; 91 93 GLTexture *m_texture; 92 94 }; -
trunk/demos/boxes/reflection.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/refraction.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** -
trunk/demos/boxes/roundedbox.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 47 47 48 48 VertexDescription 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 52 53 {VertexDescription::Null, 0, 0, 0, 0}, 53 54 }; … … 79 80 80 81 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); 85 85 int winding = (corner & 1) ^ ((corner >> 1) & 1) ^ (corner >> 2); 86 86 int offsX = ((corner ^ 1) - corner) * vertexCountPerCorner; … … 130 130 131 131 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); 134 135 135 136 vp[vidx].position = scale * pos; 136 137 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); 138 139 139 140 // Corner polygons -
trunk/demos/boxes/roundedbox.h
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 50 50 51 51 #include "gltrianglemesh.h" 52 #include "vector.h" 52 #include <QtGui/qvector3d.h> 53 #include <QtGui/qvector2d.h> 53 54 #include "glbuffers.h" 54 55 55 56 struct P3T2N3Vertex 56 57 { 57 gfx::Vector3fposition;58 gfx::Vector2ftexCoord;59 gfx::Vector3fnormal;58 QVector3D position; 59 QVector2D texCoord; 60 QVector3D normal; 60 61 static VertexDescription description[]; 61 62 }; -
trunk/demos/boxes/scene.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** 40 40 ****************************************************************************/ 41 41 42 #include <QDebug> 42 43 #include "scene.h" 44 #include <QtGui/qmatrix4x4.h> 45 #include <QtGui/qvector3d.h> 43 46 44 47 #include "3rdparty/fbm.h" … … 343 346 m_parameterEdits << colorEdit; 344 347 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))); 346 349 ++row; 347 350 } else if (type == "float") { … … 351 354 m_parameterEdits << floatEdit; 352 355 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))); 354 357 ++row; 355 358 } … … 485 488 setSceneRect(0, 0, width, height); 486 489 487 m_trackBalls[0] = TrackBall(0.0 005f, gfx::Vector3f::vector(0, 1, 0), TrackBall::Sphere);488 m_trackBalls[1] = TrackBall(0.00 01f, 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); 490 493 491 494 m_renderOptions = new RenderOptionsDialog; … … 494 497 495 498 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))); 498 501 connect(m_renderOptions, SIGNAL(textureChanged(int)), this, SLOT(setTexture(int))); 499 502 connect(m_renderOptions, SIGNAL(shaderChanged(int)), this, SLOT(setShader(int))); … … 532 535 if (m_mainCubemap) 533 536 delete m_mainCubemap; 534 foreach ( GLProgram *program, m_programs)537 foreach (QGLShaderProgram *program, m_programs) 535 538 if (program) delete program; 536 539 if (m_vertexShader) 537 540 delete m_vertexShader; 538 foreach ( GLFragmentShader *shader, m_fragmentShaders)541 foreach (QGLShader *shader, m_fragmentShaders) 539 542 if (shader) delete shader; 540 543 foreach (GLRenderTargetCube *rt, m_cubemaps) … … 550 553 m_box = new GLRoundedBox(0.25f, 1.0f, 10); 551 554 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")); 553 557 554 558 QStringList list; … … 556 560 << ":/res/boxes/cubemap_negy.jpg" << ":/res/boxes/cubemap_posz.jpg" << ":/res/boxes/cubemap_negz.jpg"; 557 561 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(); 562 568 563 569 const int NOISE_SIZE = 128; // for a different size, B and BM in fbm.c must also be changed … … 611 617 files = QDir(":/res/boxes/").entryInfoList(filter, QDir::Files | QDir::Readable); 612 618 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()); 615 622 // The program does not take ownership over the shaders, so store them in a vector so they can be deleted afterwards. 616 program->a ttach(*m_vertexShader);617 program->a ttach(*shader);618 if ( program->failed()) {623 program->addShader(m_vertexShader); 624 program->addShader(shader); 625 if (!program->link()) { 619 626 qWarning("Failed to compile and link shader program"); 620 627 qWarning("Vertex shader log:"); … … 635 642 636 643 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(); 639 646 } 640 647 641 648 if (m_programs.size() == 0) 642 m_programs << new GLProgram;649 m_programs << new QGLShaderProgram; 643 650 644 651 m_renderOptions->emitParameterChanged(); 652 } 653 654 static 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 663 static 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); 645 670 } 646 671 647 672 // If one of the boxes should not be rendered, set excludeBox to its index. 648 673 // 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();674 void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox) 675 { 676 QMatrix4x4 invView = view.inverted(); 652 677 653 678 // If multi-texturing is supported, use three saplers. … … 665 690 glDisable(GL_CULL_FACE); 666 691 667 gfx::Matrix4x4fviewRotation(view);692 QMatrix4x4 viewRotation(view); 668 693 viewRotation(3, 0) = viewRotation(3, 1) = viewRotation(3, 2) = 0.0f; 669 694 viewRotation(0, 3) = viewRotation(1, 3) = viewRotation(2, 3) = 0.0f; 670 695 viewRotation(3, 3) = 1.0f; 671 glLoadMatrixf(viewRotation.bits());696 loadMatrix(viewRotation); 672 697 glScalef(20.0f, 20.0f, 20.0f); 673 698 … … 676 701 m_environment->bind(); 677 702 m_environmentProgram->bind(); 678 m_environmentProgram->set Int("tex", 0);679 m_environmentProgram->set Int("env", 1);680 m_environmentProgram->set Int("noise", 2);703 m_environmentProgram->setUniformValue("tex", GLint(0)); 704 m_environmentProgram->setUniformValue("env", GLint(1)); 705 m_environmentProgram->setUniformValue("noise", GLint(2)); 681 706 m_box->draw(); 682 m_environmentProgram-> unbind();707 m_environmentProgram->release(); 683 708 m_environment->unbind(); 684 709 } 685 710 686 glLoadMatrixf(view.bits());711 loadMatrix(view); 687 712 688 713 glEnable(GL_CULL_FACE); … … 694 719 695 720 glPushMatrix(); 696 gfx::Matrix4x4fm;697 m _trackBalls[1].rotation().matrix(m);698 glMultMatrixf(m.bits());721 QMatrix4x4 m; 722 m.rotate(m_trackBalls[1].rotation()); 723 multMatrix(m); 699 724 700 725 glRotatef(360.0f * i / m_programs.size(), 0.0f, 0.0f, 1.0f); … … 709 734 } 710 735 m_programs[i]->bind(); 711 m_programs[i]->set Int("tex", 0);712 m_programs[i]->set Int("env", 1);713 m_programs[i]->set Int("noise", 2);714 m_programs[i]->set Matrix("view", view);715 m_programs[i]->set Matrix("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); 716 741 m_box->draw(); 717 m_programs[i]-> unbind();742 m_programs[i]->release(); 718 743 719 744 if (glActiveTexture) { … … 727 752 728 753 if (-1 != excludeBox) { 729 gfx::Matrix4x4fm;730 m _trackBalls[0].rotation().matrix(m);731 glMultMatrixf(m.bits());754 QMatrix4x4 m; 755 m.rotate(m_trackBalls[0].rotation()); 756 multMatrix(m); 732 757 733 758 if (glActiveTexture) { … … 739 764 740 765 m_programs[m_currentShader]->bind(); 741 m_programs[m_currentShader]->set Int("tex", 0);742 m_programs[m_currentShader]->set Int("env", 1);743 m_programs[m_currentShader]->set Int("noise", 2);744 m_programs[m_currentShader]->set Matrix("view", view);745 m_programs[m_currentShader]->set Matrix("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); 746 771 m_box->draw(); 747 m_programs[m_currentShader]-> unbind();772 m_programs[m_currentShader]->release(); 748 773 749 774 if (glActiveTexture) { … … 830 855 const int N = (m_updateAllCubemaps ? 1 : 3); 831 856 832 gfx::Matrix4x4fmat;857 QMatrix4x4 mat; 833 858 GLRenderTargetCube::getProjectionMatrix(mat, 0.1f, 100.0f); 834 859 835 860 glMatrixMode(GL_PROJECTION); 836 861 glPushMatrix(); 837 glLoadMatrixf(mat.bits());862 loadMatrix(mat); 838 863 839 864 glMatrixMode(GL_MODELVIEW); 840 865 glPushMatrix(); 841 866 842 gfx::Vector3fcenter;867 QVector3D center; 843 868 844 869 for (int i = m_frame % N; i < m_cubemaps.size(); i += N) { … … 847 872 848 873 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)); 850 876 851 877 for (int face = 0; face < 6; ++face) { … … 853 879 854 880 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); 857 883 858 884 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); … … 886 912 float height = float(painter->device()->height()); 887 913 914 painter->beginNativePainting(); 888 915 setStates(); 889 916 … … 898 925 glMatrixMode(GL_MODELVIEW); 899 926 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); 906 930 renderBoxes(view); 907 931 908 932 defaultStates(); 909 933 ++m_frame; 934 935 painter->endNativePainting(); 910 936 } 911 937 … … 937 963 938 964 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()); 940 966 event->accept(); 941 967 } else { 942 m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), gfx::Quaternionf::identity());968 m_trackBalls[2].release(pixelPosToViewPos(event->scenePos()), QQuaternion()); 943 969 } 944 970 } … … 961 987 962 988 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()); 964 990 event->accept(); 965 991 } … … 983 1009 984 1010 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()); 986 1012 event->accept(); 987 1013 } … … 1022 1048 { 1023 1049 // set the color in all programs 1024 foreach ( GLProgram *program, m_programs) {1050 foreach (QGLShaderProgram *program, m_programs) { 1025 1051 program->bind(); 1026 program->set Color(name, color);1027 program-> unbind();1052 program->setUniformValue(program->uniformLocation(name), QColor(color)); 1053 program->release(); 1028 1054 } 1029 1055 } … … 1032 1058 { 1033 1059 // set the color in all programs 1034 foreach ( GLProgram *program, m_programs) {1060 foreach (QGLShaderProgram *program, m_programs) { 1035 1061 program->bind(); 1036 program->set Float(name, value);1037 program-> unbind();1062 program->setUniformValue(program->uniformLocation(name), value); 1063 program->release(); 1038 1064 } 1039 1065 } -
trunk/demos/boxes/scene.h
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 51 51 #include "roundedbox.h" 52 52 #include "gltrianglemesh.h" 53 #include "vector.h"54 53 #include "trackball.h" 55 54 #include "glbuffers.h" 56 #include "glshaders.h"57 55 #include "qtbox.h" 58 56 59 57 #define PI 3.14159265358979 58 59 QT_BEGIN_NAMESPACE 60 class QMatrix4x4; 61 QT_END_NAMESPACE 60 62 61 63 class ParameterEdit : public QWidget … … 107 109 class GraphicsWidget : public QGraphicsProxyWidget 108 110 { 111 public: 112 GraphicsWidget() : QGraphicsProxyWidget(0, Qt::Window) {} 109 113 protected: 110 114 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); … … 196 200 void newItem(ItemDialog::ItemType type); 197 201 protected: 198 void renderBoxes(const gfx::Matrix4x4f&view, int excludeBox = -2);202 void renderBoxes(const QMatrix4x4 &view, int excludeBox = -2); 199 203 void setStates(); 200 204 void setLights(); … … 232 236 GLRenderTargetCube *m_mainCubemap; 233 237 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 }; 242 244 243 245 #endif -
trunk/demos/boxes/trackball.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 41 41 42 42 #include "trackball.h" 43 #include "scene.h" 43 44 44 45 //============================================================================// … … 52 53 , m_mode(mode) 53 54 { 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(); 56 57 m_lastTime = QTime::currentTime(); 57 58 } 58 59 59 TrackBall::TrackBall(float angularVelocity, const gfx::Vector3f& axis, TrackMode mode)60 TrackBall::TrackBall(float angularVelocity, const QVector3D& axis, TrackMode mode) 60 61 : m_axis(axis) 61 62 , m_angularVelocity(angularVelocity) … … 64 65 , m_mode(mode) 65 66 { 66 m_rotation = gfx::Quaternionf::quaternion(1.0f, 0.0f, 0.0f, 0.0f);67 m_rotation = QQuaternion(); 67 68 m_lastTime = QTime::currentTime(); 68 69 } 69 70 70 void TrackBall::push(const QPointF& p, const gfx::Quaternionf&)71 void TrackBall::push(const QPointF& p, const QQuaternion &) 71 72 { 72 73 m_rotation = rotation(); … … 77 78 } 78 79 79 void TrackBall::move(const QPointF& p, const gfx::Quaternionf&transformation)80 void TrackBall::move(const QPointF& p, const QQuaternion &transformation) 80 81 { 81 82 if (!m_pressed) … … 91 92 { 92 93 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; 97 98 } 98 99 break; 99 100 case Sphere: 100 101 { 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); 103 104 if (sqrZ > 0) 104 lastPos3D [2] = sqrt(sqrZ);105 lastPos3D.setZ(sqrt(sqrZ)); 105 106 else 106 107 lastPos3D.normalize(); 107 108 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); 110 111 if (sqrZ > 0) 111 currentPos3D [2] = sqrt(sqrZ);112 currentPos3D.setZ(sqrt(sqrZ)); 112 113 else 113 114 currentPos3D.normalize(); 114 115 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))); 117 118 118 119 m_angularVelocity = angle / msecs; 119 120 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; 122 123 } 123 124 break; 124 125 } 126 125 127 126 128 m_lastPos = p; … … 128 130 } 129 131 130 void TrackBall::release(const QPointF& p, const gfx::Quaternionf&transformation)132 void TrackBall::release(const QPointF& p, const QQuaternion &transformation) 131 133 { 132 134 // Calling move() caused the rotation to stop if the framerate was too low. … … 147 149 } 148 150 149 gfx::QuaternionfTrackBall::rotation() const151 QQuaternion TrackBall::rotation() const 150 152 { 151 153 if (m_paused || m_pressed) … … 154 156 QTime currentTime = QTime::currentTime(); 155 157 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; 157 159 } 158 160 -
trunk/demos/boxes/trackball.h
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 45 45 #include <QtGui> 46 46 47 #include "vector.h" 47 #include <QtGui/qvector3d.h> 48 #include <QtGui/qquaternion.h> 48 49 49 50 class TrackBall … … 56 57 }; 57 58 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); 59 60 // 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); 63 64 void start(); // starts clock 64 65 void stop(); // stops clock 65 gfx::Quaternionfrotation() const;66 QQuaternion rotation() const; 66 67 private: 67 gfx::Quaternionfm_rotation;68 gfx::Vector3fm_axis;68 QQuaternion m_rotation; 69 QVector3D m_axis; 69 70 float m_angularVelocity; 70 71 -
trunk/demos/boxes/wood.fsh
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the demonstration applications of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 **
Note:
See TracChangeset
for help on using the changeset viewer.