summaryrefslogtreecommitdiffstats
path: root/doc/src/tutorials/simpleobject.qdoc
blob: 42e6b06ce39b5abc7c2a4c32f24a55ee6be0fe42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtQuick3D documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of this
** file.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \title Applying Transformations and Materials
    \keyword Object Effects
    \example tutorials/cube4

    In this tutorial we will apply transformations and materials to a
    simple cube object to demonstrate how to modify the QGLPainter
    state to achieve different effects.

    \section2 Cube in QtQuick3D

    It is quite simple to achieve these effects in QtQuick3D:

    \snippet tutorials/cube4/cube.qml 1

    \section2 Cube in Qt3D

    In the C++ world we start by declaring a view class to show our cube
    on the screen:

    \snippet tutorials/cube1/cubeview.h 1

    QGLView provides most of the logic for initializing the view,
    setting the camera position, and handling navigation via
    keyboard and mouse events.  In the constructor we use
    QGLBuilder to create the geometry for the cube object that
    we will be using in later steps:

    \snippet tutorials/cube1/cubeview.cpp 1

    Then it is a simple matter to draw the object in our \c{paintGL()}
    method:

    \snippet tutorials/cube1/cubeview.cpp 2

    If we run the program now, we get the following output, which isn't
    very cube-like:

    \image tutorials/cube1-screenshot.png

    The problem is that we are looking at the cube straight onto its
    front face.  So the rest of the cube is hidden from our view and
    it looks like a square.  Let's modify the modelview transformation
    matrix a little bit to apply a 45 degree rotation around the
    axis (1, 1, 1):

    \snippet tutorials/cube2/cubeview.cpp 2

    Now the results are a little better:

    \image tutorials/cube2-screenshot.png

    The cube is still a little odd-looking however.  This is because
    up until now we have been using the default flat color effect
    in QGLPainter that colors the faces with a uniform color
    (white in this case).  So let's change to a lit material effect
    with a nice green color:

    \snippet tutorials/cube3/cubeview.cpp 2

    That's much better; now it looks like a cube:

    \image tutorials/cube3-screenshot.png

    To complete this tutorial, let's make the cube a little more
    interesting by adding a texture to the side:

    \snippet tutorials/cube4/cubeview.h 1
    \dots
    \snippet tutorials/cube4/cubeview.h 2
    \snippet tutorials/cube4/cubeview.cpp 1
    \dots
    \snippet tutorials/cube4/cubeview.cpp 2
    \snippet tutorials/cube4/cubeview.cpp 3

    \image tutorials/cube4-screenshot.png

    \l{qt3d-examples.html}{Return to the main Tutorials page}.
*/