#include "stdafx.h" #include "SGameEnvironmentMap.h" #include "KRenderObject.h" #include "SGameViewPort.h" #include "SGameObject.h" namespace { const int ENVMAP_SEGMENT_COUNT = 2; const int ENVMAP_SEGMENET_INDEX_COUNT = (ENVMAP_SEGMENT_COUNT - 1) * (ENVMAP_SEGMENT_COUNT - 1) * 2; } SGameEnvironmentMapPrimitive::SGameEnvironmentMapPrimitive() : m_pPrimitive( NULL ), m_pIndexed( NULL ) { SetBlendMode(K3DMaterial::MBM_ENVMAP); } SGameEnvironmentMapPrimitive::~SGameEnvironmentMapPrimitive() { SAFE_DELETE( m_pPrimitive ); SAFE_DELETE( m_pIndexed ); } void SGameEnvironmentMapPrimitive::SetVertex( K3DVERTEX_WATER* pVertex ) { m_pPrimitive = pVertex; } void SGameEnvironmentMapPrimitive::SetIndexed( K3DINDEXED_WATER* pIndexed ) { m_pIndexed = pIndexed; } void SGameEnvironmentMapPrimitive::Render( KViewportObject *viewport, class K3DRenderDevice *dev, bool bUseAccum ) { static bool bTex1 = true; static bool bTex2 = false; if( bTex1 ) dev->SetTexture( 0, NULL ); //범프맵 끄기 if( bTex2 ) dev->SetTexture( 1, NULL ); //반사맵 끄기 dev->SetVertexShaderConstant( CONSTANT_VISIBILITY, &m_fVisibility, 1 ); dev->DrawIndexedPrimitiveUP_VS( 0, m_pPrimitive, (ENVMAP_SEGMENT_COUNT*ENVMAP_SEGMENT_COUNT), sizeof(K3DVERTEX_WATER), (WORD*)m_pIndexed, ENVMAP_SEGMENET_INDEX_COUNT*3 ); } ////////////////////////////////////////////////////////////////// // SGameEnvironmentMap::SGameEnvironmentMap( SGameObject* pObject ) : m_pObject( pObject ), m_pEnvMapPrimitive( NULL ), m_pPrimitive( NULL ), m_pIndexed( NULL ) { static float fScale = 300.f; K3DMatrix matTrans = *m_pObject->GetTransform(); m_fWidthLength = fScale / (float)(ENVMAP_SEGMENT_COUNT-1); m_fHeightLength = fScale / (float)(ENVMAP_SEGMENT_COUNT-1); m_fWidthCenter = fScale / 2.f; m_fHeightCenter = fScale / 2.f; m_pEnvMapPrimitive = new SGameEnvironmentMapPrimitive; m_pEnvMapPrimitive->GetRootMat()->_41 = matTrans._41; m_pEnvMapPrimitive->GetRootMat()->_42 = matTrans._42; m_pPrimitive = new K3DVERTEX_WATER[ENVMAP_SEGMENT_COUNT*ENVMAP_SEGMENT_COUNT]; K3DVERTEX_WATER* pTempVertex = m_pPrimitive; WORD wTile=0; for(int h = 0; h < ENVMAP_SEGMENT_COUNT; ++h ) { for( int w = 0; w < ENVMAP_SEGMENT_COUNT; ++w ) { pTempVertex->p = K3DVector( (-m_fWidthCenter ) + (w*m_fWidthLength), m_fHeightCenter - (h*m_fHeightLength), 0.f ); pTempVertex->normal = K3DVector( 0.f, 0.f, 1.f ); pTempVertex->color = 0xb4ffff00; pTempVertex->tu = (static_cast(w)/ (ENVMAP_SEGMENT_COUNT-1) ); pTempVertex->tv = (static_cast(h)/ (ENVMAP_SEGMENT_COUNT-1) ); pTempVertex->tu2 = (static_cast(w)/ (ENVMAP_SEGMENT_COUNT-1) ); pTempVertex->tv2 = (static_cast(h)/ (ENVMAP_SEGMENT_COUNT-1) ); m_pObject->GetHeight( pTempVertex->p.x + matTrans._41 , pTempVertex->p.y + matTrans._42, pTempVertex->p.z, wTile ); ++pTempVertex; } } m_pIndexed = new K3DINDEXED_WATER[ENVMAP_SEGMENET_INDEX_COUNT]; K3DINDEXED_WATER* pTempIndexed = m_pIndexed; for(int h = 0; h < (ENVMAP_SEGMENT_COUNT-1); ++h ) { for( int w = 0; w < (ENVMAP_SEGMENT_COUNT-1); ++w ) { pTempIndexed->a = (WORD)((ENVMAP_SEGMENT_COUNT*h)+w); pTempIndexed->b = (WORD)((ENVMAP_SEGMENT_COUNT*h)+w+1); pTempIndexed->c = (WORD)((ENVMAP_SEGMENT_COUNT*(h+1))+w); pTempIndexed++; pTempIndexed->a = (WORD)((ENVMAP_SEGMENT_COUNT*h)+w+1); pTempIndexed->b = (WORD)((ENVMAP_SEGMENT_COUNT*(h+1))+w+1); pTempIndexed->c = (WORD)((ENVMAP_SEGMENT_COUNT*(h+1))+w); ++pTempIndexed; } } m_pEnvMapPrimitive->SetVertex( m_pPrimitive ); m_pEnvMapPrimitive->SetIndexed( m_pIndexed ); m_pEnvMapPrimitive->SetTransparent( true ); } SGameEnvironmentMap::~SGameEnvironmentMap() { SAFE_DELETE( m_pEnvMapPrimitive ); } void SGameEnvironmentMap::Process( DWORD dwTime ) { } void SGameEnvironmentMap::Render( KViewportObject *viewport ) { K3DMatrix matRoot; K3DMatrixIdentity( matRoot ); matRoot._41 = m_pObject->GetTransform()->_41; matRoot._42 = m_pObject->GetTransform()->_42; matRoot._43 = m_pObject->GetTransform()->_43; m_pEnvMapPrimitive->SetRootMat( &matRoot ); m_pEnvMapPrimitive->SetVisibility(1.f); viewport->Register( m_pEnvMapPrimitive, KRenderObject::RENDEREFX_NONE ); /* K3DVector vPlane[4]; for( int x = 0; x < 4; ++x ) vPlane[x] = K3DVector( m_pPrimitive[x].p.x + matRoot._41, m_pPrimitive[x].p.y + matRoot._42, m_pPrimitive[x].p.z + matRoot._43 ); viewport->SetWaterPlane( vPlane );*/ }