00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "std3d.h"
00027
00028 #include <vector>
00029 #include "nel/misc/hierarchical_timer.h"
00030 #include "3d/landscape_model.h"
00031 #include "3d/landscape.h"
00032 #include "3d/cluster.h"
00033 #include "3d/scene.h"
00034 #include "3d/light_trav.h"
00035 using namespace std;
00036 using namespace NLMISC;
00037
00038 #define NL3D_MEM_LANDSCAPE NL_ALLOC_CONTEXT( 3dLand )
00039
00040 namespace NL3D
00041 {
00042
00043
00044
00045
00046 void CLandscapeModel::registerBasic()
00047 {
00048 CMOT::registerModel(LandscapeModelId, TransformId, CLandscapeModel::creator);
00049 CMOT::registerObs(ClipTravId, LandscapeModelId, CLandscapeClipObs::creator);
00050 CMOT::registerObs(RenderTravId, LandscapeModelId, CLandscapeRenderObs::creator);
00051 }
00052
00053
00054
00055 CLandscapeModel::CLandscapeModel()
00056 {
00057 Landscape.init();
00058 _ActiveAdditive=false;
00059 _Additive=1.f;
00060
00061
00062 CTransform::setIsRenderable(true);
00063 }
00064
00065
00066
00067 void CLandscapeModel::initModel()
00068 {
00069 CTransform::initModel();
00070
00071
00072
00073 Landscape.createVegetableBlendLayersModels(safe_cast<CScene*>(_OwnerMot));
00074 }
00075
00076
00077
00078 void CLandscapeClipObs::init()
00079 {
00080 CTransformClipObs::init();
00081
00082
00083 CClipTrav *clipTrav= (CClipTrav*)Trav;
00084 clipTrav->unlink(NULL, Model);
00085 clipTrav->link(clipTrav->RootCluster, Model);
00086 }
00087
00088
00089 bool CLandscapeClipObs::clip(IBaseClipObs *caller)
00090 {
00091 H_AUTO( NL3D_Landscape_Clip );
00092
00093 CLandscapeModel *landModel= (CLandscapeModel*)Model;
00094 CClipTrav *clipTrav= (CClipTrav*)Trav;
00095
00096
00097 landModel->Landscape.setDriver(clipTrav->RenderTrav->getDriver());
00098
00099
00100 vector<CPlane> &pyramid= clipTrav->WorldFrustumPyramid;
00101
00102
00103 landModel->Landscape.clip(clipTrav->CamPos, pyramid);
00104
00105
00106
00107
00108 landModel->CurrentPyramid[0]= pyramid[NL3D_CLIP_PLANE_LEFT];
00109 landModel->CurrentPyramid[1]= pyramid[NL3D_CLIP_PLANE_RIGHT];
00110 landModel->CurrentPyramid[2]= pyramid[NL3D_CLIP_PLANE_TOP];
00111 landModel->CurrentPyramid[3]= pyramid[NL3D_CLIP_PLANE_BOTTOM];
00112 nlassert(NL3D_TESSBLOCK_NUM_CLIP_PLANE==4);
00113
00114
00115 return true;
00116 }
00117
00118
00119 void CLandscapeRenderObs::traverse(IObs *caller)
00120 {
00121 NL3D_MEM_LANDSCAPE
00122
00123 CLandscapeModel *landModel= (CLandscapeModel*)Model;
00124
00125 CRenderTrav *trav= (CRenderTrav*)Trav;
00126
00127
00128
00129 landModel->Landscape.setPZBModelPosition(trav->CamPos);
00130
00131
00132 CMatrix m;
00133 m.identity();
00134
00135
00136 m.setPos(landModel->Landscape.getPZBModelPosition());
00137 trav->getDriver()->setupModelMatrix(m);
00138
00139
00140
00141 CScene *scene= dynamic_cast<CScene*>(landModel->_OwnerMot);
00142 if(scene)
00143 {
00144
00145 landModel->Landscape.setVegetableTime(scene->getCurrentTime());
00146
00147
00148 landModel->Landscape.setVegetableUpdateLightingTime(scene->getCurrentSystemTime());
00149
00150
00151 H_BEFORE( NL3D_Landscape_UpdateLighting );
00152 landModel->Landscape.updateLighting(scene->getCurrentSystemTime());
00153 H_AFTER( NL3D_Landscape_UpdateLighting );
00154
00155
00156 if(scene->isLightingSystemEnabled())
00157 {
00158 H_AUTO( NL3D_Landscape_DynamicLighting );
00159
00160
00161 landModel->Landscape.setupVegetableLighting(scene->getSunAmbient(), scene->getSunDiffuse(),
00162 scene->getSunDirection());
00163
00164
00165 IBaseLightObs *lightObs= static_cast<IBaseLightObs*>(landModel->_LightObs);
00166
00167 CLightTrav *lightTrav= (CLightTrav*)lightObs->Trav;
00168
00169 landModel->Landscape.computeDynamicLighting(lightTrav->LightingManager.getAllDynamicLightList());
00170 }
00171 }
00172
00173
00174 H_BEFORE( NL3D_Landscape_Refine );
00175 landModel->Landscape.refine(trav->CamPos);
00176 H_AFTER( NL3D_Landscape_Refine );
00177
00178
00179 H_BEFORE( NL3D_Landscape_Render );
00180 landModel->Landscape.render(trav->CamPos, trav->CamLook, landModel->CurrentPyramid, landModel->isAdditive ());
00181 H_AFTER( NL3D_Landscape_Render );
00182 }
00183
00184
00185
00186 }