Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreAutoParamDataSource.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://ogre.sourceforge.net/
    00006
    00007 Copyright © 2000-2003 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreStableHeaders.h"
    00026
    00027 #include "OgreAutoParamDataSource.h"
    00028 #include "OgreRenderable.h"
    00029 #include "OgreCamera.h"
    00030 #include "OgreRenderTarget.h"
    00031
    00032 namespace Ogre {
    00033     const Matrix4 PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE(
    00034         0.5,    0,  0, -0.5,
    00035         0, -0.5,  0, -0.5,
    00036         0,    0,  0,   1,
    00037         0,    0,  0,   1);
    00038
    00039     //-----------------------------------------------------------------------------
    00040     AutoParamDataSource::AutoParamDataSource()
    00041         : mWorldMatrixDirty(true),
    00042          mWorldViewMatrixDirty(true),
    00043          mViewProjMatrixDirty(true),
    00044          mWorldViewProjMatrixDirty(true),
    00045          mInverseWorldMatrixDirty(true),
    00046          mInverseWorldViewMatrixDirty(true),
    00047          mInverseViewMatrixDirty(true),
    00048          mCameraPositionObjectSpaceDirty(true),
    00049          mTextureViewProjMatrixDirty(true),
    00050          mCurrentRenderable(NULL),
    00051          mCurrentCamera(NULL),
    00052          mCurrentTextureProjector(NULL),
    00053          mCurrentRenderTarget(NULL)
    00054     {
    00055         mBlankLight.setDiffuseColour(ColourValue::Black);
    00056         mBlankLight.setSpecularColour(ColourValue::Black);
    00057         mBlankLight.setAttenuation(0,0,0,0);
    00058     }
    00059     //-----------------------------------------------------------------------------
    00060     AutoParamDataSource::~AutoParamDataSource()
    00061     {
    00062     }
    00063     //-----------------------------------------------------------------------------
    00064     void AutoParamDataSource::setCurrentRenderable(const Renderable* rend)
    00065     {
    00066         mCurrentRenderable = rend;
    00067         mWorldMatrixDirty = true;
    00068         mWorldViewMatrixDirty = true;
    00069         mViewProjMatrixDirty = true;
    00070         mWorldViewProjMatrixDirty = true;
    00071         mInverseWorldMatrixDirty = true;
    00072         mInverseWorldViewMatrixDirty = true;
    00073         mCameraPositionObjectSpaceDirty = true;
    00074     }
    00075     //-----------------------------------------------------------------------------
    00076     void AutoParamDataSource::setCurrentCamera(const Camera* cam)
    00077     {
    00078         mCurrentCamera = cam;
    00079         mWorldViewMatrixDirty = true;
    00080         mViewProjMatrixDirty = true;
    00081         mWorldViewProjMatrixDirty = true;
    00082         mInverseViewMatrixDirty = true;
    00083         mInverseWorldViewMatrixDirty = true;
    00084         mCameraPositionObjectSpaceDirty = true;
    00085     }
    00086     //-----------------------------------------------------------------------------
    00087     void AutoParamDataSource::setCurrentLightList(const LightList* ll)
    00088     {
    00089         mCurrentLightList = ll;
    00090     }
    00091     //-----------------------------------------------------------------------------
    00092     const Matrix4& AutoParamDataSource::getWorldMatrix(void) const
    00093     {
    00094         if (mWorldMatrixDirty)
    00095         {
    00096             mCurrentRenderable->getWorldTransforms(mWorldMatrix);
    00097             mWorldMatrixCount = mCurrentRenderable->getNumWorldTransforms();
    00098             mWorldMatrixDirty = false;
    00099         }
    00100         return mWorldMatrix[0];
    00101     }
    00102     //-----------------------------------------------------------------------------
    00103     size_t AutoParamDataSource::getWorldMatrixCount(void) const
    00104     {
    00105         if (mWorldMatrixDirty)
    00106         {
    00107             mCurrentRenderable->getWorldTransforms(mWorldMatrix);
    00108             mWorldMatrixCount = mCurrentRenderable->getNumWorldTransforms();
    00109             mWorldMatrixDirty = false;
    00110         }
    00111         return mWorldMatrixCount;
    00112     }
    00113     //-----------------------------------------------------------------------------
    00114     const Matrix4* AutoParamDataSource::getWorldMatrixArray(void) const
    00115     {
    00116         if (mWorldMatrixDirty)
    00117         {
    00118             mCurrentRenderable->getWorldTransforms(mWorldMatrix);
    00119             mWorldMatrixCount = mCurrentRenderable->getNumWorldTransforms();
    00120             mWorldMatrixDirty = false;
    00121         }
    00122         return mWorldMatrix;
    00123     }
    00124     //-----------------------------------------------------------------------------
    00125     const Matrix4& AutoParamDataSource::getViewMatrix(void) const
    00126     {
    00127         return mCurrentCamera->getViewMatrix();
    00128     }
    00129     //-----------------------------------------------------------------------------
    00130     const Matrix4& AutoParamDataSource::getViewProjectionMatrix(void) const
    00131     {
    00132         if (mViewProjMatrixDirty)
    00133         {
    00134             mViewProjMatrix = getProjectionMatrix() * getViewMatrix();
    00135             mViewProjMatrixDirty = false;
    00136         }
    00137         return mViewProjMatrix;
    00138     }
    00139     //-----------------------------------------------------------------------------
    00140     const Matrix4& AutoParamDataSource::getProjectionMatrix(void) const
    00141     {
    00142         // NB use API-independent projection matrix since GPU programs
    00143         // bypass the API-specific handedness and use right-handed coords
    00144         mProjectionMatrix = mCurrentCamera->getStandardProjectionMatrix();
    00145         if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
    00146         {
    00147             // Because we're not using setProjectionMatrix, this needs to be done here
    00148             mProjectionMatrix[1][1] = -mProjectionMatrix[1][1];
    00149         }
    00150         return mProjectionMatrix;
    00151     }
    00152     //-----------------------------------------------------------------------------
    00153     const Matrix4& AutoParamDataSource::getWorldViewMatrix(void) const
    00154     {
    00155         if (mWorldViewMatrixDirty)
    00156         {
    00157             mWorldViewMatrix = getViewMatrix() * getWorldMatrix();
    00158             mWorldViewMatrixDirty = false;
    00159         }
    00160         return mWorldViewMatrix;
    00161     }
    00162     //-----------------------------------------------------------------------------
    00163     const Matrix4& AutoParamDataSource::getWorldViewProjMatrix(void) const
    00164     {
    00165         if (mWorldViewProjMatrixDirty)
    00166         {
    00167             mWorldViewProjMatrix = getProjectionMatrix() * getWorldViewMatrix();
    00168             mWorldViewProjMatrixDirty = false;
    00169         }
    00170         return mWorldViewProjMatrix;
    00171     }
    00172     //-----------------------------------------------------------------------------
    00173     const Matrix4& AutoParamDataSource::getInverseWorldMatrix(void) const
    00174     {
    00175         if (mInverseWorldMatrixDirty)
    00176         {
    00177             mInverseWorldMatrix = getWorldMatrix().inverse();
    00178             mInverseWorldMatrixDirty = false;
    00179         }
    00180         return mInverseWorldMatrix;
    00181     }
    00182     //-----------------------------------------------------------------------------
    00183     const Matrix4& AutoParamDataSource::getInverseWorldViewMatrix(void) const
    00184     {
    00185         if (mInverseWorldViewMatrixDirty)
    00186         {
    00187             mInverseWorldViewMatrix = getWorldViewMatrix().inverse();
    00188             mInverseWorldViewMatrixDirty = false;
    00189         }
    00190         return mInverseWorldViewMatrix;
    00191     }
    00192     //-----------------------------------------------------------------------------
    00193     const Matrix4& AutoParamDataSource::getInverseViewMatrix(void) const
    00194     {
    00195         if (mInverseViewMatrixDirty)
    00196         {
    00197             mInverseViewMatrix = getViewMatrix().inverse();
    00198             mInverseViewMatrixDirty = false;
    00199         }
    00200         return mInverseViewMatrix;
    00201     }
    00202     //-----------------------------------------------------------------------------
    00203     const Vector4& AutoParamDataSource::getCameraPositionObjectSpace(void) const
    00204     {
    00205         if (mCameraPositionObjectSpaceDirty)
    00206         {
    00207             mCameraPositionObjectSpace =
    00208                 getInverseWorldMatrix() * mCurrentCamera->getDerivedPosition();
    00209             mCameraPositionObjectSpaceDirty = false;
    00210         }
    00211         return mCameraPositionObjectSpace;
    00212     }
    00213     //-----------------------------------------------------------------------------
    00214     const Light& AutoParamDataSource::getLight(size_t index) const
    00215     {
    00216         // If outside light range, return a blank light to ensure zeroised for program
    00217         if (mCurrentLightList->size() <= index)
    00218         {
    00219             return mBlankLight;
    00220         }
    00221         else
    00222         {
    00223             return *((*mCurrentLightList)[index]);
    00224         }
    00225     }
    00226     //-----------------------------------------------------------------------------
    00227     void AutoParamDataSource::setAmbientLightColour(const ColourValue& ambient)
    00228     {
    00229         mAmbientLight = ambient;
    00230     }
    00231     //-----------------------------------------------------------------------------
    00232     const ColourValue& AutoParamDataSource::getAmbientLightColour(void) const
    00233     {
    00234         return mAmbientLight;
    00235
    00236     }
    00237     //-----------------------------------------------------------------------------
    00238     void AutoParamDataSource::setTextureProjector(const Frustum* frust)
    00239     {
    00240         mCurrentTextureProjector = frust;
    00241         mTextureViewProjMatrixDirty = true;
    00242
    00243     }
    00244     //-----------------------------------------------------------------------------
    00245     const Matrix4& AutoParamDataSource::getTextureViewProjMatrix(void) const
    00246     {
    00247         if (mTextureViewProjMatrixDirty)
    00248         {
    00249             mTextureViewProjMatrix =
    00250                 PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE *
    00251                 mCurrentTextureProjector->getViewMatrix() *
    00252                 mCurrentTextureProjector->getStandardProjectionMatrix();
    00253             mTextureViewProjMatrixDirty = false;
    00254         }
    00255         return mTextureViewProjMatrix;
    00256     }
    00257     //-----------------------------------------------------------------------------
    00258     void AutoParamDataSource::setCurrentRenderTarget(const RenderTarget* target)
    00259     {
    00260         mCurrentRenderTarget = target;
    00261     }
    00262     //-----------------------------------------------------------------------------
    00263     const RenderTarget* AutoParamDataSource::getCurrentRenderTarget(void) const
    00264     {
    00265         return mCurrentRenderTarget;
    00266     }
    00267     //-----------------------------------------------------------------------------
    00268     void AutoParamDataSource::setShadowDirLightExtrusionDistance(Real dist)
    00269     {
    00270         mDirLightExtrusionDistance = dist;
    00271     }
    00272     //-----------------------------------------------------------------------------
    00273     Real AutoParamDataSource::getShadowExtrusionDistance(void) const
    00274     {
    00275         const Light& l = getLight(0); // only ever applies to one light at once
    00276         if (l.getType() == Light::LT_DIRECTIONAL)
    00277         {
    00278             // use constant
    00279             return mDirLightExtrusionDistance;
    00280         }
    00281         else
    00282         {
    00283             // Calculate based on object space light distance
    00284             // compared to light attenuation range
    00285             Vector3 objPos = getInverseWorldMatrix() *
    00286                 l.getDerivedPosition();
    00287             return l.getAttenuationRange() - objPos.length();
    00288         }
    00289     }
    00290     //-----------------------------------------------------------------------------
    00291     const Renderable* AutoParamDataSource::getCurrentRenderable(void) const
    00292     {
    00293         return mCurrentRenderable;
    00294     }
    00295 }
    00296

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:14 2004