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 00031 namespace Ogre { 00032 00033 //----------------------------------------------------------------------------- 00034 AutoParamDataSource::AutoParamDataSource() 00035 : mWorldMatrixDirty(true), 00036 mWorldViewMatrixDirty(true), 00037 mWorldViewProjMatrixDirty(true), 00038 mInverseWorldMatrixDirty(true), 00039 mInverseWorldViewMatrixDirty(true), 00040 mInverseViewMatrixDirty(true), 00041 mCameraPositionObjectSpaceDirty(true), 00042 mCurrentRenderable(NULL), 00043 mCurrentCamera(NULL) 00044 { 00045 mBlankLight.setDiffuseColour(ColourValue::Black); 00046 mBlankLight.setSpecularColour(ColourValue::Black); 00047 mBlankLight.setAttenuation(0,0,0,0); 00048 } 00049 //----------------------------------------------------------------------------- 00050 AutoParamDataSource::~AutoParamDataSource() 00051 { 00052 } 00053 //----------------------------------------------------------------------------- 00054 void AutoParamDataSource::setCurrentRenderable(const Renderable* rend) 00055 { 00056 mCurrentRenderable = rend; 00057 mWorldMatrixDirty = true; 00058 mWorldViewMatrixDirty = true; 00059 mWorldViewProjMatrixDirty = true; 00060 mInverseWorldMatrixDirty = true; 00061 mInverseWorldViewMatrixDirty = true; 00062 mCameraPositionObjectSpaceDirty = true; 00063 } 00064 //----------------------------------------------------------------------------- 00065 void AutoParamDataSource::setCurrentCamera(const Camera* cam) 00066 { 00067 mCurrentCamera = cam; 00068 mWorldViewMatrixDirty = true; 00069 mWorldViewProjMatrixDirty = true; 00070 mInverseViewMatrixDirty = true; 00071 mInverseWorldViewMatrixDirty = true; 00072 mCameraPositionObjectSpaceDirty = true; 00073 } 00074 //----------------------------------------------------------------------------- 00075 void AutoParamDataSource::setCurrentLightList(const LightList* ll) 00076 { 00077 mCurrentLightList = ll; 00078 } 00079 //----------------------------------------------------------------------------- 00080 const Matrix4& AutoParamDataSource::getWorldMatrix(void) const 00081 { 00082 if (mWorldMatrixDirty) 00083 { 00084 mCurrentRenderable->getWorldTransforms(mWorldMatrix); 00085 mWorldMatrixDirty = false; 00086 } 00087 return mWorldMatrix[0]; 00088 } 00089 //----------------------------------------------------------------------------- 00090 const Matrix4& AutoParamDataSource::getViewMatrix(void) const 00091 { 00092 return mCurrentCamera->getViewMatrix(); 00093 } 00094 //----------------------------------------------------------------------------- 00095 const Matrix4& AutoParamDataSource::getProjectionMatrix(void) const 00096 { 00097 // NB use API-independent projection matrix since GPU programs 00098 // bypass the API-specific handedness and use right-handed coords 00099 return mCurrentCamera->getStandardProjectionMatrix(); 00100 } 00101 //----------------------------------------------------------------------------- 00102 const Matrix4& AutoParamDataSource::getWorldViewMatrix(void) const 00103 { 00104 if (mWorldViewMatrixDirty) 00105 { 00106 mWorldViewMatrix = getViewMatrix() * getWorldMatrix(); 00107 mWorldViewMatrixDirty = false; 00108 } 00109 return mWorldViewMatrix; 00110 } 00111 //----------------------------------------------------------------------------- 00112 const Matrix4& AutoParamDataSource::getWorldViewProjMatrix(void) const 00113 { 00114 if (mWorldViewProjMatrixDirty) 00115 { 00116 mWorldViewProjMatrix = getProjectionMatrix() * getWorldViewMatrix(); 00117 mWorldViewProjMatrixDirty = false; 00118 } 00119 return mWorldViewProjMatrix; 00120 } 00121 //----------------------------------------------------------------------------- 00122 const Matrix4& AutoParamDataSource::getInverseWorldMatrix(void) const 00123 { 00124 if (mInverseWorldMatrixDirty) 00125 { 00126 mInverseWorldMatrix = getWorldMatrix().inverse(); 00127 mInverseWorldMatrixDirty = false; 00128 } 00129 return mInverseWorldMatrix; 00130 } 00131 //----------------------------------------------------------------------------- 00132 const Matrix4& AutoParamDataSource::getInverseWorldViewMatrix(void) const 00133 { 00134 if (mInverseWorldViewMatrixDirty) 00135 { 00136 mInverseWorldViewMatrix = getWorldViewMatrix().inverse(); 00137 mInverseWorldViewMatrixDirty = false; 00138 } 00139 return mInverseWorldViewMatrix; 00140 } 00141 //----------------------------------------------------------------------------- 00142 const Matrix4& AutoParamDataSource::getInverseViewMatrix(void) const 00143 { 00144 if (mInverseViewMatrixDirty) 00145 { 00146 mInverseViewMatrix = getViewMatrix().inverse(); 00147 mInverseViewMatrixDirty = false; 00148 } 00149 return mInverseViewMatrix; 00150 } 00151 //----------------------------------------------------------------------------- 00152 const Vector4& AutoParamDataSource::getCameraPositionObjectSpace(void) const 00153 { 00154 if (mCameraPositionObjectSpaceDirty) 00155 { 00156 mCameraPositionObjectSpace = 00157 getInverseWorldMatrix() * mCurrentCamera->getDerivedPosition(); 00158 mCameraPositionObjectSpaceDirty = false; 00159 } 00160 return mCameraPositionObjectSpace; 00161 } 00162 //----------------------------------------------------------------------------- 00163 const Light& AutoParamDataSource::getLight(size_t index) const 00164 { 00165 // If outside light range, return a blank light to ensure zeroised for program 00166 if (mCurrentLightList->size() <= index) 00167 { 00168 return mBlankLight; 00169 } 00170 else 00171 { 00172 return *((*mCurrentLightList)[index]); 00173 } 00174 } 00175 //----------------------------------------------------------------------------- 00176 void AutoParamDataSource::setAmbientLightColour(const ColourValue& ambient) 00177 { 00178 mAmbientLight = ambient; 00179 } 00180 //----------------------------------------------------------------------------- 00181 const ColourValue& AutoParamDataSource::getAmbientLightColour(void) const 00182 { 00183 return mAmbientLight; 00184 00185 } 00186 } 00187
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:02 2004