Merge branch 'ryzom/ark-features' into main/gingo-test
[ryzomcore.git] / nel / src / 3d / water_env_map_user.cpp
blob446ade3b8a92de25acf939ac70dd880b526f624b
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "std3d.h"
18 #include "nel/3d/water_env_map_user.h"
19 #include "nel/3d/u_scene.h"
20 #include "nel/3d/u_camera.h"
22 #ifdef DEBUG_NEW
23 #define new DEBUG_NEW
24 #endif
26 namespace NL3D
28 //////////////////////
29 // CWaterEnvMapUser //
30 //////////////////////
32 // ***********************************************************************************
33 void CWaterEnvMapUser::init(uint cubeMapSize, uint projection2DSize, TGlobalAnimationTime updateTime)
35 EnvMap.init(cubeMapSize, projection2DSize, updateTime, *(EnvMap.Driver->getDriver()));
38 //////////////////////////////
39 // CWaterEnvMapRenderHelper //
40 //////////////////////////////
43 // ***********************************************************************************
44 void CWaterEnvMapRenderHelper::render(TFace face, TGlobalAnimationTime time, UDriver &drv)
46 CMatrix mat;
47 using NLMISC::CVector;
48 switch(face)
50 case IWaterEnvMapRender::positive_x: mat.setRot(CVector::J, -CVector::I, -CVector::K); break;
51 case IWaterEnvMapRender::negative_x: mat.setRot(-CVector::J, CVector::I, -CVector::K); break;
52 case IWaterEnvMapRender::positive_y: mat.setRot(CVector::I, CVector::J, -CVector::K); break;
53 case IWaterEnvMapRender::negative_y: mat.setRot(-CVector::I, -CVector::J, -CVector::K); break;
54 case IWaterEnvMapRender::positive_z: mat.setRot(-CVector::I, CVector::K, -CVector::J); break;
55 case IWaterEnvMapRender::negative_z: mat.setRot(-CVector::I, -CVector::K, CVector::J); break;
56 default:
57 nlassert(0);
58 break;
60 doRender(mat, time, drv);
64 //////////////////////////////////
65 // CWaterEnvMapRenderFromUScene //
66 //////////////////////////////////
68 // ***********************************************************************************
69 CWaterEnvMapRenderFromUScene::CWaterEnvMapRenderFromUScene()
71 _Scene = NULL;
72 _ZNear = 0.1f;
73 _ZFar = 1000.f;
74 _RenderPart = UScene::RenderAll;
77 // ***********************************************************************************
78 void CWaterEnvMapRenderFromUScene::setScene(UScene *scene, UCamera cam)
80 _Scene = scene;
81 _Cam = cam;
82 if (_Scene)
84 nlassert(!_Cam.empty());
89 // ***********************************************************************************
90 void CWaterEnvMapRenderFromUScene::doRender(const CMatrix &camMatrix, TGlobalAnimationTime time, UDriver &drv)
92 if (!_Scene) return;
93 preRender(time, drv);
94 UCamera oldCam = _Scene->getCam();
95 if (_Cam.empty()) return;
96 _Scene->setCam(_Cam);
97 _Cam.setTransformMode(UTransformable::DirectMatrix);
98 nlassert(!_Cam.empty());
99 _Cam.setFrustum(-_ZNear, _ZNear, -_ZNear, _ZNear, _ZNear, _ZFar);
100 drv.setCullMode(drv.getCullMode() == UDriver::CCW ? UDriver::CW : UDriver::CCW);
101 CMatrix mat = camMatrix;
102 mat.setPos(_CamPos);
103 _Cam.setMatrix(mat);
104 CViewport old = _Scene->getViewport();
105 _Scene->setViewport(CViewport());
106 _Scene->beginPartRender();
107 _Scene->renderPart(_RenderPart);
108 _Scene->endPartRender();
109 _Scene->setViewport(old);
110 drv.setCullMode(drv.getCullMode() == UDriver::CCW ? UDriver::CW : UDriver::CCW);
111 _Scene->setCam(oldCam);
112 postRender(time, drv);
115 // ***********************************************************************************
116 void CWaterEnvMapUser::invalidate()
118 EnvMap.invalidate();
121 } // NL3D