Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OgreAutoParamDataSource.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 29.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30
31#include "OgreAutoParamDataSource.h"
32#include "OgreRenderable.h"
33#include "OgreCamera.h"
34#include "OgreRenderTarget.h"
35#include "OgreControllerManager.h"
36#include "OgreMath.h"
37#include "OgreRoot.h"
38#include "OgreRenderSystem.h"
39
40namespace Ogre {
41    const Matrix4 PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE(
42        0.5,    0,    0,  0.5, 
43        0,   -0.5,    0,  0.5, 
44        0,      0,    1,    0,
45        0,      0,    0,    1);
46
47    //-----------------------------------------------------------------------------
48    AutoParamDataSource::AutoParamDataSource()
49        : mWorldMatrixDirty(true),
50         mViewMatrixDirty(true),
51         mProjMatrixDirty(true),
52         mWorldViewMatrixDirty(true),
53         mViewProjMatrixDirty(true),
54         mWorldViewProjMatrixDirty(true),
55         mInverseWorldMatrixDirty(true),
56         mInverseWorldViewMatrixDirty(true),
57         mInverseViewMatrixDirty(true),
58         mInverseTransposeWorldMatrixDirty(true),
59         mInverseTransposeWorldViewMatrixDirty(true),
60         mCameraPositionObjectSpaceDirty(true),
61         mCameraPositionDirty(true),
62                 mSceneDepthRangeDirty(true),
63                 mShadowCamDepthRangesDirty(true),
64         mCurrentRenderable(0),
65         mCurrentCamera(0), 
66         mCurrentRenderTarget(0),
67         mCurrentViewport(0), 
68                 mCurrentSceneManager(0),
69                 mMainCamBoundsInfo(0),
70         mCurrentPass(0)
71    {
72        mBlankLight.setDiffuseColour(ColourValue::Black);
73        mBlankLight.setSpecularColour(ColourValue::Black);
74        mBlankLight.setAttenuation(0,1,0,0);
75                for(size_t i = 0; i < OGRE_MAX_SIMULTANEOUS_LIGHTS; ++i)
76                {
77                        mTextureViewProjMatrixDirty[i] = true;
78                        mCurrentTextureProjector[i] = 0;
79                }
80
81    }
82    //-----------------------------------------------------------------------------
83    AutoParamDataSource::~AutoParamDataSource()
84    {
85    }
86    //-----------------------------------------------------------------------------
87    void AutoParamDataSource::setCurrentRenderable(const Renderable* rend)
88    {
89                mCurrentRenderable = rend;
90                mWorldMatrixDirty = true;
91        mViewMatrixDirty = true;
92        mProjMatrixDirty = true;
93                mWorldViewMatrixDirty = true;
94        mViewProjMatrixDirty = true;
95                mWorldViewProjMatrixDirty = true;
96                mInverseWorldMatrixDirty = true;
97        mInverseViewMatrixDirty = true;
98                mInverseWorldViewMatrixDirty = true;
99                mInverseTransposeWorldMatrixDirty = true;
100                mInverseTransposeWorldViewMatrixDirty = true;
101                mCameraPositionObjectSpaceDirty = true;
102    }
103    //-----------------------------------------------------------------------------
104    void AutoParamDataSource::setCurrentCamera(const Camera* cam)
105    {
106        mCurrentCamera = cam;
107        mViewMatrixDirty = true;
108        mProjMatrixDirty = true;
109        mWorldViewMatrixDirty = true;
110        mViewProjMatrixDirty = true;
111        mWorldViewProjMatrixDirty = true;
112        mInverseViewMatrixDirty = true;
113        mInverseWorldViewMatrixDirty = true;
114        mInverseTransposeWorldViewMatrixDirty = true;
115        mCameraPositionObjectSpaceDirty = true;
116        mCameraPositionDirty = true;
117    }
118    //-----------------------------------------------------------------------------
119    void AutoParamDataSource::setCurrentLightList(const LightList* ll)
120    {
121        mCurrentLightList = ll;
122                mShadowCamDepthRangesDirty = true;
123    }
124        //-----------------------------------------------------------------------------
125        void AutoParamDataSource::setMainCamBoundsInfo(VisibleObjectsBoundsInfo* info)
126        {
127                mMainCamBoundsInfo = info;
128                mSceneDepthRangeDirty = true;
129        }
130        //-----------------------------------------------------------------------------
131        void AutoParamDataSource::setCurrentSceneManager(const SceneManager* sm)
132        {
133                mCurrentSceneManager = sm;
134        }
135    //-----------------------------------------------------------------------------
136    void AutoParamDataSource::setWorldMatrices(const Matrix4* m, size_t count)
137    {
138        mWorldMatrixArray = m;
139        mWorldMatrixCount = count;
140        mWorldMatrixDirty = false;
141    }
142    //-----------------------------------------------------------------------------
143    const Matrix4& AutoParamDataSource::getWorldMatrix(void) const
144    {
145        if (mWorldMatrixDirty)
146        {
147            mWorldMatrixArray = mWorldMatrix;
148            mCurrentRenderable->getWorldTransforms(mWorldMatrix);
149            mWorldMatrixCount = mCurrentRenderable->getNumWorldTransforms();
150            mWorldMatrixDirty = false;
151        }
152        return mWorldMatrixArray[0];
153    }
154    //-----------------------------------------------------------------------------
155    size_t AutoParamDataSource::getWorldMatrixCount(void) const
156    {
157        if (mWorldMatrixDirty)
158        {
159            mWorldMatrixArray = mWorldMatrix;
160            mCurrentRenderable->getWorldTransforms(mWorldMatrix);
161            mWorldMatrixCount = mCurrentRenderable->getNumWorldTransforms();
162            mWorldMatrixDirty = false;
163        }
164        return mWorldMatrixCount;
165    }
166    //-----------------------------------------------------------------------------
167    const Matrix4* AutoParamDataSource::getWorldMatrixArray(void) const
168    {
169        if (mWorldMatrixDirty)
170        {
171            mWorldMatrixArray = mWorldMatrix;
172            mCurrentRenderable->getWorldTransforms(mWorldMatrix);
173            mWorldMatrixCount = mCurrentRenderable->getNumWorldTransforms();
174            mWorldMatrixDirty = false;
175        }
176        return mWorldMatrixArray;
177    }
178    //-----------------------------------------------------------------------------
179    const Matrix4& AutoParamDataSource::getViewMatrix(void) const
180    {
181        if (mViewMatrixDirty)
182        {
183            if (mCurrentRenderable && mCurrentRenderable->getUseIdentityView())
184                mViewMatrix = Matrix4::IDENTITY;
185            else
186                mViewMatrix = mCurrentCamera->getViewMatrix(true);
187            mViewMatrixDirty = false;
188        }
189        return mViewMatrix;
190    }
191    //-----------------------------------------------------------------------------
192    const Matrix4& AutoParamDataSource::getViewProjectionMatrix(void) const
193    {
194        if (mViewProjMatrixDirty)
195        {
196            mViewProjMatrix = getProjectionMatrix() * getViewMatrix();
197            mViewProjMatrixDirty = false;
198        }
199        return mViewProjMatrix;
200    }
201    //-----------------------------------------------------------------------------
202    const Matrix4& AutoParamDataSource::getProjectionMatrix(void) const
203    {
204        if (mProjMatrixDirty)
205        {
206            // NB use API-independent projection matrix since GPU programs
207            // bypass the API-specific handedness and use right-handed coords
208            if (mCurrentRenderable && mCurrentRenderable->getUseIdentityProjection())
209            {
210                // Use identity projection matrix, still need to take RS depth into account.
211                RenderSystem* rs = Root::getSingleton().getRenderSystem();
212                rs->_convertProjectionMatrix(Matrix4::IDENTITY, mProjectionMatrix, true);
213            }
214            else
215            {
216                mProjectionMatrix = mCurrentCamera->getProjectionMatrixWithRSDepth();
217            }
218            if (mCurrentRenderTarget && mCurrentRenderTarget->requiresTextureFlipping())
219            {
220                // Because we're not using setProjectionMatrix, this needs to be done here
221                // Invert transformed y
222                mProjectionMatrix[1][0] = -mProjectionMatrix[1][0];
223                mProjectionMatrix[1][1] = -mProjectionMatrix[1][1];
224                mProjectionMatrix[1][2] = -mProjectionMatrix[1][2];
225                mProjectionMatrix[1][3] = -mProjectionMatrix[1][3];
226            }
227            mProjMatrixDirty = false;
228        }
229        return mProjectionMatrix;
230    }
231    //-----------------------------------------------------------------------------
232    const Matrix4& AutoParamDataSource::getWorldViewMatrix(void) const
233    {
234        if (mWorldViewMatrixDirty)
235        {
236            mWorldViewMatrix = getViewMatrix().concatenateAffine(getWorldMatrix());
237            mWorldViewMatrixDirty = false;
238        }
239        return mWorldViewMatrix;
240    }
241    //-----------------------------------------------------------------------------
242    const Matrix4& AutoParamDataSource::getWorldViewProjMatrix(void) const
243    {
244        if (mWorldViewProjMatrixDirty)
245        {
246            mWorldViewProjMatrix = getProjectionMatrix() * getWorldViewMatrix();
247            mWorldViewProjMatrixDirty = false;
248        }
249        return mWorldViewProjMatrix;
250    }
251    //-----------------------------------------------------------------------------
252    const Matrix4& AutoParamDataSource::getInverseWorldMatrix(void) const
253    {
254        if (mInverseWorldMatrixDirty)
255        {
256            mInverseWorldMatrix = getWorldMatrix().inverseAffine();
257            mInverseWorldMatrixDirty = false;
258        }
259        return mInverseWorldMatrix;
260    }
261    //-----------------------------------------------------------------------------
262    const Matrix4& AutoParamDataSource::getInverseWorldViewMatrix(void) const
263    {
264        if (mInverseWorldViewMatrixDirty)
265        {
266            mInverseWorldViewMatrix = getWorldViewMatrix().inverseAffine();
267            mInverseWorldViewMatrixDirty = false;
268        }
269        return mInverseWorldViewMatrix;
270    }
271    //-----------------------------------------------------------------------------
272    const Matrix4& AutoParamDataSource::getInverseViewMatrix(void) const
273    {
274        if (mInverseViewMatrixDirty)
275        {
276            mInverseViewMatrix = getViewMatrix().inverseAffine();
277            mInverseViewMatrixDirty = false;
278        }
279        return mInverseViewMatrix;
280    }
281    //-----------------------------------------------------------------------------
282    const Matrix4& AutoParamDataSource::getInverseTransposeWorldMatrix(void) const
283    {
284        if (mInverseTransposeWorldMatrixDirty)
285        {
286            mInverseTransposeWorldMatrix = getInverseWorldMatrix().transpose();
287            mInverseTransposeWorldMatrixDirty = false;
288        }
289        return mInverseTransposeWorldMatrix;
290    }
291    //-----------------------------------------------------------------------------
292    const Matrix4& AutoParamDataSource::getInverseTransposeWorldViewMatrix(void) const
293    {
294        if (mInverseTransposeWorldViewMatrixDirty)
295        {
296            mInverseTransposeWorldViewMatrix = getInverseWorldViewMatrix().transpose();
297            mInverseTransposeWorldViewMatrixDirty = false;
298        }
299        return mInverseTransposeWorldViewMatrix;
300    }
301    //-----------------------------------------------------------------------------
302    const Vector4& AutoParamDataSource::getCameraPosition(void) const
303    {
304        if(mCameraPositionDirty)
305        {
306            Vector3 vec3 = mCurrentCamera->getDerivedPosition();
307            mCameraPosition[0] = vec3[0];
308            mCameraPosition[1] = vec3[1];
309            mCameraPosition[2] = vec3[2];
310            mCameraPosition[3] = 1.0;
311            mCameraPositionDirty = false;
312        }
313        return mCameraPosition;
314    }   
315    //-----------------------------------------------------------------------------
316    const Vector4& AutoParamDataSource::getCameraPositionObjectSpace(void) const
317    {
318        if (mCameraPositionObjectSpaceDirty)
319        {
320            mCameraPositionObjectSpace = 
321                getInverseWorldMatrix().transformAffine(mCurrentCamera->getDerivedPosition());
322            mCameraPositionObjectSpaceDirty = false;
323        }
324        return mCameraPositionObjectSpace;
325    }
326    //-----------------------------------------------------------------------------
327    const Light& AutoParamDataSource::getLight(size_t index) const
328    {
329        // If outside light range, return a blank light to ensure zeroised for program
330        if (mCurrentLightList->size() <= index)
331        {
332            return mBlankLight;
333        }
334        else
335        {
336            return *((*mCurrentLightList)[index]);
337        }
338    }
339    //-----------------------------------------------------------------------------
340        void AutoParamDataSource::setAmbientLightColour(const ColourValue& ambient)
341        {
342                mAmbientLight = ambient;
343        }
344    //-----------------------------------------------------------------------------
345        const ColourValue& AutoParamDataSource::getAmbientLightColour(void) const
346        {
347                return mAmbientLight;
348               
349        }
350    //-----------------------------------------------------------------------------
351    void AutoParamDataSource::setCurrentPass(const Pass* pass)
352    {
353        mCurrentPass = pass;
354    }
355    //-----------------------------------------------------------------------------
356    const Pass* AutoParamDataSource::getCurrentPass(void) const
357    {
358        return mCurrentPass;
359    }
360    //-----------------------------------------------------------------------------
361    Vector4 AutoParamDataSource::getTextureSize(size_t index) const
362    {
363        Vector4 size = Vector4(1,1,1,1);
364
365        if (index < mCurrentPass->getNumTextureUnitStates())
366        {
367            const TexturePtr& tex = mCurrentPass->getTextureUnitState(
368                                static_cast<unsigned short>(index))->_getTexturePtr();
369            if (!tex.isNull())
370            {
371                size.x = tex->getWidth();
372                size.y = tex->getHeight();
373                size.z = tex->getDepth();
374            }
375        }
376
377        return size;
378    }
379    //-----------------------------------------------------------------------------
380    Vector4 AutoParamDataSource::getInverseTextureSize(size_t index) const
381    {
382        Vector4 size = getTextureSize(index);
383        return 1 / size;
384    }
385    //-----------------------------------------------------------------------------
386    Vector4 AutoParamDataSource::getPackedTextureSize(size_t index) const
387    {
388        Vector4 size = getTextureSize(index);
389        return Vector4(size.x, size.y, 1 / size.x, 1 / size.y);
390    }
391    //-----------------------------------------------------------------------------
392    const ColourValue& AutoParamDataSource::getSurfaceAmbientColour(void) const
393    {
394        return mCurrentPass->getAmbient();
395    }
396    //-----------------------------------------------------------------------------
397    const ColourValue& AutoParamDataSource::getSurfaceDiffuseColour(void) const
398    {
399        return mCurrentPass->getDiffuse();
400    }
401    //-----------------------------------------------------------------------------
402    const ColourValue& AutoParamDataSource::getSurfaceSpecularColour(void) const
403    {
404        return mCurrentPass->getSpecular();
405    }
406    //-----------------------------------------------------------------------------
407    const ColourValue& AutoParamDataSource::getSurfaceEmissiveColour(void) const
408    {
409        return mCurrentPass->getSelfIllumination();
410    }
411    //-----------------------------------------------------------------------------
412    Real AutoParamDataSource::getSurfaceShininess(void) const
413    {
414        return mCurrentPass->getShininess();
415    }
416    //-----------------------------------------------------------------------------
417    ColourValue AutoParamDataSource::getDerivedAmbientLightColour(void) const
418    {
419        return getAmbientLightColour() * getSurfaceAmbientColour();
420    }
421    //-----------------------------------------------------------------------------
422    ColourValue AutoParamDataSource::getDerivedSceneColour(void) const
423    {
424        ColourValue result = getDerivedAmbientLightColour() + getSurfaceEmissiveColour();
425        result.a = getSurfaceDiffuseColour().a;
426        return result;
427    }
428    //-----------------------------------------------------------------------------
429    void AutoParamDataSource::setFog(FogMode mode, const ColourValue& colour,
430        Real expDensity, Real linearStart, Real linearEnd)
431    {
432        (void)mode; // ignored
433        mFogColour = colour;
434        mFogParams.x = expDensity;
435        mFogParams.y = linearStart;
436        mFogParams.z = linearEnd;
437        mFogParams.w = linearEnd != linearStart ? 1 / (linearEnd - linearStart) : 0;
438    }
439    //-----------------------------------------------------------------------------
440    const ColourValue& AutoParamDataSource::getFogColour(void) const
441    {
442        return mFogColour;
443    }
444    //-----------------------------------------------------------------------------
445    const Vector4& AutoParamDataSource::getFogParams(void) const
446    {
447        return mFogParams;
448    }
449    //-----------------------------------------------------------------------------
450    void AutoParamDataSource::setTextureProjector(const Frustum* frust, size_t index = 0)
451    {
452        mCurrentTextureProjector[index] = frust;
453        mTextureViewProjMatrixDirty[index] = true;
454
455    }
456    //-----------------------------------------------------------------------------
457    const Matrix4& AutoParamDataSource::getTextureViewProjMatrix(size_t index) const
458    {
459        if (mTextureViewProjMatrixDirty[index] && mCurrentTextureProjector[index])
460        {
461            mTextureViewProjMatrix[index] = 
462                PROJECTIONCLIPSPACE2DTOIMAGESPACE_PERSPECTIVE * 
463                mCurrentTextureProjector[index]->getProjectionMatrixWithRSDepth() * 
464                                mCurrentTextureProjector[index]->getViewMatrix();
465            mTextureViewProjMatrixDirty[index] = false;
466        }
467        return mTextureViewProjMatrix[index];
468    }
469    //-----------------------------------------------------------------------------
470    void AutoParamDataSource::setCurrentRenderTarget(const RenderTarget* target)
471    {
472        mCurrentRenderTarget = target;
473    }
474    //-----------------------------------------------------------------------------
475    const RenderTarget* AutoParamDataSource::getCurrentRenderTarget(void) const
476    {
477        return mCurrentRenderTarget;
478    }
479    //-----------------------------------------------------------------------------
480    void AutoParamDataSource::setCurrentViewport(const Viewport* viewport)
481    {
482        mCurrentViewport = viewport;
483    }
484    //-----------------------------------------------------------------------------
485        void AutoParamDataSource::setShadowDirLightExtrusionDistance(Real dist)
486        {
487                mDirLightExtrusionDistance = dist;
488        }
489    //-----------------------------------------------------------------------------
490        Real AutoParamDataSource::getShadowExtrusionDistance(void) const
491        {
492                const Light& l = getLight(0); // only ever applies to one light at once
493                if (l.getType() == Light::LT_DIRECTIONAL)
494                {
495                        // use constant
496                        return mDirLightExtrusionDistance;
497                }
498                else
499                {
500                        // Calculate based on object space light distance
501                        // compared to light attenuation range
502                        Vector3 objPos = getInverseWorldMatrix().transformAffine(l.getDerivedPosition());
503                        return l.getAttenuationRange() - objPos.length();
504                }
505        }
506    //-----------------------------------------------------------------------------
507    const Renderable* AutoParamDataSource::getCurrentRenderable(void) const
508    {
509        return mCurrentRenderable;
510    }
511        //-----------------------------------------------------------------------------
512        Matrix4 AutoParamDataSource::getInverseViewProjMatrix(void) const
513        {
514                return this->getViewProjectionMatrix().inverse();
515        }
516        //-----------------------------------------------------------------------------
517        Matrix4 AutoParamDataSource::getInverseTransposeViewProjMatrix(void) const
518        {
519                return this->getInverseViewProjMatrix().transpose();
520        }
521        //-----------------------------------------------------------------------------
522        Matrix4 AutoParamDataSource::getTransposeViewProjMatrix(void) const
523        {
524                return this->getViewProjectionMatrix().transpose();
525        }
526        //-----------------------------------------------------------------------------
527        Matrix4 AutoParamDataSource::getTransposeViewMatrix(void) const
528        {
529                return this->getViewMatrix().transpose();
530        }
531        //-----------------------------------------------------------------------------
532        Matrix4 AutoParamDataSource::getInverseTransposeViewMatrix(void) const
533        {
534                return this->getInverseViewMatrix().transpose();
535        }
536        //-----------------------------------------------------------------------------
537        Matrix4 AutoParamDataSource::getTransposeProjectionMatrix(void) const
538        {
539                return this->getProjectionMatrix().transpose();
540        }
541        //-----------------------------------------------------------------------------
542        Matrix4 AutoParamDataSource::getInverseProjectionMatrix(void) const 
543        {
544                return this->getProjectionMatrix().inverse();
545        }
546        //-----------------------------------------------------------------------------
547        Matrix4 AutoParamDataSource::getInverseTransposeProjectionMatrix(void) const
548        {
549                return this->getInverseProjectionMatrix().transpose();
550        }
551        //-----------------------------------------------------------------------------
552        Matrix4 AutoParamDataSource::getTransposeWorldViewProjMatrix(void) const
553        {
554                return this->getWorldViewProjMatrix().transpose();
555        }
556        //-----------------------------------------------------------------------------
557        Matrix4 AutoParamDataSource::getInverseWorldViewProjMatrix(void) const
558        {
559                return this->getWorldViewProjMatrix().inverse();
560        }
561        //-----------------------------------------------------------------------------
562        Matrix4 AutoParamDataSource::getInverseTransposeWorldViewProjMatrix(void) const
563        {
564                return this->getInverseWorldViewProjMatrix().transpose();
565        }
566        //-----------------------------------------------------------------------------
567        Matrix4 AutoParamDataSource::getTransposeWorldViewMatrix(void) const
568        {
569                return this->getWorldViewMatrix().transpose();
570        }
571        //-----------------------------------------------------------------------------
572        Matrix4 AutoParamDataSource::getTransposeWorldMatrix(void) const
573        {
574                return this->getWorldMatrix().transpose();
575        }
576    //-----------------------------------------------------------------------------
577    Real AutoParamDataSource::getTime(void) const
578    {
579        return ControllerManager::getSingleton().getElapsedTime();
580    }
581        //-----------------------------------------------------------------------------
582        Real AutoParamDataSource::getTime_0_X(Real x) const
583        {
584                return fmod(this->getTime(), x);
585        }
586        //-----------------------------------------------------------------------------
587        Real AutoParamDataSource::getCosTime_0_X(Real x) const
588        { 
589                return cos(this->getTime_0_X(x)); 
590        }
591        //-----------------------------------------------------------------------------
592        Real AutoParamDataSource::getSinTime_0_X(Real x) const
593        { 
594                return sin(this->getTime_0_X(x)); 
595        }
596        //-----------------------------------------------------------------------------
597        Real AutoParamDataSource::getTanTime_0_X(Real x) const
598        { 
599                return tan(this->getTime_0_X(x)); 
600        }
601        //-----------------------------------------------------------------------------
602        Vector4 AutoParamDataSource::getTime_0_X_packed(Real x) const
603        {
604                Real t = this->getTime_0_X(x);
605                return Vector4(t, sin(t), cos(t), tan(t));
606        }
607        //-----------------------------------------------------------------------------
608        Real AutoParamDataSource::getTime_0_1(Real x) const
609        { 
610                return this->getTime_0_X(x)/x; 
611        }
612        //-----------------------------------------------------------------------------
613        Real AutoParamDataSource::getCosTime_0_1(Real x) const
614        { 
615                return cos(this->getTime_0_1(x)); 
616        }
617        //-----------------------------------------------------------------------------
618        Real AutoParamDataSource::getSinTime_0_1(Real x) const
619        { 
620                return sin(this->getTime_0_1(x)); 
621        }
622        //-----------------------------------------------------------------------------
623        Real AutoParamDataSource::getTanTime_0_1(Real x) const
624        { 
625                return tan(this->getTime_0_1(x)); 
626        }
627        //-----------------------------------------------------------------------------
628        Vector4 AutoParamDataSource::getTime_0_1_packed(Real x) const
629        {
630                Real t = this->getTime_0_1(x);
631                return Vector4(t, sin(t), cos(t), tan(t));
632        }
633        //-----------------------------------------------------------------------------
634        Real AutoParamDataSource::getTime_0_2Pi(Real x) const
635        { 
636                return this->getTime_0_X(x)/x*2*Math::PI; 
637        }
638        //-----------------------------------------------------------------------------
639        Real AutoParamDataSource::getCosTime_0_2Pi(Real x) const
640        { 
641                return cos(this->getTime_0_2Pi(x)); 
642        }
643        //-----------------------------------------------------------------------------
644        Real AutoParamDataSource::getSinTime_0_2Pi(Real x) const
645        { 
646                return sin(this->getTime_0_2Pi(x)); 
647        }
648        //-----------------------------------------------------------------------------
649        Real AutoParamDataSource::getTanTime_0_2Pi(Real x) const
650        { 
651                return tan(this->getTime_0_2Pi(x)); 
652        }
653        //-----------------------------------------------------------------------------
654        Vector4 AutoParamDataSource::getTime_0_2Pi_packed(Real x) const
655        {
656                Real t = this->getTime_0_2Pi(x);
657                return Vector4(t, sin(t), cos(t), tan(t));
658        }
659        //-----------------------------------------------------------------------------
660        Real AutoParamDataSource::getFrameTime(void) const
661        {
662                return ControllerManager::getSingleton().getFrameTimeSource()->getValue();
663        }
664        //-----------------------------------------------------------------------------
665        Real AutoParamDataSource::getFPS() const
666        {
667                return mCurrentRenderTarget->getLastFPS();
668        }
669        //-----------------------------------------------------------------------------
670        Real AutoParamDataSource::getViewportWidth() const
671        { 
672                return mCurrentViewport->getActualWidth(); 
673        }
674        //-----------------------------------------------------------------------------
675        Real AutoParamDataSource::getViewportHeight() const
676        { 
677                return mCurrentViewport->getActualHeight(); 
678        }
679        //-----------------------------------------------------------------------------
680        Real AutoParamDataSource::getInverseViewportWidth() const
681        { 
682                return 1.0f/mCurrentViewport->getActualWidth(); 
683        }
684        //-----------------------------------------------------------------------------
685        Real AutoParamDataSource::getInverseViewportHeight() const
686        { 
687                return 1.0f/mCurrentViewport->getActualHeight(); 
688        }
689        //-----------------------------------------------------------------------------
690        Vector3 AutoParamDataSource::getViewDirection() const
691        {
692                return mCurrentCamera->getDerivedDirection();
693        }
694        //-----------------------------------------------------------------------------
695        Vector3 AutoParamDataSource::getViewSideVector() const
696        { 
697                return mCurrentCamera->getDerivedRight();
698        }
699        //-----------------------------------------------------------------------------
700        Vector3 AutoParamDataSource::getViewUpVector() const
701        { 
702                return mCurrentCamera->getDerivedUp();
703        }
704        //-----------------------------------------------------------------------------
705        Real AutoParamDataSource::getFOV() const
706        { 
707                return mCurrentCamera->getFOVy().valueRadians(); 
708        }
709        //-----------------------------------------------------------------------------
710        Real AutoParamDataSource::getNearClipDistance() const
711        { 
712                return mCurrentCamera->getNearClipDistance(); 
713        }
714        //-----------------------------------------------------------------------------
715        Real AutoParamDataSource::getFarClipDistance() const
716        { 
717                return mCurrentCamera->getFarClipDistance(); 
718        }
719        //-----------------------------------------------------------------------------
720    int AutoParamDataSource::getPassNumber(void) const
721    {
722        return mPassNumber;
723    }
724        //-----------------------------------------------------------------------------
725    void AutoParamDataSource::setPassNumber(const int passNumber)
726    {
727        mPassNumber = passNumber;
728    }
729        //-----------------------------------------------------------------------------
730    void AutoParamDataSource::incPassNumber(void)
731    {
732        ++mPassNumber;
733    }
734        //-----------------------------------------------------------------------------
735        const Vector4& AutoParamDataSource::getSceneDepthRange() const
736        {
737                if (mSceneDepthRangeDirty)
738                {
739                        // calculate depth information
740                        mSceneDepthRange.x = mMainCamBoundsInfo->minDistance;
741                        mSceneDepthRange.y = mMainCamBoundsInfo->maxDistance;
742                        mSceneDepthRange.z = mMainCamBoundsInfo->maxDistance - mMainCamBoundsInfo->minDistance;
743                        mSceneDepthRange.w = 1.0f / mSceneDepthRange.z;
744                        mSceneDepthRangeDirty = false;
745                }
746
747                return mSceneDepthRange;
748
749        }
750        //-----------------------------------------------------------------------------
751        const Vector4& AutoParamDataSource::getShadowSceneDepthRange(size_t lightIndex) const
752        {
753                static Vector4 dummy(0, 100000, 100000, 1/100000);
754
755                if (!mCurrentSceneManager->isShadowTechniqueTextureBased())
756                        return dummy;
757
758                if (mShadowCamDepthRangesDirty)
759                {
760                        mShadowCamDepthRanges.clear();
761                        for (LightList::const_iterator i = mCurrentLightList->begin();
762                                i != mCurrentLightList->end(); ++i)
763                        {
764                                // Skip non shadow casting lights
765                                if (!(*i)->getCastShadows())
766                                        continue;
767
768                                const VisibleObjectsBoundsInfo& info = 
769                                        mCurrentSceneManager->getShadowCasterBoundsInfo(*i);
770
771                                mShadowCamDepthRanges.push_back(Vector4(
772                                        info.minDistance, 
773                                        info.maxDistance, 
774                                        info.maxDistance - info.minDistance,
775                                        1.0f / (info.maxDistance - info.minDistance)));
776                        }
777
778                        mShadowCamDepthRangesDirty = false;
779                }
780
781                if (lightIndex >= mShadowCamDepthRanges.size())
782                {
783                        return dummy;
784                }
785                else
786                {
787                        return mShadowCamDepthRanges[lightIndex];
788                }
789
790        }
791
792}
793
Note: See TracBrowser for help on using the repository browser.