summaryrefslogtreecommitdiffstats
path: root/doc/src/tutorials/simpleobject.qdoc
blob: 28e967150d4e6ff7cb0dce1d0d570d1d571a8cfd (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) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the Qt3D documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** 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.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms
** and conditions contained in a signed written agreement between you
** and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \title Applying Transformations and Materials
    \keyword Object Effects
    \example qt3d/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 QML

    It is quite simple to achieve these effects in Qt3D:

    \snippet quick3d/cube/qml/cube.qml 1

    \section2 Cube in C++

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

    \snippet qt3d/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 qt3d/cube1/cubeview.cpp 1

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

    \snippet qt3d/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 qt3d/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 qt3d/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 qt3d/cube4/cubeview.h 1
    \dots
    \snippet qt3d/cube4/cubeview.h 2
    \snippet qt3d/cube4/cubeview.cpp 1
    \dots
    \snippet qt3d/cube4/cubeview.cpp 2
    \snippet qt3d/cube4/cubeview.cpp 3

    \image tutorials/cube4-screenshot.png

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