source: GTP/trunk/Lib/Illum/IllumModule/OgreIllumModule/src/RenderingRuns/OgreChildParticlesystemRenderingRun.cpp @ 1055

Revision 1055, 4.0 KB checked in by szirmay, 18 years ago (diff)
Line 
1#include "OgreChildPSystemRenderingRun.h"
2#include "OgreIlluminationManager.h"
3#include "OgreDistanceCubeMapRenderingRun.h"
4
5
6
7OgreChildPSystemRenderingRun::OgreChildPSystemRenderingRun(OgreSharedRuns* sharedRuns,
8                                                                                                                        String name,
9                                                                                                                        unsigned long startFrame,
10                                                                                                                        unsigned long updateInterval,
11                                                                                                                        unsigned int resolution,
12                                                                                                                        bool perspectiveRendering,
13                                                                                                                        String childParticleSystemName,
14                                                                                                                        String particleScriptName,
15                                                                                                                        bool useOwnMaterial,
16                                                                                                                        String materialName)
17                                                                                                                   :ChildPsystemRenderingRun(resolution, perspectiveRendering, startFrame, updateInterval)
18                                                                                                                   , OgreRenderingRun(startFrame, updateInterval)
19                                                                                                                   , RenderingRun(startFrame, updateInterval)
20{
21        this->sharedRuns = sharedRuns;
22        this->name = name;     
23        this->resolution = resolution;
24        this->materialName = materialName;
25        this->particleScriptName = particleScriptName;
26        this->perspectiveRendering = perspectiveRendering;
27        this->childParticleSystemName = childParticleSystemName;
28        this->useOwnMaterial = useOwnMaterial;
29        createImpostorTexture();       
30}
31
32void OgreChildPSystemRenderingRun::createImpostorTexture()
33{
34        TexturePtr texPtr = Ogre::TextureManager::getSingleton().createManual(name,
35                                                                                                                                                "default",
36                                                                                                                                                TEX_TYPE_2D,
37                                                                                                                                                resolution,
38                                                                                                                                                resolution,
39                                                                                                                                                0,
40                                                                                                                                                0,
41                                                                                                                                                PF_FLOAT16_RGBA,
42                                                                                                                                                TU_RENDERTARGET);
43         impostorTexture = texPtr.getPointer();
44         impostorCamera = Root::getSingleton()._getCurrentSceneManager()->createCamera(name + "_CAMERA");
45         //add viewport to rendertarget
46         HardwarePixelBuffer* hpb = (impostorTexture->getBuffer()).getPointer();
47         RenderTarget* rt = hpb->getRenderTarget();
48         Viewport* v = rt->addViewport(impostorCamera);
49         v->setOverlaysEnabled(false);
50         rt->setAutoUpdated(false);
51}
52
53void OgreChildPSystemRenderingRun::updateFrame(unsigned long frameNum)
54{
55       
56        Material* mat = (Material*) MaterialManager::getSingleton().getByName(materialName).getPointer();
57
58    SceneManager* sm = Ogre::Root::getSingleton()._getCurrentSceneManager();
59        RenderQueue* rq = sm->getRenderQueue();
60        rq->clear();
61
62        Sphere boundSphere = ((OgreSharedRuns*)sharedRuns->getRoot(ILLUMRUN_HPP_IMPOSTOR))->getBoundingSphere();
63        Camera* mainCam = OgreIlluminationManager::getSingleton().getMainCamera();
64        impostorCamera->setPosition(mainCam->getPosition());
65        Vector3 dir = boundSphere.getCenter() - mainCam->getPosition();
66        float r = boundSphere.getRadius();
67        float d = dir.normalise();
68        impostorCamera->setDirection(dir);
69
70        if(perspectiveRendering)
71        {
72                impostorCamera->setProjectionType(PT_PERSPECTIVE);
73                impostorCamera->setAspectRatio(1.0);
74                Radian a = Math::ASin(r / d);
75                impostorCamera->setFOVy(a * 2.0);
76                impostorCamera->setNearClipDistance(std::max(0.01f, d - r));
77                impostorCamera->setFarClipDistance(r + d);             
78        }
79        else
80        {
81                impostorCamera->setPosition(boundSphere.getCenter());
82                impostorCamera->setProjectionType(PT_ORTHOGRAPHIC);
83                Matrix4 m;
84                m = Matrix4::IDENTITY;
85                float scale = 1.0 / boundSphere.getRadius();
86                m.setScale(Vector3(scale, scale, scale));
87                impostorCamera->setCustomProjectionMatrix(true, m);
88        }       
89
90        ParticleSystem* psys = Root::getSingleton()._getCurrentSceneManager()->getParticleSystem(childParticleSystemName);
91        psys->getParentSceneNode()->setPosition(boundSphere.getCenter());
92        psys->_notifyCurrentCamera(impostorCamera);
93        psys->_updateRenderQueue(rq);
94       
95        if(!useOwnMaterial)
96                setMaterialForRenderables(materialName,rq);
97       
98        RenderTarget* rt = impostorTexture->getBuffer().getPointer()->getRenderTarget();
99         
100        rt->update();   
101       
102        /*
103                static int framecount = 0;
104                String filename = "photon";
105                filename.append(this->name);
106                //filename.append(StringConverter::toString(framecount));
107                filename.append(".png");
108                rt->writeContentsToFile(filename);
109                framecount++;
110        */
111       
112        if(!useOwnMaterial)
113                restoreMaterials();
114}
115
Note: See TracBrowser for help on using the repository browser.