Sea.cpp
上传用户:henghua
上传日期:2007-11-14
资源大小:7655k
文件大小:19k
- #include "Sea.h"
- #include <stdio.h>
- #include "tools.h"
- // 初始化部分
- CSea::CSea( const LPDIRECT3DDEVICE9 dev, CCamera *cam, CConfiguration *cfg, CMeshObj **ppmesh, int num_mesh, CBoatWave *pW)
- {
- position = SEAPOSITION;
- normal = SEANORMAL;
- sizeX = SEASIZEX+1;
- sizeY = SEASIZEY+1;
- config = cfg;
- device = dev;
- pCamera = cam;
- ppMeshObj = ppmesh;
- num_meshobj = num_mesh;
- pWave = pW;
- D3DXPlaneFromPointNormal( &plane, &position, &normal );
- D3DXPlaneFromPointNormal( &upPlane, &(position + 15.0f * normal), &normal);
- D3DXPlaneFromPointNormal( &downPlane, &(position - 15.0f * normal), &normal);
-
- pNoiseGenerator = new CNoiseGenerator(sizeX, sizeY, config, device);
- InitializeBuffers();
- InitializeTextures();
- LoadEffect();
- }
- bool CSea::InitializeBuffers(){
- if( FAILED( device->CreateVertexBuffer( sizeX*sizeY*sizeof(SEAVERTEX), D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC,
- D3DFVF_SEAVERTEX, D3DPOOL_DEFAULT, &seaVertices, NULL ) ) )
- return false;
- if( FAILED( device->CreateIndexBuffer( sizeof(unsigned int)*6*(sizeX-1)*(sizeY-1), D3DUSAGE_WRITEONLY,
- D3DFMT_INDEX32, D3DPOOL_DEFAULT, &seaIndices,NULL)))
- return false;
- unsigned int *pIB;
- if( FAILED( seaIndices->Lock(0,0,(void**)&pIB,0 ) ) )
- return false;
- int i = 0, v, u;
- for(v=0; v<sizeY-1; v++){
- for(u=0; u<sizeX-1; u++){
- pIB[i++] = v*sizeX + u;
- pIB[i++] = v*sizeX + u + 1;
- pIB[i++] = (v+1)*sizeX + u;
- pIB[i++] = (v+1)*sizeX + u;
- pIB[i++] = v*sizeX + u + 1;
- pIB[i++] = (v+1)*sizeX + u + 1;
- }
- }
- seaIndices->Unlock();
- return true;
- }
- bool CSea::InitializeTextures()
- {
- if( FAILED( D3DXCreateTextureFromFile( device, "textures/fresnel_water_linear.bmp", &FresnelMap ) ) )
- {
- MessageBox(NULL, "Could not find fresnelmap", "Textures.exe", MB_OK);
- return false;
- }
- device->CreateTexture(512, 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &SeaReflaMap,NULL);
- device->CreateTexture(512, 512, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &SeaRefraMap,NULL);
- device->CreateDepthStencilSurface(512, 512, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, true, &new_depthstencil, NULL );
- return true;
- }
- void CSea::LoadEffect(){
- char *errortext;
- LPD3DXBUFFER errors;
- D3DXHANDLE hTechnique;
- D3DXCreateEffectFromFile(device, "fx\SeaShader.fx",
- NULL, NULL, 0, NULL, &SeaEffect, &errors );
- if (errors != NULL){
- errortext = (char*) errors->GetBufferPointer();
- MessageBox(NULL, errortext, "OceanFlame", MB_OK);
- }
- SeaEffect->FindNextValidTechnique(NULL, &hTechnique);
- SeaEffect->SetTechnique(hTechnique);
- }
- bool CSea::Update()
- {
- SetupMatrices(pCamera);
-
- seaBeSeen = CalculateExtension();
-
- if (seaBeSeen){
- pNoiseGenerator->UpdateNoise(&extension, pWave);
-
- D3DVERTEXBUFFER_DESC pDesc;
- SEAVERTEX *pV;
- HRESULT hr = seaVertices->GetDesc( &pDesc );
- if( FAILED(seaVertices->Lock( 0, 0, (void**) &pV, D3DLOCK_DISCARD)))
- {
- MessageBox(NULL, "Could not lock vertexbuffer", "Textures.exe", MB_OK);
- }
- else
- {
- int size = pDesc.Size;
- memcpy(pV, pNoiseGenerator->noiseVertices, size);
- seaVertices->Unlock();
- }
- }
- return true;
- }
- // 利用投影网格技术计算投射矩阵
- bool CSea::CalculateExtension()
- {
- D3DXVECTOR3 frustum[8];
- D3DXVECTOR3 projectedPoints[24];
- int cube[] = { 0,1, 0,2, 2,3, 1,3, 0,4, 2,6, 3,7, 1,5, 4,6, 4,5, 5,7, 6,7};
- // 先求出视景体八个角的世界坐标
- D3DXVec3TransformCoord(&frustum[0], &D3DXVECTOR3(-1,-1,-1), &(pCamera->invviewproj));
- D3DXVec3TransformCoord(&frustum[1], &D3DXVECTOR3(+1,-1,-1), &(pCamera->invviewproj));
- D3DXVec3TransformCoord(&frustum[2], &D3DXVECTOR3(-1,+1,-1), &(pCamera->invviewproj));
- D3DXVec3TransformCoord(&frustum[3], &D3DXVECTOR3(+1,+1,-1), &(pCamera->invviewproj));
- D3DXVec3TransformCoord(&frustum[4], &D3DXVECTOR3(-1,-1,+1), &(pCamera->invviewproj));
- D3DXVec3TransformCoord(&frustum[5], &D3DXVECTOR3(+1,-1,+1), &(pCamera->invviewproj));
- D3DXVec3TransformCoord(&frustum[6], &D3DXVECTOR3(-1,+1,+1), &(pCamera->invviewproj));
- D3DXVec3TransformCoord(&frustum[7], &D3DXVECTOR3(+1,+1,+1), &(pCamera->invviewproj));
- // 计算视景体与海水起伏控制高度两个上下界面的交点并保存
- int i, numPoints=0;
- int head, tail;
- for(i=0; i<12; i++)
- {
- head=cube[i*2], tail=cube[i*2+1];
- if ((upPlane.a*frustum[head].x + upPlane.b*frustum[head].y + upPlane.c*frustum[head].z + upPlane.d*1)
- /(upPlane.a*frustum[tail].x + upPlane.b*frustum[tail].y + upPlane.c*frustum[tail].z + upPlane.d*1)<0)
- D3DXPlaneIntersectLine( &projectedPoints[numPoints++], &upPlane, &frustum[head], &frustum[tail]);
-
- if ((downPlane.a*frustum[head].x + downPlane.b*frustum[head].y + downPlane.c*frustum[head].z + downPlane.d*1)
- /(downPlane.a*frustum[tail].x + downPlane.b*frustum[tail].y + downPlane.c*frustum[tail].z + downPlane.d*1)<0)
- D3DXPlaneIntersectLine( &projectedPoints[numPoints++], &downPlane, &frustum[head], &frustum[tail]);
-
- }
-
- // 看视景体八个角点有无在两个界面之间
- for(i=0; i<8; i++)
- if ((upPlane.a*frustum[i].x + upPlane.b*frustum[i].y + upPlane.c*frustum[i].z + upPlane.d*1)
- /(downPlane.a*frustum[i].x + downPlane.b*frustum[i].y + downPlane.c*frustum[i].z + downPlane.d*1)<0)
- projectedPoints[numPoints++] = frustum[i];
-
- // 创建一个投射视角,用来构造投射矩阵
- CCamera *projectedCamera = new CCamera(pCamera);
- D3DXVECTOR3 lookAt1, lookAt2;
- projectedCamera->position += D3DXVECTOR3(downPlane.a,downPlane.b,downPlane.c)*10.0f;
- // 控制投射矩阵向前方向
- if(D3DXPlaneDotNormal(&plane, &(pCamera->forward)) < 0.0f)
- {
- D3DXPlaneIntersectLine( &lookAt1, &plane, &(pCamera->position), &(pCamera->position + pCamera->forward) );
- }
- else
- {
- D3DXVECTOR3 turnOver;
- turnOver = pCamera->forward - 2*normal*D3DXVec3Dot(&(pCamera->forward),&normal);
- D3DXPlaneIntersectLine( &lookAt1, &plane, &(pCamera->position), &(pCamera->position + turnOver) );
- }
- lookAt2 = pCamera->position + 10.0f * pCamera->forward;
- lookAt2 = lookAt2 - normal*D3DXVec3Dot(&lookAt2,&normal);
- float adjust= fabs(D3DXPlaneDotNormal(&plane, &(pCamera->forward)));
- lookAt1 = lookAt1*adjust + lookAt2*(1.0f-adjust);
-
- projectedCamera->forward = lookAt1-projectedCamera->position;
- projectedCamera->UpdateLookAt();
- // 求包围所有点的最大矩形包围
- for(i=0; i<numPoints; i++)
- {
- D3DXVec3TransformCoord( &projectedPoints[i], &projectedPoints[i], &(projectedCamera->viewproj));
- }
- float xmin, xmax, ymin, ymax;
- if(numPoints > 0)
- {
- xmin = projectedPoints[0].x, xmax = projectedPoints[0].x;
- ymin = projectedPoints[0].y, ymax = projectedPoints[0].y;
- for(i=1; i<numPoints; i++)
- {
- if (projectedPoints[i].x > xmax) xmax = projectedPoints[i].x;
- if (projectedPoints[i].x < xmin) xmin = projectedPoints[i].x;
- if (projectedPoints[i].y > ymax) ymax = projectedPoints[i].y;
- if (projectedPoints[i].y < ymin) ymin = projectedPoints[i].y;
- }
- D3DXMATRIXA16 matrix(xmax-xmin, 0, 0, xmin,
- 0, ymax-ymin, 0, ymin,
- 0, 0, 1, 0,
- 0, 0, 0, 1);
- D3DXMatrixTranspose(&matrix,&matrix);
- // 生成投射矩阵
- extension = matrix*projectedCamera->invviewproj;
- if(projectedCamera != NULL)
- delete projectedCamera;
- return true;
- }
- if(projectedCamera != NULL)
- delete projectedCamera;
- return false;
- }
- bool CSea::Render(){
- D3DXMATRIXA16 temp;
- D3DXMatrixIdentity(&temp);
- device->SetTransform( D3DTS_WORLD, &temp );
- // 分别渲染折射和反射场景
- RenderReflection();
- RenderRefraction();
- device->Clear( 0, NULL,D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, D3DCOLOR_XRGB((int)(198),(int)(210),(int)(255)), 1.0f, 0 );
-
- device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
- device->SetRenderState(D3DRS_ZWRITEENABLE,true);
- device->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESSEQUAL);
- device->SetRenderState(D3DRS_ALPHABLENDENABLE,false);
- // 用GPU计算海面,从而达到更加逼真的效果
- if (seaBeSeen)
- {
- {
- HRESULT hr;
- device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
- device->SetStreamSource( 0, seaVertices, 0, sizeof(SEAVERTEX) );
- device->SetFVF( D3DFVF_SEAVERTEX);
- device->SetIndices(seaIndices);
- pNoiseGenerator->UpdateVerticesNormal(pWave);
-
- float tnd = config->get_float(p_bNight_Day);
- device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
- hr=SeaEffect->Begin(NULL,NULL);
- hr=SeaEffect->Pass(0);
- hr=SeaEffect->SetMatrix("mViewProj",&(pCamera->viewproj));
- hr=SeaEffect->SetMatrix("mView",&(pCamera->view));
- /*SeaEffect->SetFloat("sun_alfa", config->params[p_fSunPosAlpha].fData);
- SeaEffect->SetFloat("sun_theta", config->params[p_fSunPosTheta].fData);*/
- float sa = config->params[p_fSunPosAlpha].fData,
- st = config->params[p_fSunPosTheta].fData * fabs(tnd * 2 - 1);
- hr=SeaEffect->SetVector("sun_vec",&D3DXVECTOR4(cos(st)*sin(sa), sin(st), cos(st)*cos(sa),0));
- hr=SeaEffect->SetFloat("sun_shininess", config->params[p_fSunShininess].fData);
- hr=SeaEffect->SetFloat("sun_strength", config->params[p_fSunStrength].fData);
- SeaEffect->SetFloat("reflrefr_offset", config->params[p_bReflRefrStrength].fData);
- SeaEffect->SetBool("diffuseSkyRef", config->params[p_bDiffuseRefl].bData);
- SeaEffect->SetVector("watercolour", &D3DXVECTOR4(config->params[p_fWaterColourR].fData,config->params[p_fWaterColourG].fData,config->params[p_fWaterColourB].fData,1));
- SeaEffect->SetFloat("LODbias", config->get_float(p_fLODbias) );
- SeaEffect->SetFloat("night_day", config->get_float(p_bNight_Day) );
- SeaEffect->SetVector("view_position", &D3DXVECTOR4(pCamera->position.x,pCamera->position.y,pCamera->position.z,1));
- SeaEffect->SetTexture("FresnelMap",FresnelMap);
- SeaEffect->SetTexture("Heightmap",pNoiseGenerator->heightMap);
- SeaEffect->SetTexture("Normalmap",pNoiseGenerator->normalMap);
- SeaEffect->SetTexture("Refractionmap",SeaRefraMap);
- SeaEffect->SetTexture("Reflectionmap",SeaReflaMap);
- device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, sizeX*sizeY, 0, 2*(sizeX-1)*(sizeY-1) );
-
- SeaEffect->End();
- }
- }
- return true;
- }
- CSea::~CSea()
- {
- }
- void CSea::SetupMatrices(const CCamera *camera_view)
- {
- D3DXMATRIXA16 matWorld,matProj;
- D3DXMatrixIdentity(&matWorld);
- device->SetTransform( D3DTS_WORLD, &matWorld );
- device->SetTransform( D3DTS_VIEW, &(camera_view->view) );
- device->SetTransform( D3DTS_PROJECTION, &(camera_view->proj) );
- }
- float CSea::get_height_at( float x, float z )
- {
- if (pNoiseGenerator)
- return pNoiseGenerator->GetHeight(x,z);
- return 0.0f;
- }
- void CSea::RenderRefraction()
- {
- // **保存旧的渲染目标表面, 设置新的渲染目标表面**
- device->GetRenderTarget(0, &old_target);
- device->GetDepthStencilSurface(&old_depthstencil);
- SeaRefraMap->GetSurfaceLevel(0, &new_target);
- device->SetRenderTarget(0, new_target);
- device->SetDepthStencilSurface(new_depthstencil);
- // **清空后台缓冲区**
- float red=0.12f, green=0.22f, blue=0.29f;
- device->Clear( 0, NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB((int)(255*red),(int)(255*green),(int)(255*blue)), 1.0f, 0 );
-
- // **保存旧的世界变换矩阵, 设置新的世界变换矩阵**
- D3DXMATRIXA16 old_world, scale;
- device->GetTransform(D3DTS_WORLD,&old_world);
- D3DXMatrixScaling( &scale, 1, 0.75, 1 );
- device->MultiplyTransform(D3DTS_WORLD, &scale );
- device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
- // **添加一个裁剪平面**
- float plane[4]={0, -1, 0, 0};
- plane[0] = 0;
- plane[1] = -1;
- plane[2] = 0;
- plane[3] = 10.0f;
- device->SetClipPlane(0,plane);
- // ***** 开始渲染 *****
- // 设置太阳光
- SetSunLight(rsm_refraction);
-
- int i;
- for(i=0; i<this->num_meshobj; i++)
- {
- if(ppMeshObj[i]->movement_mode == is_land || ppMeshObj[i]->movement_mode == moving_on_sea)
- {
- GPUDrawMeshObj( ppMeshObj[i] );
- }
- }
-
- device->SetRenderState( D3DRS_LIGHTING, false);
- device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
-
- device->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESSEQUAL );
- device->SetRenderState( D3DRS_CLIPPLANEENABLE, 0);
- device->SetTransform(D3DTS_WORLD, &old_world);
- device->SetRenderTarget(0, old_target);
- device->SetDepthStencilSurface(old_depthstencil);
- }
- void CSea::RenderReflection()
- {
- // **保存旧的渲染目标表面和深度模版表面, 设置新的渲染目标表面和深度模版表面**
- device->GetRenderTarget(0, &old_target );
- device->GetDepthStencilSurface(&old_depthstencil);
- SeaReflaMap->GetSurfaceLevel( 0,&new_target );
- device->SetRenderTarget(0, new_target);
- device->SetDepthStencilSurface( new_depthstencil );
- // **清空后台缓冲区**
- device->Clear( 0, NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0, 1.0f, 0 );
- float red=0.12f, green=0.22f, blue=0.29f;
- //device->Clear( 0, NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB((int)(255*0.1f),(int)(255*0.5f),(int)(255*0.8)), 1.0f, 0 );
- // **保存旧的世界变换矩阵, 设置新的世界变换矩阵**
- D3DXMATRIXA16 old_world, scale;
- device->GetTransform(D3DTS_WORLD,&old_world);
- device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW ); // 设置剔除模式
- // **添加一个裁剪平面**
- float plane[4];
- plane[0] = 0;
- plane[1] = -1;
- plane[2] = 0;
- plane[3] = 5.0f;
- device->SetClipPlane(0,plane);
- device->SetRenderState( D3DRS_CLIPPLANEENABLE, 1);
- // ***** 开始渲染 *****
- // 设置太阳光
- SetSunLight(rsm_reflection);
- D3DXMATRIXA16 store2, offset, yrot,scale2; // 旧世界变换矩阵, 平移矩阵, 旋转矩阵, 放缩矩阵
- // 获取旧的世界变换矩阵
- device->GetTransform(D3DTS_WORLD,&store2);
-
- int i;
- for(i=0; i<this->num_meshobj; i++){
- if(ppMeshObj[i]->movement_mode == fixed_down_sea)
- continue;
- device->MultiplyTransform(D3DTS_WORLD, &(ppMeshObj[i]->matWorld0));
- device->MultiplyTransform(D3DTS_WORLD, &(ppMeshObj[i]->matWorld) );
- // device->MultiplyTransform(D3DTS_WORLD, &(ppMeshObj[i]->rotate) );
- //if(ppMeshObj[i]->movement_mode == moving_up_freely)
- //{
- // 作用一个微镜面平移
- D3DXMatrixTranslation( &offset, 0,+2.0f, 0);
- device->MultiplyTransform(D3DTS_WORLD, &offset );
- //}
- // 在原世界变换矩阵上作用一个放缩
- //D3DXMatrixScaling( &scale2, ppMeshObj[i]->scale0.x, ppMeshObj[i]->scale0.y, ppMeshObj[i]->scale0.z);
- //device->MultiplyTransform(D3DTS_WORLD, &scale2 );
- // **依据不同的物体设置新的裁剪平面**
- SetClipPlane( ppMeshObj[i] );
- D3DXMatrixScaling( &scale, 1, -1, 1 ); // 生成反射成像的镜面变换矩阵
- device->MultiplyTransform(D3DTS_WORLD, &scale );
- // **打开光照**
- device->SetRenderState( D3DRS_LIGHTING, true);
- // **画**
- Draw_meshobj( ppMeshObj[i] );
-
- // **还原旧的世界变换矩阵**
- device->SetTransform(D3DTS_WORLD, &store2);
- }
- // **还原:关闭光照**
- device->SetRenderState( D3DRS_LIGHTING, false);
- device->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
- // **还原旧的世界变换矩阵和旧的渲染目标表面和深度模版表面**
- device->SetRenderState( D3DRS_CLIPPLANEENABLE, 0);
- device->SetTransform(D3DTS_WORLD, &old_world);
- device->SetRenderTarget(0, old_target);
- device->SetDepthStencilSurface( old_depthstencil );
- }
- // 光线反射(太阳光,火焰)
- void CSea::SetSunLight(int mode)
- {
- // 设置太阳光
- D3DLIGHT9 sun;
- sun.Direction.x = -cos(config->get_float(p_fSunPosTheta))*sin(config->get_float(p_fSunPosAlpha));
- sun.Direction.y = -sin(config->get_float(p_fSunPosTheta));
- sun.Direction.z = -cos(config->get_float(p_fSunPosTheta))*cos(config->get_float(p_fSunPosAlpha));
- if(mode==rsm_reflection)
- {
- //sun.Direction.x = -sun.Direction.x;
- sun.Direction.y = -sun.Direction.y;
- //sun.Direction.z = -sun.Direction.z;
- }
- sun.Diffuse.r = 2.0f;
- sun.Diffuse.g = 2.0f;
- sun.Diffuse.b = 2.0f;
- sun.Diffuse.a = 1.0f;
- sun.Ambient.a = 1.0f;
- sun.Ambient.r = 0.2f;
- sun.Ambient.g = 0.3f;
- sun.Ambient.b = 0.3f;
- sun.Specular.r = 1.0f;
- sun.Specular.g = 1.0f;
- sun.Specular.b = 1.0f;
- sun.Specular.a = 1.0f;
- sun.Attenuation0 = 1.0f;
- sun.Type = D3DLIGHT_DIRECTIONAL;
- device->SetLight(0, &sun);
- device->LightEnable( 0, true);
- }
- // 设置裁减平面
- void CSea::SetClipPlane(CMeshObj *pM)
- {
- float plane[4];
- device->GetClipPlane(0,plane);
-
- if( pM->movement_mode == is_land ) // 如: 海中的小岛
- plane[3] = 0.1;
- else
- {
- if( pM->movement_mode == moving_on_sea )
- plane[3] = this->get_height_at(pM->position.x, pM->position.z) + 0.1;
- }
- device->SetClipPlane(0,plane);
- }
- void CSea::Draw_meshobj(CMeshObj *pM)
- {
- // 设置材质对漫反射光,镜面反射光,环境光的反射系数
- if(pM->draw_mtrls_state == not_have_mtrls)
- {
- device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1 );
- device->SetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_COLOR1 );
- device->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );
- }
- else
- {
- if(pM->draw_mtrls_state == have_mtrls)
- {
- device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL );
- device->SetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL );
- device->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL );
- }
- }
- int i;
- for(i=0; i<pM->num_mtrls; i++)
- {
- if(pM->draw_mtrls_state == have_mtrls)
- device->SetMaterial( &(pM->pMeshMtrls[i]) );
- if(pM->draw_texs_state == have_mtrls)
- device->SetTexture(0, pM->pMeshTexs[i] );
- if(pM->draw_texs_state == load_texs )
- {
- if(pM->load_texs_mode == 0)
- device->SetTexture(0, pM->pMeshTexs[i]);
- else
- device->SetTexture(0, pM->pMeshTexs[0]);
- }
- pM->pMesh->DrawSubset(i);
- }
- }
- void CSea::GPUDrawMeshObj(CMeshObj *pM)
- {
- LPDIRECT3DVERTEXBUFFER9 vb;
- LPDIRECT3DINDEXBUFFER9 ib;
- pM->pMesh->GetVertexBuffer(&vb);
- pM->pMesh->GetIndexBuffer(&ib);
-
- device->SetStreamSource(0, vb, 0, pM->pMesh->GetNumBytesPerVertex());
- device->SetIndices(ib);
- device->SetFVF( pM->pMesh->GetFVF() );
- pM->pLoadEffect->Begin(NULL,NULL);
- pM->pLoadEffect->Pass(0);
- pM->pLoadEffect->SetMatrix("mWorld",&(pM->matWorld*pM->matWorld0));
- pM->pLoadEffect->SetMatrix("mViewProj",&(pCamera->viewproj));
- pM->pLoadEffect->SetMatrix("mView",&(pCamera->view));
- float sa = config->params[p_fSunPosAlpha].fData, st = config->params[p_fSunPosTheta].fData;
- pM->pLoadEffect->SetVector("sun_vec",&D3DXVECTOR4(cos(st)*sin(sa), sin(st), cos(st)*cos(sa),0));
- pM->pLoadEffect->SetFloat("sun_shininess", config->params[p_fSunShininess].fData);
- pM->pLoadEffect->SetFloat("sun_strength", config->params[p_fSunStrength].fData);
- pM->pLoadEffect->SetVector("watercolour", &D3DXVECTOR4(config->params[p_fWaterColourR].fData,config->params[p_fWaterColourG].fData,config->params[p_fWaterColourB].fData,1));
- pM->pLoadEffect->SetVector("view_position", &D3DXVECTOR4(pCamera->position.x,pCamera->position.y,pCamera->position.z,1));
- pM->pLoadEffect->SetTexture("texDiffuse",pM->pMeshTexs[pM->gpu_tex]);
- device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, pM->pMesh->GetNumVertices(), 0, pM->pMesh->GetNumFaces() );
- pM->pLoadEffect->End();
- }