source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreFocusingMapRenderingRun.cpp @ 1103

Revision 1103, 3.1 KB checked in by szirmay, 18 years ago (diff)
Line 
1#include "OgreFocusingMapRenderingRun.h"
2
3
4void OgreFocusingMapRenderingRun::getMinMax(Vector3& min, Vector3& max)
5{       
6        unsigned int buffersize = focusingMapSize * focusingMapSize * 4;
7        float* floatbuffer = new float[buffersize];
8        PixelBox lockBox(focusingMapSize, focusingMapSize, 1, PF_FLOAT32_RGBA, floatbuffer);
9        focusingTexture->getBuffer()->blitToMemory(lockBox);
10       
11    float minX = 0;
12        float minY = 0;
13        float minZ = 0;
14        float maxX = 0;
15        float maxY = 0;
16        float maxZ = 0;
17
18        bool first = true;
19       
20        for(int i = 0; i < buffersize; i+= 4)
21        {
22                float x = floatbuffer[i];
23                float y = floatbuffer[i + 1];
24                float z = floatbuffer[i + 2];
25                float valid = floatbuffer[i + 3];
26
27                if(valid)
28                {
29                        if(first)
30                        {
31                                minX = x;
32                                minY = y;
33                                minZ = z;
34                                maxX = x;
35                                maxY = y;
36                                maxZ = z;
37
38                                first = false;
39                        }
40                        else
41                        {
42                                if(x < minX)minX = x;
43                                if(y < minY)minY = y;
44                                if(z < minZ)minZ = z;
45
46                                if(x > maxX)maxX = x;
47                                if(y > maxY)maxY = y;
48                                if(z > maxZ)maxZ = z;
49                        }
50                }
51        }
52
53        min.x = minX; min.y = minY; min.z = minZ;
54        max.x = maxX; max.y = maxY; max.z = maxZ;
55
56        delete[] floatbuffer;
57}
58
59OgreFocusingMapRenderingRun::OgreFocusingMapRenderingRun(       String name,
60                                                                                                                        Viewport* playerView,
61                                                                                                                        Matrix4 lightMatrix,
62                                                                                                                        unsigned int focusingMapSize
63                                                                                                                   )
64                                                                                                                   : OgreRenderingRun(1, 1)
65                                                                                                                   , RenderingRun(1, 1)
66{
67        this->name = name;
68        this->playerView = playerView;
69        this->lightMatrix = lightMatrix;
70        this->focusingMapSize = focusingMapSize;
71       
72        createFocusingMap();
73       
74       
75}
76
77
78
79void OgreFocusingMapRenderingRun::createFocusingMap()
80{
81        int width = focusingMapSize;
82        int height = focusingMapSize;
83        TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,
84                                                                                                                                                "default",
85                                                                                                                                                TEX_TYPE_2D,
86                                                                                                                                                width,
87                                                                                                                                                height,
88                                                                                                                                                0,
89                                                                                                                                                0,
90                                                                                                                                                PF_FLOAT32_RGBA,
91                                                                                                                                                TU_RENDERTARGET);
92        focusingTexture = texPtr.getPointer();
93         playerCamera = playerView->getCamera();
94         //add viewport to rendertarget
95         HardwarePixelBuffer* hpb = (focusingTexture->getBuffer()).getPointer();
96         RenderTarget* rt = hpb->getRenderTarget();
97         Viewport* v = rt->addViewport(playerCamera);
98         v->setOverlaysEnabled(false);
99         rt->setAutoUpdated(false);
100}
101
102
103
104void OgreFocusingMapRenderingRun::updateFrame(unsigned long frameNum)
105{
106       
107       
108        MaterialPtr mat = MaterialManager::getSingleton().getByName("GameTools/FocusingShader");
109        GpuProgramParameters* Vparams = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters().getPointer();
110        Vparams->setNamedConstant("lightTransform", lightMatrix);
111               
112        setMaterialForVisibles(String("GameTools/FocusingShader"), playerCamera);
113
114        RenderTarget* rt = focusingTexture->getBuffer().getPointer()->getRenderTarget();
115
116        ColourValue backColor(0,0,0,0);
117        rt->getViewport(0)->setBackgroundColour(backColor);
118               
119        rt->update();   
120
121        //rt->writeContentsToFile("focusingmap.dds");
122       
123        restoreMaterials();     
124}
125
126
Note: See TracBrowser for help on using the repository browser.