qtmobility/examples/sensors/cubehouse/lightmodel.cpp
changeset 4 90517678cc4f
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3D module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    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 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "lightmodel.h"
       
    43 
       
    44 /*!
       
    45     \class LightModel
       
    46     \brief The LightModel class defines the lighting model to use for the scene.
       
    47     \since 4.7
       
    48     \ingroup qt3d
       
    49     \ingroup qt3d::painting
       
    50 */
       
    51 
       
    52 /*!
       
    53     \enum LightModel::Model
       
    54     This enum defines the type of lighting model to use: one-sided or two-sided.
       
    55 
       
    56     \value OneSided One-sided lighting, with the front face material used for both front and back faces.
       
    57     \value TwoSided Two-sided lighting, with separate front and back face materials.
       
    58 */
       
    59 
       
    60 /*!
       
    61     \enum LightModel::ColorControl
       
    62     This enum controls the number of colors to be generated by the lighting computation.
       
    63 
       
    64     \value SingleColor A single color is generated by the lighting computation.
       
    65     \value SeparateSpecularColor A separate specular color computation is
       
    66            performed and then summed into the pixel color after texture mapping.
       
    67 */
       
    68 
       
    69 /*!
       
    70     \enum LightModel::ViewerPosition
       
    71     This enum defines the position of the viewer for the purposes of lighting calculations.
       
    72 
       
    73     \value ViewerAtInfinity The viewer is at infinity along the -z axis.
       
    74     \value LocalViewer The viewer is at the local origin in eye coordinates.
       
    75 */
       
    76 
       
    77 class LightModelPrivate
       
    78 {
       
    79 public:
       
    80     LightModelPrivate()
       
    81         : model(LightModel::OneSided),
       
    82           colorControl(LightModel::SingleColor),
       
    83           viewerPosition(LightModel::ViewerAtInfinity)
       
    84     {
       
    85         ambientSceneColor.setRgbF(0.2, 0.2, 0.2, 1.0);
       
    86     }
       
    87 
       
    88     LightModel::Model model;
       
    89     LightModel::ColorControl colorControl;
       
    90     LightModel::ViewerPosition viewerPosition;
       
    91     QColor ambientSceneColor;
       
    92 };
       
    93 
       
    94 /*!
       
    95     Constructs a light model object with default values and attach
       
    96     it to \a parent.
       
    97 */
       
    98 LightModel::LightModel(QObject *parent)
       
    99     : QObject(parent), d_ptr(new LightModelPrivate)
       
   100 {
       
   101 }
       
   102 
       
   103 /*!
       
   104     Destroys this light model.
       
   105 */
       
   106 LightModel::~LightModel()
       
   107 {
       
   108 }
       
   109 
       
   110 /*!
       
   111     \property LightModel::model
       
   112     \brief the lighting model to use, either OneSided or TwoSided.
       
   113     The default is OneSided.
       
   114 
       
   115     \sa modelChanged()
       
   116 */
       
   117 LightModel::Model LightModel::model() const
       
   118 {
       
   119     Q_D(const LightModel);
       
   120     return d->model;
       
   121 }
       
   122 
       
   123 void LightModel::setModel(LightModel::Model value)
       
   124 {
       
   125     Q_D(LightModel);
       
   126     if (d->model != value) {
       
   127         d->model = value;
       
   128         emit modelChanged();
       
   129         emit lightModelChanged();
       
   130     }
       
   131 }
       
   132 
       
   133 /*!
       
   134     \property LightModel::colorControl
       
   135     \brief the color control mode, either SingleColor or
       
   136     SeparateSpecularColor.  The default value is SingleColor.
       
   137 
       
   138     If SingleColor is specified, then a single color is calculated
       
   139     by the lighting computation for a vertex.  If SeparateSpecularColor
       
   140     is specified, then a separate specular color computation is
       
   141     performed and then summed into the pixel color after texture mapping.
       
   142 
       
   143     \sa colorControlChanged()
       
   144 */
       
   145 LightModel::ColorControl LightModel::colorControl() const
       
   146 {
       
   147     Q_D(const LightModel);
       
   148     return d->colorControl;
       
   149 }
       
   150 
       
   151 void LightModel::setColorControl(LightModel::ColorControl value)
       
   152 {
       
   153     Q_D(LightModel);
       
   154     if (d->colorControl != value) {
       
   155         d->colorControl = value;
       
   156         emit colorControlChanged();
       
   157         emit lightModelChanged();
       
   158     }
       
   159 }
       
   160 
       
   161 /*!
       
   162     \property LightModel::viewerPosition
       
   163     \brief the viewer position, either ViewerAtInfinity or LocalViewer.
       
   164     The default value is ViewerAtInfinity.
       
   165 
       
   166     \sa viewerPositionChanged()
       
   167 */
       
   168 LightModel::ViewerPosition LightModel::viewerPosition() const
       
   169 {
       
   170     Q_D(const LightModel);
       
   171     return d->viewerPosition;
       
   172 }
       
   173 
       
   174 void LightModel::setViewerPosition(LightModel::ViewerPosition value)
       
   175 {
       
   176     Q_D(LightModel);
       
   177     if (d->viewerPosition != value) {
       
   178         d->viewerPosition = value;
       
   179         emit viewerPositionChanged();
       
   180         emit lightModelChanged();
       
   181     }
       
   182 }
       
   183 
       
   184 /*!
       
   185     \property LightModel::ambientSceneColor
       
   186     \brief the ambient color of the entire scene.  The default value
       
   187     is (0.2, 0.2, 0.2, 1.0).
       
   188 
       
   189     \sa ambientSceneColorChanged()
       
   190 */
       
   191 QColor LightModel::ambientSceneColor() const
       
   192 {
       
   193     Q_D(const LightModel);
       
   194     return d->ambientSceneColor;
       
   195 }
       
   196 
       
   197 void LightModel::setAmbientSceneColor(const QColor& value)
       
   198 {
       
   199     Q_D(LightModel);
       
   200     if (d->ambientSceneColor != value) {
       
   201         d->ambientSceneColor = value;
       
   202         emit ambientSceneColorChanged();
       
   203         emit lightModelChanged();
       
   204     }
       
   205 }
       
   206 
       
   207 /*!
       
   208     \fn void LightModel::modelChanged()
       
   209 
       
   210     This signal is emitted when model() changes.
       
   211 
       
   212     \sa model(), lightModelChanged()
       
   213 */
       
   214 
       
   215 /*!
       
   216     \fn void LightModel::colorControlChanged()
       
   217 
       
   218     This signal is emitted when colorControl() changes.
       
   219 
       
   220     \sa colorControl(), lightModelChanged()
       
   221 */
       
   222 
       
   223 /*!
       
   224     \fn void LightModel::viewerPositionChanged()
       
   225 
       
   226     This signal is emitted when viewerPosition() changes.
       
   227 
       
   228     \sa viewerPosition(), lightModelChanged()
       
   229 */
       
   230 
       
   231 /*!
       
   232     \fn void LightModel::ambientSceneColorChanged()
       
   233 
       
   234     This signal is emitted when ambientSceneColor() changes.
       
   235 
       
   236     \sa ambientSceneColor(), lightModelChanged()
       
   237 */
       
   238 
       
   239 /*!
       
   240     \fn void LightModel::lightModelChanged()
       
   241 
       
   242     This signal is emitted when one of model(), colorControl(),
       
   243     viewerPosition(), or ambientSceneColor() changes.
       
   244 */