Initial commit: ROW Client source code
Game client codebase including: - CharacterActionControl: Character and creature management - GlobalScript: Network, items, skills, quests, utilities - RYLClient: Main client application with GUI and event handlers - Engine: 3D rendering engine (RYLGL) - MemoryManager: Custom memory allocation - Library: Third-party dependencies (DirectX, boost, etc.) - Tools: Development utilities 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
514
Engine/Zalla3D Scene Class/AmbienceManager.cpp
Normal file
514
Engine/Zalla3D Scene Class/AmbienceManager.cpp
Normal file
@@ -0,0 +1,514 @@
|
||||
// AmbienceManager.cpp: implementation of the CAmbienceManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "BaseGraphicsLayer.h"
|
||||
#include "SceneManager.h"
|
||||
#include "SoundMgr.h"
|
||||
#include "AmbienceManager.h"
|
||||
#include "BgmManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//#define AMB_GAP 0.005
|
||||
|
||||
CAmbienceManager* CAmbienceManager::ms_pInstance = NULL;
|
||||
|
||||
struct TESTSCREEN_VERTEX
|
||||
{
|
||||
float x, y, z, rhw;
|
||||
float u, v;
|
||||
};
|
||||
|
||||
CAmbienceManager* CAmbienceManager::_GetInstance()
|
||||
{
|
||||
if( ms_pInstance == NULL )
|
||||
{ ms_pInstance = new CAmbienceManager; }
|
||||
return ms_pInstance;
|
||||
}
|
||||
|
||||
CAmbienceManager::CAmbienceManager()
|
||||
{
|
||||
}
|
||||
|
||||
CAmbienceManager::~CAmbienceManager()
|
||||
{
|
||||
}
|
||||
|
||||
void CAmbienceManager::_Destroy()
|
||||
{
|
||||
if( ms_pInstance ) ms_pInstance->ReleaseAllData();
|
||||
SAFE_DELETE( ms_pInstance );
|
||||
}
|
||||
|
||||
|
||||
void CAmbienceManager::Create( bool bTestMode )
|
||||
{
|
||||
m_bTestMode = bTestMode;
|
||||
if( m_bTestMode )
|
||||
{
|
||||
m_pAmbTexture = NULL;
|
||||
m_bTestShow = false;
|
||||
m_ptFont= new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
|
||||
m_ptFont->InitDeviceObjects( BaseGraphicsLayer::GetDevice() );
|
||||
m_ptFont->RestoreDeviceObjects();
|
||||
D3DXCreateSprite( BaseGraphicsLayer::GetDevice(), &m_pMouseArrow );
|
||||
D3DXCreateTextureFromFileEx( BaseGraphicsLayer::GetDevice(), "MouseArrow.bmp",
|
||||
D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, 1, 0,
|
||||
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE,
|
||||
D3DX_FILTER_NONE, 0xff000000, NULL, NULL,
|
||||
&m_pArrowTexture );
|
||||
}
|
||||
|
||||
m_pSectorAmbMap = new CSectorAmbienceMap;
|
||||
m_bFadeIn = false;
|
||||
m_bFadeOut = false;
|
||||
m_fFadeInVolume = 0.0f;
|
||||
m_fFadeOutVolume = 0.0f;
|
||||
strcpy( m_strFadeInFileName, "" );
|
||||
strcpy( m_strFadeOutFileName, "" );
|
||||
strcpy( m_strOldFile, "" );
|
||||
m_bAmbPlay = false;
|
||||
strcpy( m_strAmbPlayFile, "" );
|
||||
m_fAmbVolume =0.0f;
|
||||
m_fMasterVolume = 1.0f;
|
||||
m_pCurSchedule = NULL;
|
||||
}
|
||||
|
||||
|
||||
void CAmbienceManager::ReleaseAllData()
|
||||
{
|
||||
SAFE_DELETE( m_pSectorAmbMap );
|
||||
|
||||
if( m_bTestMode )
|
||||
{
|
||||
SAFE_RELEASE( m_pAmbTexture );
|
||||
SAFE_RELEASE( m_pMouseArrow );
|
||||
SAFE_RELEASE( m_pArrowTexture );
|
||||
delete m_ptFont;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CAmbienceManager::Update( D3DXVECTOR3& Pos, float fSkip, bool bCharSel )
|
||||
{
|
||||
|
||||
int SectorX, SectorY;
|
||||
SectorAmbience* pInfo=NULL;
|
||||
float fVolume;
|
||||
D3DVECTOR vPoint;
|
||||
DWORD dwMode;
|
||||
char* strPlayFile;
|
||||
float fVolumeGap = 0.01f;
|
||||
|
||||
SectorX = (int)(Pos.x / SECTORSIZE);
|
||||
SectorY = (int)(Pos.z / SECTORSIZE);
|
||||
|
||||
pInfo = m_pSectorAmbMap->GetSectorAmbience( SectorX, SectorY );
|
||||
|
||||
if( pInfo && !bCharSel)
|
||||
{
|
||||
bool bPlay = GetAmbienceInfo( pInfo, Pos, strPlayFile, vPoint, fVolume, dwMode );
|
||||
|
||||
if( CBgmManager::_GetInstance()->IsCurBgmTurnAmbEvent() ||
|
||||
CSceneManager::ms_pSceneEventMgr->m_bEventMusic )
|
||||
{
|
||||
bPlay = false;
|
||||
}
|
||||
|
||||
/*
|
||||
if( m_bTestMode )
|
||||
{
|
||||
if( bPlay )
|
||||
{
|
||||
m_ptFont->DrawText( 2, 175, D3DCOLOR_ARGB(255,255,255,0), "AmbienceOn" );
|
||||
if( strPlayFile ) m_ptFont->DrawText( 2, 200, D3DCOLOR_ARGB(255,255,255,0), strPlayFile );
|
||||
char buf[MAX_PATH];
|
||||
sprintf( buf, "%f, %f, %f", vPoint.x, vPoint.y, vPoint.z );
|
||||
m_ptFont->DrawText( 2, 225, D3DCOLOR_ARGB(255,255,255,0), buf );
|
||||
sprintf( buf, "VOLUME:%f", fVolume );
|
||||
m_ptFont->DrawText( 2, 250, D3DCOLOR_ARGB(255,255,255,0), buf );
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
CStreamingSound3D* pSound3D;
|
||||
if( bPlay )
|
||||
{
|
||||
PlayAmbience( strPlayFile, vPoint, fVolume, dwMode );
|
||||
RandomPlaySound();
|
||||
}
|
||||
|
||||
if( m_bFadeIn )
|
||||
{
|
||||
m_fFadeInVolume += fVolumeGap;
|
||||
if( m_fFadeInVolume >= fVolume )
|
||||
{
|
||||
m_bFadeIn = false;
|
||||
}
|
||||
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound3D( pSound3D, m_strFadeInFileName );
|
||||
pSound3D->SetVolume( m_fFadeInVolume*m_fMasterVolume );
|
||||
}
|
||||
else if( bPlay )
|
||||
{
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound3D( pSound3D, m_strFadeInFileName );
|
||||
pSound3D->SetVolume( fVolume*m_fMasterVolume );
|
||||
m_fAmbVolume = fVolume;
|
||||
}
|
||||
|
||||
if( m_bFadeOut )
|
||||
{
|
||||
m_fFadeOutVolume -= fVolumeGap;
|
||||
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound3D( pSound3D, m_strFadeOutFileName );
|
||||
if( m_fFadeOutVolume >= 0.0f ) pSound3D->SetVolume( m_fFadeOutVolume*m_fMasterVolume );
|
||||
|
||||
if( m_fFadeOutVolume <= 0.0f )
|
||||
{
|
||||
m_bFadeOut = false;
|
||||
pSound3D->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
static float fAmbVolume=0.0f;
|
||||
static bool bInit = false;
|
||||
if( !bPlay && m_bAmbPlay )
|
||||
{
|
||||
if( !bInit )
|
||||
{
|
||||
fAmbVolume = m_fAmbVolume;
|
||||
bInit = true;
|
||||
}
|
||||
fAmbVolume -= fVolumeGap;
|
||||
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound3D( pSound3D, m_strAmbPlayFile );
|
||||
if( fAmbVolume <= 0.0f )
|
||||
{
|
||||
pSound3D->Stop();
|
||||
m_bAmbPlay = false;
|
||||
bInit = false;
|
||||
strcpy( m_strOldFile, "" );
|
||||
}
|
||||
else pSound3D->SetVolume( fAmbVolume*m_fMasterVolume );
|
||||
}
|
||||
|
||||
//if( m_bTestMode ) TestScreen( Pos );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CAmbienceManager::LoadTexture( SectorAmbience* pInfo )
|
||||
{
|
||||
static SectorAmbience* pOldInfo = pInfo;
|
||||
static bool bOnce = false;
|
||||
|
||||
if( !bOnce )
|
||||
{
|
||||
SAFE_RELEASE(m_pAmbTexture);
|
||||
D3DXCreateTextureFromFileEx( BaseGraphicsLayer::GetDevice(), pInfo->strTexFilename,
|
||||
D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, 1, 0,
|
||||
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE,
|
||||
D3DX_FILTER_NONE, 0x00000000, NULL, NULL,
|
||||
&m_pAmbTexture );
|
||||
bOnce = true;
|
||||
}
|
||||
|
||||
if( pOldInfo->iSectorX != pInfo->iSectorX || pOldInfo->iSectorY != pInfo->iSectorY )
|
||||
{
|
||||
pOldInfo = pInfo;
|
||||
SAFE_RELEASE(m_pAmbTexture);
|
||||
D3DXCreateTextureFromFileEx( BaseGraphicsLayer::GetDevice(), pInfo->strTexFilename,
|
||||
D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, 1, 0,
|
||||
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE,
|
||||
D3DX_FILTER_NONE, 0x00000000, NULL, NULL,
|
||||
&m_pAmbTexture );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CAmbienceManager::PlayAmbience( char* strFile, D3DVECTOR vPos, float fVol, DWORD dwMode )
|
||||
{
|
||||
|
||||
static CStreamingSound3D* pSound3D;
|
||||
|
||||
if( strcmp(m_strOldFile, strFile) != 0 )
|
||||
{
|
||||
m_bFadeIn = true;
|
||||
strcpy( m_strFadeInFileName, strFile );
|
||||
m_fFadeInVolume = 0.0f;
|
||||
|
||||
m_bAmbPlay = true;
|
||||
strcpy( m_strAmbPlayFile, strFile );
|
||||
|
||||
if( strlen(m_strOldFile) )
|
||||
{
|
||||
m_bFadeOut = true;
|
||||
strcpy( m_strFadeOutFileName, m_strOldFile );
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound3D( pSound3D, m_strOldFile );
|
||||
pSound3D->GetVolume( m_fFadeOutVolume );
|
||||
}
|
||||
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound3D( pSound3D, strFile );
|
||||
strcpy( m_strOldFile, strFile );
|
||||
pSound3D->SetPosition( vPos );
|
||||
pSound3D->SetVolume( 0.0f );
|
||||
pSound3D->SetMode( dwMode );
|
||||
pSound3D->SetLooping( true );
|
||||
pSound3D->Play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CAmbienceManager::GetAmbienceInfo( SectorAmbience* pinInfo, D3DXVECTOR3& inPos, char*& outStrFile,
|
||||
D3DVECTOR& outPos, float& outVol, DWORD& outMode )
|
||||
{
|
||||
int LockPosX, LockPosY;
|
||||
GetTextureLockPos( LockPosX, LockPosY, inPos );
|
||||
|
||||
if( m_bTestMode ) LoadTexture( pinInfo );
|
||||
|
||||
vector<AmbienceInfo*>::iterator iter;
|
||||
for( iter = pinInfo->AmbInfoList.begin(); iter != pinInfo->AmbInfoList.end(); iter++ )
|
||||
{
|
||||
DWORD AmbColor = pinInfo->ColorTable[LockPosY][LockPosX] & 0x00ffffff;
|
||||
|
||||
if( AmbColor == (*iter)->dwColor || AmbColor == (*iter)->dwPointColor )
|
||||
{
|
||||
//1.ã<><C3A3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ɸ<EFBFBD><C9B8>Ϳ<EFBFBD> <20><><EFBFBD>尡<EFBFBD><E5B0A1><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ã<>´<EFBFBD>.
|
||||
int PointNum = (*iter)->AmbPointList.size();
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ٸ<EFBFBD>
|
||||
if( PointNum == 0 )
|
||||
{
|
||||
outMode = MODE_DISABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ã<>´<EFBFBD>. HeadPoint<6E><74> <20><><EFBFBD><EFBFBD>
|
||||
D3DXVECTOR3 HeadPoint;
|
||||
float OldLength;
|
||||
D3DXVECTOR3 Point;
|
||||
D3DXVECTOR3 Dist;
|
||||
float length;
|
||||
|
||||
for( int i = 0; i < PointNum; i++ )
|
||||
{
|
||||
Point = *((*iter)->AmbPointList[i]);
|
||||
Dist = inPos - Point;
|
||||
length = D3DXVec3Length( &Dist );
|
||||
|
||||
if(!i)
|
||||
{
|
||||
OldLength = length;
|
||||
HeadPoint = Point;
|
||||
}
|
||||
|
||||
if( OldLength >= length && i )
|
||||
{
|
||||
OldLength = length;
|
||||
HeadPoint = Point;
|
||||
}
|
||||
}
|
||||
|
||||
outPos = HeadPoint; // HeadPoint <20>̰<EFBFBD><CCB0><EFBFBD> <20><><EFBFBD>尡<EFBFBD><E5B0A1><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ǥ
|
||||
outMode = MODE_NORMAL;
|
||||
}
|
||||
|
||||
//2. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ٿ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD≯<EFBFBD><CCB8><EFBFBD> <20><><EFBFBD>´<EFBFBD>.
|
||||
float fCurTime = CSceneManager::m_WeatherManager.m_fWeatherTime;
|
||||
|
||||
outStrFile = NULL;
|
||||
|
||||
// edith 2009.05.05 AMB <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ó<><C3B3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
if( fCurTime >= 6.0f && fCurTime < 18.0f )
|
||||
{
|
||||
m_pCurSchedule = (*iter)->ScheduleList[0];
|
||||
outStrFile = m_pCurSchedule->strFilename;
|
||||
}
|
||||
else if( (*iter)->ScheduleList.size() > 1 )
|
||||
{
|
||||
m_pCurSchedule = (*iter)->ScheduleList[1];
|
||||
outStrFile = m_pCurSchedule->strFilename;
|
||||
}
|
||||
|
||||
/*
|
||||
for( int i = 0; i < (int)((*iter)->ScheduleList.size()); i++ )
|
||||
{
|
||||
pSchedule = (*iter)->ScheduleList[i];
|
||||
m_pCurSchedule = pSchedule;
|
||||
|
||||
if( fCurTime >= pSchedule->fStartTime && fCurTime <= pSchedule->fEndTime )
|
||||
{
|
||||
outStrFile = pSchedule->strFilename;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
outStrFile = NULL;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if( outStrFile == NULL ) return false;
|
||||
|
||||
//3. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>´<EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
DWORD Volume = pinInfo->ColorTable[LockPosY][LockPosX];
|
||||
Volume = Volume>>24;
|
||||
outVol = (float)Volume;
|
||||
outVol = outVol/255.0f; //<2F>ּ<EFBFBD><D6BC><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 ~ 1
|
||||
|
||||
if( outVol > 1.0f ) outVol = 1.0f;
|
||||
if( outVol < 0.0f ) outVol = 0.0f;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CAmbienceManager::GetTextureLockPos( int& outX, int& outY, D3DXVECTOR3 inPos )
|
||||
{
|
||||
float Magnification = (float)SECTORSIZE / (float)AMB_TEXTURESIZE;
|
||||
|
||||
outX = (int)inPos.x % SECTORSIZE;
|
||||
outY = (int)inPos.z % SECTORSIZE;
|
||||
|
||||
outX = (float)outX / Magnification;
|
||||
outY = (float)outY / Magnification;
|
||||
|
||||
outY = AMB_TEXTURESIZE - outY -1; //Convert Texture LockPos
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CAmbienceManager::TestScreen( D3DXVECTOR3 Pos )
|
||||
{
|
||||
LPDIRECT3DDEVICE8 pd3dDevice = BaseGraphicsLayer::GetDevice();
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
pd3dDevice->SetVertexShader( D3DFVF_XYZRHW | D3DFVF_TEX1 );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
|
||||
pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
|
||||
D3DVIEWPORT8 TempViewport;
|
||||
pd3dDevice->GetViewport( &TempViewport );
|
||||
|
||||
float center = TempViewport.Width - 128;
|
||||
|
||||
TESTSCREEN_VERTEX pVertex[4];
|
||||
pVertex[0].x = center;
|
||||
pVertex[0].y = 0;
|
||||
pVertex[0].z = 0.0f;
|
||||
pVertex[0].rhw = 1.0f;
|
||||
pVertex[0].u = 0.0f;
|
||||
pVertex[0].v = 0.0f;
|
||||
|
||||
pVertex[1].x = 128.0f + center;
|
||||
pVertex[1].y = 0;
|
||||
pVertex[1].z = 0.0f;
|
||||
pVertex[1].rhw = 1.0f;
|
||||
pVertex[1].u = 1.0f;
|
||||
pVertex[1].v = 0.0f;
|
||||
|
||||
pVertex[2].x = center;
|
||||
pVertex[2].y = 128.0f;
|
||||
pVertex[2].z = 0.0f;
|
||||
pVertex[2].rhw = 1.0f;
|
||||
pVertex[2].u = 0.0f;
|
||||
pVertex[2].v = 1.0f;
|
||||
|
||||
pVertex[3].x = 128.0f + center;
|
||||
pVertex[3].y = 128.0f;
|
||||
pVertex[3].z = 0.0f;
|
||||
pVertex[3].rhw = 1.0f;
|
||||
pVertex[3].u = 1.0f;
|
||||
pVertex[3].v = 1.0f;
|
||||
|
||||
int LockPosX, LockPosY;
|
||||
GetTextureLockPos( LockPosX, LockPosY, Pos );
|
||||
|
||||
pd3dDevice->SetTexture( 0, m_pAmbTexture );
|
||||
pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, pVertex, sizeof(TESTSCREEN_VERTEX) );
|
||||
|
||||
//Set things back to normal
|
||||
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE, TRUE );
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ȭ<><C8AD>ǥ<EFBFBD><EFBFBD><D7B8>⤾<EFBFBD><E2A4BE><EFBFBD><EFBFBD>
|
||||
RECT rect__;
|
||||
SetRect( &rect__, 0, 0, 16, 16 );
|
||||
D3DXMATRIX mat;
|
||||
D3DXMatrixTranslation( &mat, LockPosX+center, LockPosY, 0 );
|
||||
m_pMouseArrow->DrawTransform( m_pArrowTexture, &rect__, &mat, 0xffffffff );
|
||||
}
|
||||
|
||||
|
||||
void CAmbienceManager::AllStop()
|
||||
{
|
||||
m_bFadeIn = false;
|
||||
m_bFadeOut = false;
|
||||
m_fFadeInVolume = 0.0f;
|
||||
m_fFadeOutVolume = 0.0f;
|
||||
strcpy( m_strFadeInFileName, "" );
|
||||
strcpy( m_strFadeOutFileName, "" );
|
||||
strcpy( m_strOldFile, "" );
|
||||
m_bAmbPlay = false;
|
||||
strcpy( m_strAmbPlayFile, "" );
|
||||
m_fAmbVolume =0.0f;
|
||||
m_fMasterVolume = 1.0f;
|
||||
|
||||
CSoundMgr::_GetInstance()->AllStopStreamingSound3D();
|
||||
}
|
||||
|
||||
void CAmbienceManager::RandomPlaySound()
|
||||
{
|
||||
|
||||
if( m_pCurSchedule->iRandSndCycle < 0 ) return;
|
||||
|
||||
static DWORD dwOldTime;
|
||||
static DWORD dwCurTime;
|
||||
dwCurTime = GetTickCount();
|
||||
|
||||
if( dwCurTime - dwOldTime > (DWORD) m_pCurSchedule->iRandSndCycle * 1000 )
|
||||
{
|
||||
if(m_pCurSchedule->RandomSndList.empty())
|
||||
return;
|
||||
|
||||
char* strRndSndFile = m_pCurSchedule->RandomSndList[rand()%m_pCurSchedule->RandomSndList.size()];
|
||||
char ext[_MAX_EXT];
|
||||
_splitpath( strRndSndFile, NULL, NULL, NULL, ext );
|
||||
dwOldTime = dwCurTime;
|
||||
char tempBuf[256];
|
||||
sprintf( tempBuf, "%s%s", AMBIENCEPATH, strRndSndFile );
|
||||
|
||||
if( !strcmp(ext, ".ogg") )
|
||||
{
|
||||
CStreamingSound* pStream;
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound( pStream, tempBuf );
|
||||
pStream->Play();
|
||||
pStream->SetVolume( m_fMasterVolume );
|
||||
}
|
||||
else
|
||||
{
|
||||
CSound* pSound;
|
||||
CSoundMgr::_GetInstance()->GetSound( pSound, tempBuf, 1 );
|
||||
pSound->Play();
|
||||
pSound->SetVolume( m_fMasterVolume );
|
||||
}
|
||||
}
|
||||
}
|
||||
73
Engine/Zalla3D Scene Class/AmbienceManager.h
Normal file
73
Engine/Zalla3D Scene Class/AmbienceManager.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// AmbienceManager.h: interface for the CAmbienceManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_AMBIENCEMANAGER_H__0F58FE74_1039_42DF_94B3_9CCEAC652943__INCLUDED_)
|
||||
#define AFX_AMBIENCEMANAGER_H__0F58FE74_1039_42DF_94B3_9CCEAC652943__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SectorAmbienceMap.h"
|
||||
#include "RenderTexture.h"
|
||||
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
class CD3DFont;
|
||||
class CSceneEventMgr;
|
||||
|
||||
class CAmbienceManager
|
||||
{
|
||||
friend class CSceneEventMgr;
|
||||
|
||||
protected:
|
||||
static CAmbienceManager* ms_pInstance;
|
||||
CSectorAmbienceMap* m_pSectorAmbMap;
|
||||
|
||||
bool m_bFadeIn;
|
||||
bool m_bFadeOut;
|
||||
float m_fFadeInVolume;
|
||||
float m_fFadeOutVolume;
|
||||
char m_strFadeInFileName[MAX_PATH];
|
||||
char m_strFadeOutFileName[MAX_PATH];
|
||||
char m_strOldFile[MAX_PATH];
|
||||
bool m_bAmbPlay;
|
||||
char m_strAmbPlayFile[MAX_PATH];
|
||||
float m_fAmbVolume;
|
||||
float m_fMasterVolume;
|
||||
AmbSchedule* m_pCurSchedule;
|
||||
|
||||
//TestMode
|
||||
bool m_bTestMode;
|
||||
bool m_bTestShow;
|
||||
CD3DFont* m_ptFont;
|
||||
LPDIRECT3DTEXTURE8 m_pAmbTexture;
|
||||
LPDIRECT3DTEXTURE8 m_pArrowTexture;
|
||||
LPD3DXSPRITE m_pMouseArrow;
|
||||
|
||||
protected:
|
||||
CAmbienceManager();
|
||||
virtual ~CAmbienceManager();
|
||||
void LoadTexture( SectorAmbience* );
|
||||
void GetTextureLockPos( int& outX, int& outY, D3DXVECTOR3 inPos );
|
||||
bool GetAmbienceInfo( SectorAmbience* pinInfo, D3DXVECTOR3& inPos,
|
||||
char*& outStrFile, D3DVECTOR& outPos, float& outVol, DWORD& outMode );
|
||||
void TestScreen(D3DXVECTOR3 Pos);
|
||||
void RandomPlaySound();
|
||||
|
||||
public:
|
||||
static CAmbienceManager* _GetInstance();
|
||||
static void _Destroy();
|
||||
void Create( bool bTestMode=false );
|
||||
void ReleaseAllData();
|
||||
void Update( D3DXVECTOR3& Pos, float fSkip, bool bCharSel );
|
||||
void PlayAmbience( char* strFile, D3DVECTOR vPos, float fVol, DWORD dwMode );
|
||||
void SetTestScreen( bool bShow ) { m_bTestShow = bShow; };
|
||||
CSectorAmbienceMap* GetAmbienceMap() { return m_pSectorAmbMap; };
|
||||
void AllStop();
|
||||
void SetVolume( float fVol ) { m_fMasterVolume = fVol; }
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_AMBIENCEMANAGER_H__0F58FE74_1039_42DF_94B3_9CCEAC652943__INCLUDED_)
|
||||
125
Engine/Zalla3D Scene Class/AmbienceStruct.cpp
Normal file
125
Engine/Zalla3D Scene Class/AmbienceStruct.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
|
||||
#include "AmbienceStruct.h"
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
tString::tString()
|
||||
: m_pString( NULL )
|
||||
{
|
||||
}
|
||||
|
||||
tString::tString( const char * szString )
|
||||
{
|
||||
m_pString = new char[ strlen( szString ) + 1 ];
|
||||
strcpy( m_pString, szString );
|
||||
}
|
||||
|
||||
tString::tString( const tString & rhs )
|
||||
: m_pString( NULL )
|
||||
{
|
||||
this->operator=( rhs.m_pString );
|
||||
}
|
||||
|
||||
tString::~tString()
|
||||
{
|
||||
if(m_pString) {
|
||||
delete[] m_pString;
|
||||
m_pString = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
tString & tString::operator=( const tString & rhs )
|
||||
{
|
||||
if(m_pString) {
|
||||
delete[] m_pString;
|
||||
m_pString = NULL;
|
||||
}
|
||||
if( rhs.m_pString == NULL )
|
||||
{
|
||||
m_pString = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pString = new char[ strlen( rhs.m_pString ) + 1 ];
|
||||
strcpy( m_pString, rhs.m_pString );
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
unsigned int tString::size()
|
||||
{
|
||||
if( m_pString )
|
||||
return strlen( m_pString );
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
|
||||
SSoundAsset::SSoundAsset()
|
||||
: m_eTrigger( T_IN_OUT )
|
||||
, m_iSndBufIndex( -1 )
|
||||
, m_b3DSound( true )
|
||||
, m_Name( "<EFBFBD≯<EFBFBD> <20><><EFBFBD><EFBFBD>" )
|
||||
, m_pWaveFileList( new WAVEFILELIST )
|
||||
{}
|
||||
|
||||
SSoundAsset::SSoundAsset( const SSoundAsset & rhs )
|
||||
: m_eTrigger( rhs.m_eTrigger )
|
||||
, m_iSndBufIndex( rhs.m_iSndBufIndex )
|
||||
, m_b3DSound( rhs.m_b3DSound )
|
||||
, m_Name( rhs.m_Name )
|
||||
, m_pWaveFileList( new WAVEFILELIST( *rhs.m_pWaveFileList ) )
|
||||
{
|
||||
}
|
||||
|
||||
SSoundAsset::~SSoundAsset()
|
||||
{
|
||||
if(m_pWaveFileList != NULL) {
|
||||
delete m_pWaveFileList;
|
||||
m_pWaveFileList = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
SSoundAsset & SSoundAsset::operator =( const SSoundAsset & rhs )
|
||||
{
|
||||
m_eTrigger = rhs.m_eTrigger;
|
||||
m_iSndBufIndex = rhs.m_iSndBufIndex;
|
||||
m_b3DSound = rhs.m_b3DSound;
|
||||
m_Name = rhs.m_Name;
|
||||
|
||||
if( m_pWaveFileList )
|
||||
*m_pWaveFileList = *rhs.m_pWaveFileList;
|
||||
else
|
||||
m_pWaveFileList = new WAVEFILELIST( *rhs.m_pWaveFileList );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
|
||||
SAmbience::SAmbience()
|
||||
: m_SoundAssetID( 0 )
|
||||
, m_fPosX( 0.0f )
|
||||
, m_fPosY( 0.0f )
|
||||
, m_fPosZ( 0.0f )
|
||||
, m_fMinDistance( 0.0f )
|
||||
, m_fMaxDistance( 0.0f )
|
||||
, iSoundBufferIndex( -1 )
|
||||
, lObjectSceneID( 0 )
|
||||
{}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
75
Engine/Zalla3D Scene Class/AmbienceStruct.h
Normal file
75
Engine/Zalla3D Scene Class/AmbienceStruct.h
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
#ifndef _AmbienceStruct_H_
|
||||
#define _AmbienceStruct_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "STL.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// STL<54><4C> string Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ũ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
|
||||
|
||||
class tString
|
||||
{
|
||||
char * m_pString;
|
||||
public:
|
||||
tString();
|
||||
tString( const char * );
|
||||
tString( const tString & );
|
||||
~tString();
|
||||
|
||||
tString & operator=( const tString & );
|
||||
|
||||
unsigned int size();
|
||||
const char * c_str() { return m_pString; }
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
typedef std::pair<float, tString> WAVEFILE;
|
||||
typedef std::list< WAVEFILE > WAVEFILELIST; //pair<float, string> => <20>ð<EFBFBD>, ȭ<><C8AD><EFBFBD≯<EFBFBD>
|
||||
|
||||
struct SSoundAsset
|
||||
{
|
||||
enum eTrigger {
|
||||
T_IN = 0,
|
||||
T_OUT = 1,
|
||||
T_IN_OUT = 2
|
||||
};
|
||||
|
||||
tString m_Name;
|
||||
eTrigger m_eTrigger;
|
||||
int m_iSndBufIndex;
|
||||
bool m_b3DSound;
|
||||
WAVEFILELIST * m_pWaveFileList;
|
||||
|
||||
SSoundAsset();
|
||||
SSoundAsset( const SSoundAsset & );
|
||||
~SSoundAsset();
|
||||
SSoundAsset & operator=( const SSoundAsset & );
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
struct SAmbience
|
||||
{
|
||||
int m_SoundAssetID;
|
||||
float m_fPosX;
|
||||
float m_fPosY;
|
||||
float m_fPosZ;
|
||||
float m_fMinDistance;
|
||||
float m_fMaxDistance;
|
||||
int iSoundBufferIndex;
|
||||
long lObjectSceneID;
|
||||
|
||||
SAmbience();
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
#endif
|
||||
0
Engine/Zalla3D Scene Class/BGMController.cpp
Normal file
0
Engine/Zalla3D Scene Class/BGMController.cpp
Normal file
638
Engine/Zalla3D Scene Class/BSPBaseClass.cpp
Normal file
638
Engine/Zalla3D Scene Class/BSPBaseClass.cpp
Normal file
@@ -0,0 +1,638 @@
|
||||
#include "BSPBaseClass.h"
|
||||
#include <stdio.h>
|
||||
|
||||
Poly* BSPBaseData::m_pPolygonArray;
|
||||
Node *BSPBaseData::m_pNodeArray;
|
||||
Leaf *BSPBaseData::m_pLeafArray;
|
||||
Plane *BSPBaseData::m_pPlaneArray;
|
||||
Portal **BSPBaseData::m_pPortalArray;
|
||||
BYTE *BSPBaseData::m_pPVSData;
|
||||
|
||||
long BSPBaseData::m_nPolygons;
|
||||
long BSPBaseData::m_nNodes;
|
||||
long BSPBaseData::m_nLeafs;
|
||||
long BSPBaseData::m_nPlanes;
|
||||
long BSPBaseData::m_nPortals;
|
||||
|
||||
long BSPBaseData::m_nMaxNodes;
|
||||
long BSPBaseData::m_nMaxPolygons;
|
||||
long BSPBaseData::m_nMaxPlanes;
|
||||
long BSPBaseData::m_nMaxLeafs;
|
||||
long BSPBaseData::m_nMaxPortals;
|
||||
|
||||
long BSPBaseData::m_BytePerSet;
|
||||
long BSPBaseData::m_PVSCompressedSize;
|
||||
|
||||
|
||||
BSPBaseData::BSPBaseData()
|
||||
{
|
||||
|
||||
m_pPolygonArray=NULL;
|
||||
m_pNodeArray=NULL;
|
||||
m_pLeafArray=NULL;
|
||||
m_pPlaneArray=NULL;
|
||||
m_pPortalArray=NULL;
|
||||
m_pPVSData=NULL;
|
||||
|
||||
m_nPolygons=0;
|
||||
m_nNodes=0;
|
||||
m_nLeafs=0;
|
||||
m_nPlanes=0;
|
||||
m_nPortals=0;
|
||||
|
||||
m_nMaxNodes=100;
|
||||
m_nMaxPolygons=100;
|
||||
m_nMaxPlanes=100;
|
||||
m_nMaxLeafs=100;
|
||||
m_nMaxPortals=100;
|
||||
|
||||
}
|
||||
|
||||
void BSPBaseData::Create()
|
||||
{
|
||||
m_pPolygonArray=(Poly*)malloc(m_nMaxPolygons*sizeof(Poly));
|
||||
m_pNodeArray=(Node*)malloc(m_nMaxNodes*sizeof(Node));
|
||||
m_pLeafArray=(Leaf*)malloc(m_nMaxLeafs*sizeof(Leaf));
|
||||
m_pPlaneArray=(Plane*)malloc(m_nMaxPlanes*sizeof(Plane));
|
||||
m_pPortalArray=(Portal**)malloc(m_nMaxPortals*sizeof(Portal));
|
||||
|
||||
ZeroMemory(m_pNodeArray,sizeof(Node)*m_nMaxNodes);
|
||||
ZeroMemory(m_pPolygonArray,sizeof(Poly)*m_nMaxPolygons);
|
||||
ZeroMemory(m_pLeafArray,sizeof(Leaf)*m_nMaxLeafs);
|
||||
ZeroMemory(m_pPlaneArray,sizeof(Plane)*m_nMaxPlanes);
|
||||
ZeroMemory(m_pPortalArray,sizeof(Portal)*m_nMaxPortals);
|
||||
}
|
||||
|
||||
int BSPBaseData::ClassifyPoly(Plane *pPlane, Poly *pPoly)
|
||||
{
|
||||
int Front=0;
|
||||
int Back=0;
|
||||
int OnPlane=0;
|
||||
float fResult;
|
||||
vector3 vecPoint1=pPlane->m_vecPointOnPlane;
|
||||
for(int i=0;i<pPoly->m_nVertex;i++)
|
||||
{
|
||||
vector3 vecPoint2=pPoly->m_pVertexList[i].v;
|
||||
vector3 vecDir=vecPoint1-vecPoint2;
|
||||
fResult=vecDir*pPlane->m_vecNormal;
|
||||
if(fResult>0.001f)
|
||||
{
|
||||
Back++;
|
||||
}
|
||||
else if(fResult<-0.001f)
|
||||
{
|
||||
Front++;
|
||||
}
|
||||
else
|
||||
{
|
||||
OnPlane++;
|
||||
Front++;
|
||||
Back++;
|
||||
}
|
||||
}
|
||||
if(OnPlane==pPoly->m_nVertex) return CP_ONPLANE;
|
||||
if(Back==pPoly->m_nVertex) return CP_BACK;
|
||||
if(Front==pPoly->m_nVertex) return CP_FRONT;
|
||||
return CP_SPANNING;
|
||||
}
|
||||
|
||||
void BSPBaseData::SplitPolygon(Poly *pPoly, Plane *pPlane, Poly *pFrontSplit, Poly *pBackSplit)
|
||||
{
|
||||
//LVertex FrontList[40],BackList[40],FirstVertex;
|
||||
//vector3 FrontList[40],BackList[40],FirstVertex;
|
||||
|
||||
LVertex FrontList[40],BackList[40],FirstVertex;
|
||||
vector3 vecPlaneNormal,vecIntersectionPoint,vecPointOnPlane,vecPointA,vecPointB;
|
||||
unsigned long cFront=0,cBack=0,ulCurrentVertex=0;
|
||||
float fPercent;
|
||||
|
||||
vecPointOnPlane=pPlane->m_vecPointOnPlane;
|
||||
vecPlaneNormal=pPlane->m_vecNormal;
|
||||
|
||||
FirstVertex=pPoly->m_pVertexList[0];
|
||||
switch(ClassifyPoint(&FirstVertex.v,pPlane))
|
||||
{
|
||||
case CP_FRONT:
|
||||
FrontList[cFront++]=FirstVertex;
|
||||
break;
|
||||
case CP_BACK:
|
||||
BackList[cBack++]=FirstVertex;
|
||||
break;
|
||||
case CP_ONPLANE:
|
||||
BackList[cBack++]=FirstVertex;
|
||||
FrontList[cFront++]=FirstVertex;
|
||||
break;
|
||||
}
|
||||
for(int i=1;i<pPoly->m_nVertex+1;i++)
|
||||
{
|
||||
if(i==pPoly->m_nVertex)
|
||||
ulCurrentVertex=0;
|
||||
else
|
||||
ulCurrentVertex=i;
|
||||
vecPointA=pPoly->m_pVertexList[i-1].v;
|
||||
vecPointB=pPoly->m_pVertexList[ulCurrentVertex].v;
|
||||
int Result=ClassifyPoint(&vecPointB,pPlane);
|
||||
if(Result==CP_ONPLANE)
|
||||
{
|
||||
BackList[cBack++]=pPoly->m_pVertexList[ulCurrentVertex];
|
||||
FrontList[cFront++]=pPoly->m_pVertexList[ulCurrentVertex];
|
||||
}
|
||||
else if(GetIntersect(&vecPointA,&vecPointB,&vecPointOnPlane,&vecPlaneNormal,&vecIntersectionPoint,&fPercent)==true)
|
||||
{
|
||||
LVertex vecCpy;
|
||||
vecCpy.v=vecIntersectionPoint;
|
||||
|
||||
float fDeltaU,fDeltaV,fTexU,fTexV;
|
||||
fDeltaU=pPoly->m_pVertexList[ulCurrentVertex].tu-pPoly->m_pVertexList[i-1].tu;
|
||||
fDeltaV=pPoly->m_pVertexList[ulCurrentVertex].tv-pPoly->m_pVertexList[i-1].tv;
|
||||
fTexU=pPoly->m_pVertexList[i-1].tu+(fDeltaU*fPercent);
|
||||
fTexV=pPoly->m_pVertexList[i-1].tv+(fDeltaV*fPercent);
|
||||
vecCpy.tu=fTexU;
|
||||
vecCpy.tv=fTexV;
|
||||
|
||||
if(Result==CP_FRONT)
|
||||
{
|
||||
BackList[cBack++]=vecCpy;
|
||||
FrontList[cFront++]=vecCpy;
|
||||
if(ulCurrentVertex!=0)
|
||||
{
|
||||
FrontList[cFront++]=pPoly->m_pVertexList[ulCurrentVertex];
|
||||
}
|
||||
}
|
||||
if(Result==CP_BACK)
|
||||
{
|
||||
FrontList[cFront++]=vecCpy;
|
||||
BackList[cBack++]=vecCpy;
|
||||
if(ulCurrentVertex!=0)
|
||||
{
|
||||
BackList[cBack++]=pPoly->m_pVertexList[ulCurrentVertex];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Result==CP_FRONT)
|
||||
{
|
||||
if(ulCurrentVertex!=0)
|
||||
FrontList[cFront++]=pPoly->m_pVertexList[ulCurrentVertex];
|
||||
}
|
||||
if(Result==CP_BACK)
|
||||
{
|
||||
if(ulCurrentVertex!=0)
|
||||
BackList[cBack++]=pPoly->m_pVertexList[ulCurrentVertex];
|
||||
}
|
||||
}
|
||||
}
|
||||
pFrontSplit->m_nVertex=0;
|
||||
pBackSplit->m_nVertex=0;
|
||||
|
||||
pFrontSplit->m_pVertexList=new LVertex[cFront];
|
||||
pBackSplit->m_pVertexList=new LVertex[cBack];
|
||||
for(i=0;i<(int)cFront;i++)
|
||||
{
|
||||
pFrontSplit->m_nVertex++;
|
||||
pFrontSplit->m_pVertexList[i]=FrontList[i];
|
||||
}
|
||||
for(i=0;i<(int)cBack;i++)
|
||||
{
|
||||
pBackSplit->m_nVertex++;
|
||||
pBackSplit->m_pVertexList[i]=BackList[i];
|
||||
}
|
||||
pFrontSplit->m_nIndices=(pFrontSplit->m_nVertex-2)*3;
|
||||
pBackSplit->m_nIndices=(pBackSplit->m_nVertex-2)*3;
|
||||
|
||||
pFrontSplit->m_TextureIndex=pPoly->m_TextureIndex;
|
||||
pBackSplit->m_TextureIndex=pPoly->m_TextureIndex;
|
||||
|
||||
pFrontSplit->m_pIndices=new WORD[pFrontSplit->m_nIndices];
|
||||
pBackSplit->m_pIndices=new WORD[pBackSplit->m_nIndices];
|
||||
|
||||
WORD v0,v1,v2;
|
||||
for(i=0;i<pFrontSplit->m_nIndices/3;i++)
|
||||
{
|
||||
if(i==0)
|
||||
{
|
||||
v0=0;
|
||||
v1=1;
|
||||
v2=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
v1=v2;
|
||||
v2++;
|
||||
}
|
||||
pFrontSplit->m_pIndices[i*3+0]=v0;
|
||||
pFrontSplit->m_pIndices[i*3+1]=v1;
|
||||
pFrontSplit->m_pIndices[i*3+2]=v2;
|
||||
}
|
||||
for(i=0;i<pBackSplit->m_nIndices/3;i++)
|
||||
{
|
||||
if(i==0)
|
||||
{
|
||||
v0=0;
|
||||
v1=1;
|
||||
v2=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
v1=v2;
|
||||
v2++;
|
||||
}
|
||||
pBackSplit->m_pIndices[i*3+0]=v0;
|
||||
pBackSplit->m_pIndices[i*3+1]=v1;
|
||||
pBackSplit->m_pIndices[i*3+2]=v2;
|
||||
}
|
||||
pFrontSplit->m_vecNormal=pPoly->m_vecNormal;
|
||||
pBackSplit->m_vecNormal=pPoly->m_vecNormal;
|
||||
/*
|
||||
FrontSplit->Normal=Poly->Normal;
|
||||
BackSplit->Normal=Poly->Normal;
|
||||
*/
|
||||
}
|
||||
|
||||
BSPBaseData::ClassifyPoint(vector3 *vecPoint, Plane *pPlane)
|
||||
{
|
||||
float fResult;
|
||||
vector3 vecPointOnPlane=pPlane->m_vecPointOnPlane;
|
||||
vector3 vecDir=vecPointOnPlane-*vecPoint;
|
||||
fResult=vecDir*pPlane->m_vecNormal;
|
||||
if(fResult<-0.001f)
|
||||
return CP_FRONT;
|
||||
if(fResult>0.001f)
|
||||
return CP_BACK;
|
||||
return CP_ONPLANE;
|
||||
}
|
||||
|
||||
bool BSPBaseData::GetIntersect(vector3 *vecLineStart, vector3 *vecLineEnd, vector3 *pVertex, vector3 *vecNormal, vector3 *vecIntersection, float *fPercentage)
|
||||
{
|
||||
vector3 vecDirection,vecL1;
|
||||
float fLineLength,fDistFromPlane;
|
||||
vecDirection=*vecLineEnd-*vecLineStart;
|
||||
fLineLength=vecDirection*(*vecNormal);
|
||||
if(fabsf(fLineLength)<0.0001f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
vecL1=*pVertex-*vecLineStart;
|
||||
fDistFromPlane=vecL1*(*vecNormal);
|
||||
*fPercentage=fDistFromPlane/fLineLength;
|
||||
if(*fPercentage<0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(*fPercentage>1.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
*vecIntersection=*vecLineStart+vecDirection*(*fPercentage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BSPBaseData::CalculateBox(BoundingBox *pBox,Poly *pPolyList)
|
||||
{
|
||||
Poly *pPoly=pPolyList;
|
||||
while(pPoly!=NULL)
|
||||
{
|
||||
for(int i=0;i<pPoly->m_nVertex;i++)
|
||||
{
|
||||
if(pPoly->m_pVertexList[i].v.x<pBox->m_vecBoxMin.x)
|
||||
pBox->m_vecBoxMin.x=pPoly->m_pVertexList[i].v.x;
|
||||
if(pPoly->m_pVertexList[i].v.y<pBox->m_vecBoxMin.y)
|
||||
pBox->m_vecBoxMin.y=pPoly->m_pVertexList[i].v.y;
|
||||
if(pPoly->m_pVertexList[i].v.z<pBox->m_vecBoxMin.z)
|
||||
pBox->m_vecBoxMin.z=pPoly->m_pVertexList[i].v.z;
|
||||
|
||||
if(pPoly->m_pVertexList[i].v.x>pBox->m_vecBoxMax.x)
|
||||
pBox->m_vecBoxMax.x=pPoly->m_pVertexList[i].v.x;
|
||||
if(pPoly->m_pVertexList[i].v.y>pBox->m_vecBoxMax.y)
|
||||
pBox->m_vecBoxMax.y=pPoly->m_pVertexList[i].v.y;
|
||||
if(pPoly->m_pVertexList[i].v.z>pBox->m_vecBoxMax.z)
|
||||
pBox->m_vecBoxMax.z=pPoly->m_pVertexList[i].v.z;
|
||||
}
|
||||
pPoly=pPoly->m_pNext;
|
||||
}
|
||||
}
|
||||
|
||||
void BSPBaseData::DeletePolygon(Poly *pPoly)
|
||||
{
|
||||
delete [] pPoly->m_pVertexList;
|
||||
delete [] pPoly->m_pIndices;
|
||||
delete pPoly;
|
||||
}
|
||||
|
||||
void BSPBaseData::IncreaseNumberOfNodes()
|
||||
{
|
||||
m_nNodes++;
|
||||
if(m_nNodes==m_nMaxNodes)
|
||||
{
|
||||
m_nMaxNodes+=100;
|
||||
m_pNodeArray=(Node*)realloc(m_pNodeArray,m_nMaxNodes*sizeof(Node));
|
||||
}
|
||||
}
|
||||
|
||||
void BSPBaseData::IncreaseNumberOfPolygons()
|
||||
{
|
||||
m_nPolygons++;
|
||||
if(m_nPolygons==m_nMaxPolygons)
|
||||
{
|
||||
m_nMaxPolygons+=100;
|
||||
m_pPolygonArray=(Poly*)realloc(m_pPolygonArray,m_nMaxPolygons*sizeof(Poly));
|
||||
}
|
||||
}
|
||||
|
||||
void BSPBaseData::IncreaseNumberOfPlanes()
|
||||
{
|
||||
m_nPlanes++;
|
||||
if(m_nPlanes==m_nMaxPlanes)
|
||||
{
|
||||
m_nMaxPlanes+=100;
|
||||
m_pPlaneArray=(Plane*)realloc(m_pPlaneArray,m_nMaxPlanes*sizeof(Plane));
|
||||
}
|
||||
}
|
||||
|
||||
void BSPBaseData::IncreaseNumberOfLeafs()
|
||||
{
|
||||
m_nLeafs++;
|
||||
if(m_nLeafs==m_nMaxLeafs)
|
||||
{
|
||||
m_nMaxLeafs+=100;
|
||||
m_pLeafArray=(Leaf*)realloc(m_pLeafArray,m_nMaxLeafs*sizeof(Leaf));
|
||||
}
|
||||
}
|
||||
|
||||
void BSPBaseData::IncreaseNumberOfPortals()
|
||||
{
|
||||
m_nPortals++;
|
||||
if(m_nPortals==m_nMaxPortals)
|
||||
{
|
||||
m_nMaxPortals+=100;
|
||||
m_pPortalArray=(Portal**)realloc(m_pPortalArray,m_nMaxPortals*sizeof(Portal*));
|
||||
}
|
||||
}
|
||||
|
||||
void BSPBaseData::DeletePortal(Portal *pPortal)
|
||||
{
|
||||
/*
|
||||
delete []Portal->VertexList;
|
||||
delete []Portal->Indices;
|
||||
delete Portal;
|
||||
*/
|
||||
delete [] pPortal->m_pVertexList;
|
||||
delete [] pPortal->m_pIndices;
|
||||
delete pPortal;
|
||||
}
|
||||
|
||||
Poly* BSPBaseData::LoadMWM(char *strFilename)
|
||||
{
|
||||
FILE *fp;
|
||||
Poly *pRoot=NULL;
|
||||
Poly *pChild=NULL;
|
||||
WORD cPoly,nVertex;
|
||||
int i,b;
|
||||
LVertex xyzBuffer[50];
|
||||
WORD TextureIndex;
|
||||
DWORD uselessinfo;
|
||||
fp=fopen(strFilename,"rb");
|
||||
fread(&cPoly,sizeof(WORD),1,fp);
|
||||
|
||||
for(i=0;i<cPoly;i++)
|
||||
{
|
||||
fread(&nVertex,sizeof(WORD),1,fp);
|
||||
for(b=0;b<nVertex;b++)
|
||||
{
|
||||
fread(&xyzBuffer[b].v.x,sizeof(float),1,fp);
|
||||
fread(&xyzBuffer[b].v.y,sizeof(float),1,fp);
|
||||
fread(&xyzBuffer[b].v.z,sizeof(float),1,fp);
|
||||
fread(&uselessinfo,sizeof(DWORD),1,fp);
|
||||
fread(&xyzBuffer[b].diff.c,sizeof(DWORD),1,fp);
|
||||
fread(&xyzBuffer[b].spec.c,sizeof(DWORD),1,fp);
|
||||
fread(&xyzBuffer[b].tu,sizeof(float),1,fp);
|
||||
fread(&xyzBuffer[b].tv,sizeof(float),1,fp);
|
||||
}
|
||||
fread(&TextureIndex,sizeof(WORD),1,fp);
|
||||
if(i==0)
|
||||
{
|
||||
pRoot=AddPolygon(NULL,&xyzBuffer[0],nVertex);
|
||||
pRoot->m_TextureIndex=TextureIndex;
|
||||
pChild=pRoot;
|
||||
}
|
||||
else
|
||||
{
|
||||
pChild=AddPolygon(pChild,&xyzBuffer[0],nVertex);
|
||||
pChild->m_TextureIndex=TextureIndex;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return pRoot;
|
||||
}
|
||||
|
||||
Poly* BSPBaseData::AddPolygon(Poly *pParent, LVertex *Vertices, WORD nVertex)
|
||||
{
|
||||
Poly *pChild=new Poly;
|
||||
pChild->m_nVertex=nVertex;
|
||||
pChild->m_nIndices=(nVertex-2)*3;
|
||||
pChild->m_pNext=NULL;
|
||||
pChild->m_bBeenUsedAsSplitter=false;
|
||||
|
||||
pChild->m_pVertexList=new LVertex[pChild->m_nVertex];
|
||||
pChild->m_pIndices=new WORD[pChild->m_nIndices];
|
||||
|
||||
for(int i=0;i<nVertex;i++)
|
||||
{
|
||||
pChild->m_pVertexList[i]=Vertices[i];
|
||||
}
|
||||
|
||||
WORD v0,v1,v2;
|
||||
for(i=0;i<pChild->m_nIndices/3;i++)
|
||||
{
|
||||
if(i==0)
|
||||
{
|
||||
v0=0;
|
||||
v1=1;
|
||||
v2=2;
|
||||
}
|
||||
else
|
||||
{
|
||||
v1=v2;
|
||||
v2++;
|
||||
}
|
||||
pChild->m_pIndices[i*3+0]=v0;
|
||||
pChild->m_pIndices[i*3+1]=v1;
|
||||
pChild->m_pIndices[i*3+2]=v2;
|
||||
}
|
||||
vector3 vec0=pChild->m_pVertexList[0].v;
|
||||
vector3 vec1=pChild->m_pVertexList[1].v;
|
||||
vector3 vec2=pChild->m_pVertexList[pChild->m_nVertex-1].v;
|
||||
vector3 vecNormal=(vec1-vec0)^(vec2-vec0);
|
||||
vecNormal.Normalize();
|
||||
pChild->m_vecNormal=vecNormal;
|
||||
|
||||
if(pParent!=NULL)
|
||||
{
|
||||
pParent->m_pNext=pChild;
|
||||
}
|
||||
return pChild;
|
||||
/*
|
||||
|
||||
// generate polygon normal
|
||||
D3DXVECTOR3 * vec0=(D3DXVECTOR3 *) &Child->VertexList[0];
|
||||
D3DXVECTOR3 * vec1=(D3DXVECTOR3 *) &Child->VertexList[1];
|
||||
D3DXVECTOR3 * vec2=(D3DXVECTOR3 *) &Child->VertexList[Child->NumberOfVertices-1];// the last vert
|
||||
|
||||
|
||||
D3DXVECTOR3 edge1=(*vec1)-(*vec0);
|
||||
D3DXVECTOR3 edge2=(*vec2)-(*vec0);
|
||||
D3DXVec3Cross(&Child->Normal,&edge1,&edge2);
|
||||
D3DXVec3Normalize(&Child->Normal,&Child->Normal);
|
||||
|
||||
|
||||
if (Parent!=NULL)
|
||||
{
|
||||
Parent->Next=Child;
|
||||
}
|
||||
|
||||
return Child;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void BSPBaseData::CopyBspData(BSPBaseData *pData)
|
||||
{
|
||||
m_nMaxPolygons=pData->m_nMaxPolygons;
|
||||
m_nMaxNodes=pData->m_nMaxNodes;
|
||||
m_nMaxLeafs=pData->m_nMaxLeafs;
|
||||
m_nMaxPlanes=pData->m_nMaxPlanes;
|
||||
m_nMaxPortals=pData->m_nMaxPortals;
|
||||
|
||||
m_nPolygons=pData->m_nPolygons;
|
||||
m_nNodes=pData->m_nNodes;
|
||||
m_nLeafs=pData->m_nLeafs;
|
||||
m_nPlanes=pData->m_nPlanes;
|
||||
m_nPortals=pData->m_nPortals;
|
||||
|
||||
m_pPolygonArray=(Poly*)malloc(m_nMaxPolygons*sizeof(Poly));
|
||||
m_pNodeArray=(Node*)malloc(m_nMaxNodes*sizeof(Node));
|
||||
m_pLeafArray=(Leaf*)malloc(m_nMaxLeafs*sizeof(Leaf));
|
||||
m_pPlaneArray=(Plane*)malloc(m_nMaxPlanes*sizeof(Plane));
|
||||
m_pPortalArray=(Portal**)malloc(m_nMaxPortals*sizeof(Portal));
|
||||
|
||||
memcpy(m_pPolygonArray,pData->m_pPolygonArray,sizeof(Poly)*m_nMaxPolygons);
|
||||
memcpy(m_pNodeArray,pData->m_pNodeArray,sizeof(Node)*m_nMaxNodes);
|
||||
memcpy(m_pLeafArray,pData->m_pLeafArray,sizeof(Leaf)*m_nMaxLeafs);
|
||||
memcpy(m_pPlaneArray,pData->m_pPlaneArray,sizeof(Plane)*m_nMaxPlanes);
|
||||
memcpy(m_pPortalArray,pData->m_pPortalArray,sizeof(Portal)*m_nMaxPortals);
|
||||
}
|
||||
|
||||
void BSPBaseData::SplitPortal(Portal *pPortal, Plane *pPlane, Portal *pFrontSplit, Portal *pBackSplit)
|
||||
{
|
||||
SplitPolygon((Poly*)pPortal,pPlane,(Poly*)pFrontSplit,(Poly*)pBackSplit);
|
||||
pFrontSplit->m_nLeafs=pPortal->m_nLeafs;
|
||||
pBackSplit->m_nLeafs=pPortal->m_nLeafs;
|
||||
|
||||
memcpy(pFrontSplit->m_LeafOwnerArray,pPortal->m_LeafOwnerArray,sizeof(long)*pPortal->m_nLeafs);
|
||||
memcpy(pBackSplit->m_LeafOwnerArray,pPortal->m_LeafOwnerArray,sizeof(long)*pPortal->m_nLeafs);
|
||||
}
|
||||
|
||||
void BSPBaseData::Save(char *strFilename,List<CQShader*> &ShaderList)
|
||||
{
|
||||
FILE *fp=fopen(strFilename,"wb");
|
||||
|
||||
fwrite(&ShaderList.num,sizeof(int),1,fp);
|
||||
for(int i=0;i<ShaderList.num;i++)
|
||||
{
|
||||
fwrite(ShaderList[i]->GetTextureName(),sizeof(char)*256,1,fp);
|
||||
}
|
||||
|
||||
m_nNodes++;
|
||||
fwrite(&m_nNodes,sizeof(long),1,fp);
|
||||
|
||||
for(i=0;i<m_nNodes;i++)
|
||||
{
|
||||
fwrite(&m_pNodeArray[i].m_bLeaf,sizeof(unsigned char),1,fp);
|
||||
fwrite(&m_pNodeArray[i].m_Plane,sizeof(unsigned long),1,fp);
|
||||
fwrite(&m_pNodeArray[i].m_Front,sizeof(unsigned long),1,fp);
|
||||
fwrite(&m_pNodeArray[i].m_Back,sizeof(unsigned long),1,fp);
|
||||
}
|
||||
|
||||
fwrite(&m_nPlanes,sizeof(long),1,fp);
|
||||
fwrite(m_pPlaneArray,sizeof(Plane),m_nPlanes,fp);
|
||||
|
||||
fwrite(&m_nLeafs,sizeof(long),1,fp);
|
||||
for(i=0;i<m_nLeafs;i++)
|
||||
{
|
||||
fwrite(&m_pLeafArray[i].m_StartPolygon,sizeof(long),1,fp);
|
||||
fwrite(&m_pLeafArray[i].m_EndPolygon,sizeof(long),1,fp);
|
||||
fwrite(&m_pLeafArray[i].m_PVSIndex,sizeof(long),1,fp);
|
||||
fwrite(&m_pLeafArray[i].m_BoundingBox,sizeof(BoundingBox),1,fp);
|
||||
}
|
||||
|
||||
fwrite(&m_nPolygons,sizeof(long),1,fp);
|
||||
|
||||
for(i=0;i<m_nPolygons;i++)
|
||||
{
|
||||
fwrite(&m_pPolygonArray[i].m_nVertex,sizeof(WORD),1,fp);
|
||||
fwrite(m_pPolygonArray[i].m_pVertexList,sizeof(LVertex),m_pPolygonArray[i].m_nVertex,fp);
|
||||
fwrite(&m_pPolygonArray[i].m_nIndices,sizeof(WORD),1,fp);
|
||||
fwrite(m_pPolygonArray[i].m_pIndices,sizeof(WORD),m_pPolygonArray[i].m_nIndices,fp);
|
||||
fwrite(&m_pPolygonArray[i].m_vecNormal,sizeof(vector3),1,fp);
|
||||
m_pPolygonArray[i].m_TextureIndex=0;
|
||||
fwrite(&m_pPolygonArray[i].m_TextureIndex,sizeof(DWORD),1,fp);
|
||||
}
|
||||
fwrite(&m_PVSCompressedSize,sizeof(long),1,fp);
|
||||
fwrite(m_pPVSData,sizeof(BYTE),m_PVSCompressedSize,fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void BSPBaseData::Load(char *strFilename)
|
||||
{
|
||||
FILE *fp=fopen(strFilename,"rb");
|
||||
|
||||
fread(&m_nNodes,sizeof(long),1,fp);
|
||||
m_pNodeArray=(Node*)malloc(m_nNodes*sizeof(Node));
|
||||
for(int i=0;i<m_nNodes;i++)
|
||||
{
|
||||
fread(&m_pNodeArray[i].m_bLeaf,sizeof(unsigned char),1,fp);
|
||||
fread(&m_pNodeArray[i].m_Plane,sizeof(unsigned long),1,fp);
|
||||
fread(&m_pNodeArray[i].m_Front,sizeof(unsigned long),1,fp);
|
||||
fread(&m_pNodeArray[i].m_Back,sizeof(unsigned long),1,fp);
|
||||
}
|
||||
fread(&m_nPlanes,sizeof(long),1,fp);
|
||||
m_pPlaneArray=(Plane*)malloc(m_nPlanes*sizeof(Plane));
|
||||
fread(m_pPlaneArray,sizeof(Plane),m_nPlanes,fp);
|
||||
|
||||
fread(&m_nLeafs,sizeof(long),1,fp);
|
||||
m_pLeafArray=(Leaf*)malloc(m_nLeafs*sizeof(Leaf));
|
||||
|
||||
for(i=0;i<m_nLeafs;i++)
|
||||
{
|
||||
fread(&m_pLeafArray[i].m_StartPolygon,sizeof(long),1,fp);
|
||||
fread(&m_pLeafArray[i].m_EndPolygon,sizeof(long),1,fp);
|
||||
fread(&m_pLeafArray[i].m_PVSIndex,sizeof(long),1,fp);
|
||||
fread(&m_pLeafArray[i].m_BoundingBox,sizeof(BoundingBox),1,fp);
|
||||
}
|
||||
|
||||
fread(&m_nPolygons,sizeof(long),1,fp);
|
||||
m_pPolygonArray=(Poly*)malloc(m_nPolygons*sizeof(Poly));
|
||||
for(i=0;i<m_nPolygons;i++)
|
||||
{
|
||||
fread(&m_pPolygonArray[i].m_nVertex,sizeof(WORD),1,fp);
|
||||
m_pPolygonArray[i].m_pVertexList=new LVertex[m_pPolygonArray[i].m_nVertex];
|
||||
fread(m_pPolygonArray[i].m_pVertexList,sizeof(LVertex),m_pPolygonArray[i].m_nVertex,fp);
|
||||
fread(&m_pPolygonArray[i].m_nIndices,sizeof(WORD),1,fp);
|
||||
m_pPolygonArray[i].m_pIndices=new WORD[m_pPolygonArray[i].m_nIndices];
|
||||
fread(m_pPolygonArray[i].m_pIndices,sizeof(WORD),m_pPolygonArray[i].m_nIndices,fp);
|
||||
fread(&m_pPolygonArray[i].m_vecNormal,sizeof(vector3),1,fp);
|
||||
fread(&m_pPolygonArray[i].m_TextureIndex,sizeof(DWORD),1,fp);
|
||||
}
|
||||
fread(&m_PVSCompressedSize,sizeof(long),1,fp);
|
||||
m_pPVSData=(BYTE*)malloc(m_PVSCompressedSize*sizeof(BYTE));
|
||||
fread(m_pPVSData,sizeof(BYTE),m_PVSCompressedSize,fp);
|
||||
fclose(fp);
|
||||
}
|
||||
131
Engine/Zalla3D Scene Class/BSPBaseClass.h
Normal file
131
Engine/Zalla3D Scene Class/BSPBaseClass.h
Normal file
@@ -0,0 +1,131 @@
|
||||
#ifndef BSPBASECLASS_H
|
||||
#define BSPBASECLASS_H
|
||||
#pragma once
|
||||
|
||||
#include "3DMath.h"
|
||||
#include "Vertex.h"
|
||||
#include "List.h"
|
||||
#include "QShader.h"
|
||||
class Plane
|
||||
{
|
||||
public:
|
||||
vector3 m_vecPointOnPlane;
|
||||
vector3 m_vecNormal;
|
||||
};
|
||||
|
||||
class Poly
|
||||
{
|
||||
public:
|
||||
LVertex *m_pVertexList;
|
||||
vector3 m_vecNormal;
|
||||
WORD m_nVertex;
|
||||
WORD m_nIndices;
|
||||
WORD *m_pIndices;
|
||||
bool m_bBeenUsedAsSplitter;
|
||||
DWORD m_TextureIndex;
|
||||
|
||||
Poly *m_pNext;
|
||||
};
|
||||
|
||||
class Portal
|
||||
{
|
||||
public:
|
||||
LVertex *m_pVertexList;
|
||||
vector3 m_vecNormal;
|
||||
WORD m_nVertex;
|
||||
WORD m_nIndices;
|
||||
WORD *m_pIndices;
|
||||
BYTE m_nLeafs;
|
||||
long m_LeafOwnerArray[4];
|
||||
Portal *m_pPrev;
|
||||
Portal *m_pNext;
|
||||
};
|
||||
|
||||
class BoundingBox
|
||||
{
|
||||
public:
|
||||
vector3 m_vecBoxMin;
|
||||
vector3 m_vecBoxMax;
|
||||
};
|
||||
|
||||
class Leaf
|
||||
{
|
||||
public:
|
||||
long m_StartPolygon;
|
||||
long m_EndPolygon;
|
||||
long m_PortalIndexList[50];
|
||||
long m_nPortals;
|
||||
long m_PVSIndex;
|
||||
BoundingBox m_BoundingBox;
|
||||
};
|
||||
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
unsigned char m_bLeaf;
|
||||
unsigned long m_Plane;
|
||||
unsigned long m_Front;
|
||||
signed long m_Back;
|
||||
BoundingBox m_BoundingBox;
|
||||
};
|
||||
|
||||
class ClipPlane
|
||||
{
|
||||
public:
|
||||
WORD m_nPlane;
|
||||
Plane *m_pPlane;
|
||||
};
|
||||
|
||||
const int CP_FRONT=1001;
|
||||
const int CP_BACK =1002;
|
||||
const int CP_ONPLANE=1003;
|
||||
const int CP_SPANNING=1004;
|
||||
|
||||
|
||||
class BSPBaseData
|
||||
{
|
||||
public:
|
||||
void Load(char *strFilename);
|
||||
void Save(char *strFilename,List<CQShader*> &ShaderList);
|
||||
void SplitPortal(Portal *pPortal, Plane *pPlane, Portal *pFrontSplit, Portal *pBackSplit);
|
||||
void CopyBspData(BSPBaseData *pData);
|
||||
static Poly* AddPolygon(Poly* pParent,LVertex *Vertices,WORD nVertex);
|
||||
static Poly* LoadMWM(char *strFilename);
|
||||
void DeletePortal(Portal *pPortal);
|
||||
void IncreaseNumberOfPortals();
|
||||
void IncreaseNumberOfLeafs();
|
||||
void IncreaseNumberOfPlanes();
|
||||
void IncreaseNumberOfPolygons();
|
||||
void IncreaseNumberOfNodes();
|
||||
void DeletePolygon(Poly *pPoly);
|
||||
void CalculateBox(BoundingBox *pBox,Poly *pPolyList);
|
||||
bool GetIntersect (vector3 *vecLineStart,vector3 *vecLineEnd,vector3 *pVertex,vector3 *vecNormal,vector3 *vecIntersection,float *fPercentage);
|
||||
ClassifyPoint(vector3 *vecPoint,Plane *pPlane);
|
||||
void SplitPolygon(Poly *pPoly, Plane *pPlane, Poly *pFrontSplit, Poly *pBackSplit);
|
||||
static int ClassifyPoly(Plane *pPlane,Poly *pPoly);
|
||||
static void Create();
|
||||
BSPBaseData();
|
||||
static Node *m_pNodeArray;
|
||||
static Poly *m_pPolygonArray;
|
||||
static Leaf *m_pLeafArray;
|
||||
static Plane *m_pPlaneArray;
|
||||
static Portal **m_pPortalArray;
|
||||
static BYTE *m_pPVSData;
|
||||
static long m_nPolygons;
|
||||
static long m_nNodes;
|
||||
static long m_nLeafs;
|
||||
static long m_nPlanes;
|
||||
static long m_nPortals;
|
||||
|
||||
static long m_nMaxNodes;
|
||||
static long m_nMaxPolygons;
|
||||
static long m_nMaxPlanes;
|
||||
static long m_nMaxLeafs;
|
||||
static long m_nMaxPortals;
|
||||
|
||||
//static BYTE *m_pPVSData;
|
||||
static long m_BytePerSet;
|
||||
static long m_PVSCompressedSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
122
Engine/Zalla3D Scene Class/BSPBaseDataDefine.h
Normal file
122
Engine/Zalla3D Scene Class/BSPBaseDataDefine.h
Normal file
@@ -0,0 +1,122 @@
|
||||
#include "3DMath.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
#define LUMP_ENTITIES 0
|
||||
#define LUMP_SHADERS 1
|
||||
#define LUMP_PLANES 2
|
||||
#define LUMP_NODES 3
|
||||
#define LUMP_LEAFS 4
|
||||
#define LUMP_LEAFSURFACES 5
|
||||
#define LUMP_LEAFBRUSHES 6
|
||||
#define LUMP_MODELS 7
|
||||
#define LUMP_BRUSHES 8
|
||||
#define LUMP_BRUSHSIDES 9
|
||||
#define LUMP_DRAWVERTS 10
|
||||
#define LUMP_DRAWINDEXES 11
|
||||
#define LUMP_FOGS 12
|
||||
#define LUMP_SURFACES 13
|
||||
#define LUMP_LIGHTMAPS 14
|
||||
#define LUMP_LIGHTGRID 15
|
||||
#define LUMP_VISIBILITY 16
|
||||
#define HEADER_LUMPS 17
|
||||
|
||||
class Lump
|
||||
{
|
||||
public:
|
||||
int m_Fileofs;
|
||||
int m_Filelen;
|
||||
};
|
||||
|
||||
class DHeader
|
||||
{
|
||||
public:
|
||||
int m_Ident;
|
||||
int m_Version;
|
||||
Lump m_Lump[HEADER_LUMPS];
|
||||
};
|
||||
|
||||
typedef int BBoxT[6];
|
||||
typedef float BBoxFT[6];
|
||||
typedef float TexCoordT[2];
|
||||
typedef float vec4T[4];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Plane;
|
||||
int Children[2];
|
||||
int Min[3];
|
||||
int Max[3];
|
||||
}NodeT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
vector3 vec;
|
||||
float fOffset;
|
||||
}PlaneT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Cluster;
|
||||
int Area;
|
||||
int Min[3];
|
||||
int Max[3];
|
||||
int FirstFace,nFaces;
|
||||
int FirstUnknown,nUnknowns;
|
||||
}LeafT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Shader;
|
||||
int Unknown1[1];
|
||||
int FaceType;
|
||||
int FirstVert,nVerts;
|
||||
int FirstElem,nElems;
|
||||
// Lightmap Info//
|
||||
int LM_TextureNum;
|
||||
int LM_Offset[2];
|
||||
int LM_Size[2];
|
||||
vector3 vecOrig;
|
||||
BBoxFT BBox;
|
||||
vector3 vecNormal;
|
||||
int MeshCP[2];
|
||||
}SurfaceT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int Shader;
|
||||
int Unknown1[1];
|
||||
int FaceType;
|
||||
int FirstVert,nVerts;
|
||||
int FirstElem,nElems;
|
||||
// Lightmap Info//
|
||||
int LM_TextureNum;
|
||||
int LM_Offset[2];
|
||||
int LM_Size[2];
|
||||
vector3 vecOrig;
|
||||
BBoxFT BBox;
|
||||
vector3 vecNormal;
|
||||
int MeshCP[2];
|
||||
MultiVertex *pVertex;
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pIndicesBuffer;
|
||||
WORD *pIndices;
|
||||
}DrawSurface;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int nClusters;
|
||||
int RowSize;
|
||||
BYTE data[1];
|
||||
}VisiblityT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int *nSurfaces[100];
|
||||
int **pDrawSurfaces[100];
|
||||
}DrawSurfaceListT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char m_strTexture[256];
|
||||
}DShader;
|
||||
157
Engine/Zalla3D Scene Class/BaseCloth.cpp
Normal file
157
Engine/Zalla3D Scene Class/BaseCloth.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
#include ".\basecloth.h"
|
||||
#include "dxutil.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
CBaseCloth::CBaseCloth( const CClothProperty* pProp ) : m_pParticles(NULL), m_pSprings(NULL)
|
||||
{
|
||||
m_Prop = *pProp;
|
||||
|
||||
int r, c;
|
||||
float f;
|
||||
D3DXVECTOR3 vL;
|
||||
int count = 0;
|
||||
m_iNumVertex = (m_Prop.m_iRow+1)*(m_Prop.m_iCol+1);
|
||||
m_iNumFace = m_Prop.m_iRow*m_Prop.m_iCol*2;
|
||||
m_iNumSpring = m_Prop.m_iCol*(m_Prop.m_iRow+1) + m_Prop.m_iRow*(m_Prop.m_iCol+1) + m_Prop.m_iCol*m_Prop.m_iRow*2;
|
||||
float fMassPerFace = m_Prop.m_fMass / (float)(m_Prop.m_iCol*m_Prop.m_iRow*2);
|
||||
m_fCStep = (float)m_Prop.m_iWidth / (float)m_Prop.m_iCol;
|
||||
m_fRStep = (float)m_Prop.m_iHeight / (float)m_Prop.m_iRow;
|
||||
|
||||
m_pParticles = new Particle[m_iNumVertex];
|
||||
m_pSprings = new Spring[m_iNumSpring];
|
||||
|
||||
float fBottomLine;
|
||||
D3DXVECTOR3 vLeftTop, vLeftBottom, vRightTop, vRightBottom, vOutLerpPoint, vNewLeftTop,
|
||||
vNewLeftBottom, vNewRightTop, vNewRightBottom;
|
||||
|
||||
if( pProp->m_FormType == CFT_TRAPEZOID )
|
||||
{
|
||||
fBottomLine = (float)m_Prop.m_iWidth*(float)2.5f;
|
||||
vLeftTop = D3DXVECTOR3( -(float)m_Prop.m_iWidth/2, (float)m_Prop.m_iHeight/2, 0.0f );
|
||||
vLeftBottom = D3DXVECTOR3( -fBottomLine/2, -(float)m_Prop.m_iHeight/2, 0.0f );
|
||||
vRightTop = D3DXVECTOR3( (float)m_Prop.m_iWidth/2, (float)m_Prop.m_iHeight/2, 0.0f );
|
||||
vRightBottom = D3DXVECTOR3( fBottomLine/2, -(float)m_Prop.m_iHeight/2, 0.0f );
|
||||
vOutLerpPoint, vNewLeftTop, vNewLeftBottom, vNewRightTop, vNewRightBottom;
|
||||
}
|
||||
|
||||
for( r = 0; r <= m_Prop.m_iRow; r++ )
|
||||
{
|
||||
for( c = 0; c <= m_Prop.m_iCol; c++ )
|
||||
{
|
||||
if((r == 0) && (c == 0))
|
||||
f = 1;
|
||||
else if((r == m_Prop.m_iRow) && (c == 0))
|
||||
f = 2;
|
||||
else if((r == 0) && (c == m_Prop.m_iCol))
|
||||
f = 2;
|
||||
else if((r == m_Prop.m_iRow) && (c == m_Prop.m_iCol))
|
||||
f = 1;
|
||||
else if(((r == 0) || (r == m_Prop.m_iRow)) && ((c != 0) && (c != m_Prop.m_iCol)))
|
||||
f = 3;
|
||||
else
|
||||
f = 6;
|
||||
|
||||
m_pParticles[ROWCOL(r,c)].fMass = (f * fMassPerFace) / 3;
|
||||
m_pParticles[ROWCOL(r,c)].fInvMass = 1 / m_pParticles[ROWCOL(r,c)].fMass;
|
||||
m_pParticles[ROWCOL(r,c)].vVel = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_pParticles[ROWCOL(r,c)].vAccel = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_pParticles[ROWCOL(r,c)].vForce = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_pParticles[ROWCOL(r,c)].bLocked = false;
|
||||
m_pParticles[ROWCOL(r,c)].RC.r = r;
|
||||
m_pParticles[ROWCOL(r,c)].RC.c = c;
|
||||
|
||||
if( pProp->m_FormType == CFT_TRAPEZOID )
|
||||
{
|
||||
D3DXVec3Lerp( &vNewLeftTop, &vLeftTop, &vLeftBottom, r ? ((float)r/(float)m_Prop.m_iRow) : 0 );
|
||||
D3DXVec3Lerp( &vNewRightTop, &vRightTop, &vRightBottom, r ? ((float)r/(float)m_Prop.m_iRow) : 0 );
|
||||
D3DXVec3Lerp( &vOutLerpPoint, &vNewLeftTop, &vNewRightTop, c ? ((float)c/(float)m_Prop.m_iCol) : 0 );
|
||||
m_pParticles[ROWCOL(r,c)].vPos = vOutLerpPoint;
|
||||
}
|
||||
else if( pProp->m_FormType == CFT_QUAD )
|
||||
{
|
||||
m_pParticles[ROWCOL(r,c)].vPos.x = c * m_fCStep - (float)m_Prop.m_iWidth/2.0f;
|
||||
m_pParticles[ROWCOL(r,c)].vPos.y = (m_Prop.m_iHeight - (r * m_fRStep)) - (float)m_Prop.m_iHeight/2.0f;
|
||||
m_pParticles[ROWCOL(r,c)].vPos.z = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( r = 0; r <= m_Prop.m_iRow; r++ )
|
||||
{
|
||||
for( c = 0; c <= m_Prop.m_iCol; c++ )
|
||||
{
|
||||
if(c<m_Prop.m_iCol)
|
||||
{
|
||||
m_pSprings[count].p1.r = r;
|
||||
m_pSprings[count].p1.c = c;
|
||||
m_pSprings[count].p2.r = r;
|
||||
m_pSprings[count].p2.c = c+1;
|
||||
m_pSprings[count].k = m_Prop.m_fSpringTensionConstant;
|
||||
m_pSprings[count].d = m_Prop.m_fSpringDampingConstant;
|
||||
vL = m_pParticles[ROWCOL(r,c)].vPos - m_pParticles[ROWCOL(r,c+1)].vPos;
|
||||
m_pSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
if(r<m_Prop.m_iRow)
|
||||
{
|
||||
m_pSprings[count].p1.r = r;
|
||||
m_pSprings[count].p1.c = c;
|
||||
m_pSprings[count].p2.r = r+1;
|
||||
m_pSprings[count].p2.c = c;
|
||||
m_pSprings[count].k = m_Prop.m_fSpringTensionConstant;
|
||||
m_pSprings[count].d = m_Prop.m_fSpringDampingConstant;
|
||||
vL = m_pParticles[ROWCOL(r,c)].vPos - m_pParticles[ROWCOL(r+1,c)].vPos;
|
||||
m_pSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
if(r<m_Prop.m_iRow && c<m_Prop.m_iCol)
|
||||
{
|
||||
m_pSprings[count].p1.r = r;
|
||||
m_pSprings[count].p1.c = c;
|
||||
m_pSprings[count].p2.r = r+1;
|
||||
m_pSprings[count].p2.c = c+1;
|
||||
m_pSprings[count].k = m_Prop.m_fSpringShearConstant;
|
||||
m_pSprings[count].d = m_Prop.m_fSpringDampingConstant;
|
||||
vL = m_pParticles[ROWCOL(r,c)].vPos - m_pParticles[ROWCOL(r+1,c+1)].vPos;
|
||||
m_pSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
if(c>0 && r<m_Prop.m_iRow)
|
||||
{
|
||||
m_pSprings[count].p1.r = r;
|
||||
m_pSprings[count].p1.c = c;
|
||||
m_pSprings[count].p2.r = r+1;
|
||||
m_pSprings[count].p2.c = c-1;
|
||||
m_pSprings[count].k = m_Prop.m_fSpringShearConstant;
|
||||
m_pSprings[count].d = m_Prop.m_fSpringDampingConstant;
|
||||
vL = m_pParticles[ROWCOL(r,c)].vPos - m_pParticles[ROWCOL(r+1,c-1)].vPos;
|
||||
m_pSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CBaseCloth::~CBaseCloth(void)
|
||||
{
|
||||
SAFE_DELETE_ARRAY( m_pParticles );
|
||||
SAFE_DELETE_ARRAY( m_pSprings );
|
||||
}
|
||||
|
||||
void CBaseCloth::LockParticle( int iRow, int iCol )
|
||||
{
|
||||
m_pParticles[ROWCOL(iRow,iCol)].bLocked = true;
|
||||
m_LockedParticleList.push_back(&m_pParticles[ROWCOL(iRow,iCol)]);
|
||||
}
|
||||
|
||||
void CBaseCloth::UnLockParticle( int iRow, int iCol )
|
||||
{
|
||||
m_pParticles[ROWCOL(iRow,iCol)].bLocked = false;
|
||||
|
||||
PARTICLEVECTOR::iterator iter;
|
||||
for( iter = m_LockedParticleList.begin(); iter != m_LockedParticleList.end(); iter++ )
|
||||
{
|
||||
if( (*iter)->RC.r == iRow && (*iter)->RC.c == iCol )
|
||||
m_LockedParticleList.erase(iter);
|
||||
}
|
||||
}
|
||||
134
Engine/Zalla3D Scene Class/BaseCloth.h
Normal file
134
Engine/Zalla3D Scene Class/BaseCloth.h
Normal file
@@ -0,0 +1,134 @@
|
||||
#pragma once
|
||||
|
||||
#include "d3dx8.h"
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
enum CLOTH_FORM_TYPE
|
||||
{
|
||||
CFT_QUAD,
|
||||
CFT_TRAPEZOID
|
||||
};
|
||||
|
||||
class CClothProperty
|
||||
{
|
||||
public:
|
||||
int m_iWidth;
|
||||
int m_iHeight;
|
||||
int m_iRow;
|
||||
int m_iCol;
|
||||
float m_fMass;
|
||||
float m_fGravity;
|
||||
float m_fSpringTensionConstant;
|
||||
float m_fSpringShearConstant;
|
||||
float m_fSpringDampingConstant;
|
||||
float m_fDragCoefficient;
|
||||
float m_fCollisionToLerance;
|
||||
float m_fKrestitution;
|
||||
float m_fFrictionfactor;
|
||||
CLOTH_FORM_TYPE m_FormType;
|
||||
|
||||
public:
|
||||
CClothProperty() {}
|
||||
virtual ~CClothProperty() {}
|
||||
|
||||
void Init( int iWidth, int iHeight, int iRow, int iCol, CLOTH_FORM_TYPE Type )
|
||||
{
|
||||
m_iWidth = iWidth;
|
||||
m_iHeight = iHeight;
|
||||
m_iRow = iRow; //<2F><><EFBFBD>ΰ<EFBFBD> <20><>ĭ<EFBFBD>ΰ<EFBFBD>
|
||||
m_iCol = iCol; //<2F><><EFBFBD>ΰ<EFBFBD> <20><>ĭ<EFBFBD>ΰ<EFBFBD>
|
||||
m_fMass = 50.0f;
|
||||
m_fGravity = -32.174f;
|
||||
m_fSpringTensionConstant = 400.0f;
|
||||
m_fSpringShearConstant = 400.0f;
|
||||
m_fSpringDampingConstant = 1.0f;
|
||||
m_fDragCoefficient = 0.05f;
|
||||
m_fCollisionToLerance = 0.05f;
|
||||
m_fKrestitution = 0.25f;
|
||||
m_fFrictionfactor = 0.5f;
|
||||
m_FormType = Type;
|
||||
}
|
||||
};
|
||||
|
||||
class CBaseCloth
|
||||
{
|
||||
protected:
|
||||
struct ParticleRef
|
||||
{
|
||||
int r; //<2F><>
|
||||
int c; //<2F><>
|
||||
};
|
||||
|
||||
struct Particle
|
||||
{
|
||||
float fMass;
|
||||
float fInvMass;
|
||||
D3DXVECTOR3 vPos;
|
||||
D3DXVECTOR3 vVel;
|
||||
D3DXVECTOR3 vAccel;
|
||||
D3DXVECTOR3 vForce;
|
||||
bool bLocked;
|
||||
ParticleRef RC;
|
||||
};
|
||||
|
||||
struct Spring
|
||||
{
|
||||
ParticleRef p1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31>
|
||||
ParticleRef p2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2<><32>
|
||||
float k; //ź<><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float d; //<2F><><EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD>
|
||||
float L; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
struct CollisionSphere
|
||||
{
|
||||
float fRadius;
|
||||
D3DXVECTOR3 vPos;
|
||||
};
|
||||
|
||||
typedef vector<Particle*> PARTICLEVECTOR;
|
||||
|
||||
public:
|
||||
Particle* m_pParticles;
|
||||
Spring* m_pSprings;
|
||||
int m_iNumSpring;
|
||||
int m_iNumFace;
|
||||
int m_iNumVertex;
|
||||
float m_fRStep;
|
||||
float m_fCStep;
|
||||
|
||||
PARTICLEVECTOR m_LockedParticleList;
|
||||
CClothProperty m_Prop;
|
||||
|
||||
protected:
|
||||
inline int ROWCOL( int r, int c );
|
||||
|
||||
public:
|
||||
CBaseCloth( const CClothProperty* pProp );
|
||||
virtual ~CBaseCloth(void);
|
||||
|
||||
virtual void Render() = 0;
|
||||
virtual void Update( float dt=0.025f ) = 0;
|
||||
void LockParticle( int iRow, int iCol );
|
||||
void UnLockParticle( int iRow, int iCol );
|
||||
inline void SetParticlePos( int iRow, int iCol, const D3DXVECTOR3& vPos );
|
||||
inline void GetParticlePos( int iRow, int iCol, D3DXVECTOR3& vPos );
|
||||
};
|
||||
|
||||
inline int CBaseCloth::ROWCOL( int r, int c )
|
||||
{
|
||||
return (r*(m_Prop.m_iCol+1)+c);
|
||||
}
|
||||
|
||||
inline void CBaseCloth::SetParticlePos( int iRow, int iCol, const D3DXVECTOR3& vPos )
|
||||
{
|
||||
m_pParticles[ROWCOL(iRow,iCol)].vPos = vPos;
|
||||
}
|
||||
|
||||
inline void CBaseCloth::GetParticlePos( int iRow, int iCol, D3DXVECTOR3& vPos )
|
||||
{
|
||||
vPos = m_pParticles[ROWCOL(iRow,iCol)].vPos;
|
||||
}
|
||||
|
||||
|
||||
150
Engine/Zalla3D Scene Class/BaseDataDefine.h
Normal file
150
Engine/Zalla3D Scene Class/BaseDataDefine.h
Normal file
@@ -0,0 +1,150 @@
|
||||
#ifndef _BASEDATA_H
|
||||
#define _BASEDATA_H
|
||||
|
||||
#pragma once
|
||||
|
||||
const long MAX_NAMEBUFFER=256;
|
||||
|
||||
extern char INITVALUEFILE[];
|
||||
extern char MAPDATAPATH[];
|
||||
extern char ROOTPATH[];
|
||||
|
||||
extern char CHARACTERDATAPATH[];
|
||||
extern char CHARACTERTEXTUREDATAPATH[];
|
||||
extern char CHARACTERMESHTEX[];
|
||||
extern char CHARACTERANIPACK[];
|
||||
extern char CHARACTERLODMESH[];
|
||||
extern char CHARACTERTEXPIECE[];
|
||||
extern char CHARACTERATTACHMENTMESH[];
|
||||
extern char CHARACTERTEXTURE[];
|
||||
|
||||
extern char ORIGINALTEXUTREINTERFACEPATH[];
|
||||
extern char ORIGINALTEXUTRELIGHTMAPPATH[];
|
||||
extern char ORIGINALTEXUTRENATUREPATH[];
|
||||
extern char ORIGINALTEXTUREOBJECTPATH[];
|
||||
extern char ORIGINALTEXTURETERRAINPATH[];
|
||||
extern char ORIGINALTEXTUREWIDEPATH[];
|
||||
extern char ORIGINALTEXTUREFXPATH[];
|
||||
extern char ORIGINALTEXTUREEFFECT[];
|
||||
|
||||
//Object Path Define//
|
||||
extern char HOUSEOBJECTPATH[];
|
||||
extern char LIGHTOBJECTPATH[];
|
||||
extern char TREEOBJECTPATH[];
|
||||
extern char OBJECTPATH[];
|
||||
extern char EFFECTPATH[];
|
||||
extern char EFFECTSOUNDSPATH[];
|
||||
extern char EFFECTSOUNDMPATH[];
|
||||
|
||||
|
||||
extern char INSTANCEOBJECTPATH[];
|
||||
//Texture Path Define//
|
||||
extern char TERRAINTEXTUREPATH[];
|
||||
extern char OBJECTTEXTUREPATH[];
|
||||
extern char NATURETEXTUREPATH[];
|
||||
extern char WIDETEXTUREPATH[];
|
||||
extern char NEOINTERFACETEXTUREPATH[];
|
||||
extern char INTERFACETEXTUREPATH[];
|
||||
extern char FXTEXTUREPATH[];
|
||||
extern char BSPTEXTUREPATH[];
|
||||
extern char BSPDATAPATH[];
|
||||
extern char EFFECTTEXTUREPATH[];
|
||||
extern char EFFECTSCRIPTPATH[];
|
||||
|
||||
extern char OBJECTGEMPATH[];
|
||||
extern char UNSHADOWWIDETEXTUREPATH[];
|
||||
|
||||
// LightMap Path Define//
|
||||
extern char LIGHTMAPTEXTUREPATH[];
|
||||
//VertexShader Path Define//
|
||||
extern char TERRAINVERTEXSHADEROATH[];
|
||||
|
||||
extern char SHADERPATH[];
|
||||
//Save Data Path Define//
|
||||
extern char WEATHERPATH[];
|
||||
//Sound Data Path Define//
|
||||
extern char SOUNDFILEPATH[];
|
||||
|
||||
//Octree Path Define//
|
||||
extern char OCTREEPATH[];
|
||||
//Sector Scene Map Path Define//
|
||||
extern char SECTORMAPPATH[];
|
||||
//Font Texture Filename//
|
||||
extern char FONTFILE[];
|
||||
|
||||
extern float LENS_NEAR_HOUSE;
|
||||
extern float LENS_NEAR_OBJECT;
|
||||
extern long MOVE_NOTHING;
|
||||
extern long MOVE_HOUSE;
|
||||
extern long MOVE_LIGHT;
|
||||
extern long MOVE_OBJECT;
|
||||
|
||||
extern float NEARPLANEVALUE;
|
||||
extern float LIGHTMAPSIZE;
|
||||
extern float MAX_ALLOWLIGHTMAPSIZE;
|
||||
extern float PERLIGHTMAP;
|
||||
|
||||
extern long GF3OPTION;
|
||||
extern long COLLISIONOBJECTVIEW;
|
||||
|
||||
// Character Lod Distance
|
||||
extern float fCHARACTERLODLEVELDIST[];
|
||||
|
||||
//Ambience DataPath
|
||||
extern char AMBIENCEPATH[];
|
||||
//BGM DataPath
|
||||
extern char BGMPATH[];
|
||||
|
||||
/*
|
||||
//Init Value File //
|
||||
#define INITVALUEFILE "c:\\MP-Project\\Mp.INI"
|
||||
|
||||
//Original Texutre Path//
|
||||
#define ORIGINALTEXUTREINTERFACEPATH "c:\\MP-Project\\RawTexture\\Interface"
|
||||
#define ORIGINALTEXUTRELIGHTMAPPATH "c:\\MP-Project\\RawTexture\\Lightmap"
|
||||
#define ORIGINALTEXUTRENATUREPATH "c:\\MP-Project\\RawTexture\\NatureObject"
|
||||
#define ORIGINALTEXTUREOBJECTPATH "c:\\MP-Project\\RawTexture\\Object"
|
||||
#define ORIGINALTEXTURETERRAINPATH "c:\\MP-Project\\RawTexture\\Terrain"
|
||||
#define ORIGINALTEXTUREWIDEPATH "c:\\MP-Project\\RawTexture\\WideTexture"
|
||||
|
||||
//Object Path Define//
|
||||
#define HOUSEOBJECTPATH "c:\\MP-Project\\Objects\\House\\"
|
||||
#define LIGHTOBJECTPATH "c:\\MP-Project\\Objects\\Object\\"
|
||||
#define TREEOBJECTPATH "c:\\MP-Project\\Objects\\NatureObject\\"
|
||||
#define OBJECTPATH "c:\\MP-Project\\Objects\\Object\\"
|
||||
//Texture Path Define//
|
||||
#define TERRAINTEXTUREPATH "c:\\MP-project\\Texture\\Terrain"
|
||||
#define OBJECTTEXTUREPATH "c:\\MP-Project\\Texture\\Object"
|
||||
#define NATURETEXTUREPATH "c:\\MP-project\\Texture\\NatureObject"
|
||||
#define WIDETEXTUREPATH "C:\\MP-Project\\Texture\\WideTexture"
|
||||
#define INTERFACETEXTUREPATH "c:\\MP-Project\\Texture\\Interface"
|
||||
|
||||
// LightMap Path Define//
|
||||
#define LIGHTMAPTEXTUREPATH "c:\\MP-Project\\Texture\\Lightmap"
|
||||
//VertexShader Path Define//
|
||||
#define TERRAINVERTEXSHADEROATH "c:\\MP-Project\\VertexShader\\LayerFog\\LayerFogTerrain.vsh"
|
||||
//Save Data Path Define//
|
||||
#define WEATHERPATH "c:\\MP-Project\\WeatherColorTable.dat"
|
||||
|
||||
//Octree Path Define//
|
||||
#define OCTREEPATH "c:\\MP-Project\\Octree"
|
||||
|
||||
//Sector Scene Map Path Define//
|
||||
#define SECTORMAPPATH "c:\\MP-Project\\Map"
|
||||
//Font Texture Filename//
|
||||
#define FONTFILE "Font-H.dds"
|
||||
|
||||
|
||||
const float LENS_NEAR_HOUSE=3000.0f;
|
||||
const float LENS_NEAR_OBJECT=5000.0f;
|
||||
const long MOVE_NOTHING=0;
|
||||
const long MOVE_HOUSE=1;
|
||||
const long MOVE_LIGHT=2;
|
||||
const long MOVE_OBJECT=3;
|
||||
|
||||
const float NEARPLANEVALUE=3.0f;
|
||||
const float LIGHTMAPSIZE=32;
|
||||
const float MAX_ALLOWLIGHTMAPSIZE=50000.0f;
|
||||
const float PERLIGHTMAP=30.0f;
|
||||
*/
|
||||
#endif
|
||||
543
Engine/Zalla3D Scene Class/BgmManager.cpp
Normal file
543
Engine/Zalla3D Scene Class/BgmManager.cpp
Normal file
@@ -0,0 +1,543 @@
|
||||
// BgmManager.cpp: implementation of the CBgmManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "BaseGraphicsLayer.h"
|
||||
#include "SceneManager.h"
|
||||
#include "BgmManager.h"
|
||||
#include "SoundMgr.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//#define VOLUME_GAP 0.005
|
||||
|
||||
CBgmManager* CBgmManager::ms_pInstance = NULL;
|
||||
|
||||
struct TESTSCREEN_VERTEX
|
||||
{
|
||||
float x, y, z, rhw;
|
||||
float u, v;
|
||||
};
|
||||
|
||||
CBgmManager::CBgmManager()
|
||||
{
|
||||
}
|
||||
|
||||
CBgmManager::~CBgmManager()
|
||||
{
|
||||
}
|
||||
|
||||
CBgmManager* CBgmManager::_GetInstance()
|
||||
{
|
||||
if( ms_pInstance == NULL ) { ms_pInstance = new CBgmManager; }
|
||||
return ms_pInstance;
|
||||
}
|
||||
|
||||
void CBgmManager::_Destroy()
|
||||
{
|
||||
if( ms_pInstance ) ms_pInstance->ReleaseAllData();
|
||||
SAFE_DELETE( ms_pInstance );
|
||||
}
|
||||
|
||||
void CBgmManager::Create( bool bTestMode )
|
||||
{
|
||||
m_bTestMode = bTestMode;
|
||||
|
||||
if( m_bTestMode )
|
||||
{
|
||||
m_pBGMTexture = NULL;
|
||||
m_bTestShow = false;
|
||||
}
|
||||
|
||||
m_Trigger.Create();
|
||||
m_bInPlace = false;
|
||||
m_fBgmVol = 0.0f;
|
||||
m_fMasterVolume = 1.0f;
|
||||
m_ePlaceStat = BS_ZERO;
|
||||
m_eBgmStat = BS_ZERO;
|
||||
memset( m_strCurBgm, 0, sizeof(m_strCurBgm) );
|
||||
m_bBgmTurnEvent = false;
|
||||
m_bActivate = true;
|
||||
m_bActBGM = FALSE;
|
||||
}
|
||||
|
||||
|
||||
void CBgmManager::ReleaseAllData()
|
||||
{
|
||||
m_Trigger.Destroy();
|
||||
|
||||
if( m_bTestMode )
|
||||
{
|
||||
SAFE_RELEASE( m_pBGMTexture );
|
||||
}
|
||||
}
|
||||
|
||||
static char strOldFile[MAX_PATH];
|
||||
static CStreamingSound* g_pSound = NULL;
|
||||
|
||||
void CBgmManager::Update( D3DXVECTOR3& Pos, float fSkip, bool bCharSel)
|
||||
{
|
||||
int SectorX, SectorY;
|
||||
PerSectorTriggerInfo* pInfo=NULL;
|
||||
|
||||
GetSectorXYFromPos( SectorX, SectorY, Pos );
|
||||
pInfo = m_Trigger.GetTrigger( SectorX, SectorY );
|
||||
|
||||
static int EventKey;
|
||||
static DWORD EventColor;
|
||||
static char* strFile;
|
||||
static char* strESF;
|
||||
bool bPossible=false;
|
||||
|
||||
m_EventTable.Update();
|
||||
|
||||
float fVolumeGap = 0.01f;
|
||||
|
||||
if(m_bActBGM && g_pSound)
|
||||
g_pSound->SetVolume( m_fMasterVolume );
|
||||
|
||||
if( pInfo )
|
||||
{
|
||||
bPossible = GetBGMEventInfo( Pos, pInfo, strFile, EventKey, strESF, EventColor);
|
||||
|
||||
if( bPossible && !bCharSel && EventKey != EK_CAMP_UNCREATE)
|
||||
{
|
||||
if(strlen(strESF) > 0 && m_EventColor != EventColor)
|
||||
{
|
||||
m_EventColor = EventColor;
|
||||
|
||||
// edith 2008.01.26 <20><><EFBFBD><EFBFBD><EFBFBD>彺ũ<E5BDBA><C5A9>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20≯<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
CEffScript* test_script = new CEffScript;
|
||||
test_script->GetScriptBinData(strESF);// "inter_interface-type-keyboard.esf"
|
||||
test_script->m_InterfacePos[0] = (float)CSceneManager::m_ScreenWidth / 2.0f;
|
||||
test_script->m_InterfacePos[1] = (float)CSceneManager::m_ScreenHeight / 5.0f;
|
||||
CSceneManager::m_EffectManager.AddInterfaceScript(test_script);
|
||||
}
|
||||
|
||||
bPossible = !CSceneManager::ms_pSceneEventMgr->m_bEventMusic;
|
||||
}
|
||||
else
|
||||
m_EventColor = 0;
|
||||
|
||||
if( bPossible )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD>
|
||||
if(EventKey == EK_NOTBGM_SAFE || EventKey >= EK_ESF_SAFE)
|
||||
{
|
||||
StopBGM();
|
||||
return;
|
||||
}
|
||||
|
||||
m_fBgmVol += fVolumeGap;
|
||||
m_eBgmStat = BS_BGM_PLAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
AGAIN:
|
||||
// <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD>
|
||||
if(EventKey == EK_NOTBGM_SAFE || EventKey >= EK_ESF_SAFE)
|
||||
{
|
||||
StopBGM();
|
||||
return;
|
||||
}
|
||||
|
||||
m_fBgmVol -= fVolumeGap;
|
||||
|
||||
if( m_fBgmVol <= 0.0f && m_eBgmStat == BS_BGM_PLAY )
|
||||
{
|
||||
m_EventColor = 0;
|
||||
StopBGM();
|
||||
}
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD>
|
||||
if(EventKey == EK_NOTBGM_SAFE || EventKey >= EK_ESF_SAFE)
|
||||
return;
|
||||
|
||||
if( m_fBgmVol > 1.0f ) m_fBgmVol = 1.0f;
|
||||
if( m_fBgmVol < 0.0f ) m_fBgmVol = 0.0f;
|
||||
|
||||
if( m_eBgmStat == BS_BGM_PLAY )
|
||||
{
|
||||
PlayBGM( strFile, EventKey );
|
||||
}
|
||||
}
|
||||
else if( m_fBgmVol > 0.0f )
|
||||
{
|
||||
goto AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CBgmManager::GetSectorXYFromPos( int& outX , int& outY, D3DXVECTOR3 inPos )
|
||||
{
|
||||
outX = (int)(inPos.x / SECTORSIZE);
|
||||
outY = (int)(inPos.z / SECTORSIZE);
|
||||
}
|
||||
|
||||
|
||||
void CBgmManager::GetTextureLockPosFromPos( int& outX, int& outY, D3DXVECTOR3 inPos )
|
||||
{
|
||||
float Magnification = (float)SECTORSIZE / (float)BGM_TEXTURESIZE;
|
||||
|
||||
outX = (int)inPos.x % SECTORSIZE;
|
||||
outY = (int)inPos.z % SECTORSIZE;
|
||||
|
||||
outX = (float)outX / Magnification;
|
||||
outY = (float)outY / Magnification;
|
||||
|
||||
outY = BGM_TEXTURESIZE - outY -1; //Convert Texture LockPos
|
||||
}
|
||||
|
||||
|
||||
bool CBgmManager::GetBGMEventInfo( D3DXVECTOR3 inPos,
|
||||
PerSectorTriggerInfo* pinInfo, char*& outStrFile, int& outEventKey, char*& outESFFile, DWORD& outEventColor)
|
||||
{
|
||||
int LockPosX, LockPosY;
|
||||
GetTextureLockPosFromPos( LockPosX, LockPosY, inPos );
|
||||
|
||||
if( m_bTestMode ) LoadTexture( pinInfo );
|
||||
|
||||
vector<DWORD>::iterator iter;
|
||||
int index = 0;
|
||||
DWORD BgmColor = pinInfo->ColorTable[LockPosY][LockPosX] & 0x00ffffff;
|
||||
m_EventTable.dwColor = pinInfo->ColorTable[LockPosY][LockPosX];
|
||||
DWORD ColorT;
|
||||
|
||||
for( iter = pinInfo->BGMColorKeyList.begin(); iter != pinInfo->BGMColorKeyList.end(); iter++ )
|
||||
{
|
||||
ColorT = (*iter);
|
||||
if( BgmColor == ColorT )
|
||||
{
|
||||
outStrFile = pinInfo->BGMFileList[index];
|
||||
m_EventTable.nEvent = outEventKey = pinInfo->EventKeyList[index];
|
||||
outEventColor = pinInfo->BGMColorKeyList[index];
|
||||
outESFFile = pinInfo->ESFFileList[index];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
index ++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CBgmManager::LoadTexture( PerSectorTriggerInfo* pInfo )
|
||||
{
|
||||
static PerSectorTriggerInfo* pOldInfo = pInfo;
|
||||
static bool bOnce = false;
|
||||
|
||||
if( !bOnce )
|
||||
{
|
||||
D3DXCreateTextureFromFileEx( BaseGraphicsLayer::GetDevice(), pInfo->strTexFilename,
|
||||
D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, 1, 0,
|
||||
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE,
|
||||
D3DX_FILTER_NONE, 0x00000000, NULL, NULL,
|
||||
&m_pBGMTexture );
|
||||
bOnce = true;
|
||||
}
|
||||
|
||||
if( pOldInfo->iSectorX != pInfo->iSectorX || pOldInfo->iSectorY != pInfo->iSectorY )
|
||||
{
|
||||
pOldInfo = pInfo;
|
||||
SAFE_RELEASE( m_pBGMTexture );
|
||||
D3DXCreateTextureFromFileEx( BaseGraphicsLayer::GetDevice(), pInfo->strTexFilename,
|
||||
D3DX_DEFAULT,
|
||||
D3DX_DEFAULT, 1, 0,
|
||||
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_FILTER_NONE,
|
||||
D3DX_FILTER_NONE, 0x00000000, NULL, NULL,
|
||||
&m_pBGMTexture );
|
||||
}
|
||||
}
|
||||
|
||||
void CBgmManager::StopBGM()
|
||||
{
|
||||
if(m_eBgmStat == BS_BGM_STOP)
|
||||
return;
|
||||
|
||||
m_eBgmStat = BS_BGM_STOP;
|
||||
m_ePlaceStat = BS_PLACE_OUT;
|
||||
|
||||
if(strlen(strOldFile) == 0)
|
||||
return;
|
||||
|
||||
CStreamingSound* pSound;
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound( pSound, strOldFile );
|
||||
if(pSound)
|
||||
pSound->Stop();
|
||||
|
||||
m_bBgmTurnEvent = false;
|
||||
strcpy( strOldFile, "" );
|
||||
}
|
||||
|
||||
void CBgmManager::PlayBGM( char* strFilename, int EventKey, BOOL bAct )
|
||||
{
|
||||
static bool bOnce = false;
|
||||
|
||||
m_bActBGM = bAct;
|
||||
|
||||
if( !bOnce )
|
||||
{
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound( g_pSound, strFilename );
|
||||
|
||||
if(!g_pSound)
|
||||
return;
|
||||
|
||||
switch( EventKey )
|
||||
{
|
||||
case EK_BGM_ONCE_SAFE:
|
||||
case EK_BGM_ONCE_UNSAFE:
|
||||
{
|
||||
g_pSound->SetLooping( false );
|
||||
}
|
||||
break;
|
||||
|
||||
case EK_BGM_TURN_AMB_SAFE:
|
||||
case EK_BGM_TURN_AMB_UNSAFE:
|
||||
{
|
||||
g_pSound->SetLooping( false );
|
||||
strcpy( m_strCurBgm, strFilename );
|
||||
m_bBgmTurnEvent = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case EK_BGM_LOOP_SAFE:
|
||||
case EK_BGM_LOOP_UNSAFE:
|
||||
{
|
||||
g_pSound->SetLooping( true );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
strcpy( strOldFile, strFilename );
|
||||
g_pSound->SetVolume( m_fBgmVol*m_fMasterVolume );
|
||||
g_pSound->Play();
|
||||
bOnce = true;
|
||||
m_ePlaceStat = BS_PLACE_IN;
|
||||
}
|
||||
|
||||
if( strcmp(strOldFile, strFilename) != 0 )
|
||||
{
|
||||
// strOldFile <20><> StopBGM <20><> ȣ<><C8A3><EFBFBD>Ǹ<EFBFBD> NULL <20>̱<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.. <20><><EFBFBD>⼭ <20><><EFBFBD><EFBFBD>ó<EFBFBD><C3B3>
|
||||
if(strlen(strOldFile) != 0)
|
||||
{
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound( g_pSound, strOldFile );
|
||||
|
||||
if(!g_pSound)
|
||||
return;
|
||||
|
||||
g_pSound->Stop();
|
||||
m_bBgmTurnEvent = false;
|
||||
}
|
||||
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound( g_pSound, strFilename );
|
||||
|
||||
if(!g_pSound)
|
||||
return;
|
||||
|
||||
switch( EventKey )
|
||||
{
|
||||
case EK_BGM_TURN_AMB_SAFE:
|
||||
case EK_BGM_TURN_AMB_UNSAFE:
|
||||
{
|
||||
m_bBgmTurnEvent = true;
|
||||
g_pSound->SetLooping( false );
|
||||
strcpy( m_strCurBgm, strFilename );
|
||||
}
|
||||
break;
|
||||
|
||||
case EK_BGM_ONCE_SAFE:
|
||||
case EK_BGM_ONCE_UNSAFE:
|
||||
{
|
||||
g_pSound->SetLooping( false );
|
||||
}
|
||||
break;
|
||||
|
||||
case EK_BGM_LOOP_SAFE:
|
||||
case EK_BGM_LOOP_UNSAFE:
|
||||
{
|
||||
g_pSound->SetLooping( true );
|
||||
}
|
||||
break;
|
||||
}
|
||||
strcpy( strOldFile, strFilename );
|
||||
g_pSound->SetVolume( m_fBgmVol*m_fMasterVolume );
|
||||
g_pSound->Play();
|
||||
m_ePlaceStat = BS_PLACE_IN;
|
||||
}
|
||||
|
||||
if( strcmp(strOldFile, strFilename) == 0 && m_ePlaceStat == BS_PLACE_OUT )
|
||||
{
|
||||
m_ePlaceStat = BS_PLACE_IN;
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound( g_pSound, strFilename );
|
||||
|
||||
if(!g_pSound)
|
||||
return;
|
||||
|
||||
switch( EventKey )
|
||||
{
|
||||
case EK_BGM_TURN_AMB_SAFE:
|
||||
case EK_BGM_TURN_AMB_UNSAFE:
|
||||
{
|
||||
m_bBgmTurnEvent = true;
|
||||
g_pSound->SetLooping( false );
|
||||
strcpy( m_strCurBgm, strFilename );
|
||||
}
|
||||
break;
|
||||
|
||||
case EK_BGM_ONCE_SAFE:
|
||||
case EK_BGM_ONCE_UNSAFE:
|
||||
{
|
||||
g_pSound->SetLooping( false );
|
||||
}
|
||||
break;
|
||||
|
||||
case EK_BGM_LOOP_SAFE:
|
||||
case EK_BGM_LOOP_UNSAFE:
|
||||
{
|
||||
g_pSound->SetLooping( true );
|
||||
}
|
||||
break;
|
||||
}
|
||||
strcpy( strOldFile, strFilename );
|
||||
g_pSound->SetVolume( m_fBgmVol*m_fMasterVolume );
|
||||
g_pSound->Play();
|
||||
}
|
||||
|
||||
if(!g_pSound)
|
||||
return;
|
||||
|
||||
g_pSound->SetVolume( m_fBgmVol*m_fMasterVolume );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CBgmManager::TestScreen( D3DXVECTOR3 Pos )
|
||||
{
|
||||
if( !m_bTestShow ) return;
|
||||
|
||||
LPDIRECT3DDEVICE8 pd3dDevice = BaseGraphicsLayer::GetDevice();
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
pd3dDevice->SetVertexShader( D3DFVF_XYZRHW | D3DFVF_TEX1 );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
|
||||
D3DVIEWPORT8 TempViewport;
|
||||
pd3dDevice->GetViewport( &TempViewport );
|
||||
|
||||
float center = TempViewport.Width - 300;
|
||||
|
||||
TESTSCREEN_VERTEX pVertex[4];
|
||||
pVertex[0].x = center;
|
||||
pVertex[0].y = 0;
|
||||
pVertex[0].z = 0.0f;
|
||||
pVertex[0].rhw = 1.0f;
|
||||
pVertex[0].u = 0.0f;
|
||||
pVertex[0].v = 0.0f;
|
||||
|
||||
pVertex[1].x = 300.0f + center;
|
||||
pVertex[1].y = 0;
|
||||
pVertex[1].z = 0.0f;
|
||||
pVertex[1].rhw = 1.0f;
|
||||
pVertex[1].u = 1.0f;
|
||||
pVertex[1].v = 0.0f;
|
||||
|
||||
pVertex[2].x = center;
|
||||
pVertex[2].y = 300.0f;
|
||||
pVertex[2].z = 0.0f;
|
||||
pVertex[2].rhw = 1.0f;
|
||||
pVertex[2].u = 0.0f;
|
||||
pVertex[2].v = 1.0f;
|
||||
|
||||
pVertex[3].x = 300.0f + center;
|
||||
pVertex[3].y = 300.0f;
|
||||
pVertex[3].z = 0.0f;
|
||||
pVertex[3].rhw = 1.0f;
|
||||
pVertex[3].u = 1.0f;
|
||||
pVertex[3].v = 1.0f;
|
||||
|
||||
pd3dDevice->SetTexture( 0, m_pBGMTexture );
|
||||
pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, pVertex, sizeof(TESTSCREEN_VERTEX) );
|
||||
|
||||
//Set things back to normal
|
||||
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE, TRUE );
|
||||
}
|
||||
|
||||
|
||||
void CBgmManager::AllStop()
|
||||
{
|
||||
m_bInPlace = false;
|
||||
m_fBgmVol = 0.0f;
|
||||
m_ePlaceStat = BS_ZERO;
|
||||
m_eBgmStat = BS_ZERO;
|
||||
CSoundMgr::_GetInstance()->AllStopStreamingSound();
|
||||
}
|
||||
|
||||
|
||||
bool CBgmManager::IsSafetyZone( D3DXVECTOR3& Pos )
|
||||
{
|
||||
int SectorX, SectorY;
|
||||
PerSectorTriggerInfo* pInfo=NULL;
|
||||
|
||||
GetSectorXYFromPos( SectorX, SectorY, Pos );
|
||||
pInfo = m_Trigger.GetTrigger( SectorX, SectorY );
|
||||
|
||||
if( pInfo )
|
||||
{
|
||||
// DWORD ColorKey;
|
||||
int LockPosX, LockPosY;
|
||||
GetTextureLockPosFromPos( LockPosX, LockPosY, Pos );
|
||||
DWORD BgmColor = pInfo->ColorTable[LockPosY][LockPosX] & 0x00ffffff;
|
||||
|
||||
for( size_t i = 0; i < pInfo->BGMColorKeyList.size(); ++i )
|
||||
{
|
||||
// ColorKey = pInfo->BGMColorKeyList[i];
|
||||
if( BgmColor == pInfo->BGMColorKeyList[i] )
|
||||
{
|
||||
switch( pInfo->EventKeyList[i] )
|
||||
{
|
||||
case EK_BGM_LOOP_SAFE:
|
||||
case EK_BGM_ONCE_SAFE:
|
||||
case EK_NOTBGM_SAFE:
|
||||
case EK_BGM_TURN_AMB_SAFE:
|
||||
case EK_ESF_SAFE:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CBgmManager::IsCurBgmTurnAmbEvent()
|
||||
{
|
||||
|
||||
if( m_bBgmTurnEvent )
|
||||
{
|
||||
CStreamingSound* pSound;
|
||||
CSoundMgr::_GetInstance()->GetStreamingSound( pSound, m_strCurBgm );
|
||||
return pSound->IsPlaying();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CBgmManager::SetActivate( bool bAct )
|
||||
{
|
||||
m_bActivate = bAct;
|
||||
if( bAct == false )
|
||||
m_fMasterVolume = 0.0f;
|
||||
}
|
||||
90
Engine/Zalla3D Scene Class/BgmManager.h
Normal file
90
Engine/Zalla3D Scene Class/BgmManager.h
Normal file
@@ -0,0 +1,90 @@
|
||||
// BgmManager.h: interface for the CBgmManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_BGMMANAGER_H__CF4545F4_7FA9_4473_8450_171C8740AE69__INCLUDED_)
|
||||
#define AFX_BGMMANAGER_H__CF4545F4_7FA9_4473_8450_171C8740AE69__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "d3dx8.h"
|
||||
#include "SectorBGMTrigger.h"
|
||||
|
||||
class CSceneEventMgr;
|
||||
|
||||
class CBgmManager
|
||||
{
|
||||
friend class CSceneEventMgr;
|
||||
|
||||
struct EventTable
|
||||
{
|
||||
int nEvent;
|
||||
DWORD dwColor;
|
||||
EventTable() : nEvent(-1), dwColor(0) {}
|
||||
void Update() { nEvent = -1; dwColor = 0; }
|
||||
};
|
||||
|
||||
enum BGM_STATE
|
||||
{
|
||||
BS_ZERO = 0,
|
||||
BS_PLACE_IN,
|
||||
BS_PLACE_OUT,
|
||||
BS_BGM_STOP,
|
||||
BS_BGM_PLAY
|
||||
};
|
||||
|
||||
BGM_STATE m_ePlaceStat;
|
||||
BGM_STATE m_eBgmStat;
|
||||
|
||||
protected:
|
||||
static CBgmManager* ms_pInstance;
|
||||
CSectorBGMTrigger m_Trigger;
|
||||
bool m_bInPlace;
|
||||
float m_fBgmVol;
|
||||
float m_fMasterVolume;
|
||||
bool m_bActivate;
|
||||
char m_strCurBgm[256];
|
||||
bool m_bBgmTurnEvent;
|
||||
EventTable m_EventTable;
|
||||
|
||||
DWORD m_EventColor;
|
||||
|
||||
BOOL m_bActBGM;
|
||||
|
||||
//TestMode
|
||||
bool m_bTestMode;
|
||||
bool m_bTestShow;
|
||||
LPDIRECT3DTEXTURE8 m_pBGMTexture;
|
||||
|
||||
protected:
|
||||
CBgmManager();
|
||||
virtual ~CBgmManager();
|
||||
|
||||
void GetSectorXYFromPos( int& outX , int& outY, D3DXVECTOR3 inPos );
|
||||
void GetTextureLockPosFromPos( int& outX , int& outY, D3DXVECTOR3 inPos );
|
||||
bool GetBGMEventInfo( D3DXVECTOR3 inPos,
|
||||
PerSectorTriggerInfo* pinInfo, char*& outStrFile, int& outEventKey, char*& outESFFile, DWORD& outEventColor);
|
||||
void LoadTexture( PerSectorTriggerInfo* pInfo );
|
||||
void TestScreen( D3DXVECTOR3 Pos );
|
||||
|
||||
public:
|
||||
void PlayBGM( char* strFilename, int EventKey, BOOL bAct = FALSE );
|
||||
void StopBGM();
|
||||
|
||||
static CBgmManager* _GetInstance();
|
||||
static void _Destroy();
|
||||
void Create( bool bTestMode=false );
|
||||
void ReleaseAllData();
|
||||
void Update( D3DXVECTOR3& Pos, float fSkip, bool bCharSel );
|
||||
CSectorBGMTrigger* GetBGMTrigger() { return &m_Trigger; }
|
||||
void SetVolume( float fVol ) { m_fMasterVolume = fVol; }
|
||||
void AllStop();
|
||||
bool IsSafetyZone( D3DXVECTOR3& Pos );
|
||||
bool IsCurBgmTurnAmbEvent();
|
||||
void SetActivate( bool bAct );
|
||||
bool IsActivated();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_BGMMANAGER_H__CF4545F4_7FA9_4473_8450_171C8740AE69__INCLUDED_)
|
||||
25
Engine/Zalla3D Scene Class/BillboardParticle.cpp
Normal file
25
Engine/Zalla3D Scene Class/BillboardParticle.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// BillboardParticle.cpp: implementation of the CBillboardParticle class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "BillboardParticle.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CBillboardParticle::CBillboardParticle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CBillboardParticle::~CBillboardParticle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CBillboardParticle::Create(vector3 vecPos)
|
||||
{
|
||||
|
||||
}
|
||||
23
Engine/Zalla3D Scene Class/BillboardParticle.h
Normal file
23
Engine/Zalla3D Scene Class/BillboardParticle.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// BillboardParticle.h: interface for the CBillboardParticle class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_BILLBOARDPARTICLE_H__76021856_2A4A_4818_B687_CC374D0D028D__INCLUDED_)
|
||||
#define AFX_BILLBOARDPARTICLE_H__76021856_2A4A_4818_B687_CC374D0D028D__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
#include "Particle.h"
|
||||
|
||||
class CBillboardParticle : public CParticle
|
||||
{
|
||||
vector3 m_vecPos;
|
||||
public:
|
||||
void Create(vector3 vecPos);
|
||||
CBillboardParticle();
|
||||
virtual ~CBillboardParticle();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_BILLBOARDPARTICLE_H__76021856_2A4A_4818_B687_CC374D0D028D__INCLUDED_)
|
||||
503
Engine/Zalla3D Scene Class/BinTree.h
Normal file
503
Engine/Zalla3D Scene Class/BinTree.h
Normal file
@@ -0,0 +1,503 @@
|
||||
|
||||
|
||||
#ifndef _BinTree_H_
|
||||
#define _BinTree_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#pragma warning(disable:4786) //STL<54><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Warning<6E><67> <20><><EFBFBD>ֱ<EFBFBD> <20><><EFBFBD><EFBFBD>..
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
int Power( int x, unsigned y )
|
||||
{
|
||||
int result = 1;
|
||||
for( unsigned i = 0; i < y; i++ )
|
||||
{
|
||||
result *= x;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//LOGxY<78><59><EFBFBD><EFBFBD> <20>Ҽ<EFBFBD><D2BC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ϵȴ<CFB5>.
|
||||
int LogInt( unsigned x, unsigned y )
|
||||
{
|
||||
int i = 0;
|
||||
while( y >= x )
|
||||
{
|
||||
i++;
|
||||
y /= x;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// <09><><EFBFBD><EFBFBD> Ʈ<><C6AE> - 1<><31><EFBFBD><EFBFBD> <20>迭<EFBFBD><E8BFAD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ϹǷ<CFB9> 0 ... n <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȸ<EFBFBD><C8B8> <20>ϸ<EFBFBD>
|
||||
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȸ(level-order-traversal)<29><> <20><>.
|
||||
// <09>ε<EFBFBD><CEB5><EFBFBD> 0<><30> ij<><C4B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
template < class T >
|
||||
class CBinTree
|
||||
{
|
||||
public:
|
||||
typedef void (*SAVEFUNC)( FILE *, const T & );
|
||||
typedef void (*LOADFUNC)( FILE *, T & );
|
||||
|
||||
public:
|
||||
////////////////<2F><>ƿ<EFBFBD><C6BF>Ƽ <20>Լ<EFBFBD><D4BC><EFBFBD>/////////////////////
|
||||
//<2F><><EFBFBD>ϰ<EFBFBD> 0<><30> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ǹ<EFBFBD><C7B9><EFBFBD>.
|
||||
static unsigned Root() { return 1; }
|
||||
static unsigned Parent( unsigned index ) { return index / 2; }
|
||||
static unsigned LeftChild( unsigned index ) { return index * 2; }
|
||||
static unsigned RightChild( unsigned index ) { return index * 2 + 1; }
|
||||
static unsigned LevelAtIndex( unsigned index ) { return LogInt( x, index ); }
|
||||
static unsigned IndexAtLevel( unsigned nLevel ) { return int( Power( 2, nLevel ) ); }
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
|
||||
protected:
|
||||
struct SNode
|
||||
{
|
||||
T data; //<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
byte isRed : 1;
|
||||
byte isValid : 1;
|
||||
byte isLeaf : 1;
|
||||
|
||||
};
|
||||
|
||||
protected:
|
||||
typedef vector<SNode> DATACONTAINER;
|
||||
|
||||
DATACONTAINER m_vecTreeData;
|
||||
|
||||
|
||||
protected:
|
||||
void LoadExtraInfo( SNode & node, FILE * fp )
|
||||
{
|
||||
unsigned char c = 0;
|
||||
|
||||
fread( &c, sizeof( c ), 1, fp );
|
||||
|
||||
node.isRed = ( c & 0x01 ) >> 0;
|
||||
node.isValid = ( c & 0x02 ) >> 1;
|
||||
node.isLeaf = ( c & 0x04 ) >> 2;
|
||||
}
|
||||
|
||||
void SaveExtraInfo( SNode & node, FILE * fp )
|
||||
{
|
||||
unsigned char c = 0;
|
||||
|
||||
c = ( node.isRed << 0 ) | ( node.isValid << 1 ) | ( node.isLeaf << 2 );
|
||||
|
||||
assert( ( ( c & 0x01 ) >> 0 ) == node.isRed );
|
||||
assert( ( ( c & 0x02 ) >> 1 ) == node.isValid );
|
||||
assert( ( ( c & 0x04 ) >> 2 ) == node.isLeaf );
|
||||
|
||||
fwrite( &c, sizeof( c ), 1, fp );
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
///////////////////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD>////////////////////
|
||||
CBinTree()
|
||||
{
|
||||
}
|
||||
|
||||
~CBinTree()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Create()
|
||||
{
|
||||
Destroy();
|
||||
|
||||
m_vecTreeData.push_back( SNode() ); //<2F>Ѹ<EFBFBD><D1B8><EFBFBD><EFBFBD><EFBFBD> <20>߰<EFBFBD>
|
||||
|
||||
for( unsigned i = 0; i < m_vecTreeData.size(); i++ ) //<2F><><EFBFBD><EFBFBD> <20><>ȿ(invalid) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
{
|
||||
m_vecTreeData[i].isValid = 0;
|
||||
m_vecTreeData[i].isLeaf = 1;
|
||||
}
|
||||
|
||||
m_vecTreeData[0].isValid = 1;
|
||||
}
|
||||
|
||||
void Create( FILE * fp, LOADFUNC LoadData )
|
||||
{
|
||||
Destroy();
|
||||
|
||||
if( LoadData == 0 )
|
||||
return;
|
||||
|
||||
if( fp == 0 )
|
||||
return;
|
||||
|
||||
unsigned size = 0;
|
||||
fread( &size, sizeof( unsigned ), 1, fp );
|
||||
|
||||
m_vecTreeData.push_back( SNode() );
|
||||
|
||||
for( unsigned i = 1; i < size; i++ )
|
||||
{
|
||||
m_vecTreeData.push_back( SNode() );
|
||||
assert( m_vecTreeData.size() == ( i + 1 ) );
|
||||
LoadData( fp, m_vecTreeData[i].data );
|
||||
LoadExtraInfo( m_vecTreeData[i], fp );
|
||||
}
|
||||
}
|
||||
|
||||
void Destroy()
|
||||
{
|
||||
m_vecTreeData.clear();
|
||||
}
|
||||
|
||||
void Save( FILE * fp, SAVEFUNC SaveData )
|
||||
{
|
||||
if( SaveData == 0 )
|
||||
return;
|
||||
|
||||
if( fp == 0 )
|
||||
return;
|
||||
|
||||
unsigned size = m_vecTreeData.size();
|
||||
fwrite( &size, sizeof( unsigned ), 1, fp );
|
||||
|
||||
for( unsigned i = 1; i < size; i++ )
|
||||
{
|
||||
SaveData( fp, m_vecTreeData[i].data );
|
||||
SaveExtraInfo( m_vecTreeData[i], fp );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
T & SetData( unsigned index )
|
||||
{
|
||||
if( index >= m_vecTreeData.size() )
|
||||
{
|
||||
m_vecTreeData.resize( index + 1 );
|
||||
}
|
||||
|
||||
m_vecTreeData[ index ].isValid = true;
|
||||
m_vecTreeData[ Parent( index ) ].isLeaf = false;
|
||||
|
||||
return m_vecTreeData[ index ].data;
|
||||
}
|
||||
|
||||
const T & GetData( unsigned index )
|
||||
{
|
||||
if( index >= m_vecTreeData.size() )
|
||||
throw out_of_range( "index out of range(at CBinTree::GetData)" );
|
||||
|
||||
return m_vecTreeData[ index ].data;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
bool IsEmpty()
|
||||
{
|
||||
if( m_vecTreeData.empty() )
|
||||
return true;
|
||||
|
||||
if( m_vecTreeData[1].isValid == false )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsValid( unsigned index )
|
||||
{
|
||||
if( index >= m_vecTreeData.size() )
|
||||
return false;
|
||||
|
||||
return m_vecTreeData[ index ].isValid == 1;
|
||||
}
|
||||
|
||||
bool IsLeaf( unsigned index )
|
||||
{
|
||||
return m_vecTreeData[ index ].isLeaf == 1;
|
||||
}
|
||||
|
||||
unsigned Capacity()
|
||||
{
|
||||
return m_vecTreeData.capacity();
|
||||
}
|
||||
|
||||
unsigned Size()
|
||||
{
|
||||
return m_vecTreeData.size();
|
||||
}
|
||||
|
||||
unsigned Min( unsigned index ) //index<65><78> <20>ڽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ּҰ<D6BC><D2B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
{
|
||||
while( LeftChild( index ) < m_vecTreeData.size() && IsValid( LeftChild( index ) ) )
|
||||
index = LeftChild( index );
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
unsigned Max( unsigned index ) //index<65><78> <20>ڽ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ִ밪<D6B4><EBB0AA> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
{
|
||||
while( RightChild( index ) < m_vecTreeData.size() && IsValid( RightChild( index ) ) )
|
||||
index = RightChild( index );
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
class iterator_base
|
||||
{
|
||||
protected:
|
||||
CBinTree * m_pBinTree;
|
||||
unsigned m_uiCurIndex;
|
||||
|
||||
public:
|
||||
iterator_base( CBinTree * pBinTree, unsigned index )
|
||||
: m_pBinTree( pBinTree ), m_uiCurIndex( index )
|
||||
{
|
||||
}
|
||||
|
||||
T & operator*() const
|
||||
{
|
||||
return m_pBinTree->m_vecTreeData[m_uiCurIndex].data;
|
||||
}
|
||||
|
||||
|
||||
T * operator->() const
|
||||
{
|
||||
return (&**this);
|
||||
}
|
||||
|
||||
bool operator==( iterator_base & rhs ) const
|
||||
{
|
||||
if( m_pBinTree == rhs.m_pBinTree && m_uiCurIndex == rhs.m_uiCurIndex )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool operator!=( iterator_base & rhs ) const
|
||||
{
|
||||
return !operator==( rhs );
|
||||
}
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
if( m_pBinTree != NULL && m_uiCurIndex != 0 )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
unsigned GetIndex() const
|
||||
{
|
||||
return m_uiCurIndex;
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȸ - 1 2 4 8 9 5 10 11 3 6 12 13 7 14 15
|
||||
class iterator_preorder : public iterator_base
|
||||
{
|
||||
protected:
|
||||
void Inc()
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȿ<EFBFBD><C8BF> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȿ<EFBFBD>ϸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD> <20><>ȿ<EFBFBD>ϸ<EFBFBD> <20>θ<EFBFBD><CEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ư<EFBFBD><C6B0><EFBFBD>.
|
||||
//<2F>θ<EFBFBD> <20><><EFBFBD>尡 <20>湮<EFBFBD>ߴ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD≯<EFBFBD> <20>Ǵٽ<C7B4> <20>θ<EFBFBD><CEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
|
||||
if( m_pBinTree->IsValid( LeftChild( m_uiCurIndex ) ) )
|
||||
m_uiCurIndex = LeftChild( m_uiCurIndex );
|
||||
else if( m_pBinTree->IsValid( RightChild( m_uiCurIndex ) ) )
|
||||
m_uiCurIndex = RightChild( m_uiCurIndex );
|
||||
else
|
||||
{
|
||||
unsigned tempIndex;
|
||||
|
||||
while( m_uiCurIndex == RightChild( tempIndex = Parent( m_uiCurIndex ) )
|
||||
|| !m_pBinTree->IsValid( RightChild( tempIndex ) ) )
|
||||
{
|
||||
m_uiCurIndex = tempIndex;
|
||||
if( m_uiCurIndex == 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
m_uiCurIndex = RightChild( tempIndex );
|
||||
}
|
||||
}
|
||||
|
||||
void Dec()
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> ȣ<><C8A3><EFBFBD>ϸ<EFBFBD> <20>ٷ<EFBFBD> end<6E><64> <20>Ǿ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>س<EFBFBD><D8B3><EFBFBD>.
|
||||
m_uiCurIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator_preorder( CBinTree * pBinTree, unsigned index )
|
||||
: iterator_base( pBinTree, index )
|
||||
{
|
||||
}
|
||||
|
||||
iterator_preorder & operator++()
|
||||
{
|
||||
Inc();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
iterator_preorder operator++(int)
|
||||
{
|
||||
iterator_preorder tmp = *this;
|
||||
Inc();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
iterator_preorder & operator--()
|
||||
{
|
||||
Dec();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
iterator_preorder operator--(int)
|
||||
{
|
||||
iterator_preorder tmp = *this;
|
||||
Dec();
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȸ - 8 4 9 2 10 5 11 1 12 6 13 3 14 7 15
|
||||
class iterator_inorder
|
||||
{
|
||||
protected:
|
||||
void Inc()
|
||||
{
|
||||
//Leftmost<73><74> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ѵ<EFBFBD>.
|
||||
if( m_pBinTree->IsValid( RightChild( m_uiCurIndex ) ) )
|
||||
m_uiCurIndex = Min( RightChild( m_uiCurIndex ) );
|
||||
else
|
||||
{
|
||||
unsigned tempIndex;
|
||||
|
||||
while( m_uiCurIndex == RightChild( tempIndex = Parent( m_uiCurIndex ) ) )
|
||||
m_uiCurIndex = tempIndex;
|
||||
|
||||
m_uiCurIndex = tempIndex;
|
||||
}
|
||||
}
|
||||
|
||||
void Dec()
|
||||
{
|
||||
if( m_pBinTree->IsValid( LeftChild( m_uiCurIndex ) ) )
|
||||
m_uiCurIndex = Max( LeftChild( m_uiCurIndex ) );
|
||||
else
|
||||
{
|
||||
unsigned tempIndex;
|
||||
|
||||
while( m_uiCurIndex == LeftChild( tempIndex = Parent( m_uiCurIndex ) ) )
|
||||
m_uiCurIndex = tempIndex;
|
||||
|
||||
m_uiCurIndex = tempIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
iterator_inorder( CBinTree * pBinTree, unsigned index )
|
||||
: iterator_base( pBinTree, index )
|
||||
{
|
||||
}
|
||||
|
||||
iterator_inorder & operator++()
|
||||
{
|
||||
Inc();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
iterator_inorder operator++(int)
|
||||
{
|
||||
iterator_inorder tmp = *this;
|
||||
Inc();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
iterator_inorder & operator--()
|
||||
{
|
||||
Dec();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
iterator_inorder operator--(int)
|
||||
{
|
||||
iterator_inorder tmp = *this;
|
||||
Dec();
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ȸ - 0~n<><6E><EFBFBD><EFBFBD> <20><><EFBFBD>ʴ<EFBFBD><CAB4><EFBFBD> <20><>ȸ<EFBFBD>ϸ<EFBFBD> <20><>.
|
||||
class iterator_levelorder
|
||||
{
|
||||
public:
|
||||
iterator_levelorder( CBinTree * pBinTree, unsigned index )
|
||||
: iterator_base( pBinTree, index )
|
||||
{
|
||||
}
|
||||
|
||||
iterator_levelorder & operator++()
|
||||
{
|
||||
m_uiCurIndex++;
|
||||
return (*this );
|
||||
}
|
||||
|
||||
iterator_levelorder operator++(int)
|
||||
{
|
||||
iterator_levelorder tmp = *this;
|
||||
m_uiCurIndex++;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
iterator_levelorder & operator--()
|
||||
{
|
||||
m_uiCurIndex--;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
iterator_levelorder operator--(int)
|
||||
{
|
||||
iterator_levelorder tmp = *this;
|
||||
m_uiCurIndex--;
|
||||
return tmp;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
iterator_preorder Begin_preorder() { return iterator_preorder( this, 1 ); }
|
||||
iterator_levelorder Begin_levelorder() { return iterator_levelorder( this, 1 ); }
|
||||
|
||||
iterator_preorder End_preorder() { return iterator_preorder( this, 0 ); }
|
||||
iterator_levelorder End_levelorder() { return iterator_levelorder( this, m_TreeData.size() ); }
|
||||
|
||||
friend class iterator_base;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
271
Engine/Zalla3D Scene Class/BoidScene.cpp
Normal file
271
Engine/Zalla3D Scene Class/BoidScene.cpp
Normal file
@@ -0,0 +1,271 @@
|
||||
// BoidScene.cpp: implementation of the CBoidScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <time.h>
|
||||
#include "BoidScene.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
CBoidScene::CBoidScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CBoidScene::~CBoidScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CBoidScene::Create(int nBoid,int BoidObject)
|
||||
{
|
||||
srand(time(NULL));
|
||||
|
||||
m_nBoids=nBoid;
|
||||
m_pBoids=new BoidNode[nBoid];
|
||||
|
||||
m_BoidObject=BoidObject;
|
||||
|
||||
m_vecGoal=vector3(0.0f,0.0f,0.0f);
|
||||
|
||||
for(int i=0;i<m_nBoids;i++)
|
||||
{
|
||||
m_pBoids[i].m_vecLoc=vector3(i+10,i+10+150,i+10);
|
||||
m_pBoids[i].m_vecDir=vector3(1.0f,0.0f,0.0f);
|
||||
m_pBoids[i].m_fYaw=0.0f;
|
||||
m_pBoids[i].m_fPitch=0.0f;
|
||||
m_pBoids[i].m_fRoll=0.0f;
|
||||
m_pBoids[i].m_fDYaw=0.0f;
|
||||
m_pBoids[i].m_fSpeed=0.1f;
|
||||
m_pBoids[i].m_fAni=rnd()*2.0f;
|
||||
m_pBoids[i].m_fDist=new float[m_nBoids];
|
||||
}
|
||||
CSceneManager::m_MeshObjectContainer.SetPath(OBJECTPATH);
|
||||
m_pBoidObject[0]=CSceneManager::m_MeshObjectContainer.GetMeshObject("butter01.R3S");
|
||||
m_pBoidObject[1]=CSceneManager::m_MeshObjectContainer.GetMeshObject("butter02.R3S");
|
||||
|
||||
m_InfluenceRadius = 20.0f;
|
||||
m_InfluenceRadiusSquared = m_InfluenceRadius * m_InfluenceRadius;
|
||||
m_CollisionFraction = 0.8f;
|
||||
m_InvCollisionFraction = 1.0f/(1.0f-m_CollisionFraction);
|
||||
m_NormalSpeed = 0.1f;
|
||||
m_AngleTweak = 0.02f;
|
||||
m_PitchToSpeedRatio = 0.002f;
|
||||
}
|
||||
|
||||
void CBoidScene::Update(float fUpdate)
|
||||
{
|
||||
/*
|
||||
UpdateFlock();
|
||||
|
||||
matrix matWorld;
|
||||
matrix matRotateX,matRotateY,matRotateZ,matTemp;
|
||||
for(int i=0;i<m_nBoids;i++)
|
||||
{
|
||||
vector3 vecStep;
|
||||
matWorld.Translation(m_pBoids[i].m_vecLoc);
|
||||
|
||||
matRotateY.YRotation(-m_pBoids[i].m_fYaw);
|
||||
matRotateX.XRotation(-m_pBoids[i].m_fPitch);
|
||||
matRotateZ.ZRotation(-m_pBoids[i].m_fRoll);
|
||||
|
||||
matTemp=matRotateX*matRotateY;
|
||||
matTemp=matRotateZ*matTemp;
|
||||
matWorld=matTemp*matWorld;
|
||||
|
||||
m_pBoids[i].m_matLocal=matWorld;
|
||||
|
||||
m_pBoids[i].m_vecDir.x=matWorld._31;
|
||||
m_pBoids[i].m_vecDir.y=matWorld._32;
|
||||
m_pBoids[i].m_vecDir.z=matWorld._33;
|
||||
|
||||
m_pBoids[i].m_vecLoc+=m_pBoids[i].m_vecDir*m_pBoids[i].m_fSpeed;
|
||||
|
||||
m_pBoids[i].m_fAni+=0.3f;
|
||||
}
|
||||
static float tic = -200.0f * 1;
|
||||
tic += 0.01f;
|
||||
|
||||
m_vecGoal.x = 405.0f * (float)sin(tic*0.1f)+800;
|
||||
m_vecGoal.y = 150.0f;
|
||||
m_vecGoal.z = 405.0f * (float)cos(tic*0.1f)+800;
|
||||
*/
|
||||
|
||||
}
|
||||
void CBoidScene::UpdateFlock()
|
||||
{
|
||||
vector3 vecLens;
|
||||
float fDist;
|
||||
|
||||
for(int i=0;i<m_nBoids;i++)
|
||||
{
|
||||
for(int j=i+1;j<m_nBoids;j++)
|
||||
{
|
||||
vecLens=m_pBoids[i].m_vecLoc-m_pBoids[j].m_vecLoc;
|
||||
fDist=vecLens*vecLens;
|
||||
fDist=m_InfluenceRadiusSquared-fDist;
|
||||
|
||||
if(fDist<0.0f)
|
||||
fDist=0.0f;
|
||||
else
|
||||
fDist/=m_InfluenceRadiusSquared;
|
||||
|
||||
m_pBoids[i].m_fDist[j]=m_pBoids[j].m_fDist[i]=fDist;
|
||||
}
|
||||
m_pBoids[i].m_fDist[i]=0.0f;
|
||||
m_pBoids[i].m_vecDeltaDir=vector3(0.0f,0.0f,0.0f);
|
||||
m_pBoids[i].m_vecDeltaPos=vector3(0.0f,0.0f,0.0f);
|
||||
|
||||
m_pBoids[i].m_DeltaCnt=0;
|
||||
}
|
||||
|
||||
for(int i=0;i<m_nBoids;i++)
|
||||
{
|
||||
for(int j=i+1;j<m_nBoids;j++)
|
||||
{
|
||||
if(m_pBoids[i].m_fDist[j]>0.0f)
|
||||
{
|
||||
vector3 vecDiff=m_pBoids[i].m_vecLoc-m_pBoids[j].m_vecLoc;
|
||||
vecDiff.Normalize();
|
||||
|
||||
vector3 vecDelta;
|
||||
|
||||
float fCollWeight=0.0f;
|
||||
|
||||
if(m_pBoids[i].m_fDist[j]-m_CollisionFraction > 0.0f)
|
||||
fCollWeight=(m_pBoids[i].m_fDist[j]-m_CollisionFraction)
|
||||
*m_InvCollisionFraction;
|
||||
|
||||
if(m_pBoids[i].m_fDist[j]-(1.0f-m_CollisionFraction) >0.0f)
|
||||
fCollWeight-=m_pBoids[i].m_fDist[j]*(1.0f-fCollWeight);
|
||||
|
||||
|
||||
vecDelta=fCollWeight*vecDiff;
|
||||
|
||||
m_pBoids[i].m_vecDeltaPos+=vecDelta;
|
||||
m_pBoids[j].m_vecDeltaPos-=vecDelta;
|
||||
|
||||
m_pBoids[i].m_vecDeltaDir+=m_pBoids[j].m_vecDir*m_pBoids[i].m_fDist[j];
|
||||
m_pBoids[j].m_vecDeltaDir+=m_pBoids[i].m_vecDir*m_pBoids[i].m_fDist[j];
|
||||
|
||||
m_pBoids[i].m_DeltaCnt++;
|
||||
m_pBoids[j].m_DeltaCnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0;i<m_nBoids;i++)
|
||||
{
|
||||
if(m_pBoids[i].m_DeltaCnt)
|
||||
{
|
||||
m_pBoids[i].m_vecDeltaDir/=(float)m_pBoids[i].m_DeltaCnt;
|
||||
m_pBoids[i].m_vecDeltaDir-=m_pBoids[i].m_vecDir;
|
||||
m_pBoids[i].m_vecDeltaDir*=1.5f;
|
||||
}
|
||||
vector3 vecDelta=m_pBoids[i].m_vecDeltaDir+m_pBoids[i].m_vecDeltaPos;
|
||||
vector3 vecOffset;
|
||||
|
||||
vecLens=m_vecGoal-m_pBoids[i].m_vecLoc;
|
||||
vector3 vecGoal=0.5f*vecLens.Normalized();
|
||||
|
||||
vecDelta+=vecGoal;
|
||||
|
||||
if(vecDelta.y>0.01f)
|
||||
{
|
||||
m_pBoids[i].m_fPitch+=m_AngleTweak;
|
||||
if(m_pBoids[i].m_fPitch > 0.8f)
|
||||
m_pBoids[i].m_fPitch=0.8f;
|
||||
}
|
||||
else if(vecDelta.y<-0.01f)
|
||||
{
|
||||
m_pBoids[i].m_fPitch-=m_AngleTweak;
|
||||
if(m_pBoids[i].m_fPitch<-0.8f)
|
||||
m_pBoids[i].m_fPitch=-0.8f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pBoids[i].m_fPitch*=0.98f;
|
||||
}
|
||||
m_pBoids[i].m_fSpeed-=m_pBoids[i].m_fPitch*m_PitchToSpeedRatio;
|
||||
m_pBoids[i].m_fSpeed=(m_pBoids[i].m_fSpeed-m_NormalSpeed)*0.99f+m_NormalSpeed;
|
||||
|
||||
if(m_pBoids[i].m_fSpeed<m_NormalSpeed/2.0f)
|
||||
m_pBoids[i].m_fSpeed=m_NormalSpeed/2.0f;
|
||||
if(m_pBoids[i].m_fSpeed>m_NormalSpeed*5.0f)
|
||||
m_pBoids[i].m_fSpeed=m_NormalSpeed*5.0f;
|
||||
|
||||
vecOffset=vecDelta;
|
||||
vecOffset.y=0.0f;
|
||||
vecDelta=m_pBoids[i].m_vecDir;
|
||||
vecOffset.Normalize();
|
||||
|
||||
float fDot=vecOffset*vecDelta;
|
||||
|
||||
if(fDot>0.7f)
|
||||
{
|
||||
fDot-=0.7f;
|
||||
m_pBoids[i].m_fSpeed+=fDot*0.005f;
|
||||
}
|
||||
|
||||
vecOffset=vecOffset^vecDelta;
|
||||
fDot=(1.0f-fDot)/2.0f*0.07f;
|
||||
|
||||
if(vecOffset.y>0.05f)
|
||||
m_pBoids[i].m_fDYaw=(m_pBoids[i].m_fDYaw*19.0f+fDot)*0.05f;
|
||||
else if(vecOffset.y<-0.05f)
|
||||
m_pBoids[i].m_fDYaw=(m_pBoids[i].m_fDYaw*19.0f-fDot)*0.05f;
|
||||
else
|
||||
m_pBoids[i].m_fDYaw*=0.98f;
|
||||
|
||||
m_pBoids[i].m_fYaw+=m_pBoids[i].m_fDYaw;
|
||||
m_pBoids[i].m_fRoll=-m_pBoids[i].m_fDYaw*20.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void CBoidScene::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
/*
|
||||
pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
|
||||
pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,TRUE);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
|
||||
for(int i=0;i<m_nBoids;i++)
|
||||
{
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,m_pBoids[i].m_matLocal);
|
||||
|
||||
if(cosf(m_pBoids[i].m_fAni)>0.0f)
|
||||
m_pBoidObject[0]->Render(pd3dDevice);
|
||||
else
|
||||
m_pBoidObject[1]->Render(pd3dDevice);
|
||||
}
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,FALSE);
|
||||
*/
|
||||
}
|
||||
|
||||
void CBoidScene::DeleteBoid()
|
||||
{
|
||||
if(m_pBoids) {
|
||||
for(int i=0;i<m_nBoids;i++)
|
||||
{
|
||||
if(m_pBoids[i].m_fDist != NULL) {
|
||||
delete [] m_pBoids[i].m_fDist;
|
||||
m_pBoids[i].m_fDist = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
delete [] m_pBoids;
|
||||
m_pBoids = NULL;
|
||||
}
|
||||
}
|
||||
63
Engine/Zalla3D Scene Class/BoidScene.h
Normal file
63
Engine/Zalla3D Scene Class/BoidScene.h
Normal file
@@ -0,0 +1,63 @@
|
||||
// BoidScene.h: interface for the CBoidScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_BOIDSCENE_H__C74FEBE3_6C82_40E8_8862_3914033E05E0__INCLUDED_)
|
||||
#define AFX_BOIDSCENE_H__C74FEBE3_6C82_40E8_8862_3914033E05E0__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "3DMath.h"
|
||||
#include "MeshObject.h"
|
||||
|
||||
#define MIN(a,b) ((a<b)?a:b)
|
||||
#define MAX(a,b) ((a>b)?a:b)
|
||||
#define rnd() (((FLOAT)rand() ) / RAND_MAX)
|
||||
|
||||
class CBoidScene
|
||||
{
|
||||
class BoidNode
|
||||
{
|
||||
public:
|
||||
vector3 m_vecLoc;
|
||||
vector3 m_vecDir;
|
||||
vector3 m_vecDeltaPos;
|
||||
vector3 m_vecDeltaDir;
|
||||
int m_DeltaCnt;
|
||||
float m_fSpeed;
|
||||
float m_fYaw,m_fPitch,m_fRoll,m_fDYaw;
|
||||
color m_color;
|
||||
float *m_fDist;
|
||||
matrix m_matLocal;
|
||||
float m_fAni;
|
||||
};
|
||||
CMeshObject *m_pBoidObject[2];
|
||||
|
||||
public:
|
||||
void DeleteBoid();
|
||||
|
||||
int m_nBoids;
|
||||
int m_BoidObject;
|
||||
|
||||
float m_InfluenceRadius;
|
||||
float m_InfluenceRadiusSquared;
|
||||
float m_CollisionFraction;
|
||||
float m_InvCollisionFraction;
|
||||
float m_NormalSpeed;
|
||||
float m_AngleTweak;
|
||||
float m_PitchToSpeedRatio;
|
||||
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void UpdateFlock();
|
||||
void Update(float fUpdate);
|
||||
vector3 m_vecGoal;
|
||||
void Create(int nBoid,int BoidObject);
|
||||
BoidNode *m_pBoids;
|
||||
CBoidScene();
|
||||
virtual ~CBoidScene();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_BOIDSCENE_H__C74FEBE3_6C82_40E8_8862_3914033E05E0__INCLUDED_)
|
||||
819
Engine/Zalla3D Scene Class/BoidScene2.cpp
Normal file
819
Engine/Zalla3D Scene Class/BoidScene2.cpp
Normal file
@@ -0,0 +1,819 @@
|
||||
#include "boidscene2.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
|
||||
CBoidGroup::CBoidGroup() {
|
||||
|
||||
memset(m_BoidName,0,sizeof(char) * 256);
|
||||
|
||||
CloseGroup = -1;
|
||||
Space = LAND;
|
||||
limit.x = limit.y = limit.z = BOIDUNLIMIT;
|
||||
SeenRad = SEENDEFAULT;
|
||||
Pattern = BOIDGROUP;
|
||||
SubPattern = RELEASE;
|
||||
FearValue = FEARFULL;
|
||||
Unit_Num = 0;
|
||||
Lod = NOT;
|
||||
|
||||
Units = NULL;
|
||||
BoidBox = BOIDRAD;
|
||||
fwd.x = 1.0f;
|
||||
fwd.y = 0.0f;
|
||||
fwd.z = 0.3f;
|
||||
BoidMesh = NULL;
|
||||
Boid_Range.x = 0.0f;
|
||||
Boid_Range.y = 0.0f;
|
||||
Boid_Range.z = 0.0f;
|
||||
Boid_Speed = 1.0f;
|
||||
|
||||
m_SetPos.x = m_SetPos.y= m_SetPos.z = 0.0f;
|
||||
|
||||
srand(time(0));
|
||||
pat = 0;
|
||||
m_Pick = false;
|
||||
m_LimitHeight = 0.0f;
|
||||
m_CurrentFrame = timeGetTime();
|
||||
m_BeforeFrame = m_CurrentFrame;
|
||||
m_BoidKind = 0;
|
||||
|
||||
startup = false;
|
||||
tick = 0;
|
||||
|
||||
|
||||
}
|
||||
void CBoidGroup::SetBoidName(char *filename,char *path) {
|
||||
sprintf(m_BoidName,"%s\\%s",path,filename);
|
||||
|
||||
|
||||
}
|
||||
char *CBoidGroup::GetBoidName() {
|
||||
return m_BoidName;
|
||||
}
|
||||
// ȸ<><C8B8> :: <20><><EFBFBD>ֹ<EFBFBD><D6B9>̳<EFBFBD> <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʰ<EFBFBD> ȸ<><C8B8>
|
||||
void CBoidGroup::avoid()
|
||||
{
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>浹
|
||||
|
||||
//ȸ<><C8B8> :: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>浹 ȸ<><C8B8>
|
||||
void CBoidGroup::HeightSeparate(BoidUnit *boid,D3DXVECTOR3 *vec) {
|
||||
|
||||
//////////////////<2F>߰<EFBFBD><DFB0>Ǹ鼭 <20><><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD> <20>Ѵ<EFBFBD>.
|
||||
/*
|
||||
D3DXVECTOR3 field;
|
||||
D3DXVECTOR3 change;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> pos <20><><EFBFBD>ϱ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>)
|
||||
//GetHeigh(&field);
|
||||
//boid <20><>ġ <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD>ٸ<EFBFBD>..
|
||||
if(boid->pos.y < field.y) {
|
||||
field.y = boid->pos.y;
|
||||
change = boid->pos - field;
|
||||
// <20><>ġ <20><><EFBFBD><EFBFBD>
|
||||
boid->pos = boid->before_pos;
|
||||
|
||||
D3DXVec3Normalize(&change,&change);
|
||||
change *=MAX;
|
||||
|
||||
(*vec) +=change;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD> :: <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><><EFBFBD><EFBFBD> <20><>ǥ <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void CBoidGroup::concenter(BoidUnit *boid,D3DXVECTOR3 *vec) {
|
||||
D3DXVECTOR3 div_vec(0.0f,0.0f,0.0f);
|
||||
float length;
|
||||
int select_num = 0;
|
||||
D3DXVECTOR3 tmp(0.0f,0.0f,0.0f);
|
||||
|
||||
for(int i=0;i<Unit_Num;i++) {
|
||||
div_vec = boid->pos - Units[i].pos;
|
||||
length = D3DXVec3Length(&div_vec);
|
||||
if(length <BOIDRAD) {
|
||||
tmp +=Units[i].pos;
|
||||
select_num++;
|
||||
}
|
||||
}
|
||||
if(select_num) {
|
||||
tmp /= (float)select_num;
|
||||
|
||||
tmp -= boid->pos;
|
||||
D3DXVec3Normalize(&tmp,&tmp);
|
||||
tmp *=BMIN;
|
||||
|
||||
(*vec) +=tmp;
|
||||
}
|
||||
}
|
||||
void CBoidGroup::SetPos(float x,float y,float z) {
|
||||
m_SetPos.x = x;
|
||||
m_SetPos.y = y;
|
||||
m_SetPos.z = z;
|
||||
|
||||
}
|
||||
// <20>浹 <20><><EFBFBD>ϱ<EFBFBD> :: <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><> <20><><EFBFBD><EFBFBD> <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> <20>ʰ<EFBFBD>.
|
||||
void CBoidGroup::separate(BoidUnit *boid,D3DXVECTOR3 *vec) {
|
||||
|
||||
float length;
|
||||
|
||||
float r;
|
||||
int min_index = -1;
|
||||
float min_length;
|
||||
|
||||
D3DXVECTOR3 min_vec(0.0f,0.0f,0.0f);
|
||||
D3DXVECTOR3 change(0.0f,0.0f,0.0f);
|
||||
|
||||
float k = BOIDMAXLIMIT;
|
||||
|
||||
D3DXVECTOR3 tmp;
|
||||
|
||||
for(int i=0;i<Unit_Num;i++) {
|
||||
if(boid != (&Units[i])) {
|
||||
tmp = boid->pos - Units[i].pos;
|
||||
|
||||
length = D3DXVec3Length(&tmp);
|
||||
|
||||
if(length < k) {
|
||||
min_index = i;
|
||||
min_length = length;
|
||||
min_vec = Units[i].pos;
|
||||
k = length;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if( min_index == -1 )
|
||||
return;
|
||||
|
||||
// <20>ּ<EFBFBD> <20>Ÿ<EFBFBD>/<2F><><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
r = min_length/(BOIDRAD);
|
||||
// if(min_length < BOIDRAD) {
|
||||
change = Units[min_index].pos - boid->pos;
|
||||
|
||||
// <20>ʹ<EFBFBD> <20>۰ų<DBB0> Ŭ<><C5AC> r<><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (0.05~0.1 <20><><EFBFBD><EFBFBD>)
|
||||
if (r < BMIN)
|
||||
r = BMIN;
|
||||
if (r > BMAX)
|
||||
r = BMAX;
|
||||
// <20>浹 <20><><EFBFBD><EFBFBD> <20><><EFBFBD>϶<EFBFBD>
|
||||
if (min_length < BOIDRAD) {
|
||||
D3DXVec3Normalize(&change,&change);
|
||||
change *=(-0.01f);
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
(*vec) +=change;
|
||||
}
|
||||
// <20>浹 <20><><EFBFBD><EFBFBD> <20><><EFBFBD>϶<EFBFBD>
|
||||
else if (min_length> BOIDRAD) {
|
||||
D3DXVec3Normalize(&change,&change);
|
||||
change *=0.01f;
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
(*vec) +=change;
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD> :: <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><><EFBFBD><EFBFBD> <20><><EFBFBD>⺤<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void CBoidGroup::align(BoidUnit *boid,D3DXVECTOR3 *vec) {
|
||||
|
||||
float k = BOIDMAXLIMIT;
|
||||
int min_index = -1;
|
||||
|
||||
float length;
|
||||
|
||||
D3DXVECTOR3 change(0.0f,0.0f,0.0f);
|
||||
D3DXVECTOR3 tmp(0.0f,0.0f,0.0f);
|
||||
|
||||
for(int i=0;i<Unit_Num;i++) {
|
||||
if(boid != (&Units[i])) {
|
||||
|
||||
tmp = boid->pos - Units[i].pos;
|
||||
length = D3DXVec3Length(&tmp);
|
||||
|
||||
if(length < k) {
|
||||
min_index = i;
|
||||
k = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(min_index != -1) {
|
||||
change = Units[min_index].fwd;
|
||||
D3DXVec3Normalize(&change,&change);
|
||||
change *=BMIN;
|
||||
(*vec) +=change;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void CBoidGroup::RandomRot(CBoidGroup::BoidUnit *boid,float rot) {
|
||||
static int minus = 1;
|
||||
int mulyaxis = false;
|
||||
D3DXVECTOR3 tmp = boid->fwd;
|
||||
D3DXMATRIX mat;
|
||||
D3DXMATRIX ver;
|
||||
D3DXMatrixIdentity(&mat);
|
||||
D3DXMatrixIdentity(&ver);
|
||||
|
||||
ver._41 = tmp.x;
|
||||
ver._42 = tmp.y;
|
||||
ver._43 = tmp.z;
|
||||
|
||||
minus = minus > 0 ? -1 : 1;
|
||||
|
||||
|
||||
D3DXMatrixRotationY(&mat,D3DXToRadian(rot * (float)minus));
|
||||
//D3DXMatrixRotationX(&mat,D3DXToRadian(rot * (float)minus));
|
||||
|
||||
|
||||
D3DXMatrixMultiply(&mat,&ver,&mat);
|
||||
|
||||
boid->fwd.x = mat._41;
|
||||
boid->fwd.y = mat._42;
|
||||
boid->fwd.z = mat._43;
|
||||
|
||||
/* do {
|
||||
if(fabs(boid->fwd.y) < 0.1f)
|
||||
mulyaxis = true;
|
||||
else
|
||||
mulyaxis = false;
|
||||
boid->fwd.y *=10.0f;
|
||||
} while(mulyaxis);*/
|
||||
|
||||
}
|
||||
// <20><><EFBFBD>踦 <20><><EFBFBD> boid<69><64> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
|
||||
void CBoidGroup::Bound(CBoidGroup::BoidUnit *boid) {
|
||||
D3DXVECTOR3 tmp = boid->fwd;
|
||||
D3DXMATRIX mat;
|
||||
D3DXMATRIX ver;
|
||||
D3DXMatrixIdentity(&mat);
|
||||
D3DXMatrixIdentity(&ver);
|
||||
ver._41 = tmp.x;
|
||||
ver._42 = tmp.y;
|
||||
ver._43 = tmp.z;
|
||||
|
||||
switch(m_BoidKind) {
|
||||
case 0:
|
||||
D3DXMatrixRotationY(&mat,D3DXToRadian(2.0f));
|
||||
break;
|
||||
case 1:
|
||||
D3DXMatrixRotationY(&mat,D3DXToRadian(15.0f));
|
||||
break;
|
||||
}
|
||||
D3DXMatrixMultiply(&mat,&ver,&mat);
|
||||
|
||||
//float tmp;
|
||||
|
||||
float size_x = Boid_Range.x;
|
||||
float size_z= Boid_Range.z;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٲ<EFBFBD><D9B2><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
if(((boid->pos.x - m_SetPos.x) > size_x) || ((m_SetPos.x - boid->pos.x) > size_x)) {
|
||||
// tmp = (boid->fwd.x) * (-0.4f);
|
||||
// boid->fwd.x -= tmp;
|
||||
boid->fwd.x = mat._41;
|
||||
boid->fwd.y = mat._42;
|
||||
boid->fwd.z = mat._43;
|
||||
|
||||
|
||||
}
|
||||
if(((boid->pos.z - m_SetPos.z) > size_z) || ((m_SetPos.z - boid->pos.z) > size_z)) {
|
||||
// tmp = (boid->fwd.z) * (-0.4f);
|
||||
// boid->fwd.z -=tmp;
|
||||
boid->fwd.x = mat._41;
|
||||
boid->fwd.y = mat._42;
|
||||
boid->fwd.z = mat._43;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
if(boid->pos.x <(float)(TEST_SECNUM * TEST_SECSIZE))
|
||||
boid->pos.x = ((float)(TEST_SECNUM * TEST_SECSIZE) + TEST_SECSIZE);
|
||||
else if(boid->pos.x >((float)(TEST_SECNUM * TEST_SECSIZE) + TEST_SECSIZE))
|
||||
boid->pos.x = (float)(TEST_SECNUM * TEST_SECSIZE);
|
||||
|
||||
if(boid->pos.y <(float)(TEST_SECNUM * TEST_SECSIZE))
|
||||
boid->pos.y = ((float)(TEST_SECNUM * TEST_SECSIZE) + TEST_SECSIZE);
|
||||
else if(boid->pos.y >((float)(TEST_SECNUM * TEST_SECSIZE) + TEST_SECSIZE))
|
||||
boid->pos.y = (float)(TEST_SECNUM * TEST_SECSIZE);
|
||||
|
||||
if(boid->pos.z <(float)(TEST_SECNUM * TEST_SECSIZE))
|
||||
boid->pos.z = ((float)(TEST_SECNUM * TEST_SECSIZE) + TEST_SECSIZE);
|
||||
else if(boid->pos.z >((float)(TEST_SECNUM * TEST_SECSIZE) + TEST_SECSIZE))
|
||||
boid->pos.z = (float)(TEST_SECNUM * TEST_SECSIZE);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
CBoidGroup::~CBoidGroup() {
|
||||
|
||||
if(Unit_Num || (Units != NULL)) {
|
||||
delete[] Units;
|
||||
Units = NULL;
|
||||
}
|
||||
/* if(BoidMesh)
|
||||
delete BoidMesh;*/
|
||||
}
|
||||
void CBoidGroup::SetUnitNum(int n) {
|
||||
Unit_Num = n;
|
||||
Units = new BoidUnit[Unit_Num];
|
||||
|
||||
SetUnit();
|
||||
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD> <20>ܰ<EFBFBD> rot
|
||||
void CBoidGroup::RotSet(CBoidGroup::BoidUnit *U) {
|
||||
float roll, pitch, yaw;
|
||||
float lateDot;
|
||||
|
||||
D3DXVECTOR3 late,tmp;
|
||||
D3DXVECTOR3 tmp2;
|
||||
|
||||
// stop <20><><EFBFBD><EFBFBD>
|
||||
if(U->fwd == U->before_fwd)
|
||||
return;
|
||||
|
||||
tmp = U->fwd - U->before_fwd;
|
||||
|
||||
D3DXVec3Cross(&tmp2,&U->fwd,&tmp);
|
||||
|
||||
|
||||
D3DXVec3Cross(&late,&tmp2,&U->fwd);
|
||||
|
||||
D3DXVec3Normalize(&late,&late);
|
||||
|
||||
lateDot = D3DXVec3Dot(&tmp,&late);
|
||||
if (lateDot == 0) {
|
||||
roll = 0.0f;
|
||||
}
|
||||
else {
|
||||
roll = (float) -atan2(BGRAVITY, lateDot) + BHALF_PI;
|
||||
}
|
||||
|
||||
pitch = (float) -atan(U->fwd.y / sqrt((U->fwd.z * U->fwd.z ) + (U->fwd.x * U->fwd.x)));
|
||||
|
||||
yaw = (float) atan2(U->fwd.x, U->fwd.z);
|
||||
|
||||
U->rot[0] = pitch;
|
||||
U->rot[1] = yaw;
|
||||
U->rot[2] = roll;
|
||||
}
|
||||
void CBoidGroup::SetFwd() {
|
||||
int i;
|
||||
for(i=0;i<Unit_Num;i++) {
|
||||
Units[i].fwd.x = BRAND();
|
||||
Units[i].fwd.y = BRAND();
|
||||
Units[i].fwd.z = BRAND();
|
||||
|
||||
if(rand()%2)
|
||||
Units[i].fwd.x *=-1.0f;
|
||||
if(rand()%2)
|
||||
Units[i].fwd.y *=-1.0f;
|
||||
if(rand()%2)
|
||||
Units[i].fwd.z *=-1.0f;
|
||||
if(rand()%2) {
|
||||
//Units[i].fwd.x = Units[i].fwd.y = Units[i].fwd.z = 0.0f;
|
||||
//Units[i].before_fwd.x = Units[i].before_fwd.y = Units[i].before_fwd.z = 0.0f;
|
||||
}
|
||||
|
||||
//fwd length
|
||||
Units[i].speed = D3DXVec3Length(&Units[i].fwd);
|
||||
}
|
||||
|
||||
}
|
||||
void CBoidGroup::separate2(BoidUnit *boid) {
|
||||
int i;
|
||||
D3DXVECTOR3 tmp;
|
||||
D3DXVECTOR3 tf;
|
||||
float length;
|
||||
D3DXVECTOR3 min_vec;
|
||||
int min_index;
|
||||
float k = BOIDMAXLIMIT;
|
||||
|
||||
for(i=0;i<Unit_Num;i++) {
|
||||
if(boid != (&Units[i])) {
|
||||
tmp = boid->pos - Units[i].pos;
|
||||
length = D3DXVec3Length(&tmp);
|
||||
|
||||
if(length < k) {
|
||||
min_vec = tmp;
|
||||
min_index = i;
|
||||
k= length;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(k < BOIDRAD) {
|
||||
D3DXVec3Normalize(&min_vec,&min_vec);
|
||||
D3DXVec3Normalize(&tf,&boid->fwd);
|
||||
tmp = tf + min_vec;
|
||||
//ƨ<><C6A8><EFBFBD><EFBFBD>
|
||||
tmp *=BMIN;
|
||||
boid->fwd += tmp;
|
||||
}
|
||||
}
|
||||
void CBoidGroup::Update() {
|
||||
int i,j,count;
|
||||
|
||||
|
||||
|
||||
if(startup == false) {
|
||||
m_CurrentFrame = timeGetTime();
|
||||
m_BeforeFrame = m_CurrentFrame;
|
||||
startup = true;
|
||||
}
|
||||
|
||||
m_CurrentFrame = timeGetTime();
|
||||
|
||||
count = (int)(m_CurrentFrame - m_BeforeFrame)/30;
|
||||
|
||||
for(j=0;j<count;j++) {
|
||||
|
||||
m_CurrentFrame = timeGetTime();
|
||||
m_BeforeFrame = m_CurrentFrame;
|
||||
|
||||
D3DXVECTOR3 change(0.0f,0.0f,0.0f);
|
||||
|
||||
if(!(tick % 35))
|
||||
pat = (pat >0) ? 0:1;
|
||||
tick++;
|
||||
//pat = 1;
|
||||
|
||||
for(i=0;i<Unit_Num;i++) {
|
||||
|
||||
Units[i].frame+=(Units[i].vot);
|
||||
|
||||
if((Units[i].frame * BoidMesh->m_UnitF) >= BoidMesh->m_EndF) {
|
||||
|
||||
float kvalue = (float)((float)(Units[i].frame * BoidMesh->m_UnitF) / BoidMesh->m_EndF);
|
||||
Units[i].frame = (Units[i].frame * BoidMesh->m_UnitF) - (BoidMesh->m_EndF * kvalue);
|
||||
Units[i].frame /= (float)BoidMesh->m_UnitF;
|
||||
|
||||
if(Units[i].frame <= 0.0f)
|
||||
Units[i].frame = 0.0f;
|
||||
|
||||
//Units[i].vot = Units[i].backup_vot;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* if((Units[i].frame * BoidMesh->m_UnitF) >= BoidMesh->m_EndF) {
|
||||
|
||||
Units[i].frame = (BoidMesh->m_StartF / BoidMesh->m_UnitF);
|
||||
Units[i].vot = Units[i].backup_vot;
|
||||
|
||||
}
|
||||
*/
|
||||
// if(Units[i].active != SLEEP) {
|
||||
|
||||
Units[i].before_pos = Units[i].pos;
|
||||
Units[i].before_fwd = Units[i].fwd;
|
||||
Units[i].pos +=(Units[i].fwd);
|
||||
// <20><><EFBFBD><EFBFBD> <20>ൿ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(pat) {
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> group<75><70> boid <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>浹 <20><><EFBFBD><EFBFBD>(<28>⺻ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.0f)
|
||||
// <20><><EFBFBD>鸲<EFBFBD><E9B8B2> <20>־ BOIDRAD <20><><EFBFBD><EFBFBD> <20>͵鸸 <20><><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD> <20>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD>
|
||||
separate(&Units[i],&change);
|
||||
// <20><><EFBFBD><EFBFBD> boid <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
align(&Units[i],&change);
|
||||
//<2F><><EFBFBD><EFBFBD> :: <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><><EFBFBD><EFBFBD> <20><>ǥ <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
concenter(&Units[i],&change);
|
||||
randomvec(&Units[i],&change);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD><C7BE><EFBFBD> <20><><EFBFBD><EFBFBD> <20>߰<EFBFBD>
|
||||
if(D3DXVec3Length(&change) > BMAXCHANGE) {
|
||||
D3DXVec3Normalize(&change,&change);
|
||||
change *=BMAXCHANGE;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
separate2(&Units[i]);
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> üũ
|
||||
//HeightSeparate(&Units[i],&change);
|
||||
|
||||
Units[i].fwd +=change;
|
||||
|
||||
// <20><><EFBFBD>鸲 <20><><EFBFBD><EFBFBD> (y <20><> <20><> <20><><EFBFBD><EFBFBD>)
|
||||
Units[i].fwd.y *= 0.4f;
|
||||
|
||||
|
||||
//butterfly(Units[i]);
|
||||
|
||||
//speed <20><><EFBFBD><EFBFBD> (1.0)<29><><EFBFBD>Ϸ<EFBFBD>
|
||||
if ((Units[i].speed = D3DXVec3Length(&Units[i].fwd)) > BMAXSPEED) {
|
||||
D3DXVec3Normalize(&Units[i].fwd,&Units[i].fwd);
|
||||
Units[i].fwd *=(BMAXSPEED);
|
||||
Units[i].speed = BMAXSPEED;
|
||||
}
|
||||
// <20>ӵ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
(Units[i].fwd) *= Boid_Speed;
|
||||
switch(m_BoidKind) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if(!(tick % (30 /*+ (15 - (int)Boid_Speed)*/)))
|
||||
RandomRot(&Units[i],25.0f);
|
||||
break;
|
||||
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD> <20>϶<EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><>
|
||||
// <20>ӵ<EFBFBD><D3B5><EFBFBD> 15<31>϶<EFBFBD> 20 <20><><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD> <20>ѹ<EFBFBD><D1B9><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ
|
||||
|
||||
|
||||
Bound(&Units[i]);
|
||||
|
||||
RotSet(&Units[i]);
|
||||
// <20><><EFBFBD><EFBFBD> <20>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD> <20>浹<EFBFBD><E6B5B9> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
/* if(!pat) {
|
||||
//<2F><EFBFBD>Ʈ Land live
|
||||
if(Units[i].height<0)
|
||||
Units[i].pos.y++;
|
||||
else if(Units[i].height>0) {
|
||||
Units[i].pos.y--;
|
||||
}
|
||||
if(Units[i].pos.y == 500 || Units[i].pos.y == 0)
|
||||
Units[i].height *= (-1);
|
||||
}*/
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void CBoidGroup::randomvec(BoidUnit *boid,D3DXVECTOR3 *vec) {
|
||||
/*
|
||||
D3DXVECTOR3 tmp(0.0f,0.0f,0.0f);
|
||||
|
||||
|
||||
float diff = (boid->speed - 0.05f)/ MAX;
|
||||
float urgency = (float) fabs(diff);
|
||||
|
||||
|
||||
if (urgency < MIN) urgency = MIN;
|
||||
if (urgency > MAX) urgency = MAX;
|
||||
|
||||
float jitter = RAND();
|
||||
|
||||
if (jitter < 0.45f) {
|
||||
vec->x += MIN * SIGN(diff);
|
||||
} else if (jitter < 0.90f) {
|
||||
vec->z += MIN * SIGN(diff);
|
||||
} else {
|
||||
vec->y += MIN * SIGN(diff);
|
||||
}
|
||||
|
||||
if(rand() %2)
|
||||
(*vec) *= -0.001;
|
||||
else
|
||||
(*vec) *= 0.001;
|
||||
//if(rand() %10 == 7)
|
||||
|
||||
/* if(rand() %2) {
|
||||
tmp.x = rand()%10 -5;
|
||||
tmp.y = rand()%10 -5;
|
||||
tmp.z = rand()%10 -5;
|
||||
|
||||
(*vec) += tmp;
|
||||
// if(rand() %2)
|
||||
// boid->fwd.x = boid->fwd.y = boid->fwd.z = 0.0f;
|
||||
}*/
|
||||
}
|
||||
void CBoidGroup::SetUnitVot(float vot) {
|
||||
for(int i=0;i<Unit_Num;i++) {
|
||||
Units[i].vot = vot;
|
||||
Units[i].backup_vot = vot;
|
||||
|
||||
}
|
||||
}
|
||||
void CBoidGroup::SetUnit() {
|
||||
int i;
|
||||
// boid <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> set
|
||||
float last_frame = (float)((float)BoidMesh->m_EndF / BoidMesh->m_UnitF);
|
||||
|
||||
float frame_set[6] = {0.0f,
|
||||
last_frame * (1.0f/5.0f),
|
||||
last_frame * (2.0f/5.0f),
|
||||
last_frame * (3.0f/5.0f),
|
||||
last_frame * (4.0f/5.0f),
|
||||
last_frame * (5.0f/5.0f),
|
||||
};
|
||||
|
||||
//SECTORSIZE
|
||||
|
||||
for(i=0;i<Unit_Num;i++) {
|
||||
Units[i].rot[0] = Units[i].rot[1] = Units[i].rot[2] = 0.0f;
|
||||
|
||||
// pos
|
||||
Units[i].pos.x = m_SetPos.x + (float)(rand()%(int)Boid_Range.x);
|
||||
Units[i].pos.y = m_SetPos.y + (float)(rand()%(int)Boid_Range.y);
|
||||
Units[i].pos.z = m_SetPos.z + (float)(rand()%(int)Boid_Range.z);
|
||||
|
||||
if(Units[i].pos.y < m_SetPos.y + m_LimitHeight) { // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
Units[i].pos.y = m_SetPos.y + m_LimitHeight;
|
||||
|
||||
}
|
||||
|
||||
// live
|
||||
Units[i].Live = true;
|
||||
Units[i].active = rand()%5;
|
||||
|
||||
Units[i].fwd.x = BRAND();
|
||||
Units[i].fwd.y = BRAND();
|
||||
Units[i].fwd.z = BRAND();
|
||||
|
||||
Units[i].height = -1;
|
||||
|
||||
if(rand()%2)
|
||||
Units[i].fwd.x *=-1.0f;
|
||||
if(rand()%2)
|
||||
Units[i].fwd.y *=-1.0f;
|
||||
if(rand()%2)
|
||||
Units[i].fwd.z *=-1.0f;
|
||||
|
||||
//fwd length
|
||||
Units[i].speed = D3DXVec3Length(&Units[i].fwd);
|
||||
|
||||
Units[i].vot = 1.0f;
|
||||
Units[i].frame = frame_set[(rand() % 6)];
|
||||
|
||||
Units[i].backup_frame = Units[i].frame;
|
||||
|
||||
//BoidMesh->SetVot(Units[i].vot);
|
||||
|
||||
/* //speed
|
||||
switch(SubPattern) {
|
||||
case RELEASE:
|
||||
//Units[i].fwd.x = 0.1f;
|
||||
//Units[i].fwd.y = 0.0f;
|
||||
//Units[i].fwd.z = 1.0f;
|
||||
|
||||
|
||||
break;
|
||||
case AVOID:
|
||||
|
||||
Units[i].fwd.x = fwd.x + (float)(rand()%1000)/1000.0f - 0.5f;
|
||||
Units[i].fwd.y = fwd.y + (float)(rand()%1000)/1000.0f - 0.5f;
|
||||
Units[i].fwd.z = fwd.z + (float)(rand()%1000)/1000.0f - 0.5f;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
switch(Units[i].active) {
|
||||
case SLEEP:
|
||||
Units[i].fwd.x = Units[i].fwd.y = Units[i].fwd.z =0.0f;
|
||||
break;
|
||||
case PEACE:
|
||||
Units[i].fwd.x = (float)(rand()%1000)/1000.0f - 0.5f;
|
||||
Units[i].fwd.y = 0.0f;//(float)(rand()%1000)/1000.0f - 0.5f;
|
||||
Units[i].fwd.z = (float)(rand()%1000)/1000.0f - 0.5f;
|
||||
Units[i].fwd *= 0.1f;
|
||||
break;
|
||||
case WALK:
|
||||
Units[i].fwd.x = fwd.x;
|
||||
Units[i].fwd.y = 0.0f;//fwd.y;
|
||||
Units[i].fwd.z = fwd.z;
|
||||
Units[i].fwd *=0.01f;
|
||||
break;
|
||||
case RUN:
|
||||
Units[i].fwd.x = fwd.x;
|
||||
Units[i].fwd.y = 0.0f;//fwd.y;
|
||||
Units[i].fwd.z = fwd.z;
|
||||
break;
|
||||
case FLYING:
|
||||
Units[i].fwd.x = fwd.x;
|
||||
Units[i].fwd.y = fwd.y;
|
||||
Units[i].fwd.z = fwd.z;
|
||||
break;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
switch(Space) {
|
||||
case LAND:
|
||||
// Units[i].pos.y = GetHeight(Units[i].pos.x,Units[i].pos.z);
|
||||
// Units[i].speed.y = 0.0f;
|
||||
// Units[i].pos.y = 0.0f;
|
||||
// Units[i].pos.y = 0.0f;
|
||||
// Units[i].fwd.y = 0.0f;
|
||||
|
||||
|
||||
|
||||
break;
|
||||
case WATER:
|
||||
break;
|
||||
case FLY:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CBoidGroup::butterfly(CBoidGroup::BoidUnit &Unit){
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> y<><79> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// Unit.fwd.y += 0.3f;
|
||||
if(Unit.m_fly<100) {
|
||||
|
||||
Unit.pos.y += 1.0f;
|
||||
Unit.m_fly++;
|
||||
}
|
||||
else if(Unit.m_fly >=100 && Unit.m_fly <=200){
|
||||
Unit.pos.y -= 1.0f;
|
||||
Unit.m_fly++;
|
||||
}
|
||||
else if(Unit.m_fly >200){
|
||||
Unit.m_fly = 0;
|
||||
}
|
||||
|
||||
}
|
||||
bool CBoidGroup::Render(LPDIRECT3DDEVICE8 device) {
|
||||
D3DXMATRIX world;
|
||||
device->GetTransform(D3DTS_WORLD,&world);
|
||||
|
||||
|
||||
D3DXMATRIX back = world;
|
||||
D3DXMATRIX quater;
|
||||
D3DXQUATERNION qt;
|
||||
int i;
|
||||
|
||||
|
||||
D3DXMatrixIdentity(&quater);
|
||||
int lod = 0;
|
||||
switch(lod) {
|
||||
case NOT:
|
||||
for(i=0;i<Unit_Num;i++) {
|
||||
world = back;
|
||||
|
||||
|
||||
D3DXQuaternionRotationYawPitchRoll(&qt,Units[i].rot[1],Units[i].rot[0],Units[i].rot[2]);
|
||||
D3DXMatrixRotationQuaternion(&world,&qt);
|
||||
|
||||
world._41 = Units[i].pos.x;
|
||||
world._42 = Units[i].pos.y;
|
||||
world._43 = Units[i].pos.z;
|
||||
|
||||
if(strstr(m_BoidName,"Boid_Gull_T1.GEM") != NULL)
|
||||
world._42 += 1500.0f;
|
||||
|
||||
|
||||
|
||||
|
||||
BoidMesh->SetTransMatrix(world);
|
||||
|
||||
/*if((Units[i].frame * BoidMesh->m_UnitF) >= BoidMesh->m_EndF) {
|
||||
|
||||
float kvalue = (float)((float)(Units[i].frame * BoidMesh->m_UnitF) / BoidMesh->m_EndF);
|
||||
Units[i].frame = (Units[i].frame * BoidMesh->m_UnitF) - (BoidMesh->m_EndF * kvalue);
|
||||
Units[i].frame /= (float)BoidMesh->m_UnitF;
|
||||
|
||||
if(Units[i].frame <= 0.0f)
|
||||
Units[i].frame = 0.0f;
|
||||
|
||||
//Units[i].vot = Units[i].backup_vot;
|
||||
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if((Units[i].frame * BoidMesh->m_UnitF) >= BoidMesh->m_EndF) {
|
||||
|
||||
//Units[i].frame = (BoidMesh->m_StartF / BoidMesh->m_UnitF);
|
||||
Units[i].frame = (int)(Units[i].frame * BoidMesh->m_UnitF) % (int)BoidMesh->m_EndF;
|
||||
if(Units[i].frame <= 0.0f)
|
||||
Units[i].frame = 0.0f;
|
||||
else
|
||||
Units[i].frame /= (float)BoidMesh->m_UnitF;
|
||||
|
||||
Units[i].vot = Units[i].backup_vot;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
//BOID <20><><EFBFBD><EFBFBD> <20>÷<EFBFBD><C3B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٸ<EFBFBD><D9B8><EFBFBD>
|
||||
BoidMesh->SetCurrentFrame(Units[i].frame);
|
||||
BoidMesh->SetBlend(D3DBLEND_ONE,D3DBLEND_ZERO);
|
||||
BoidMesh->SetNullTexture(m_Pick);
|
||||
BoidMesh->Render();
|
||||
|
||||
//Update();
|
||||
|
||||
|
||||
//BoidMesh->Update();
|
||||
}
|
||||
break;
|
||||
case MIDDLE:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
242
Engine/Zalla3D Scene Class/BoidScene2.h
Normal file
242
Engine/Zalla3D Scene Class/BoidScene2.h
Normal file
@@ -0,0 +1,242 @@
|
||||
#ifndef __BOID_H__
|
||||
#define __BOID_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <d3dx8.h>
|
||||
#include "CGemRender.h"
|
||||
#include <time.h>
|
||||
|
||||
//#include "datadefine.h"
|
||||
//#include " SectorDefine.h"
|
||||
|
||||
#define BOIDUNLIMIT -100000
|
||||
#define BOIDMAXLIMIT 10000000
|
||||
|
||||
#define SEENDEFAULT 50.0f
|
||||
#define FEARFULL 1.0f
|
||||
#define NOTFEAR 0.0f
|
||||
//separate
|
||||
#define BOIDRAD 10.0f
|
||||
//align
|
||||
#define ALIGN 0.00005f
|
||||
|
||||
#define TEST_SECNUM 0
|
||||
#define TEST_SECSIZE 800
|
||||
#define BPI 3.14159f
|
||||
#define BHALF_PI (BPI/2)
|
||||
#define BGRAVITY 9.806650f
|
||||
// 0~1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> return
|
||||
#define BRAND() (float) (rand()/(RAND_MAX * 1.0))
|
||||
|
||||
//change value
|
||||
#define BMAXSPEED 0.5f
|
||||
#define BMIN 0.05f
|
||||
#define BMAX 0.1f
|
||||
#define BMAXCHANGE (BMAXSPEED * BMAX)
|
||||
//#define BDesiredSpeed (BMAXSPEED/2)
|
||||
|
||||
enum SPACE{ LAND,
|
||||
WATER,
|
||||
FLY};
|
||||
enum PAT{ BOIDGROUP,
|
||||
INDIVIDUAL};
|
||||
// <20><><EFBFBD><EFBFBD> <20>ൿ<EFBFBD><E0B5BF><EFBFBD><EFBFBD> (ȸ<><C8B8>,<2C><EFBFBD>,<2C>л<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||||
enum SUBPAT{ AVOID,
|
||||
RELEASE,
|
||||
SPREAD,
|
||||
SAMELOOK,
|
||||
MASTER
|
||||
};
|
||||
|
||||
enum LOD{ NOT,
|
||||
MIDDLE,
|
||||
FAR
|
||||
};
|
||||
enum ACT{ SLEEP,
|
||||
PEACE,
|
||||
WALK,
|
||||
RUN,
|
||||
FLYING
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CBoidGroup{
|
||||
public:
|
||||
// <20>Ϲ<EFBFBD> <20><><EFBFBD>̵<EFBFBD> <20><><EFBFBD><EFBFBD>ü
|
||||
class BoidUnit {
|
||||
public:
|
||||
BoidUnit() {
|
||||
pos.x = pos.y = pos.z = 0.0f;
|
||||
before_pos = pos;
|
||||
Live = true;
|
||||
rot[0] = rot[1] =rot[2] = 0.0f;
|
||||
speed = 0.0f;
|
||||
look.x = look.y = look.z = 0.0f;
|
||||
before_look.x = before_look.y = before_look.z = 0.0f;
|
||||
fwd.x = fwd.y =fwd.z = 0.0f;
|
||||
before_fwd.x = before_fwd.y = before_fwd.z = 0.0f;
|
||||
vot = 1.0f;
|
||||
backup_vot = vot;
|
||||
backup_frame = 0.0f;
|
||||
active = 0;
|
||||
height = -1;
|
||||
frame = 0.0f;
|
||||
m_fly = 0;
|
||||
start_vot = 0.0f;
|
||||
}
|
||||
~BoidUnit() {
|
||||
|
||||
}
|
||||
bool Live;
|
||||
float frame;
|
||||
D3DXVECTOR3 pos;
|
||||
D3DXVECTOR3 before_pos;
|
||||
|
||||
//ȸ<><C8B8> <20><>
|
||||
// D3DXVECTOR3 rotaxis;
|
||||
float rot[3];
|
||||
|
||||
//speed (fwd<77><64> length)
|
||||
float speed;
|
||||
|
||||
// <20><>ǥ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
D3DXVECTOR3 look;
|
||||
D3DXVECTOR3 before_look;
|
||||
|
||||
D3DXVECTOR3 fwd;
|
||||
D3DXVECTOR3 before_fwd;
|
||||
int height;
|
||||
// <20><EFBFBD><EEB5BF><EFBFBD><EFBFBD>
|
||||
int active;
|
||||
float vot;
|
||||
float backup_vot;
|
||||
float backup_frame;
|
||||
|
||||
float start_vot;
|
||||
int m_fly;
|
||||
|
||||
};
|
||||
|
||||
CBoidGroup();
|
||||
~CBoidGroup();
|
||||
// Boid Mesh Name setting
|
||||
void SetBoidName(char *filename,char *path);
|
||||
char *GetBoidName();
|
||||
|
||||
void RandomRot(BoidUnit *, float );
|
||||
|
||||
// boid Update
|
||||
// õ<><C3B5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Update
|
||||
void Update();
|
||||
void SetSpace(int s) { Space = s; }
|
||||
// ȸ<><C8B8> :: <20><><EFBFBD>ֹ<EFBFBD><D6B9>̳<EFBFBD> <20>ٸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʰ<EFBFBD> ȸ<><C8B8>
|
||||
void avoid();
|
||||
|
||||
// <20>浹 <20><><EFBFBD>ϱ<EFBFBD> :: <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><> <20><><EFBFBD><EFBFBD> <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> <20>ʰ<EFBFBD>.
|
||||
void separate(BoidUnit *,D3DXVECTOR3 *);
|
||||
// <20>浹<EFBFBD><E6B5B9><EFBFBD>ϱ<EFBFBD> :: <20><><EFBFBD><EFBFBD><EFBFBD>ൿ <20><><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void separate2(BoidUnit *);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>浹 <20><><EFBFBD>ϱ<EFBFBD>
|
||||
void HeightSeparate(BoidUnit *,D3DXVECTOR3 *);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD> :: <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><><EFBFBD><EFBFBD> <20><><EFBFBD>⺤<EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void align(BoidUnit *,D3DXVECTOR3 *);
|
||||
//<2F><><EFBFBD><EFBFBD> :: <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><><EFBFBD><EFBFBD> <20><>ǥ <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void concenter(BoidUnit *,D3DXVECTOR3 *);
|
||||
void randomvec(BoidUnit *,D3DXVECTOR3 *);
|
||||
// rot setting
|
||||
void RotSet(BoidUnit *);
|
||||
|
||||
// <20><><EFBFBD>踦 <20><><EFBFBD> boid<69><64> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
|
||||
void Bound(BoidUnit *);
|
||||
|
||||
void SetUnit();
|
||||
void SetBoidSpeed(float s) {
|
||||
Boid_Speed = s;
|
||||
}
|
||||
void SetBoidRange(float x,float y,float z,float limit) {
|
||||
Boid_Range.x = x;
|
||||
Boid_Range.y = y;
|
||||
Boid_Range.z = z;
|
||||
m_LimitHeight = limit;
|
||||
|
||||
}
|
||||
|
||||
// Boid Render failed : 0 return
|
||||
bool Render(LPDIRECT3DDEVICE8 );
|
||||
// <20><EFBFBD><EEB5BF><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(0 : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1: <20><><EFBFBD><EFBFBD><EFBFBD>ൿ<EFBFBD><E0B5BF>)
|
||||
void SetPat(int v) {pat = v;}
|
||||
int GetPat() { return pat;}
|
||||
void SetUnitVot(float vot);
|
||||
void SetPos(float x,float y,float z);
|
||||
void CreateMaster();
|
||||
float GetHeight(float x,float z);
|
||||
|
||||
void SetMesh(CGemRender *mesh) {BoidMesh = mesh;}
|
||||
void SetFwd(D3DXVECTOR3 sp) { fwd = sp; }
|
||||
void SetFwd(float x,float y,float z) { fwd.x = x;fwd.y = y;fwd.z = z;}
|
||||
void SetFwd();
|
||||
void SetPick(bool b) {m_Pick = b;}
|
||||
|
||||
void SetBoidKind(int v) {m_BoidKind = v;}
|
||||
|
||||
void SetUnitNum(int n);
|
||||
void butterfly(BoidUnit &);
|
||||
|
||||
int pat;
|
||||
private:
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ϴ<EFBFBD> <20><>Ȳ <20><><EFBFBD><EFBFBD>.(<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ִ<EFBFBD> <20><EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||||
int CloseGroup;
|
||||
// <20><><EFBFBD><EFBFBD> <20><>
|
||||
int Space;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..)
|
||||
D3DXVECTOR3 limit;
|
||||
// Speed
|
||||
D3DXVECTOR3 fwd;
|
||||
D3DXVECTOR3 m_SetPos;
|
||||
// <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> boid <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>浹<EFBFBD><E6B5B9> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float BoidBox;
|
||||
|
||||
// <20><> <20><EFBFBD><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20>νİ<CEBD><C4B0><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
float SeenRad;
|
||||
// <20><> <20><><EFBFBD>̵<EFBFBD> <20><EFBFBD><D7B7><EFBFBD> <20>ൿ <20><><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>,<2C><>ü)
|
||||
int Pattern;
|
||||
// <20><><EFBFBD><EFBFBD> <20>ൿ<EFBFBD><E0B5BF><EFBFBD><EFBFBD> (ȸ<><C8B8>,<2C><EFBFBD>,<2C>л<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||||
int SubPattern;
|
||||
// <20≯<EFBFBD><CCB8><EFBFBD> <20><EFBFBD> <20><><EFBFBD><EFBFBD> <20><EFBFBD> (0.0f~1.0f)
|
||||
float FearValue;
|
||||
|
||||
|
||||
// Boid Unit Number
|
||||
int Unit_Num;
|
||||
int Lod;
|
||||
//sector id
|
||||
int SecX,SecY;
|
||||
|
||||
|
||||
BoidUnit *Units;
|
||||
// move range
|
||||
D3DXVECTOR3 Boid_Range;
|
||||
float m_LimitHeight;
|
||||
|
||||
// speed
|
||||
float Boid_Speed;
|
||||
|
||||
// Boid<69><64> Mesh Data
|
||||
CGemRender *BoidMesh;
|
||||
char m_BoidName[256];
|
||||
bool m_Pick;
|
||||
unsigned long m_BeforeFrame;
|
||||
unsigned long m_CurrentFrame;
|
||||
int m_BoidKind;
|
||||
bool startup;
|
||||
int tick;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
525
Engine/Zalla3D Scene Class/BspDataDefine.h
Normal file
525
Engine/Zalla3D Scene Class/BspDataDefine.h
Normal file
@@ -0,0 +1,525 @@
|
||||
#pragma once
|
||||
|
||||
#include "3DMath.h"
|
||||
#include "Vertex.h"
|
||||
|
||||
/*
|
||||
*/
|
||||
|
||||
#define CONTENTS_DETAIL 0x8000000
|
||||
|
||||
#define MAX_SURFACE_VERTS 256
|
||||
#define MAX_MAP_SHADER 0xff
|
||||
#define MAX_MAP_MODELS 0x400
|
||||
#define MAX_MAP_DRAW_SURFS 0x20000
|
||||
#define MAX_MAP_DRAW_VERTS 0x80000
|
||||
#define MAX_MAP_DRAW_INDEXES 0x80000
|
||||
#define MAX_MAP_NODES 0x20000
|
||||
#define MAX_MAP_LEAFS 0x20000
|
||||
#define MAX_MAP_LEAFFACES 0x20000
|
||||
#define MAX_MAP_LEAFBRUSHES 0x40000
|
||||
#define MAX_MAP_BRUSHSIDES 0x20000
|
||||
#define MAX_MAP_BRUSHES 0x8000
|
||||
#define MAX_MAP_VISIBILITY 0x100000
|
||||
|
||||
#define MAX_STARTPOSITION 100
|
||||
#define MAX_LIGHT 0xff
|
||||
|
||||
#define MAX_PATCH_SIZE 32
|
||||
|
||||
|
||||
#define LUMP_ENTITIES 0
|
||||
#define LUMP_SHADERS 1
|
||||
#define LUMP_PLANES 2
|
||||
#define LUMP_NODES 3
|
||||
#define LUMP_LEAFS 4
|
||||
#define LUMP_LEAFSURFACES 5
|
||||
#define LUMP_LEAFBRUSHES 6
|
||||
#define LUMP_MODELS 7
|
||||
#define LUMP_BRUSHES 8
|
||||
#define LUMP_BRUSHSIDES 9
|
||||
#define LUMP_DRAWVERTS 10
|
||||
#define LUMP_DRAWINDEXES 11
|
||||
#define LUMP_FOGS 12
|
||||
#define LUMP_SURFACES 13
|
||||
#define LUMP_LIGHT 14
|
||||
#define LUMP_LIGHTGRID 15
|
||||
#define LUMP_VISIBILITY 16
|
||||
#define HEADER_LUMPS 17
|
||||
|
||||
#define MAX_EXPANDED_AXIS 128
|
||||
#define SUBDIVISION_LIMIT 8.0
|
||||
|
||||
#define PLANE_X 0
|
||||
#define PLANE_Y 1
|
||||
#define PLANE_Z 2
|
||||
#define PLANE_NON_AXIAL 3
|
||||
|
||||
#define ON_EPSILON 0.01
|
||||
|
||||
class Lump
|
||||
{
|
||||
public:
|
||||
int m_Fileofs;
|
||||
int m_Filelen;
|
||||
};
|
||||
|
||||
class DHeader
|
||||
{
|
||||
public:
|
||||
int m_Ident;
|
||||
int m_Version;
|
||||
Lump m_Lump[HEADER_LUMPS];
|
||||
};
|
||||
|
||||
#define PLANE_HASHES 1024
|
||||
#define NORMAL_EPSILON 0.0001
|
||||
#define DIST_EPSILON 0.02
|
||||
|
||||
class SPlane {
|
||||
public:
|
||||
vector3 m_vecNormal;
|
||||
float m_fDist;
|
||||
int m_Type;
|
||||
SPlane *m_pHash_Chain;
|
||||
};
|
||||
|
||||
#define MAX_POINTS_ON_WINDING 64
|
||||
#define MAX_POINTS_ON_FIXED_WINDING 12
|
||||
|
||||
class SWinding {
|
||||
public:
|
||||
int m_nPoints;
|
||||
vector3 m_vecPoints[MAX_POINTS_ON_FIXED_WINDING];
|
||||
//vector3 m_vecPoints[4];
|
||||
};
|
||||
|
||||
class SBspFace {
|
||||
public:
|
||||
SBspFace *m_pNext;
|
||||
int m_nPlane;
|
||||
int m_Priority;
|
||||
bool m_bChecked;
|
||||
bool m_bHint;
|
||||
SWinding *m_pWinding;
|
||||
};
|
||||
|
||||
|
||||
class SSide {
|
||||
public:
|
||||
int m_nPlane;
|
||||
float m_fTexMat[2][2];// Brush Primitive Texture matrix;
|
||||
float m_fvecs[2][4];// Texture Coordinate mapping
|
||||
|
||||
SWinding *m_pWinding;
|
||||
SWinding *m_pVisibleHull;
|
||||
|
||||
int m_nShader;
|
||||
|
||||
//struct shaderInfo_s *shaderInfo;
|
||||
|
||||
int m_Contents;
|
||||
int m_SurfaceFlags;
|
||||
int m_Value;
|
||||
|
||||
bool m_bVisible;
|
||||
bool m_bBevel;
|
||||
bool m_bBackSide;
|
||||
};
|
||||
|
||||
#define MAX_BRUSH_SIDES 1024
|
||||
|
||||
class SBspBrush {
|
||||
public:
|
||||
SBspBrush *m_pNext;
|
||||
int m_nEntity;
|
||||
int m_nBrush;
|
||||
|
||||
int m_nShader;
|
||||
//struct shaderInfo_s *contentShader;
|
||||
|
||||
int m_Contents;
|
||||
bool m_bDetail;
|
||||
bool m_bOpaque;
|
||||
int m_nOutPut;
|
||||
int m_PortalAreas[2];
|
||||
|
||||
SBspBrush *m_pOriginal;
|
||||
|
||||
vector3 m_vecMin,m_vecMax;
|
||||
int m_nSides;
|
||||
|
||||
SSide m_Sides[6];
|
||||
};
|
||||
|
||||
class SNode;
|
||||
|
||||
class SDrawSurRef
|
||||
{
|
||||
public:
|
||||
SDrawSurRef *m_pNextRef;
|
||||
int m_OutputNumber;
|
||||
};
|
||||
|
||||
class SPortal {
|
||||
public:
|
||||
SPlane m_Plane;
|
||||
SNode *m_pOnNode;
|
||||
SNode *m_pNodes[2];
|
||||
SPortal *m_pNext[2];
|
||||
SWinding *m_pWinding;
|
||||
|
||||
bool m_bSideFound;
|
||||
bool m_bHint;
|
||||
SSide *m_pSide;
|
||||
};
|
||||
|
||||
class SNode {
|
||||
public:
|
||||
int m_nPlane;
|
||||
SNode *m_pParent;
|
||||
vector3 m_vecMin,m_vecMax;
|
||||
SBspBrush *m_pVolume;
|
||||
|
||||
SSide *m_Side;
|
||||
SNode *m_pChildren[2];
|
||||
bool m_bHint;
|
||||
int m_nTinyPortals;
|
||||
vector3 m_vecReferencePoint;
|
||||
|
||||
bool m_bOpaque;
|
||||
bool m_bAreaPortal;
|
||||
int m_Cluster;
|
||||
int m_Area;
|
||||
SBspBrush *m_pBrushList;
|
||||
SDrawSurRef *m_pDrawSurfReferences;
|
||||
int m_Occupied;
|
||||
SPortal *m_pPortal;
|
||||
};
|
||||
|
||||
class STree {
|
||||
public:
|
||||
SNode *m_pHeadNode;
|
||||
SNode m_OutSideNode;
|
||||
vector3 m_vecMin,m_vecMax;
|
||||
};
|
||||
|
||||
class SDrawSurf
|
||||
{
|
||||
public:
|
||||
int m_nShader;
|
||||
SBspBrush *m_MapBrush;
|
||||
SSide *m_Side;
|
||||
SDrawSurf *m_pNextOnShader;
|
||||
|
||||
int m_nFog;
|
||||
int m_nLightmap;
|
||||
int m_nLightmapX,m_nLightmapY;
|
||||
int m_LightmapWidth,m_LightmapHeight;
|
||||
|
||||
int m_nVerts;
|
||||
BspVertex *m_pVerts;
|
||||
|
||||
int m_nIndex;
|
||||
int *m_pIndex;
|
||||
|
||||
int m_nPlane;
|
||||
|
||||
vector3 m_vecLightmapOrigin;
|
||||
vector3 m_vecLightmapVecs[3];
|
||||
|
||||
bool m_bPatch;
|
||||
int m_PatchWidth;
|
||||
int m_PatchHeight;
|
||||
|
||||
bool m_bMiscModel;
|
||||
bool m_bFlareSurface;
|
||||
};
|
||||
|
||||
class SEdgePoint
|
||||
{
|
||||
public:
|
||||
float m_fIntercept;
|
||||
vector3 m_vecXYZ;
|
||||
SEdgePoint *m_pPrev,*m_pNext;
|
||||
};
|
||||
|
||||
class SEdgeLine
|
||||
{
|
||||
public:
|
||||
vector3 m_vecNormal1;
|
||||
float m_fDist1;
|
||||
vector3 m_vecNormal2;
|
||||
float m_fDist2;
|
||||
|
||||
vector3 m_vecOrigin;
|
||||
vector3 m_vecDir;
|
||||
|
||||
SEdgePoint m_Chain;
|
||||
};
|
||||
|
||||
class SOriginalEdge {
|
||||
public:
|
||||
float m_fLength;
|
||||
BspVertex *m_dv[2];
|
||||
};
|
||||
|
||||
class SMesh
|
||||
{
|
||||
public:
|
||||
int m_nWidth,m_nHeight;
|
||||
BspVertex *m_pVerts;
|
||||
};
|
||||
|
||||
class SParseMesh
|
||||
{
|
||||
public:
|
||||
SParseMesh *m_pNext;
|
||||
SMesh m_Mesh;
|
||||
|
||||
int m_nShader;
|
||||
|
||||
bool m_bGrouped;
|
||||
SParseMesh *m_pGrupChain;
|
||||
};
|
||||
|
||||
class DSurface
|
||||
{
|
||||
public:
|
||||
int m_nShader;
|
||||
int m_nFog;
|
||||
int m_SurfaceType;
|
||||
|
||||
int m_FirstVert;
|
||||
int m_nVerts;
|
||||
|
||||
int m_FirstIndex;
|
||||
int m_nIndex;
|
||||
|
||||
int m_nLightmap;
|
||||
int m_LightmapX,m_LightmapY;
|
||||
int m_LightmapWidth,m_LightmapHeight;
|
||||
|
||||
vector3 m_vecLightmapOrigin;
|
||||
vector3 m_vecLightmap[3];
|
||||
|
||||
int m_PatchWidth;
|
||||
int m_PatchHeight;
|
||||
};
|
||||
|
||||
class DPlane
|
||||
{
|
||||
public:
|
||||
vector3 m_vecNormal;
|
||||
float m_fDist;
|
||||
};
|
||||
|
||||
class DModel
|
||||
{
|
||||
public:
|
||||
vector3 m_vecMin,m_vecMax;
|
||||
int m_nFirstSurface,m_nSurfaces;
|
||||
int m_nFirstBrush,m_nBrushes;
|
||||
};
|
||||
|
||||
class DNode
|
||||
{
|
||||
public:
|
||||
int m_nPlane;
|
||||
int m_Children[2];
|
||||
vector3 m_min;
|
||||
vector3 m_max;
|
||||
};
|
||||
|
||||
class DLeaf
|
||||
{
|
||||
public:
|
||||
int m_Cluster;
|
||||
int m_Area;
|
||||
|
||||
vector3 m_min;
|
||||
vector3 m_max;
|
||||
|
||||
int m_FirstLeafSurface;
|
||||
int m_nLeafSurfaces;
|
||||
int m_FirstLeafBrush;
|
||||
int m_nLeafBrushes;
|
||||
};
|
||||
|
||||
class DBrush
|
||||
{
|
||||
public:
|
||||
int m_FirstSide;
|
||||
int m_nSides;
|
||||
int m_nShader;
|
||||
};
|
||||
|
||||
class DBrushSide
|
||||
{
|
||||
public:
|
||||
int m_nPlane;
|
||||
int m_nShader;
|
||||
};
|
||||
|
||||
class DVisiblity
|
||||
{
|
||||
public:
|
||||
int nClusters;
|
||||
int RowSize;
|
||||
unsigned char data[1];
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SPassage
|
||||
{
|
||||
public:
|
||||
SPassage *m_pNext;
|
||||
BYTE m_Cansee[1];
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
stat_none,
|
||||
stat_working,
|
||||
stat_done
|
||||
}Vstatus;
|
||||
|
||||
class VPortal
|
||||
{
|
||||
public:
|
||||
int m_Num;
|
||||
bool m_bHint;
|
||||
bool m_bRemoved;
|
||||
SPlane m_Plane;
|
||||
int m_Leaf;
|
||||
|
||||
vector3 m_vecOrigin;
|
||||
float m_fRadius;
|
||||
|
||||
SWinding *m_pWinding;
|
||||
Vstatus m_Status;
|
||||
BYTE *m_pPortalFront;
|
||||
BYTE *m_pPortalFlood;
|
||||
BYTE *m_pPortalVis;
|
||||
|
||||
int m_nMightsee;
|
||||
SPassage *m_Passage;
|
||||
};
|
||||
|
||||
#define MAX_PORTALS_ON_LEAF 128
|
||||
|
||||
class Leaf
|
||||
{
|
||||
public:
|
||||
int m_nPortals;
|
||||
int m_Merged;
|
||||
VPortal *m_pPortals[MAX_PORTALS_ON_LEAF];
|
||||
};
|
||||
|
||||
#define MAX_MAP_PORTALS 65536
|
||||
#define MAX_SEPERATORS 64
|
||||
#define MAX_PORTALS 32768
|
||||
|
||||
class PStack
|
||||
{
|
||||
public:
|
||||
BYTE m_Mightsee[MAX_PORTALS/8];
|
||||
PStack *m_pNext;
|
||||
Leaf *m_pLeaf;
|
||||
VPortal *m_pPortal;
|
||||
SWinding *m_pSource;
|
||||
SWinding *m_pPass;
|
||||
|
||||
SWinding m_Winding[3];
|
||||
int m_FreeWindings[3];
|
||||
|
||||
SPlane m_PortalPlane;
|
||||
int m_Depth;
|
||||
|
||||
SPlane m_Seperators[2][MAX_SEPERATORS];
|
||||
int m_nSeperators[2];
|
||||
};
|
||||
|
||||
class ThreadData
|
||||
{
|
||||
public:
|
||||
VPortal *m_pBase;
|
||||
int m_cChains;
|
||||
PStack m_PStackHead;
|
||||
};
|
||||
|
||||
class DShader
|
||||
{
|
||||
public:
|
||||
char m_strTextureName[256];
|
||||
};
|
||||
|
||||
class DLight
|
||||
{
|
||||
public:
|
||||
vector3 m_vecLightPos;
|
||||
color m_LightColor;
|
||||
float m_fLightRange;
|
||||
int m_Photons;
|
||||
};
|
||||
|
||||
class TraceT
|
||||
{
|
||||
public:
|
||||
vector3 m_vecFilter;
|
||||
vector3 m_vecHit;
|
||||
float m_fHitFraction;
|
||||
bool m_bPassSolid;
|
||||
};
|
||||
|
||||
class TraceWorkT
|
||||
{
|
||||
public:
|
||||
vector3 m_vecStart,m_vecEnd;
|
||||
int m_nOpenLeafs;
|
||||
int m_OpenLeafNumbers[MAX_MAP_LEAFS];
|
||||
TraceT *m_Trace;
|
||||
int m_PatchShadows;
|
||||
};
|
||||
|
||||
|
||||
#define TRACE_ON_EPSILON 0.1
|
||||
|
||||
class TNode
|
||||
{
|
||||
public:
|
||||
int m_Type;
|
||||
vector3 m_vecNormal;
|
||||
float m_fDist;
|
||||
int m_Children[2];
|
||||
int m_nPlaneNum;
|
||||
};
|
||||
|
||||
#define MAX_TNODES (MAX_MAP_NODES*4)
|
||||
#define TRACE_ON_EPSILON 0.1
|
||||
|
||||
class CFaceT
|
||||
{
|
||||
public:
|
||||
float m_fSurface[4];
|
||||
int m_nBoundaries;
|
||||
float m_fBoundaries[4][4];
|
||||
|
||||
vector3 m_vecPoint[4];
|
||||
float m_fTextureMatrix[2][4];
|
||||
};
|
||||
|
||||
class SurfaceTestT
|
||||
{
|
||||
public:
|
||||
vector3 m_vecMins,m_vecMaxs;
|
||||
vector3 m_vecOrigins;
|
||||
float m_fRadius;
|
||||
|
||||
bool m_bPatch;
|
||||
int m_nFacets;
|
||||
CFaceT *m_Facets;
|
||||
|
||||
int m_nShader;
|
||||
};
|
||||
3418
Engine/Zalla3D Scene Class/BspScene.cpp
Normal file
3418
Engine/Zalla3D Scene Class/BspScene.cpp
Normal file
File diff suppressed because it is too large
Load Diff
219
Engine/Zalla3D Scene Class/BspScene.h
Normal file
219
Engine/Zalla3D Scene Class/BspScene.h
Normal file
@@ -0,0 +1,219 @@
|
||||
// BspScene.h: interface for the CBspScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_BSPSCENE_H__EFE28EE9_11AC_466C_B92C_4E7930C219D3__INCLUDED_)
|
||||
#define AFX_BSPSCENE_H__EFE28EE9_11AC_466C_B92C_4E7930C219D3__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
//#include "BSPBaseDataDefine.h"
|
||||
#include "BspDataDefine.h"
|
||||
#include "Texture.h"
|
||||
#include <vector>
|
||||
#include "ViewCamera.h"
|
||||
#include "MeshObject.h"
|
||||
|
||||
typedef float vector2[2];
|
||||
|
||||
class CBspScene
|
||||
{
|
||||
class DSurfaceEx
|
||||
{
|
||||
public:
|
||||
DSurface *m_pSurface;
|
||||
vector3 m_vecMax,m_vecMin;
|
||||
std::vector<int> m_ApplyLightList;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pShadowVertexBuffer;
|
||||
int m_nShadowVertex;
|
||||
std::vector<int> m_ShadowIndicesList;
|
||||
};
|
||||
class DLightEx
|
||||
{
|
||||
public:
|
||||
DLight *m_pLight;
|
||||
std::vector<int> m_ApplySurface;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pEdgeIndexBuffer;
|
||||
int m_nEdgePoly;
|
||||
};
|
||||
class CurveBuffer
|
||||
{
|
||||
public:
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void FillPatch3(int *numcp, int *size, vector3 *p);
|
||||
void FillPatch2(int *numcp, int *size, vector2 *p);
|
||||
void FillCurve3(int numcp, int size, int stride,vector3 *p);
|
||||
void FillCurve2(int numcp, int size, int stride, vector2 *p);
|
||||
void FillPatchVertex();
|
||||
int FindLevel(vector3 *v);
|
||||
void FindSize();
|
||||
void CreateCurveBuffer(DSurface *pSurface,BspVertex *pControlPointVertex);
|
||||
BspVertex *m_pVertex;
|
||||
WORD *m_pIndices;
|
||||
DSurface *m_pSurface;
|
||||
vector3 *m_pControlPoint;
|
||||
int m_PatchSizeWidth;
|
||||
int m_PatchSizeHeight;
|
||||
int m_nIndices;
|
||||
|
||||
};
|
||||
class CBSPShader
|
||||
{
|
||||
public:
|
||||
CTexture *m_DiffuseTexture;
|
||||
CTexture *m_BumpTexture;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pIndicesBuffer;
|
||||
int m_nPoly;
|
||||
int m_nVertex;
|
||||
int m_nIndices;
|
||||
|
||||
int m_nDrawIndices;
|
||||
WORD *m_pIndices;
|
||||
std::vector<int> m_ApplyLightList;
|
||||
};
|
||||
std::vector<DLightEx> m_LightEx;
|
||||
std::vector<CBSPShader> m_ShaderList;
|
||||
std::vector<DSurfaceEx*> m_DSurfaceEx;
|
||||
CViewCamera m_Camera;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
// std::vector<CurveBuffer*> m_CurveBufferList;
|
||||
|
||||
TNode *m_TNodes,*m_TNodes_p;
|
||||
SurfaceTestT *m_SurfaceTest[MAX_MAP_DRAW_SURFS];
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pIndicesBuffer;
|
||||
int m_nLightmap;
|
||||
int m_nMaxIndices;
|
||||
bool m_bCull;
|
||||
|
||||
DWORD m_dwBSPAmbientVertexShader;
|
||||
DWORD m_dwBSPAmbientPixelShader;
|
||||
|
||||
DWORD m_dwBSPDiffuseVertexShader;
|
||||
DWORD m_dwBSPDiffusePixelShader;
|
||||
|
||||
DWORD m_dwBSPSpecularVertexShader;
|
||||
DWORD m_dwBSPSpecularPixelShader;
|
||||
|
||||
DWORD m_dwBSPShadowVertexShader;
|
||||
|
||||
LPDIRECT3DCUBETEXTURE8 m_pNormalizeCubeMap;
|
||||
LPDIRECT3DVOLUMETEXTURE8 m_pPointFalloffMap;
|
||||
|
||||
std::vector<BspShadowVertex> m_SurfaceEdgeVertexList;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pEdgeVertexBuffer;
|
||||
|
||||
|
||||
public:
|
||||
int FindShadowEdgeVertex(BspShadowVertex Vertex);
|
||||
void LerpDrawVert(BspVertex *a, BspVertex *b, BspVertex *out);
|
||||
SMesh* CopyMesh(SMesh *mesh);
|
||||
void ProjectPointOntoVector(vector3 &point, vector3 &vStart, vector3 &vEnd, vector3 &vProj);
|
||||
void FreeMesh(SMesh *m);
|
||||
void MakeMeshNormals(SMesh in);
|
||||
void PutMeshOnCurve(SMesh in);
|
||||
SMesh* SubdivideMesh(SMesh in, float maxError, float minLength);
|
||||
void AddPointToBounds(vector3 &v, vector3 &max, vector3 &min);
|
||||
int PlaneTypeForNormal(vector3 p);
|
||||
SMesh* RemoveLinearMeshColumnsRows(SMesh *in);
|
||||
void FacetsForPatch(DSurface *dsurf, int nShader, SurfaceTestT *test);
|
||||
bool CM_GenerateFacetFor4Points(CFaceT *f, BspVertex *a, BspVertex *b, BspVertex *c, BspVertex *d);
|
||||
void TextureMatrixFromPoints(CFaceT *f, BspVertex *a, BspVertex *b, BspVertex *c);
|
||||
void CM_GenerateBoundaryForPoints(float boundary[], float plane[], vector3 &a, vector3 &b);
|
||||
bool PlaneFromPoints(float *plane, vector3 &a, vector3 &b, vector3 &c);
|
||||
bool CM_GenerateFacetFor3Points(CFaceT *f, BspVertex *a, BspVertex *b, BspVertex *c);
|
||||
void FacetsForTriangleSurface(DSurface *dsurf, int nShader, SurfaceTestT *test);
|
||||
void InitSurfacesForTesting();
|
||||
void TraceAgainstFacet(TraceWorkT *tr,int nShader,CFaceT *facet);
|
||||
bool SphereCull(vector3 &start, vector3 &stop, vector3 &origin, float radius);
|
||||
void TraceAgainstSurface(TraceWorkT *tw, SurfaceTestT *surf);
|
||||
int RecurTraceLine(int node, vector3 &start, vector3 &stop, TraceWorkT *tw);
|
||||
void TraceLine(vector3 &start, vector3 &stop, TraceT *trace, bool testAll, TraceWorkT *tw);
|
||||
void MakeTnode(int nodenum);
|
||||
void InitTrace();
|
||||
bool RecurTraceLine(int nNode,vector3 &vecStart,vector3 &vecEnd);
|
||||
bool TraceLineCollision(vector3 &vecStart,vector3 vecEnd);
|
||||
void DetectEdge(int *pEdges,int &nEdges,int nEdge0,int nEdge1,DSurface *pSrcSurface,vector3 vecPlaneNormal,vector3 vecPlaneOrigin);
|
||||
void CalcShadowVolume(BspVertex *pVertex,int nVertex,int *pIndices,int nIndices,DSurfaceEx &Surface);
|
||||
void SurfaceLightArrange();
|
||||
void InitShader();
|
||||
void CullCollisionPoly(vector3 vecPos);
|
||||
void DeleteLight();
|
||||
void RenderLight(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void UpdateLightmapVector3(int n);
|
||||
void AddLight(vector3 vecLightPos,float fRange,color clr);
|
||||
bool m_bLightmapVector;
|
||||
void LoadLightmapVector3();
|
||||
bool m_bSkyRender;
|
||||
void RenderBox(LPDIRECT3DDEVICE8 pd3dDevice,DWORD dwColor);
|
||||
void CullWalkLeaf(int n);
|
||||
void CullWalkNodes(int n);
|
||||
void CullPoly(vector3 vecMax,vector3 vecMin,std::vector<vector3> &PolyList);
|
||||
bool LeafInFrustum(vector3 &vecMax,vector3 &vecMin);
|
||||
void RenderBackend(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderInit();
|
||||
void RenderWalkFace(int n);
|
||||
void RenderWalkLeaf(int n);
|
||||
void RenderWalkNode(int n);
|
||||
int ClassfyPoint(vector3 p, int nPlane);
|
||||
int FindCluster(vector3 vecPos);
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice,vector3 vecViewPos);
|
||||
int CopyLump(DHeader *header,int lump,void **dest,int size);
|
||||
void Load(char *strFilename);
|
||||
CBspScene();
|
||||
virtual ~CBspScene();
|
||||
|
||||
vector3 m_vecMaxBox,m_vecMinBox;
|
||||
|
||||
int *m_SurfaceInc;
|
||||
|
||||
int m_EyeCluster;//<2F><> Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?//
|
||||
vector3 m_vecViewPos;
|
||||
|
||||
DShader *m_Shaders;
|
||||
int m_nShader;
|
||||
|
||||
BspVertex *m_DrawVerts;
|
||||
int m_nDrawVerts;
|
||||
|
||||
DPlane *m_Planes;
|
||||
int m_nPlanes;
|
||||
|
||||
DLeaf *m_Leafs;
|
||||
int m_nLeafs;
|
||||
|
||||
DNode *m_Nodes;
|
||||
int m_nNodes;
|
||||
|
||||
DSurface *m_DrawSurfaces;
|
||||
int m_nDrawSurfaces;
|
||||
|
||||
int *m_LeafSurfaces;
|
||||
int m_nLeafSurfaces;
|
||||
|
||||
int *m_DrawIndex;
|
||||
int m_nDrawIndex;
|
||||
|
||||
DVisiblity *m_Visibility;
|
||||
int m_nVisibility;
|
||||
|
||||
DLight *m_Light;
|
||||
int m_nLight;
|
||||
|
||||
std::vector<DLight> m_EditLightList;
|
||||
|
||||
vector3 m_vecCenter,m_vecMax,m_vecMin;
|
||||
|
||||
CMeshObject *m_pLightObject;
|
||||
int m_SelectLight;
|
||||
|
||||
vector3 *m_pSurfaceMaxBox;
|
||||
vector3 *m_pSurfaceMinBox;
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_BSPSCENE_H__EFE28EE9_11AC_466C_B92C_4E7930C219D3__INCLUDED_)
|
||||
324
Engine/Zalla3D Scene Class/CharacterCape.cpp
Normal file
324
Engine/Zalla3D Scene Class/CharacterCape.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
#include ".\charactercape.h"
|
||||
#include "dxutil.h"
|
||||
#include "SceneManager.h"
|
||||
#include "ClothMgr.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
float CCharacterCape::s_fChrTypeCollisionRadius[CCharacterCape::CHARACTER_TYPE_COUNT] =
|
||||
{
|
||||
45.0f,
|
||||
45.0f,
|
||||
75.0f,
|
||||
45.0f
|
||||
};
|
||||
|
||||
CCharacterCape::CCharacterCape(const CClothProperty* pProp, bool bTest ) : CBaseCloth(pProp),
|
||||
m_pSphere(NULL), m_vMoveValue(D3DXVECTOR3(0,0,0)), m_fRotateValue(0.0f), m_bTestMode(bTest),
|
||||
m_pChrModel(NULL), m_vFixedPoint(D3DXVECTOR3(0,0,0)), m_OldPointPos(vector3(0,0,0)),
|
||||
m_OldPointPos2(vector3(0,0,0)), m_CurPointPos(vector3(0,0,0)), m_CurPointPos2(vector3(0,0,0)),
|
||||
m_vOldPos(D3DXVECTOR3(0,0,0)), m_vCurPos(D3DXVECTOR3(0,0,0)), m_fOldRot(0), m_fCurRot(0),
|
||||
m_pBackTexture(NULL), m_pDecalTexture(NULL), m_bEnable(true)
|
||||
{
|
||||
ZeroMemory( m_strCapeNationalFlag, sizeof(m_strCapeNationalFlag) );
|
||||
ZeroMemory( m_strCapeBackground, sizeof(m_strCapeBackground) );
|
||||
D3DXCreateTextureFromFile( CSceneManager::GetDevice(), "c:\\picture2.bmp", &m_pBackTexture );
|
||||
D3DXCreateTextureFromFile( CSceneManager::GetDevice(), "c:\\~picture1.bmp", &m_pDecalTexture );
|
||||
}
|
||||
|
||||
CCharacterCape::~CCharacterCape(void)
|
||||
{
|
||||
SAFE_RELEASE( m_pSphere );
|
||||
SAFE_RELEASE( m_pBackTexture );
|
||||
SAFE_RELEASE( m_pDecalTexture );
|
||||
}
|
||||
|
||||
void CCharacterCape::Create( CHARACTER_TYPE Type, CZ3DGeneralChrModel* pChrModel )
|
||||
{
|
||||
m_pChrModel = pChrModel;
|
||||
|
||||
m_CollisionSphere.fRadius = s_fChrTypeCollisionRadius[Type];
|
||||
m_CollisionSphere.vPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
if( m_bTestMode )
|
||||
D3DXCreateSphere( CSceneManager::GetDevice(), m_CollisionSphere.fRadius, 10, 10, &m_pSphere, NULL );
|
||||
|
||||
LockParticle( 0, 0 );
|
||||
LockParticle( 0, 1 );
|
||||
LockParticle( 0, 2 );
|
||||
LockParticle( 0, 3 );
|
||||
LockParticle( 0, 4 );
|
||||
}
|
||||
|
||||
void CCharacterCape::Render()
|
||||
{
|
||||
if( !m_bEnable ) return;
|
||||
|
||||
CClothMgr::_Instance()->m_CapeRenderer.SetupCloth( this );
|
||||
LPDIRECT3DDEVICE8 pd3dDevice = CSceneManager::GetDevice();
|
||||
pd3dDevice->SetTexture( 0, m_pDecalTexture );
|
||||
pd3dDevice->LightEnable( 0, TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/*
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_ADD );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
|
||||
pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE );
|
||||
pd3dDevice->SetTextureStageState( 2, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
*/
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
|
||||
pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
|
||||
CClothMgr::_Instance()->m_CapeRenderer.Render();
|
||||
}
|
||||
|
||||
void CCharacterCape::Update( float dt )
|
||||
{
|
||||
if( !m_bEnable ) return;
|
||||
|
||||
MoveLockedParticle( m_vMoveValue );
|
||||
RotateLockedParticle( m_fRotateValue );
|
||||
|
||||
if( m_pChrModel )
|
||||
{
|
||||
vector3 CurPos = m_pChrModel->GetPosition();
|
||||
float fCurRot = m_pChrModel->GetDirection();
|
||||
|
||||
m_OldPointPos = m_CurPointPos;
|
||||
m_OldPointPos2 = m_CurPointPos2;
|
||||
m_pChrModel->GetFixedPoint( 1, m_CurPointPos ); //<2F><><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>.
|
||||
m_pChrModel->GetFixedPoint( 0, m_CurPointPos2 ); //<2F><><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>.
|
||||
|
||||
m_CurPointPos += CurPos;
|
||||
m_CurPointPos2 += CurPos;
|
||||
|
||||
vector3 tempPP, tempPP2, tempMV;
|
||||
tempPP = m_CurPointPos - CurPos;
|
||||
tempPP2 = m_CurPointPos2 - CurPos;
|
||||
tempMV = (tempPP+tempPP2)*0.5f + CurPos;
|
||||
|
||||
vector3 CSPoint;
|
||||
m_pChrModel->GetFixedPoint( 2, CSPoint );
|
||||
CSPoint += CurPos;
|
||||
|
||||
SetCollisionSpherePos( D3DXVECTOR3(CSPoint.x, CSPoint.y, CSPoint.z) );
|
||||
SetMoveValue( D3DXVECTOR3(tempMV.x, tempMV.y, tempMV.z) );
|
||||
SetRotateValue( fCurRot );
|
||||
SetParticlePos( 0, 0, D3DXVECTOR3(m_CurPointPos2.x, m_CurPointPos2.y, m_CurPointPos2.z) );
|
||||
|
||||
D3DXVECTOR3 vLerpPoint;
|
||||
D3DXVec3Lerp( &vLerpPoint, &D3DXVECTOR3(m_CurPointPos2.x, m_CurPointPos2.y, m_CurPointPos2.z),
|
||||
&D3DXVECTOR3(m_CurPointPos.x, m_CurPointPos.y, m_CurPointPos.z), 0.25 );
|
||||
SetParticlePos( 0, 1, vLerpPoint );
|
||||
D3DXVec3Lerp( &vLerpPoint, &D3DXVECTOR3(m_CurPointPos2.x, m_CurPointPos2.y, m_CurPointPos2.z),
|
||||
&D3DXVECTOR3(m_CurPointPos.x, m_CurPointPos.y, m_CurPointPos.z), 0.5 );
|
||||
SetParticlePos( 0, 2, vLerpPoint );
|
||||
|
||||
m_vFixedPoint = vLerpPoint;
|
||||
|
||||
D3DXVec3Lerp( &vLerpPoint, &D3DXVECTOR3(m_CurPointPos2.x, m_CurPointPos2.y, m_CurPointPos2.z),
|
||||
&D3DXVECTOR3(m_CurPointPos.x, m_CurPointPos.y, m_CurPointPos.z), 0.75 );
|
||||
SetParticlePos( 0, 3, vLerpPoint );
|
||||
SetParticlePos( 0, 4, D3DXVECTOR3(m_CurPointPos.x, m_CurPointPos.y, m_CurPointPos.z) );
|
||||
}
|
||||
|
||||
CalculateForce();
|
||||
Integrate( dt );
|
||||
|
||||
CalculateForce();
|
||||
Integrate( dt );
|
||||
|
||||
CalculateForce();
|
||||
Integrate( dt );
|
||||
|
||||
CalculateForce();
|
||||
Integrate( dt );
|
||||
|
||||
//Ƣ<><C6A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ȥ<><C8A4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>źκ<C5BA>
|
||||
D3DXVECTOR3 vDist = m_pParticles[ROWCOL(0, 0)].vPos - m_pParticles[ROWCOL(1, 0)].vPos;
|
||||
if( D3DXVec3Length( &vDist ) > 50 )
|
||||
{
|
||||
ResetParticle();
|
||||
}
|
||||
}
|
||||
|
||||
void CCharacterCape::CalculateForce()
|
||||
{
|
||||
int r, c, i, r1, c1, r2, c2;
|
||||
D3DXVECTOR3 dragVector;
|
||||
D3DXVECTOR3 f1, f2, d, v;
|
||||
float L, tempValue;
|
||||
D3DXVECTOR3 vDist;
|
||||
D3DXMATRIX matWorld, matTrans, matRot;
|
||||
D3DXVECTOR3 vTemp;
|
||||
D3DXVECTOR3 vPos;
|
||||
D3DXVECTOR3 vAxis;
|
||||
|
||||
m_fRotateValue *= ADDVALUE_ROT;
|
||||
|
||||
for(r=0; r<=m_Prop.m_iRow; r++)
|
||||
{
|
||||
for(c=0; c<=m_Prop.m_iCol; c++)
|
||||
{
|
||||
if( !m_pParticles[ROWCOL(r,c)].bLocked )
|
||||
{
|
||||
m_pParticles[ROWCOL(r,c)].vForce = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
//gravity
|
||||
m_pParticles[ROWCOL(r,c)].vForce.y += (float)(m_Prop.m_fGravity * m_pParticles[ROWCOL(r,c)].fMass);
|
||||
|
||||
// viscous drag
|
||||
dragVector = -m_pParticles[ROWCOL(r,c)].vVel;
|
||||
D3DXVec3Normalize( &dragVector, &dragVector );
|
||||
float tempValue = D3DXVec3Length( &m_pParticles[ROWCOL(r,c)].vVel );
|
||||
m_pParticles[ROWCOL(r,c)].vForce += dragVector * tempValue * tempValue * m_Prop.m_fDragCoefficient;
|
||||
|
||||
//<2F>浹
|
||||
vDist = m_pParticles[ROWCOL(r,c)].vPos - m_CollisionSphere.vPos;
|
||||
if( D3DXVec3Length(&vDist) < m_CollisionSphere.fRadius )
|
||||
{
|
||||
D3DXVec3Normalize( &vDist, &vDist );
|
||||
vDist = vDist*600;
|
||||
m_pParticles[ROWCOL(r,c)].vForce += vDist;
|
||||
}
|
||||
|
||||
m_pParticles[ROWCOL(r,c)].vPos += m_vMoveValue * ADDVALUE_POS;
|
||||
D3DXMatrixRotationY( &matRot, m_fRotateValue );
|
||||
vAxis = (m_pParticles[ROWCOL(0,0)].vPos + m_pParticles[ROWCOL(0,4)].vPos)/2;
|
||||
vTemp = m_pParticles[ROWCOL(r,c)].vPos - vAxis;
|
||||
D3DXMatrixTranslation( &matTrans, vTemp.x, vTemp.y, vTemp.z );
|
||||
D3DXMatrixMultiply( &matWorld, &matTrans, &matRot );
|
||||
vPos = D3DXVECTOR3(0.0F, 0.0F, 0.0F);
|
||||
D3DXVec3TransformCoord( &vPos, &vPos, &matWorld );
|
||||
m_pParticles[ROWCOL(r,c)].vPos += vPos - vTemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_vMoveValue = D3DXVECTOR3(0,0,0);
|
||||
m_fRotateValue = 0;
|
||||
|
||||
// Process spring forces
|
||||
for(i = 0; i<m_iNumSpring; i++)
|
||||
{
|
||||
r1 = m_pSprings[i].p1.r;
|
||||
c1 = m_pSprings[i].p1.c;
|
||||
r2 = m_pSprings[i].p2.r;
|
||||
c2 = m_pSprings[i].p2.c;
|
||||
|
||||
d = m_pParticles[ROWCOL(r1,c1)].vPos - m_pParticles[ROWCOL(r2,c2)].vPos;
|
||||
v = m_pParticles[ROWCOL(r1,c1)].vVel - m_pParticles[ROWCOL(r2,c2)].vVel;
|
||||
L = m_pSprings[i].L;
|
||||
|
||||
tempValue = D3DXVec3Length(&d);
|
||||
|
||||
f1 = -(m_pSprings[i].k * (tempValue - L) +
|
||||
m_pSprings[i].d * ( D3DXVec3Dot(&v, &d) / tempValue )) * ( d / tempValue );
|
||||
f2 = -f1;
|
||||
|
||||
if(m_pParticles[ROWCOL(r1,c1)].bLocked == FALSE)
|
||||
m_pParticles[ROWCOL(r1,c1)].vForce += f1;
|
||||
|
||||
if(m_pParticles[ROWCOL(r2,c2)].bLocked == FALSE)
|
||||
m_pParticles[ROWCOL(r2,c2)].vForce += f2;
|
||||
}
|
||||
}
|
||||
|
||||
void CCharacterCape:: Integrate( float dt )
|
||||
{
|
||||
int iVertexIndex=0;
|
||||
D3DXVECTOR3 vDist;
|
||||
|
||||
for( int r=0; r<=m_Prop.m_iRow; r++)
|
||||
{
|
||||
for(int c=0; c<=m_Prop.m_iCol; c++)
|
||||
{
|
||||
if( !m_pParticles[ROWCOL(r,c)].bLocked )
|
||||
{
|
||||
m_pParticles[ROWCOL(r,c)].vAccel = m_pParticles[ROWCOL(r,c)].vForce * m_pParticles[ROWCOL(r,c)].fInvMass;
|
||||
m_pParticles[ROWCOL(r,c)].vVel += m_pParticles[ROWCOL(r,c)].vAccel * dt;
|
||||
m_pParticles[ROWCOL(r,c)].vPos += m_pParticles[ROWCOL(r,c)].vVel * dt * ADDVALUE_TOTAL;
|
||||
|
||||
//<2F>浹<EFBFBD><E6B5B9><EFBFBD><EFBFBD>1
|
||||
/*
|
||||
vDist = m_pParticles[ROWCOL(r,c)].vPos - m_CollisionSphere.vPos;
|
||||
if( D3DXVec3Length(&vDist) < m_CollisionSphere.fRadius )
|
||||
{
|
||||
m_pParticles[ROWCOL(r,c)].vPos = vOldPos;
|
||||
D3DXVec3Normalize( &vDist, &vDist );
|
||||
Vn = D3DXVec3Dot(&vDist, &m_pParticles[ROWCOL(r,c)].vVel) * vDist;
|
||||
Vt = m_pParticles[ROWCOL(r,c)].vVel - Vn;
|
||||
m_pParticles[ROWCOL(r,c)].vVel = (-(m_Prop.m_fKrestitution+1) * Vn) + (m_Prop.m_fFrictionfactor*Vt);
|
||||
}*/
|
||||
|
||||
//<2F>浹<EFBFBD><E6B5B9><EFBFBD><EFBFBD>2
|
||||
vDist = m_pParticles[ROWCOL(r,c)].vPos - m_CollisionSphere.vPos;
|
||||
if( D3DXVec3Length(&vDist) < m_CollisionSphere.fRadius )
|
||||
{
|
||||
D3DXVec3Normalize( &vDist, &vDist );
|
||||
vDist *= m_CollisionSphere.fRadius;
|
||||
m_pParticles[ROWCOL(r,c)].vPos = m_CollisionSphere.vPos + vDist;
|
||||
m_pParticles[ROWCOL(r,c)].vVel = D3DXVECTOR3(0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCharacterCape::ResetParticle()
|
||||
{
|
||||
D3DXMATRIX matWorld, matTrans, matRot;
|
||||
D3DXMatrixRotationY( &matRot, m_pChrModel->GetDirection() );
|
||||
D3DXMatrixTranslation( &matTrans, m_vFixedPoint.x, m_vFixedPoint.y, m_vFixedPoint.z );
|
||||
matWorld = matRot*matTrans;
|
||||
|
||||
for( int r = 0; r <= m_Prop.m_iRow; r++ )
|
||||
{
|
||||
for( int c = 0; c <= m_Prop.m_iCol; c++ )
|
||||
{
|
||||
if( !m_pParticles[ROWCOL(r,c)].bLocked )
|
||||
{
|
||||
m_pParticles[ROWCOL(r,c)].vPos.x = c * m_fCStep - (float)m_Prop.m_iWidth/2.0f;
|
||||
m_pParticles[ROWCOL(r,c)].vPos.y = 0.0f;
|
||||
m_pParticles[ROWCOL(r,c)].vPos.z = r * m_fRStep;
|
||||
m_pParticles[ROWCOL(r,c)].vVel = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_pParticles[ROWCOL(r,c)].vAccel = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_pParticles[ROWCOL(r,c)].vForce = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
D3DXVec3TransformCoord( &m_pParticles[ROWCOL(r,c)].vPos, &m_pParticles[ROWCOL(r,c)].vPos, &matWorld );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCharacterCape::DrawCollisionSphere()
|
||||
{
|
||||
if( !m_bTestMode ) return;
|
||||
|
||||
D3DXMATRIX matWorld;
|
||||
CSceneManager::GetDevice()->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
|
||||
D3DXMatrixTranslation( &matWorld, m_CollisionSphere.vPos.x, m_CollisionSphere.vPos.y, m_CollisionSphere.vPos.z );
|
||||
CSceneManager::GetDevice()->SetTransform( D3DTS_WORLD, &matWorld );
|
||||
m_pSphere->DrawSubset(0);
|
||||
CSceneManager::GetDevice()->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
|
||||
}
|
||||
|
||||
void CCharacterCape::RenderShadow()
|
||||
{
|
||||
if( !m_bEnable ) return;
|
||||
|
||||
CClothMgr::_Instance()->m_CapeRenderer.Render();
|
||||
}
|
||||
145
Engine/Zalla3D Scene Class/CharacterCape.h
Normal file
145
Engine/Zalla3D Scene Class/CharacterCape.h
Normal file
@@ -0,0 +1,145 @@
|
||||
#pragma once
|
||||
|
||||
#include "BaseCloth.h"
|
||||
#include "Z3DGeneralChrModel.h"
|
||||
|
||||
#define ADDVALUE_POS 0.95f
|
||||
#define ADDVALUE_ROT 0.96f
|
||||
#define ADDVALUE_TOTAL 1.2f
|
||||
|
||||
#define CCR_HUMAN_MAN 45
|
||||
#define CCR_HUMAN_WOMAN 45
|
||||
#define CCR_AKHAN_MAN 45
|
||||
#define CCR_AKHAN_WOMAN 45
|
||||
|
||||
class CCharacterCape : public CBaseCloth
|
||||
{
|
||||
public:
|
||||
enum CHARACTER_TYPE
|
||||
{
|
||||
HUMAN_MAN,
|
||||
HUMAN_WOMAN,
|
||||
AKHAN_MAN,
|
||||
AKHAN_WOMAN,
|
||||
CHARACTER_TYPE_COUNT
|
||||
};
|
||||
|
||||
public:
|
||||
LPD3DXMESH m_pSphere;
|
||||
D3DXVECTOR3 m_vMoveValue;
|
||||
float m_fRotateValue;
|
||||
bool m_bTestMode;
|
||||
CZ3DGeneralChrModel* m_pChrModel;
|
||||
D3DXVECTOR3 m_vFixedPoint;
|
||||
vector3 m_OldPointPos;
|
||||
vector3 m_OldPointPos2;
|
||||
vector3 m_CurPointPos;
|
||||
vector3 m_CurPointPos2;
|
||||
D3DXVECTOR3 m_vOldPos;
|
||||
D3DXVECTOR3 m_vCurPos;
|
||||
float m_fOldRot;
|
||||
float m_fCurRot;
|
||||
LPDIRECT3DTEXTURE8 m_pBackTexture;
|
||||
LPDIRECT3DTEXTURE8 m_pDecalTexture;
|
||||
bool m_bEnable;
|
||||
|
||||
CollisionSphere m_CollisionSphere;
|
||||
char m_strCapeNationalFlag[MAX_PATH];
|
||||
char m_strCapeBackground[MAX_PATH];
|
||||
static float s_fChrTypeCollisionRadius[CHARACTER_TYPE_COUNT];
|
||||
|
||||
protected:
|
||||
void CalculateForce();
|
||||
void Integrate( float dt );
|
||||
void MoveLockedParticle( const D3DXVECTOR3& vPos );
|
||||
void RotateLockedParticle( float fFrameRot );
|
||||
|
||||
public:
|
||||
CCharacterCape(const CClothProperty* pProp, bool bTest = false );
|
||||
~CCharacterCape(void);
|
||||
|
||||
virtual void Update( float dt = 0.025f );
|
||||
virtual void Render();
|
||||
|
||||
void Create( CHARACTER_TYPE Type, CZ3DGeneralChrModel* pChrModel=NULL );
|
||||
void RenderShadow();
|
||||
void DrawCollisionSphere();
|
||||
void ResetParticle();
|
||||
|
||||
//inline
|
||||
void SetMoveValue( const D3DXVECTOR3& vPos );
|
||||
void SetRotateValue( float fRot );
|
||||
void SetCollisionSpherePos( const D3DXVECTOR3& vPos );
|
||||
void SetCollisionSphereRadius( float fRadius );
|
||||
float GetCollisionSphereRadius() const;
|
||||
void SetModel( CZ3DGeneralChrModel* pModel );
|
||||
void SetCapeNationalFlagTexture( const char* strFileName );
|
||||
void SetCapeBackgroundTexture( const char* strFileName );
|
||||
void SetEnable( bool bIsEnable );
|
||||
};
|
||||
|
||||
/************************************************************************/
|
||||
/* Inline */
|
||||
/************************************************************************/
|
||||
inline void CCharacterCape::MoveLockedParticle( const D3DXVECTOR3& vMoveValue )
|
||||
{
|
||||
m_vMoveValue = vMoveValue;
|
||||
for( unsigned int i = 0; i < m_LockedParticleList.size(); i++ )
|
||||
{
|
||||
m_LockedParticleList[i]->vPos += m_vMoveValue;
|
||||
}
|
||||
}
|
||||
|
||||
inline void CCharacterCape::RotateLockedParticle( float fFrameRot )
|
||||
{
|
||||
m_fRotateValue = fFrameRot;
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetMoveValue( const D3DXVECTOR3& vPos )
|
||||
{
|
||||
m_vOldPos = m_vCurPos;
|
||||
m_vCurPos = vPos;
|
||||
m_vMoveValue = m_vCurPos - m_vOldPos;
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetRotateValue( float fRot )
|
||||
{
|
||||
m_fOldRot = m_fCurRot;
|
||||
m_fCurRot = fRot;
|
||||
m_fRotateValue = m_fCurRot - m_fOldRot;
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetCollisionSpherePos( const D3DXVECTOR3& vPos )
|
||||
{
|
||||
m_CollisionSphere.vPos = vPos;
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetCollisionSphereRadius( float fRadius )
|
||||
{
|
||||
m_CollisionSphere.fRadius = fRadius;
|
||||
}
|
||||
|
||||
inline float CCharacterCape::GetCollisionSphereRadius() const
|
||||
{
|
||||
return m_CollisionSphere.fRadius;
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetModel( CZ3DGeneralChrModel* pModel )
|
||||
{
|
||||
m_pChrModel = pModel;
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetCapeBackgroundTexture( const char* strFileName )
|
||||
{
|
||||
strcpy( m_strCapeBackground, strFileName );
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetCapeNationalFlagTexture( const char* strFileName )
|
||||
{
|
||||
strcpy( m_strCapeNationalFlag, strFileName );
|
||||
}
|
||||
|
||||
inline void CCharacterCape::SetEnable( bool bIsEnable )
|
||||
{
|
||||
m_bEnable = bIsEnable;
|
||||
}
|
||||
4001
Engine/Zalla3D Scene Class/CharacterLightShadowManager.cpp
Normal file
4001
Engine/Zalla3D Scene Class/CharacterLightShadowManager.cpp
Normal file
File diff suppressed because it is too large
Load Diff
216
Engine/Zalla3D Scene Class/CharacterLightShadowManager.h
Normal file
216
Engine/Zalla3D Scene Class/CharacterLightShadowManager.h
Normal file
@@ -0,0 +1,216 @@
|
||||
// CharacterLightShadowManager.h: interface for the CCharacterLightShadowManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CHARACTERLIGHTSHADOWMANAGER_H__33851909_688F_4AB6_B1C8_A6A5D8F8011A__INCLUDED_)
|
||||
#define AFX_CHARACTERLIGHTSHADOWMANAGER_H__33851909_688F_4AB6_B1C8_A6A5D8F8011A__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <vector>
|
||||
#include "Z3DGeneralChrModel.h"
|
||||
#include "Z3DAttachment.h"
|
||||
#include "RenderTexture.h"
|
||||
#include "HeightFieldScene.h"
|
||||
#include "CollisionDetection.h"
|
||||
//#include "Z3DSoundEventHelper.h"
|
||||
#include "Z3DEventSignal.h"
|
||||
|
||||
#define EVENT_HIT 0x00000001<<0
|
||||
#define EVENT_WEAPON_TRAIL_ON 0x00000001<<1
|
||||
#define EVENT_WEAPON_TRAIL_OFF 0x00000001<<2
|
||||
#define EVENT_JUMP 0x00000001<<3
|
||||
#define EVENT_WALK 0x00000001<<4
|
||||
#define EVENT_CANCEL 0x00000001<<5
|
||||
#define EVENT_SHOT 0x00000001<<6
|
||||
#define EVENT_JUST 0x00000001<<7
|
||||
#define EVENT_JUSTSTART 0x00000001<<8
|
||||
#define EVENT_JUSTEND 0x00000001<<9
|
||||
#define EVENT_HIT_LEFT 0x00000001<<10
|
||||
//CollisionDetection Type
|
||||
#define CDT_NONE 0
|
||||
#define CDT_FULL 1
|
||||
#define CDT_ONLYTERRAIN 2
|
||||
#define CDT_FIRSTBOTTOM 3
|
||||
#define CDT_SKYUNIT 4
|
||||
|
||||
#define HOUSETYPENUM 8
|
||||
const char * const strHouseName[HOUSETYPENUM] = {
|
||||
"wt_sg_a000.r3s", // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ϼ<EFBFBD>
|
||||
"OuterCastle_FrontDoor.R3S", // <20><><EFBFBD><EFBFBD>
|
||||
"wt_cb_a000.r3s", // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
"king_power_7000.r3s", // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (ī<><C4AB><EFBFBD><EFBFBD>Ʈ)
|
||||
"life_eui_GG_6000.r3s", // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> (<28><EFBFBD>ī<EFBFBD><C4AB><EFBFBD><EFBFBD>)
|
||||
"excavator_7000.r3s", // ä<><C3A4><EFBFBD><EFBFBD>
|
||||
"wts_sg_a000.r3s", // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
"OuterCastle_FrontDoor_Open.R3S" // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
};
|
||||
const char * const strMedHouseName[HOUSETYPENUM] = {
|
||||
"medwt_sg_a000.r3s",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"wtsO_sg_a000.r3s",
|
||||
""
|
||||
};
|
||||
const char * const strInHouseName[HOUSETYPENUM] = {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
};
|
||||
class CCharacterLightShadowManager
|
||||
{
|
||||
CHeightFieldScene *m_pHeightField;
|
||||
class CChrLightNode
|
||||
{
|
||||
public:
|
||||
D3DLIGHT8 m_Light;
|
||||
int m_dwTimer;
|
||||
};
|
||||
DWORD m_dwCharacterPixelShader;
|
||||
DWORD m_dwCharacterVertexShader;
|
||||
DWORD m_dwCharacterSpecPixelShader;
|
||||
DWORD m_dwCharacterSpecularVertexShader;
|
||||
LPDIRECT3DTEXTURE8 m_pTex_DiffSpec_IlluminationMap;
|
||||
/*
|
||||
// static List<CollisionType> m_CharacterCollisionType;
|
||||
// static List<CZ3DGeneralChrModel*> m_CharacterList;
|
||||
// static List<CZ3DSoundEventHelper*> m_CharacterSoundHelperList;
|
||||
// static List<POINT> m_CharacterScreenPositionList;
|
||||
// static List<bool> m_CharacterAttackEventList;
|
||||
// static List<bool> m_CharacterTrailOnEventList;
|
||||
// static List<bool> m_CharacterTrailOffEventList;
|
||||
// static List<int> m_CharacterDelayTimer;
|
||||
// static List<CChrLightNode> m_CharacterLightList;
|
||||
// static List<vector3> m_CharacterPerFrameMove;
|
||||
// static List<vector3> m_CharacterRealPosition;
|
||||
// static List<int> m_CharacterRandomPostionTimer;
|
||||
// static List<vector3> m_CharacterRandomPostionAdder;
|
||||
*/
|
||||
|
||||
public:
|
||||
|
||||
class CCharacterDataNode
|
||||
{
|
||||
public:
|
||||
CollisionType m_CollisionType;
|
||||
CZ3DGeneralChrModel *m_pChrmodel;
|
||||
POINT m_ptScreenPosition;
|
||||
DWORD m_dwEvent;
|
||||
int m_DelayTimer;
|
||||
CChrLightNode m_Light;
|
||||
vector3 m_vecPerFrameMove;
|
||||
float m_fAccelate;
|
||||
vector3 m_vecZeroVelocity;
|
||||
vector3 m_vecRealPosition;
|
||||
int m_RandomPositionTimer;
|
||||
float m_fFallSpeed;
|
||||
vector3 m_vecRandomPositionAdder;
|
||||
bool m_bFirstAccelate;
|
||||
bool m_bCollisionDetectAble;
|
||||
bool m_bGravityAble;
|
||||
int m_CollisionDetectType;
|
||||
bool m_bRender;
|
||||
bool m_bHide; // ij<><C4B3><EFBFBD><EFBFBD> Hide (<28>浹<EFBFBD><E6B5B9><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
bool m_bSkipCollision; // <20>浹ó<E6B5B9><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
float m_fAlphaValue;
|
||||
|
||||
int m_cAttackEvent;
|
||||
int m_cJumpEvent;
|
||||
int m_cWalkEvent;
|
||||
int m_cCancelEvent;
|
||||
int m_cShotEvent;
|
||||
int m_cJustEvent;
|
||||
int m_cJustStartEvent;
|
||||
int m_cJustEndEvent;
|
||||
bool m_bBuild; // <20>Ǽ<EFBFBD> <20><><EFBFBD><EFBFBD> flag
|
||||
};
|
||||
|
||||
CCharacterDataNode GetCharacterDataNode(CZ3DGeneralChrModel *pChrmodel);
|
||||
void SetCharacterDataNode(CCharacterDataNode SetNode);
|
||||
void CharacterCollisionDetectType(CZ3DGeneralChrModel *pChrmodel,int nType);
|
||||
void CharacterGravityAble(CZ3DGeneralChrModel *pChrmodel,bool bGravityAble);
|
||||
static void CharacterCollisionAble(CZ3DGeneralChrModel *pChrmodel, bool bCollisionDetectionAble);
|
||||
void CharacterFirstAccelate(CZ3DGeneralChrModel *pChrmodel,bool bFirstAccelate);
|
||||
float GetCharacterVelocity(CZ3DGeneralChrModel *pChrmodel);
|
||||
CollisionType GetCharacterCollisionType(CZ3DGeneralChrModel *pChrmodel);
|
||||
static std::vector<CCharacterDataNode> m_CharacterList;
|
||||
|
||||
void RenderGlare(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void CharacterRandomPos(CZ3DGeneralChrModel *pChrmodel,int nTimer,vector3 vecRand);
|
||||
vector3 GetCharacterMovementVector(CZ3DGeneralChrModel *pChrmodel);
|
||||
void CharacterMovementVector(CZ3DGeneralChrModel *pChrmodel,vector3 vecChrMove,float fAccelate=0.0f);
|
||||
void DelChrLight(DWORD dwLightID);
|
||||
void UpdateLight();
|
||||
void AddChrLight(CZ3DGeneralChrModel *pChrmodel,vector3 vecPos,DWORD dwColor,float fLens,DWORD dwTime);
|
||||
void CreateEditor();
|
||||
void AddDelayTimer(CZ3DGeneralChrModel *pChr,int nDelay);
|
||||
int GetCharacterEvent(CZ3DGeneralChrModel *pChrmodel,DWORD Event);
|
||||
void CharacterSoundPlay(CZ3DGeneralChrModel *pChrmodel, char *strSoundFile);
|
||||
void HeightFiledOnChrFixPos();
|
||||
CollisionType CharacterCollisionType(CZ3DGeneralChrModel* pFindCharacter);
|
||||
|
||||
static CRenderTexture m_pShadowTexture;//<2F><EFBFBD><D7B8><EFBFBD>
|
||||
CTexture *m_pCharacterLight;// <20><><EFBFBD><EFBFBD> light
|
||||
|
||||
void CameraTest(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void SetHeightField(CHeightFieldScene *pHeightField){m_pHeightField=pHeightField;};
|
||||
|
||||
void UpdateFrame(int m_nFocuesCharacter);
|
||||
void SetChrBuildEnable(bool bBuild, int nFocusCharacter = 0);
|
||||
bool GetChrBuildEnable(int nFocusCharacter = 0);
|
||||
void ActionProcess();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// by yundi 2004.12.14
|
||||
//
|
||||
// flush accumulated events of all charaters register in character manager
|
||||
void FlushAccumulatedCharacterEvents();
|
||||
|
||||
//CZ3DGeneralChrModel* AddCharacter( Z3D_CHR_TYPE ct, Z3D_CHR_FACE_TYPE ft, Z3D_CHR_HAIR_STYLE hs, Z3D_CHR_DEFAULT_TYPE dt );
|
||||
CZ3DGeneralChrModel* AddCharacter( const char* szGCMDSName, const char* szFaceType, const char* szHairStyle ,int iValue = -1,CZ3DGeneralChrModel **ppOld = NULL,bool bHouse = false,int iHouseType = -1,D3DXVECTOR3 vecPos = D3DXVECTOR3(0.0f,0.0f,0.0f));
|
||||
CZ3DGeneralChrModel* ReplaceCharacter( CZ3DGeneralChrModel* pChrOldModel, const char* szGCMDSName, vector3& vecPos = vector3(0.0f,0.0f,0.0f) );
|
||||
CZ3DGeneralChrModel* SwitchingModel(int iNum,CZ3DGeneralChrModel *pNew);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// by ichabod
|
||||
void DeleteHouse( CZ3DGeneralChrModel* pDelChr ) ;
|
||||
CCharacterDataNode* GetCharacterDataNodeEx( CZ3DGeneralChrModel *pModel ) ;
|
||||
CCharacterDataNode UndeleteListChr( CZ3DGeneralChrModel* pModel ) ;
|
||||
void UnallocListChr( CCharacterDataNode pModel, BOOL bFirst = FALSE ) ;
|
||||
int GetCharacterDataNodeIndex( CZ3DGeneralChrModel *pModel ) ;
|
||||
VOID SetNodeModel( CZ3DGeneralChrModel *pOrg, CZ3DGeneralChrModel *pNew ) ;
|
||||
void SwapElement( CCharacterLightShadowManager::CCharacterDataNode Node1,
|
||||
CCharacterLightShadowManager::CCharacterDataNode Node2 ) ;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
void DeleteCharacter(CZ3DGeneralChrModel* pDelChr);
|
||||
void DeleteElement(CZ3DGeneralChrModel* pDelChr);
|
||||
|
||||
float GetCollisionChrCamera(vector3 vecStart,vector3 vecEnd);
|
||||
void HeightFieldShadowRender(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void HeightFieldCharacterLightRender(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
|
||||
void InHouseShadowRender(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void CharacterLightSetting(int nChr,LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
|
||||
void Create();
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderGlow(IDirect3DDevice8* pDevice);
|
||||
void RenderEnv(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
|
||||
CCharacterLightShadowManager();
|
||||
virtual ~CCharacterLightShadowManager();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_CHARACTERLIGHTSHADOWMANAGER_H__33851909_688F_4AB6_B1C8_A6A5D8F8011A__INCLUDED_)
|
||||
424
Engine/Zalla3D Scene Class/ChristmasParticle.cpp
Normal file
424
Engine/Zalla3D Scene Class/ChristmasParticle.cpp
Normal file
@@ -0,0 +1,424 @@
|
||||
// ChristmasParticle.cpp: implementation of the CChristmasParticle class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ChristmasParticle.cpp: implementation of the CChristmasParticle class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "ChristmasParticle.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
CChristmasParticle::CChristmasParticle()
|
||||
{
|
||||
m_pVertexBuffer = NULL;
|
||||
m_pIndexBuffer = NULL;
|
||||
|
||||
m_pImageTexture = NULL;
|
||||
|
||||
m_fHeight = 0.0f;
|
||||
// m_bStart = false;
|
||||
m_vecCenter = D3DXVECTOR3(0.0f,0.0f,0.0f);
|
||||
m_vecUp = D3DXVECTOR3(0.0f,0.0f,0.0f);
|
||||
m_vecRight = D3DXVECTOR3(0.0f,0.0f,0.0f);
|
||||
m_bPointSprite = true;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
CChristmasParticle::~CChristmasParticle()
|
||||
{
|
||||
if(m_pVertexBuffer != NULL) {
|
||||
m_pVertexBuffer->Release();
|
||||
m_pVertexBuffer= NULL;
|
||||
}
|
||||
if(m_pIndexBuffer != NULL) {
|
||||
m_pIndexBuffer->Release();
|
||||
m_pIndexBuffer = NULL;
|
||||
|
||||
}
|
||||
|
||||
if(m_pImageTexture != NULL) {
|
||||
delete m_pImageTexture;
|
||||
m_pImageTexture = NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CChristmasParticle::Init(int iNodesNum,char *strTexture) {
|
||||
|
||||
|
||||
m_pDevice = CSceneManager::GetDevice();
|
||||
// Point Sprite Check
|
||||
D3DCAPS8 CapsTest;
|
||||
|
||||
m_pDevice->GetDeviceCaps(&CapsTest);
|
||||
|
||||
if((float)(CapsTest.MaxPointSize) <= 32.0f)
|
||||
m_bPointSprite = false;
|
||||
else
|
||||
m_bPointSprite = true;
|
||||
|
||||
|
||||
m_bPointSprite = false;
|
||||
|
||||
CTexture::SetPath(EFFECTTEXTUREPATH);
|
||||
|
||||
m_pImageTexture = new CTexture;
|
||||
|
||||
m_pImageTexture->Load(strTexture);
|
||||
|
||||
BYTE *pImage = (BYTE *)m_pImageTexture->Lock();
|
||||
|
||||
|
||||
InitParticle(iNodesNum,"CParticle.dds");
|
||||
SetParticlePosition(pImage,32,32);
|
||||
m_pImageTexture->Unlock();
|
||||
|
||||
if(m_bPointSprite == true ) {
|
||||
m_pDevice->CreateVertexBuffer(sizeof(CChristmasParticleVertex) * iNodesNum,D3DUSAGE_WRITEONLY,dwChristmasParticleVertexDecl,D3DPOOL_DEFAULT,&m_pVertexBuffer);
|
||||
}
|
||||
else {
|
||||
|
||||
m_pDevice->CreateVertexBuffer(sizeof(CRainParticleVertex) * m_iVertexBufferNum,D3DUSAGE_WRITEONLY,dwRainParticleVertexDecl,D3DPOOL_DEFAULT,&m_pVertexBuffer);
|
||||
m_pDevice->CreateIndexBuffer(sizeof(WORD) * m_iIndexBufferNum,D3DUSAGE_WRITEONLY,D3DFMT_INDEX16 ,D3DPOOL_DEFAULT,&m_pIndexBuffer);
|
||||
|
||||
WORD *pIndex = NULL;
|
||||
m_pIndexBuffer->Lock(0,0,(BYTE **)&pIndex,0);
|
||||
int i;
|
||||
|
||||
for( i= 0 ; i < m_iNodesNum; i++ ) {
|
||||
|
||||
pIndex[(i*6)] = (i * 4)+2;
|
||||
pIndex[(i*6)+1] = (i * 4);
|
||||
pIndex[(i*6)+2] = (i * 4)+3;
|
||||
|
||||
pIndex[(i*6)+3] = (i * 4)+3;
|
||||
pIndex[(i*6)+4] = (i * 4);
|
||||
pIndex[(i*6)+5] = (i * 4)+1;
|
||||
|
||||
//pIndex+=6;
|
||||
|
||||
}
|
||||
m_pIndexBuffer->Unlock();
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
0 ---- 1
|
||||
| |
|
||||
| |
|
||||
2 ---- 3
|
||||
|
||||
Index : 203 , 301
|
||||
*/
|
||||
void CChristmasParticle::UpdateBuffer(float fStep) {
|
||||
|
||||
//Update(fStep,m_fHeight);
|
||||
|
||||
|
||||
|
||||
if(m_bPointSprite == true) {
|
||||
int i;
|
||||
D3DXMATRIX matWorldView;
|
||||
D3DXMATRIX matWorld,matView;
|
||||
D3DXVECTOR3 vecRight,vecUp;
|
||||
D3DXVECTOR3 vecPos,vecSize;
|
||||
DWORD dwColor;
|
||||
D3DXVECTOR3 vecTmp;
|
||||
|
||||
m_pDevice->GetTransform(D3DTS_VIEW,&matView);
|
||||
|
||||
|
||||
vecRight = D3DXVECTOR3(matView._11,matView._21,matView._31);
|
||||
D3DXVec3Normalize(&vecRight,&vecRight);
|
||||
|
||||
vecUp = D3DXVECTOR3(matView._12,matView._22,matView._32);
|
||||
D3DXVec3Normalize(&vecUp,&vecUp);
|
||||
|
||||
m_iScreenNodesNum = 0;
|
||||
|
||||
CChristmasParticleVertex *pVertex = NULL;
|
||||
m_pVertexBuffer->Lock(0,0,(BYTE **)&pVertex,0);
|
||||
for(i = 0; i < m_iImageParticleNum; i++ ) {
|
||||
if( m_pNodes[i].m_fLife>0.0f ) {
|
||||
|
||||
|
||||
vecPos = m_pNodes[i].m_vecPos;
|
||||
vecPos -= m_vecCenter;
|
||||
|
||||
//dwColor = D3DCOLOR_COLORVALUE(((rand() % 100) / 100.0f),((rand() % 100) / 100.0f),((rand() % 100) / 100.0f),m_pNodes[i].m_fVisible);
|
||||
|
||||
dwColor = D3DCOLOR_COLORVALUE(m_pNodes[i].m_vecColor.x,m_pNodes[i].m_vecColor.y,m_pNodes[i].m_vecColor.z,m_pNodes[i].m_fVisible);
|
||||
pVertex[m_iScreenNodesNum].m_dwColor = dwColor;
|
||||
pVertex[m_iScreenNodesNum].m_vecPos = vecPos;
|
||||
|
||||
m_iScreenNodesNum++;
|
||||
|
||||
}
|
||||
else {
|
||||
m_pNodes[i].m_vecPos = m_vecPos;
|
||||
}
|
||||
}
|
||||
|
||||
m_pVertexBuffer->Unlock();
|
||||
|
||||
}
|
||||
else { // Point Sprite Not Use.
|
||||
|
||||
int i;
|
||||
|
||||
D3DXMATRIX matWorldView;
|
||||
D3DXMATRIX matWorld,matView;
|
||||
D3DXVECTOR3 vecRight,vecUp;
|
||||
D3DXVECTOR3 vecPos,vecSize;
|
||||
DWORD dwColor;
|
||||
D3DXVECTOR3 vecTmp;
|
||||
|
||||
m_pDevice->GetTransform(D3DTS_VIEW,&matView);
|
||||
|
||||
|
||||
vecRight = D3DXVECTOR3(matView._11,matView._21,matView._31);
|
||||
D3DXVec3Normalize(&vecRight,&vecRight);
|
||||
|
||||
vecUp = D3DXVECTOR3(matView._12,matView._22,matView._32);
|
||||
D3DXVec3Normalize(&vecUp,&vecUp);
|
||||
|
||||
m_iScreenNodesNum = 0;
|
||||
|
||||
CRainParticleVertex *pVertex = NULL;
|
||||
m_pVertexBuffer->Lock(0,0,(BYTE **)&pVertex,0);
|
||||
for(i = 0; i < m_iImageParticleNum; i++ ) {
|
||||
if( m_pNodes[i].m_fLife>0.0f ) {
|
||||
|
||||
vecPos = m_pNodes[i].m_vecPos;
|
||||
vecPos -= m_vecCenter;
|
||||
|
||||
vecSize = D3DXVECTOR3(m_pNodes[i].m_vecSize.x,m_pNodes[i].m_vecSize.z,0.0f);
|
||||
vecSize.z = (vecSize.x + vecSize.z) /2.0f;
|
||||
|
||||
dwColor = D3DCOLOR_COLORVALUE(m_pNodes[i].m_vecColor.x,m_pNodes[i].m_vecColor.y,m_pNodes[i].m_vecColor.z,m_pNodes[i].m_fVisible);
|
||||
pVertex[m_iScreenNodesNum].m_dwColor = dwColor;
|
||||
pVertex[m_iScreenNodesNum + 1].m_dwColor = dwColor;
|
||||
pVertex[m_iScreenNodesNum + 2].m_dwColor = dwColor;
|
||||
pVertex[m_iScreenNodesNum + 3].m_dwColor = dwColor;
|
||||
|
||||
pVertex[m_iScreenNodesNum].m_vecTexcoord = D3DXVECTOR2(0.0f,1.0f);
|
||||
pVertex[m_iScreenNodesNum + 1].m_vecTexcoord = D3DXVECTOR2(1.0f,1.0f);
|
||||
pVertex[m_iScreenNodesNum + 2].m_vecTexcoord = D3DXVECTOR2(0.0f,0.0f);
|
||||
pVertex[m_iScreenNodesNum + 3].m_vecTexcoord = D3DXVECTOR2(1.0f,0.0);
|
||||
|
||||
vecTmp = (vecUp - vecRight);
|
||||
|
||||
vecTmp.x *= vecSize.x;
|
||||
vecTmp.y *= vecSize.y;
|
||||
vecTmp.z *= vecSize.z;
|
||||
|
||||
pVertex[m_iScreenNodesNum].m_vecPos = ( vecTmp )+vecPos;
|
||||
|
||||
vecTmp = (vecRight + vecUp);
|
||||
|
||||
vecTmp.x *= vecSize.x;
|
||||
vecTmp.y *= vecSize.y;
|
||||
vecTmp.z *= vecSize.z;
|
||||
|
||||
pVertex[m_iScreenNodesNum+1].m_vecPos = ( vecTmp )+vecPos;
|
||||
|
||||
vecTmp = (vecRight + vecUp);
|
||||
|
||||
vecTmp.x *= -vecSize.x;
|
||||
vecTmp.y *= -vecSize.y;
|
||||
vecTmp.z *= -vecSize.z;
|
||||
|
||||
pVertex[m_iScreenNodesNum+2].m_vecPos = ( vecTmp )+vecPos;
|
||||
|
||||
vecTmp = (vecRight - vecUp);
|
||||
|
||||
vecTmp.x *= vecSize.x;
|
||||
vecTmp.y *= vecSize.y;
|
||||
vecTmp.z *= vecSize.z;
|
||||
|
||||
pVertex[m_iScreenNodesNum+3].m_vecPos = ( vecTmp )+vecPos;
|
||||
|
||||
|
||||
m_iScreenNodesNum += 4;
|
||||
}
|
||||
}
|
||||
|
||||
m_pVertexBuffer->Unlock();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void CChristmasParticle::Render() {
|
||||
|
||||
if(m_bPointSprite) {
|
||||
D3DXMATRIX matView;
|
||||
D3DXMatrixIdentity(&matView);
|
||||
D3DXMATRIX matInvView;
|
||||
|
||||
m_pDevice->GetTransform(D3DTS_VIEW,&matView);
|
||||
matView._41 = matView._42 = matView._43 =0.0;
|
||||
D3DXMatrixInverse(&matInvView,NULL,&matView);
|
||||
|
||||
//m_Device->SetTransform(D3DTS_WORLD,&world);
|
||||
|
||||
D3DXMATRIX matWorld;
|
||||
D3DXMATRIX matBefore;
|
||||
m_pDevice->GetTransform(D3DTS_WORLD,&matBefore);
|
||||
|
||||
D3DXMatrixMultiply(&matWorld,&matBefore,&matInvView);
|
||||
matWorld._41 = m_vecCenter.x;
|
||||
matWorld._42 = m_vecCenter.y;
|
||||
matWorld._43 = m_vecCenter.z;
|
||||
|
||||
m_pDevice->SetTransform(D3DTS_WORLD,&matWorld);
|
||||
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
|
||||
m_pDevice->SetStreamSource(0,m_pVertexBuffer,sizeof(CChristmasParticleVertex));
|
||||
|
||||
|
||||
m_pDevice->SetTexture(0,m_pParticleTexture->GetTexture());
|
||||
m_pDevice->SetVertexShader(dwChristmasParticleVertexDecl);
|
||||
m_pDevice->SetPixelShader(NULL);
|
||||
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
|
||||
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
||||
|
||||
m_pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
|
||||
m_pDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
|
||||
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
||||
m_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE );
|
||||
m_pDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
|
||||
|
||||
//////
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(SMINSIZE) );
|
||||
|
||||
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSCALE_A, FtoDW(0.00f) );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSCALE_B, FtoDW(0.00f) );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSCALE_C, FtoDW(1.00f) );
|
||||
|
||||
if(m_bStart && !m_bExtUse)
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(20.0f) );
|
||||
else
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(7.0f) );
|
||||
|
||||
//////
|
||||
m_pDevice->DrawPrimitive( D3DPT_POINTLIST, 0,m_iScreenNodesNum);
|
||||
if(rand() % 2) {
|
||||
if(!m_bExtUse) {
|
||||
m_pDevice->SetTexture(0,m_pExtTexture->GetTexture());
|
||||
}
|
||||
m_pDevice->DrawPrimitive( D3DPT_POINTLIST, 0,m_iScreenNodesNum);
|
||||
|
||||
}
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
m_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
|
||||
m_pDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
|
||||
|
||||
////
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.00f) );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(1.0f) );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSPRITEENABLE,FALSE);
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSCALEENABLE,FALSE);
|
||||
m_pDevice->SetTransform(D3DTS_WORLD,&matBefore);
|
||||
}
|
||||
else { // Point Sprite Not Use.
|
||||
|
||||
|
||||
D3DXMATRIX matView;
|
||||
D3DXMatrixIdentity(&matView);
|
||||
D3DXMATRIX matInvView;
|
||||
|
||||
m_pDevice->GetTransform(D3DTS_VIEW,&matView);
|
||||
matView._41 = matView._42 = matView._43 =0.0;
|
||||
D3DXMatrixInverse(&matInvView,NULL,&matView);
|
||||
|
||||
//m_Device->SetTransform(D3DTS_WORLD,&world);
|
||||
|
||||
D3DXMATRIX matWorld;
|
||||
D3DXMATRIX matBefore;
|
||||
m_pDevice->GetTransform(D3DTS_WORLD,&matBefore);
|
||||
|
||||
D3DXMatrixMultiply(&matWorld,&matBefore,&matInvView);
|
||||
matWorld._41 = m_vecCenter.x;
|
||||
matWorld._42 = m_vecCenter.y;
|
||||
matWorld._43 = m_vecCenter.z;
|
||||
|
||||
m_pDevice->SetTransform(D3DTS_WORLD,&matWorld);
|
||||
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
|
||||
m_pDevice->SetStreamSource(0,m_pVertexBuffer,sizeof(CRainParticleVertex));
|
||||
m_pDevice->SetIndices(m_pIndexBuffer,0);
|
||||
|
||||
m_pDevice->SetTexture(0,m_pParticleTexture->GetTexture());
|
||||
m_pDevice->SetVertexShader(dwRainParticleVertexDecl);
|
||||
|
||||
m_pDevice->SetPixelShader(NULL);
|
||||
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE );
|
||||
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
||||
|
||||
m_pDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE );
|
||||
m_pDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
|
||||
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
||||
m_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
|
||||
m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE );
|
||||
m_pDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
|
||||
|
||||
|
||||
m_pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0,m_iScreenNodesNum,
|
||||
0,(m_iScreenNodesNum / 2));
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
m_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
|
||||
m_pDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
|
||||
////
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.00f) );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSIZE, FtoDW(1.0f) );
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSPRITEENABLE,FALSE);
|
||||
m_pDevice->SetRenderState( D3DRS_POINTSCALEENABLE,FALSE);
|
||||
m_pDevice->SetTransform(D3DTS_WORLD,&matBefore);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
67
Engine/Zalla3D Scene Class/ChristmasParticle.h
Normal file
67
Engine/Zalla3D Scene Class/ChristmasParticle.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// ChristmasParticle.h: interface for the CChristmasParticle class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CHRISTMASPARTICLE_H__24078282_01D5_4099_A4CF_1B76DA1E6890__INCLUDED_)
|
||||
#define AFX_CHRISTMASPARTICLE_H__24078282_01D5_4099_A4CF_1B76DA1E6890__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "NatureParticle.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/timeb.h>
|
||||
|
||||
const DWORD dwRainParticleVertexDecl = (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(0));
|
||||
|
||||
class CRainParticleVertex {
|
||||
public:
|
||||
D3DXVECTOR3 m_vecPos;
|
||||
DWORD m_dwColor;
|
||||
D3DXVECTOR2 m_vecTexcoord;
|
||||
|
||||
};
|
||||
|
||||
|
||||
const DWORD dwChristmasParticleVertexDecl = (D3DFVF_XYZ | D3DFVF_DIFFUSE);
|
||||
|
||||
class CChristmasParticleVertex {
|
||||
public:
|
||||
D3DXVECTOR3 m_vecPos;
|
||||
DWORD m_dwColor;
|
||||
|
||||
};
|
||||
|
||||
class CTexture;
|
||||
class CChristmasParticle : public CNatureParticle
|
||||
{
|
||||
public:
|
||||
CChristmasParticle();
|
||||
virtual ~CChristmasParticle();
|
||||
virtual void Init(int iNodesNum,char *strTexture);
|
||||
virtual void UpdateBuffer(float fStep = 1.0f);
|
||||
virtual void Render();
|
||||
void SetStart(bool bFlag) { m_bStart = bFlag;}
|
||||
void SetCenter(float fX,float fY,float fZ) { m_vecCenter = D3DXVECTOR3(fX,fY,fZ);}
|
||||
DWORD FtoDW( FLOAT f ) { return *((DWORD*)&f); }
|
||||
float m_fHeight;
|
||||
// bool m_bStart;
|
||||
|
||||
D3DXVECTOR3 m_vecCenter;
|
||||
D3DXVECTOR3 m_vecUp;
|
||||
D3DXVECTOR3 m_vecRight;
|
||||
DWORD m_dwStartTime;
|
||||
|
||||
protected:
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;
|
||||
LPDIRECT3DDEVICE8 m_pDevice;
|
||||
CTexture *m_pImageTexture;
|
||||
bool m_bPointSprite;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_CHRISTMASPARTICLE_H__24078282_01D5_4099_A4CF_1B76DA1E6890__INCLUDED_)
|
||||
263
Engine/Zalla3D Scene Class/ChristmasParticleManager.cpp
Normal file
263
Engine/Zalla3D Scene Class/ChristmasParticleManager.cpp
Normal file
@@ -0,0 +1,263 @@
|
||||
// hristmasParticleManager.cpp: implementation of the ChristmasParticleManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "ChristmasParticleManager.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
const D3DXVECTOR3 g_ChristmasParticleColor[4] = {
|
||||
D3DXVECTOR3(1.0f, 0.22f, 0.16f),
|
||||
D3DXVECTOR3(0.05f, 0.38f,1.0f),
|
||||
D3DXVECTOR3(0.07f,1.0f, 0.34f),
|
||||
D3DXVECTOR3(1.0f, 0.83f,0.38f),
|
||||
};
|
||||
CChristmasParticleManager::CChristmasParticleManager()
|
||||
{
|
||||
m_iNodesNum = 0;
|
||||
m_Nodes.clear();
|
||||
|
||||
}
|
||||
|
||||
CChristmasParticleManager::~CChristmasParticleManager()
|
||||
{
|
||||
for(int i = 0; i < (int)m_Nodes.size(); i++ ) {
|
||||
if(m_Nodes[i] != NULL) {
|
||||
delete m_Nodes[i];
|
||||
m_Nodes[i] = NULL;
|
||||
}
|
||||
}
|
||||
m_Nodes.clear();
|
||||
|
||||
}
|
||||
|
||||
void CChristmasParticleManager::AddParticle(CChristmasParticle *pNode,float fX,float fY,float fZ) {
|
||||
|
||||
if(pNode != NULL) {
|
||||
pNode->SetMaxLife(75.0f);
|
||||
pNode->SetVisible(1.0f,0.0f);
|
||||
pNode->SetBaseMass(1.2f);
|
||||
pNode->SetFraction(0.0f);
|
||||
pNode->SetGravity( 0.0f, -0.1f, 0.0f );
|
||||
pNode->SetColor(1.0f,1.0f,1.0f,0.0f,0.0f,0.0f);
|
||||
pNode->SetSize(4.0f,4.0f,4.0f,4.0f);
|
||||
|
||||
D3DXVECTOR3 vecCenter;
|
||||
|
||||
vector3 vecDir = CSceneManager::m_ViewCamera->GetViewTowardVector();
|
||||
vecDir.Normalize();
|
||||
|
||||
|
||||
vecCenter.x = fX + vecDir.x * 1500.0f;
|
||||
vecCenter.y = fY + 100;//m_pChristmasParticle->m_fHeight;
|
||||
|
||||
vecCenter.z = fZ + vecDir.z * 1500.0f;
|
||||
pNode->SetCenter(vecCenter.x,vecCenter.y,vecCenter.z);
|
||||
|
||||
m_Nodes.push_back(pNode);
|
||||
m_iNodesNum = (int)m_Nodes.size();
|
||||
}
|
||||
}
|
||||
void CChristmasParticleManager::DeleteEnd() {
|
||||
int i;
|
||||
for( i= (m_iNodesNum - 1); i >= 0; i-- ) {
|
||||
if((m_Nodes[i] != NULL) && !m_Nodes[i]->m_bStart && m_Nodes[i]->GetEnd()) {
|
||||
delete m_Nodes[i];
|
||||
m_Nodes[i] = NULL;
|
||||
m_Nodes.erase(m_Nodes.begin() + i);
|
||||
m_iNodesNum = (int)m_Nodes.size();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
void CChristmasParticleManager::DeleteParticle(int iNum) {
|
||||
if(m_iNodesNum <= iNum) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_Nodes[iNum] != NULL) {
|
||||
delete m_Nodes[iNum];
|
||||
m_Nodes[iNum] = NULL;
|
||||
|
||||
}
|
||||
m_Nodes.erase(m_Nodes.begin() + iNum);
|
||||
m_iNodesNum = (int)m_Nodes.size();
|
||||
|
||||
}
|
||||
void CChristmasParticleManager::Render() {
|
||||
|
||||
int i;
|
||||
for( i = 0; i < m_iNodesNum; i++ ) {
|
||||
if(m_Nodes[i] != NULL) {
|
||||
m_Nodes[i]->UpdateBuffer();
|
||||
m_Nodes[i]->Render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void CChristmasParticleManager::ProcessParticle() {
|
||||
|
||||
int i,j;
|
||||
|
||||
|
||||
DWORD dwNowTime;
|
||||
dwNowTime = timeGetTime();
|
||||
|
||||
|
||||
for( i = 0; i < m_iNodesNum; i++ ) {
|
||||
float fDeltaTime = 0.0f;
|
||||
int iSkipFrame = 1;
|
||||
|
||||
if(m_Nodes[i] == NULL)
|
||||
continue;
|
||||
|
||||
if(m_Nodes[i]->m_bFirst != true) {
|
||||
|
||||
if( (dwNowTime - m_Nodes[i]->m_dwStartTime) >= 50) {//m_TickFrame) {
|
||||
iSkipFrame =((int)(dwNowTime - m_Nodes[i]->m_dwStartTime)/ 50);
|
||||
}
|
||||
else {
|
||||
iSkipFrame = 0;
|
||||
}
|
||||
|
||||
|
||||
/*fDeltaTime = static_cast<float>((NowTime.millitm - m_Nodes[i]->m_StartTime.millitm));
|
||||
iSkipFrame = (int)(fDeltaTime * 0.0001f);
|
||||
|
||||
if(iSkipFrame <= 0)
|
||||
iSkipFrame = 1;
|
||||
*/
|
||||
}
|
||||
for(j = 0; j < iSkipFrame; j++ ) {
|
||||
if((m_Nodes[i]->m_bStart) && (m_Nodes[i]->m_fHeight < 600.0f)) {
|
||||
m_Nodes[i]->m_fHeight += 20.0f;
|
||||
|
||||
}
|
||||
if(m_Nodes[i]->m_bFirst == true) { // <20><> ó<><C3B3> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ
|
||||
|
||||
m_Nodes[i]->m_bFirst = false;
|
||||
D3DXMATRIX matView,matInvView;
|
||||
|
||||
CSceneManager::GetDevice()->GetTransform(D3DTS_VIEW,&matView);
|
||||
D3DXMatrixInverse(&matInvView,NULL,&matView);
|
||||
D3DXVECTOR3 vecViewPos = D3DXVECTOR3(matInvView._41,matInvView._42,matInvView._43);
|
||||
|
||||
|
||||
vector3 vecDir = CSceneManager::m_ViewCamera->GetViewTowardVector();
|
||||
vecDir.Normalize();
|
||||
vector3 vecUp = CSceneManager::m_ViewCamera->GetViewUpVector();
|
||||
vecUp.Normalize();
|
||||
|
||||
vector3 vecCross = vecDir ^ vecUp;
|
||||
vecCross.Normalize();
|
||||
|
||||
|
||||
/*
|
||||
vecViewPos.x = CSceneManager::m_CharacterManager.m_CharacterList[0].m_vecRealPosition.x + vecDir.x * 1500.0f;
|
||||
vecViewPos.y = CSceneManager::m_CharacterManager.m_CharacterList[0].m_vecRealPosition.y + 100;//m_pChristmasParticle->m_fHeight;
|
||||
|
||||
vecViewPos.z = CSceneManager::m_CharacterManager.m_CharacterList[0].m_vecRealPosition.z + vecDir.z * 1500.0f;
|
||||
*/
|
||||
//m_Nodes[i]->m_vecCenter = D3DXVECTOR3(vecViewPos.x,vecViewPos.y,vecViewPos.z);
|
||||
m_Nodes[i]->m_vecRight = D3DXVECTOR3(vecCross.x,vecCross.y,vecCross.z);
|
||||
m_Nodes[i]->m_vecUp = D3DXVECTOR3(vecUp.x,vecUp.y,vecUp.z);
|
||||
m_Nodes[i]->SetStart(true);
|
||||
///Sound
|
||||
CEffScript *pCristmas = new CEffScript;
|
||||
pCristmas->GetScriptBinData("Christmaspiyu.esf");
|
||||
|
||||
CSceneManager::AddInterfaceScript(pCristmas);
|
||||
vector3 *vecCameraPos = CSceneManager::m_ViewCamera->GetPosition();
|
||||
|
||||
pCristmas->SetStartPos(vecCameraPos->x,vecCameraPos->y,vecCameraPos->z);
|
||||
pCristmas->SetEndPos(vecCameraPos->x,vecCameraPos->y,vecCameraPos->z);
|
||||
|
||||
pCristmas->SetChr(NULL,NULL);
|
||||
pCristmas->SetChrFwd(0.0f,0.0f,1.0f);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(m_Nodes[i]->m_fHeight >= 600.0f) { // <20><>ǥ <20><>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD> <20>ö<EFBFBD><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_Nodes[i]->SetExtUse(true);
|
||||
m_Nodes[i]->SetStart(false);
|
||||
m_Nodes[i]->SetMaxLife(120.0f);
|
||||
|
||||
///Sound
|
||||
CEffScript *pCristmas = new CEffScript;
|
||||
|
||||
|
||||
int iRand = rand() % 4;
|
||||
|
||||
switch(iRand) {
|
||||
case 0:
|
||||
m_Nodes[i]->SetColor(g_ChristmasParticleColor[0].x,g_ChristmasParticleColor[0].y,g_ChristmasParticleColor[0].z,
|
||||
g_ChristmasParticleColor[0].x,g_ChristmasParticleColor[0].y,g_ChristmasParticleColor[0].z);
|
||||
|
||||
break;
|
||||
case 1:
|
||||
m_Nodes[i]->SetColor(g_ChristmasParticleColor[1].x,g_ChristmasParticleColor[1].y,g_ChristmasParticleColor[2].z,
|
||||
g_ChristmasParticleColor[1].x,g_ChristmasParticleColor[1].y,g_ChristmasParticleColor[2].z);
|
||||
|
||||
|
||||
break;
|
||||
case 2:
|
||||
m_Nodes[i]->SetColor(g_ChristmasParticleColor[2].x,g_ChristmasParticleColor[2].y,g_ChristmasParticleColor[2].z,
|
||||
g_ChristmasParticleColor[2].x,g_ChristmasParticleColor[2].y,g_ChristmasParticleColor[2].z);
|
||||
|
||||
|
||||
break;
|
||||
case 3:
|
||||
m_Nodes[i]->SetColor(g_ChristmasParticleColor[3].x,g_ChristmasParticleColor[3].y,g_ChristmasParticleColor[3].z,
|
||||
g_ChristmasParticleColor[3].x,g_ChristmasParticleColor[3].y,g_ChristmasParticleColor[3].z);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
pCristmas->GetScriptBinData("ChristParticle.esf");
|
||||
CSceneManager::AddInterfaceScript(pCristmas);
|
||||
vector3 *vecCameraPos = CSceneManager::m_ViewCamera->GetPosition();
|
||||
|
||||
pCristmas->SetStartPos(vecCameraPos->x,vecCameraPos->y,vecCameraPos->z);
|
||||
pCristmas->SetEndPos(vecCameraPos->x,vecCameraPos->y,vecCameraPos->z);
|
||||
|
||||
pCristmas->SetChr(NULL,NULL);
|
||||
pCristmas->SetChrFwd(0.0f,0.0f,1.0f);
|
||||
|
||||
|
||||
m_Nodes[i]->SetVisible(1.0f,0.0f);
|
||||
m_Nodes[i]->CreateChristmasParticle(m_Nodes[i]->m_vecCenter.x,
|
||||
(m_Nodes[i]->m_vecCenter.y + (m_Nodes[i]->m_fHeight * 2.0f)),m_Nodes[i]->m_vecCenter.z,
|
||||
5.0f,850,
|
||||
m_Nodes[i]->m_vecRight.x,m_Nodes[i]->m_vecRight.y,m_Nodes[i]->m_vecRight.z,
|
||||
m_Nodes[i]->m_vecUp.x,m_Nodes[i]->m_vecUp.y,m_Nodes[i]->m_vecUp.z,true);
|
||||
|
||||
m_Nodes[i]->m_fHeight = 0.0f;
|
||||
}
|
||||
else if(m_Nodes[i]->m_bStart) {
|
||||
m_Nodes[i]->SetMaxLife(10.0f);
|
||||
m_Nodes[i]->SetColor(1.0f,1.0f,1.0f,1.0f,1.0f,1.0f);
|
||||
m_Nodes[i]->SetVisible(0.3f,0.0f);
|
||||
m_Nodes[i]->CreateChristmasParticle(m_Nodes[i]->m_vecCenter.x,
|
||||
(m_Nodes[i]->m_vecCenter.y + m_Nodes[i]->m_fHeight),m_Nodes[i]->m_vecCenter.z,0.1f,10,
|
||||
m_Nodes[i]->m_vecRight.x,m_Nodes[i]->m_vecRight.y,m_Nodes[i]->m_vecRight.z,
|
||||
m_Nodes[i]->m_vecUp.x,m_Nodes[i]->m_vecUp.y,m_Nodes[i]->m_vecUp.z);
|
||||
|
||||
}
|
||||
|
||||
m_Nodes[i]->m_dwStartTime = timeGetTime();
|
||||
m_Nodes[i]->Update(1.0f,m_Nodes[i]->m_fHeight);
|
||||
|
||||
}
|
||||
}
|
||||
DeleteEnd();
|
||||
|
||||
|
||||
}
|
||||
32
Engine/Zalla3D Scene Class/ChristmasParticleManager.h
Normal file
32
Engine/Zalla3D Scene Class/ChristmasParticleManager.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// hristmasParticleManager.h: interface for the ChristmasParticleManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_HRISTMASPARTICLEMANAGER_H__114DD580_853B_4680_B82E_A16AFBC204A2__INCLUDED_)
|
||||
#define AFX_HRISTMASPARTICLEMANAGER_H__114DD580_853B_4680_B82E_A16AFBC204A2__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
#include "ChristmasParticle.h"
|
||||
#include <vector>
|
||||
|
||||
class CChristmasParticleManager
|
||||
{
|
||||
protected:
|
||||
int m_iNodesNum;
|
||||
std::vector<CChristmasParticle *> m_Nodes;
|
||||
|
||||
public:
|
||||
CChristmasParticleManager();
|
||||
virtual ~CChristmasParticleManager();
|
||||
|
||||
void AddParticle(CChristmasParticle *,float fX,float fY,float fZ);
|
||||
void ProcessParticle();
|
||||
void DeleteParticle(int iNum);
|
||||
void Render();
|
||||
void DeleteEnd();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_HRISTMASPARTICLEMANAGER_H__114DD580_853B_4680_B82E_A16AFBC204A2__INCLUDED_)
|
||||
168
Engine/Zalla3D Scene Class/CircleParticle.cpp
Normal file
168
Engine/Zalla3D Scene Class/CircleParticle.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
// CircleParticle.cpp: implementation of the CCircleParticle class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "CircleParticle.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CCircleParticle::CCircleParticle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCircleParticle::~CCircleParticle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCircleParticle::Create(vector3 vecPos, vector3 vecTarget)
|
||||
{
|
||||
vector3 vecDirRand,vecPosRand;
|
||||
vecDirRand=vecTarget-vecPos;
|
||||
vecDirRand.Normalize();
|
||||
|
||||
m_vecPos=vecPos;
|
||||
for(int cParticle=0;cParticle<1000;cParticle++)
|
||||
{
|
||||
vecPosRand=vector3(Random(),Random(),Random());
|
||||
vecPosRand.Normalize();
|
||||
vecPosRand*=Random()*20.0f;
|
||||
|
||||
ParticleNode AddNode;
|
||||
AddNode.m_vecPos0=vecPosRand;
|
||||
AddNode.m_vecPos=AddNode.m_vecPos0;
|
||||
AddNode.m_vecVelocity0=vector3(Random()*0.5f,Random()*0.5f,Random()*0.5f);
|
||||
AddNode.m_vecVelocity0-=vecDirRand*2.0f;
|
||||
AddNode.m_vecVelocity0.Normalize();
|
||||
AddNode.m_vecVelocity=AddNode.m_vecVelocity0;
|
||||
|
||||
AddNode.m_vecAccelate=-vecDirRand*0.01f;
|
||||
|
||||
AddNode.m_fSize=4.0f;
|
||||
AddNode.m_fFadeTime=(Random()+1.0f)*30.0f;
|
||||
AddNode.m_fNowTime=0.0f;
|
||||
AddNode.m_clrStartDiffuse.c=0xffffaaaa;
|
||||
AddNode.m_clrEndDiffuse.c=0xff000000;
|
||||
m_ParticleNodeList.push_back(AddNode);
|
||||
}
|
||||
CTexture::SetPath(FXTEXTUREPATH);
|
||||
m_ParticleTexture.Load("Circle.dds");
|
||||
}
|
||||
|
||||
bool CCircleParticle::Update(float fUpdateTime)
|
||||
{
|
||||
m_NowTime+=0.0f;
|
||||
m_fNowVelocity+=m_fAcceleration;
|
||||
if(m_fNowVelocity>=60.0f)
|
||||
m_fNowVelocity=60.0f;
|
||||
|
||||
|
||||
if(m_NowTime > m_TotalRemainTime)
|
||||
return true;
|
||||
|
||||
//m_vecNowPos=(m_vecTarget-m_vecPos)*(m_NowTime/m_TotalRemainTime)+m_vecPos;
|
||||
m_vecNowPos=m_vecPos;
|
||||
vector3 vecDirRand,vecPosRand;
|
||||
for(int cParticle=0;cParticle<(int)m_ParticleNodeList.size();cParticle++)
|
||||
{
|
||||
if(m_ParticleNodeList[cParticle].m_fNowTime>=m_ParticleNodeList[cParticle].m_fFadeTime)
|
||||
{
|
||||
m_ParticleNodeList[cParticle].m_fNowTime=0.0f;
|
||||
m_ParticleNodeList[cParticle].m_vecPos=m_ParticleNodeList[cParticle].m_vecPos0;
|
||||
m_ParticleNodeList[cParticle].m_vecVelocity=m_ParticleNodeList[cParticle].m_vecVelocity0;
|
||||
}
|
||||
m_ParticleNodeList[cParticle].m_fNowTime+=fUpdateTime;
|
||||
m_ParticleNodeList[cParticle].m_vecPos+=m_ParticleNodeList[cParticle].m_vecVelocity;
|
||||
m_ParticleNodeList[cParticle].m_vecVelocity+=m_ParticleNodeList[cParticle].m_vecAccelate*m_ParticleNodeList[cParticle].m_fNowTime;
|
||||
m_ParticleNodeList[cParticle].m_clrNowDiffuse=color::Interpolation(m_ParticleNodeList[cParticle].m_clrStartDiffuse,
|
||||
m_ParticleNodeList[cParticle].m_clrEndDiffuse,
|
||||
m_ParticleNodeList[cParticle].m_fNowTime/m_ParticleNodeList[cParticle].m_fFadeTime);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CCircleParticle::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE);
|
||||
pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
|
||||
|
||||
matrix matInit;
|
||||
matInit.MakeIdent();
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,matInit);
|
||||
|
||||
vector3 vecTL(-1.0f,1.0f,0.0f);
|
||||
vector3 vecBL(-1.0f,-1.0f,0.0f);
|
||||
vector3 vecBR(1.0f,-1.0f,0.0f);
|
||||
vector3 vecTR(1.0f,1.0f,0.0f);
|
||||
|
||||
matrix matPosition=*m_matPosition;
|
||||
matPosition._41=0.0f;
|
||||
matPosition._42=0.0f;
|
||||
matPosition._43=0.0f;
|
||||
|
||||
matrix matTL,matBL,matBR,matTR;
|
||||
matTL.Translation(vecTL);
|
||||
matBL.Translation(vecBL);
|
||||
matBR.Translation(vecBR);
|
||||
matTR.Translation(vecTR);
|
||||
|
||||
matTL=matTL*matPosition;
|
||||
matBL=matBL*matPosition;
|
||||
matBR=matBR*matPosition;
|
||||
matTR=matTR*matPosition;
|
||||
|
||||
vecTL=matTL.GetLoc();
|
||||
vecBL=matBL.GetLoc();
|
||||
vecBR=matBR.GetLoc();
|
||||
vecTR=matTR.GetLoc();
|
||||
|
||||
LVertex Vertex[4];
|
||||
Vertex[0].tu=0.0f;Vertex[0].tv=1.0f;
|
||||
Vertex[1].tu=0.0f;Vertex[1].tv=0.0f;
|
||||
Vertex[2].tu=1.0f;Vertex[2].tv=1.0f;
|
||||
Vertex[3].tu=1.0f;Vertex[3].tv=0.0f;
|
||||
|
||||
pd3dDevice->SetVertexShader(LVERTEXFVF);
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
|
||||
pd3dDevice->SetTexture(0,m_ParticleTexture.GetTexture());
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
|
||||
Vertex[0].spec.c=0x0;Vertex[1].spec.c=0x0;Vertex[2].spec.c=0x0;Vertex[3].spec.c=0x0;
|
||||
|
||||
for(int cParticle=0;cParticle<(int)m_ParticleNodeList.size();cParticle++)
|
||||
{
|
||||
if(m_ParticleNodeList[cParticle].m_fNowTime>=m_ParticleNodeList[cParticle].m_fFadeTime)
|
||||
continue;
|
||||
|
||||
Vertex[0].v=m_ParticleNodeList[cParticle].m_vecPos+vecBL*m_ParticleNodeList[cParticle].m_fSize+m_vecNowPos;
|
||||
Vertex[1].v=m_ParticleNodeList[cParticle].m_vecPos+vecTL*m_ParticleNodeList[cParticle].m_fSize+m_vecNowPos;
|
||||
Vertex[2].v=m_ParticleNodeList[cParticle].m_vecPos+vecBR*m_ParticleNodeList[cParticle].m_fSize+m_vecNowPos;
|
||||
Vertex[3].v=m_ParticleNodeList[cParticle].m_vecPos+vecTR*m_ParticleNodeList[cParticle].m_fSize+m_vecNowPos;
|
||||
|
||||
|
||||
Vertex[0].diff.c=Vertex[1].diff.c=Vertex[2].diff.c=Vertex[3].diff.c=
|
||||
m_ParticleNodeList[cParticle].m_clrNowDiffuse.c;
|
||||
|
||||
pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Vertex,sizeof(LVertex));
|
||||
}
|
||||
pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
|
||||
pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
}
|
||||
29
Engine/Zalla3D Scene Class/CircleParticle.h
Normal file
29
Engine/Zalla3D Scene Class/CircleParticle.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// CircleParticle.h: interface for the CCircleParticle class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CIRCLEPARTICLE_H__46C31B75_D404_429C_9E90_E3AFE811CE52__INCLUDED_)
|
||||
#define AFX_CIRCLEPARTICLE_H__46C31B75_D404_429C_9E90_E3AFE811CE52__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "Particle.h"
|
||||
|
||||
class CCircleParticle : public CParticle
|
||||
{
|
||||
public:
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
vector3 m_vecPos,m_vecTarget,m_vecNowPos;
|
||||
float m_fNowVelocity,m_fAcceleration;
|
||||
float m_TotalRemainTime;
|
||||
float m_NowTime;
|
||||
bool Update(float fUpdateTime);
|
||||
void Create(vector3 vecPos,vector3 vecTarget);
|
||||
CCircleParticle();
|
||||
virtual ~CCircleParticle();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_CIRCLEPARTICLE_H__46C31B75_D404_429C_9E90_E3AFE811CE52__INCLUDED_)
|
||||
323
Engine/Zalla3D Scene Class/ClothMgr.cpp
Normal file
323
Engine/Zalla3D Scene Class/ClothMgr.cpp
Normal file
@@ -0,0 +1,323 @@
|
||||
#include ".\clothmgr.h"
|
||||
#include "SceneManager.h"
|
||||
#include "dxutil.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
CClothMgr* CClothMgr::s_pInstance = NULL;
|
||||
|
||||
CQuadClothResource::CQuadClothResource() : m_pVB(NULL),
|
||||
m_pIB(NULL), m_pClothVertex(NULL), m_pClothIndex(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CQuadClothResource::~CQuadClothResource()
|
||||
{
|
||||
SAFE_RELEASE( m_pVB );
|
||||
SAFE_RELEASE( m_pIB );
|
||||
SAFE_DELETE_ARRAY( m_pClothVertex );
|
||||
SAFE_DELETE_ARRAY( m_pClothIndex );
|
||||
}
|
||||
|
||||
void CQuadClothResource::Init( int iRow, int iCol )
|
||||
{
|
||||
m_iCol = iCol;
|
||||
m_iRow = iRow;
|
||||
|
||||
LPDIRECT3DDEVICE8 pd3dDevice = CSceneManager::GetDevice();
|
||||
|
||||
m_iNumVertex = (iRow+1) * (iCol+1);
|
||||
m_iNumFace = iRow * iCol * 2;
|
||||
|
||||
m_pClothVertex = new ClothVertex[m_iNumVertex];
|
||||
m_pClothIndex = new WORD[m_iNumFace*3];
|
||||
|
||||
int iVertex = 0;
|
||||
int iIndex = 0;
|
||||
int r, c;
|
||||
for( r = 0; r <= iRow; r++ )
|
||||
{
|
||||
for( c = 0; c <= iCol; c++ )
|
||||
{
|
||||
m_pClothVertex[iVertex].pos = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_pClothVertex[iVertex].n = D3DXVECTOR3( rand()%100, rand()%100, -rand()%100 );
|
||||
|
||||
if( c == 0 ) m_pClothVertex[iVertex].u = 0.0f;
|
||||
else m_pClothVertex[iVertex].u = (float)c/(float)iCol;
|
||||
if( r == 0 ) m_pClothVertex[iVertex].v = 0.0f;
|
||||
else m_pClothVertex[iVertex].v = (float)r/(float)iRow;
|
||||
|
||||
iVertex++;
|
||||
}
|
||||
}
|
||||
|
||||
for( r = 0; r < iRow; r++ )
|
||||
{
|
||||
for( c = 0; c < iCol; c++ )
|
||||
{
|
||||
m_pClothIndex[iIndex++] = c + r*(iCol+1);
|
||||
m_pClothIndex[iIndex++] = c + r*(iCol+1) + 1;
|
||||
m_pClothIndex[iIndex++] = c + (r+1)*(iCol+1);
|
||||
m_pClothIndex[iIndex++] = c + r*(iCol+1) + 1;
|
||||
m_pClothIndex[iIndex++] = c + (r+1)*(iCol+1) + 1;
|
||||
m_pClothIndex[iIndex++] = c + (r+1)*(iCol+1);
|
||||
}
|
||||
}
|
||||
|
||||
pd3dDevice->CreateVertexBuffer( sizeof(ClothVertex)*m_iNumVertex, D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC, ClothVertex::FVF,
|
||||
D3DPOOL_DEFAULT, &m_pVB );
|
||||
pd3dDevice->CreateIndexBuffer( sizeof(WORD)*m_iNumFace*3, D3DUSAGE_WRITEONLY,
|
||||
D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIB );
|
||||
|
||||
void* pVert;
|
||||
m_pVB->Lock( 0, 0, (BYTE**)&pVert, 0 );
|
||||
memcpy( pVert, m_pClothVertex, sizeof(ClothVertex)*m_iNumVertex );
|
||||
m_pVB->Unlock();
|
||||
|
||||
void* pIndics;
|
||||
m_pIB->Lock( 0, 0, (BYTE**)&pIndics, 0 );
|
||||
memcpy( pIndics, m_pClothIndex, sizeof(WORD)*iRow*iCol*2*3 );
|
||||
m_pIB->Unlock();
|
||||
}
|
||||
|
||||
void CQuadClothResource::Render()
|
||||
{
|
||||
D3DXMATRIX matWorld;
|
||||
LPDIRECT3DDEVICE8 pd3dDevice = CSceneManager::GetDevice();
|
||||
D3DXMatrixIdentity( &matWorld );
|
||||
pd3dDevice->SetVertexShader( ClothVertex::FVF );
|
||||
pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(ClothVertex) );
|
||||
pd3dDevice->SetIndices( m_pIB, 0 );
|
||||
pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
|
||||
pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, m_iNumVertex, 0, m_iNumFace );
|
||||
}
|
||||
|
||||
void CQuadClothResource::UpdateLockedVertex()
|
||||
{
|
||||
void* pVert;
|
||||
m_pVB->Lock( 0, 0, (BYTE**)&pVert, D3DLOCK_DISCARD|D3DLOCK_NOSYSLOCK );
|
||||
memcpy( pVert, m_pClothVertex, sizeof(ClothVertex)*m_iNumVertex );
|
||||
m_pVB->Unlock();
|
||||
}
|
||||
|
||||
void CQuadClothResource::ComputeNormals()
|
||||
{
|
||||
D3DXVECTOR3 a, b, N;
|
||||
int ComputeNum;
|
||||
|
||||
for( int r = 0; r <= m_iRow; r++ )
|
||||
{
|
||||
for( int c = 0; c <= m_iCol; c++ )
|
||||
{
|
||||
ComputeNum = 0;
|
||||
m_pClothVertex[ROWCOL(r,c)].n = D3DXVECTOR3(0,0,-1);
|
||||
|
||||
if( r > 0 && c > 0 && r < m_iRow && c < m_iCol )
|
||||
{
|
||||
CalcNormal(r, c, r, c-1, r-1, c);
|
||||
ComputeNum++;
|
||||
|
||||
CalcNormal(r, c, r-1, c, r, c+1);
|
||||
ComputeNum++;
|
||||
|
||||
CalcNormal(r, c, r, c+1, r+1, c);
|
||||
ComputeNum++;
|
||||
|
||||
CalcNormal(r, c, r+1, c, r, c-1);
|
||||
ComputeNum++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if( c == 0 && r == 0 )
|
||||
{
|
||||
CalcNormal(r, c, r, c+1, r+1, c);
|
||||
ComputeNum++;
|
||||
}
|
||||
if( c == m_iCol && r == 0 )
|
||||
{
|
||||
CalcNormal(r, c, r+1, c, r, c-1);
|
||||
ComputeNum++;
|
||||
}
|
||||
if( c == 0 && r == m_iRow )
|
||||
{
|
||||
CalcNormal(r, c, r-1, c, r, c+1);
|
||||
ComputeNum++;
|
||||
}
|
||||
if( c == m_iCol && r == m_iRow )
|
||||
{
|
||||
CalcNormal(r, c, r, c-1, r-1, c);
|
||||
ComputeNum++;
|
||||
}
|
||||
|
||||
//--------------------------------
|
||||
//<2F>翷<EFBFBD><EFBFBD>
|
||||
if( c == 0 && r > 0 && r < m_iRow )
|
||||
{
|
||||
CalcNormal(r, c, r-1, c, r, c+1);
|
||||
ComputeNum++;
|
||||
CalcNormal(r, c, r, c+1, r+1, c);
|
||||
ComputeNum++;
|
||||
}
|
||||
if( c == m_iCol && r > 0 && r < m_iRow )
|
||||
{
|
||||
CalcNormal(r, c, r, c-1, r-1, c);
|
||||
ComputeNum++;
|
||||
CalcNormal(r, c, r+1, c, r, c-1);
|
||||
ComputeNum++;
|
||||
}
|
||||
//-------------------------------
|
||||
//<2F><><EFBFBD>ٴڸ<DAB8>
|
||||
if( r == 0 && c > 0 && c < m_iCol )
|
||||
{
|
||||
CalcNormal(r, c, r+1, c, r, c-1);
|
||||
ComputeNum++;
|
||||
CalcNormal(r, c, r, c+1, r+1, c);
|
||||
ComputeNum++;
|
||||
}
|
||||
if( r == m_iRow && c > 0 && c < m_iCol )
|
||||
{
|
||||
CalcNormal(r, c, r, c-1, r-1, c);
|
||||
ComputeNum++;
|
||||
CalcNormal(r, c, r-1, c, r, c+1);
|
||||
ComputeNum++;
|
||||
}
|
||||
}
|
||||
|
||||
m_pClothVertex[ROWCOL(r,c)].n /= (float)ComputeNum;
|
||||
D3DXVec3Normalize( &m_pClothVertex[ROWCOL(r,c)].n, &m_pClothVertex[ROWCOL(r,c)].n );
|
||||
m_pClothVertex[ROWCOL(r,c)].n = -m_pClothVertex[ROWCOL(r,c)].n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CQuadClothResource::CalcNormal( int r, int c, int ar, int ac, int br, int bc )
|
||||
{
|
||||
D3DXVECTOR3 a, b, N;
|
||||
a = m_pClothVertex[ROWCOL(ar,ac)].pos - m_pClothVertex[ROWCOL(r,c)].pos;
|
||||
b = m_pClothVertex[ROWCOL(br,bc)].pos - m_pClothVertex[ROWCOL(r,c)].pos;
|
||||
D3DXVec3Cross( &N, &a, &b );
|
||||
D3DXVec3Normalize( &N, &N );
|
||||
m_pClothVertex[ROWCOL(r,c)].n += N;
|
||||
}
|
||||
|
||||
void CQuadClothResource::SetupCloth( CCharacterCape* pCape )
|
||||
{
|
||||
int iVertexIndex = 0;
|
||||
for( int r=0; r <= pCape->m_Prop.m_iRow; r++)
|
||||
{
|
||||
for(int c=0; c <= pCape->m_Prop.m_iCol; c++)
|
||||
{
|
||||
SetVertex(iVertexIndex, pCape->m_pParticles[iVertexIndex].vPos);
|
||||
iVertexIndex ++;
|
||||
}
|
||||
}
|
||||
|
||||
ComputeNormals();
|
||||
UpdateLockedVertex();
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
CClothMgr::CClothMgr(void)
|
||||
{
|
||||
m_CapeRenderer.Init( 5, 4 );
|
||||
}
|
||||
|
||||
CClothMgr::~CClothMgr(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CClothMgr* CClothMgr::_Instance()
|
||||
{
|
||||
if( s_pInstance == NULL )
|
||||
{
|
||||
s_pInstance = new CClothMgr;
|
||||
}
|
||||
|
||||
return s_pInstance;
|
||||
}
|
||||
|
||||
void CClothMgr::_Destroy()
|
||||
{
|
||||
if( s_pInstance )
|
||||
{
|
||||
s_pInstance->ReleaseAllData();
|
||||
delete s_pInstance;
|
||||
}
|
||||
}
|
||||
|
||||
void CClothMgr::Update()
|
||||
{
|
||||
CLOTHMAP::iterator iter;
|
||||
|
||||
for( iter = m_ClothMap.begin(); iter != m_ClothMap.end(); iter++ )
|
||||
{
|
||||
iter->second->Update();
|
||||
}
|
||||
}
|
||||
|
||||
void CClothMgr::AddCharacterCape( CZ3DGeneralChrModel* pChrModel )
|
||||
{
|
||||
CLOTHMAP::iterator iter;
|
||||
iter = m_ClothMap.find( pChrModel );
|
||||
if( iter == m_ClothMap.end() )
|
||||
{
|
||||
vector3 point1, point2, length;
|
||||
pChrModel->GetFixedPoint( 0, point1 );
|
||||
pChrModel->GetFixedPoint( 1, point2 );
|
||||
length = point1- point2;
|
||||
|
||||
CClothProperty Prop;
|
||||
Prop.Init( length.GetLens(), 100, 5, 4, CFT_TRAPEZOID );
|
||||
CCharacterCape* pCloth = new CCharacterCape( &Prop );
|
||||
pCloth->Create( CCharacterCape::HUMAN_MAN, pChrModel );
|
||||
m_ClothMap.insert( CLOTHMAP::iterator::value_type(pChrModel, pCloth) );
|
||||
}
|
||||
}
|
||||
|
||||
void CClothMgr::DeleteCharacterCape( CZ3DGeneralChrModel* pChrModel )
|
||||
{
|
||||
CLOTHMAP::iterator iter;
|
||||
iter = m_ClothMap.find( pChrModel );
|
||||
if( iter != m_ClothMap.end() )
|
||||
{
|
||||
SAFE_DELETE( iter->second );
|
||||
m_ClothMap.erase( iter );
|
||||
}
|
||||
}
|
||||
|
||||
void CClothMgr::ReleaseAllData()
|
||||
{
|
||||
if( m_ClothMap.size() != 0 )
|
||||
{
|
||||
CLOTHMAP::iterator iter;
|
||||
for( iter = m_ClothMap.begin(); iter != m_ClothMap.end(); iter++ )
|
||||
{
|
||||
SAFE_DELETE(iter->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CCharacterCape* CClothMgr::GetCharacterCape( CZ3DGeneralChrModel* pModel )
|
||||
{
|
||||
CCharacterCape* pCape=NULL;
|
||||
CLOTHMAP::iterator iter;
|
||||
iter = m_ClothMap.find( pModel );
|
||||
if( iter != m_ClothMap.end() )
|
||||
{
|
||||
pCape = iter->second;
|
||||
}
|
||||
|
||||
return pCape;
|
||||
}
|
||||
|
||||
void CClothMgr::Reset()
|
||||
{
|
||||
for(CLOTHMAP::iterator iter = m_ClothMap.begin();
|
||||
iter != m_ClothMap.end(); iter++ )
|
||||
{
|
||||
iter->second->ResetParticle();
|
||||
}
|
||||
}
|
||||
80
Engine/Zalla3D Scene Class/ClothMgr.h
Normal file
80
Engine/Zalla3D Scene Class/ClothMgr.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#include "d3dx8.h"
|
||||
#include "CharacterCape.h"
|
||||
#include "CharacterLightShadowManager.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
class CQuadClothResource
|
||||
{
|
||||
struct ClothVertex
|
||||
{
|
||||
enum { FVF = D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1 };
|
||||
D3DXVECTOR3 pos;
|
||||
D3DXVECTOR3 n;
|
||||
float u, v;
|
||||
};
|
||||
|
||||
private:
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pVB;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pIB;
|
||||
ClothVertex* m_pClothVertex;
|
||||
WORD* m_pClothIndex;
|
||||
int m_iNumVertex;
|
||||
int m_iNumFace;
|
||||
int m_iCol;
|
||||
int m_iRow;
|
||||
|
||||
private:
|
||||
void CalcNormal( int r, int c, int ar, int ac, int br, int bc );
|
||||
inline int ROWCOL( int r, int c ) { return (r*(m_iCol+1)+c); }
|
||||
|
||||
public:
|
||||
CQuadClothResource();
|
||||
virtual ~CQuadClothResource();
|
||||
|
||||
void Init( int Row, int Col );
|
||||
void Render();
|
||||
void ShadowRender();
|
||||
void UpdateLockedVertex();
|
||||
void SetVertex( int index, D3DXVECTOR3& vPos );
|
||||
void ComputeNormals();
|
||||
void SetupCloth( CCharacterCape* pCape );
|
||||
};
|
||||
|
||||
inline void CQuadClothResource::SetVertex( int index, D3DXVECTOR3& vPos )
|
||||
{
|
||||
m_pClothVertex[index].pos = vPos;
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
class CClothMgr
|
||||
{
|
||||
public:
|
||||
typedef map<CZ3DGeneralChrModel*, CCharacterCape*> CLOTHMAP;
|
||||
friend class CCharacterCape;
|
||||
|
||||
public:
|
||||
static CClothMgr* s_pInstance;
|
||||
CLOTHMAP m_ClothMap;
|
||||
CQuadClothResource m_CapeRenderer;
|
||||
|
||||
private:
|
||||
CClothMgr(void);
|
||||
|
||||
public:
|
||||
virtual ~CClothMgr(void);
|
||||
static CClothMgr* _Instance();
|
||||
static void _Destroy();
|
||||
void ReleaseAllData();
|
||||
|
||||
void Update();
|
||||
void Render();
|
||||
void AddCharacterCape( CZ3DGeneralChrModel* pChrModel );
|
||||
void DeleteCharacterCape( CZ3DGeneralChrModel* pChrModel );
|
||||
CCharacterCape* GetCharacterCape( CZ3DGeneralChrModel* pChrModel );
|
||||
void Reset();
|
||||
};
|
||||
530
Engine/Zalla3D Scene Class/ClothSimulation.cpp
Normal file
530
Engine/Zalla3D Scene Class/ClothSimulation.cpp
Normal file
@@ -0,0 +1,530 @@
|
||||
#include ".\clothsimulation.h"
|
||||
#include "dxutil.h"
|
||||
#include <assert.h>
|
||||
|
||||
const DWORD CClothSimulation::ClothVertex::FVF = D3DFVF_XYZ|D3DFVF_TEX1;
|
||||
|
||||
CClothSimulation::CClothSimulation(void) : m_vWindDirection(D3DXVECTOR3(0.0f,0.0f,0.0f)), m_iWindForce(0),
|
||||
m_iNumRow(0), m_iNumCol(0), m_pVB(NULL), m_pIB(NULL), m_pTexture(NULL), m_vVirtualSimulation(D3DXVECTOR3(0,0,0)),
|
||||
m_vMoveParticle(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), m_fRotateParticle(0.0f), m_vWorldPos(D3DXVECTOR3(0,0,0)),
|
||||
m_vMoveValue(D3DXVECTOR3(0,0,0))
|
||||
{
|
||||
}
|
||||
|
||||
CClothSimulation::~CClothSimulation(void)
|
||||
{
|
||||
SAFE_RELEASE( m_pVB );
|
||||
SAFE_RELEASE( m_pIB );
|
||||
SAFE_RELEASE( m_pTexture );
|
||||
}
|
||||
|
||||
void CClothSimulation::Create( LPDIRECT3DDEVICE8 pd3dDevice, int iNumRow, int iNumCol, int iWidth, int iHeight )
|
||||
{
|
||||
assert( iNumRow > 0 );
|
||||
assert( iNumCol > 0 );
|
||||
assert( iWidth > 0 );
|
||||
assert( iHeight > 0 );
|
||||
assert( pd3dDevice );
|
||||
|
||||
m_pd3dDevice = pd3dDevice;
|
||||
m_iNumRow = iNumRow;
|
||||
m_iNumCol = iNumCol;
|
||||
m_iWidth = iWidth;
|
||||
m_iHeight = iHeight;
|
||||
|
||||
m_CollisionBox.Init( D3DXVECTOR3(0.0F, 0.0F, 40.0F), D3DXVECTOR3(0.0F, 0.0F, -1.0F), 100, 500, 500, 50 );
|
||||
D3DXVec3Normalize( &m_CollisionBox.vCollisionNormal, &m_CollisionBox.vCollisionNormal );
|
||||
m_CollisionBox.vCollisionNormal *= m_CollisionBox.fCollisionConstant;
|
||||
|
||||
int r, c;
|
||||
float f;
|
||||
D3DXVECTOR3 vL;
|
||||
int count = 0;
|
||||
int n = NUMSTRUCTURALSPRINGS;
|
||||
int iVertexIndex = 0;
|
||||
|
||||
for( r = 0; r <= NUMROWS; r++ )
|
||||
{
|
||||
for( c = 0; c <= NUMCOLUMNS; c++ )
|
||||
{
|
||||
//<2F><>ƼŬ <20><><EFBFBD><EFBFBD>
|
||||
if((r == 0) && (c == 0))
|
||||
f = 1;
|
||||
else if((r == NUMROWS) && (c == 0))
|
||||
f = 2;
|
||||
else if((r == 0) && (c == NUMCOLUMNS))
|
||||
f = 2;
|
||||
else if((r == NUMROWS) && (c == NUMCOLUMNS))
|
||||
f = 1;
|
||||
else if(((r == 0) || (r == NUMROWS)) && ((c != 0) && (c != NUMCOLUMNS)))
|
||||
f = 3;
|
||||
else
|
||||
f = 6;
|
||||
|
||||
m_Particles[r][c].fMass = (f * MASSPERFACE) / 3;
|
||||
m_Particles[r][c].fInvMass = 1 / m_Particles[r][c].fMass;
|
||||
m_Particles[r][c].vPos.x = c * CSTEP - (float)CLOTHWIDTH/2;
|
||||
m_Particles[r][c].vPos.y = (CLOTHHEIGHT - (r * RSTEP)) - (float)CLOTHHEIGHT/2;
|
||||
m_Particles[r][c].vPos.z = 0.0f;
|
||||
m_Particles[r][c].vVel = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_Particles[r][c].vAccel = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_Particles[r][c].vForce = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
m_Particles[r][c].bLocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
for( r = 0; r <= NUMROWS; r++ )
|
||||
{
|
||||
for( c = 0; c <= NUMCOLUMNS; c++ )
|
||||
{
|
||||
//<2F><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
m_ClothVertex[iVertexIndex].pos = m_Particles[r][c].vPos;
|
||||
if( c == 0 ) m_ClothVertex[iVertexIndex].u = 0.0f;
|
||||
else m_ClothVertex[iVertexIndex].u = (float)c/(float)NUMCOLUMNS;
|
||||
if( r == 0 ) m_ClothVertex[iVertexIndex].v = 0.0f;
|
||||
else m_ClothVertex[iVertexIndex].v = (float)r/(float)NUMROWS;
|
||||
iVertexIndex++;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(c<NUMCOLUMNS)
|
||||
{
|
||||
m_StructuralSprings[count].p1.r = r;
|
||||
m_StructuralSprings[count].p1.c = c;
|
||||
m_StructuralSprings[count].p2.r = r;
|
||||
m_StructuralSprings[count].p2.c = c+1;
|
||||
m_StructuralSprings[count].k = SPRINGTENSIONCONSTANT;
|
||||
m_StructuralSprings[count].d = SPRINGDAMPINGCONSTANT;
|
||||
vL = m_Particles[r][c].vPos - m_Particles[r][c+1].vPos;
|
||||
m_StructuralSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
if(r<NUMROWS)
|
||||
{
|
||||
m_StructuralSprings[count].p1.r = r;
|
||||
m_StructuralSprings[count].p1.c = c;
|
||||
m_StructuralSprings[count].p2.r = r+1;
|
||||
m_StructuralSprings[count].p2.c = c;
|
||||
m_StructuralSprings[count].k = SPRINGTENSIONCONSTANT;
|
||||
m_StructuralSprings[count].d = SPRINGDAMPINGCONSTANT;
|
||||
vL = m_Particles[r][c].vPos - m_Particles[r+1][c].vPos;
|
||||
m_StructuralSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
if(r<NUMROWS && c<NUMCOLUMNS)
|
||||
{
|
||||
m_StructuralSprings[count].p1.r = r;
|
||||
m_StructuralSprings[count].p1.c = c;
|
||||
m_StructuralSprings[count].p2.r = r+1;
|
||||
m_StructuralSprings[count].p2.c = c+1;
|
||||
m_StructuralSprings[count].k = SPRINGSHEARCONSTANT;
|
||||
m_StructuralSprings[count].d = SPRINGDAMPINGCONSTANT;
|
||||
vL = m_Particles[r][c].vPos - m_Particles[r+1][c+1].vPos;
|
||||
m_StructuralSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
if(c>0 && r<NUMROWS)
|
||||
{
|
||||
m_StructuralSprings[count].p1.r = r;
|
||||
m_StructuralSprings[count].p1.c = c;
|
||||
m_StructuralSprings[count].p2.r = r+1;
|
||||
m_StructuralSprings[count].p2.c = c-1;
|
||||
m_StructuralSprings[count].k = SPRINGSHEARCONSTANT;
|
||||
m_StructuralSprings[count].d = SPRINGDAMPINGCONSTANT;
|
||||
vL = m_Particles[r][c].vPos - m_Particles[r+1][c-1].vPos;
|
||||
m_StructuralSprings[count].L = D3DXVec3Length(&vL);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//<2F>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
iVertexIndex = 0;
|
||||
for( r = 0; r < NUMROWS; r++ )
|
||||
{
|
||||
for( c = 0; c < NUMCOLUMNS; c++ )
|
||||
{
|
||||
m_ClothIndex[iVertexIndex++] = c + r*(NUMCOLUMNS+1);
|
||||
m_ClothIndex[iVertexIndex++] = c + r*(NUMCOLUMNS+1) + 1;
|
||||
m_ClothIndex[iVertexIndex++] = c + (r+1)*(NUMCOLUMNS+1);
|
||||
|
||||
m_ClothIndex[iVertexIndex++] = c + r*(NUMCOLUMNS+1) + 1;
|
||||
m_ClothIndex[iVertexIndex++] = c + (r+1)*(NUMCOLUMNS+1) + 1;
|
||||
m_ClothIndex[iVertexIndex++] = c + (r+1)*(NUMCOLUMNS+1);
|
||||
}
|
||||
}
|
||||
|
||||
m_pd3dDevice->CreateVertexBuffer( sizeof(ClothVertex)*NUMVERTICES, D3DUSAGE_WRITEONLY|D3DUSAGE_DYNAMIC, ClothVertex::FVF,
|
||||
D3DPOOL_DEFAULT, &m_pVB );
|
||||
m_pd3dDevice->CreateIndexBuffer( sizeof(WORD)*NUMROWS*NUMCOLUMNS*2*3, D3DUSAGE_WRITEONLY,
|
||||
D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pIB );
|
||||
|
||||
void* pVert;
|
||||
m_pVB->Lock( 0, 0, (BYTE**)&pVert, 0 );
|
||||
memcpy( pVert, m_ClothVertex, sizeof(ClothVertex)*NUMVERTICES );
|
||||
m_pVB->Unlock();
|
||||
|
||||
void* pIndics;
|
||||
m_pIB->Lock( 0, 0, (BYTE**)&pIndics, 0 );
|
||||
memcpy( pIndics, m_ClothIndex, sizeof(WORD)*NUMROWS*NUMCOLUMNS*2*3 );
|
||||
m_pIB->Unlock();
|
||||
|
||||
D3DXCreateTextureFromFile( m_pd3dDevice, "c:\\picture.jpg", &m_pTexture );
|
||||
}
|
||||
|
||||
void CClothSimulation::Render()
|
||||
{
|
||||
//D3DXMATRIX matWorld;
|
||||
//D3DXMatrixIdentity( &matWorld );
|
||||
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
|
||||
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
|
||||
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
|
||||
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
|
||||
m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
|
||||
m_pd3dDevice->SetTexture( 0, m_pTexture );
|
||||
//m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
|
||||
//m_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
|
||||
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
|
||||
m_pd3dDevice->SetVertexShader( ClothVertex::FVF );
|
||||
m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(ClothVertex) );
|
||||
m_pd3dDevice->SetIndices( m_pIB, 0 );
|
||||
m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, NUMVERTICES, 0, NUMROWS*NUMCOLUMNS*2 );
|
||||
|
||||
m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
|
||||
m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
|
||||
}
|
||||
|
||||
void CClothSimulation::Update( float dt )
|
||||
{
|
||||
CalculateForce();
|
||||
Integrate( dt );
|
||||
|
||||
void* pVert;
|
||||
m_pVB->Lock( 0, 0, (BYTE**)&pVert, D3DLOCK_DISCARD|D3DLOCK_NOSYSLOCK );
|
||||
memcpy( pVert, m_ClothVertex, sizeof(ClothVertex)*NUMVERTICES );
|
||||
m_pVB->Unlock();
|
||||
}
|
||||
|
||||
void CClothSimulation::CalculateForce()
|
||||
{
|
||||
int r, c, i, r1, c1, r2, c2;
|
||||
D3DXVECTOR3 dragVector;
|
||||
D3DXVECTOR3 f1, f2, d, v;
|
||||
float L, tempValue;
|
||||
D3DXVECTOR3 vRandWind;
|
||||
|
||||
for(r=0; r<=NUMROWS; r++)
|
||||
{
|
||||
for(c=0; c<=NUMCOLUMNS; c++)
|
||||
{
|
||||
m_Particles[r][c].vForce = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
//gravity
|
||||
m_Particles[r][c].vForce.y += (float) (GRAVITY * m_Particles[r][c].fMass);
|
||||
|
||||
// viscous drag
|
||||
dragVector = -m_Particles[r][c].vVel;
|
||||
D3DXVec3Normalize( &dragVector, &dragVector );
|
||||
float tempValue = D3DXVec3Length( &m_Particles[r][c].vVel );
|
||||
m_Particles[r][c].vForce += dragVector * tempValue * tempValue * DRAGCOEFFICIENT;
|
||||
|
||||
// wind
|
||||
if( m_iWindForce )
|
||||
{
|
||||
vRandWind = D3DXVECTOR3( RandNum((int)m_vWindDirection.x), RandNum((int)m_vWindDirection.y),
|
||||
RandNum((int)m_vWindDirection.z) );
|
||||
D3DXVec3Normalize( &vRandWind, &vRandWind );
|
||||
m_Particles[r][c].vForce += vRandWind * (rand()%m_iWindForce);
|
||||
}
|
||||
|
||||
//virtual simulation
|
||||
m_Particles[r][c].vForce += m_vVirtualSimulation * 10 * (rand()%5+5);
|
||||
|
||||
if( !m_Particles[r][c].bLocked )
|
||||
{
|
||||
m_Particles[r][c].vPos += m_vMoveValue*0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_vMoveValue = D3DXVECTOR3(0,0,0);
|
||||
|
||||
// Process spring forces
|
||||
for(i = 0; i<NUMSTRUCTURALSPRINGS; i++)
|
||||
{
|
||||
r1 = m_StructuralSprings[i].p1.r;
|
||||
c1 = m_StructuralSprings[i].p1.c;
|
||||
r2 = m_StructuralSprings[i].p2.r;
|
||||
c2 = m_StructuralSprings[i].p2.c;
|
||||
|
||||
d = m_Particles[r1][c1].vPos - m_Particles[r2][c2].vPos;
|
||||
v = m_Particles[r1][c1].vVel - m_Particles[r2][c2].vVel;
|
||||
L = m_StructuralSprings[i].L;
|
||||
|
||||
tempValue = D3DXVec3Length(&d);
|
||||
|
||||
f1 = -(m_StructuralSprings[i].k * (tempValue - L) +
|
||||
m_StructuralSprings[i].d * ( D3DXVec3Dot(&v, &d) / tempValue )) * ( d / tempValue );
|
||||
f2 = -f1;
|
||||
|
||||
if(m_Particles[r1][c1].bLocked == FALSE)
|
||||
m_Particles[r1][c1].vForce += f1;
|
||||
|
||||
if(m_Particles[r2][c2].bLocked == FALSE)
|
||||
m_Particles[r2][c2].vForce += f2;
|
||||
}
|
||||
}
|
||||
|
||||
void CClothSimulation::Integrate( float dt )
|
||||
{
|
||||
D3DXVECTOR3 Ae;
|
||||
int r, c;
|
||||
int check = 0;
|
||||
int iVertexIndex=0;
|
||||
D3DXMATRIX matRot;
|
||||
|
||||
for(r=0; r<=NUMROWS; r++)
|
||||
{
|
||||
for(c=0; c<=NUMCOLUMNS; c++)
|
||||
{
|
||||
if( !m_Particles[r][c].bLocked )
|
||||
{
|
||||
Ae = m_Particles[r][c].vForce * m_Particles[r][c].fInvMass;
|
||||
m_Particles[r][c].vAccel = Ae;
|
||||
m_Particles[r][c].vVel += Ae * dt;
|
||||
m_Particles[r][c].vPos += m_Particles[r][c].vVel * dt;
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>-<2D><>Ÿ <20><><EFBFBD>й<EFBFBD>
|
||||
|
||||
/*
|
||||
if( m_Particles[r][c].vPos.x > m_CollisionBox.vMin.x &&
|
||||
m_Particles[r][c].vPos.y > m_CollisionBox.vMin.y &&
|
||||
m_Particles[r][c].vPos.z > m_CollisionBox.vMin.z &&
|
||||
m_Particles[r][c].vPos.x < m_CollisionBox.vMax.x &&
|
||||
m_Particles[r][c].vPos.y < m_CollisionBox.vMax.y &&
|
||||
m_Particles[r][c].vPos.z < m_CollisionBox.vMax.z )
|
||||
{
|
||||
//<2F>浹 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD><EFBFBD><EFBFBD> <20>Ǽ<EFBFBD>
|
||||
m_Particles[r][c].vVel += m_CollisionBox.vCollisionNormal*0.2f;
|
||||
}*/
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
//<2F><>ö<EFBFBD>ùķ<C3B9><C4B7>̼ǹ<CCBC><C7B9><EFBFBD>
|
||||
/*
|
||||
m_ClothVertex[iVertexIndex].pos = m_Particles[r][c].vPos - m_vMoveParticle;
|
||||
D3DXMATRIX matRot;
|
||||
D3DXMatrixRotationY( &matRot, -m_fRotateParticle );
|
||||
D3DXVec3TransformCoord( &m_ClothVertex[iVertexIndex].pos, &m_ClothVertex[iVertexIndex].pos, &matRot );
|
||||
|
||||
if( r == 0 && c == 0 ) m_ClothVertex[iVertexIndex].pos = m_vSavePoint2;
|
||||
if( r == 0 && c == 4 ) m_ClothVertex[iVertexIndex].pos = m_vSavePoint;
|
||||
iVertexIndex ++;
|
||||
*/
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ùķ<C3B9><C4B7>̼ǹ<CCBC><C7B9><EFBFBD>
|
||||
m_ClothVertex[iVertexIndex].pos = m_Particles[r][c].vPos;
|
||||
iVertexIndex ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CClothSimulation::LockParticle( int iRow, int iCol )
|
||||
{
|
||||
m_Particles[iRow][iCol].bLocked = true;
|
||||
|
||||
ParticleRef ref;
|
||||
ref.r = iRow;
|
||||
ref.c = iCol;
|
||||
m_LockedParticleMap.insert( PARTICLEMAP::iterator::value_type(&m_Particles[iRow][iCol], ref) );
|
||||
}
|
||||
|
||||
void CClothSimulation::UnLockParticle( int iRow, int iCol )
|
||||
{
|
||||
PARTICLEMAP::iterator iter;
|
||||
m_Particles[iRow][iCol].bLocked = false;
|
||||
iter = m_LockedParticleMap.find( &m_Particles[iRow][iCol] );
|
||||
if( iter != m_LockedParticleMap.end() )
|
||||
{
|
||||
m_LockedParticleMap.erase( iter );
|
||||
}
|
||||
}
|
||||
|
||||
void CClothSimulation::MoveLockedParticle( const D3DXVECTOR3& vMoveValue )
|
||||
{
|
||||
D3DXVECTOR3 TempValue = vMoveValue;
|
||||
D3DXMATRIX matRot;
|
||||
D3DXMatrixRotationY( &matRot, m_fRotateParticle );
|
||||
D3DXVec3TransformCoord( &TempValue, &TempValue, &matRot );
|
||||
|
||||
PARTICLEMAP::iterator iter;
|
||||
for( iter = m_LockedParticleMap.begin(); iter != m_LockedParticleMap.end(); iter++ )
|
||||
{
|
||||
m_Particles[iter->second.r][iter->second.c].vPos += TempValue;
|
||||
}
|
||||
|
||||
m_vMoveParticle += TempValue;
|
||||
|
||||
m_vMoveValue = TempValue;
|
||||
|
||||
//<2F>浹<EFBFBD>ڽ<EFBFBD><DABD>̵<EFBFBD>
|
||||
m_CollisionBox.vCenter += vMoveValue;
|
||||
m_CollisionBox.vMin += vMoveValue;
|
||||
m_CollisionBox.vMax += vMoveValue;
|
||||
}
|
||||
|
||||
void CClothSimulation::RotateLockedParticle( const D3DXVECTOR3& vRot, int CenterRow, int CenterCol )
|
||||
{
|
||||
D3DXMATRIX matWorld, matRot, matTrans;
|
||||
D3DXMatrixRotationYawPitchRoll( &matRot, vRot.y, vRot.x, vRot.z );
|
||||
D3DXVECTOR3 vTemp;
|
||||
D3DXVECTOR3 vPos;
|
||||
|
||||
m_fRotateParticle += vRot.y;
|
||||
|
||||
PARTICLEMAP::iterator iter;
|
||||
for( iter = m_LockedParticleMap.begin(); iter != m_LockedParticleMap.end(); iter++ )
|
||||
{
|
||||
if( iter->second.r == CenterRow && iter->second.c == CenterCol ) continue;
|
||||
|
||||
vTemp = m_Particles[iter->second.r][iter->second.c].vPos - m_Particles[CenterRow][CenterCol].vPos;
|
||||
D3DXMatrixTranslation( &matTrans, vTemp.x, vTemp.y, vTemp.z );
|
||||
D3DXMatrixMultiply( &matWorld, &matTrans, &matRot );
|
||||
vPos = D3DXVECTOR3(0.0F, 0.0F, 0.0F);
|
||||
D3DXVec3TransformCoord( &vPos, &vPos, &matWorld );
|
||||
m_Particles[iter->second.r][iter->second.c].vPos += vPos - vTemp;
|
||||
}
|
||||
|
||||
//<2F>浹<EFBFBD>ڽ<EFBFBD>ȸ<EFBFBD><C8B8>
|
||||
/*
|
||||
vTemp = m_CollisionBox.vMin - m_Particles[CenterRow][CenterCol].vPos;
|
||||
D3DXMatrixTranslation( &matTrans, vTemp.x, vTemp.y, vTemp.z );
|
||||
D3DXMatrixMultiply( &matWorld, &matTrans, &matRot );
|
||||
vPos = D3DXVECTOR3(0.0F, 0.0F, 0.0F);
|
||||
D3DXVec3TransformCoord( &vPos, &vPos, &matWorld );
|
||||
m_CollisionBox.vMin += vPos - vTemp;
|
||||
|
||||
vTemp = m_CollisionBox.vMax - m_Particles[CenterRow][CenterCol].vPos;
|
||||
D3DXMatrixTranslation( &matTrans, vTemp.x, vTemp.y, vTemp.z );
|
||||
D3DXMatrixMultiply( &matWorld, &matTrans, &matRot );
|
||||
vPos = D3DXVECTOR3(0.0F, 0.0F, 0.0F);
|
||||
D3DXVec3TransformCoord( &vPos, &vPos, &matWorld );
|
||||
m_CollisionBox.vMax += vPos - vTemp;
|
||||
|
||||
//<2F>浹<EFBFBD><E6B5B9><EFBFBD><EFBFBD>ȸ<EFBFBD><C8B8>
|
||||
D3DXVec3TransformCoord( &m_CollisionBox.vCollisionNormal, &m_CollisionBox.vCollisionNormal, &matRot );
|
||||
D3DXVec3Normalize( &m_CollisionBox.vCollisionNormal, &m_CollisionBox.vCollisionNormal );
|
||||
m_CollisionBox.vCollisionNormal *= m_CollisionBox.fCollisionConstant;
|
||||
*/
|
||||
}
|
||||
|
||||
void CClothSimulation::SetWindFactor( const D3DXVECTOR3& vDirection, int iForce )
|
||||
{
|
||||
m_vWindDirection = vDirection;
|
||||
m_iWindForce = iForce;
|
||||
}
|
||||
|
||||
void CClothSimulation::AddCollisionPlane( const D3DXPLANE& Plane )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CClothSimulation::VirtualSimulation( DWORD dwType )
|
||||
{
|
||||
float fStep = 0.8f;
|
||||
|
||||
switch( dwType )
|
||||
{
|
||||
case NOTHING:
|
||||
m_vVirtualSimulation = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
|
||||
break;
|
||||
|
||||
case MOVE_FRONT:
|
||||
//m_vVirtualSimulation += D3DXVECTOR3( 0.0f, 0.0f, 0.1f );
|
||||
//MoveLockedParticle( D3DXVECTOR3(0.0f, sinf(float(GetTickCount()))*1.5f, 0.0f) );
|
||||
MoveLockedParticle( D3DXVECTOR3(0.0f, 0.0f, -fStep) );
|
||||
break;
|
||||
|
||||
case MOVE_BACK:
|
||||
//m_vVirtualSimulation += D3DXVECTOR3( 0.0f, 0.0f, -0.1f );
|
||||
//MoveLockedParticle( D3DXVECTOR3(0.0f, sinf(float(GetTickCount()))*1.5f, 0.0f) );
|
||||
MoveLockedParticle( D3DXVECTOR3(0.0f, 0.0f, fStep) );
|
||||
break;
|
||||
|
||||
case MOVE_RIGHT:
|
||||
//m_vVirtualSimulation += D3DXVECTOR3( 0.1f, 0.0f, 0.0f );
|
||||
//MoveLockedParticle( D3DXVECTOR3(0.0f, sinf(float(GetTickCount()))*1.5f, 0.0f) );
|
||||
MoveLockedParticle( D3DXVECTOR3(-fStep, 0.0f, 0.0f) );
|
||||
break;
|
||||
|
||||
case MOVE_LEFT:
|
||||
//m_vVirtualSimulation += D3DXVECTOR3( -0.1f, 0.0f, 0.0f );
|
||||
//MoveLockedParticle( D3DXVECTOR3(0.0f, sinf(float(GetTickCount()))*1.5f, 0.0f) );
|
||||
MoveLockedParticle( D3DXVECTOR3(fStep, 0.0f, 0.0f) );
|
||||
break;
|
||||
|
||||
case ROTATE_RIGHT:
|
||||
RotateLockedParticle( D3DXVECTOR3(0.0f, 0.05f, 0.0f), 0, 2 );
|
||||
break;
|
||||
|
||||
case ROTATE_LEFT:
|
||||
RotateLockedParticle( D3DXVECTOR3(0.0f, -0.05f, 0.0f), 0, 2 );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( m_vVirtualSimulation.x > 2.0f ) m_vVirtualSimulation.x = 2.0f;
|
||||
if( m_vVirtualSimulation.x < -2.0f ) m_vVirtualSimulation.x = -2.0f;
|
||||
if( m_vVirtualSimulation.y > 1.0f ) m_vVirtualSimulation.y = 1.0f;
|
||||
if( m_vVirtualSimulation.y < -1.0f ) m_vVirtualSimulation.y = -1.0f;
|
||||
if( m_vVirtualSimulation.z > 1.0f ) m_vVirtualSimulation.z = 1.0f;
|
||||
if( m_vVirtualSimulation.z < -0.5f ) m_vVirtualSimulation.z = -0.5f;
|
||||
}
|
||||
|
||||
int CClothSimulation::RandNum( int number )
|
||||
{
|
||||
int rnd=1;
|
||||
if( number < 0 )
|
||||
{
|
||||
rnd = -number;
|
||||
if( rnd == 0 ) rnd = 1;
|
||||
rnd = -rand()%rnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( rnd == 0 ) rnd = 1;
|
||||
rnd = rand()%rnd;
|
||||
}
|
||||
|
||||
return rnd;
|
||||
}
|
||||
|
||||
void CClothSimulation::SetPosLockParticle( int iRow, int iCol, const D3DXVECTOR3& vPos )
|
||||
{
|
||||
// if( m_Particles[iRow][iCol].bLocked )
|
||||
{
|
||||
//m_Particles[iRow][iCol].vPos = vPos;
|
||||
|
||||
if( iRow == 0 && iCol == 0 ) m_vSavePoint = vPos;
|
||||
if( iRow == 0 && iCol == 4 ) m_vSavePoint2 = vPos;
|
||||
}
|
||||
}
|
||||
|
||||
void CClothSimulation::SetWorldPos( const D3DXVECTOR3& vPos )
|
||||
{
|
||||
m_vWorldPos = vPos;
|
||||
|
||||
for( int r = 0; r <= NUMROWS; r++ )
|
||||
{
|
||||
for( int c = 0; c <= NUMCOLUMNS; c++ )
|
||||
{
|
||||
if( !m_Particles[r][c].bLocked )
|
||||
m_Particles[r][c].vPos += m_vWorldPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
160
Engine/Zalla3D Scene Class/ClothSimulation.h
Normal file
160
Engine/Zalla3D Scene Class/ClothSimulation.h
Normal file
@@ -0,0 +1,160 @@
|
||||
#pragma once
|
||||
|
||||
#include "d3dx8.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#define CLOTHWIDTH 40
|
||||
#define CLOTHHEIGHT 40
|
||||
#define NUMCOLUMNS 4
|
||||
#define NUMROWS 4
|
||||
#define NUMVERTICES ((NUMCOLUMNS+1) * (NUMROWS+1))
|
||||
#define NUMFACES ((NUMCOLUMNS*NUMROWS) * 2)
|
||||
#define CLOTHMASS 50.0f
|
||||
#define MASSPERFACE (CLOTHMASS/(float) NUMFACES)
|
||||
#define CSTEP ((float) CLOTHWIDTH / (float) NUMCOLUMNS)
|
||||
#define RSTEP ((float) CLOTHHEIGHT / (float) NUMROWS)
|
||||
#define NUMSTRUCTURALSPRINGS (NUMCOLUMNS*(NUMROWS+1) + NUMROWS*(NUMCOLUMNS+1) + NUMCOLUMNS*NUMROWS*2)
|
||||
#define GRAVITY -32.174
|
||||
#define SPRINGTENSIONCONSTANT 500.0f
|
||||
#define SPRINGSHEARCONSTANT 600.0f //600
|
||||
#define SPRINGDAMPINGCONSTANT 1 //2
|
||||
#define DRAGCOEFFICIENT 0.05f
|
||||
#define COLLISIONTOLERANCE 0.05f
|
||||
#define KRESTITUTION 0.25f
|
||||
#define FRICTIONFACTOR 0.5f
|
||||
|
||||
class CClothSimulation
|
||||
{
|
||||
public:
|
||||
enum eSIMULATIONTYPE
|
||||
{
|
||||
NOTHING,
|
||||
MOVE_FRONT,
|
||||
MOVE_BACK,
|
||||
MOVE_RIGHT,
|
||||
MOVE_LEFT,
|
||||
ROTATE_FRONT,
|
||||
ROTATE_BACK,
|
||||
ROTATE_RIGHT,
|
||||
ROTATE_LEFT,
|
||||
JUMP_UP,
|
||||
JUMP_DOWN,
|
||||
SWIMMING,
|
||||
};
|
||||
|
||||
struct ClothVertex
|
||||
{
|
||||
D3DXVECTOR3 pos;
|
||||
float u, v;
|
||||
static const DWORD FVF;
|
||||
};
|
||||
|
||||
struct Particle
|
||||
{
|
||||
float fMass;
|
||||
float fInvMass;
|
||||
D3DXVECTOR3 vPos;
|
||||
D3DXVECTOR3 vVel;
|
||||
D3DXVECTOR3 vAccel;
|
||||
D3DXVECTOR3 vForce;
|
||||
bool bLocked;
|
||||
};
|
||||
|
||||
struct ParticleRef
|
||||
{
|
||||
int r; //<2F><>
|
||||
int c; //<2F><>
|
||||
};
|
||||
|
||||
struct Spring
|
||||
{
|
||||
ParticleRef p1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31>
|
||||
ParticleRef p2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2<><32>
|
||||
float k; //ź<><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
float d; //<2F><><EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD>
|
||||
float L; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
struct Collision
|
||||
{
|
||||
ParticleRef p1;
|
||||
D3DXVECTOR3 n; //<2F>浹<EFBFBD><E6B5B9><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
struct CollisionBox
|
||||
{
|
||||
D3DXVECTOR3 vMin;
|
||||
D3DXVECTOR3 vMax;
|
||||
D3DXVECTOR3 vCenter;
|
||||
D3DXVECTOR3 vCollisionNormal;
|
||||
float fCollisionConstant;
|
||||
|
||||
void Init( const D3DXVECTOR3& vPos, const D3DXVECTOR3& vNormal, float fConstant, float fWidth, float fHeight, float fDepth )
|
||||
{
|
||||
vCenter = vPos;
|
||||
vMin = D3DXVECTOR3( vPos.x-(fWidth/2), vPos.y-(fHeight/2), vPos.z-(fDepth/2) );
|
||||
vMax = D3DXVECTOR3( vPos.x+(fWidth/2), vPos.y+(fHeight/2), vPos.z+(fDepth/2) );
|
||||
vCollisionNormal = vNormal;
|
||||
fCollisionConstant = fConstant;
|
||||
}
|
||||
};
|
||||
|
||||
typedef map<Particle*, ParticleRef> PARTICLEMAP;
|
||||
|
||||
public:
|
||||
LPDIRECT3DDEVICE8 m_pd3dDevice;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pVB;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pIB;
|
||||
LPDIRECT3DTEXTURE8 m_pTexture;
|
||||
|
||||
Particle m_Particles[NUMROWS+1][NUMCOLUMNS+1];
|
||||
Spring m_StructuralSprings[NUMSTRUCTURALSPRINGS];
|
||||
Collision m_Collisions[NUMVERTICES];
|
||||
ClothVertex m_ClothVertex[NUMVERTICES];
|
||||
WORD m_ClothIndex[NUMROWS*NUMCOLUMNS*2*3];
|
||||
PARTICLEMAP m_LockedParticleMap;
|
||||
D3DXVECTOR3 m_vWindDirection;
|
||||
int m_iWindForce;
|
||||
int m_iNumRow;
|
||||
int m_iNumCol;
|
||||
int m_iWidth;
|
||||
int m_iHeight;
|
||||
int m_iNumVertex;
|
||||
float m_fClothMass;
|
||||
CollisionBox m_CollisionBox;
|
||||
D3DXVECTOR3 m_vVirtualSimulation;
|
||||
|
||||
D3DXVECTOR3 m_vMoveParticle;
|
||||
float m_fRotateParticle;
|
||||
D3DXVECTOR3 m_vWorldPos;
|
||||
|
||||
D3DXVECTOR3 m_vSavePoint, m_vSavePoint2; //<2F>ӽ÷<D3BD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD>
|
||||
|
||||
D3DXVECTOR3 m_vMoveValue;
|
||||
|
||||
protected:
|
||||
void CheckCollision();
|
||||
void CalculateForce();
|
||||
void Integrate( float dt );
|
||||
void ResolveCollisions();
|
||||
int RandNum( int number );
|
||||
|
||||
public:
|
||||
CClothSimulation(void);
|
||||
virtual ~CClothSimulation(void);
|
||||
|
||||
void Render();
|
||||
void Create( LPDIRECT3DDEVICE8 pd3dDevice, int iNumRow, int iNumCol, int iWidth, int iHeight );
|
||||
void AddCollisionPlane( const D3DXPLANE& Plane );
|
||||
void Update( float dt = 0.032f );
|
||||
void LockParticle( int iRow, int iCol );
|
||||
void UnLockParticle( int iRow, int iCol );
|
||||
void MoveLockedParticle( const D3DXVECTOR3& vPos );
|
||||
void RotateLockedParticle( const D3DXVECTOR3& vRot, int CenterRow, int CenterCol );
|
||||
void SetWindFactor( const D3DXVECTOR3& vDirection, int iForce );
|
||||
void VirtualSimulation( DWORD dwType );
|
||||
void SetPosLockParticle( int iRow, int iCol, const D3DXVECTOR3& vPos );
|
||||
void SetWorldPos( const D3DXVECTOR3& vPos );
|
||||
};
|
||||
296
Engine/Zalla3D Scene Class/CloudScene.cpp
Normal file
296
Engine/Zalla3D Scene Class/CloudScene.cpp
Normal file
@@ -0,0 +1,296 @@
|
||||
// CloudScene.cpp: implementation of the CCloudScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "CloudScene.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CCloudScene::CCloudScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCloudScene::~CCloudScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCloudScene::Create()
|
||||
{
|
||||
|
||||
m_fTrans[0]=0.0f;
|
||||
m_fTrans[1]=0.0f;
|
||||
m_fTrans[2]=0.0f;
|
||||
m_fTrans[3]=0.0f;
|
||||
|
||||
|
||||
m_CloudOctaveBlendTexture.Create(SHADOWSIZE,SHADOWSIZE);
|
||||
float fDivAng=(3.141597f*2.0f)/CLOUDDIVIDE;
|
||||
|
||||
m_CloudVertex[0].v=vector3(0.0f,100000.0f,0.0f);
|
||||
m_CloudVertex[0].spec.c=0x0;
|
||||
m_CloudVertex[0].diff.c=0xffffffff;
|
||||
m_CloudVertex[0].tu=0.0f;
|
||||
m_CloudVertex[0].tv=0.0f;
|
||||
for(int i=1;i<CLOUDVERTEX;i++)
|
||||
{
|
||||
m_CloudVertex[i].v.x=(CLOUDSIZE)*sin(-fDivAng*(i-1));
|
||||
m_CloudVertex[i].v.z=(CLOUDSIZE)*cos(-fDivAng*(i-1));
|
||||
m_CloudVertex[i].v.y=10000.0f;
|
||||
m_CloudVertex[i].diff.c=0xffffffff;
|
||||
m_CloudVertex[i].tu=(0.7f)*sin(-fDivAng*(i-1));
|
||||
m_CloudVertex[i].tv=(0.7f)*cos(-fDivAng*(i-1));
|
||||
m_CloudVertex[i].spec.c=0x0;
|
||||
}
|
||||
/*
|
||||
for(int cCloud=0;cCloud<MAX_CLOUD;cCloud++)
|
||||
{
|
||||
m_CloudVertex[cCloud][0].v=vector3(0.0f,fCloud_Height+m_fFogLayerHeight[cCloud],0.0f);
|
||||
m_CloudVertex[cCloud][0].spec.c=0x0;
|
||||
m_CloudVertex[cCloud][0].tu=0.0f;
|
||||
m_CloudVertex[cCloud][0].tv=0.0f;
|
||||
for(i=1;i<SKYVERTEX;i++)
|
||||
{
|
||||
m_CloudVertex[cCloud][i].v.x=(SKYSIZE)*sin(-fDivAng*(i-1));
|
||||
m_CloudVertex[cCloud][i].v.z=(SKYSIZE)*cos(-fDivAng*(i-1));
|
||||
m_CloudVertex[cCloud][i].v.y=fCloud_Height+m_fFogLayerHeight[cCloud]-80000.0f;
|
||||
m_CloudVertex[cCloud][i].tu=(0.7f)*sin(-fDivAng*(i-1));
|
||||
m_CloudVertex[cCloud][i].tv=(0.7f)*cos(-fDivAng*(i-1));
|
||||
m_CloudVertex[cCloud][i].spec.c=0x0;
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
int nSize=32;
|
||||
for(int i=0;i<NUMCLOUDOCTAVE;i++)
|
||||
{
|
||||
m_CloudOctaveTexture[i].CreateEmpty(nSize,nSize,D3DFMT_A4R4G4B4);
|
||||
nSize*=2;
|
||||
}
|
||||
nSize=32;
|
||||
unsigned char ucIntensity;
|
||||
WORD wColor;
|
||||
for(int i=0;i<NUMCLOUDOCTAVE;i++)
|
||||
{
|
||||
WORD *pTexture=(WORD*)m_CloudOctaveTexture[i].Lock();
|
||||
for(int y=0;y<nSize;y++)
|
||||
{
|
||||
for(int x=0;x<nSize;x++)
|
||||
{
|
||||
ucIntensity=(1.0f+Noise3D(x,y,0))*8;
|
||||
wColor=0xf000;
|
||||
wColor|=ucIntensity<<8;
|
||||
wColor|=ucIntensity<<4;
|
||||
wColor|=ucIntensity;
|
||||
pTexture[x+y*nSize]=wColor;
|
||||
//unsigned char intensity = (char)((1.0f+Noise3D(x,y,iTime)) * 128);
|
||||
}
|
||||
}
|
||||
m_CloudOctaveTexture[i].Unlock();
|
||||
nSize*=2;
|
||||
}
|
||||
}
|
||||
|
||||
inline float CCloudScene::Noise3D(int x, int y, int z)
|
||||
{
|
||||
int n = x + y * 57 + z * 131;
|
||||
n = (n<<13) ^ n;
|
||||
return ( 1.0f - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff)
|
||||
* 0.000000000931322574615478515625f);
|
||||
}
|
||||
|
||||
void CCloudScene::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
vector3 *vecViewPos=CSceneManager::GetCamera()->GetPosition();
|
||||
|
||||
matrix mat;
|
||||
mat.Translation(vector3(vecViewPos->x,0.0f,vecViewPos->z));
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,mat);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_CURRENT);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE|D3DTA_COMPLEMENT);
|
||||
|
||||
//pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
|
||||
//pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SUBTRACT );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,D3DTOP_ADD);
|
||||
//pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,D3DTOP_SELECTARG);
|
||||
//pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SUBTRACT);
|
||||
pd3dDevice->SetVertexShader(LVERTEXFVF);
|
||||
|
||||
//pd3dDevice->SetRenderState( D3DRS_FOGENABLE,FALSE);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_SRCBLEND,D3DBLEND_ONE);
|
||||
pd3dDevice->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_SRCCOLOR);
|
||||
//
|
||||
//pd3dDevice->SetRenderState( D3DRS_SRCBLEND,D3DBLEND_SRCCOLOR);
|
||||
//pd3dDevice->SetRenderState( D3DRS_DESTBLEND,D3DBLEND_INVSRCCOLOR);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
|
||||
for(int i=0;i<CLOUDVERTEX;i++)
|
||||
{
|
||||
m_CloudVertex[i].diff.c=0xff0000ff;
|
||||
}
|
||||
pd3dDevice->SetTexture(0,m_CloudOctaveBlendTexture.GetTexture());
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,CLOUDVERTEX,m_CloudVertex,sizeof(LVertex));
|
||||
//pd3dDevice->SetRenderState( D3DRS_FOGENABLE,TRUE);
|
||||
}
|
||||
|
||||
void CCloudScene::Update(LPDIRECT3DDEVICE8 pd3dDevice,float fTime)
|
||||
{
|
||||
TLVertex pVertex[4];
|
||||
float fTextureSize=SHADOWSIZE;
|
||||
|
||||
pVertex[0].v.x=0.0f;
|
||||
pVertex[1].v.x=0.0f;
|
||||
pVertex[2].v.x=fTextureSize;
|
||||
pVertex[3].v.x=fTextureSize;
|
||||
|
||||
pVertex[1].v.y=0.0f;
|
||||
pVertex[3].v.y=0.0f;
|
||||
pVertex[0].v.y=fTextureSize;
|
||||
pVertex[2].v.y=fTextureSize;
|
||||
|
||||
|
||||
pVertex[0].tu=0.0f;
|
||||
pVertex[1].tu=0.0f;
|
||||
|
||||
pVertex[3].tu=1.0f;
|
||||
pVertex[2].tu=1.0f;
|
||||
|
||||
pVertex[1].tv=0.0f;
|
||||
pVertex[3].tv=0.0f;
|
||||
|
||||
pVertex[0].tv=1.0f;
|
||||
pVertex[2].tv=1.0f;
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
pVertex[i].w=0.1f;
|
||||
pVertex[i].v.z=0.1f;
|
||||
pVertex[i].Diffuse.c=0xffffffff;
|
||||
pVertex[i].Specular.c=0x0;
|
||||
}
|
||||
static DWORD c=0;
|
||||
c++;
|
||||
|
||||
m_CloudOctaveBlendTexture.Begin(pd3dDevice);
|
||||
pd3dDevice->Clear(0,NULL, D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET,0x000000ff, 1.0f, 0);
|
||||
pd3dDevice->BeginScene();
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_CURRENT);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
|
||||
|
||||
pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
pd3dDevice->SetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS,D3DTTFF_DISABLE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE);
|
||||
pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE);
|
||||
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
|
||||
pVertex[0].tu=0.0f+m_fTrans[0];
|
||||
pVertex[1].tu=0.0f+m_fTrans[0];
|
||||
|
||||
pVertex[3].tu=1.0f+m_fTrans[0];
|
||||
pVertex[2].tu=1.0f+m_fTrans[0];
|
||||
|
||||
pVertex[1].tv=0.0f+m_fTrans[0];
|
||||
pVertex[3].tv=0.0f+m_fTrans[0];
|
||||
|
||||
pVertex[0].tv=1.0f+m_fTrans[0];
|
||||
pVertex[2].tv=1.0f+m_fTrans[0];
|
||||
|
||||
pVertex[0].Diffuse.c=pVertex[1].Diffuse.c=pVertex[2].Diffuse.c=pVertex[3].Diffuse.c=0xffffffff;
|
||||
|
||||
pd3dDevice->SetVertexShader(TLVERTEXFVF);
|
||||
pd3dDevice->SetTexture(0,m_CloudOctaveTexture[0].GetTexture());
|
||||
pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,pVertex,sizeof(TLVertex));
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
|
||||
pVertex[0].tu=0.0f+m_fTrans[1];
|
||||
pVertex[1].tu=0.0f+m_fTrans[1];
|
||||
|
||||
pVertex[3].tu=1.0f+m_fTrans[1];
|
||||
pVertex[2].tu=1.0f+m_fTrans[1];
|
||||
|
||||
pVertex[1].tv=0.0f+m_fTrans[1];
|
||||
pVertex[3].tv=0.0f+m_fTrans[1];
|
||||
|
||||
pVertex[0].tv=1.0f+m_fTrans[1];
|
||||
pVertex[2].tv=1.0f+m_fTrans[1];
|
||||
|
||||
pVertex[0].Diffuse.c=pVertex[1].Diffuse.c=pVertex[2].Diffuse.c=pVertex[3].Diffuse.c=0xff7f7f7f;
|
||||
|
||||
pd3dDevice->SetTexture(0,m_CloudOctaveTexture[1].GetTexture());
|
||||
pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,pVertex,sizeof(TLVertex));
|
||||
|
||||
pVertex[0].tu=0.0f+m_fTrans[2];
|
||||
pVertex[1].tu=0.0f+m_fTrans[2];
|
||||
|
||||
pVertex[3].tu=1.0f+m_fTrans[2];
|
||||
pVertex[2].tu=1.0f+m_fTrans[2];
|
||||
|
||||
pVertex[1].tv=0.0f+m_fTrans[2];
|
||||
pVertex[3].tv=0.0f+m_fTrans[2];
|
||||
|
||||
pVertex[0].tv=1.0f+m_fTrans[2];
|
||||
pVertex[2].tv=1.0f+m_fTrans[2];
|
||||
|
||||
pVertex[0].Diffuse.c=pVertex[1].Diffuse.c=pVertex[2].Diffuse.c=pVertex[3].Diffuse.c=0xff3f3f3f;
|
||||
pd3dDevice->SetTexture(0,m_CloudOctaveTexture[2].GetTexture());
|
||||
pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,pVertex,sizeof(TLVertex));
|
||||
|
||||
|
||||
pVertex[0].tu=0.0f+m_fTrans[3];
|
||||
pVertex[1].tu=0.0f+m_fTrans[3];
|
||||
|
||||
pVertex[3].tu=1.0f+m_fTrans[3];
|
||||
pVertex[2].tu=1.0f+m_fTrans[3];
|
||||
|
||||
pVertex[1].tv=0.0f+m_fTrans[3];
|
||||
pVertex[3].tv=0.0f+m_fTrans[3];
|
||||
|
||||
pVertex[0].tv=1.0f+m_fTrans[3];
|
||||
pVertex[2].tv=1.0f+m_fTrans[3];
|
||||
|
||||
pVertex[0].Diffuse.c=pVertex[1].Diffuse.c=pVertex[2].Diffuse.c=pVertex[3].Diffuse.c=0xff1f1f1f;
|
||||
pd3dDevice->SetTexture(0,m_CloudOctaveTexture[3].GetTexture());
|
||||
pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,pVertex,sizeof(TLVertex));
|
||||
//
|
||||
pd3dDevice->EndScene();
|
||||
m_CloudOctaveBlendTexture.End(pd3dDevice);
|
||||
|
||||
m_fTrans[0]+=0.00001f;
|
||||
m_fTrans[1]+=0.00004f;
|
||||
m_fTrans[2]+=0.00008f;
|
||||
m_fTrans[3]+=0.00010f;
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,TRUE);
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE,TRUE);
|
||||
}
|
||||
|
||||
void CCloudScene::SetColor(DWORD dwColor, DWORD dwCenterColor, DWORD *dwLayerColor)
|
||||
{
|
||||
m_CloudVertex[0].diff.c=dwCenterColor;
|
||||
for(int i=1;i<CLOUDVERTEX;i++)
|
||||
{
|
||||
m_CloudVertex[i].diff.c=dwColor;
|
||||
}
|
||||
}
|
||||
41
Engine/Zalla3D Scene Class/CloudScene.h
Normal file
41
Engine/Zalla3D Scene Class/CloudScene.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// CloudScene.h: interface for the CCloudScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CLOUDSCENE_H__8881B271_2D89_4DE6_884E_1C2B0277D447__INCLUDED_)
|
||||
#define AFX_CLOUDSCENE_H__8881B271_2D89_4DE6_884E_1C2B0277D447__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SceneNode.h"
|
||||
#include "Texture.h"
|
||||
#include <Vertex.h>
|
||||
#include "SectorDefine.h"
|
||||
#include "StateLog.h"
|
||||
#include "RenderTexture.h"
|
||||
|
||||
const int NUMCLOUDOCTAVE=4;
|
||||
|
||||
const float CLOUDSIZE=500000.0f;
|
||||
const long CLOUDDIVIDE=10;
|
||||
const long CLOUDVERTEX=CLOUDDIVIDE+2;
|
||||
|
||||
class CCloudScene : public CSceneNode
|
||||
{
|
||||
float m_fTrans[NUMCLOUDOCTAVE];
|
||||
CTexture m_CloudOctaveTexture[NUMCLOUDOCTAVE];
|
||||
LVertex m_CloudVertex[CLOUDVERTEX];
|
||||
public:
|
||||
void SetColor(DWORD dwColor,DWORD dwCenterColor,DWORD *dwLayerColor);
|
||||
CRenderTexture m_CloudOctaveBlendTexture;
|
||||
void Update(LPDIRECT3DDEVICE8 pd3dDevice,float fTime);
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
float Noise3D(int x, int y, int z);
|
||||
void Create();
|
||||
CCloudScene();
|
||||
virtual ~CCloudScene();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_CLOUDSCENE_H__8881B271_2D89_4DE6_884E_1C2B0277D447__INCLUDED_)
|
||||
2757
Engine/Zalla3D Scene Class/CollisionDetection.cpp
Normal file
2757
Engine/Zalla3D Scene Class/CollisionDetection.cpp
Normal file
File diff suppressed because it is too large
Load Diff
108
Engine/Zalla3D Scene Class/CollisionDetection.h
Normal file
108
Engine/Zalla3D Scene Class/CollisionDetection.h
Normal file
@@ -0,0 +1,108 @@
|
||||
// CollisionDetection.h: interface for the CCollisionDetection class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_COLLISIONDETECTION_H__747BC78B_816E_4F60_A14B_A17C5A7C63B6__INCLUDED_)
|
||||
#define AFX_COLLISIONDETECTION_H__747BC78B_816E_4F60_A14B_A17C5A7C63B6__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "3DMath.h"
|
||||
#include "HeightFieldScene.h"
|
||||
|
||||
enum CollisionType
|
||||
{
|
||||
CT_BOTTOM = 0,
|
||||
CT_SIDE,
|
||||
CT_TERRAIN,
|
||||
CT_CHRSIDE,
|
||||
CT_NONE,
|
||||
CT_WATER
|
||||
};
|
||||
#define COLLEPSILON 0.000001f
|
||||
|
||||
|
||||
class CCollisionDetection
|
||||
{
|
||||
class CCollisionList
|
||||
{
|
||||
public:
|
||||
float m_fDistance;
|
||||
vector3 m_vecIntersectionPoint;
|
||||
vector3 m_vecPlaneNormal;
|
||||
vector3 m_vecPlanePoint;
|
||||
CollisionType m_CollisionType;
|
||||
};
|
||||
public:
|
||||
vector3 m_vecMinMove,m_vecMaxMove;
|
||||
|
||||
float m_fMinYBound,m_fMaxYBound;
|
||||
bool m_bFirstBottom; // First Bottom.
|
||||
bool m_bFirstScene;
|
||||
|
||||
// build <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
bool m_bBuild;
|
||||
|
||||
|
||||
|
||||
bool m_CollisionDetectionDetail;
|
||||
void CheckInHouseObject(CHouseObject *pHouse,matrix matParent);
|
||||
void CheckSectorHeightCollision(CollisionType &CT);
|
||||
void CheckBspCollision();
|
||||
bool CheckSectorWater(vector3& vecPos,bool bUpper);
|
||||
void CheckCharacterCollision(bool bChrMode);
|
||||
void CheckSectorPlantCollision();
|
||||
void CheckSectorMeshCollision();
|
||||
std::vector<CCollisionList> m_CollisionList;
|
||||
vector3 CollideWithWorld(vector3 vecPos,vector3 vecVelocity,vector3 vecBefore,int Depth,CollisionType &CT,bool ChrCollision);
|
||||
vector3 GetPosition(vector3 vecPos,vector3 vecVelocity,vector3 vecBefore,CollisionType &CT,bool ChrCollision);
|
||||
void CheckHouseCollision();
|
||||
void CheckFirstHouseCollision();
|
||||
|
||||
vector3 m_vecVelocity;
|
||||
vector3 m_vecSourcePoint; // <20>浹üũ<C3BC><C5A9> <20><><EFBFBD>ϴ<EFBFBD> <20><>ġ. GetPosition <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
vector3 m_vecRadius;
|
||||
vector3 m_vecLastSafePosition;
|
||||
bool m_bStuck;
|
||||
vector3 m_vecStuckPlaneNormal;
|
||||
float m_fStuckDistance;
|
||||
bool m_bFoundCollision;
|
||||
matrix m_matInHouse;
|
||||
bool m_bHeightGradient;
|
||||
|
||||
int m_SelfChr;
|
||||
CHeightFieldScene *m_HeightField;
|
||||
CCollisionDetection();
|
||||
void SetZoneBound(float min,float max); // Zone Bound Y value
|
||||
void ZoneBoundApply(vector3 &vecPoint,CollisionType &);
|
||||
void SetFirstBottom(bool bEnable) {m_bFirstBottom = bEnable; }
|
||||
bool GetBuildEnable() { return m_bBuild;}
|
||||
bool GetHeightGradient() { return m_bHeightGradient;}
|
||||
|
||||
virtual ~CCollisionDetection();
|
||||
|
||||
// 2005.01.11 yundi : Octree <20>ε<EFBFBD><CEB5><EFBFBD> <20>浹ó<E6B5B9><C3B3> <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD> <20>߰<EFBFBD>
|
||||
void LockDetection();
|
||||
void UnlockDetection();
|
||||
bool IsDetectionLocked();
|
||||
|
||||
// 2005.12.19 yundi : <20><><EFBFBD><EFBFBD> <20>ߺ<EFBFBD><DFBA>ڵ带 utility function <20><><EFBFBD><EFBFBD> extract method
|
||||
|
||||
/*!
|
||||
(pointX, pointY) <20><> <20><><EFBFBD><EFBFBD> (minX, minY)<29><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sizeX, sizeY <20><>
|
||||
<09><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> ũ<>⸦ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>簢<EFBFBD><E7B0A2> <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ԵǴ<D4B5><C7B4><EFBFBD> üũ.
|
||||
|
||||
<09><>, üũ<C3BC><C5A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ּҰ<D6BC> <= <20><><EFBFBD><EFBFBD> < <20>ִ밪 <20><><EFBFBD>´<EFBFBD>(<28>̻<EFBFBD>/<2F≯<EFBFBD> <20><>)
|
||||
|
||||
<09><><EFBFBD>Ե<EFBFBD> <20><><EFBFBD><EFBFBD> true, <20><EFBFBD><D7B7><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> false <20><>ȯ
|
||||
*/
|
||||
static bool IsPointInRect2D(float pointX, float pointY, float minX, float minY, float sizeX, float sizeY);
|
||||
|
||||
|
||||
protected:
|
||||
int m_nLockCount;
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_COLLISIONDETECTION_H__747BC78B_816E_4F60_A14B_A17C5A7C63B6__INCLUDED_)
|
||||
1255
Engine/Zalla3D Scene Class/ContainerASE.cpp
Normal file
1255
Engine/Zalla3D Scene Class/ContainerASE.cpp
Normal file
File diff suppressed because it is too large
Load Diff
678
Engine/Zalla3D Scene Class/ContainerASE.h
Normal file
678
Engine/Zalla3D Scene Class/ContainerASE.h
Normal file
@@ -0,0 +1,678 @@
|
||||
// ContainerASE.h: interface for the CContainerASE class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_CONTAINERASE_H__9EBF9328_1E27_11D4_891B_0000E8EB4C69__INCLUDED_)
|
||||
#define AFX_CONTAINERASE_H__9EBF9328_1E27_11D4_891B_0000E8EB4C69__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <crtdbg.h>
|
||||
#include "misc.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
// internal constants of ASE reader class
|
||||
#define ASE_MAX_LINELENGTH 255 // maximum line length in ASE file
|
||||
#define ASE_MAX_TOKENLENGTH 60 // maximum token length of the line in the ASE file
|
||||
// should modify token reading part of ReadOneLine() func. when modify the value in the next line
|
||||
#define ASE_MAX_TOKEN_IN_LINE 20 // maximum token number in a line of ASE file
|
||||
#define ASE_MAX_DEPTH 20 // maximum indentation depth
|
||||
// Obesolete due to using STL
|
||||
//#define ASE_MAX_OBJECTS 1000 // maxumum object number in ASE file
|
||||
//#define ASE_MAX_MATERIALS 100 // maxumum material number in ASE file
|
||||
#define ASE_MAX_ANI_LENGTH 10000 // maximum key number in the ASE file
|
||||
|
||||
// ASE reader error type
|
||||
typedef enum
|
||||
{
|
||||
ASE_ERR_NO_ERROR = 0,
|
||||
ASE_ERR_FILE_NOT_FOUND,
|
||||
ASE_ERR_EOF,
|
||||
ASE_ERR_NOT_ENOUGH_MEMORY
|
||||
} ASE_ERR_TYPE;
|
||||
|
||||
|
||||
// ASE token type IDs
|
||||
// Imported & modified from MAX R3 ascii exporter plug-in source
|
||||
typedef enum
|
||||
{
|
||||
//
|
||||
ASE_UNKNOWN = -1,
|
||||
|
||||
// Top level category ID's
|
||||
ASE_SCENE = 0,
|
||||
ASE_GEOMETRY,
|
||||
ASE_SHAPE,
|
||||
ASE_CAMERA,
|
||||
ASE_LIGHT,
|
||||
ASE_HELPER,
|
||||
ASE_MATERIAL_LIST,
|
||||
|
||||
// Hierarchy
|
||||
ASE_GROUP,
|
||||
ASE_NODE_TM,
|
||||
ASE_NODE_NAME,
|
||||
ASE_NODE_PARENT,
|
||||
|
||||
// Object (node) properties
|
||||
ASE_PROP_MOTIONBLUR,
|
||||
ASE_PROP_CASTSHADOW,
|
||||
ASE_PROP_RECVSHADOW,
|
||||
|
||||
// Mesh related ID's
|
||||
ASE_MESH,
|
||||
ASE_MESH_NORMALS,
|
||||
ASE_MESH_NUMVERTEX,
|
||||
ASE_MESH_NUMFACES,
|
||||
ASE_MESH_VERTEX_LIST,
|
||||
ASE_MESH_VERTEX,
|
||||
ASE_MESH_FACE_LIST,
|
||||
ASE_MESH_FACE,
|
||||
ASE_MESH_SMOOTHING,
|
||||
ASE_MESH_MTLID,
|
||||
|
||||
ASE_MESH_NUMTVERTEX,
|
||||
ASE_MESH_NUMTVFACES,
|
||||
ASE_MESH_TVERTLIST,
|
||||
ASE_MESH_TVERT,
|
||||
ASE_MESH_TFACELIST,
|
||||
ASE_MESH_TFACE,
|
||||
|
||||
ASE_MESH_NUMCVERTEX,
|
||||
ASE_MESH_NUMCVFACES,
|
||||
ASE_MESH_CVERTLIST,
|
||||
ASE_MESH_VERTCOL,
|
||||
ASE_MESH_CFACELIST,
|
||||
ASE_MESH_CFACE,
|
||||
ASE_MESH_MAPPINGCHANNEL,
|
||||
|
||||
ASE_MESH_FACEMAPLIST,
|
||||
ASE_MESH_FACEMAP,
|
||||
ASE_MESH_FACEVERT,
|
||||
|
||||
ASE_MESH_FACENORMAL,
|
||||
ASE_MESH_VERTEXNORMAL,
|
||||
ASE_MESH_ANIMATION,
|
||||
|
||||
// Helper objects
|
||||
ASE_HELPER_CLASS,
|
||||
|
||||
// Controller ID's
|
||||
ASE_CONTROL_POINT3_TCB,
|
||||
ASE_CONTROL_POINT3_BEZIER,
|
||||
ASE_CONTROL_COLOR_BEZIER,
|
||||
ASE_CONTROL_POINT3_SAMPLE,
|
||||
|
||||
ASE_CONTROL_FLOAT_TCB,
|
||||
ASE_CONTROL_FLOAT_BEZIER,
|
||||
ASE_CONTROL_FLOAT_LINEAR,
|
||||
ASE_CONTROL_FLOAT_SAMPLE,
|
||||
|
||||
// "Track" is the identification of a sampled controller
|
||||
ASE_POS_TRACK,
|
||||
ASE_ROT_TRACK,
|
||||
ASE_SCALE_TRACK,
|
||||
|
||||
// Sampled keys
|
||||
ASE_POS_SAMPLE,
|
||||
ASE_ROT_SAMPLE,
|
||||
ASE_SCALE_SAMPLE,
|
||||
|
||||
// Specific controller keys
|
||||
ASE_POS_KEY,
|
||||
ASE_ROT_KEY,
|
||||
ASE_SCALE_KEY,
|
||||
ASE_POINT3_KEY,
|
||||
ASE_FLOAT_KEY,
|
||||
|
||||
// TCB Keys have Tens, cont, bias, easeIn, easeOut
|
||||
ASE_TCB_POINT3_KEY,
|
||||
ASE_TCB_FLOAT_KEY,
|
||||
ASE_TCB_POS_KEY,
|
||||
ASE_TCB_ROT_KEY,
|
||||
ASE_TCB_SCALE_KEY,
|
||||
|
||||
// Bezier keys have inTan, outTan
|
||||
ASE_BEZIER_FLOAT_KEY,
|
||||
ASE_BEZIER_POINT3_KEY,
|
||||
ASE_BEZIER_POS_KEY,
|
||||
ASE_BEZIER_SCALE_KEY,
|
||||
|
||||
ASE_CONTROL_POS_LINEAR,
|
||||
ASE_CONTROL_POS_TCB,
|
||||
ASE_CONTROL_POS_BEZIER,
|
||||
ASE_CONTROL_ROT_LINEAR,
|
||||
ASE_CONTROL_ROT_TCB,
|
||||
ASE_CONTROL_ROT_BEZIER,
|
||||
ASE_CONTROL_SCALE_LINEAR,
|
||||
ASE_CONTROL_SCALE_TCB,
|
||||
ASE_CONTROL_SCALE_BEZIER,
|
||||
|
||||
// Material / Texture related ID's
|
||||
ASE_WIRECOLOR,
|
||||
ASE_MATERIAL,
|
||||
ASE_MATERIAL_COUNT,
|
||||
ASE_MATERIAL_REF,
|
||||
ASE_NUMSUBMTLS,
|
||||
ASE_SUBMATERIAL,
|
||||
ASE_MATNAME,
|
||||
ASE_MATCLASS,
|
||||
|
||||
ASE_AMBIENT,
|
||||
ASE_DIFFUSE,
|
||||
ASE_SPECULAR,
|
||||
ASE_SHINE,
|
||||
ASE_SHINE_STRENGTH,
|
||||
ASE_TRANSPARENCY,
|
||||
ASE_WIRESIZE,
|
||||
|
||||
ASE_SHADING,
|
||||
ASE_SELFILLUM,
|
||||
ASE_TWOSIDED,
|
||||
ASE_WIRE,
|
||||
ASE_FACEMAP,
|
||||
|
||||
ASE_TEXNAME,
|
||||
ASE_TEXCLASS,
|
||||
ASE_TEXSUBNO,
|
||||
ASE_TEXAMOUNT,
|
||||
|
||||
ASE_BITMAP,
|
||||
|
||||
ASE_MAPTYPE,
|
||||
ASE_U_OFFSET,
|
||||
ASE_V_OFFSET,
|
||||
ASE_U_TILING,
|
||||
ASE_V_TILING,
|
||||
ASE_ANGLE,
|
||||
|
||||
// Sub texture types
|
||||
ASE_MAP_DIFFUSE,
|
||||
ASE_MAP_OPACITY,
|
||||
ASE_MAP_BUMP,
|
||||
ASE_MAP_REFLECT,
|
||||
|
||||
// TM related ID's
|
||||
ASE_TM_ROW0,
|
||||
ASE_TM_ROW1,
|
||||
ASE_TM_ROW2,
|
||||
ASE_TM_ROW3,
|
||||
ASE_TM_POS,
|
||||
ASE_TM_ROTAXIS,
|
||||
ASE_TM_ROTANGLE,
|
||||
ASE_TM_SCALE,
|
||||
ASE_TM_SCALEAXIS,
|
||||
ASE_TM_SCALEAXISANG,
|
||||
ASE_TM_ANIMATION,
|
||||
|
||||
// TM Inheritance flags
|
||||
ASE_INHERIT_POS,
|
||||
ASE_INHERIT_ROT,
|
||||
ASE_INHERIT_SCL,
|
||||
|
||||
// Scene related ID's
|
||||
ASE_FILENAME,
|
||||
ASE_FIRSTFRAME,
|
||||
ASE_LASTFRAME,
|
||||
ASE_FRAMESPEED,
|
||||
ASE_TICKSPERFRAME,
|
||||
ASE_ENVMAP,
|
||||
ASE_STATICBGCOLOR,
|
||||
ASE_ANIMBGCOLOR,
|
||||
ASE_STATICAMBIENT,
|
||||
ASE_ANIMAMBIENT,
|
||||
|
||||
// Generic ID's that can show up here and there
|
||||
ASE_TIMEVALUE,
|
||||
ASE_COMMENT,
|
||||
ASE_FILEID,
|
||||
ASE_BOUNDINGBOX_MIN,
|
||||
ASE_BOUNDINGBOX_MAX,
|
||||
|
||||
// Physique related ID's
|
||||
ASE_PHYSIQUE,
|
||||
ASE_PHYSIQUE_NUMVERTEX,
|
||||
ASE_PHYSIQUE_LIST,
|
||||
ASE_PHYSIQUE_TYPE_BLENDRIGID,
|
||||
ASE_PHYSIQUE_NUMNODE,
|
||||
ASE_PHYSIQUE_NODELIST,
|
||||
ASE_PHYSIQUE_NODE,
|
||||
ASE_PHYSIQUE_TYPE_NONBLENDRIGID,
|
||||
|
||||
// User property
|
||||
ASE_SKEL_KEY_ID,
|
||||
ASE_BODY_PART_ID,
|
||||
ASE_PART_KEY_ID,
|
||||
|
||||
// Braces
|
||||
ASE_LEFTBRACE,
|
||||
ASE_RIGHTBRACE
|
||||
} ASE_TOKEN_TYPE;
|
||||
|
||||
|
||||
// animation key type
|
||||
typedef enum
|
||||
{
|
||||
ASE_KEY_UNKNOWN,
|
||||
ASE_KEY_LINEAR,
|
||||
ASE_KEY_BEZIER,
|
||||
ASE_KEY_TCB,
|
||||
ASE_KEY_SAMPLE
|
||||
} ASE_KEY_TYPE;
|
||||
|
||||
|
||||
struct ASE_MATRIX4
|
||||
{
|
||||
float _11, _12, _13, _14;
|
||||
float _21, _22, _23, _24;
|
||||
float _31, _32, _33, _34;
|
||||
float _41, _42, _43, _44;
|
||||
|
||||
ASE_MATRIX4() { ZeroMemory( this, sizeof( ASE_MATRIX4 ) ); }
|
||||
};
|
||||
|
||||
struct ASE_VECTOR3F
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
void Multiply( ASE_MATRIX4 m )
|
||||
{
|
||||
float fx = x, fy = y, fz = z;
|
||||
|
||||
x = m._11 * fx + m._21 * fy +
|
||||
m._31 * fz + m._41;
|
||||
y = m._12 * fx + m._22 * fy +
|
||||
m._32 * fz + m._42;
|
||||
z = m._13 * fx + m._23 * fy +
|
||||
m._33 * fz + m._43;
|
||||
}
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
float n = sqrtf(x*x + y*y + z*z);
|
||||
if( n > FLOAT_EPSILON )
|
||||
{
|
||||
x /= n;
|
||||
y /= n;
|
||||
z /= n;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct ASE_COLOR3F
|
||||
{
|
||||
float r, g, b;
|
||||
// inline con/destructor
|
||||
ASE_COLOR3F() { r = g = b = 1.0f; }
|
||||
~ASE_COLOR3F() {}
|
||||
};
|
||||
|
||||
struct ASE_UVCOORD
|
||||
{
|
||||
float u, v;
|
||||
};
|
||||
|
||||
struct ASE_QUAT
|
||||
{
|
||||
float x, y, z, w;
|
||||
// inline con/destructor
|
||||
ASE_QUAT() { x = y = z = 0.0f; w = 1.0f; }
|
||||
~ASE_QUAT() {}
|
||||
};
|
||||
|
||||
struct ASE_VECTORKEY
|
||||
{
|
||||
long tick;
|
||||
float x, y, z;
|
||||
};
|
||||
|
||||
struct ASE_QUATKEY
|
||||
{
|
||||
long tick;
|
||||
float x, y, z, w;
|
||||
};
|
||||
|
||||
// deleted at 00.7.26
|
||||
//struct ASE_VERTEX
|
||||
//{
|
||||
// ASE_VECTOR3F pos;
|
||||
// ASE_VECTOR3F normal; ASE<53><45> <20>߸<EFBFBD><DFB8><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28>ؽ<EFBFBD><D8BD><EFBFBD> <20><><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>) <20><><EFBFBD>̽<EFBFBD> <20><><EFBFBD><EFBFBD>ü<EFBFBD><C3BC> <20>Űܰ<C5B0>
|
||||
// ASE_COLOR3F color;
|
||||
//};
|
||||
|
||||
struct ASE_FACE
|
||||
{
|
||||
WORD awIndex[3];
|
||||
WORD awTIndex[3];
|
||||
WORD awCIndex[3];
|
||||
ASE_VECTOR3F avecIndexnormals[3];
|
||||
ASE_VECTOR3F vecFacenormal;
|
||||
WORD wSgroup_id; // smoothing group id
|
||||
WORD wMaterial_id; // actually, this is material id for 'multi-sub' materialed object
|
||||
|
||||
ASE_FACE() { wSgroup_id = -1; wMaterial_id = -1; }
|
||||
~ASE_FACE() {}
|
||||
};
|
||||
|
||||
struct ASE_PHYS_NODE
|
||||
{
|
||||
float weight;
|
||||
char name[ASE_MAX_TOKENLENGTH+1];
|
||||
};
|
||||
|
||||
struct ASE_PHYS_DATA
|
||||
{
|
||||
WORD nodecount;
|
||||
ASE_PHYS_NODE *pNode;
|
||||
|
||||
ASE_PHYS_DATA() { nodecount = 0; pNode = NULL; }
|
||||
// copy constructor
|
||||
ASE_PHYS_DATA( const ASE_PHYS_DATA &s )
|
||||
{
|
||||
nodecount = s.nodecount;
|
||||
pNode = new ASE_PHYS_NODE[nodecount];
|
||||
for( int i = 0; i < nodecount; i++ )
|
||||
pNode[i] = s.pNode[i];
|
||||
}
|
||||
~ASE_PHYS_DATA() { SAFE_DELETEA( pNode ); }
|
||||
ASE_PHYS_DATA& operator=( const ASE_PHYS_DATA &s )
|
||||
{
|
||||
nodecount = s.nodecount;
|
||||
pNode = new ASE_PHYS_NODE[nodecount];
|
||||
for( int i = 0; i < nodecount; i++ )
|
||||
pNode[i] = s.pNode[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct ASE_MTRL
|
||||
{
|
||||
long lId;
|
||||
long lParent_id;
|
||||
ASE_COLOR3F ambient;
|
||||
ASE_COLOR3F diffuse;
|
||||
ASE_COLOR3F specular;
|
||||
float fOpacity;
|
||||
float fSelfillum;
|
||||
char *szTexture;
|
||||
|
||||
ASE_MTRL() { lId = -1; lParent_id = -1; fOpacity = 1.0f; fSelfillum = 0.0f; szTexture = NULL; }
|
||||
~ASE_MTRL() { SAFE_DELETE( szTexture ); }
|
||||
};
|
||||
|
||||
struct ASE_OBJECT
|
||||
{
|
||||
// identification & hierarchy
|
||||
char szName[ASE_MAX_TOKENLENGTH+1];
|
||||
char szParentName[ASE_MAX_TOKENLENGTH+1];
|
||||
|
||||
bool bIsGeomObject;
|
||||
|
||||
// mesh things (vertex, index, texture coord, .... )
|
||||
long lVertexCount;
|
||||
ASE_VECTOR3F *pVertices;
|
||||
|
||||
long lTVertexCount;
|
||||
ASE_UVCOORD *pTVertices;
|
||||
|
||||
long lCVertexCount;
|
||||
ASE_COLOR3F *pCVertices;
|
||||
|
||||
long lFaceCount;
|
||||
ASE_FACE *pFaces;
|
||||
|
||||
// Material
|
||||
ASE_COLOR3F color;
|
||||
long lMat_id; // material reference id
|
||||
|
||||
// TM
|
||||
ASE_MATRIX4 TM;
|
||||
|
||||
ASE_VECTORKEY TM_PosKey;
|
||||
ASE_QUATKEY TM_RotKey;
|
||||
ASE_VECTORKEY TM_SclKey;
|
||||
|
||||
// Animation key
|
||||
long lPosKeyCount;
|
||||
ASE_KEY_TYPE ePosKeyType;
|
||||
ASE_VECTORKEY **ppPosKey;
|
||||
|
||||
long lRotKeyCount;
|
||||
ASE_KEY_TYPE eRotKeyType;
|
||||
ASE_QUATKEY **ppRotKey;
|
||||
|
||||
long lSclKeyCount;
|
||||
ASE_KEY_TYPE eSclKeyType;
|
||||
ASE_VECTORKEY **ppSclKey;
|
||||
|
||||
// Physique
|
||||
long lPhysDataCount; // same as vertex number when it's properly physique'd
|
||||
ASE_PHYS_DATA **ppPhysiqueData;
|
||||
|
||||
long lSkelKeyId;
|
||||
long lBodyPartId;
|
||||
long lPartKeyId;
|
||||
|
||||
ASE_OBJECT::ASE_OBJECT()
|
||||
{
|
||||
szName[0] = '\0';
|
||||
szParentName[0] = '\0';
|
||||
|
||||
bIsGeomObject = false;
|
||||
|
||||
lVertexCount = 0;
|
||||
pVertices = NULL;
|
||||
|
||||
lTVertexCount = 0;
|
||||
pTVertices = NULL;
|
||||
|
||||
lCVertexCount = 0;
|
||||
pCVertices = NULL;
|
||||
|
||||
lFaceCount = 0;
|
||||
pFaces = NULL;
|
||||
|
||||
lMat_id = -1;
|
||||
|
||||
lPosKeyCount = 0;
|
||||
ePosKeyType = ASE_KEY_UNKNOWN;
|
||||
ppPosKey = NULL;
|
||||
|
||||
lRotKeyCount = 0;
|
||||
eRotKeyType = ASE_KEY_UNKNOWN;
|
||||
ppRotKey = NULL;
|
||||
|
||||
lSclKeyCount = 0;
|
||||
eSclKeyType = ASE_KEY_UNKNOWN;
|
||||
ppSclKey = NULL;
|
||||
|
||||
lPhysDataCount = 0;
|
||||
ppPhysiqueData = NULL;
|
||||
|
||||
lSkelKeyId = -1;
|
||||
lBodyPartId = -1;
|
||||
lPartKeyId = -1;
|
||||
}
|
||||
|
||||
ASE_OBJECT::~ASE_OBJECT()
|
||||
{
|
||||
long i;
|
||||
|
||||
SAFE_DELETEA( pVertices );
|
||||
SAFE_DELETEA( pFaces );
|
||||
SAFE_DELETEA( pTVertices );
|
||||
|
||||
for( i = 0; i < lPosKeyCount; i++ )
|
||||
SAFE_DELETE( ppPosKey[i] );
|
||||
SAFE_DELETEA( ppPosKey );
|
||||
|
||||
for( i = 0; i < lRotKeyCount; i++ )
|
||||
SAFE_DELETE( ppRotKey[i] );
|
||||
SAFE_DELETEA( ppRotKey );
|
||||
|
||||
for( i = 0; i < lSclKeyCount; i++ )
|
||||
SAFE_DELETE( ppSclKey[i] );
|
||||
SAFE_DELETEA( ppSclKey );
|
||||
|
||||
for( i = 0; i < lPhysDataCount; i++ )
|
||||
SAFE_DELETE( ppPhysiqueData[i] );
|
||||
SAFE_DELETEA( ppPhysiqueData );
|
||||
}
|
||||
};
|
||||
|
||||
class CContainerASE
|
||||
{
|
||||
public:
|
||||
long GetFirstFrame() { return m_lFirstFrame; }
|
||||
long GetLastFrame() { return m_lLastFrame; }
|
||||
long GetTicksPerFrame() { return m_lTicksPerFrame; }
|
||||
long GetObjectCount() { return m_vecpObjects.size(); }
|
||||
long GetMaterialCount() { return m_vecpMaterials.size(); }
|
||||
|
||||
ASE_OBJECT* GetObject( int idx )
|
||||
{
|
||||
if( idx < (int)m_vecpObjects.size() )
|
||||
{
|
||||
return m_vecpObjects[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ASE_MTRL* GetMaterial( int idx )
|
||||
{
|
||||
if( idx < (int)m_vecpMaterials.size() )
|
||||
{
|
||||
return m_vecpMaterials[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ASE_ERR_TYPE ReadASE( const char *szFileName );
|
||||
|
||||
CContainerASE();
|
||||
virtual ~CContainerASE();
|
||||
bool Reset();
|
||||
|
||||
protected:
|
||||
char m_szFileName[ASE_MAX_LINELENGTH+1];
|
||||
|
||||
long m_lFirstFrame;
|
||||
long m_lLastFrame;
|
||||
long m_lTicksPerFrame;
|
||||
|
||||
//long m_lObjectCount;
|
||||
std::vector<ASE_OBJECT*> m_vecpObjects;
|
||||
//long m_lMaterialCount;
|
||||
std::vector<ASE_MTRL*> m_vecpMaterials;
|
||||
|
||||
long m_lSkelKeyId; // user-prop value, yundi custom
|
||||
|
||||
void ReadScene();
|
||||
void ReadTM();
|
||||
void ReadObject( bool geomflag ); // for reading Geom & helper object
|
||||
void ReadMesh();
|
||||
void ReadVertices();
|
||||
void ReadTextureVertices();
|
||||
void ReadColorVertices();
|
||||
void ReadFaces();
|
||||
void ReadTextureFaces();
|
||||
void ReadColorFaces();
|
||||
void ReadNormals();
|
||||
void ReadAni();
|
||||
void ReadPosKey();
|
||||
void ReadRotKey();
|
||||
void ReadSclKey();
|
||||
void ReadPhysique();
|
||||
void ReadPhysList();
|
||||
void ReadPhysVertex( ASE_PHYS_DATA *pData );
|
||||
void ReadPhysNode( ASE_PHYS_NODE *pNode );
|
||||
void ReadMaterial();
|
||||
void ReadMaterialItem();
|
||||
void ReadDiffuseMap();
|
||||
void ReadUserProp();
|
||||
|
||||
static char *RipOutString();
|
||||
static ASE_TOKEN_TYPE Token2Id( const char *szToken );
|
||||
static ASE_ERR_TYPE ReadOneLine();
|
||||
static char * GetLastToken();
|
||||
static void Skip();
|
||||
|
||||
static void PushDepth( long lDepth );
|
||||
static long PeekDepth();
|
||||
static long PopDepth();
|
||||
|
||||
static FILE *ms_pFile;
|
||||
|
||||
static char ms_szLineBuff[ASE_MAX_LINELENGTH+1];
|
||||
static char ms_szTmpBuff[ASE_MAX_LINELENGTH+1];
|
||||
static char ms_szTokenBuff[ASE_MAX_TOKEN_IN_LINE][ASE_MAX_TOKENLENGTH+1];
|
||||
static long ms_lTokenCount; // <20><><EFBFBD><EFBFBD> <20>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD> <20>ٿ<EFBFBD><D9BF><EFBFBD><EFBFBD><EFBFBD> <20><>ū <20><><EFBFBD><EFBFBD>
|
||||
static ASE_ERR_TYPE ms_parseState;
|
||||
|
||||
static long ms_lCurDepth;
|
||||
static long ms_alDepthStack[ASE_MAX_DEPTH];
|
||||
static long ms_lDepthStackLength;
|
||||
|
||||
static long ms_lLineCount;
|
||||
//static ASE_OBJECT *ms_apObjects[ASE_MAX_OBJECTS];
|
||||
//static ASE_MTRL *ms_apMaterials[ASE_MAX_MATERIALS];
|
||||
static void *ms_apTmpKey[ASE_MAX_ANI_LENGTH];
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline void CContainerASE::PushDepth(long lDepth)
|
||||
{
|
||||
if( ms_lDepthStackLength < ASE_MAX_DEPTH )
|
||||
{
|
||||
ms_alDepthStack[ms_lDepthStackLength] = lDepth;
|
||||
ms_lDepthStackLength++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline long CContainerASE::PeekDepth()
|
||||
{
|
||||
if( ms_lDepthStackLength > 0 )
|
||||
return ms_alDepthStack[ms_lDepthStackLength - 1];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
inline long CContainerASE::PopDepth()
|
||||
{
|
||||
if( ms_lDepthStackLength > 0 )
|
||||
{
|
||||
ms_lDepthStackLength--;
|
||||
return ( ms_alDepthStack[ms_lDepthStackLength] );
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline char * CContainerASE::GetLastToken()
|
||||
{
|
||||
return ms_szTokenBuff[ms_lTokenCount - 1];
|
||||
}
|
||||
|
||||
|
||||
#endif // !defined(AFX_CONTAINERASE_H__9EBF9328_1E27_11D4_891B_0000E8EB4C69__INCLUDED_)
|
||||
175
Engine/Zalla3D Scene Class/DataDefine.cpp
Normal file
175
Engine/Zalla3D Scene Class/DataDefine.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
#include "BaseDataDefine.h"
|
||||
#include "SectorDefine.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
long SHADOWSIZE=256;
|
||||
long MAXCHRSHADOW=4;
|
||||
long GROUNDSHADOW=1;
|
||||
long WATERREFLECTION=1;
|
||||
long LIGHTMAPRENDER=1;
|
||||
long CHRTEXTURESIZE=0;
|
||||
//Init Value File //
|
||||
char INITVALUEFILE[256]="c:\\MP-Project\\Mp.INI";
|
||||
|
||||
char MAPDATAPATH[256]="c:\\MP-Project\\MapData";
|
||||
|
||||
char ROOTPATH[256] = "c:\\MP-Project\\";
|
||||
|
||||
//Character DataSet Path//
|
||||
|
||||
char CHARACTERDATAPATH[256]="c:\\MP-Project\\Character\\Data\\";
|
||||
char CHARACTERTEXTUREDATAPATH[256]="c:\\MP-Project\\Character\\Data\\tex\\";
|
||||
char CHARACTERMESHTEX[256]="c:\\MP-Project\\Character\\Data\\meshtex.htable";
|
||||
char CHARACTERANIPACK[256]="c:\\MP-Project\\Character\\Data\\ani\\APack.ntable";
|
||||
char CHARACTERLODMESH[256]="c:\\MP-Project\\Character\\Data\\mesh\\LODMesh.ntable";
|
||||
char CHARACTERTEXPIECE[256]="c:\\MP-Project\\Character\\Data\\tex\\Texpiece.ntable";
|
||||
char CHARACTERATTACHMENTMESH[256]="c:\\MP-Project\\Character\\Data\\Amesh\\amesh.ntable";
|
||||
char CHARACTERTEXTURE[256]="c:\\MP-Project\\Character\\Data\\Texture\\texture.ntable";
|
||||
|
||||
|
||||
//Original Texutre Path//
|
||||
char ORIGINALTEXUTREINTERFACEPATH[256]="c:\\MP-Project\\RawTexture\\Interface";
|
||||
char ORIGINALTEXUTRELIGHTMAPPATH[256]="c:\\MP-Project\\RawTexture\\Lightmap";
|
||||
char ORIGINALTEXUTRENATUREPATH[256]="c:\\MP-Project\\RawTexture\\NatureObject";
|
||||
char ORIGINALTEXTUREOBJECTPATH[256]="c:\\MP-Project\\RawTexture\\Object";
|
||||
char ORIGINALTEXTURETERRAINPATH[256]="c:\\MP-Project\\RawTexture\\Terrain";
|
||||
char ORIGINALTEXTUREWIDEPATH[256]="c:\\MP-Project\\RawTexture\\WideTexture";
|
||||
char ORIGINALTEXTUREFXPATH[256]="c:\\MP-Project\\Texture\\FX";
|
||||
char ORIGINALTEXTUREEFFECT[256]="c:\\MP-Project\\Texture\\Effect";
|
||||
|
||||
//Object Path Define//
|
||||
char HOUSEOBJECTPATH[256]="c:\\MP-Project\\Objects\\House\\";
|
||||
char LIGHTOBJECTPATH[256]="c:\\MP-Project\\Objects\\Object\\";
|
||||
char TREEOBJECTPATH[256]="c:\\MP-Project\\Objects\\NatureObject\\";
|
||||
char OBJECTPATH[256]="c:\\MP-Project\\Objects\\Object\\";
|
||||
char OBJECTGEMPATH[256] = "c:\\MP-Project\\Objects\\Gem\\";
|
||||
char INSTANCEOBJECTPATH[256]="c:\\MP-Project\\Objects\\Instance\\";
|
||||
//Texture Path Define//
|
||||
char TERRAINTEXTUREPATH[256]="c:\\MP-project\\Texture\\Terrain";
|
||||
char OBJECTTEXTUREPATH[256]="c:\\MP-Project\\Texture\\Object";
|
||||
char NATURETEXTUREPATH[256]="c:\\MP-project\\Texture\\NatureObject";
|
||||
char WIDETEXTUREPATH[256]="C:\\MP-Project\\Texture\\WideTexture";
|
||||
char INTERFACETEXTUREPATH[256]="c:\\MP-Project\\Texture\\Interface";
|
||||
char NEOINTERFACETEXTUREPATH[ 256 ]="c:\\MP-Project\\Texture\\Interface\\NeoInterface";
|
||||
char FXTEXTUREPATH[256]="c:\\MP-Project\\Texture\\FX";
|
||||
char BSPTEXTUREPATH[256]="c:\\MP-Project\\Texture\\BSP";
|
||||
char BSPDATAPATH[256]="c:\\MP-Project\\MapData\\Bsp\\";
|
||||
|
||||
char EFFECTTEXTUREPATH[256]="c:\\MP-Project\\Texture\\Effect\\";
|
||||
char EFFECTSCRIPTPATH[256] = "c:\\MP-Project\\Effect\\Esf\\";
|
||||
|
||||
|
||||
char UNSHADOWWIDETEXTUREPATH[256]="c:\\MP-Project\\Texture\\UnShadowWideTexture";
|
||||
|
||||
// LightMap Path Define//
|
||||
char LIGHTMAPTEXTUREPATH[256]="c:\\MP-Project\\Texture\\Lightmap";
|
||||
//VertexShader Path Define//
|
||||
char TERRAINVERTEXSHADEROATH[256]="c:\\MP-Project\\VertexShader\\LayerFog\\LayerFogTerrain.vsh";
|
||||
char SHADERPATH[256]="c:\\MP-Project\\Shader\\";
|
||||
//Save Data Path Define//
|
||||
char WEATHERPATH[256]="c:\\MP-Project\\WeatherColorTable.dat";
|
||||
|
||||
//Octree Path Define//
|
||||
char OCTREEPATH[256]="c:\\MP-Project\\Octree";
|
||||
//Sector Scene Map Path Define//
|
||||
char SECTORMAPPATH[256]="c:\\MP-Project\\Map";
|
||||
//Font Texture Filename//
|
||||
char FONTFILE[256]="Font-H.dds";
|
||||
char EFFECTPATH[256] = "c:\\MP-Project\\Effect\\";
|
||||
|
||||
//Sound Path//
|
||||
char SOUNDFILEPATH[256]="c:\\MP-Project\\Sound\\";
|
||||
char EFFECTSOUNDSPATH[256] = "c:\\MP-Project\\Sound\\Effect\\Ssnd\\";
|
||||
char EFFECTSOUNDMPATH[256] = "c:\\MP-Project\\Sound\\Effect\\Msnd\\";
|
||||
|
||||
float DETAILGROUND=5.0f;
|
||||
|
||||
float LENS_NEAR_HOUSE=30000.0f;
|
||||
float LENS_NEAR_OBJECT=5000.0f;
|
||||
long MOVE_NOTHING=0;
|
||||
long MOVE_HOUSE=1;
|
||||
long MOVE_LIGHT=2;
|
||||
long MOVE_OBJECT=3;
|
||||
|
||||
float NEARPLANEVALUE=3.0f;
|
||||
float LIGHTMAPSIZE=32;
|
||||
float MAX_ALLOWLIGHTMAPSIZE=50000.0f;
|
||||
float PERLIGHTMAP=30.0f;
|
||||
|
||||
float DETAILTEXTUREDEPTH=75.0f;
|
||||
float FIELDHIGH=13000.0f;
|
||||
float FIELDMIDDLE=8000.0f;
|
||||
float FIELDLOW=0.0f;
|
||||
|
||||
long ROAMBUFFERSIZE=6;
|
||||
enum HEIGHTSAVEMODE { LOWERDETAIL,HIGHDETAIL };
|
||||
float FIELDDIVIDE=64.0f;
|
||||
|
||||
|
||||
//House Data define.......
|
||||
|
||||
///*
|
||||
float MAX_HOUSEVIEWRANGE=80000.0f;
|
||||
float MAX_HOUSEDISAPPER=MAX_HOUSEVIEWRANGE-4000.0f;
|
||||
float MAX_OUTVIEWRANGE=15000.0f;
|
||||
float MAX_MEDVIEWRANGE=10000.0f;
|
||||
float MAX_INVIEWRANGE=4200.0f;
|
||||
//*/
|
||||
/*
|
||||
float MAX_HOUSEVIEWRANGE=15000.0f;
|
||||
float MAX_HOUSEDISAPPER=MAX_HOUSEVIEWRANGE-4000.0f;
|
||||
float MAX_OUTVIEWRANGE=15000.0f;
|
||||
float MAX_MEDVIEWRANGE=15000.0f;
|
||||
float MAX_INVIEWRANGE=3000.0f;
|
||||
//*/
|
||||
|
||||
|
||||
float MAX_HOUSECOLLISION=30000.0f;
|
||||
|
||||
//Object Data define
|
||||
float MAX_OBJECTVIEWRANBE=10000.0f;
|
||||
float MAX_OBJECTDISAPPER=MAX_OBJECTVIEWRANBE-1000.0f;
|
||||
//Nature Data define......//
|
||||
|
||||
long MAX_SEEDRANGE=30;
|
||||
float LENS_REALPOLYTREE=5000.0f;
|
||||
|
||||
// Grass Data define........//
|
||||
float MAX_GRASS=100;
|
||||
int MAX_GRASSRANGE=19;
|
||||
|
||||
long SIZE_FOGTEXTURE=64;
|
||||
|
||||
float fFogHeight=3000.0f;
|
||||
float fFogXRange=5000.0f;
|
||||
float fFogYRange=1000.0f;
|
||||
float fFogAddHeight=100.0f;
|
||||
|
||||
|
||||
float TERRAINLOD = 10000.f;
|
||||
|
||||
float fFogMax=20000.0f;
|
||||
float fFogMin=-1000.0f;
|
||||
|
||||
float fSky_Height=120000.0f;
|
||||
float fCloud_Height=50000.0f;
|
||||
|
||||
|
||||
//Sun Scene Data define..
|
||||
float fSun_Length=200000.0f;
|
||||
float fSun_FrontEye=10000.0f;
|
||||
//Lens Flare Data Define..
|
||||
long LENSFLARE=4;
|
||||
|
||||
//Fall Scene Data Define ...
|
||||
long MAX_FALLPARTICLE=1000;
|
||||
|
||||
long GF3OPTION=0;
|
||||
long COLLISIONOBJECTVIEW=0;
|
||||
|
||||
float fCHARACTERLODLEVELDIST[3] = {1700.0f,3000.0f,4500.0f};
|
||||
|
||||
//Ambience DataPath
|
||||
char AMBIENCEPATH[256] = "c:\\MP-Project\\SOUND\\Amb\\";
|
||||
//BGM DataPath
|
||||
char BGMPATH[256] = "c:\\MP-Project\\SOUND\\Bgm\\";
|
||||
21
Engine/Zalla3D Scene Class/EffectObject.cpp
Normal file
21
Engine/Zalla3D Scene Class/EffectObject.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// EffectObject.cpp: implementation of the CEffectObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "EffectObject.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CEffectObject::CEffectObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CEffectObject::~CEffectObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
24
Engine/Zalla3D Scene Class/EffectObject.h
Normal file
24
Engine/Zalla3D Scene Class/EffectObject.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// EffectObject.h: interface for the CEffectObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_EFFECTOBJECT_H__89D6C0E9_F6E4_4183_A4B0_03903A691A77__INCLUDED_)
|
||||
#define AFX_EFFECTOBJECT_H__89D6C0E9_F6E4_4183_A4B0_03903A691A77__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <d3d8.h>
|
||||
#include "SceneNode.h"
|
||||
|
||||
class CEffectObject : public CSceneNode
|
||||
{
|
||||
public:
|
||||
virtual void Render(LPDIRECT3DDEVICE8 pd3dDevice)=0;
|
||||
virtual void Load(char *strFilename)=0;
|
||||
CEffectObject();
|
||||
virtual ~CEffectObject();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_EFFECTOBJECT_H__89D6C0E9_F6E4_4183_A4B0_03903A691A77__INCLUDED_)
|
||||
275
Engine/Zalla3D Scene Class/EffectObjectAnimation.cpp
Normal file
275
Engine/Zalla3D Scene Class/EffectObjectAnimation.cpp
Normal file
@@ -0,0 +1,275 @@
|
||||
// EffectObjectAnimation.cpp: implementation of the CEffectObjectAnimation class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
#include "SceneManager.h"
|
||||
#include "EffectObjectAnimation.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CEffectObjectAnimation::CEffectObjectAnimation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CEffectObjectAnimation::~CEffectObjectAnimation()
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < (int)m_pNodeMeshObjectList.size(); ++i)
|
||||
{
|
||||
delete m_pNodeMeshObjectList[i];
|
||||
}
|
||||
m_pNodeMeshObjectList.clear();
|
||||
|
||||
for(i = 0; i < (int)m_AnimationPackList.size(); ++i)
|
||||
{
|
||||
delete m_AnimationPackList[i];
|
||||
}
|
||||
m_AnimationPackList.clear();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CEffectObjectAnimation::Load(char *strFilename)
|
||||
{
|
||||
|
||||
//z3d::MatrixToD3DMATRIX
|
||||
/*
|
||||
FILE *fp;
|
||||
int nObject=0;
|
||||
fp=fopen(strFilename,"wb");
|
||||
DWORD dwRenderingType=0;
|
||||
fwrite(&dwRenderingType,sizeof(DWORD),1,fp);
|
||||
nObject=Index;
|
||||
|
||||
fwrite(&HaveMat,sizeof(HaveMat),1,fp);
|
||||
for(int cMtrl=0;cMtrl<HaveMat;cMtrl++)
|
||||
{
|
||||
fwrite((void*)(MatName[cMtrl]),sizeof(char)*256,1,fp);
|
||||
}
|
||||
for(int cObject=0;cObject<nObject;cObject++)
|
||||
{
|
||||
fwrite((void*)(&cSaveVertex[cObject]),sizeof(int),1,fp);
|
||||
fwrite((void*)(&cSaveFace[cObject]),sizeof(int),1,fp);
|
||||
fwrite((void*)(&cSaveKeyPosition[cObject]),sizeof(int),1,fp);
|
||||
fwrite((void*)(SaveVertex[cObject]),sizeof(Vertex)*cSaveVertex[cObject],1,fp);
|
||||
fwrite((void*)(SaveFace[cObject]),sizeof(WORD)*cSaveFace[cObject]*3,1,fp);
|
||||
fwrite((void*)(SaveKeyPosition[cObject]),sizeof(KeyPosition)*cSaveKeyPosition[cObject],1,fp);
|
||||
}
|
||||
fclose(fp);
|
||||
*/
|
||||
///*
|
||||
DWORD dwRenderingType=0;
|
||||
CFileLoad FileLoader;
|
||||
FileLoader.Load(strFilename);
|
||||
FileLoader.GetData(&dwRenderingType,sizeof(DWORD));
|
||||
|
||||
CMeshObject *pAddMesh=new CMeshObject();
|
||||
int nMat;
|
||||
char strTextureName[256];
|
||||
FileLoader.GetData(&nMat,sizeof(int));
|
||||
for(int i=0;i<nMat;i++)
|
||||
{
|
||||
FileLoader.GetData(strTextureName,sizeof(char)*MAX_NAMEBUFFER);
|
||||
pAddMesh->m_pMat.push_back(new CTexture());
|
||||
strcpy(pAddMesh->m_pMat[i]->m_strName,strTextureName);
|
||||
}
|
||||
CTexture::SetPath(OBJECTTEXTUREPATH);
|
||||
pAddMesh->TextureLoad();
|
||||
int cVertex=0,cIndices=0,nKeyPos,nKeyRot;
|
||||
LPDIRECT3DVERTEXBUFFER8 pAllocVB;
|
||||
LPDIRECT3DINDEXBUFFER8 pAllocIB;
|
||||
|
||||
MultiVertex *pVertexData;
|
||||
WORD *pIndicesData;
|
||||
|
||||
FileLoader.GetData(&cVertex,sizeof(int));
|
||||
FileLoader.GetData(&cIndices,sizeof(int));
|
||||
FileLoader.GetData(&nKeyPos,sizeof(int));
|
||||
FileLoader.GetData(&nKeyRot,sizeof(int));
|
||||
CSceneManager::GetDevice()->CreateVertexBuffer(cVertex*sizeof(MultiVertex),D3DUSAGE_WRITEONLY,
|
||||
MultiFVF,D3DPOOL_MANAGED,&pAllocVB);
|
||||
CSceneManager::GetDevice()->CreateIndexBuffer(cIndices*3*sizeof(WORD),D3DUSAGE_WRITEONLY,
|
||||
D3DFMT_INDEX16,D3DPOOL_MANAGED,&pAllocIB);
|
||||
pAllocVB->Lock(0,0,(BYTE**)&pVertexData,0);
|
||||
pAllocIB->Lock(0,cIndices*3*sizeof(WORD),(BYTE**)&pIndicesData,0);
|
||||
FileLoader.GetData(pVertexData,sizeof(MultiVertex)*cVertex);
|
||||
FileLoader.GetData(pIndicesData,sizeof(WORD)*cIndices*3);
|
||||
|
||||
pAllocVB->Unlock();
|
||||
pAllocIB->Unlock();
|
||||
|
||||
pAddMesh->m_pVertexBuffer.push_back(pAllocVB);
|
||||
pAddMesh->m_pIndicesBuffer.push_back(pAllocIB);
|
||||
|
||||
pAddMesh->m_nVertex.push_back(cVertex);
|
||||
pAddMesh->m_nIndices.push_back(cIndices);
|
||||
pAddMesh->m_pMatRef.push_back(0);
|
||||
|
||||
AnimationPackage *AniPack=new AnimationPackage;
|
||||
KeyPosition KeyPos;
|
||||
for(int cKeyPos=0;cKeyPos<nKeyPos;cKeyPos++)
|
||||
{
|
||||
FileLoader.GetData(&KeyPos,sizeof(KeyPosition));
|
||||
AniPack->m_KeyPosList.push_back(KeyPos);
|
||||
}
|
||||
KeyRotation KeyRot;
|
||||
for(int cKeyRot=0;cKeyRot<nKeyRot;cKeyRot++)
|
||||
{
|
||||
FileLoader.GetData(&KeyRot,sizeof(KeyRotation));
|
||||
AniPack->m_KeyRotList.push_back(KeyRot);
|
||||
}
|
||||
/*
|
||||
quaternion qtAccumlate,qtTemp;
|
||||
qtAccumlate.x=AniPack->m_KeyRotList[0].x;
|
||||
qtAccumlate.y=AniPack->m_KeyRotList[0].y;
|
||||
qtAccumlate.z=AniPack->m_KeyRotList[0].z;
|
||||
qtAccumlate.w=AniPack->m_KeyRotList[0].w;
|
||||
for(cKeyRot=1;cKeyRot<nKeyRot;cKeyRot++)
|
||||
{
|
||||
//qtAccumlate*=AniPack->m_KeyRotList[cKeyRot];
|
||||
qtTemp.x=AniPack->m_KeyRotList[cKeyRot].x;
|
||||
qtTemp.y=AniPack->m_KeyRotList[cKeyRot].y;
|
||||
qtTemp.z=AniPack->m_KeyRotList[cKeyRot].z;
|
||||
qtTemp.w=AniPack->m_KeyRotList[cKeyRot].w;
|
||||
qtAccumlate*=qtTemp;
|
||||
//qtAccumlate=qtTemp*qtAccumlate;
|
||||
AniPack->m_KeyRotList[cKeyRot].x=qtAccumlate.x;
|
||||
AniPack->m_KeyRotList[cKeyRot].y=qtAccumlate.y;
|
||||
AniPack->m_KeyRotList[cKeyRot].z=qtAccumlate.z;
|
||||
AniPack->m_KeyRotList[cKeyRot].w=qtAccumlate.w;
|
||||
}
|
||||
for(cKeyRot=0;cKeyRot<nKeyRot;cKeyRot++)
|
||||
AniPack->m_KeyRotList[cKeyRot].w=-AniPack->m_KeyRotList[cKeyRot].w;
|
||||
*/
|
||||
|
||||
m_AnimationPackList.push_back(AniPack);
|
||||
pAddMesh->m_dwShader=MultiFVF;
|
||||
m_pNodeMeshObjectList.push_back(pAddMesh);
|
||||
|
||||
/*
|
||||
char strTextureName[256];
|
||||
for(int i=0;i<nMat;i++)
|
||||
{
|
||||
FileLoader.GetData(strTextureName,sizeof(char)*MAX_NAMEBUFFER);
|
||||
if(strcmp(strTextureName,"")==0)
|
||||
continue;
|
||||
m_pMat.Add(new CTexture());
|
||||
strcpy(m_pMat[i]->m_strName,strTextureName);
|
||||
}
|
||||
char strObjectName[256];
|
||||
int MatRef,cVertex,cIndices;
|
||||
MultiVertex *pVertexData;
|
||||
WORD *pIndicesData;
|
||||
|
||||
for(i=0;i<nObject;i++)
|
||||
{
|
||||
FileLoader.GetData(strObjectName,sizeof(char)*256);
|
||||
FileLoader.GetData(&MatRef,sizeof(long));
|
||||
FileLoader.GetData(&cVertex,sizeof(long));
|
||||
FileLoader.GetData(&cIndices,sizeof(int));
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 pAllocVB;
|
||||
LPDIRECT3DINDEXBUFFER8 pAllocIB;
|
||||
|
||||
CSceneManager::GetDevice()->CreateVertexBuffer(cVertex*sizeof(MultiVertex),D3DUSAGE_WRITEONLY,
|
||||
MultiFVF,D3DPOOL_MANAGED,&pAllocVB);
|
||||
CSceneManager::GetDevice()->CreateIndexBuffer(cIndices*3*sizeof(WORD),D3DUSAGE_WRITEONLY,
|
||||
D3DFMT_INDEX16,D3DPOOL_MANAGED,&pAllocIB);
|
||||
|
||||
pAllocVB->Lock(0,0,(BYTE**)&pVertexData,0);
|
||||
pAllocIB->Lock(0,cIndices*3*sizeof(WORD),(BYTE**)&pIndicesData,0);
|
||||
|
||||
FileLoader.GetData(pVertexData,sizeof(MultiVertex)*cVertex);
|
||||
FileLoader.GetData(pIndicesData,sizeof(WORD)*cIndices*3);
|
||||
|
||||
pAllocVB->Unlock();
|
||||
pAllocIB->Unlock();
|
||||
|
||||
m_pVertexBuffer.Add(pAllocVB);
|
||||
m_pIndicesBuffer.Add(pAllocIB);
|
||||
|
||||
m_nVertex.Add(cVertex);
|
||||
m_nIndices.Add(cIndices);
|
||||
m_pMatRef.Add(MatRef);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void CEffectObjectAnimation::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
static int KeyFrame=0;
|
||||
KeyFrame+=30;
|
||||
if(KeyFrame>16000)
|
||||
KeyFrame=0;
|
||||
int Interval=m_AnimationPackList[0]->m_KeyPosList[1].keytime-m_AnimationPackList[0]->m_KeyPosList[0].keytime;
|
||||
float fInterTime=(float)KeyFrame/(float)Interval;
|
||||
|
||||
vector3 vecInterPos;
|
||||
vecInterPos.x=m_AnimationPackList[0]->m_KeyPosList[1].x-m_AnimationPackList[0]->m_KeyPosList[0].x;
|
||||
vecInterPos.y=m_AnimationPackList[0]->m_KeyPosList[1].y-m_AnimationPackList[0]->m_KeyPosList[0].y;
|
||||
vecInterPos.z=m_AnimationPackList[0]->m_KeyPosList[1].z-m_AnimationPackList[0]->m_KeyPosList[0].z;
|
||||
//vecInterPos/=(float)Interval;
|
||||
vector3 vecAniPos;
|
||||
vecAniPos.x=m_AnimationPackList[0]->m_KeyPosList[0].x+vecInterPos.x*fInterTime;
|
||||
vecAniPos.y=m_AnimationPackList[0]->m_KeyPosList[0].y+vecInterPos.y*fInterTime;
|
||||
vecAniPos.z=m_AnimationPackList[0]->m_KeyPosList[0].z+vecInterPos.z*fInterTime;
|
||||
|
||||
quaternion qtFirst,qtEnd,qtNow;
|
||||
qtFirst.x=m_AnimationPackList[0]->m_KeyRotList[0].x;
|
||||
qtFirst.y=m_AnimationPackList[0]->m_KeyRotList[0].y;
|
||||
qtFirst.z=m_AnimationPackList[0]->m_KeyRotList[0].z;
|
||||
qtFirst.w=m_AnimationPackList[0]->m_KeyRotList[0].w;
|
||||
qtEnd.x=m_AnimationPackList[0]->m_KeyRotList[1].x;
|
||||
qtEnd.y=m_AnimationPackList[0]->m_KeyRotList[1].y;
|
||||
qtEnd.z=m_AnimationPackList[0]->m_KeyRotList[1].z;
|
||||
qtEnd.w=m_AnimationPackList[0]->m_KeyRotList[1].w;
|
||||
z3d::QuaternionSlerp(qtNow,qtFirst,qtEnd,fInterTime);
|
||||
//D3DMath_MatrixFromQuaternion(rotmat,x,y,z,w);
|
||||
|
||||
D3DXQUATERNION qNow,qFirst,qEnd;
|
||||
qFirst.x=qtFirst.x;
|
||||
qFirst.y=qtFirst.y;
|
||||
qFirst.z=qtFirst.z;
|
||||
qFirst.w=qtFirst.w;
|
||||
|
||||
qEnd.x=qtEnd.x;
|
||||
qEnd.y=qtEnd.y;
|
||||
qEnd.z=qtEnd.z;
|
||||
qEnd.w=qtEnd.w;
|
||||
D3DXQuaternionSlerp(&qNow,&qFirst,&qEnd,fInterTime);
|
||||
|
||||
qtNow.x=qNow.x;
|
||||
qtNow.y=qNow.y;
|
||||
qtNow.z=qNow.z;
|
||||
qtNow.w=qNow.w;
|
||||
|
||||
|
||||
matrix matRot;
|
||||
//z3d::MatrixRotationQuaternion(matRot,qtNow);
|
||||
D3DXMatrixRotationQuaternion(matRot,&qNow);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
|
||||
matrix matInit;
|
||||
//matInit.MakeIdent();
|
||||
matInit.Translation(vecAniPos);
|
||||
matInit=matRot*matInit;
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,matInit);
|
||||
//pd3dDevice->SetTransform(D3DTS_WORLD,matRot);
|
||||
for(int cObject=0;cObject<(int)m_pNodeMeshObjectList.size();cObject++)
|
||||
{
|
||||
m_pNodeMeshObjectList[cObject]->Render(pd3dDevice);
|
||||
}
|
||||
}
|
||||
40
Engine/Zalla3D Scene Class/EffectObjectAnimation.h
Normal file
40
Engine/Zalla3D Scene Class/EffectObjectAnimation.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// EffectObjectAnimation.h: interface for the CEffectObjectAnimation class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_EFFECTOBJECTANIMATION_H__40A299A4_DF8B_4714_B504_74380E21D329__INCLUDED_)
|
||||
#define AFX_EFFECTOBJECTANIMATION_H__40A299A4_DF8B_4714_B504_74380E21D329__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "EffectObject.h"
|
||||
#include "MeshObject.h"
|
||||
#include <vector>
|
||||
#include "FileLoad.h"
|
||||
|
||||
class CEffectObjectAnimation : public CEffectObject
|
||||
{
|
||||
class KeyPosition{public:float x,y,z;long keytime;};
|
||||
class KeyRotation{public:float x,y,z,w;long keytime;};
|
||||
class KeyScale{public:float x,y,z;long keytime;};
|
||||
|
||||
class AnimationPackage
|
||||
{
|
||||
public:
|
||||
std::vector<KeyPosition> m_KeyPosList;
|
||||
std::vector<KeyRotation> m_KeyRotList;
|
||||
std::vector<KeyScale> m_KeySclList;
|
||||
};
|
||||
std::vector<AnimationPackage*> m_AnimationPackList;
|
||||
std::vector<CMeshObject*> m_pNodeMeshObjectList;
|
||||
public:
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void Load(char *strFilename);
|
||||
CEffectObjectAnimation();
|
||||
virtual ~CEffectObjectAnimation();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_EFFECTOBJECTANIMATION_H__40A299A4_DF8B_4714_B504_74380E21D329__INCLUDED_)
|
||||
246
Engine/Zalla3D Scene Class/FallScene.cpp
Normal file
246
Engine/Zalla3D Scene Class/FallScene.cpp
Normal file
@@ -0,0 +1,246 @@
|
||||
// FallScene.cpp: implementation of the CFallScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "FallScene.h"
|
||||
#include "SceneManager.h"
|
||||
#include <BaseGraphicsLayer.h>
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CTexture CFallScene::m_WaterFallTexture;
|
||||
|
||||
CFallScene::CFallScene()
|
||||
{
|
||||
m_MapFall=NULL;
|
||||
|
||||
}
|
||||
|
||||
CFallScene::~CFallScene()
|
||||
{
|
||||
//m_pFallVertex->Release();
|
||||
//m_pFallIndices->Release();
|
||||
}
|
||||
|
||||
void CFallScene::Create()
|
||||
{
|
||||
for(int i=0;i<30;i++)
|
||||
{
|
||||
m_FallVertex[i].diff.c=0xffffffff;
|
||||
m_FallVertex[i].spec.c=0x0;
|
||||
}
|
||||
CTexture::SetPath(NATURETEXTUREPATH);
|
||||
//m_WaterFallTexture.Load("WaterFall.dds");
|
||||
/*
|
||||
CSceneManager::GetDevice()->CreateVertexBuffer(MAX_FALLPARTICLE*4*sizeof(TLVertex),
|
||||
D3DUSAGE_WRITEONLY,TLVERTEXFVF,D3DPOOL_MANAGED,
|
||||
&m_pFallVertex);
|
||||
CSceneManager::GetDevice()->CreateIndexBuffer(MAX_FALLPARTICLE*6*sizeof(WORD),D3DUSAGE_WRITEONLY,
|
||||
D3DFMT_INDEX16,D3DPOOL_MANAGED,&m_pFallIndices);
|
||||
WORD *pIndices;
|
||||
m_pFallIndices->Lock(0,MAX_FALLPARTICLE*6*sizeof(WORD),(BYTE**)&pIndices,0);
|
||||
int i;
|
||||
for(i=0;i<MAX_FALLPARTICLE;i++)
|
||||
{
|
||||
pIndices[i*6+0]=i*4+0;
|
||||
pIndices[i*6+1]=i*4+1;
|
||||
pIndices[i*6+2]=i*4+2;
|
||||
pIndices[i*6+3]=i*4+1;
|
||||
pIndices[i*6+4]=i*4+2;
|
||||
pIndices[i*6+5]=i*4+3;
|
||||
}
|
||||
m_pFallIndices->Unlock();
|
||||
for(i=0;i<MAX_FALLPARTICLE;i++)
|
||||
{
|
||||
|
||||
m_fVelocity[i]=((rand()%100)+1)/200.0f;
|
||||
m_vecDir[i].y=-(rand()%10)-1;
|
||||
m_vecDir[i].x=0.0f;
|
||||
m_vecDir[i].z=0.0f;
|
||||
|
||||
m_vecPos[i].x=(rand()%4000);
|
||||
m_vecPos[i].z=0.0f;
|
||||
m_vecPos[i].y=20000.0f;
|
||||
m_Collition[i]=0;
|
||||
|
||||
}
|
||||
CTexture::SetPath(NATURETEXTUREPATH);
|
||||
m_FallPartTexture.Load("Flare2.dds");
|
||||
*/
|
||||
}
|
||||
|
||||
void CFallScene::Update()
|
||||
{
|
||||
/*
|
||||
for(int i=0;i<MAX_FALLPARTICLE;i++)
|
||||
{
|
||||
//m_vecPos[i]+=(m_vecDir[i]*m_fVelocity[i]);
|
||||
m_vecPos[i].y+=(m_vecDir[i].y*m_fVelocity[i]);
|
||||
m_vecPos[i].x+=(m_vecDir[i].x*100.0f);
|
||||
m_vecPos[i].z+=(m_vecDir[i].z*100.0f);
|
||||
m_fVelocity[i]*=1.1f;
|
||||
m_vecDir[i].y-=0.1f;
|
||||
|
||||
if(m_vecPos[i].y<13000.0f && m_Collition[i]==0)
|
||||
{
|
||||
//m_vecDir[i].x=-cosf(3.1415f/(4000.0f/m_vecPos[i].x));
|
||||
//m_vecDir[i].z=sinf(3.1415f/(4000.0f/m_vecPos[i].x));
|
||||
float fDivide=3.0f;
|
||||
float fAngle=( (3.1415f/fDivide)) / (4000.0f/m_vecPos[i].x);
|
||||
fAngle+=(3.1415f/fDivide);
|
||||
m_vecDir[i].x=-cosf(fAngle);
|
||||
m_vecDir[i].z=sinf(fAngle);
|
||||
|
||||
m_vecDir[i].y=6.0f;
|
||||
m_Collition[i]=1;
|
||||
m_fVelocity[i]=((rand()%100)+1)/200.0f;
|
||||
}
|
||||
|
||||
if(m_vecPos[i].y<=0.0f && m_Collition[i]==1)
|
||||
{
|
||||
m_vecPos[i].x=(rand()%4000);
|
||||
m_vecPos[i].z=rand()%10;
|
||||
m_vecPos[i].y=20000.0f;
|
||||
m_fVelocity[i]=((rand()%100)+1)/200.0f;
|
||||
m_vecDir[i].y=-(rand()%10)-1;
|
||||
m_vecDir[i].x=0.0f;
|
||||
m_vecDir[i].z=0.0f;
|
||||
m_Collition[i]=0;
|
||||
}
|
||||
}
|
||||
//*/
|
||||
}
|
||||
|
||||
void CFallScene::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
|
||||
for(int i=0;i<(int)m_MapFall->m_FallHeightList.size();i++)
|
||||
{
|
||||
m_FallVertex[i*2+0].tv-=0.1f;
|
||||
m_FallVertex[i*2+1].tv-=0.1f;
|
||||
}
|
||||
|
||||
pd3dDevice->SetTexture(0,m_WaterFallTexture.GetTexture());
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
pd3dDevice->SetVertexShader(LVERTEXFVF);
|
||||
pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2*((int)m_MapFall->m_FallHeightList.size()-1),
|
||||
m_FallVertex,sizeof(LVertex));
|
||||
|
||||
/*
|
||||
Update();
|
||||
const float fParticleSize=20.0f;
|
||||
vector3 m_vecRes;
|
||||
float w;
|
||||
TLVertex* v;
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
|
||||
pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE);
|
||||
//pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
|
||||
|
||||
m_pFallVertex->Lock(NULL,NULL,(BYTE**)&v,NULL);
|
||||
|
||||
for(int i=0;i<MAX_FALLPARTICLE;i++)
|
||||
{
|
||||
BaseGraphicsLayer::TransformVector(m_vecPos[i],m_vecRes,w);
|
||||
|
||||
|
||||
v[i*4+0].v=m_vecRes;
|
||||
|
||||
v[i*4+0].w=w;
|
||||
v[i*4+0].Diffuse.c=0x220000ff;
|
||||
v[i*4+0].Specular.c=0x0;
|
||||
|
||||
v[i*4+1].v=m_vecRes;
|
||||
v[i*4+1].w=w;
|
||||
v[i*4+1].Diffuse.c=0x220000ff;
|
||||
v[i*4+1].Specular.c=0x0;
|
||||
|
||||
v[i*4+2].v=m_vecRes;
|
||||
v[i*4+2].w=w;
|
||||
v[i*4+2].Diffuse.c=0x220000ff;
|
||||
v[i*4+2].Specular.c=0x0;
|
||||
|
||||
v[i*4+3].v=m_vecRes;
|
||||
v[i*4+3].w=w;
|
||||
v[i*4+3].Diffuse.c=0x220000ff;
|
||||
v[i*4+3].Specular.c=0x0;
|
||||
|
||||
v[i*4+0].v.x-=fParticleSize;
|
||||
v[i*4+0].v.y+=fParticleSize;
|
||||
|
||||
v[i*4+1].v.x-=fParticleSize;
|
||||
v[i*4+1].v.y-=fParticleSize;
|
||||
|
||||
v[i*4+2].v.x+=fParticleSize;
|
||||
v[i*4+2].v.y+=fParticleSize;
|
||||
|
||||
v[i*4+3].v.x+=fParticleSize;
|
||||
v[i*4+3].v.y-=fParticleSize;
|
||||
|
||||
v[i*4+0].tu=0.0f;
|
||||
v[i*4+0].tv=1.0f;
|
||||
|
||||
v[i*4+1].tu=0.0f;
|
||||
v[i*4+1].tv=0.0f;
|
||||
|
||||
v[i*4+2].tu=1.0f;
|
||||
v[i*4+2].tv=1.0f;
|
||||
|
||||
v[i*4+3].tu=1.0f;
|
||||
v[i*4+3].tv=0.0f;
|
||||
}
|
||||
m_pFallVertex->Unlock();
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
|
||||
|
||||
pd3dDevice->SetVertexShader(TLVERTEXFVF);
|
||||
pd3dDevice->SetStreamSource(0,m_pFallVertex,sizeof(TLVertex));
|
||||
pd3dDevice->SetIndices(m_pFallIndices,0);
|
||||
pd3dDevice->SetTexture(0,m_FallPartTexture.GetTexture());
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
|
||||
pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,MAX_FALLPARTICLE*4,0,MAX_FALLPARTICLE*2);
|
||||
pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
|
||||
//pd3dDevice->DrawPrimitive(D3D,0,4*MAX_FALLPARTICLE);
|
||||
*/
|
||||
}
|
||||
|
||||
void CFallScene::MakeFallScene(CSectorFallMap *MapFall)
|
||||
{
|
||||
m_MapFall=MapFall;
|
||||
|
||||
float fInterHeight;
|
||||
for(int i=0;i<(int)MapFall->m_FallHeightList.size();i++)
|
||||
{
|
||||
m_FallVertex[i*2+0].diff=MapFall->m_FallColor[i];
|
||||
m_FallVertex[i*2+1].diff=MapFall->m_FallColor[i];
|
||||
if(i!=0)
|
||||
{
|
||||
fInterHeight=abs(MapFall->m_FallHeightList[i]-MapFall->m_FallHeightList[i-1]);
|
||||
|
||||
m_FallVertex[i*2+0].tv=m_FallVertex[(i-1)*2+0].tv+fInterHeight/3000.0f;
|
||||
m_FallVertex[i*2+1].tv=m_FallVertex[(i-1)*2+1].tv+fInterHeight/3000.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_FallVertex[i*2+0].tv=0.0f;
|
||||
m_FallVertex[i*2+1].tv=0.0f;
|
||||
}
|
||||
m_FallVertex[i*2+0].v.x=MapFall->m_FallAddXList[i];
|
||||
m_FallVertex[i*2+0].v.z=MapFall->m_FallLeftList[i];
|
||||
m_FallVertex[i*2+0].v.y=MapFall->m_FallHeightList[i];
|
||||
m_FallVertex[i*2+0].tu=0.0f;
|
||||
|
||||
m_FallVertex[i*2+1].v.x=MapFall->m_FallAddXList[i];
|
||||
m_FallVertex[i*2+1].v.z=MapFall->m_FallRightList[i];
|
||||
m_FallVertex[i*2+1].v.y=MapFall->m_FallHeightList[i];
|
||||
m_FallVertex[i*2+1].tu=1.0f;
|
||||
}
|
||||
}
|
||||
40
Engine/Zalla3D Scene Class/FallScene.h
Normal file
40
Engine/Zalla3D Scene Class/FallScene.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// FallScene.h: interface for the CFallScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_FALLSCENE_H__6A50DFC3_6D31_40A1_AC38_148155D94CD9__INCLUDED_)
|
||||
#define AFX_FALLSCENE_H__6A50DFC3_6D31_40A1_AC38_148155D94CD9__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
#include "SceneNode.h"
|
||||
#include "SectorDefine.h"
|
||||
#include <Vertex.h>
|
||||
#include <Texture.h>
|
||||
#include "SectorFallMap.h"
|
||||
|
||||
class CFallScene : public CSceneNode
|
||||
{
|
||||
/*
|
||||
CTexture m_FallPartTexture;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pFallVertex;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pFallIndices;
|
||||
vector3 m_vecPos[MAX_FALLPARTICLE];
|
||||
vector3 m_vecDir[MAX_FALLPARTICLE];
|
||||
float m_fVelocity[MAX_FALLPARTICLE];
|
||||
long m_Collition[MAX_FALLPARTICLE];
|
||||
*/
|
||||
LVertex m_FallVertex[30];
|
||||
CSectorFallMap *m_MapFall;
|
||||
static CTexture m_WaterFallTexture;
|
||||
public:
|
||||
void MakeFallScene(CSectorFallMap *MapFall);
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void Update();
|
||||
void Create();
|
||||
CFallScene();
|
||||
virtual ~CFallScene();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_FALLSCENE_H__6A50DFC3_6D31_40A1_AC38_148155D94CD9__INCLUDED_)
|
||||
168
Engine/Zalla3D Scene Class/FogManager.cpp
Normal file
168
Engine/Zalla3D Scene Class/FogManager.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
|
||||
#include "FogManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
/*************************************************************************************************************
|
||||
|
||||
CFogManager class
|
||||
|
||||
***************************************************************************************************************/
|
||||
|
||||
|
||||
CFogManager :: CFogManager() {
|
||||
int m_FogNum = 0;
|
||||
}
|
||||
CFogManager ::~CFogManager() {
|
||||
|
||||
for(int i = 0;i<m_FogNum;i++)
|
||||
delete m_FogUnit[i];
|
||||
|
||||
m_FogUnit.clear();
|
||||
}
|
||||
|
||||
// return value : update <20><> particle <20><>ü <20><><EFBFBD><EFBFBD>
|
||||
// arg 1 ,2 : <20>˻<EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ǥ
|
||||
int CFogManager::UpdateFog(int secx,int secy) {
|
||||
|
||||
int i; /* close person <20>Լ<EFBFBD> <20>߰<EFBFBD>*/
|
||||
int count = 0; /* SECTORSIZE <20><> <20><><EFBFBD>ϵǾ<CFB5><C7BE>ִ<EFBFBD> SectorDefine.h include */
|
||||
//Z3D Sceneclass <20>ȿ<EFBFBD> <20>ִ<EFBFBD>.
|
||||
vector3 center;
|
||||
vector3 pos;
|
||||
// int indexx,indexy;
|
||||
|
||||
for(i=0;i<m_FogNum;i++) {
|
||||
center = m_FogUnit[i]->GetCenter();
|
||||
//indexx = (int)(center.x/SECTORSIZE);
|
||||
//indexy = (int)(center.z/SECTORSIZE);
|
||||
// Sector <20><><EFBFBD><EFBFBD> <20><EFBFBD> rendering
|
||||
// if(secx == indexx && secy == indexy) {
|
||||
//get person pos;
|
||||
m_FogUnit[i]->Update(pos.x,pos.y,pos.z);
|
||||
count++;
|
||||
// }
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int CFogManager::UpdateFog(int num) {
|
||||
D3DXVECTOR3 pos;
|
||||
//get person pos
|
||||
m_FogUnit[num]->Update(pos.x,pos.y,pos.z);
|
||||
return num;
|
||||
}
|
||||
|
||||
int CFogManager::Render(int num) {
|
||||
m_FogUnit[num]->Render();
|
||||
return num;
|
||||
}
|
||||
int CFogManager::Render() {
|
||||
|
||||
int i;
|
||||
int count = 0;
|
||||
vector3 center;
|
||||
// secter index
|
||||
// int indexx,indexy;
|
||||
|
||||
for(i=0;i<m_FogNum;i++) {
|
||||
center = m_FogUnit[i]->GetCenter();
|
||||
//indexx = (int)(center.x/SECTORSIZE);
|
||||
//indexy = (int)(center.z/SECTORSIZE);
|
||||
//if(secx == indexx && secy == indexy) {
|
||||
m_FogUnit[i]->Render();
|
||||
count++;
|
||||
//}
|
||||
}
|
||||
return count;
|
||||
|
||||
}
|
||||
int CFogManager::SetFog(int num) {
|
||||
|
||||
/* m_FogUnit[num]->SetCenter(30.0f);
|
||||
m_FogUnit[num]->SetCenterPos(0.0f,0.0f,10.0f);
|
||||
m_FogUnit[num]->SetColor(1.0f,1.0f,1.0f,1.0f);
|
||||
m_FogUnit[num]->SetFlow(-2.0f);
|
||||
m_FogUnit[num]->SetGravity(0.0f,0.0f,0.0f);
|
||||
D3DXVECTOR3 tm;
|
||||
tm.z = 0.3f;
|
||||
tm.x = 0.6f;
|
||||
tm.y = 0.1f;
|
||||
// tm.x = tm.y = tm.z = 0.0f;
|
||||
// tm.x = 0.3f;
|
||||
// tm.y = 0.1f;
|
||||
m_FogUnit[num]->SetSize(5.0f);
|
||||
m_FogUnit[num]->SetImpress(tm);
|
||||
m_FogUnit[num]->SetPos();
|
||||
m_FogUnit[num]->SetColor(1.0f,1.0f,1.0f,1.0f);
|
||||
m_FogUnit[num]->SetEtc();
|
||||
m_FogUnit[num]->SetRad(5.0f);
|
||||
m_FogUnit[num]->SetSpeed(0.0f,0.0f,0.0f);
|
||||
m_FogUnit[num]->SetSpeedPower(0.0f);
|
||||
m_FogUnit[num]->SetWind(0.0f,0.0f,0.0f);
|
||||
m_FogUnit[num]->CreateTextureBuffer(2);
|
||||
|
||||
m_FogUnit[num]->SetTexture(0,"white.dds");
|
||||
m_FogUnit[num]->SetTexture(1,"white32.dds");
|
||||
m_FogUnit[num]->Setfadein(1.0f);
|
||||
m_FogUnit[num]->CreateVertexBuffer();*/
|
||||
//m_FogUnit[num]->Create();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
void CFogManager::Insert_Fog() {
|
||||
CFogScene *tmp;
|
||||
|
||||
m_FogUnit.push_back(tmp);
|
||||
m_FogUnit[m_FogNum] = new CFogScene();
|
||||
|
||||
/// m_FogUnit[m_FogNum]->Create();
|
||||
|
||||
m_FogNum++;
|
||||
}
|
||||
int CFogManager::FindFog(float x,float y,float z) {
|
||||
vector3 center;
|
||||
for(int i=0;i<m_FogNum;i++) {
|
||||
center = m_FogUnit[i]->GetCenter();
|
||||
if(center.x == x && center.y == y && center.z == z)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ӿ<EFBFBD> <20>߰<EFBFBD> <20>Ǹ鼭 <20><><EFBFBD>Ƴ<EFBFBD> <20>ڵ<EFBFBD>
|
||||
/*void CFogManager::CalculateLod() {
|
||||
int i;
|
||||
vector3 f_pos;
|
||||
|
||||
// cameram get
|
||||
matrix *matViewPosition=(matrix*)CSceneManager::GetCamera()->GetMatPosition();
|
||||
vector3 vecViewPos=matViewPosition->GetLoc();
|
||||
|
||||
vecViewPos.x-=m_AccumulateTM._41;
|
||||
vecViewPos.z-=m_AccumulateTM._43;
|
||||
|
||||
float fLens=0.0f;
|
||||
|
||||
if( 0.0f-fLens_FarTree <= vecViewPos.x &&
|
||||
SECTORSIZE+fLens_FarTree > vecViewPos.x &&
|
||||
0.0f-fLens_FarTree <= vecViewPos.z &&
|
||||
SECTORSIZE+fLens_FarTree > vecViewPos.z) {
|
||||
for(i=0;i<Fog_Num;i++) {
|
||||
|
||||
f_pos.x = Fog_Unit[i]->Center_Point.x - vecViewPos.x;
|
||||
f_pos.y = Fog_Unit[i]->Center_Point.y - vecViewPos.y;
|
||||
f_pos.z = Fog_Unit[i]->Center_Point.z - vecViewPos.z;
|
||||
fLens=CFastMath::FastSqrt((f_pos.x*f_pos.x)+(f_pos.y*f_pos.y)+(f_pos.z*f_pos.z));
|
||||
|
||||
if(fLens <=LOD_NEAR)
|
||||
Fog_Unit[i]->Lod = NEAR_LOD;
|
||||
else if(fLens <=LOD_FAR)
|
||||
Fog_Unit[i]->Lod = FAR_LOD;
|
||||
else
|
||||
Fog_Unit[i]->Lod = NOT_SCENE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
31
Engine/Zalla3D Scene Class/FogManager.h
Normal file
31
Engine/Zalla3D Scene Class/FogManager.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef __CFOGMANAGER_H__
|
||||
#define __CFOGMANAGER_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FogScene.h"
|
||||
|
||||
class CFogManager {
|
||||
public:
|
||||
CFogManager();
|
||||
~CFogManager();
|
||||
int SetFog(int num);
|
||||
|
||||
int UpdateFog(int secx,int secy);
|
||||
int UpdateFog(int num);
|
||||
int FindFog(float ,float ,float );
|
||||
|
||||
int Render();
|
||||
int Render(int num);
|
||||
void Insert_Fog();
|
||||
void CalculateLod();
|
||||
|
||||
|
||||
vector<CFogScene *> m_FogUnit;
|
||||
int m_FogNum;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
819
Engine/Zalla3D Scene Class/FogScene.cpp
Normal file
819
Engine/Zalla3D Scene Class/FogScene.cpp
Normal file
@@ -0,0 +1,819 @@
|
||||
#include "FogScene.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
|
||||
CFogScene ::CFogScene() {
|
||||
m_bPick = false;
|
||||
|
||||
srand(time(0));
|
||||
m_ParticleNum = INIT_NUM;
|
||||
m_ClosePointNum = 0;
|
||||
|
||||
|
||||
|
||||
m_FogBuffer = NULL;
|
||||
m_FogPointSpriteBuffer = NULL;
|
||||
m_BaseTexture = NULL;
|
||||
m_LodNum = 0;
|
||||
//Lod_Level = NEAR;
|
||||
m_SpeedPower = 0.0f;
|
||||
m_CenterPoint.x = m_CenterPoint.y = m_CenterPoint.z = 0.0f;
|
||||
m_Impress.x = m_Impress.y = m_Impress.z = 0.0f;
|
||||
m_Center = 0.0f;
|
||||
|
||||
m_Size = 1.0f;
|
||||
|
||||
m_SrcBlendMode = D3DBLEND_SRCALPHA;
|
||||
|
||||
m_DstBlendMode = D3DBLEND_INVSRCALPHA;
|
||||
|
||||
m_TextureNum = 0;
|
||||
m_Rad = 5.0f;
|
||||
|
||||
m_FadeIn = 1.0f;
|
||||
m_FadeOut = 0.0f;
|
||||
m_Lod = NEAR_LOD;
|
||||
|
||||
m_Device = CSceneManager::GetDevice();
|
||||
m_FadeInSpeed = 1.0f;
|
||||
m_pPoint = NULL;
|
||||
m_BackFadeIn = 1.0f;
|
||||
|
||||
}
|
||||
CFogScene ::CFogScene(int num) {
|
||||
m_BackFadeIn = 1.0f;
|
||||
m_pPoint = NULL;
|
||||
m_bPick = false;
|
||||
m_ParticleNum = num;
|
||||
m_ClosePointNum = 0;
|
||||
m_FogBuffer = NULL;
|
||||
m_FogPointSpriteBuffer = NULL;
|
||||
m_BaseTexture = NULL;
|
||||
m_LodNum = 0;
|
||||
|
||||
//Lod_Level = NEAR;
|
||||
m_SpeedPower = 0.0f;
|
||||
m_Rad = 5.0f;
|
||||
m_CenterPoint.x = m_CenterPoint.y = m_CenterPoint.z = 0.0f;
|
||||
m_Impress.x = m_Impress.y = m_Impress.z = 0.0f;
|
||||
m_Center = 0.0f;
|
||||
|
||||
m_Size = 1.0f;
|
||||
|
||||
m_SrcBlendMode = D3DBLEND_SRCALPHA;
|
||||
|
||||
m_DstBlendMode = D3DBLEND_INVSRCALPHA;
|
||||
|
||||
m_Lod = NEAR_LOD;
|
||||
m_TextureNum = 0;
|
||||
|
||||
m_FadeIn = 1.0f;
|
||||
m_FadeOut = 0.0f;
|
||||
|
||||
m_Device = CSceneManager::GetDevice();
|
||||
}
|
||||
void CFogScene::Create(vector3 cen) {
|
||||
m_Node = new ParticleNode[m_ParticleNum];
|
||||
|
||||
CTexture::SetPath(NATURETEXTUREPATH);
|
||||
m_BaseTexture=new CTexture;
|
||||
//texture image load
|
||||
m_BaseTexture->Load(FOGTEX);
|
||||
m_TextureNum++;
|
||||
//set fog parameter
|
||||
SetCenter(40000.0f);
|
||||
SetCenterPos(cen);
|
||||
|
||||
SetFlow(cen.y - 200.0f);
|
||||
SetGravity(0.0f,0.0f,0.0f);
|
||||
vector3 tm;
|
||||
tm.z = 0.3f;
|
||||
tm.x = 0.6f;
|
||||
tm.y = 0.1f;
|
||||
// tm.x = tm.y = tm.z = 0.0f;
|
||||
// tm.x = 0.3f;
|
||||
// tm.y = 0.1f;
|
||||
SetSize(5000.0f);
|
||||
SetImpress(tm);
|
||||
SetPos();
|
||||
SetColor(0.8f,0.8f,0.8f,0.5f);
|
||||
// SetVertexColor(0.3f,0.3f,0.3f,0.5f,2);
|
||||
// SetVertexColor(0.3f,0.3f,0.3f,0.5f,3);
|
||||
|
||||
SetEtc();
|
||||
SetRad(3000.0f);
|
||||
SetSpeed(0.0f,0.0f,0.0f);
|
||||
SetSpeedPower(0.0f);
|
||||
SetWind(0.0f,0.0f,0.0f);
|
||||
Setfadein(1.0f);
|
||||
SetFadeInSpeed(0.3f);
|
||||
SetFadeOutSpeed(3.0f);
|
||||
CreateVertexBuffer();
|
||||
|
||||
}
|
||||
/*<2A><> vertex <20><> <20><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
0------1
|
||||
| |
|
||||
| |
|
||||
3------2
|
||||
*/
|
||||
void CFogScene::SetVertexColor(float r,float g,float b,float a,int dimension) {
|
||||
int i;
|
||||
|
||||
for(i=0;i<m_ParticleNum;i++){
|
||||
m_Node[i].r[dimension] = r;
|
||||
m_Node[i].g[dimension] = g;
|
||||
m_Node[i].b[dimension] = b;
|
||||
m_Node[i].Life = a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CFogScene::~CFogScene() {
|
||||
|
||||
if(m_FogBuffer != NULL)
|
||||
m_FogBuffer->Release();
|
||||
|
||||
if(m_FogPointSpriteBuffer != NULL)
|
||||
m_FogPointSpriteBuffer->Release();
|
||||
|
||||
if(m_Node != NULL) {
|
||||
delete[] m_Node;
|
||||
m_Node = NULL;
|
||||
}
|
||||
/* if(m_pVertex != NULL) {
|
||||
delete[] m_pVertex;
|
||||
m_pVertex = NULL;
|
||||
}
|
||||
if(m_pPoint != NULL) {
|
||||
delete[] m_pPoint;
|
||||
m_pPoint = NULL;
|
||||
}*/
|
||||
if(m_BaseTexture != NULL) {
|
||||
delete m_BaseTexture;
|
||||
m_BaseTexture = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CFogScene::SetWind(float x,float y,float z) {
|
||||
m_Wind[0] = x;
|
||||
m_Wind[1] = y;
|
||||
m_Wind[2] = z;
|
||||
}
|
||||
void CFogScene::SetFlow(float flow_height,int index) {
|
||||
m_Node[index].Flow = flow_height;
|
||||
}
|
||||
void CFogScene::SetFlow(float flow_height) {
|
||||
int i;
|
||||
for(i=0;i<m_ParticleNum;i++)
|
||||
m_Node[i].Flow = flow_height;
|
||||
}
|
||||
void CFogScene::SetHeight(float height,int index) {
|
||||
m_Node[index].Y = height;
|
||||
}
|
||||
void CFogScene::SetHeight(float height) {
|
||||
int i;
|
||||
for(i=0;i<m_ParticleNum;i++)
|
||||
m_Node[i].Y = height;
|
||||
|
||||
}
|
||||
void CFogScene::SetColor(float r,float g,float b,float a) {
|
||||
int i;
|
||||
for(i=0;i<m_ParticleNum;i++){
|
||||
m_Node[i].r[0] = m_Node[i].r[1] = m_Node[i].r[2] = m_Node[i].r[3] = r;
|
||||
m_Node[i].g[0] = m_Node[i].g[1] = m_Node[i].g[2] = m_Node[i].g[3] = g;
|
||||
m_Node[i].b[0] = m_Node[i].b[1] = m_Node[i].b[2] = m_Node[i].b[3] = b;
|
||||
m_Node[i].Life = a;
|
||||
}
|
||||
|
||||
}
|
||||
void CFogScene::SetColor(float r,float g,float b,float a,int p_index) {
|
||||
m_Node[p_index].r[0] = m_Node[p_index].r[1] = m_Node[p_index].r[2] = m_Node[p_index].r[3] = r;
|
||||
m_Node[p_index].g[0] = m_Node[p_index].g[1] = m_Node[p_index].g[2] = m_Node[p_index].g[3] = g;
|
||||
m_Node[p_index].b[0] = m_Node[p_index].b[1] = m_Node[p_index].b[2] = m_Node[p_index].b[3] = b;
|
||||
m_Node[p_index].Life = a;
|
||||
}
|
||||
|
||||
// <20>߷<EFBFBD>
|
||||
void CFogScene ::SetGravity(float x,float y,float z) {
|
||||
|
||||
m_Gravity[0] = x;
|
||||
m_Gravity[1] = y;
|
||||
m_Gravity[2] = z;
|
||||
|
||||
|
||||
}
|
||||
void CFogScene::SetSpeedPower(float power) {
|
||||
m_SpeedPower = power;
|
||||
}
|
||||
|
||||
void CFogScene::SetImpress(vector3 imp) {
|
||||
m_Impress = imp;
|
||||
}
|
||||
void CFogScene::SetImpress(float x,float y,float z) {
|
||||
m_Impress.x = x;
|
||||
m_Impress.y = y;
|
||||
m_Impress.z = z;
|
||||
}
|
||||
|
||||
void CFogScene::SetCenterPos(vector3 center) {
|
||||
m_CenterPoint = center;
|
||||
}
|
||||
void CFogScene ::SetPos() {
|
||||
int i;
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
m_Node[i].X = m_CenterPoint.x + (((float)(rand()%1000) - 500.0f)/1000.0f * (m_Center * (m_Impress.x + 0.1f)));
|
||||
m_Node[i].Y = m_CenterPoint.y + (((float)(rand()%1000) - 500.0f)/1000.0f * (m_Center * (m_Impress.y + 0.1f)));+350.0f;
|
||||
m_Node[i].Z = m_CenterPoint.z + (((float)(rand()%1000) - 500.0f)/1000.0f * (m_Center * (m_Impress.z + 0.1f)));
|
||||
|
||||
m_Node[i].BackX = m_Node[i].X;
|
||||
m_Node[i].BackY = m_Node[i].Y;
|
||||
m_Node[i].BackZ = m_Node[i].Z;
|
||||
}
|
||||
}
|
||||
void CFogScene ::SetPos(int node_num) {
|
||||
m_Node[node_num].X = m_CenterPoint.x + (((float)(rand()%1000) - 500.0f)/1000.0f * (m_Center * m_Impress.x));
|
||||
m_Node[node_num].Y = m_CenterPoint.y + (((float)(rand()%1000) - 500.0f)/1000.0f * (m_Center * m_Impress.y));
|
||||
m_Node[node_num].Z = m_CenterPoint.z + (((float)(rand()%1000) - 500.0f)/1000.0f * (m_Center * m_Impress.z));
|
||||
|
||||
m_Node[node_num].BackX = m_Node[node_num].X;
|
||||
m_Node[node_num].BackY = m_Node[node_num].Y;
|
||||
m_Node[node_num].BackZ = m_Node[node_num].Z;
|
||||
|
||||
}
|
||||
void CFogScene ::SetPos(int node_num,float x,float y,float z) {
|
||||
m_Node[node_num].X = x;
|
||||
m_Node[node_num].Y = y;
|
||||
m_Node[node_num].Z = z;
|
||||
|
||||
m_Node[node_num].BackX = m_Node[node_num].X;
|
||||
m_Node[node_num].BackY = m_Node[node_num].Y;
|
||||
m_Node[node_num].BackZ = m_Node[node_num].Z;
|
||||
|
||||
}
|
||||
void CFogScene ::SetCenterPos(float x,float y,float z) {
|
||||
m_CenterPoint.x = x;
|
||||
m_CenterPoint.y = y;
|
||||
m_CenterPoint.z = z;
|
||||
|
||||
}
|
||||
|
||||
void CFogScene::SetSpeed(float x,float y,float z) {
|
||||
int i;
|
||||
m_Speed[0] = x;
|
||||
m_Speed[1] = y;
|
||||
m_Speed[2] = z;
|
||||
|
||||
for(i=0;i<m_ParticleNum;i++){
|
||||
m_Node[i].Xi = x;
|
||||
m_Node[i].Yi = y;
|
||||
m_Node[i].Zi = z;
|
||||
}
|
||||
}
|
||||
|
||||
void CFogScene::SetSpeed(float x,float y,float z,int index) {
|
||||
m_Node[index].Xi = x;
|
||||
m_Node[index].Yi = y;
|
||||
m_Node[index].Zi = z;
|
||||
}
|
||||
void CFogScene::SetSpeed() {
|
||||
int i;
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
if(m_SpeedPower != 0.0f) {
|
||||
m_Node[i].Xi =((float)(rand() %(int)m_SpeedPower) -m_SpeedPower/2.0f) *0.001f;
|
||||
m_Node[i].Yi =((float)(rand() %(int)m_SpeedPower) -m_SpeedPower/2.0f) *0.001f;
|
||||
m_Node[i].Zi =((float)(rand() %(int)m_SpeedPower) -m_SpeedPower/2.0f) *0.001f;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Particle Center <20><><EFBFBD><EFBFBD> <20><><EFBFBD>ߵ<EFBFBD>
|
||||
void CFogScene ::SetCenter(float Cvalue) {
|
||||
m_Center = Cvalue;
|
||||
}
|
||||
|
||||
void CFogScene::CreateVertexBuffer() {
|
||||
|
||||
// int i;
|
||||
// int count = 0;
|
||||
|
||||
|
||||
m_Device->CreateVertexBuffer( m_ParticleNum * sizeof(POINTVERTEX),D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY | D3DUSAGE_POINTS,
|
||||
D3DFVF_POINTVERTEX, D3DPOOL_DEFAULT, &m_FogPointSpriteBuffer);
|
||||
|
||||
m_Device->CreateVertexBuffer(m_ParticleNum*sizeof(ParticleVertex) * 6,0,
|
||||
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1,D3DPOOL_MANAGED,&m_FogBuffer);
|
||||
|
||||
/*
|
||||
vector3 right;
|
||||
vector3 up;
|
||||
D3DXMATRIX m_World;
|
||||
|
||||
m_pVertex = new ParticleVertex[m_ParticleNum * 6];
|
||||
|
||||
m_Device->GetTransform(D3DTS_VIEW,&m_World);
|
||||
|
||||
right.x = m_World._11;
|
||||
right.y = m_World._21;
|
||||
right.z = m_World._31;
|
||||
|
||||
up.x = m_World._12;
|
||||
up.y = m_World._22;
|
||||
up.z = m_World._32;
|
||||
|
||||
if(m_Lod == NEAR_LOD) {
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
//0
|
||||
m_pVertex[count].x = m_Node[i].X + (-right.x + up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (-right.y + up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (-right.z + up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 0.0f;
|
||||
m_pVertex[count].ty = 0.0f;
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[0],m_Node[i].g[0],m_Node[i].b[0],m_Node[i].Life);
|
||||
//1
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x + up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y + up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z + up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 1.0f;
|
||||
m_pVertex[count].ty = 0.0f;
|
||||
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[1],m_Node[i].g[1],m_Node[i].b[1],m_Node[i].Life);
|
||||
|
||||
//2
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x - up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y - up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z - up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 1.0f;
|
||||
m_pVertex[count].ty = 1.0f;
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[2],m_Node[i].g[2],m_Node[i].b[2],m_Node[i].Life);
|
||||
|
||||
//0
|
||||
m_pVertex[count].x = m_Node[i].X + (-right.x + up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (-right.y + up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (-right.z + up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 0.0f;
|
||||
m_pVertex[count].ty = 0.0f;
|
||||
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[0],m_Node[i].g[0],m_Node[i].b[0],m_Node[i].Life);
|
||||
|
||||
//2
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x - up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y - up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z - up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 1.0f;
|
||||
m_pVertex[count].ty = 1.0f;
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[2],m_Node[i].g[2],m_Node[i].b[2],m_Node[i].Life);
|
||||
|
||||
//3
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x + up.x)*(-m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y + up.y)*(-m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z + up.z)*(-m_Size);
|
||||
m_pVertex[count].tx = 0.0f;
|
||||
m_pVertex[count].ty = 1.0f;
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[3],m_Node[i].g[3],m_Node[i].b[3],m_Node[i].Life);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
m_Device->CreateVertexBuffer(m_ParticleNum*sizeof(ParticleVertex) * 6,0,
|
||||
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1,D3DPOOL_MANAGED,&m_FogBuffer);
|
||||
|
||||
VOID *tmp;
|
||||
m_FogBuffer->Lock(0,m_ParticleNum*sizeof(ParticleVertex) * 6,
|
||||
(BYTE **)&tmp,0);
|
||||
memcpy(tmp,m_pVertex,m_ParticleNum*sizeof(ParticleVertex) * 6);
|
||||
|
||||
m_FogBuffer->Unlock();
|
||||
|
||||
delete[] m_pVertex;
|
||||
m_pVertex = NULL;
|
||||
|
||||
*/
|
||||
}
|
||||
void CFogScene::ChangeVertexBuffer() {
|
||||
int i;
|
||||
int count = 0;
|
||||
int count2 = 0;
|
||||
|
||||
vector3 right;
|
||||
vector3 up;
|
||||
D3DXMATRIX m_World;
|
||||
|
||||
if(m_ClosePointNum >0)
|
||||
m_pVertex = new ParticleVertex[m_ClosePointNum * 6];
|
||||
m_pPoint = new POINTVERTEX[m_ParticleNum - m_ClosePointNum];
|
||||
|
||||
|
||||
m_Device->GetTransform(D3DTS_VIEW,&m_World);
|
||||
|
||||
right.x = m_World._11;
|
||||
right.y = m_World._21;
|
||||
right.z = m_World._31;
|
||||
|
||||
up.x = m_World._12;
|
||||
up.y = m_World._22;
|
||||
up.z = m_World._32;
|
||||
|
||||
// Lod near
|
||||
if(m_Lod == NEAR_LOD) {
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
//0
|
||||
if(m_Node[i].m_bClose) {
|
||||
m_pVertex[count].x = m_Node[i].X + (-right.x + up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (-right.y + up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (-right.z + up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 0.0f;
|
||||
m_pVertex[count].ty = 0.0f;
|
||||
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[0],m_Node[i].g[0],m_Node[i].b[0],m_Node[i].Life);
|
||||
//1
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x + up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y + up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z + up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 1.0f;
|
||||
m_pVertex[count].ty = 0.0f;
|
||||
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[1],m_Node[i].g[1],m_Node[i].b[1],m_Node[i].Life);
|
||||
|
||||
//2
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x - up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y - up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z - up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 1.0f;
|
||||
m_pVertex[count].ty = 1.0f;
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[2],m_Node[i].g[2],m_Node[i].b[2],m_Node[i].Life);
|
||||
|
||||
//0
|
||||
m_pVertex[count].x = m_Node[i].X + (-right.x + up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (-right.y + up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (-right.z + up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 0.0f;
|
||||
m_pVertex[count].ty = 0.0f;
|
||||
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[0],m_Node[i].g[0],m_Node[i].b[0],m_Node[i].Life);
|
||||
|
||||
//2
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x - up.x)*(m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y - up.y)*(m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z - up.z)*(m_Size);
|
||||
m_pVertex[count].tx = 1.0f;
|
||||
m_pVertex[count].ty = 1.0f;
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[2],m_Node[i].g[2],m_Node[i].b[2],m_Node[i].Life);
|
||||
|
||||
//3
|
||||
m_pVertex[count].x = m_Node[i].X + (right.x + up.x)*(-m_Size);
|
||||
m_pVertex[count].y = m_Node[i].Y + (right.y + up.y)*(-m_Size);
|
||||
m_pVertex[count].z = m_Node[i].Z + (right.z + up.z)*(-m_Size);
|
||||
m_pVertex[count].tx = 0.0f;
|
||||
m_pVertex[count].ty = 1.0f;
|
||||
m_pVertex[count++].Color = D3DCOLOR_COLORVALUE(m_Node[i].r[3],m_Node[i].g[3],m_Node[i].b[3],m_Node[i].Life);
|
||||
} // m_bclose == true;
|
||||
else {
|
||||
m_pPoint[count2].v.x = m_Node[i].X;
|
||||
m_pPoint[count2].v.y = m_Node[i].Y;
|
||||
m_pPoint[count2].v.z = m_Node[i].Z;
|
||||
m_pPoint[count2++].color = D3DCOLOR_COLORVALUE(m_Node[i].r[0],m_Node[i].g[0],m_Node[i].b[0],m_Node[i].Life);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if(m_ClosePointNum) {
|
||||
VOID *tmp;
|
||||
m_FogBuffer->Lock(0,m_ClosePointNum * sizeof(ParticleVertex) * 6,
|
||||
(BYTE **)&tmp,0);
|
||||
memcpy(tmp,m_pVertex,m_ClosePointNum * sizeof(ParticleVertex) * 6);
|
||||
|
||||
m_FogBuffer->Unlock();
|
||||
|
||||
delete[] m_pVertex;
|
||||
m_pVertex = NULL;
|
||||
}
|
||||
//point sprite
|
||||
|
||||
VOID *tmp2;
|
||||
m_FogPointSpriteBuffer->Lock(0,(m_ParticleNum - m_ClosePointNum) * sizeof(POINTVERTEX),(BYTE **)&tmp2 ,0);
|
||||
|
||||
memcpy(tmp2,m_pPoint,sizeof(POINTVERTEX) * (m_ParticleNum - m_ClosePointNum));
|
||||
|
||||
m_FogPointSpriteBuffer->Unlock();
|
||||
|
||||
delete[] m_pPoint;
|
||||
m_pPoint = NULL;
|
||||
|
||||
}
|
||||
|
||||
// arg1 : LOD level
|
||||
void CFogScene::Render() {
|
||||
LRESULT rt;
|
||||
// <20>̺κ<CCBA><CEBA><EFBFBD> <20><><EFBFBD><EFBFBD>. point sprite use.
|
||||
ChangeVertexBuffer();
|
||||
|
||||
if(m_Lod) {
|
||||
float size = 1.0f;
|
||||
if(m_Size > 1000.0f) {
|
||||
size += ((m_Size - 1000.0f)/1000.0f);
|
||||
}
|
||||
if(!m_bPick)
|
||||
m_Device->SetTexture(0,m_BaseTexture->GetTexture());
|
||||
else {
|
||||
m_Device->SetTexture(0,NULL);
|
||||
m_Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
|
||||
}
|
||||
// point sprite setting ////////////////////////
|
||||
m_Device->SetRenderState( D3DRS_POINTSPRITEENABLE, TRUE );
|
||||
m_Device->SetRenderState( D3DRS_POINTSCALEENABLE, TRUE );
|
||||
|
||||
HRESULT hr;
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSIZE, FtoDW(10.0f * size) );
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(1.00f) );
|
||||
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSCALE_A, FtoDW(2.0f) );
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSCALE_B, FtoDW(1.00f) );
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSCALE_C, FtoDW(0.00f) );
|
||||
/*
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSCALE_A, FtoDW(0.00001f) );
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSCALE_B, FtoDW(0.00f) );
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSCALE_C, FtoDW(0.00f) );
|
||||
*/
|
||||
////////////////////////////////////////////////
|
||||
m_Device->SetRenderState( D3DRS_LIGHTING, FALSE);
|
||||
m_Device->SetRenderState(D3DRS_ZWRITEENABLE,FALSE);
|
||||
|
||||
m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
m_Device->SetRenderState(D3DRS_SRCBLEND,m_SrcBlendMode);
|
||||
m_Device->SetRenderState(D3DRS_DESTBLEND,m_DstBlendMode);
|
||||
m_Device->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
|
||||
//m_Device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE,D3DMCS_COLOR1);
|
||||
//m_Device->BeginScene();
|
||||
|
||||
m_Device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
|
||||
m_Device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
|
||||
m_Device->SetTextureStageState(0,D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
m_Device->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);
|
||||
|
||||
m_Device->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE);
|
||||
m_Device->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_TEXTURE);
|
||||
m_Device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
|
||||
|
||||
m_Device->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
|
||||
//// point sprite
|
||||
|
||||
m_Device->SetStreamSource( 0, m_FogPointSpriteBuffer, sizeof(POINTVERTEX));
|
||||
m_Device->SetVertexShader( D3DFVF_POINTVERTEX );
|
||||
|
||||
rt = m_Device->DrawPrimitive( D3DPT_POINTLIST, 0,m_ParticleNum - m_ClosePointNum);
|
||||
////
|
||||
hr = m_Device->SetRenderState( D3DRS_POINTSIZE_MIN, FtoDW(0.00f) );
|
||||
m_Device->SetRenderState( D3DRS_POINTSIZE, FtoDW(1.0f) );
|
||||
m_Device->SetRenderState( D3DRS_POINTSPRITEENABLE,FALSE);
|
||||
m_Device->SetRenderState( D3DRS_POINTSCALEENABLE,FALSE);
|
||||
|
||||
// <20>Ϲ<EFBFBD> quad
|
||||
if(m_ClosePointNum) {
|
||||
m_Device->SetStreamSource(0,m_FogBuffer,sizeof(ParticleVertex));
|
||||
m_Device->SetVertexShader(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
|
||||
|
||||
rt = m_Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,m_ClosePointNum*2);
|
||||
}
|
||||
// end setting
|
||||
//m_Device->EndScene();
|
||||
|
||||
if(m_bPick)
|
||||
m_Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
|
||||
|
||||
m_Device->SetRenderState(D3DRS_ZWRITEENABLE,TRUE);
|
||||
m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
m_Device->SetRenderState( D3DRS_LIGHTING, TRUE);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void CFogScene::SetEtc() {
|
||||
int i;
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
m_Node[i].bFade = false;
|
||||
m_Node[i].bFadeIn = false;
|
||||
m_Node[i].Fade = 0.01f;
|
||||
|
||||
// Node[i].Fade = (float)(rand()%100)/100000.0f + 0.005;
|
||||
}
|
||||
}
|
||||
// update node
|
||||
void CFogScene::Update(float x,float y,float z) {
|
||||
int i;
|
||||
ClosePerson(x,y,z);
|
||||
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
|
||||
if(m_Node[i].Life <=m_FadeOut) {
|
||||
m_Node[i].Active = false;
|
||||
m_Node[i].bFadeIn = true;
|
||||
m_Node[i].bFade = false;
|
||||
m_Node[i].Life = m_FadeOut;
|
||||
|
||||
}
|
||||
|
||||
//fade out
|
||||
if(m_Node[i].bFade == true) {
|
||||
m_Node[i].Life -= m_Node[i].Fade*m_FadeOutSpeed;
|
||||
if(m_Node[i].Life < m_FadeOut)
|
||||
m_Node[i].Life = m_FadeOut;
|
||||
}
|
||||
// fade in and out off
|
||||
if(m_Node[i].bFade == false && m_Node[i].bFadeIn == false) {
|
||||
m_Node[i].BackX = m_Node[i].X;
|
||||
m_Node[i].BackY = m_Node[i].Y;
|
||||
m_Node[i].BackZ = m_Node[i].Z;
|
||||
}
|
||||
|
||||
// wind <20><><EFBFBD><EFBFBD>
|
||||
m_Node[i].X += m_Node[i].Xi + m_Wind[0];
|
||||
|
||||
//if(Node[i].Xi >0)
|
||||
// MessageBox(NULL,"test","test",MB_OK);
|
||||
m_Node[i].Y += m_Wind[1];
|
||||
m_Node[i].Z += m_Wind[2];
|
||||
|
||||
//flow <20><><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD> <20>ȳ<EFBFBD><C8B3><EFBFBD><EFBFBD><EFBFBD>.
|
||||
if(m_Node[i].Flow <= m_Node[i].Y + m_Node[i].Yi)
|
||||
m_Node[i].Y += m_Node[i].Yi;
|
||||
|
||||
m_Node[i].Z += m_Node[i].Zi;
|
||||
|
||||
// <20>߷<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
m_Node[i].X += m_Gravity[0];
|
||||
m_Node[i].Y += m_Gravity[1];
|
||||
m_Node[i].Z += m_Gravity[2];
|
||||
|
||||
|
||||
if(m_Node[i].Active == false) {
|
||||
|
||||
m_Node[i].X = m_Node[i].BackX;
|
||||
m_Node[i].Y = m_Node[i].BackY;
|
||||
m_Node[i].Z = m_Node[i].BackZ;
|
||||
m_Node[i].Xi = 0.0f;
|
||||
m_Node[i].Yi = 0.0f;
|
||||
m_Node[i].Zi = 0.0f;
|
||||
m_Node[i].bFadeIn = true;
|
||||
m_Node[i].bFade = false;
|
||||
|
||||
//Node[i].Life = 1.0f;
|
||||
}
|
||||
//fade in
|
||||
if(m_Node[i].bFadeIn == true) {
|
||||
m_Node[i].Life +=m_Node[i].Fade * m_FadeInSpeed;
|
||||
|
||||
if(m_Node[i].Life > m_FadeIn) {
|
||||
|
||||
m_Node[i].Life = m_FadeIn;
|
||||
m_Node[i].Active = true;
|
||||
m_Node[i].bFadeIn = false;
|
||||
m_Node[i].bFade = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// ChangeVertexBuffer();
|
||||
}
|
||||
void CFogScene::Resetting() {
|
||||
int i;
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
if(m_Node[i].Active == false) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
void CFogScene::ClosePerson(vector3 pos) {
|
||||
int i;
|
||||
float tmp[3];
|
||||
float unit[3];
|
||||
float length;
|
||||
static vector3 before(0.0f,0.0f,0.0f);
|
||||
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
tmp[0] = m_Node[i].BackX - pos.x;
|
||||
tmp[1] = m_Node[i].BackY - pos.y;
|
||||
tmp[2] = m_Node[i].BackZ - pos.z;
|
||||
|
||||
length = (float)sqrt((tmp[0] * tmp[0]) + (tmp[1] * tmp[1]) + (tmp[2] * tmp[2]));
|
||||
unit[0] = tmp[0] / length;
|
||||
unit[1] = tmp[1] / length;
|
||||
unit[2] = tmp[2] / length;
|
||||
|
||||
if(m_Rad > length && before.x != pos.x && before.y != pos.y && before.z != pos.z) {
|
||||
float Density = 0.66f;
|
||||
/*if(m_Node[i].Life > m_FadeOut) {
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..
|
||||
Setfadein(0.7f);
|
||||
m_Node[i].Xi +=unit[0] * 0.01f;
|
||||
m_Node[i].bFade = true;
|
||||
//Node[i].Yi +=unit[1];
|
||||
m_Node[i].Zi +=unit[2]*0.01f;
|
||||
}*/
|
||||
m_Device->SetRenderState(D3DRS_FOGENABLE, TRUE);
|
||||
|
||||
// fog Į<><C4AE><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
m_Device->SetRenderState(D3DRS_FOGCOLOR,D3DCOLOR_COLORVALUE(m_Node[0].r[0],m_Node[0].g[0],m_Node[0].b[0],m_Node[0].Life));
|
||||
|
||||
m_Device->SetRenderState(D3DRS_FOGTABLEMODE,D3DFOG_EXP);
|
||||
m_Device->SetRenderState(D3DRS_FOGDENSITY, *(DWORD *)(&Density));
|
||||
|
||||
}
|
||||
else {
|
||||
m_Device->SetRenderState(D3DRS_FOGENABLE,FALSE);
|
||||
before = pos;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..--;
|
||||
Setfadein(1.0f);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CFogScene::ClosePerson(float x,float y,float z){
|
||||
int i;
|
||||
float tmp[3] = {0.0f,0.0f,0.0f};
|
||||
float unit[3] = {0.0f,0.0f,0.0f};
|
||||
float length = 0.0f;
|
||||
float Density = 0.66f;
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ѻ<EFBFBD><D1BB><EFBFBD><EFBFBD>϶<EFBFBD> <20><><EFBFBD>̴<EFBFBD>.. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD≯<EFBFBD>.. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>÷<EFBFBD><C3B7><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> üũ<C3BC>Ͽ<EFBFBD><CFBF><EFBFBD> <20>Ұ<EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static float before[3] = {0.0f,0.0f,0.0f};
|
||||
int f=0;
|
||||
m_ClosePointNum = 0;
|
||||
|
||||
for(i=0;i<m_ParticleNum;i++) {
|
||||
tmp[0] = m_Node[i].BackX - x;
|
||||
// tmp[1] = m_Node[i].BackY - y;
|
||||
tmp[2] = m_Node[i].BackZ - z;
|
||||
|
||||
length = (float)sqrt((tmp[0] * tmp[0]) /*+ (tmp[1] * tmp[1])*/ + (tmp[2] * tmp[2]));
|
||||
unit[0] = tmp[0] / length;
|
||||
unit[1] = tmp[1] / length;
|
||||
unit[2] = tmp[2] / length;
|
||||
|
||||
if(m_Rad > length && (before[0] != x || before[1] != y || before[2] != z)) {
|
||||
if(m_Node[i].Life > m_FadeOut) {
|
||||
|
||||
m_Node[i].Xi +=unit[0]*0.01f;
|
||||
m_Node[i].bFade = true;
|
||||
//Node[i].Yi +=unit[1]*5.0f;
|
||||
m_Node[i].Zi +=unit[2]*0.01f;
|
||||
}
|
||||
else {
|
||||
|
||||
// f--;
|
||||
|
||||
before[0] = x;
|
||||
before[1] = y;
|
||||
before[2] = z;
|
||||
}
|
||||
}
|
||||
if(m_Rad >length) {
|
||||
f++;
|
||||
}
|
||||
if(m_Rad + 7500.0f>length) {
|
||||
// point sprite -> bilboard fog settting
|
||||
m_ClosePointNum++;
|
||||
m_Node[i].m_bClose = true;
|
||||
}
|
||||
else {
|
||||
m_Node[i].m_bClose = false;
|
||||
}
|
||||
|
||||
}
|
||||
// <20><><EFBFBD><EFBFBD> <20>ȰԼӿ<D4BC> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
if(f>0) {
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..
|
||||
Setfadein(m_BackFadeIn / 2.0f);
|
||||
}
|
||||
//<2F><><EFBFBD><EFBFBD> <20>ȰԼӿ<D4BC> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..
|
||||
if(f==0) {
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..--;
|
||||
Setfadein(m_BackFadeIn);
|
||||
}
|
||||
}
|
||||
|
||||
void CFogScene::SetSize(float fsize) {
|
||||
m_Size = fsize;
|
||||
}
|
||||
void CFogScene::SetBlendMode(DWORD src,DWORD dst) {
|
||||
|
||||
m_SrcBlendMode = src;
|
||||
|
||||
m_DstBlendMode = dst;
|
||||
}
|
||||
void CFogScene::Setfadein(float f) {
|
||||
m_FadeIn = f;
|
||||
}
|
||||
void CFogScene::Setfadeout(float f) {
|
||||
m_FadeOut = f;
|
||||
}
|
||||
void CFogScene::SetBackFadeIn(float f) {
|
||||
m_BackFadeIn = f;
|
||||
|
||||
}
|
||||
264
Engine/Zalla3D Scene Class/FogScene.h
Normal file
264
Engine/Zalla3D Scene Class/FogScene.h
Normal file
@@ -0,0 +1,264 @@
|
||||
#ifndef __WBFOG_H__
|
||||
#define __WBFOG_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "texture.h"
|
||||
#include "SceneNode.h"
|
||||
#include "SceneManager.h"
|
||||
#include "3dmath.h"
|
||||
|
||||
#include <d3dx8.h>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#define INIT_NUM 50
|
||||
|
||||
//Lod Size
|
||||
#define LOD_NEAR 2000.0f
|
||||
#define LOD_FAR 60000.0f
|
||||
|
||||
#define ALPHA_MAX 0xffffffff
|
||||
#define ALPHA_MID 0x80808080
|
||||
|
||||
#define D3DFVF_POINTVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
|
||||
|
||||
#define FOGTEX "vfog.dds"
|
||||
//LOD Define
|
||||
enum LODLEVEL{
|
||||
NOT_SCENE,
|
||||
NEAR_LOD,
|
||||
FAR_LOD
|
||||
};
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CFogScene : public CSceneNode{
|
||||
public:
|
||||
CFogScene( );
|
||||
CFogScene(int );
|
||||
void Create(vector3 );
|
||||
|
||||
// particle's system center
|
||||
void SetCenterPos(float x,float y,float z);
|
||||
void SetCenterPos(vector3 );
|
||||
//particle node pos
|
||||
void SetPos();
|
||||
void SetPos(int );
|
||||
void SetPos(int ,float ,float ,float );
|
||||
|
||||
// <20><><EFBFBD>ߵ<EFBFBD>
|
||||
void SetCenter(float );
|
||||
void Render();
|
||||
|
||||
void SetPick(bool b) {m_bPick = b;}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
void SetFlow(float );
|
||||
|
||||
void SetFlow(float ,int );
|
||||
// color set
|
||||
void SetColor(float ,float ,float ,float );
|
||||
void SetColor(float ,float ,float ,float ,int p_index);
|
||||
// <20><><EFBFBD><EFBFBD> <20>÷<EFBFBD>(<28><><EFBFBD>ؽ<EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||||
void SetVertexColor(float ,float ,float ,float ,int dimension);
|
||||
|
||||
// gravity set
|
||||
void SetGravity(float ,float ,float );
|
||||
// speed set
|
||||
void SetSpeed(float ,float ,float );
|
||||
void SetSpeed(float ,float ,float ,int );
|
||||
void SetSpeed();
|
||||
//bfade set...
|
||||
void SetEtc();
|
||||
|
||||
// set height
|
||||
void SetHeight(float ,int );
|
||||
void SetHeight(float );
|
||||
|
||||
void SetWind(float ,float ,float );
|
||||
void SetImpress(vector3 imp);
|
||||
void SetImpress(float ,float ,float );
|
||||
|
||||
void SetSpeedPower(float );
|
||||
void Update(float ,float ,float );
|
||||
void ClosePerson(vector3 );
|
||||
void ClosePerson(float ,float ,float );
|
||||
|
||||
// parameter resetting.
|
||||
void Resetting();
|
||||
|
||||
void ChangeVertexBuffer();
|
||||
|
||||
void SetSize(float );
|
||||
void SetBlendMode(DWORD ,DWORD );
|
||||
|
||||
void SetRad(float r) { m_Rad = r;}
|
||||
void CreateVertexBuffer();
|
||||
vector3 GetCenter() {return m_CenterPoint;}
|
||||
|
||||
void Setfadeout(float );
|
||||
void Setfadein(float );
|
||||
void SetBackFadeIn(float f);
|
||||
void SetFadeInSpeed(float s) {m_FadeInSpeed = s;}
|
||||
void SetFadeOutSpeed(float s) {m_FadeOutSpeed = s;}
|
||||
DWORD FtoDW( FLOAT f ) { return *((DWORD*)&f); }
|
||||
~CFogScene();
|
||||
|
||||
private:
|
||||
class POINTVERTEX {
|
||||
public:
|
||||
D3DXVECTOR3 v;
|
||||
D3DCOLOR color;
|
||||
|
||||
POINTVERTEX() {
|
||||
v.x = v.y = v.z = 0.0f;
|
||||
color = D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f);
|
||||
}
|
||||
~POINTVERTEX() {}
|
||||
};
|
||||
|
||||
// <20><>ƼŬ <20>⺻ <20><><EFBFBD><EFBFBD> class
|
||||
class ParticleNode{
|
||||
|
||||
public:
|
||||
bool Active; // really life
|
||||
float Life; //Alpha value
|
||||
float Fade; // Alpha speed
|
||||
bool bFade; // start fade y/n
|
||||
bool bFadeIn;//fade in y/n
|
||||
bool m_bClose;
|
||||
|
||||
// <20>ִ<EFBFBD> fadein/out value
|
||||
|
||||
|
||||
//RGB
|
||||
float r[4];
|
||||
float g[4];
|
||||
float b[4];
|
||||
|
||||
//Position
|
||||
float X;
|
||||
float Y;
|
||||
float Z;
|
||||
// Before Position
|
||||
float BackX;
|
||||
float BackY;
|
||||
float BackZ;
|
||||
// speed
|
||||
float Xi;
|
||||
float Yi;
|
||||
float Zi;
|
||||
// sector position
|
||||
int Sector_X;
|
||||
int Sector_Y;
|
||||
// limit value in y axis
|
||||
float Flow;
|
||||
ParticleNode() {
|
||||
m_bClose = false;
|
||||
|
||||
}
|
||||
~ParticleNode() {}
|
||||
};
|
||||
//render <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Ǵ<EFBFBD> vertex <20><><EFBFBD><EFBFBD> class
|
||||
class ParticleVertex{
|
||||
|
||||
public:
|
||||
float x,y,z;
|
||||
DWORD Color;
|
||||
float tx,ty;
|
||||
ParticleVertex() {
|
||||
x = y = z = 0.0f;
|
||||
Color = D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f);
|
||||
tx = ty = 0.0f;
|
||||
}
|
||||
~ParticleVertex() {}
|
||||
};
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
float m_FadeOut;
|
||||
float m_FadeIn;
|
||||
// fade in speed
|
||||
float m_FadeInSpeed;
|
||||
float m_FadeOutSpeed;
|
||||
|
||||
// <20>ٶ<EFBFBD> <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD> <20> <20>ӵ<EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||||
float m_Wind[3];
|
||||
//center <20><><EFBFBD>ߵ<EFBFBD>
|
||||
float m_Center;
|
||||
//<2F><><EFBFBD><EFBFBD>ġ
|
||||
vector3 m_Impress;
|
||||
|
||||
|
||||
// speed vector = direction vector * Speed_Power
|
||||
float m_SpeedPower;
|
||||
//<2F>߷<EFBFBD>
|
||||
float m_Gravity[3];
|
||||
//speed
|
||||
float m_Speed[3];
|
||||
|
||||
int m_ParticleNum;
|
||||
int m_ClosePointNum;
|
||||
|
||||
int m_LodLevel;
|
||||
int m_LodNum;
|
||||
// particle size
|
||||
float m_Size;
|
||||
|
||||
DWORD m_SrcBlendMode;
|
||||
DWORD m_DstBlendMode;
|
||||
|
||||
|
||||
// fog system center.
|
||||
vector3 m_CenterPoint;
|
||||
ParticleVertex *m_pVertex;
|
||||
POINTVERTEX *m_pPoint;
|
||||
|
||||
ParticleNode *m_Node;
|
||||
//LPDIRECT3DTEXTURE8 *m_TextureId;
|
||||
CTexture *m_BaseTexture;
|
||||
int m_TextureNum;
|
||||
LPDIRECT3DDEVICE8 m_Device;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_FogBuffer;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_FogPointSpriteBuffer;
|
||||
float m_BackFadeIn;
|
||||
float m_Rad;
|
||||
// picking <20><> <20><><EFBFBD>̴<EFBFBD> <20><>
|
||||
bool m_bPick;
|
||||
int m_Lod;
|
||||
};
|
||||
|
||||
class CVfogArg{
|
||||
public:
|
||||
float m_FadeIn;
|
||||
float m_FadeOut;
|
||||
float m_FadeInSpeed;
|
||||
float m_A1;
|
||||
float m_A2;
|
||||
float m_A3;
|
||||
float m_A4;
|
||||
float m_B1;
|
||||
float m_B2;
|
||||
float m_B3;
|
||||
float m_B4;
|
||||
int m_Center;
|
||||
int m_Num;
|
||||
float m_G1;
|
||||
float m_G2;
|
||||
float m_G3;
|
||||
float m_G4;
|
||||
float m_Gx;
|
||||
float m_Gy;
|
||||
float m_Gz;
|
||||
float m_ImX;
|
||||
float m_ImY;
|
||||
float m_ImZ;
|
||||
float m_R1;
|
||||
float m_R2;
|
||||
float m_R3;
|
||||
float m_R4;
|
||||
float m_Rad;
|
||||
int m_Size;
|
||||
};
|
||||
|
||||
#endif
|
||||
616
Engine/Zalla3D Scene Class/FullSceneEffect.cpp
Normal file
616
Engine/Zalla3D Scene Class/FullSceneEffect.cpp
Normal file
@@ -0,0 +1,616 @@
|
||||
// FullSceneEffect.cpp: implementation of the CFullSceneEffect class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "FullSceneEffect.h"
|
||||
#include "BaseGraphicsLayer.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
enum FULLSCENE_EFFECTS {
|
||||
FULLSCENE_MOTIONBLUR = 0,
|
||||
FULLSCENE_BRIGHT,
|
||||
FULLSCENE_BLACK,
|
||||
FULLSCENE_CONTRAST,
|
||||
FULLSCENE_LEVEL,
|
||||
FULLSCENE_GRAYLEVEL,
|
||||
FULLSCENE_EDGE,
|
||||
FULLSCENE_NEGATIVE,
|
||||
FULLSCENE_SEPIA,
|
||||
FULLSCENE_SOLAR,
|
||||
FULLSCENE_NUMS,
|
||||
};
|
||||
#define FULLSCENE_BLURTEXNUM 6
|
||||
#define FULLSCENE_BLURTEXSIZE 1024
|
||||
|
||||
class CFullSceneEffect
|
||||
{
|
||||
protected:
|
||||
LPDIRECT3DDEVICE8 m_pDevice;
|
||||
|
||||
LPDIRECT3DTEXTURE8 m_pBlurTexture[FULLSCENE_BLURTEXNUM];
|
||||
LPDIRECT3DSURFACE8 m_pBlurTextureSurf[FULLSCENE_BLURTEXNUM];
|
||||
|
||||
LPDIRECT3DTEXTURE8 m_pRenderTexture;
|
||||
LPDIRECT3DSURFACE8 m_pRenderTextureSurface;
|
||||
LPDIRECT3DSURFACE8 m_pRenderZSurface;
|
||||
|
||||
LPDIRECT3DSURFACE8 m_pFrameBuffer;
|
||||
LPDIRECT3DSURFACE8 m_pFrameZBuffer;
|
||||
bool m_bFlag[FULLSCENE_NUMS];
|
||||
|
||||
public:
|
||||
|
||||
void Init(LPDIRECT3DDEVICE8 lpDevice);
|
||||
|
||||
void BeginRender();
|
||||
void EndRender();
|
||||
void Render();
|
||||
void Update();
|
||||
void SetFlag(int i,bool bFlag) { m_bFlag[i] = bFlag;}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
*/
|
||||
CFullSceneEffect::CFullSceneEffect() : m_pDevice(0),m_pRenderZSurface(0),m_pFrameBuffer(0),m_pFrameZBuffer(0)
|
||||
{
|
||||
|
||||
for(int i = 0; i < FULLSCENE_BLURTEXNUM + 1; i++ )
|
||||
{
|
||||
m_pRenderTexture[i] = NULL;
|
||||
m_pRenderTextureSurface[i] = NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
memset(m_bFlag,0,sizeof(bool) * FULLSCENE_NUMS);
|
||||
memset(m_bLockFlag,0,sizeof(bool) * FULLSCENE_NUMS);
|
||||
|
||||
m_iFrameWidth = 0;
|
||||
m_iFrameHeight = 0;
|
||||
m_pVertexBuffer = NULL;
|
||||
m_iBlurTexUpdateFrame = 1; // BlurTex Update <20><><EFBFBD><EFBFBD>
|
||||
m_iBlurTexUpdateCount = 0;
|
||||
|
||||
m_lstEffects.clear();
|
||||
m_bPixelShader = false;
|
||||
|
||||
m_iBlurFirstUpdate = -1;
|
||||
|
||||
|
||||
m_bFullSceneEffect = true;
|
||||
|
||||
m_iRenderWidth = 0;
|
||||
m_iRenderHeight = 0;
|
||||
|
||||
|
||||
m_pRenderZSurface = NULL;
|
||||
m_pFrameBuffer = NULL;
|
||||
m_pFrameZBuffer = NULL;
|
||||
|
||||
m_pVertexBuffer = NULL;
|
||||
|
||||
m_iMaxCountNum = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
CFullSceneEffect::~CFullSceneEffect()
|
||||
{
|
||||
|
||||
for(int i = 0; i < FULLSCENE_BLURTEXNUM + 1; i++ ) {
|
||||
if(m_pRenderTexture[i]) {
|
||||
m_pRenderTexture[i]->Release();
|
||||
m_pRenderTexture[i] = NULL;
|
||||
}
|
||||
if(m_pRenderTextureSurface[i] ) {
|
||||
m_pRenderTextureSurface[i]->Release();
|
||||
m_pRenderTextureSurface[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_pRenderZSurface) {
|
||||
m_pRenderZSurface->Release();
|
||||
m_pRenderZSurface = NULL;
|
||||
}
|
||||
if(m_pFrameBuffer) {
|
||||
m_pFrameBuffer->Release();
|
||||
m_pFrameBuffer = NULL;
|
||||
}
|
||||
if(m_pFrameZBuffer) {
|
||||
m_pFrameZBuffer->Release();
|
||||
m_pFrameZBuffer = NULL;
|
||||
}
|
||||
if(m_pVertexBuffer) {
|
||||
m_pVertexBuffer->Release();
|
||||
m_pVertexBuffer = NULL;
|
||||
}
|
||||
|
||||
for(int i=0;i <(int)(m_lstEffects.size());i++)
|
||||
{
|
||||
if(m_lstEffects[i] != NULL)
|
||||
{
|
||||
delete m_lstEffects[i];
|
||||
m_lstEffects[i] = NULL;
|
||||
}
|
||||
}
|
||||
m_lstEffects.clear();
|
||||
|
||||
|
||||
}
|
||||
void CFullSceneEffect::Init(LPDIRECT3DDEVICE8 lpDevice)
|
||||
{
|
||||
m_iCurrentTextureNum = 0;
|
||||
m_iMaxCountNum = 0;
|
||||
|
||||
if(m_bFullSceneEffect) {
|
||||
m_pDevice = lpDevice;
|
||||
|
||||
m_pDevice->GetDeviceCaps(&m_pCaps);
|
||||
if(m_pCaps.PixelShaderVersion <= 1.0f)
|
||||
{
|
||||
m_bPixelShader = false;
|
||||
|
||||
}
|
||||
else
|
||||
m_bPixelShader = true;
|
||||
|
||||
m_pDevice->GetRenderTarget(&m_pFrameBuffer);
|
||||
|
||||
D3DSURFACE_DESC FrameDecl;
|
||||
m_pFrameBuffer->GetDesc( &FrameDecl );
|
||||
|
||||
m_iFrameWidth = FrameDecl.Width;
|
||||
m_iFrameHeight = FrameDecl.Height;
|
||||
|
||||
D3DXCreateTexture(m_pDevice, m_iFrameWidth,m_iFrameHeight, 1,
|
||||
D3DUSAGE_RENDERTARGET, BaseGraphicsLayer::m_d3dpp.BackBufferFormat,
|
||||
D3DPOOL_DEFAULT, &m_pRenderTexture[0]);
|
||||
|
||||
// Render Texture Surface Get
|
||||
m_pRenderTexture[0]->GetSurfaceLevel(0, &m_pRenderTextureSurface[0]);
|
||||
m_pRenderTextureSurface[0]->GetDesc( &FrameDecl );
|
||||
|
||||
int iTexWidth = FrameDecl.Width;
|
||||
int iTexHeight = FrameDecl.Height;
|
||||
|
||||
/*
|
||||
if(BaseGraphicsLayer::GetGraphicCard() < 5)
|
||||
{
|
||||
if(iTexWidth > 1024 || iTexHeight > 1024) { // 1024 <20>̻<EFBFBD><CCBB><EFBFBD> <20>ʹ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
m_bFullSceneEffect = false;
|
||||
if(m_pRenderTexture[0]) {
|
||||
m_pRenderTexture[0]->Release();
|
||||
m_pRenderTexture[0] = NULL;
|
||||
}
|
||||
if(m_pRenderTextureSurface[0]) {
|
||||
m_pRenderTextureSurface[0]->Release();
|
||||
m_pRenderTextureSurface[0] = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
m_iRenderWidth = iTexWidth;
|
||||
m_iRenderHeight = iTexHeight;
|
||||
|
||||
for(int iBlur = 0;iBlur < FULLSCENE_BLURTEXNUM; iBlur++) {
|
||||
D3DXCreateTexture(m_pDevice, iTexWidth,iTexHeight, 1,
|
||||
D3DUSAGE_RENDERTARGET, BaseGraphicsLayer::m_d3dpp.BackBufferFormat,
|
||||
D3DPOOL_DEFAULT, &m_pRenderTexture[iBlur+1]);
|
||||
|
||||
// Render Texture Surface Get
|
||||
m_pRenderTexture[iBlur+1]->GetSurfaceLevel(0, &m_pRenderTextureSurface[iBlur+1]);
|
||||
|
||||
}
|
||||
//Depth Buffer Create
|
||||
|
||||
m_pDevice->CreateDepthStencilSurface(iTexWidth,
|
||||
iTexHeight,
|
||||
BaseGraphicsLayer::m_d3dpp.AutoDepthStencilFormat,
|
||||
D3DMULTISAMPLE_NONE,
|
||||
&m_pRenderZSurface);
|
||||
|
||||
// Frame Surface Backup
|
||||
m_pDevice->GetDepthStencilSurface(&m_pFrameZBuffer);
|
||||
|
||||
m_pDevice->GetViewport(&m_FrameViewport);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20>Ҷ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϰ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20>ش<EFBFBD>.
|
||||
/*
|
||||
m_RenderViewport.X = 0 + 1;
|
||||
m_RenderViewport.Y = 0 + 1;
|
||||
m_RenderViewport.Width = iTexWidth - 2;
|
||||
m_RenderViewport.Height = iTexHeight- 2;
|
||||
m_RenderViewport.MinZ = 0.0f;
|
||||
m_RenderViewport.MaxZ = 1.0f;
|
||||
*/
|
||||
|
||||
m_RenderViewport.X = 0;
|
||||
m_RenderViewport.Y = 0;
|
||||
m_RenderViewport.Width = iTexWidth;
|
||||
m_RenderViewport.Height = iTexHeight;
|
||||
m_RenderViewport.MinZ = 0.0f;
|
||||
m_RenderViewport.MaxZ = 1.0f;
|
||||
|
||||
m_ClearViewport.X = 0;
|
||||
m_ClearViewport.Y = 0;
|
||||
m_ClearViewport.Width = iTexWidth;
|
||||
m_ClearViewport.Height = iTexHeight;
|
||||
m_ClearViewport.MinZ = 0.0f;
|
||||
m_ClearViewport.MaxZ = 1.0f;
|
||||
|
||||
CreateVertexBuffer();
|
||||
|
||||
m_iBlurTexUpdateFrame = 1; // BlurTex Update <20><><EFBFBD><EFBFBD>
|
||||
m_iBlurTexUpdateCount = 0;
|
||||
if(m_bPixelShader) {
|
||||
// Filter Init
|
||||
for(int i = 0; i < FULLSCENE_NUMS;i++ )
|
||||
{
|
||||
CFullSceneShader *m_pShader = NULL;
|
||||
|
||||
switch(i) {
|
||||
case FULLSCENE_BRIGHT:
|
||||
m_pShader = new CFullSceneShader("Brightness");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;
|
||||
case FULLSCENE_BLACK:
|
||||
m_pShader = new CFullSceneShader("Black");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
|
||||
break;
|
||||
/* case FULLSCENE_CONTRAST:
|
||||
m_pShader = new CFullSceneShader("Contrast");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
|
||||
break;*/
|
||||
/* case FULLSCENE_LEVEL:
|
||||
m_pShader = new CFullSceneShader("Levels");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;*/
|
||||
|
||||
/* case FULLSCENE_GRAYLEVEL:
|
||||
m_pShader = new CFullSceneShader("LevelsGrayScale.psh");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
|
||||
break;*/
|
||||
case FULLSCENE_EDGE:
|
||||
m_pShader = new CFullSceneShader("Edges");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
|
||||
break;
|
||||
case FULLSCENE_NEGATIVE:
|
||||
m_pShader = new CFullSceneShader("Negative");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
|
||||
break;
|
||||
case FULLSCENE_SEPIA:
|
||||
m_pShader = new CFullSceneShader("Sepia");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
|
||||
break;
|
||||
/* case FULLSCENE_SOLAR:
|
||||
m_pShader = new CFullSceneShader("Solarize");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
|
||||
break;*/
|
||||
case FULLSCENE_EDGE2:
|
||||
m_pShader = new CFullSceneShader("Edge2");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;
|
||||
case FULLSCENE_EDGE3:
|
||||
m_pShader = new CFullSceneShader("Edge3");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;
|
||||
|
||||
case FULLSCENE_SHARPEN:
|
||||
m_pShader = new CFullSceneShader("Sharpen");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;
|
||||
case FULLSCENE_SATURATION:
|
||||
m_pShader = new CFullSceneShader("saturation");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;
|
||||
case FULLSCENE_SATURATION2:
|
||||
m_pShader = new CFullSceneShader("saturation2");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;
|
||||
/* case FULLSCENE_BLUR:
|
||||
m_pShader = new CFullSceneShader("Blur.psh");
|
||||
m_lstEffects.push_back(m_pShader);
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void CFullSceneEffect::CreateVertexBuffer()
|
||||
{
|
||||
m_pDevice->CreateVertexBuffer(sizeof(TLVertex) * 4,D3DUSAGE_WRITEONLY,TLVERTEXFVF,D3DPOOL_MANAGED,&m_pVertexBuffer);
|
||||
TLVertex *pVertex = NULL;
|
||||
|
||||
m_pVertexBuffer->Lock(0,0,(BYTE **)&pVertex,0);
|
||||
|
||||
pVertex[0].v.x=0.0f;
|
||||
pVertex[1].v.x=0.0f;
|
||||
pVertex[2].v.x=m_iFrameWidth;
|
||||
pVertex[3].v.x=m_iFrameWidth;
|
||||
|
||||
pVertex[1].v.y=0.0f;
|
||||
pVertex[3].v.y=0.0f;//
|
||||
pVertex[0].v.y=m_iFrameHeight;
|
||||
pVertex[2].v.y=m_iFrameHeight;
|
||||
|
||||
pVertex[0].tu=0.0f;
|
||||
pVertex[1].tu=0.0f;
|
||||
|
||||
pVertex[3].tu=1.0f;
|
||||
pVertex[2].tu=1.0f;
|
||||
|
||||
pVertex[1].tv=0.0f;
|
||||
pVertex[3].tv=0.0f;
|
||||
|
||||
pVertex[0].tv=1.0f;
|
||||
pVertex[2].tv=1.0f;
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
pVertex[i].w=0.1f;
|
||||
pVertex[i].v.z=0.1f;
|
||||
pVertex[i].Diffuse.c=0xffffffff;
|
||||
pVertex[i].Specular.c=0xffffffff;
|
||||
}
|
||||
|
||||
m_pVertexBuffer->Unlock();
|
||||
|
||||
|
||||
}
|
||||
HRESULT CFullSceneEffect::BeginRender(DWORD dwClearColor)
|
||||
{
|
||||
if(m_bFullSceneEffect) {
|
||||
|
||||
HRESULT hr = m_pDevice->SetRenderTarget(m_pRenderTextureSurface[m_iCurrentTextureNum], m_pRenderZSurface);//m_pFrameZBuffer);
|
||||
m_pDevice->SetViewport(&m_ClearViewport);
|
||||
|
||||
m_pDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER|D3DCLEAR_TARGET, dwClearColor, 1.0f, 0 );
|
||||
m_pDevice->SetViewport(&m_RenderViewport);
|
||||
return hr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
HRESULT CFullSceneEffect::EndRender()
|
||||
{
|
||||
if(m_bFullSceneEffect) {
|
||||
|
||||
HRESULT hr = m_pDevice->SetRenderTarget(m_pFrameBuffer, m_pFrameZBuffer);
|
||||
m_pDevice->SetViewport(&m_FrameViewport);
|
||||
|
||||
return hr;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CFullSceneEffect::Render(int iValue) {
|
||||
if(m_bFullSceneEffect) {
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_MIPFILTER, D3DTEXF_NONE);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP);
|
||||
}
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
|
||||
|
||||
|
||||
/////////////////
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
m_pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
|
||||
m_pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
|
||||
|
||||
|
||||
m_pDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,0);
|
||||
m_pDevice->SetTextureStageState(0 ,D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_NORMALIZENORMALS,FALSE);
|
||||
m_pDevice->SetRenderState(D3DRS_LOCALVIEWER,FALSE);
|
||||
m_pDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
|
||||
m_pDevice->SetRenderState(D3DRS_FOGENABLE,FALSE);
|
||||
|
||||
m_pDevice->SetVertexShader(TLVERTEXFVF);
|
||||
m_pDevice->SetStreamSource(0,m_pVertexBuffer,sizeof(TLVertex));
|
||||
|
||||
m_pDevice->SetTexture(0,m_pRenderTexture[m_iCurrentTextureNum]);
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
|
||||
if(m_bPixelShader) {
|
||||
// FullScene Filter
|
||||
for(int i=1;i <FULLSCENE_NUMS; i++ ) {
|
||||
if(m_bFlag[i] == true)
|
||||
{
|
||||
if(iValue == 0)
|
||||
m_lstEffects[i - 1]->Apply();
|
||||
else
|
||||
m_lstEffects[i - 1]->Apply(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(iValue == 1) {
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
|
||||
m_pDevice->SetRenderState(D3DRS_TEXTUREFACTOR, 0x66ffffff);
|
||||
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
|
||||
}
|
||||
|
||||
if(m_bFlag[FULLSCENE_EDGE] == true ||
|
||||
m_bFlag[FULLSCENE_EDGE2] == true ||
|
||||
m_bFlag[FULLSCENE_EDGE3] == true ||
|
||||
m_bFlag[FULLSCENE_SHARPEN] == true)
|
||||
{
|
||||
m_pDevice->SetTexture(1,m_pRenderTexture[m_iCurrentTextureNum]);
|
||||
m_pDevice->SetTexture(2,m_pRenderTexture[m_iCurrentTextureNum]);
|
||||
m_pDevice->SetTexture(3,m_pRenderTexture[m_iCurrentTextureNum]);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_pDevice->SetPixelShader(0);
|
||||
|
||||
}
|
||||
// Render Scene
|
||||
m_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
|
||||
|
||||
|
||||
// FullScene MotionBlur
|
||||
if(m_bFlag[FULLSCENE_MOTIONBLUR] == true && (m_bFlag[FULLSCENE_BRIGHT] != true) && (m_iBlurFirstUpdate >= 0)) {//&&( m_bFlag[FULLSCENE_SATURATION] != true)) {
|
||||
|
||||
// FullScene Filter
|
||||
if(m_bPixelShader) {
|
||||
for(int i=1;i <FULLSCENE_NUMS; i++ ) {
|
||||
if(m_bFlag[i] == true)
|
||||
{
|
||||
m_lstEffects[i - 1]->Apply(1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_pDevice->SetPixelShader(0);
|
||||
}
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
m_pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
m_pDevice->SetRenderState(D3DRS_TEXTUREFACTOR, 0x66ffffff);
|
||||
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
|
||||
m_pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
|
||||
|
||||
for(int iBlur = 0;iBlur < m_iMaxCountNum; iBlur++) {
|
||||
if(iBlur == m_iCurrentTextureNum)
|
||||
continue;
|
||||
|
||||
m_pDevice->SetVertexShader(TLVERTEXFVF);
|
||||
m_pDevice->SetTexture(0,m_pRenderTexture[iBlur]);
|
||||
|
||||
if(m_bPixelShader) {
|
||||
if(m_bFlag[FULLSCENE_EDGE] == true ||
|
||||
m_bFlag[FULLSCENE_EDGE2] == true ||
|
||||
m_bFlag[FULLSCENE_EDGE3] == true ||
|
||||
m_bFlag[FULLSCENE_SHARPEN] == true)
|
||||
{
|
||||
m_pDevice->SetTexture(1,m_pRenderTexture[iBlur]);
|
||||
m_pDevice->SetTexture(2,m_pRenderTexture[iBlur]);
|
||||
m_pDevice->SetTexture(3,m_pRenderTexture[iBlur]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
|
||||
}
|
||||
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
}
|
||||
if(m_bPixelShader) {
|
||||
//Filter Pixel Shader Free
|
||||
for(int i=1;i <FULLSCENE_NUMS; i++ ) {
|
||||
if(m_bFlag[i] == true)
|
||||
{
|
||||
m_lstEffects[i - 1]->UnApply();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_COLORARG1, D3DTA_TEXTURE);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
||||
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_MIPFILTER, D3DTEXF_LINEAR);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP);
|
||||
m_pDevice->SetTextureStageState(i, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP);
|
||||
}
|
||||
|
||||
m_pDevice->SetRenderState(D3DRS_FOGENABLE,TRUE);
|
||||
m_pDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
|
||||
|
||||
|
||||
Update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
void CFullSceneEffect::Update()
|
||||
{
|
||||
m_iCurrentTextureNum++;
|
||||
m_iMaxCountNum++;
|
||||
if(m_iCurrentTextureNum >= FULLSCENE_BLURTEXNUM +1)
|
||||
m_iCurrentTextureNum = 0;
|
||||
if(m_iMaxCountNum >= FULLSCENE_BLURTEXNUM +1)
|
||||
m_iMaxCountNum = FULLSCENE_BLURTEXNUM +1;
|
||||
|
||||
|
||||
/* */if(m_bFlag[FULLSCENE_MOTIONBLUR] == true) {
|
||||
/*
|
||||
m_iBlurTexUpdateCount++;
|
||||
|
||||
if(m_iBlurTexUpdateCount == m_iBlurTexUpdateFrame) { // Update Blur Texture
|
||||
m_iBlurFirstUpdate++;
|
||||
m_iBlurTexUpdateCount = 0;
|
||||
D3DXLoadSurfaceFromSurface(
|
||||
m_pBlurTextureSurf[m_iCurrentBlurTex],
|
||||
NULL,
|
||||
NULL,
|
||||
m_pRenderTextureSurface,
|
||||
NULL,
|
||||
NULL,
|
||||
D3DX_DEFAULT,
|
||||
0);
|
||||
|
||||
m_iCurrentBlurTex++;
|
||||
if(m_iCurrentBlurTex >= FULLSCENE_BLURTEXNUM)
|
||||
m_iCurrentBlurTex = 0;*/
|
||||
m_iBlurFirstUpdate++;
|
||||
if(m_iBlurFirstUpdate >= FULLSCENE_BLURTEXNUM)
|
||||
m_iBlurFirstUpdate = FULLSCENE_BLURTEXNUM;
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
// m_iCurrentBlurTex = 0;
|
||||
m_iBlurFirstUpdate = -1;
|
||||
}
|
||||
}
|
||||
118
Engine/Zalla3D Scene Class/FullSceneEffect.h
Normal file
118
Engine/Zalla3D Scene Class/FullSceneEffect.h
Normal file
@@ -0,0 +1,118 @@
|
||||
// FullSceneEffect.h: interface for the CFullSceneEffect class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_FULLSCENEEFFECT_H__3E5DCE3F_4B17_40D9_A830_FCE7E55D490A__INCLUDED_)
|
||||
#define AFX_FULLSCENEEFFECT_H__3E5DCE3F_4B17_40D9_A830_FCE7E55D490A__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
#include <d3dx8.h>
|
||||
#include <d3d8.h>
|
||||
#include <vector>
|
||||
|
||||
#include "Vertex.h"
|
||||
#include "FullSceneShader.h"
|
||||
|
||||
enum FULLSCENE_EFFECTS {
|
||||
FULLSCENE_MOTIONBLUR = 0,
|
||||
FULLSCENE_BRIGHT,
|
||||
FULLSCENE_BLACK,
|
||||
// FULLSCENE_CONTRAST,
|
||||
FULLSCENE_EDGE,
|
||||
FULLSCENE_NEGATIVE,
|
||||
FULLSCENE_SEPIA,
|
||||
// FULLSCENE_SOLAR,
|
||||
FULLSCENE_EDGE2,
|
||||
FULLSCENE_EDGE3,
|
||||
FULLSCENE_SHARPEN,
|
||||
// FULLSCENE_LEVEL,
|
||||
FULLSCENE_SATURATION,
|
||||
FULLSCENE_SATURATION2,
|
||||
FULLSCENE_NUMS,
|
||||
};
|
||||
#define FULLSCENE_BLURTEXNUM 2
|
||||
#define FULLSCENE_BLURTEXSIZE 1024
|
||||
#define FULLSCENE_RENDERSIZE 1024
|
||||
|
||||
|
||||
class CFullSceneEffect
|
||||
{
|
||||
protected:
|
||||
LPDIRECT3DDEVICE8 m_pDevice;
|
||||
D3DCAPS8 m_pCaps;
|
||||
bool m_bPixelShader;
|
||||
|
||||
/* LPDIRECT3DTEXTURE8 m_pBlurTexture[FULLSCENE_BLURTEXNUM];
|
||||
LPDIRECT3DSURFACE8 m_pBlurTextureSurf[FULLSCENE_BLURTEXNUM];
|
||||
int m_iCurrentBlurTex;*/
|
||||
int m_iBlurTexUpdateFrame; // BlurTex Update <20><><EFBFBD><EFBFBD>
|
||||
int m_iBlurTexUpdateCount;
|
||||
|
||||
|
||||
/*LPDIRECT3DTEXTURE8 m_pRenderTexture;
|
||||
LPDIRECT3DSURFACE8 m_pRenderTextureSurface;
|
||||
*/
|
||||
LPDIRECT3DTEXTURE8 m_pRenderTexture[FULLSCENE_BLURTEXNUM + 1];
|
||||
LPDIRECT3DSURFACE8 m_pRenderTextureSurface[FULLSCENE_BLURTEXNUM + 1];
|
||||
int m_iCurrentTextureNum;
|
||||
int m_iMaxCountNum;
|
||||
|
||||
|
||||
|
||||
LPDIRECT3DSURFACE8 m_pRenderZSurface;
|
||||
|
||||
LPDIRECT3DSURFACE8 m_pFrameBuffer;
|
||||
LPDIRECT3DSURFACE8 m_pFrameZBuffer;
|
||||
bool m_bFlag[FULLSCENE_NUMS];
|
||||
bool m_bLockFlag[FULLSCENE_NUMS];
|
||||
D3DVIEWPORT8 m_FrameViewport;
|
||||
D3DVIEWPORT8 m_RenderViewport;
|
||||
D3DVIEWPORT8 m_ClearViewport;
|
||||
|
||||
int m_iFrameWidth;
|
||||
int m_iFrameHeight;
|
||||
|
||||
int m_iRenderWidth;
|
||||
int m_iRenderHeight;
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
|
||||
|
||||
std::vector<CFullSceneShader *> m_lstEffects;
|
||||
int m_iBlurFirstUpdate;
|
||||
bool m_bFullSceneEffect;
|
||||
|
||||
public:
|
||||
CFullSceneEffect();
|
||||
virtual ~CFullSceneEffect();
|
||||
|
||||
void Init(LPDIRECT3DDEVICE8 lpDevice);
|
||||
|
||||
void CreateVertexBuffer();
|
||||
|
||||
HRESULT BeginRender(DWORD dwClearColor);
|
||||
HRESULT EndRender();
|
||||
void Render(int i = 0);
|
||||
void Update();
|
||||
|
||||
void SetFlag(int i,bool bFlag) {
|
||||
if(!m_bLockFlag[i]) // lock <20>Ȱɷ<C8B0><C9B7>־<EFBFBD><D6BE><EFBFBD> <20><><EFBFBD>۰<EFBFBD><DBB0><EFBFBD>
|
||||
m_bFlag[i] = bFlag;
|
||||
|
||||
}
|
||||
bool GetFlag(int i) {return m_bFlag[i];}
|
||||
|
||||
void SetLockFlag(int i,bool bFlag) { m_bLockFlag[i] = bFlag;}
|
||||
bool GetLockFlag(int i) { return m_bLockFlag[i];}
|
||||
|
||||
void SetBlurUpdateFrame(int iFrame) { m_iBlurTexUpdateFrame = iFrame;}
|
||||
bool GetEnable() { return m_bFullSceneEffect;}
|
||||
|
||||
int GetRenderWidth() { return m_iRenderWidth;}
|
||||
int GetRenderHeight() { return m_iRenderHeight;}
|
||||
|
||||
VOID SetFullSceneEffectEnable( bool bFullScene ) { m_bFullSceneEffect = bFullScene ; }
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_FULLSCENEEFFECT_H__3E5DCE3F_4B17_40D9_A830_FCE7E55D490A__INCLUDED_)
|
||||
21
Engine/Zalla3D Scene Class/FullSceneGrayShader.h
Normal file
21
Engine/Zalla3D Scene Class/FullSceneGrayShader.h
Normal file
@@ -0,0 +1,21 @@
|
||||
// FullSceneGrayShader.h: interface for the CFullSceneGrayShader class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_FULLSCENEGRAYSHADER_H__5B043856_B726_45B8_9F8E_7807E9C4803C__INCLUDED_)
|
||||
#define AFX_FULLSCENEGRAYSHADER_H__5B043856_B726_45B8_9F8E_7807E9C4803C__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
#include "ShaderScene.h"
|
||||
|
||||
class CFullSceneGrayShader : public CShaderScene
|
||||
{
|
||||
public:
|
||||
CFullSceneGrayShader();
|
||||
virtual ~CFullSceneGrayShader();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_FULLSCENEGRAYSHADER_H__5B043856_B726_45B8_9F8E_7807E9C4803C__INCLUDED_)
|
||||
274
Engine/Zalla3D Scene Class/FullScenePShader.cpp
Normal file
274
Engine/Zalla3D Scene Class/FullScenePShader.cpp
Normal file
@@ -0,0 +1,274 @@
|
||||
// FullScenePShader.cpp: implementation of the CFullScenePShader class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "FullScenePShader.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
char Brightness[] =
|
||||
"ps.1.1\n"
|
||||
"tex t0\n"
|
||||
"add r0, t0, c0\n";
|
||||
|
||||
char Black[] =
|
||||
"ps.1.1\n"
|
||||
"tex t0\n"
|
||||
"dp3 r0, t0, c0\n"
|
||||
"mov r0.a, c2.a\n";
|
||||
|
||||
char Edges[] =
|
||||
"ps.1.1\n"
|
||||
"tex t0\n"
|
||||
"tex t1\n"
|
||||
"tex t2\n"
|
||||
"mov_x2 r0, t0\n"
|
||||
"sub r0, r0, t1\n"
|
||||
"sub_x2 r0, r0, t2\n";
|
||||
|
||||
char Negative[] =
|
||||
"ps.1.1\n"
|
||||
"tex t0\n"
|
||||
"mov r0, 1-t0\n"
|
||||
"mov r0.a, c2.a\n";
|
||||
|
||||
char Sepia[] =
|
||||
"ps.1.1\n"
|
||||
"def c1, 0.3, 0.6, 0.1, 1.0\n"
|
||||
"def c2, 0.9, 0.7, 0.3, 1.0\n"
|
||||
"def c3, 0.5, 0.5, 0.5, 1.0\n"
|
||||
"tex t0\n"
|
||||
"dp3 r0, t0, c1\n"
|
||||
"mul r0, r0, c2\n"
|
||||
"mov r0.a, c2.a\n";
|
||||
|
||||
char Edge2[] =
|
||||
"ps.1.1\n"
|
||||
"def c1, 0.3f, 0.59f, 0.11f, 0.0f\n"
|
||||
"def c4, 1.0f, 1.0f, 1.0f, 1.0f\n"
|
||||
"tex t0\n"
|
||||
"tex t1\n"
|
||||
"tex t2\n"
|
||||
"tex t3\n"
|
||||
"dp3 r0.rgba, t0, c1\n" // convert t0 color to luminance, store in r0.a
|
||||
"dp3 r1.rgba, t2, c1\n" // convert t2 color to luminance, store in r1.a
|
||||
"dp3 r0.rgb, t1, c1\n" // convert t1 color to luminance, store in r0.rgb
|
||||
"dp3 r1.rgb, t3, c1\n" // convert t3 color to luminance, store in r1.rgb
|
||||
"sub_x4 r0, r0, r1\n" // take both differences (and keep oversaturating the colors)
|
||||
"mul_x4 r0, r0, r0\n" // square both differences (instead of abs())
|
||||
"sub_sat r0.rgb, 1-r0, r0.a\n" // invert and add the 2 components:
|
||||
"mul r0, r0, c4\n";
|
||||
|
||||
char Edge3[] =
|
||||
"ps.1.1\n"
|
||||
"def c1, 0.3f, 0.59f, 0.11f, 0.0f\n"
|
||||
"tex t0\n"
|
||||
"tex t1\n"
|
||||
"tex t2\n"
|
||||
"tex t3\n"
|
||||
"dp3 r0.rgba, t0, c1\n" // convert t0 color to luminance, store in r0.a
|
||||
"dp3 r1.rgba, t2, c1\n" // convert t2 color to luminance, store in r1.a
|
||||
"dp3 r0.rgb, t1, c1\n" // convert t1 color to luminance, store in r0.rgb
|
||||
"dp3 r1.rgb, t3, c1\n" // convert t3 color to luminance, store in r1.rgb
|
||||
"sub_x4 r0, r0, r1\n" // take both differences (and keep oversaturating the colors)
|
||||
"mul_x2 r0, r0, r0\n" // square both differences (instead of abs())
|
||||
"sub_sat r0, 1-r0, r0.a\n" // invert and add the 2 components:
|
||||
"mul_x2_sat r0, r0, r1\n"; // and multiply with luminance for final result
|
||||
|
||||
char Sharpen[] =
|
||||
"ps.1.1\n"
|
||||
"tex t0\n" // this is the center sample
|
||||
"tex t1\n"
|
||||
"tex t2\n"
|
||||
"tex t3\n"
|
||||
"mov r0, t0\n"
|
||||
"sub r0, r0, t1\n"
|
||||
"add r0, r0, t0\n"
|
||||
"sub r0, r0, t2\n"
|
||||
"add r0, r0, t0\n"
|
||||
"sub r0, r0, t3\n"
|
||||
"add_sat r0, r0, t0\n"
|
||||
"mov r0.a, c2.a\n";
|
||||
|
||||
char saturation[] =
|
||||
"ps.1.1\n"
|
||||
"def c1, 0.2125, 0.7154, 0.0721, 0.0\n"
|
||||
"def c2, 1.0, 0.0, 0.0, 0.4\n"
|
||||
"def c4, 0.8, 0.8, 0.8, 1.0\n"
|
||||
"tex t0\n"
|
||||
"dp3 r1, t0, c1\n"
|
||||
"sub r0, t0, r1\n"
|
||||
"mad_sat r0, r0, c2.wwww, r1\n"
|
||||
"sub r0, r0, c3\n"
|
||||
"mul r1, r0, c4\n"
|
||||
"add r0, r0, r1\n"
|
||||
"add r0, r0, c3\n"
|
||||
"mov r0.a, c4.a\n";
|
||||
|
||||
char saturation2[] =
|
||||
"ps.1.1\n"
|
||||
"def c1, 0.2125, 0.7154, 0.0721, 0.0\n"
|
||||
"def c2, 1.0, 0.0, 0.0, 0.4\n"
|
||||
"def c4, 0.8, 0.8, 0.8, 1.0\n"
|
||||
"tex t0\n"
|
||||
"dp3 r1, t0, c1\n"
|
||||
"sub r0, t0, r1\n"
|
||||
"mad_sat r0, r0, c2.wwww, r1\n"
|
||||
"sub r0, r0, c3\n"
|
||||
"mul r1, r0, c4\n"
|
||||
"add r0, r0, r1\n"
|
||||
"add r0, r0, c3\n"
|
||||
"mov r0.a, c4.a\n";
|
||||
|
||||
|
||||
CFullScenePShader::CFullScenePShader(char *strFileName)
|
||||
{
|
||||
memset(m_strName,0,sizeof(char) * 256);
|
||||
strcpy(m_strName,strFileName);
|
||||
/*
|
||||
char strTmp[256] = {0};
|
||||
|
||||
sprintf(strTmp,"%s%s",SHADERFILEPATH,strFileName);*/
|
||||
if(strstr("Brightness",strFileName))
|
||||
CreatePixelShaderFromBuffer(Brightness);
|
||||
if(strstr("Black",strFileName))
|
||||
CreatePixelShaderFromBuffer(Black);
|
||||
if(strstr("Edges",strFileName))
|
||||
CreatePixelShaderFromBuffer(Edges);
|
||||
if(strstr("Negative",strFileName))
|
||||
CreatePixelShaderFromBuffer(Negative);
|
||||
if(strstr("Sepia",strFileName))
|
||||
CreatePixelShaderFromBuffer(Sepia);
|
||||
if(strstr("Edge2",strFileName))
|
||||
CreatePixelShaderFromBuffer(Edge2);
|
||||
if(strstr("Edge3",strFileName))
|
||||
CreatePixelShaderFromBuffer(Edge3);
|
||||
if(strstr("Sharpen",strFileName))
|
||||
CreatePixelShaderFromBuffer(Sharpen);
|
||||
if(strstr("saturation",strFileName))
|
||||
CreatePixelShaderFromBuffer(saturation);
|
||||
if(strstr("saturation2",strFileName))
|
||||
CreatePixelShaderFromBuffer(saturation);
|
||||
|
||||
}
|
||||
|
||||
CFullScenePShader::~CFullScenePShader()
|
||||
{
|
||||
|
||||
}
|
||||
void CFullScenePShader::Apply()
|
||||
{
|
||||
CSceneManager::GetDevice()->SetPixelShader(m_dwPixelShader);
|
||||
SetupPixelShaderConstants(0);
|
||||
|
||||
}
|
||||
void CFullScenePShader::Apply(int i)
|
||||
{
|
||||
CSceneManager::GetDevice()->SetPixelShader(m_dwPixelShader);
|
||||
SetupPixelShaderConstants(1);
|
||||
|
||||
}
|
||||
void CFullScenePShader::SetupPixelShaderConstants(int i)
|
||||
{
|
||||
|
||||
|
||||
|
||||
// For Bright,Contrast
|
||||
if(strstr(m_strName,"Brightness")) {
|
||||
float fDelta = 0.3f;
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(0, &D3DXVECTOR4(fDelta,fDelta,fDelta, 1.0f),1);
|
||||
}
|
||||
/*
|
||||
if(strstr(m_strName,"Contrast.psh")) {
|
||||
//float Delta = 0.2f;
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(0, &D3DXVECTOR4(-CSceneManager::m_vecLifeColor.x, -CSceneManager::m_vecLifeColor.x, -CSceneManager::m_vecLifeColor.x, 1.0f),1);
|
||||
}*/
|
||||
if(strstr(m_strName,"Black")) {
|
||||
/*D3DXVECTOR3 vecColor(1.0f,1.0f,1.0f);
|
||||
|
||||
vecColor.x = CSceneManager::m_vecLifeColor.x * 0.5f;
|
||||
vecColor.y = CSceneManager::m_vecLifeColor.y;
|
||||
vecColor.z = CSceneManager::m_vecLifeColor.z * 0.16f;
|
||||
|
||||
|
||||
if(vecColor.x > 1.0f) vecColor.x = 1.0f;
|
||||
if(vecColor.y > 1.0f) vecColor.y = 1.0f;
|
||||
if(vecColor.z > 1.0f) vecColor.z = 1.0f;
|
||||
|
||||
if(vecColor.x < 0.0f) vecColor.x = 0.0f;
|
||||
if(vecColor.y < 0.0f) vecColor.y = 0.0f;
|
||||
if(vecColor.z < 0.0f) vecColor.z = 0.0f;
|
||||
*/
|
||||
D3DXVECTOR3 vecColor(0.5f,1.0f,0.16f);
|
||||
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(0, &D3DXVECTOR4(vecColor.x, vecColor.y, vecColor.z, 1.0f),1);
|
||||
}
|
||||
/**/
|
||||
if(i == 1) //Blur Image <20><> RGB -> Sepia
|
||||
{
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(2, &D3DXVECTOR4(0.9f, 0.7f, 0.3f,0.4f),1);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(2, &D3DXVECTOR4(0.9f, 0.7f, 0.3f,1.0f),1);
|
||||
}
|
||||
/* if(strstr(m_strName,"Edge3.psh")) {
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(1, &D3DXVECTOR4(0.3f, 0.59f, 0.11f, 0.0f ),1);
|
||||
}*/
|
||||
/*
|
||||
if(strstr(m_strName,"Levels")) {
|
||||
D3DXVECTOR3 vecColor(1.0f,1.0f,1.0f);
|
||||
vecColor.x = CSceneManager::m_vecLifeColor.x * 0.5f;
|
||||
vecColor.y = CSceneManager::m_vecLifeColor.y;
|
||||
vecColor.z = CSceneManager::m_vecLifeColor.z * 0.16f;
|
||||
|
||||
if(vecColor.x > 1.0f) vecColor.x = 1.0f;
|
||||
if(vecColor.y > 1.0f) vecColor.y = 1.0f;
|
||||
if(vecColor.z > 1.0f) vecColor.z = 1.0f;
|
||||
|
||||
if(vecColor.x < 0.0f) vecColor.x = 0.0f;
|
||||
if(vecColor.y < 0.0f) vecColor.y = 0.0f;
|
||||
if(vecColor.z < 0.0f) vecColor.z = 0.0f;
|
||||
|
||||
|
||||
|
||||
//float Delta = 0.2f;
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(1, &D3DXVECTOR4(vecColor.y,0.0f,0.0f,0.0f),1);
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(2, &D3DXVECTOR4(0.0f,vecColor.y,0.0f,0.0f),1);
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(3, &D3DXVECTOR4(0.0f,0.0f,vecColor.y,0.0f),1);
|
||||
}*/
|
||||
|
||||
if(strstr(m_strName,"saturation")) {
|
||||
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(1, &D3DXVECTOR4(0.2125f, 0.7154f, 0.0721f, 0.0f),1);
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(2, &D3DXVECTOR4(1.0f, 0.5f, 0.8f, 0.4f),1);
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(3, &D3DXVECTOR4(0.5f, 0.5f, 0.5f, 1.0f),1);
|
||||
if(i == 1)
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(4, &D3DXVECTOR4(0.8f,0.8f,0.8f,0.4f),1);
|
||||
else
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(4, &D3DXVECTOR4(0.8f,0.8f,0.8f,1.0f),1);
|
||||
|
||||
}
|
||||
if(strstr(m_strName,"saturation2")) {
|
||||
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(1, &D3DXVECTOR4(0.2125f, 0.7154f, 0.0721f, 0.0f),1);
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(2, &D3DXVECTOR4(1.0f, 0.5f, 0.8f, (CSceneManager::m_fLife * 3.0f/1.0f)),1);
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(3, &D3DXVECTOR4(0.5f, 0.5f, 0.5f, 1.0f),1);
|
||||
if(i == 1)
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(4, &D3DXVECTOR4(0.0f,0.0f,0.0f,0.4f),1);
|
||||
else
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(4, &D3DXVECTOR4(0.0f,0.0f,0.0f,1.0f),1);
|
||||
|
||||
}
|
||||
if(strstr(m_strName,"Edge2")) {
|
||||
if(i == 0)
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(4, &D3DXVECTOR4(1.0f, 1.0f, 1.0f,1.0f),1);
|
||||
else
|
||||
CSceneManager::GetDevice()->SetPixelShaderConstant(4, &D3DXVECTOR4(1.0f, 1.0f, 1.0f,0.4f),1);
|
||||
}
|
||||
}
|
||||
30
Engine/Zalla3D Scene Class/FullScenePShader.h
Normal file
30
Engine/Zalla3D Scene Class/FullScenePShader.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// FullScenePShader.h: interface for the CFullScenePShader class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_FULLSCENEPSHADER_H__C0DFAFF9_A1C0_47DF_8E6B_3E2112AFD22E__INCLUDED_)
|
||||
#define AFX_FULLSCENEPSHADER_H__C0DFAFF9_A1C0_47DF_8E6B_3E2112AFD22E__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "ShaderScene.h"
|
||||
|
||||
class CFullScenePShader : public CPixelShader
|
||||
{
|
||||
public:
|
||||
CFullScenePShader(char *);
|
||||
virtual ~CFullScenePShader();
|
||||
virtual void Apply();
|
||||
void Apply(int i);
|
||||
|
||||
protected:
|
||||
virtual void SetupPixelShaderConstants(){}
|
||||
void SetupPixelShaderConstants(int i);
|
||||
char m_strName[256];
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_FULLSCENEPSHADER_H__C0DFAFF9_A1C0_47DF_8E6B_3E2112AFD22E__INCLUDED_)
|
||||
45
Engine/Zalla3D Scene Class/FullSceneShader.cpp
Normal file
45
Engine/Zalla3D Scene Class/FullSceneShader.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// FullSceneShader.cpp: implementation of the CFullSceneShader class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "FullSceneShader.h"
|
||||
#include "FullScenePShader.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CFullSceneShader::CFullSceneShader(char *strFileName)
|
||||
{
|
||||
|
||||
m_pPixelShader = new CFullScenePShader(strFileName);
|
||||
|
||||
}
|
||||
|
||||
CFullSceneShader::~CFullSceneShader()
|
||||
{
|
||||
if(m_pPixelShader)
|
||||
{
|
||||
delete m_pPixelShader;
|
||||
m_pPixelShader = NULL;
|
||||
|
||||
}
|
||||
}
|
||||
void CFullSceneShader::Apply()
|
||||
{
|
||||
if(m_pPixelShader)
|
||||
m_pPixelShader->Apply();
|
||||
|
||||
}
|
||||
void CFullSceneShader::Apply(int i)
|
||||
{
|
||||
if(m_pPixelShader)
|
||||
m_pPixelShader->Apply(i);
|
||||
|
||||
}
|
||||
void CFullSceneShader::UnApply()
|
||||
{
|
||||
CSceneManager::GetDevice()->SetPixelShader(0);
|
||||
}
|
||||
30
Engine/Zalla3D Scene Class/FullSceneShader.h
Normal file
30
Engine/Zalla3D Scene Class/FullSceneShader.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// FullSceneShader.h: interface for the CFullSceneShader class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_FULLSCENESHADER_H__FD09FAF4_5266_40CD_88BA_A291AFDC848F__INCLUDED_)
|
||||
#define AFX_FULLSCENESHADER_H__FD09FAF4_5266_40CD_88BA_A291AFDC848F__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "ShaderScene.h"
|
||||
|
||||
class CFullScenePShader;
|
||||
class CFullSceneShader : public CShaderScene
|
||||
{
|
||||
public:
|
||||
CFullSceneShader(char *strFileName);
|
||||
virtual ~CFullSceneShader();
|
||||
virtual void Apply();
|
||||
void Apply(int i);
|
||||
virtual void UnApply();
|
||||
protected:
|
||||
CFullScenePShader *m_pPixelShader;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_FULLSCENESHADER_H__FD09FAF4_5266_40CD_88BA_A291AFDC848F__INCLUDED_)
|
||||
278
Engine/Zalla3D Scene Class/GrassManager.cpp
Normal file
278
Engine/Zalla3D Scene Class/GrassManager.cpp
Normal file
@@ -0,0 +1,278 @@
|
||||
// GrassManager.cpp: implementation of the CGrassManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "GrassManager.h"
|
||||
#include "SceneManager.h"
|
||||
#include "RenderOption.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CGrassManager::CGrassManager()
|
||||
{
|
||||
if(CRenderOption::m_GrassRendering && CRenderOption::m_GrassAnimationUseVertexShader)
|
||||
{
|
||||
float fAdder=(3.14159f*2.0f)/20.0f;
|
||||
for(int i=0;i<20;i++)
|
||||
{
|
||||
m_fGrassRot[i]=fAdder*i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CGrassManager::~CGrassManager()
|
||||
{
|
||||
if(m_pGrassNode != NULL)
|
||||
{
|
||||
delete[] m_pGrassNode;
|
||||
m_pGrassNode = NULL;
|
||||
}
|
||||
}
|
||||
void CGrassManager::Delete()
|
||||
{
|
||||
if(m_pGrassNode) {
|
||||
for(int i=0;i<MAX_GRASSRANGE*MAX_GRASSRANGE;i++) {
|
||||
|
||||
m_pGrassNode[i].UnloadData();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void CGrassManager::Create()
|
||||
{
|
||||
if(CRenderOption::m_GrassRendering)
|
||||
{
|
||||
MAX_GRASSRANGE=CRenderOption::m_GrassRenderRange;
|
||||
|
||||
m_pGrassNode=new CGrassScene[MAX_GRASSRANGE*MAX_GRASSRANGE];
|
||||
for(int i=0;i<MAX_GRASSRANGE*MAX_GRASSRANGE;i++)
|
||||
{
|
||||
m_pGrassNode[i].Create();
|
||||
}
|
||||
|
||||
m_NowPositionX=0;
|
||||
m_NowPositionY=0;
|
||||
for(int ix=-MAX_GRASSRANGE/2,cx=0;ix<MAX_GRASSRANGE/2;ix++,cx++)
|
||||
{
|
||||
for(int iy=-MAX_GRASSRANGE/2,cy=0;iy<MAX_GRASSRANGE/2;iy++,cy++)
|
||||
{
|
||||
m_pGrassNode[cx+cy*MAX_GRASSRANGE].Generate(
|
||||
ix*LINTERVAL,
|
||||
iy*LINTERVAL,10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGrassManager::UpdateRange()
|
||||
{
|
||||
if(CRenderOption::m_GrassRendering)
|
||||
{
|
||||
vector3 *ViewPos;
|
||||
vector3 CharPos;
|
||||
if(CSceneManager::m_ViewerMode==0 || CSceneManager::m_ViewerMode==2)
|
||||
ViewPos=CSceneManager::GetCamera()->GetPosition();
|
||||
else
|
||||
{
|
||||
CSceneManager::m_CharacterManager.m_CharacterList[0].m_pChrmodel->GetPosition(CharPos.x,CharPos.y,CharPos.z);
|
||||
ViewPos=&CharPos;
|
||||
}
|
||||
|
||||
int UpdatePositionX=(int)(ViewPos->x/LINTERVAL);
|
||||
int UpdatePositionY=(int)(ViewPos->z/LINTERVAL);
|
||||
|
||||
if( m_NowPositionX == UpdatePositionX &&
|
||||
m_NowPositionY == UpdatePositionY) return;
|
||||
|
||||
int WillX=(int)(ViewPos->x/LINTERVAL);
|
||||
int WillY=(int)(ViewPos->z/LINTERVAL);
|
||||
int MoveX=m_NowPositionX-WillX;
|
||||
int MoveY=m_NowPositionY-WillY;
|
||||
|
||||
int *UpdateGrass=new int[MAX_GRASSRANGE*MAX_GRASSRANGE];
|
||||
int *NotUpdateGrass=new int[MAX_GRASSRANGE*MAX_GRASSRANGE];
|
||||
int CountUpdate=0;
|
||||
|
||||
memset(NotUpdateGrass,-1,sizeof(int)*MAX_GRASSRANGE*MAX_GRASSRANGE);
|
||||
|
||||
int fx,fy;
|
||||
int ix,iy;
|
||||
int grassx,grassy;
|
||||
|
||||
for(ix=0;ix<MAX_GRASSRANGE;ix++)
|
||||
{
|
||||
for(iy=0;iy<MAX_GRASSRANGE;iy++)
|
||||
{
|
||||
grassx=m_pGrassNode[ix+iy*MAX_GRASSRANGE].m_GrassPosX;
|
||||
grassy=m_pGrassNode[ix+iy*MAX_GRASSRANGE].m_GrassPosY;
|
||||
|
||||
if( (grassx >= WillX-(int)(MAX_GRASSRANGE/2.0f) && grassx <= WillX+(int)(MAX_GRASSRANGE/2)) &&
|
||||
(grassy >= WillY-(int)(MAX_GRASSRANGE/2.0f) && grassy <= WillY+(int)(MAX_GRASSRANGE/2)) )
|
||||
{
|
||||
fx=grassx-WillX+(int)(MAX_GRASSRANGE/2.0f);
|
||||
fy=grassy-WillY+(int)(MAX_GRASSRANGE/2.0f);
|
||||
if(NotUpdateGrass[fx+fy*MAX_GRASSRANGE]==0)
|
||||
{
|
||||
UpdateGrass[CountUpdate++]=ix+iy*MAX_GRASSRANGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
NotUpdateGrass[fx+fy*MAX_GRASSRANGE]=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
UpdateGrass[CountUpdate++]=ix+iy*MAX_GRASSRANGE;
|
||||
|
||||
}
|
||||
}
|
||||
if(CountUpdate!=MAX_GRASSRANGE*MAX_GRASSRANGE)
|
||||
{
|
||||
UpdateGrass[CountUpdate]=-1;
|
||||
}
|
||||
|
||||
int InnerCount=0;
|
||||
int CheckEndUpdate=0;
|
||||
for(ix=0;ix<MAX_GRASSRANGE;ix++)
|
||||
{
|
||||
for(iy=0;iy<MAX_GRASSRANGE;iy++)
|
||||
{
|
||||
if(NotUpdateGrass[ix+iy*MAX_GRASSRANGE]==-1)
|
||||
{
|
||||
CheckEndUpdate=UpdateGrass[InnerCount++];
|
||||
if(CheckEndUpdate==-1)
|
||||
break;
|
||||
m_pGrassNode[CheckEndUpdate].m_GrassPosX=(ix+WillX-(int)(MAX_GRASSRANGE/2.0f));
|
||||
m_pGrassNode[CheckEndUpdate].m_GrassPosY=(iy+WillY-(int)(MAX_GRASSRANGE/2.0f));
|
||||
m_pGrassNode[CheckEndUpdate].Generate(
|
||||
(ix+WillX-(int)(MAX_GRASSRANGE/2.0f))*LINTERVAL,
|
||||
(iy+WillY-(int)(MAX_GRASSRANGE/2.0f))*LINTERVAL,30);
|
||||
}
|
||||
|
||||
}
|
||||
if(CheckEndUpdate==-1)
|
||||
break;
|
||||
}
|
||||
m_NowPositionX=UpdatePositionX;
|
||||
m_NowPositionY=UpdatePositionY;
|
||||
if(UpdateGrass) {
|
||||
delete [] UpdateGrass;
|
||||
UpdateGrass = NULL;
|
||||
}
|
||||
if(NotUpdateGrass) {
|
||||
delete [] NotUpdateGrass;
|
||||
NotUpdateGrass = NULL;
|
||||
}
|
||||
}
|
||||
//*/
|
||||
|
||||
}
|
||||
|
||||
void CGrassManager::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
if(CRenderOption::m_GrassRendering) // Ǯ<><EFBFBD><D7B8><EFBFBD>
|
||||
{
|
||||
if(CRenderOption::m_GrassAnimationUseVertexShader)
|
||||
{
|
||||
for(int i=0;i<20;i++)
|
||||
{
|
||||
float frate=sinf(m_fGrassRot[i]);
|
||||
if(frate>0.98f)
|
||||
frate=0.98f;
|
||||
if(frate<-0.98f)
|
||||
frate=-0.98f;
|
||||
|
||||
vector3 vecRotAxis;
|
||||
vecRotAxis=vector3(1.0f,0.0f,0.0f);
|
||||
vecRotAxis.Normalize();
|
||||
matrix matRot;
|
||||
matRot.Rotation(vecRotAxis,frate*0.003f);
|
||||
//matRot.Rotation(vecRotAxis,frate);
|
||||
|
||||
float f=tan(0.003f)*(20000.0f+100.0f);
|
||||
|
||||
if(i==0)
|
||||
{
|
||||
matRot.MakeIdent();
|
||||
}
|
||||
|
||||
|
||||
matRot.Transpose();
|
||||
pd3dDevice->SetVertexShaderConstant(15+4*i,&matRot,4);
|
||||
}
|
||||
|
||||
}
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
//pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,TRUE);
|
||||
//
|
||||
|
||||
//pd3dDevice->SetRenderState( D3DRS_LIGHTING,TRUE);
|
||||
/*pd3dDevice->LightEnable(0,FALSE);
|
||||
pd3dDevice->LightEnable(1,FALSE);
|
||||
pd3dDevice->LightEnable(2,FALSE);
|
||||
pd3dDevice->LightEnable(3,FALSE);
|
||||
pd3dDevice->LightEnable(4,FALSE);
|
||||
pd3dDevice->LightEnable(5,FALSE);
|
||||
pd3dDevice->LightEnable(6,FALSE);
|
||||
pd3dDevice->LightEnable(7,FALSE); */
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_AMBIENT,CSceneManager::m_WeatherManager.m_InterFurGrassColor.c);
|
||||
//
|
||||
matrix matPos;
|
||||
matPos.MakeIdent();
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,matPos);
|
||||
for(int ix=0;ix<MAX_GRASSRANGE;ix++)
|
||||
{
|
||||
for(int iy=0;iy<MAX_GRASSRANGE;iy++)
|
||||
{
|
||||
m_pGrassNode[ix+iy*MAX_GRASSRANGE].Render(pd3dDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
//*/
|
||||
}
|
||||
|
||||
void CGrassManager::Update(float fUpdate)
|
||||
{
|
||||
//*
|
||||
if(CRenderOption::m_GrassRendering)
|
||||
{
|
||||
for(int i=0;i<20;i++)
|
||||
{
|
||||
m_fGrassRot[i]+=fUpdate;
|
||||
}
|
||||
for(int ix=0;ix<MAX_GRASSRANGE;ix++)
|
||||
{
|
||||
for(int iy=0;iy<MAX_GRASSRANGE;iy++)
|
||||
{
|
||||
m_pGrassNode[ix+iy*MAX_GRASSRANGE].Update(fUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
//*/
|
||||
}
|
||||
|
||||
void CGrassManager::RenderShadow(LPDIRECT3DDEVICE8 pd3dDevice,CRenderTexture &pShadowTexture)
|
||||
{
|
||||
if(CRenderOption::m_GrassRendering)
|
||||
{
|
||||
for(int ix=0;ix<MAX_GRASSRANGE;ix++)
|
||||
{
|
||||
for(int iy=0;iy<MAX_GRASSRANGE;iy++)
|
||||
{
|
||||
m_pGrassNode[ix+iy*MAX_GRASSRANGE].RenderShadow(pd3dDevice,pShadowTexture);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Engine/Zalla3D Scene Class/GrassManager.h
Normal file
32
Engine/Zalla3D Scene Class/GrassManager.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// GrassManager.h: interface for the CGrassManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_GRASSMANAGER_H__9CA4057F_447A_4203_876A_E6ACA7C47081__INCLUDED_)
|
||||
#define AFX_GRASSMANAGER_H__9CA4057F_447A_4203_876A_E6ACA7C47081__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "GrassScene.h"
|
||||
|
||||
class CGrassManager
|
||||
{
|
||||
CGrassScene *m_pGrassNode;
|
||||
int m_NowPositionX,m_NowPositionY;
|
||||
float m_fGrassRot[20];
|
||||
public:
|
||||
void RenderShadow(LPDIRECT3DDEVICE8 pd3dDevice,CRenderTexture &pShadowTexture);
|
||||
void Update(float fUpdate);
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void UpdateRange();
|
||||
void Create();
|
||||
CGrassManager();
|
||||
virtual ~CGrassManager();
|
||||
void Delete();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_GRASSMANAGER_H__9CA4057F_447A_4203_876A_E6ACA7C47081__INCLUDED_)
|
||||
2038
Engine/Zalla3D Scene Class/GrassScene.cpp
Normal file
2038
Engine/Zalla3D Scene Class/GrassScene.cpp
Normal file
File diff suppressed because it is too large
Load Diff
65
Engine/Zalla3D Scene Class/GrassScene.h
Normal file
65
Engine/Zalla3D Scene Class/GrassScene.h
Normal file
@@ -0,0 +1,65 @@
|
||||
// GrassScene.h: interface for the CGrassScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_GRASSSCENE_H__9CB57CBD_783D_427E_95F8_EB4C27501B03__INCLUDED_)
|
||||
#define AFX_GRASSSCENE_H__9CB57CBD_783D_427E_95F8_EB4C27501B03__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "MeshObject.h"
|
||||
|
||||
#include "SectorDefine.h"
|
||||
#include "SceneNode.h"
|
||||
#include "Vertex.h"
|
||||
#include "RenderTexture.h"
|
||||
|
||||
class GrassExtVertex
|
||||
{
|
||||
public:
|
||||
vector3 v;
|
||||
float fw0,fw1;
|
||||
float index0,index1;
|
||||
float tu,tv;
|
||||
float fColorRate;
|
||||
};
|
||||
|
||||
class CGrassScene : public CSceneNode
|
||||
{
|
||||
vector3 *m_vecGrassPos;
|
||||
unsigned char *m_GrassShadow;
|
||||
unsigned char *m_GrassKind;
|
||||
static CMeshObject *m_NormalGrass[5];
|
||||
int m_cGrassElement;
|
||||
vector3 m_MinBox,m_MaxBox;
|
||||
|
||||
float m_fGrassRot;
|
||||
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pGrassVertexBuffer;
|
||||
LPDIRECT3DINDEXBUFFER8 m_pGrassIndicesBuffer;
|
||||
|
||||
static DWORD m_dwGrassVertexShader;
|
||||
|
||||
DWORD m_dwAlphaFactor;
|
||||
DWORD m_dwAlphaUnit;
|
||||
DWORD m_dwLimit;
|
||||
|
||||
|
||||
public:
|
||||
void RenderShadow(LPDIRECT3DDEVICE8 pd3dDevice,CRenderTexture &pShadowTexture);
|
||||
static CTexture *m_NormalTexture;
|
||||
void Update(float fUpdate);
|
||||
int m_GrassPosX,m_GrassPosY;
|
||||
void Generate(float fx,float fz,int cGrassElement);
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void Create();
|
||||
void UpdateRange();
|
||||
CGrassScene();
|
||||
virtual ~CGrassScene();
|
||||
void UnloadData();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_GRASSSCENE_H__9CB57CBD_783D_427E_95F8_EB4C27501B03__INCLUDED_)
|
||||
458
Engine/Zalla3D Scene Class/H3DContainer.h
Normal file
458
Engine/Zalla3D Scene Class/H3DContainer.h
Normal file
@@ -0,0 +1,458 @@
|
||||
// H3DContainer.h: interface for the CH3DContainer class template.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_H3DCONTAINER_H__EFFCAF0D_E084_4326_8D7C_BD0CAF16EB34__INCLUDED_)
|
||||
#define AFX_H3DCONTAINER_H__EFFCAF0D_E084_4326_8D7C_BD0CAF16EB34__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
//#include "FunctionPerformanceCheck.h"
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#include "misc.h"
|
||||
|
||||
//#include <io.h>
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "Z3DStringTable.h"
|
||||
|
||||
|
||||
|
||||
/*namespace ppuchuu{
|
||||
template<class _key_t, class _data_t>
|
||||
class map
|
||||
{
|
||||
public:
|
||||
struct _element_t
|
||||
{
|
||||
_element_t( _key_t _k, _data_t _d )
|
||||
{
|
||||
first = _k;
|
||||
second = _d;
|
||||
}
|
||||
|
||||
_key_t first;
|
||||
_data_t second;
|
||||
};
|
||||
|
||||
typedef std::vector<_element_t>::iterator iterator;
|
||||
|
||||
map()
|
||||
{
|
||||
}
|
||||
|
||||
~map()
|
||||
{
|
||||
}
|
||||
|
||||
_data_t& operator []( _key_t &_k )
|
||||
{
|
||||
for(int i = 0; i < (int)m_vecActualData.size(); ++i )
|
||||
{
|
||||
if( _k == m_vecActualData[i].first )
|
||||
{
|
||||
return m_vecActualData[i].second;
|
||||
}
|
||||
}
|
||||
|
||||
_element_t _e( _k, _data_t() );
|
||||
m_vecActualData.push_back( _e );
|
||||
return m_vecActualData[m_vecActualData.size()-1].second;
|
||||
}
|
||||
|
||||
iterator find( _key_t &_k )
|
||||
{
|
||||
iterator it;
|
||||
for( it = m_vecActualData.begin(); it != m_vecActualData.end(); it++ )
|
||||
{
|
||||
if( _k == it->first )
|
||||
{
|
||||
return it;
|
||||
}
|
||||
}
|
||||
|
||||
return it;
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
return m_vecActualData.begin();
|
||||
}
|
||||
|
||||
iterator end()
|
||||
{
|
||||
return m_vecActualData.end();
|
||||
}
|
||||
|
||||
void erase( iterator it )
|
||||
{
|
||||
m_vecActualData.erase( it );
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<_element_t> m_vecActualData;
|
||||
|
||||
};
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// UID under Win32 file system...
|
||||
/*struct H3D_FILE_UID
|
||||
{
|
||||
public:
|
||||
H3D_FILE_UID( int i )
|
||||
{
|
||||
dwVolumeSerialNumber = 0UL;
|
||||
dwFileIndexHigh = 0UL;
|
||||
dwFileIndexLow = 0UL;
|
||||
}
|
||||
|
||||
H3D_FILE_UID()
|
||||
{
|
||||
}
|
||||
|
||||
bool operator == ( const H3D_FILE_UID &op ) const
|
||||
{
|
||||
return ( (dwVolumeSerialNumber == op.dwVolumeSerialNumber) &&
|
||||
(dwFileIndexHigh == op.dwFileIndexHigh) &&
|
||||
(dwFileIndexLow == op.dwFileIndexLow) );
|
||||
}
|
||||
|
||||
bool operator < ( const H3D_FILE_UID &op ) const
|
||||
{
|
||||
if( dwVolumeSerialNumber < op.dwVolumeSerialNumber )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( dwFileIndexHigh < op.dwFileIndexHigh )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( dwFileIndexLow < op.dwFileIndexLow )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD dwVolumeSerialNumber;
|
||||
DWORD dwFileIndexHigh;
|
||||
DWORD dwFileIndexLow;
|
||||
};*/
|
||||
|
||||
template<class _obj> class CH3DContainer;
|
||||
|
||||
template<class _obj>
|
||||
struct H3DContainerTag
|
||||
{
|
||||
friend class CH3DContainer<_obj>;
|
||||
|
||||
public:
|
||||
H3DContainerTag()
|
||||
{
|
||||
m_rpObject = NULL;
|
||||
//m_UIDFile = H3D_FILE_UID(0);
|
||||
m_UIDFile = NULL_TOK;
|
||||
m_rpContainer = NULL;
|
||||
}
|
||||
|
||||
_obj* GetObject()
|
||||
{
|
||||
return m_rpObject;
|
||||
}
|
||||
|
||||
bool Release()
|
||||
{
|
||||
bool bRet = true;
|
||||
|
||||
if( m_rpContainer )
|
||||
{
|
||||
bRet = m_rpContainer->Release( m_UIDFile );
|
||||
}
|
||||
|
||||
//m_UIDFile = H3D_FILE_UID(0);
|
||||
m_UIDFile = NULL_TOK;
|
||||
m_rpObject = NULL;
|
||||
m_rpContainer = NULL;
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
bool operator == ( const H3DContainerTag<_obj> &op )
|
||||
{
|
||||
return ( m_UIDFile == op.m_UIDFile );
|
||||
}
|
||||
|
||||
protected:
|
||||
_obj* m_rpObject;
|
||||
//H3D_FILE_UID m_UIDFile;
|
||||
Z3DTOK m_UIDFile;
|
||||
CH3DContainer<_obj>* m_rpContainer;
|
||||
};
|
||||
|
||||
template<class _obj>
|
||||
class CH3DContainer
|
||||
{
|
||||
friend struct H3DContainerTag<_obj>;
|
||||
|
||||
public:
|
||||
CH3DContainer()
|
||||
{
|
||||
m_szFilePath = NULL;
|
||||
}
|
||||
|
||||
~CH3DContainer();
|
||||
|
||||
void SetFilePath( const char* szPath );
|
||||
|
||||
bool GetObject( H3DContainerTag<_obj> &tag, const char* szFileName );
|
||||
|
||||
/*bool LoadHandleNameTable( const char* szFilename, const char* szPath = NULL )
|
||||
{
|
||||
// dummy function for intermediate compatibility
|
||||
SetFilePath( szPath );
|
||||
|
||||
return true;
|
||||
}*/
|
||||
|
||||
bool PreLoadAll( const char* szFileSpec );
|
||||
|
||||
void FlushAll();
|
||||
|
||||
protected:
|
||||
struct H3DContainerElement
|
||||
{
|
||||
int lRefCount;
|
||||
_obj* pObj;
|
||||
|
||||
H3DContainerElement()
|
||||
{
|
||||
lRefCount = 0;
|
||||
pObj = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
//bool Release( H3D_FILE_UID hf );
|
||||
bool Release( Z3DTOK hf );
|
||||
|
||||
char* m_szFilePath;
|
||||
std::map<Z3DTOK, H3DContainerElement> m_mapContainerElement;
|
||||
//std::map<H3D_FILE_UID, H3DContainerElement> m_mapContainerElement;
|
||||
//ppuchuu::map<H3D_FILE_UID, H3DContainerElement> m_mapContainerElement;
|
||||
};
|
||||
|
||||
|
||||
template<class _obj>
|
||||
void CH3DContainer<_obj>::SetFilePath( const char* szPath )
|
||||
{
|
||||
long lLen = strlen(szPath);
|
||||
if( 0 == lLen )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( szPath[lLen-1] != '\\' && szPath[lLen-1] != '/' )
|
||||
{
|
||||
++lLen;
|
||||
}
|
||||
|
||||
m_szFilePath = new char[lLen+1];
|
||||
strcpy( m_szFilePath, szPath );
|
||||
m_szFilePath[lLen-1] = '/';
|
||||
m_szFilePath[lLen] = '\0';
|
||||
}
|
||||
|
||||
|
||||
template<class _obj>
|
||||
bool CH3DContainer<_obj>::GetObject( H3DContainerTag<_obj> &tag, const char* szFileName )
|
||||
{
|
||||
//DeclareBlockTimingCheck( "before CreateFile", aa );
|
||||
//DeclareBlockTimingCheck( "CreateFile", bb );
|
||||
//DeclareBlockTimingCheck( "GetFileInformationByHandle", cc );
|
||||
//DeclareBlockTimingCheck( "CloseHandle", dd );
|
||||
|
||||
|
||||
if( NULL == szFileName )
|
||||
{
|
||||
//tag.m_UIDFile = H3D_FILE_UID(0);
|
||||
tag.m_UIDFile = NULL_TOK;
|
||||
tag.m_rpObject = NULL;
|
||||
tag.m_rpContainer = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD> file UID <20><> <20><><EFBFBD>´<EFBFBD>.
|
||||
//H3D_FILE_UID hfu;
|
||||
Z3DTOK hfu;
|
||||
|
||||
static char szFullPathName[MAX_PATH]; // full path <20>ۼ<EFBFBD>
|
||||
szFullPathName[0] = '\0';
|
||||
if( m_szFilePath )
|
||||
{
|
||||
strcpy( szFullPathName, m_szFilePath );
|
||||
}
|
||||
strcat( szFullPathName, szFileName );
|
||||
|
||||
/*HANDLE hFile = CreateFile( szFullPathName, GENERIC_READ, FILE_SHARE_READ,
|
||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );*/
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϰ<EFBFBD> <20>ϴ<EFBFBD> <20><>Ʈ<EFBFBD><C6AE><EFBFBD><EFBFBD><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><><EFBFBD>ϸ<EFBFBD><CFB8><EFBFBD> <20>߰<EFBFBD><DFB0>س<EFBFBD><D8B3>´<EFBFBD>.(<28><><EFBFBD>ϵ<EFBFBD> <20><><EFBFBD><EFBFBD> ã<>°<EFBFBD> <20>ƴ<EFBFBD>)
|
||||
hfu = g_TokFileName.Add( szFullPathName );
|
||||
|
||||
/*if( INVALID_HANDLE_VALUE == hFile )
|
||||
{
|
||||
//tag.m_UIDFile = H3D_FILE_UID(0);
|
||||
tag.m_UIDFile = NULL_TOK;
|
||||
tag.m_rpObject = NULL;
|
||||
tag.m_rpContainer = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
BY_HANDLE_FILE_INFORMATION hfi;
|
||||
if( 0 == GetFileInformationByHandle( hFile, &hfi ) )
|
||||
{
|
||||
CloseHandle( hFile );
|
||||
|
||||
//tag.m_UIDFile = H3D_FILE_UID(0);
|
||||
tag.m_UIDFile = NULL_TOK;
|
||||
tag.m_rpObject = NULL;
|
||||
tag.m_rpContainer = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
hfu.dwVolumeSerialNumber = hfi.dwVolumeSerialNumber;
|
||||
hfu.dwFileIndexHigh = hfi.nFileIndexHigh;
|
||||
hfu.dwFileIndexLow = hfi.nFileIndexLow;
|
||||
CloseHandle( hFile );*/
|
||||
|
||||
// map<61><70><EFBFBD><EFBFBD> file UID<49><44> Ű<><C5B0> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD>
|
||||
H3DContainerElement celem = m_mapContainerElement[hfu];
|
||||
if( NULL == celem.pObj )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD> <20><> -> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̹Ƿ<CCB9> <20>ε<EFBFBD>.
|
||||
celem.pObj = new _obj;
|
||||
if( false == celem.pObj->Load( szFullPathName ) )
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD> <20>ε<EFBFBD> <20><><EFBFBD>н<EFBFBD>
|
||||
//tag.m_UIDFile = H3D_FILE_UID(0);
|
||||
SAFE_DELETE( celem.pObj );
|
||||
|
||||
tag.m_UIDFile = NULL_TOK;
|
||||
tag.m_rpObject = NULL;
|
||||
tag.m_rpContainer = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
++celem.lRefCount;
|
||||
m_mapContainerElement[hfu] = celem;
|
||||
|
||||
tag.m_rpObject = celem.pObj;
|
||||
tag.m_UIDFile = hfu;
|
||||
tag.m_rpContainer = this;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class _obj>
|
||||
//bool CH3DContainer<_obj>::Release( H3D_FILE_UID hf )
|
||||
bool CH3DContainer<_obj>::Release( Z3DTOK hf )
|
||||
{
|
||||
std::map<Z3DTOK, H3DContainerElement>::iterator it;
|
||||
//std::map<H3D_FILE_UID, H3DContainerElement>::iterator it;
|
||||
//ppuchuu::map<H3D_FILE_UID, H3DContainerElement>::iterator it;
|
||||
|
||||
it = m_mapContainerElement.find( hf );
|
||||
if( m_mapContainerElement.end() == it )
|
||||
{
|
||||
return false; // no proper handle
|
||||
}
|
||||
|
||||
--(it->second.lRefCount);
|
||||
if( 0 == it->second.lRefCount )
|
||||
{
|
||||
SAFE_DELETE( it->second.pObj );
|
||||
m_mapContainerElement.erase( it );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class _obj>
|
||||
CH3DContainer<_obj>::~CH3DContainer()
|
||||
{
|
||||
SAFE_DELETEA( m_szFilePath );
|
||||
|
||||
FlushAll();
|
||||
}
|
||||
|
||||
|
||||
template<class _obj>
|
||||
void CH3DContainer<_obj>::FlushAll()
|
||||
{
|
||||
std::map<Z3DTOK, H3DContainerElement>::iterator it;
|
||||
//std::map<H3D_FILE_UID, H3DContainerElement>::iterator it;
|
||||
//ppuchuu::map<H3D_FILE_UID, H3DContainerElement>::iterator it;
|
||||
|
||||
for( it = m_mapContainerElement.begin(); it != m_mapContainerElement.end(); it++ )
|
||||
{
|
||||
SAFE_DELETE( it->second.pObj );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class _obj>
|
||||
bool CH3DContainer<_obj>::PreLoadAll( const char* szFileSpec )
|
||||
{
|
||||
SimpleString strFullPath( m_szFilePath, szFileSpec );
|
||||
char* szFileNamePart;
|
||||
H3DContainerTag<_obj> tag;
|
||||
|
||||
|
||||
_finddata_t fileinfo;
|
||||
long lFindHandle = _findfirst( strFullPath, &fileinfo );
|
||||
|
||||
if( -1 == lFindHandle )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
szFileNamePart = strrchr( fileinfo.name, '\\' );
|
||||
if( NULL == szFileNamePart )
|
||||
{
|
||||
szFileNamePart = fileinfo.name;
|
||||
}
|
||||
else
|
||||
{
|
||||
++szFileNamePart;
|
||||
}
|
||||
|
||||
GetObject( tag, szFileNamePart );
|
||||
|
||||
} while( 0 == _findnext( lFindHandle, &fileinfo ) );
|
||||
|
||||
_findclose( lFindHandle );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif // !defined(AFX_H3DCONTAINER_H__EFFCAF0D_E084_4326_8D7C_BD0CAF16EB34__INCLUDED_)
|
||||
193
Engine/Zalla3D Scene Class/H3DOutfitTable.cpp
Normal file
193
Engine/Zalla3D Scene Class/H3DOutfitTable.cpp
Normal file
@@ -0,0 +1,193 @@
|
||||
// H3DOutfitTable.cpp: implementation of the CH3DOutfitTable class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "H3DOutfitTable.h"
|
||||
#include "SimpleParser.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CH3DOutfitTable::CH3DOutfitTable()
|
||||
{
|
||||
}
|
||||
|
||||
CH3DOutfitTable::~CH3DOutfitTable()
|
||||
{
|
||||
std::map<char*, H3DOutfitElement, szi_less>::iterator it;
|
||||
|
||||
for( it = m_mapName2Outfit.begin(); it != m_mapName2Outfit.end(); it++ )
|
||||
{
|
||||
it->second.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool CH3DOutfitTable::Load( const char* szFileName )
|
||||
{
|
||||
CSimpleParser parser;
|
||||
|
||||
if( false == parser.OpenFile( szFileName ) )
|
||||
{
|
||||
return false; // file open failed
|
||||
}
|
||||
|
||||
int i;
|
||||
|
||||
char* szToken;
|
||||
char* szTmp;
|
||||
|
||||
char szItemName[260];
|
||||
std::vector<char*> vec_szMeshName;
|
||||
std::vector<char*> vec_szTexName;
|
||||
long lState = 0;
|
||||
/* lState -
|
||||
0 : item name read mode
|
||||
1 : Mesh name read mode
|
||||
2 : Tex name read mode
|
||||
3 : Set item name read mode */
|
||||
H3DOutfitElement oel;
|
||||
while( (szToken = parser.GetNextToken()) != NULL )
|
||||
{
|
||||
switch( lState )
|
||||
{
|
||||
case 0:
|
||||
if( 0 == stricmp( szToken, "Mesh" ) )
|
||||
{
|
||||
// Mesh name read mode <20><> <20><>ȯ
|
||||
lState = 1;
|
||||
}
|
||||
else if( 0 == stricmp( szToken, "Tex" ) )
|
||||
{
|
||||
// Tex name read mode <20><> <20><>ȯ
|
||||
lState = 2;
|
||||
}
|
||||
else if( 0 == stricmp( szToken, "Set" ) )
|
||||
{
|
||||
// Set item name read mode <20><> <20><>ȯ
|
||||
lState = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
// <20>̵<EFBFBD><CCB5><EFBFBD><EFBFBD><EFBFBD> <20>ƴϸ<C6B4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD> <20>б<EFBFBD><D0B1><EFBFBD>.
|
||||
strcpy( szItemName, szToken ); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD> <20>ش<EFBFBD><D8B4>ϴ<EFBFBD> <20><><EFBFBD>ڿ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if( 0 == stricmp( szToken, ";" ) )
|
||||
{
|
||||
// Mesh name read mode<64><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// outfit element <20><> mesh <20>ʵ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
|
||||
oel.lMeshCount = vec_szMeshName.size();
|
||||
oel.pszMeshName = new char*[vec_szMeshName.size()];
|
||||
for( i = 0; i < (int)vec_szMeshName.size(); ++i )
|
||||
{
|
||||
oel.pszMeshName[i] = vec_szMeshName[i];
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><>ȯ
|
||||
lState = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// mesh name<6D><65> <20>ӽ<EFBFBD> vector<6F><72> <20><><EFBFBD><EFBFBD>
|
||||
szTmp = new char[strlen(szToken)+1];
|
||||
strcpy( szTmp, szToken );
|
||||
vec_szMeshName.push_back( szTmp );
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if( 0 == stricmp( szToken, ";" ) )
|
||||
{
|
||||
// Tex name read mode<64><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
// outfit element <20><> tex <20>ʵ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD>
|
||||
oel.lTexCount = vec_szTexName.size();
|
||||
oel.pszTexName = new char*[vec_szTexName.size()];
|
||||
for( i = 0; i < (int)vec_szTexName.size(); ++i )
|
||||
{
|
||||
oel.pszTexName[i] = vec_szTexName[i];
|
||||
}
|
||||
oel.szItemName = new char[strlen(szItemName)+1];
|
||||
strcpy( oel.szItemName, szItemName );
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ۿ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>б<EFBFBD><D0B1><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̹Ƿ<CCB9>,
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>Ͽ<EFBFBD> <20>߰<EFBFBD><DFB0>ϰ<EFBFBD>,
|
||||
AddItem( oel );
|
||||
|
||||
// <20>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> vector<6F><72><EFBFBD><EFBFBD>
|
||||
vec_szMeshName.clear();
|
||||
vec_szTexName.clear();
|
||||
|
||||
oel.szSetItemName = NULL;
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><>ȯ
|
||||
lState = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// mesh name<6D><65> <20>ӽ<EFBFBD> vector<6F><72> <20><><EFBFBD><EFBFBD>
|
||||
szTmp = new char[strlen(szToken)+1];
|
||||
strcpy( szTmp, szToken );
|
||||
vec_szTexName.push_back( szTmp );
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if( 0 == stricmp( szToken, ";" ) )
|
||||
{
|
||||
lState = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
oel.szSetItemName = new char[strlen(szToken)+1];
|
||||
strcpy( oel.szSetItemName, szToken );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CH3DOutfitTable::AddItem( H3DOutfitElement &outfit )
|
||||
{
|
||||
if( m_mapName2Outfit.end() != m_mapName2Outfit.find( outfit.szItemName ) )
|
||||
{
|
||||
// <20>ش<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD><EFBFBD><EFBFBD> <20>̹<EFBFBD> <20><><EFBFBD>ϵ<EFBFBD> <20><EFBFBD><D7B8><EFBFBD> <20>ִ<EFBFBD>.
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mapName2Outfit[outfit.szItemName] = outfit;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CH3DOutfitTable
|
||||
::GetOutfit( H3DOutfitElement* &pOutfit, char* szOutfitName )
|
||||
{
|
||||
std::map<char*, H3DOutfitElement, szi_less>::iterator it;
|
||||
|
||||
it = m_mapName2Outfit.find( szOutfitName );
|
||||
if( m_mapName2Outfit.end() == it )
|
||||
{
|
||||
/*outfit.lMeshCount = 0;
|
||||
outfit.lTexCount = 0;
|
||||
outfit.pszMeshName = NULL;
|
||||
outfit.pszTexName = NULL;*/
|
||||
pOutfit = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
pOutfit = &(it->second);
|
||||
return true;
|
||||
}
|
||||
69
Engine/Zalla3D Scene Class/H3DOutfitTable.h
Normal file
69
Engine/Zalla3D Scene Class/H3DOutfitTable.h
Normal file
@@ -0,0 +1,69 @@
|
||||
// H3DOutfitTable.h: interface for the CH3DOutfitTable class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_H3DOUTFITTABLE_H__145CF134_819E_4958_8C2D_7413F1D28089__INCLUDED_)
|
||||
#define AFX_H3DOUTFITTABLE_H__145CF134_819E_4958_8C2D_7413F1D28089__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
|
||||
struct H3DOutfitElement
|
||||
{
|
||||
void Flush()
|
||||
{
|
||||
int i;
|
||||
for( i = 0; i < lMeshCount; ++i )
|
||||
{
|
||||
SAFE_DELETEA( pszMeshName[i] );
|
||||
}
|
||||
SAFE_DELETEA( pszMeshName );
|
||||
|
||||
for( i = 0; i < lTexCount; ++i )
|
||||
{
|
||||
SAFE_DELETEA( pszTexName[i] );
|
||||
}
|
||||
SAFE_DELETEA( pszTexName );
|
||||
|
||||
SAFE_DELETEA( szSetItemName );
|
||||
SAFE_DELETEA( szItemName );
|
||||
}
|
||||
|
||||
H3DOutfitElement()
|
||||
{
|
||||
szSetItemName = NULL; // <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʱ<EFBFBD>ȭ<EFBFBD><C8AD><EFBFBD>ش<EFBFBD>.
|
||||
}
|
||||
|
||||
char* szItemName;
|
||||
char* szSetItemName;
|
||||
long lMeshCount;
|
||||
long lTexCount;
|
||||
char** pszMeshName;
|
||||
char** pszTexName;
|
||||
};
|
||||
|
||||
|
||||
class CH3DOutfitTable
|
||||
{
|
||||
public:
|
||||
CH3DOutfitTable();
|
||||
~CH3DOutfitTable();
|
||||
|
||||
bool Load( const char* szFileName );
|
||||
bool GetOutfit( H3DOutfitElement* &pOutfit, char* szOutfitName );
|
||||
|
||||
protected:
|
||||
bool AddItem( H3DOutfitElement &outfit );
|
||||
|
||||
std::map<char*, H3DOutfitElement, szi_less> m_mapName2Outfit;
|
||||
//std::vector<char*> m_vec_szOutfitItemName;
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_H3DOUTFITTABLE_H__145CF134_819E_4958_8C2D_7413F1D28089__INCLUDED_)
|
||||
225
Engine/Zalla3D Scene Class/H3DWeaponTable.cpp
Normal file
225
Engine/Zalla3D Scene Class/H3DWeaponTable.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
// H3DWeaponTable.cpp: implementation of the CH3DWeaponTable class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "H3DWeaponTable.h"
|
||||
#include "SimpleParser.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CH3DWeaponTable::CH3DWeaponTable()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CH3DWeaponTable::~CH3DWeaponTable()
|
||||
{
|
||||
std::map<char*, H3DWeaponInfo, szi_less>::iterator it;
|
||||
|
||||
for( it = m_mapName2WeaponInfo.begin(); it != m_mapName2WeaponInfo.end(); it++ )
|
||||
{
|
||||
it->second.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Z3D_CHR_SKELETONPART CH3DWeaponTable::GetSkelPartByString( const char* sz )
|
||||
{
|
||||
if( 0 == stricmp( "HEAD", sz) )
|
||||
{
|
||||
return Z3D_SP_HEAD;
|
||||
}
|
||||
else if( 0 == stricmp( "NECK", sz) )
|
||||
{
|
||||
return Z3D_SP_NECK;
|
||||
}
|
||||
else if( 0 == stricmp( "CHEST", sz) )
|
||||
{
|
||||
return Z3D_SP_CHEST;
|
||||
}
|
||||
else if( 0 == stricmp( "WAIST", sz) )
|
||||
{
|
||||
return Z3D_SP_WAIST;
|
||||
}
|
||||
else if( 0 == stricmp( "PELVIS", sz) )
|
||||
{
|
||||
return Z3D_SP_PELVIS;
|
||||
}
|
||||
else if( 0 == stricmp( "R_HAND", sz) )
|
||||
{
|
||||
return Z3D_SP_R_HAND;
|
||||
}
|
||||
else if( 0 == stricmp( "R_FOREARM", sz) )
|
||||
{
|
||||
return Z3D_SP_R_FOREARM;
|
||||
}
|
||||
else if( 0 == stricmp( "R_UPPERARM", sz) )
|
||||
{
|
||||
return Z3D_SP_R_UPPERARM;
|
||||
}
|
||||
else if( 0 == stricmp( "R_THIGH", sz) )
|
||||
{
|
||||
return Z3D_SP_R_THIGH;
|
||||
}
|
||||
else if( 0 == stricmp( "R_CALF", sz) )
|
||||
{
|
||||
return Z3D_SP_R_CALF;
|
||||
}
|
||||
else if( 0 == stricmp( "R_FOOT", sz) )
|
||||
{
|
||||
return Z3D_SP_R_FOOT;
|
||||
}
|
||||
else if( 0 == stricmp( "L_HAND", sz) )
|
||||
{
|
||||
return Z3D_SP_L_HAND;
|
||||
}
|
||||
else if( 0 == stricmp( "L_FOREARM", sz) )
|
||||
{
|
||||
return Z3D_SP_L_FOREARM;
|
||||
}
|
||||
else if( 0 == stricmp( "L_UPPERARM", sz) )
|
||||
{
|
||||
return Z3D_SP_L_UPPERARM;
|
||||
}
|
||||
else if( 0 == stricmp( "L_THIGH", sz) )
|
||||
{
|
||||
return Z3D_SP_L_THIGH;
|
||||
}
|
||||
else if( 0 == stricmp( "L_CALF", sz) )
|
||||
{
|
||||
return Z3D_SP_L_CALF;
|
||||
}
|
||||
else if( 0 == stricmp( "L_FOOT", sz) )
|
||||
{
|
||||
return Z3D_SP_L_FOOT;
|
||||
}
|
||||
|
||||
return Z3D_SP_NONE;
|
||||
}
|
||||
|
||||
|
||||
bool CH3DWeaponTable::Load( const char* szFileName )
|
||||
{
|
||||
CSimpleParser parser;
|
||||
|
||||
if( false == parser.OpenFile( szFileName ) )
|
||||
{
|
||||
return false; // file open failed
|
||||
}
|
||||
|
||||
H3DWeaponInfo wi;
|
||||
char* szToken;
|
||||
|
||||
long lState; // 0 : reading weapon name, 1 : reading weapon info
|
||||
|
||||
lState = 0;
|
||||
while( (szToken = parser.GetNextToken()) != NULL )
|
||||
{
|
||||
switch( lState )
|
||||
{
|
||||
case 0:
|
||||
wi.szItemName = new char[strlen(szToken)+1];
|
||||
strcpy( wi.szItemName, szToken );
|
||||
lState = 1;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
if( 0 == stricmp( "Mesh", szToken ) )
|
||||
{
|
||||
szToken = parser.GetNextToken();
|
||||
wi.szMeshName = new char[strlen(szToken)+1];
|
||||
strcpy( wi.szMeshName, szToken );
|
||||
}
|
||||
else if( 0 == stricmp( "Tex", szToken ) )
|
||||
{
|
||||
szToken = parser.GetNextToken();
|
||||
wi.szTexName = new char[strlen(szToken)+1];
|
||||
strcpy( wi.szTexName, szToken );
|
||||
}
|
||||
else if( 0 == stricmp( "Type", szToken ) )
|
||||
{
|
||||
wi.lWeaponType = aton( parser.GetNextToken() );
|
||||
if( wi.lWeaponType > 9 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if( 0 == stricmp( "HSkel", szToken ) )
|
||||
{
|
||||
wi.hskel = GetSkelPartByString( parser.GetNextToken() );
|
||||
}
|
||||
else if( 0 == stricmp( "HPos", szToken ) )
|
||||
{
|
||||
wi.vecHpos.x = (float)atof( parser.GetNextToken() );
|
||||
wi.vecHpos.y = (float)atof( parser.GetNextToken() );
|
||||
wi.vecHpos.z = (float)atof( parser.GetNextToken() );
|
||||
}
|
||||
else if( 0 == stricmp( "HRot", szToken ) )
|
||||
{
|
||||
wi.quatHrot.x = (float)atof( parser.GetNextToken() );
|
||||
wi.quatHrot.y = (float)atof( parser.GetNextToken() );
|
||||
wi.quatHrot.z = (float)atof( parser.GetNextToken() );
|
||||
wi.quatHrot.w = (float)atof( parser.GetNextToken() );
|
||||
}
|
||||
else if( 0 == stricmp( "Skel", szToken ) )
|
||||
{
|
||||
wi.skel = GetSkelPartByString( parser.GetNextToken() );
|
||||
}
|
||||
else if( 0 == stricmp( "Pos", szToken ) )
|
||||
{
|
||||
wi.vecPos.x = (float)atof( parser.GetNextToken() );
|
||||
wi.vecPos.y = (float)atof( parser.GetNextToken() );
|
||||
wi.vecPos.z = (float)atof( parser.GetNextToken() );
|
||||
}
|
||||
else if( 0 == stricmp( "Rot", szToken ) )
|
||||
{
|
||||
wi.quatRot.x = (float)atof( parser.GetNextToken() );
|
||||
wi.quatRot.y = (float)atof( parser.GetNextToken() );
|
||||
wi.quatRot.z = (float)atof( parser.GetNextToken() );
|
||||
wi.quatRot.w = (float)atof( parser.GetNextToken() );
|
||||
}
|
||||
else if( 0 == stricmp( ";", szToken ) )
|
||||
{
|
||||
AddItem( wi );
|
||||
lState = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CH3DWeaponTable::AddItem( H3DWeaponInfo &wi )
|
||||
{
|
||||
if( m_mapName2WeaponInfo.end() != m_mapName2WeaponInfo.find( wi.szItemName ) )
|
||||
{
|
||||
// <20>ش<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20≯<EFBFBD><CCB8><EFBFBD><EFBFBD><EFBFBD> <20>̹<EFBFBD> <20><><EFBFBD>ϵ<EFBFBD> <20><EFBFBD><D7B8><EFBFBD> <20>ִ<EFBFBD>.
|
||||
return false;
|
||||
}
|
||||
|
||||
m_mapName2WeaponInfo[wi.szItemName] = wi;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CH3DWeaponTable::GetWeaponInfo( H3DWeaponInfo* &pWi, char* szWeaponName )
|
||||
{
|
||||
std::map<char*, H3DWeaponInfo, szi_less>::iterator it;
|
||||
|
||||
it = m_mapName2WeaponInfo.find( szWeaponName );
|
||||
if( m_mapName2WeaponInfo.end() == it )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
pWi = &(it->second);
|
||||
return true;
|
||||
}
|
||||
62
Engine/Zalla3D Scene Class/H3DWeaponTable.h
Normal file
62
Engine/Zalla3D Scene Class/H3DWeaponTable.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// H3DWeaponTable.h: interface for the CH3DWeaponTable class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_H3DWEAPONTABLE_H__AAFF1DDB_05DD_4D2C_BAA4_F0483EBC4503__INCLUDED_)
|
||||
#define AFX_H3DWEAPONTABLE_H__AAFF1DDB_05DD_4D2C_BAA4_F0483EBC4503__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "misc.h"
|
||||
#include "Z3D_CONSTANTS.h"
|
||||
#include "vector.h"
|
||||
#include "quaternion.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
struct H3DWeaponInfo
|
||||
{
|
||||
void Flush()
|
||||
{
|
||||
SAFE_DELETEA( szTexName );
|
||||
SAFE_DELETEA( szMeshName );
|
||||
|
||||
SAFE_DELETEA( szItemName );
|
||||
}
|
||||
|
||||
char* szItemName;
|
||||
char* szMeshName;
|
||||
char* szTexName;
|
||||
|
||||
long lWeaponType;
|
||||
|
||||
Z3D_CHR_SKELETONPART hskel;
|
||||
vector3 vecHpos; // position in hand
|
||||
quaternion quatHrot; // rotation in hand
|
||||
|
||||
Z3D_CHR_SKELETONPART skel;
|
||||
vector3 vecPos;
|
||||
quaternion quatRot;
|
||||
};
|
||||
|
||||
|
||||
class CH3DWeaponTable
|
||||
{
|
||||
public:
|
||||
CH3DWeaponTable();
|
||||
virtual ~CH3DWeaponTable();
|
||||
|
||||
bool Load( const char* szFileName );
|
||||
bool GetWeaponInfo( H3DWeaponInfo* &pWi, char* szWeaponName );
|
||||
|
||||
protected:
|
||||
Z3D_CHR_SKELETONPART GetSkelPartByString( const char* sz );
|
||||
bool AddItem( H3DWeaponInfo &wi );
|
||||
|
||||
std::map<char*, H3DWeaponInfo, szi_less> m_mapName2WeaponInfo;
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_H3DWEAPONTABLE_H__AAFF1DDB_05DD_4D2C_BAA4_F0483EBC4503__INCLUDED_)
|
||||
115
Engine/Zalla3D Scene Class/HazeScene.cpp
Normal file
115
Engine/Zalla3D Scene Class/HazeScene.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
// HazeScene.cpp: implementation of the CHazeScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "HazeScene.h"
|
||||
#include "BaseGraphicsLayer.h"
|
||||
#include "BaseDataDefine.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CHazeScene::CHazeScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CHazeScene::~CHazeScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CHazeScene::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
/*
|
||||
TLVertex pVertex[8];
|
||||
float fTextureSize=256.0f;
|
||||
|
||||
pVertex[0].v.x=0.0f;
|
||||
pVertex[1].v.x=0.0f;
|
||||
pVertex[2].v.x=fTextureSize;
|
||||
pVertex[3].v.x=fTextureSize;
|
||||
|
||||
pVertex[1].v.y=0.0f;
|
||||
pVertex[3].v.y=0.0f;
|
||||
pVertex[0].v.y=fTextureSize;
|
||||
pVertex[2].v.y=fTextureSize;
|
||||
|
||||
static float fasdf=0.0f;
|
||||
|
||||
pVertex[0].tu=0.0f+fasdf;
|
||||
pVertex[1].tu=0.0f+fasdf;
|
||||
|
||||
pVertex[3].tu=1.0f+fasdf;
|
||||
pVertex[2].tu=1.0f+fasdf;
|
||||
|
||||
pVertex[1].tv=0.0f+fasdf;
|
||||
pVertex[3].tv=0.0f+fasdf;
|
||||
|
||||
pVertex[0].tv=1.0f+fasdf;
|
||||
pVertex[2].tv=1.0f+fasdf;
|
||||
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
pVertex[i].w=0.1f;
|
||||
pVertex[i].v.z=0.1f;
|
||||
pVertex[i].Diffuse.c=0xffffffff;
|
||||
pVertex[i].Specular.c=0xffffffff;
|
||||
}
|
||||
|
||||
for(i=0;i<4;i++)
|
||||
{
|
||||
pVertex[i+4].v=pVertex[i].v+vector3(512.0f,0.0f,0.0f);
|
||||
pVertex[i+4].w=pVertex[i].w;
|
||||
pVertex[i+4].Diffuse.c=pVertex[i].Diffuse.c;
|
||||
pVertex[i+4].Specular.c=pVertex[i].Specular.c;
|
||||
}
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
|
||||
RECT rc={100,100,100+512,100+512};
|
||||
|
||||
pd3dDevice->SetTexture(0,CRenderTargetTexture::GetTexture(pd3dDevice,rc));
|
||||
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
pd3dDevice->SetVertexShader(TLVERTEXFVF);
|
||||
//m_pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,4,pVertex,sizeof(TLVertex));
|
||||
WORD pIndices[8];
|
||||
pIndices[0]=0;
|
||||
pIndices[1]=1;
|
||||
pIndices[2]=2;
|
||||
pIndices[3]=3;
|
||||
|
||||
pIndices[4]=4;
|
||||
pIndices[5]=5;
|
||||
pIndices[6]=6;
|
||||
pIndices[7]=7;
|
||||
|
||||
pd3dDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLESTRIP,0,8,2,pIndices,D3DFMT_INDEX16,pVertex,sizeof(TLVertex));
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE,FALSE);
|
||||
*/
|
||||
}
|
||||
|
||||
void CHazeScene::Create(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
if(GF3OPTION)
|
||||
{
|
||||
char strShaderPath[256];
|
||||
|
||||
sprintf(strShaderPath,"%s%s",SHADERPATH,"SampleFilter.psh");
|
||||
|
||||
LPD3DXBUFFER pCode;
|
||||
D3DXAssembleShaderFromFile(strShaderPath,0,NULL,&pCode,NULL);
|
||||
|
||||
BaseGraphicsLayer::GetDevice()->CreatePixelShader((DWORD*)pCode->GetBufferPointer(),
|
||||
&m_dwSampleFilterPixelShader);
|
||||
pCode->Release();
|
||||
|
||||
}
|
||||
}
|
||||
27
Engine/Zalla3D Scene Class/HazeScene.h
Normal file
27
Engine/Zalla3D Scene Class/HazeScene.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// HazeScene.h: interface for the CHazeScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_HAZESCENE_H__A777792E_43C9_4572_A06A_2A452B741D79__INCLUDED_)
|
||||
#define AFX_HAZESCENE_H__A777792E_43C9_4572_A06A_2A452B741D79__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include <d3d8.h>
|
||||
#include "3DMath.h"
|
||||
#include "vertex.h"
|
||||
|
||||
class CHazeScene
|
||||
{
|
||||
public:
|
||||
DWORD m_dwSampleFilterPixelShader;
|
||||
void Create(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
CHazeScene();
|
||||
virtual ~CHazeScene();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_HAZESCENE_H__A777792E_43C9_4572_A06A_2A452B741D79__INCLUDED_)
|
||||
2135
Engine/Zalla3D Scene Class/HeightFieldScene.cpp
Normal file
2135
Engine/Zalla3D Scene Class/HeightFieldScene.cpp
Normal file
File diff suppressed because it is too large
Load Diff
114
Engine/Zalla3D Scene Class/HeightFieldScene.h
Normal file
114
Engine/Zalla3D Scene Class/HeightFieldScene.h
Normal file
@@ -0,0 +1,114 @@
|
||||
// HeightFieldScene.h: interface for the CHeightFieldScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_HEIGHTFIELDSCENE_H__7E864095_E229_4C61_BE5A_0F54763B2B66__INCLUDED_)
|
||||
#define AFX_HEIGHTFIELDSCENE_H__7E864095_E229_4C61_BE5A_0F54763B2B66__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
#include "SceneNode.h"
|
||||
#include "SectorDefine.h"
|
||||
#include "SectorScene.h"
|
||||
#include "MapStorage.h"
|
||||
#include "GrassManager.h"
|
||||
#include "StateLog.h"
|
||||
#include <vector>
|
||||
|
||||
struct SectorSortNode_t {
|
||||
int iSectorIndex;
|
||||
float fViewDist;
|
||||
};
|
||||
|
||||
class CHeightFieldScene : public CSceneNode
|
||||
{
|
||||
private:
|
||||
|
||||
int m_NowTessellatePosX,m_NowTessellatePosY;
|
||||
// Arena1 <20><><EFBFBD><EFBFBD> House<73><65> World Effect object culling flag 03.03.04
|
||||
bool m_bHouseCulling;
|
||||
bool m_bObjectCulling;
|
||||
bool m_bEffectCulling;
|
||||
|
||||
SectorSortNode_t *m_pSectorSorts;
|
||||
int m_iSortsNum;
|
||||
|
||||
|
||||
public:
|
||||
int *UpdateSector;//=new int[m_LSizeX*m_LSizeY];
|
||||
int *NotUpdateSector;//=new int[m_LSizeX*m_LSizeY];
|
||||
bool *IsCulling;//=new bool[m_LSizeX*m_LSizeY];
|
||||
|
||||
int m_LSizeX,m_LSizeY;
|
||||
int m_NowPositionX,m_NowPositionY;
|
||||
void RenderGlare(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RebuildShadowPoly();
|
||||
|
||||
class CShadowedPoly
|
||||
{
|
||||
public:
|
||||
|
||||
std::vector<vector3> m_ShadowedPolyList;
|
||||
vector3 m_vecShadowPos;
|
||||
int m_nShadowID;
|
||||
int m_nGatherMethod;
|
||||
bool m_bActive;
|
||||
};
|
||||
|
||||
void DeleteShadowPolyList(int nID);
|
||||
CHeightFieldScene::CShadowedPoly* GetShadowPolyList(int nID);
|
||||
std::vector<CShadowedPoly> m_ShadowedVertexList;
|
||||
int AddShadowPoly(vector3 vecPos,int nMethod);
|
||||
|
||||
void RenderShadow(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
CGrassManager m_GrassSceneManager;
|
||||
void Update(float fUpdate);
|
||||
char* GetHeightFieldShadowCollision(vector3 vecPos);
|
||||
void GetHeightFieldRangePoly(vector3 vecPos,std::vector<vector3> &vecPolyList,float fRange);
|
||||
void AllObjectCalcLens();
|
||||
int GetLSizeX(){return m_LSizeX;};
|
||||
int GetLSizeY(){return m_LSizeY;};
|
||||
void GetLight(vector3 vecPos,std::vector<D3DLIGHT8> &LightList);
|
||||
void GetLineIntersectPoly(vector3 vecStart,vector3 vecEnd, std::vector<vector3> &vecPolyList);
|
||||
void GetHeightFieldShadowPoly(vector3 vecPos,std::vector<vector3> &vecPolyList);
|
||||
void GetInHouseShadowPoly(vector3 vecPos,std::vector<vector3> &vecPolyList,vector3 vecLightPos);
|
||||
|
||||
float GetHeight(vector3 vecPos);
|
||||
CSectorScene *m_QuadSector[LSIZEX*LSIZEY];
|
||||
CSectorScene *m_SectorScene;
|
||||
std::vector<char*> m_AlreadyLoad;
|
||||
bool CheckingTessellate();
|
||||
void Tessellate();
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderEnv(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
|
||||
void RenderMapEffect();
|
||||
|
||||
void Create(int LSizeX,int LSizeY,CMapStorage *pMapStorage);
|
||||
void Destroy(void);
|
||||
void CheckingNextTerrain();
|
||||
CHeightFieldScene();
|
||||
virtual ~CHeightFieldScene();
|
||||
|
||||
void GenerateSectorSceneObjects( int sectorX, int sectorY );
|
||||
// Arena1 <20><><EFBFBD><EFBFBD> House<73><65> World Effect culling flag 03.03.04
|
||||
void SetHouseCulling( bool bCull ) { m_bHouseCulling = bCull; }
|
||||
void SetObjectCulling( bool bCull ) { m_bObjectCulling = bCull; }
|
||||
void SetEffectCulling( bool bCull ) { m_bEffectCulling = bCull; }
|
||||
|
||||
bool GetHouseCullingFlag() { return m_bHouseCulling;}
|
||||
|
||||
void DeleteSectorNotCull();
|
||||
void InitNowPos();
|
||||
|
||||
// ray tracing (true <20><> <20>浹 <20>Ͼ <20><>)
|
||||
bool CheckRayCollision(const D3DXVECTOR3 &vecPos1,const D3DXVECTOR3 &vecPos2);
|
||||
int GetSectorIndex(const int iSX,const int iSY);
|
||||
|
||||
void SetNationFlag(unsigned char cNation);
|
||||
};
|
||||
|
||||
int Sector_tCompare(const void *arg1,const void *arg2);
|
||||
|
||||
#endif // !defined(AFX_HEIGHTFIELDSCENE_H__7E864095_E229_4C61_BE5A_0F54763B2B66__INCLUDED_)
|
||||
20
Engine/Zalla3D Scene Class/HouseNameObject.cpp
Normal file
20
Engine/Zalla3D Scene Class/HouseNameObject.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// HouseNameObject.cpp: implementation of the CHouseNameObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "HouseNameObject.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CHouseNameObject::CHouseNameObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CHouseNameObject::~CHouseNameObject()
|
||||
{
|
||||
|
||||
}
|
||||
20
Engine/Zalla3D Scene Class/HouseNameObject.h
Normal file
20
Engine/Zalla3D Scene Class/HouseNameObject.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// HouseNameObject.h: interface for the CHouseNameObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_HOUSENAMEOBJECT_H__D97587D5_5AA0_4C33_B004_8AB45606BFB5__INCLUDED_)
|
||||
#define AFX_HOUSENAMEOBJECT_H__D97587D5_5AA0_4C33_B004_8AB45606BFB5__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CHouseNameObject
|
||||
{
|
||||
public:
|
||||
CHouseNameObject();
|
||||
virtual ~CHouseNameObject();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_HOUSENAMEOBJECT_H__D97587D5_5AA0_4C33_B004_8AB45606BFB5__INCLUDED_)
|
||||
765
Engine/Zalla3D Scene Class/HouseObject.cpp
Normal file
765
Engine/Zalla3D Scene Class/HouseObject.cpp
Normal file
@@ -0,0 +1,765 @@
|
||||
// HouseObject.cpp: implementation of the CHouseObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "HouseObject.h"
|
||||
#include "SceneManager.h"
|
||||
#include "BaseGraphicsLayer.h"
|
||||
#include "RenderOption.h"
|
||||
#include "./OctreeScene.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CHouseObject::CHouseObject() : m_pInHouseObject(NULL),m_pMedHouseObject(NULL),m_pOutHouseObject(NULL),m_Lightmap(NULL),m_InLightmap(NULL),
|
||||
m_pOctree(NULL),m_isHaveLightmap(false),m_isHaveInLightmap(false),m_bModulate2X(false), m_pFlagHouseObject(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
CHouseObject::~CHouseObject()
|
||||
{
|
||||
int i;
|
||||
/*** *********/
|
||||
// Octree resource ó<><C3B3> <20>ؾ<EFBFBD><D8BE><EFBFBD>.COctreeScene *m_pOctree;
|
||||
if(m_pInHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pInHouseObject);
|
||||
m_pInHouseObject = NULL;
|
||||
}
|
||||
|
||||
if(m_pMedHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pMedHouseObject);
|
||||
m_pMedHouseObject = NULL;
|
||||
}
|
||||
|
||||
if(m_pOutHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pOutHouseObject);
|
||||
m_pOutHouseObject = NULL;
|
||||
}
|
||||
|
||||
if(m_pFlagHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pFlagHouseObject);
|
||||
m_pFlagHouseObject = NULL;
|
||||
}
|
||||
|
||||
if(m_Lightmap)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_TEXTURE,m_Lightmap);
|
||||
m_Lightmap = NULL;
|
||||
|
||||
}
|
||||
|
||||
if(m_InLightmap)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_TEXTURE,m_InLightmap);
|
||||
m_InLightmap = NULL;
|
||||
|
||||
}
|
||||
|
||||
if(m_pOctree)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_OCTREESCENE,m_pOctree);
|
||||
m_pOctree = NULL;
|
||||
}
|
||||
|
||||
for(i = 0; i < (int)m_pVertex.size(); i++ )
|
||||
{
|
||||
if(m_pVertex[i])
|
||||
{
|
||||
delete[] m_pVertex[i];
|
||||
m_pVertex[i] = NULL;
|
||||
}
|
||||
}
|
||||
m_pVertex.clear();
|
||||
|
||||
|
||||
for(i = 0; i < (int)m_pIndices.size(); i++ )
|
||||
{
|
||||
if(m_pIndices[i])
|
||||
{
|
||||
delete[] m_pIndices[i];
|
||||
m_pIndices[i] = NULL;
|
||||
}
|
||||
}
|
||||
m_pIndices.clear();
|
||||
|
||||
m_nVertex.clear();
|
||||
m_nIndices.clear();
|
||||
|
||||
}
|
||||
|
||||
const long MAX_OBJECT=100;
|
||||
void CHouseObject::GenerateNewLightmap(int iValue,matrix matSet,matrix matHouseTM,CSectorLight *pLights,int iLights)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
void CHouseObject::GenerateLightmap(matrix matSet,matrix matHouseTM,int LightmapMode)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CHouseObject::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
/**/D3DMATERIAL8 mtrl;
|
||||
ZeroMemory( &mtrl, sizeof(D3DMATERIAL8) );
|
||||
mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
|
||||
mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
|
||||
mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f;
|
||||
mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
|
||||
pd3dDevice->SetMaterial( &mtrl );
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,TRUE);
|
||||
|
||||
pd3dDevice->SetTexture(2,NULL);
|
||||
pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
|
||||
// 2005.01.10 yundi <20><><EFBFBD><EFBFBD> 3<>ÿ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ⱥ<EFBFBD><C8BA><EFBFBD><EFBFBD><EFBFBD> <20>ϴ<EFBFBD> house <20><><EFBFBD><EFBFBD> <20>ذ<EFBFBD>
|
||||
color tempColor = CSceneManager::m_WeatherManager.m_InterObjectAmbientColor;
|
||||
tempColor.a = 0xFF;
|
||||
|
||||
if(m_pOutHouseObject && m_pOutHouseObject->IsLoaded())
|
||||
{
|
||||
if(m_isHaveLightmap && m_Lightmap->IsLoaded())
|
||||
{
|
||||
|
||||
pd3dDevice->SetTexture(1,m_Lightmap->GetTexture());
|
||||
|
||||
pd3dDevice->LightEnable(0,FALSE);
|
||||
pd3dDevice->SetLight(0,&CSceneManager::m_WeatherManager.m_SunLight);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_AMBIENT, tempColor.c);
|
||||
/**/
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, tempColor.c);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X );
|
||||
|
||||
|
||||
if(m_bModulate2X)
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
else
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
|
||||
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,0);
|
||||
pd3dDevice->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,1);
|
||||
////
|
||||
|
||||
|
||||
//pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
//pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,TRUE);
|
||||
|
||||
m_pOutHouseObject->Render(pd3dDevice);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,FALSE);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_pOutHouseObject->ConvertNormal();
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_AMBIENT,CSceneManager::m_WeatherManager.m_InterAmbientColor.c);
|
||||
pd3dDevice->SetLight(0,&CSceneManager::m_WeatherManager.m_SunLight);
|
||||
pd3dDevice->LightEnable(0,TRUE);
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,TRUE);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_CURRENT);
|
||||
|
||||
if(BaseGraphicsLayer::m_VoodooOption)
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
else
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
|
||||
m_pOutHouseObject->Render(pd3dDevice);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
|
||||
}
|
||||
|
||||
//}//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
} //if(m_pOutHouseObject)
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
if(m_pMedHouseObject && m_pMedHouseObject->IsLoaded())
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//if (strstr(m_pMedHouseObject->m_strName, "_qwe"))
|
||||
//{
|
||||
|
||||
|
||||
if(m_isHaveLightmap && m_Lightmap->IsLoaded())
|
||||
{
|
||||
|
||||
pd3dDevice->SetTexture(1,m_Lightmap->GetTexture());
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
|
||||
|
||||
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
|
||||
|
||||
if(BaseGraphicsLayer::m_VoodooOption)
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
else
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
pd3dDevice->LightEnable(0,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_AMBIENT, tempColor.c);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,TRUE);
|
||||
|
||||
///////////// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD><EFBFBD>
|
||||
pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, tempColor.c);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
|
||||
|
||||
/////////////
|
||||
|
||||
m_pMedHouseObject->Render(pd3dDevice);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_pMedHouseObject->ConvertNormal();
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,TRUE);
|
||||
pd3dDevice->LightEnable(0,TRUE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
if(BaseGraphicsLayer::m_VoodooOption)
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
else
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
// <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD> <20>Ͽ콺 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 7.29
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,TRUE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,TRUE);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_AMBIENT, CSceneManager::m_WeatherManager.m_InterAmbientColor.c);
|
||||
//pd3dDevice->SetRenderState(D3DRS_AMBIENT,CSceneManager::m_WeatherManager.m_InterAmbientColor.c);
|
||||
pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, CSceneManager::m_WeatherManager.m_InterAmbientColor.c);
|
||||
|
||||
pd3dDevice->SetLight(0,&CSceneManager::m_WeatherManager.m_SunLight);
|
||||
|
||||
m_pMedHouseObject->Render(pd3dDevice);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,FALSE);
|
||||
|
||||
}
|
||||
|
||||
//}//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
} // if(m_pMedHouseObject)
|
||||
if(m_pInHouseObject && m_pInHouseObject->IsLoaded())
|
||||
{
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//if (strstr(m_pInHouseObject->m_strName, "_qwe"))
|
||||
//{
|
||||
|
||||
if(m_isHaveInLightmap && m_InLightmap->IsLoaded())
|
||||
{
|
||||
pd3dDevice->SetTexture(1,m_InLightmap->GetTexture());
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
|
||||
|
||||
if(BaseGraphicsLayer::m_VoodooOption)
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
else
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
pd3dDevice->LightEnable(0,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff);
|
||||
m_pInHouseObject->Render(pd3dDevice);
|
||||
}
|
||||
else if(m_isHaveLightmap && m_Lightmap->IsLoaded())
|
||||
{
|
||||
|
||||
|
||||
pd3dDevice->SetTexture(1,m_Lightmap->GetTexture());
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
|
||||
|
||||
if(BaseGraphicsLayer::m_VoodooOption)
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
else
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
pd3dDevice->LightEnable(0,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff);
|
||||
m_pInHouseObject->Render(pd3dDevice);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//m_pInHouseObject->ConvertNormal();
|
||||
pd3dDevice->LightEnable(0,TRUE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
//pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
if(BaseGraphicsLayer::m_VoodooOption)
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
else
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
|
||||
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_AMBIENT,CSceneManager::m_WeatherManager.m_InterAmbientColor.c);
|
||||
pd3dDevice->SetLight(0,&CSceneManager::m_WeatherManager.m_SunLight);
|
||||
|
||||
m_pInHouseObject->Render(pd3dDevice);
|
||||
}
|
||||
|
||||
//}//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(m_pFlagHouseObject && m_pFlagHouseObject->IsLoaded())
|
||||
{
|
||||
// edith 2009.05.05 9<><39><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ġ<EFBFBD>߸<EFBFBD><DFB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°<EFBFBD> <20><><EFBFBD>̷<EFBFBD><CCB7><EFBFBD> <20>߳<EFBFBD>
|
||||
matrix matWorld;
|
||||
matWorld.MakeIdent();
|
||||
|
||||
matWorld._41 = 237305.0f;
|
||||
matWorld._42 = 16055.0f;
|
||||
matWorld._43 = 236122.0f;
|
||||
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,matWorld);
|
||||
|
||||
pd3dDevice->LightEnable(0,TRUE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
||||
m_pFlagHouseObject->Render(pd3dDevice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CHouseObject::GenerateOctree()
|
||||
{
|
||||
GetPolygon();
|
||||
m_pOctree=new COctreeScene();
|
||||
vector3 pPoly[3];
|
||||
for(int i=0;i<(int)m_pVertex.size();i++)
|
||||
{
|
||||
WORD *pIndices=m_pIndices[i];
|
||||
vector3 *pVertex=m_pVertex[i];
|
||||
for(int cIndices=0;cIndices<m_nIndices[i];cIndices++)
|
||||
{
|
||||
pPoly[0]=pVertex[pIndices[cIndices*3+0]];
|
||||
pPoly[1]=pVertex[pIndices[cIndices*3+1]];
|
||||
pPoly[2]=pVertex[pIndices[cIndices*3+2]];
|
||||
m_pOctree->AddPoly(pPoly);
|
||||
}
|
||||
}
|
||||
|
||||
vector3 vecBoundBox[8];
|
||||
vector3 vecPolyTest[3];
|
||||
vector3 vecPlaneNormal;
|
||||
matrix matTrans;
|
||||
//float fIntersection;
|
||||
|
||||
WORD wCollisionIndices[]=
|
||||
{
|
||||
4,1,0,
|
||||
1,4,5,
|
||||
|
||||
5,3,1,
|
||||
3,5,7,
|
||||
|
||||
7,2,3,
|
||||
2,7,6,
|
||||
|
||||
6,0,2,
|
||||
0,6,4
|
||||
};
|
||||
|
||||
vector3 vecDirection[8];
|
||||
vecDirection[0]=vector3(0.707f,0.0f,0.707f);
|
||||
vecDirection[1]=vector3(0.707f,0.0f,-0.707f);
|
||||
vecDirection[2]=vector3(-0.707f,0.0f,0.707f);
|
||||
vecDirection[3]=vector3(-0.707f,0.0f,-0.707f);
|
||||
|
||||
vecDirection[4]=vector3(1.0f,0.0f,0.0f);
|
||||
vecDirection[5]=vector3(-1.0f,0.0f,0.0f);
|
||||
vecDirection[6]=vector3(0.0f,0.0f,1.0f);
|
||||
vecDirection[7]=vector3(0.0f,0.0f,-1.0f);
|
||||
|
||||
vector3 vecLens;
|
||||
/*
|
||||
matrix matTM;
|
||||
for(int cObject=0;cObject<m_ObjectList.num;cObject++)
|
||||
{
|
||||
matTM=m_ObjectList[cObject]->m_TM;
|
||||
|
||||
vecBoundBox[0].x=m_ObjectList[cObject]->m_vecMinBox.x;
|
||||
vecBoundBox[0].y=m_ObjectList[cObject]->m_vecMinBox.y;
|
||||
vecBoundBox[0].z=m_ObjectList[cObject]->m_vecMinBox.z;
|
||||
|
||||
vecBoundBox[1].x=m_ObjectList[cObject]->m_vecMaxBox.x;
|
||||
vecBoundBox[1].y=m_ObjectList[cObject]->m_vecMinBox.y;
|
||||
vecBoundBox[1].z=m_ObjectList[cObject]->m_vecMinBox.z;
|
||||
|
||||
vecBoundBox[2].x=m_ObjectList[cObject]->m_vecMinBox.x;
|
||||
vecBoundBox[2].y=m_ObjectList[cObject]->m_vecMinBox.y;
|
||||
vecBoundBox[2].z=m_ObjectList[cObject]->m_vecMaxBox.z;
|
||||
|
||||
vecBoundBox[3].x=m_ObjectList[cObject]->m_vecMaxBox.x;
|
||||
vecBoundBox[3].y=m_ObjectList[cObject]->m_vecMinBox.y;
|
||||
vecBoundBox[3].z=m_ObjectList[cObject]->m_vecMaxBox.z;
|
||||
|
||||
vecBoundBox[4].x=m_ObjectList[cObject]->m_vecMinBox.x;
|
||||
vecBoundBox[4].y=m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
|
||||
vecBoundBox[4].z=m_ObjectList[cObject]->m_vecMinBox.z;
|
||||
|
||||
vecBoundBox[5].x=m_ObjectList[cObject]->m_vecMaxBox.x;
|
||||
vecBoundBox[5].y=m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
|
||||
vecBoundBox[5].z=m_ObjectList[cObject]->m_vecMinBox.z;
|
||||
|
||||
vecBoundBox[6].x=m_ObjectList[cObject]->m_vecMinBox.x;
|
||||
vecBoundBox[6].y=m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
|
||||
vecBoundBox[6].z=m_ObjectList[cObject]->m_vecMaxBox.z;
|
||||
|
||||
vecBoundBox[7].x=m_ObjectList[cObject]->m_vecMaxBox.x;
|
||||
vecBoundBox[7].y=m_ObjectList[cObject]->m_vecMaxBox.y+50.0f;
|
||||
vecBoundBox[7].z=m_ObjectList[cObject]->m_vecMaxBox.z;
|
||||
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
matTrans.Translation(vecBoundBox[i]);
|
||||
matTrans=matTrans*matTM;
|
||||
vecBoundBox[i]=matTrans.GetLoc();
|
||||
}
|
||||
|
||||
//
|
||||
//vecPolyTest[0]=vecBoundBox[4];
|
||||
//vecPolyTest[1]=vecBoundBox[0];
|
||||
//vecPolyTest[2]=vecBoundBox[1];
|
||||
bool bAlready=false;
|
||||
for(int cIndices=0;cIndices<8;cIndices++)
|
||||
{
|
||||
vecPolyTest[0]=vecBoundBox[wCollisionIndices[cIndices*3+0]];
|
||||
vecPolyTest[1]=vecBoundBox[wCollisionIndices[cIndices*3+1]];
|
||||
vecPolyTest[2]=vecBoundBox[wCollisionIndices[cIndices*3+2]];
|
||||
|
||||
m_pOctree->AddPoly(vecPolyTest);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
m_pOctree->GenerateOctree();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CHouseObject::CalcBox(vector3 &MinBox, vector3 &MaxBox,int iCalcObject)
|
||||
{
|
||||
if(iCalcObject == 0)
|
||||
{
|
||||
|
||||
if(m_pOutHouseObject)
|
||||
{
|
||||
MaxBox=m_pOutHouseObject->m_MaxBox;
|
||||
MinBox=m_pOutHouseObject->m_MinBox;
|
||||
}
|
||||
if(m_pMedHouseObject)
|
||||
{
|
||||
if(MaxBox.x < m_pMedHouseObject->m_MaxBox.x)
|
||||
MaxBox.x=m_pMedHouseObject->m_MaxBox.x;
|
||||
if(MaxBox.y < m_pMedHouseObject->m_MaxBox.y)
|
||||
MaxBox.y=m_pMedHouseObject->m_MaxBox.y;
|
||||
if(MaxBox.z < m_pMedHouseObject->m_MaxBox.z)
|
||||
MaxBox.z=m_pMedHouseObject->m_MaxBox.z;
|
||||
|
||||
if(MinBox.x > m_pMedHouseObject->m_MinBox.x)
|
||||
MaxBox.x=m_pMedHouseObject->m_MinBox.x;
|
||||
if(MinBox.y > m_pMedHouseObject->m_MinBox.y)
|
||||
MinBox.y=m_pMedHouseObject->m_MinBox.y;
|
||||
if(MinBox.z > m_pMedHouseObject->m_MinBox.z)
|
||||
MinBox.z=m_pMedHouseObject->m_MinBox.z;
|
||||
|
||||
}
|
||||
if(m_pInHouseObject)
|
||||
{
|
||||
if(MaxBox.x < m_pOutHouseObject->m_MaxBox.x)
|
||||
MaxBox.x=m_pOutHouseObject->m_MaxBox.x;
|
||||
if(MaxBox.y < m_pOutHouseObject->m_MaxBox.y)
|
||||
MaxBox.y=m_pOutHouseObject->m_MaxBox.y;
|
||||
if(MaxBox.z < m_pOutHouseObject->m_MaxBox.z)
|
||||
MaxBox.z=m_pOutHouseObject->m_MaxBox.z;
|
||||
|
||||
if(MinBox.x > m_pOutHouseObject->m_MinBox.x)
|
||||
MaxBox.x=m_pOutHouseObject->m_MinBox.x;
|
||||
if(MinBox.y > m_pOutHouseObject->m_MinBox.y)
|
||||
MinBox.y=m_pOutHouseObject->m_MinBox.y;
|
||||
if(MinBox.z > m_pOutHouseObject->m_MinBox.z)
|
||||
MinBox.z=m_pOutHouseObject->m_MinBox.z;
|
||||
}
|
||||
}
|
||||
else if(iCalcObject == 1)
|
||||
{
|
||||
if(m_pInHouseObject)
|
||||
{
|
||||
MaxBox = m_pInHouseObject->m_MaxBox;
|
||||
MinBox = m_pInHouseObject->m_MinBox;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void CHouseObject::GetPolygon()
|
||||
{
|
||||
int cObject;
|
||||
m_pIndices.clear();
|
||||
m_nIndices.clear();
|
||||
m_pVertex.clear();
|
||||
|
||||
if(m_pOutHouseObject)
|
||||
{
|
||||
m_pOutHouseObject->AllLockBuffer();
|
||||
for(cObject=0;cObject<m_pOutHouseObject->GetObjectCount();cObject++)
|
||||
{
|
||||
vector3 *AddVertex=new vector3[m_pOutHouseObject->m_nVertex[cObject]];
|
||||
|
||||
MultiVertex *pVertex=(MultiVertex*)m_pOutHouseObject->m_pVertex[cObject];
|
||||
for(int cVertex=0;cVertex<m_pOutHouseObject->m_nVertex[cObject];cVertex++)
|
||||
AddVertex[cVertex]=pVertex[cVertex].v;
|
||||
|
||||
m_pVertex.push_back(AddVertex);
|
||||
WORD *AddIndices=new WORD[m_pOutHouseObject->m_nIndices[cObject]*3];
|
||||
memcpy(AddIndices,m_pOutHouseObject->m_pIndices[cObject],sizeof(WORD)*3*m_pOutHouseObject->m_nIndices[cObject]);
|
||||
m_pIndices.push_back(AddIndices);
|
||||
m_nIndices.push_back(m_pOutHouseObject->m_nIndices[cObject]);
|
||||
}
|
||||
m_pOutHouseObject->AllUnlockBuffer();
|
||||
}
|
||||
if(m_pInHouseObject)
|
||||
{
|
||||
m_pInHouseObject->AllLockBuffer();
|
||||
for(cObject=0;cObject<m_pInHouseObject->GetObjectCount();cObject++)
|
||||
{
|
||||
vector3 *AddVertex=new vector3[m_pInHouseObject->m_nVertex[cObject]];
|
||||
|
||||
MultiVertex *pVertex=(MultiVertex*)m_pInHouseObject->m_pVertex[cObject];
|
||||
for(int cVertex=0;cVertex<m_pInHouseObject->m_nVertex[cObject];cVertex++)
|
||||
AddVertex[cVertex]=pVertex[cVertex].v;
|
||||
|
||||
m_pVertex.push_back(AddVertex);
|
||||
WORD *AddIndices=new WORD[m_pInHouseObject->m_nIndices[cObject]*3];
|
||||
memcpy(AddIndices,m_pInHouseObject->m_pIndices[cObject],sizeof(WORD)*3*m_pInHouseObject->m_nIndices[cObject]);
|
||||
m_pIndices.push_back(AddIndices);
|
||||
m_nIndices.push_back(m_pInHouseObject->m_nIndices[cObject]);
|
||||
}
|
||||
m_pInHouseObject->AllUnlockBuffer();
|
||||
}
|
||||
if(m_pMedHouseObject)
|
||||
{
|
||||
m_pMedHouseObject->AllLockBuffer();
|
||||
for(cObject=0;cObject<m_pMedHouseObject->GetObjectCount();cObject++)
|
||||
{
|
||||
vector3 *AddVertex=new vector3[m_pMedHouseObject->m_nVertex[cObject]];
|
||||
|
||||
MultiVertex *pVertex=(MultiVertex*)m_pMedHouseObject->m_pVertex[cObject];
|
||||
for(int cVertex=0;cVertex<m_pMedHouseObject->m_nVertex[cObject];cVertex++)
|
||||
AddVertex[cVertex]=pVertex[cVertex].v;
|
||||
|
||||
m_pVertex.push_back(AddVertex);
|
||||
WORD *AddIndices=new WORD[m_pMedHouseObject->m_nIndices[cObject]*3];
|
||||
memcpy(AddIndices,m_pMedHouseObject->m_pIndices[cObject],sizeof(WORD)*3*m_pMedHouseObject->m_nIndices[cObject]);
|
||||
m_pIndices.push_back(AddIndices);
|
||||
m_nIndices.push_back(m_pMedHouseObject->m_nIndices[cObject]);
|
||||
}
|
||||
m_pMedHouseObject->AllUnlockBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
bool CHouseObject::LoadOut(char *strOutName)
|
||||
{
|
||||
if(m_pOutHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pOutHouseObject);
|
||||
|
||||
}
|
||||
m_pOutHouseObject = (CROSSM::CNMesh *)CSceneManager::_GetResource(CROSSM::RESOURCE_MESH,strOutName);
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CHouseObject::LoadIn(char *strInName)
|
||||
{
|
||||
if(m_pInHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pInHouseObject);
|
||||
|
||||
}
|
||||
m_pInHouseObject = (CROSSM::CNMesh *)CSceneManager::_GetResource(CROSSM::RESOURCE_MESH,strInName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CHouseObject::LoadMed(char *strMedName)
|
||||
{
|
||||
if(m_pMedHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pMedHouseObject);
|
||||
}
|
||||
m_pMedHouseObject = (CROSSM::CNMesh *)CSceneManager::_GetResource(CROSSM::RESOURCE_MESH,strMedName);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool CHouseObject::LoadFlag(char *strFlagName)
|
||||
{
|
||||
if(m_pFlagHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH, m_pFlagHouseObject);
|
||||
}
|
||||
m_pFlagHouseObject = (CROSSM::CNMesh *)CSceneManager::_GetResource(CROSSM::RESOURCE_MESH, strFlagName);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CHouseObject::LoadOctree(char *strOct)
|
||||
{
|
||||
//m_pOctree
|
||||
if(m_pOctree)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_OCTREESCENE,m_pOctree);
|
||||
}
|
||||
m_pOctree = (COctreeScene *)CSceneManager::_GetResource(CROSSM::RESOURCE_OCTREESCENE,strOct);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
bool CHouseObject::LoadLightmap(char *strName)
|
||||
{
|
||||
if(m_Lightmap)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_TEXTURE,m_Lightmap);
|
||||
}
|
||||
|
||||
m_Lightmap = (CROSSM::CNTexture *)CSceneManager::_GetResource(CROSSM::RESOURCE_TEXTURE,strName);
|
||||
m_isHaveLightmap = true;
|
||||
return true;
|
||||
|
||||
}
|
||||
bool CHouseObject::LoadInLightmap(char *strName)
|
||||
{
|
||||
if(m_InLightmap)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_TEXTURE,m_InLightmap);
|
||||
}
|
||||
|
||||
m_InLightmap = (CROSSM::CNTexture *)CSceneManager::_GetResource(CROSSM::RESOURCE_TEXTURE,strName);
|
||||
m_isHaveInLightmap = true;
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
void CHouseObject::ReleaseOut()
|
||||
{
|
||||
if(m_pOutHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pOutHouseObject);
|
||||
m_pOutHouseObject = NULL;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void CHouseObject::ReleaseIn()
|
||||
{
|
||||
if(m_pInHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pInHouseObject);
|
||||
m_pInHouseObject = NULL;
|
||||
|
||||
}
|
||||
}
|
||||
void CHouseObject::ReleaseMed()
|
||||
{
|
||||
if(m_pMedHouseObject)
|
||||
{
|
||||
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH,m_pMedHouseObject);
|
||||
m_pMedHouseObject = NULL;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CHouseObject::ReleaseFlag()
|
||||
{
|
||||
if(m_pFlagHouseObject)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_MESH, m_pFlagHouseObject);
|
||||
m_pFlagHouseObject = NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CHouseObject::ReleaseOctree()
|
||||
{
|
||||
if(m_pOctree)
|
||||
{
|
||||
CSceneManager::_ReleaseResource(CROSSM::RESOURCE_OCTREESCENE,m_pOctree);
|
||||
m_pOctree = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CHouseObject::RenderOctree(IDirect3DDevice8* pDevice)
|
||||
{
|
||||
if (m_pOctree)
|
||||
{
|
||||
m_pOctree->RenderOctreeTriangle(pDevice);
|
||||
}
|
||||
}
|
||||
143
Engine/Zalla3D Scene Class/HouseObject.h
Normal file
143
Engine/Zalla3D Scene Class/HouseObject.h
Normal file
@@ -0,0 +1,143 @@
|
||||
// HouseObject.h: interface for the CHouseObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_HOUSEOBJECT_H__F85E679D_0A78_40BA_91F8_DABE3690E8F1__INCLUDED_)
|
||||
#define AFX_HOUSEOBJECT_H__F85E679D_0A78_40BA_91F8_DABE3690E8F1__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "BaseDataDefine.h"
|
||||
#include "./NMesh.h"
|
||||
//#include "MeshObjectContainer.h"
|
||||
#include "./OctreeScene.h"
|
||||
#include "LightObjectScene.h"
|
||||
#include "ObjectScene.h"
|
||||
#include "InHouseObjectMap.h"
|
||||
#include "BspScene.h"
|
||||
#include "SectorLight.h"
|
||||
#include "NTexture.h"
|
||||
#include <vector>
|
||||
|
||||
class COctreeScene;
|
||||
|
||||
class CHouseObject
|
||||
{
|
||||
public:
|
||||
COctreeScene *m_pOctree;
|
||||
CROSSM::CNMesh *m_pInHouseObject;
|
||||
CROSSM::CNMesh *m_pMedHouseObject;
|
||||
CROSSM::CNMesh *m_pOutHouseObject;
|
||||
|
||||
CROSSM::CNMesh *m_pFlagHouseObject; // <20><><EFBFBD><EFBFBD> <20><EFBFBD>.
|
||||
|
||||
CROSSM::CNTexture *m_Lightmap;
|
||||
CROSSM::CNTexture *m_InLightmap;
|
||||
bool m_isHaveLightmap;
|
||||
bool m_isHaveInLightmap;
|
||||
bool m_bModulate2X;
|
||||
|
||||
std::vector<vector3*> m_pVertex;
|
||||
std::vector<long> m_nVertex;
|
||||
std::vector<WORD *> m_pIndices;
|
||||
std::vector<long> m_nIndices;
|
||||
|
||||
CHouseObject();
|
||||
virtual ~CHouseObject();
|
||||
|
||||
void GetPolygon();
|
||||
void CalcBox(vector3 &MinBox,vector3 &MaxBox,int iCalcObject = 0);
|
||||
void GenerateOctree();
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void GenerateLightmap(matrix matSet,matrix matHouseTM,int LightmapMode);
|
||||
void GenerateNewLightmap(int ivalue,matrix matSet,matrix matHouseTM,CSectorLight *pLights,int iLights);
|
||||
|
||||
bool LoadOut(char *strOutName);
|
||||
bool LoadIn(char *strInName);
|
||||
bool LoadMed(char *strName);
|
||||
|
||||
bool LoadFlag(char *strFlagName);
|
||||
|
||||
bool LoadOctree(char *strOct);
|
||||
|
||||
bool LoadLightmap(char *strName);
|
||||
bool LoadInLightmap(char *strName);
|
||||
|
||||
void ReleaseOut();
|
||||
void ReleaseIn();
|
||||
void ReleaseMed();
|
||||
void ReleaseFlag();
|
||||
|
||||
void ReleaseOctree();
|
||||
|
||||
|
||||
void RenderOctree(IDirect3DDevice8* pDevice);
|
||||
};
|
||||
/*
|
||||
class CHouseObject
|
||||
{
|
||||
public:
|
||||
|
||||
void RenderGlare(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
static DWORD m_dwShadowMapVertexShader;
|
||||
static DWORD m_dwShadowMapPixelShader;
|
||||
|
||||
static DWORD m_dwHouseDiffuseVertexShader;
|
||||
static DWORD m_dwHouseDiffusePixelShader;
|
||||
|
||||
static DWORD m_dwHouseSpecularVertexShader;
|
||||
static DWORD m_dwHouseSpecularPixelShader;
|
||||
|
||||
static LPDIRECT3DCUBETEXTURE8 m_pNormalizeCubeMap;
|
||||
|
||||
matrix RenderShadow(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
COctreeScene *m_pOctree;
|
||||
void GetPolygon();
|
||||
void CalcBox(vector3 &MinBox,vector3 &MaxBox,int iCalcObject = 0);
|
||||
//List<CLightObjectScene*> m_LightList;
|
||||
//List<CObjectScene*> m_ObjectList;
|
||||
void GenerateOctree();
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void GenerateLightmap(matrix matSet,matrix matHouseTM,int LightmapMode);
|
||||
void GenerateNewLightmap(int ivalue,matrix matSet,matrix matHouseTM,CSectorLight *pLights,int iLights);
|
||||
|
||||
bool SettingNight(bool bNight);
|
||||
|
||||
CROSSM::CNMesh *m_pInHouseObject;
|
||||
CROSSM::CNMesh *m_pMedHouseObject;
|
||||
CROSSM::CNMesh *m_pOutHouseObject;
|
||||
CROSSM::CNMesh *m_pLodHouseObject;
|
||||
CBspScene *m_pBspObject;
|
||||
CInHouseObjectMap *m_pInHouseMap;
|
||||
|
||||
CTexture m_Lightmap;
|
||||
CTexture m_InLightmap;
|
||||
|
||||
CTexture m_Detailmap;
|
||||
bool m_isHaveLightmap;
|
||||
bool m_isHaveInLightmap;
|
||||
|
||||
CHouseObject();
|
||||
virtual ~CHouseObject();
|
||||
|
||||
//List<vector3*> m_pVertex;
|
||||
//List<long> m_nVertex;
|
||||
//List<WORD *> m_pIndices;
|
||||
//List<long> m_nIndices;
|
||||
// Night <20><> <20><><EFBFBD><EFBFBD> <20>Ǿ<EFBFBD><C7BE><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool m_bConvertNight;
|
||||
bool m_bNightMap;
|
||||
bool m_bNightUv;
|
||||
bool m_bModulate2X;
|
||||
|
||||
// Night <20><> <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>
|
||||
//List<void *> m_pBackupVertex;
|
||||
//List<void *> m_pBackupTmp;
|
||||
CTexture m_BackupLightmap;
|
||||
|
||||
|
||||
};*/
|
||||
|
||||
#endif // !defined(AFX_HOUSEOBJECT_H__F85E679D_0A78_40BA_91F8_DABE3690E8F1__INCLUDED_)
|
||||
119
Engine/Zalla3D Scene Class/HouseObjectScene.cpp
Normal file
119
Engine/Zalla3D Scene Class/HouseObjectScene.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
// HouseObjectNode.cpp: implementation of the CHouseObjectNode class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "HouseObjectScene.h"
|
||||
#include "SceneManager.h"
|
||||
#include "ImposterScene.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
bool m_SelfLoadOut,m_SelfLoadMed,m_SelfLoadIn,m_SelfLoadInObject;
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
long m_HouseSceneID;
|
||||
CHouseObject *m_HouseObject;
|
||||
char m_strInName[MAX_NAMEBUFFER];
|
||||
char m_strMedName[MAX_NAMEBUFFER];
|
||||
char m_strOutName[MAX_NAMEBUFFER];
|
||||
|
||||
bool m_bOctree;
|
||||
bool m_bNotCull;
|
||||
bool m_bSkip;
|
||||
bool m_bMedCull;
|
||||
|
||||
CHouseObjectScene();
|
||||
virtual ~CHouseObjectScene();
|
||||
|
||||
void SetSkipFlag(bool bSkip) { m_bSkip = bSkip;}
|
||||
bool GetSkipFlag() { return m_bSkip;}
|
||||
}
|
||||
|
||||
|
||||
|
||||
*/
|
||||
CHouseObjectScene::CHouseObjectScene() : m_SelfLoadOut(false),m_SelfLoadMed(false),m_SelfLoadIn(false),m_SelfLoadInObject(false), m_bFlag(false),
|
||||
m_bOctree(false),m_bNotCull(false),m_bSkip(false),m_bMedCull(true),m_HouseObject(NULL),
|
||||
m_pImposterScene(NULL)
|
||||
{
|
||||
m_bInit = false;
|
||||
|
||||
}
|
||||
|
||||
CHouseObjectScene::~CHouseObjectScene()
|
||||
{
|
||||
if(m_HouseObject)
|
||||
{
|
||||
CROSSM::SafeDelete(m_HouseObject);
|
||||
// CSceneManager::_ReleaseObj(CROSSM::POOL_HOUSEOBJ,m_HouseObject);
|
||||
m_HouseObject = NULL;
|
||||
}
|
||||
|
||||
CImposterScene::DeleteScene( m_pImposterScene );
|
||||
m_pImposterScene = NULL;
|
||||
}
|
||||
|
||||
void CHouseObjectScene::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
if(isCulling()==false || m_bSkip || !m_HouseObject)
|
||||
return;
|
||||
|
||||
/*
|
||||
vector3 vPos;
|
||||
CSceneManager::m_CharacterManager.m_CharacterList[0].m_pChrmodel->GetPosition( vPos.x, vPos.y, vPos.z );
|
||||
D3DXVECTOR3 vCharPos = D3DXVECTOR3( vPos.x, vPos.y, vPos.z );
|
||||
D3DXVECTOR3 vHousePos = D3DXVECTOR3( m_AccumulateTM._41, m_AccumulateTM._42, m_AccumulateTM._43 );
|
||||
D3DXVECTOR3 vCharToHouseDir = vHousePos - vCharPos;
|
||||
float fDist = D3DXVec3Length( &vCharToHouseDir );
|
||||
|
||||
if( CImposterScene::IsRenderEnable(fDist, m_fRad) )
|
||||
{
|
||||
if( !m_pImposterScene )
|
||||
{
|
||||
m_pImposterScene = CImposterScene::GetScene( this );
|
||||
}
|
||||
|
||||
if( m_pImposterScene )
|
||||
{
|
||||
CImposterScene::PushRenderScene( m_pImposterScene, vCharPos, vHousePos );
|
||||
return;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if( CImposterScene::IsActivated() )
|
||||
{
|
||||
vector3 vPos;
|
||||
CSceneManager::m_CharacterManager.m_CharacterList[0].m_pChrmodel->GetPosition( vPos.x, vPos.y, vPos.z );
|
||||
D3DXVECTOR3 vCharPos = D3DXVECTOR3( vPos.x, vPos.y, vPos.z );
|
||||
D3DXVECTOR3 vHousePos = D3DXVECTOR3( m_AccumulateTM._41, m_AccumulateTM._42, m_AccumulateTM._43 );
|
||||
D3DXVECTOR3 vCharToHouseDir = vHousePos - vCharPos;
|
||||
float fDist = D3DXVec3Length( &vCharToHouseDir );
|
||||
|
||||
if( CImposterScene::IsRenderEnable(fDist, this) )
|
||||
{
|
||||
if( !m_pImposterScene )
|
||||
{
|
||||
m_pImposterScene = CImposterScene::GetScene( this );
|
||||
}
|
||||
|
||||
if( m_pImposterScene )
|
||||
{
|
||||
m_pImposterScene->Render( vCharPos, vHousePos );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)&m_AccumulateTM);
|
||||
m_HouseObject->Render(pd3dDevice);
|
||||
|
||||
// Octree <20><><EFBFBD><EFBFBD>. Octree <20><><EFBFBD><EFBFBD> Ȯ<><C8AE><EFBFBD>Ҷ<EFBFBD> on
|
||||
//m_HouseObject->RenderOctree(pd3dDevice);
|
||||
}
|
||||
|
||||
|
||||
|
||||
82
Engine/Zalla3D Scene Class/HouseObjectScene.h
Normal file
82
Engine/Zalla3D Scene Class/HouseObjectScene.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// HouseObjectNode.h: interface for the CHouseObjectNode class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_HOUSEOBJECTNODE_H__DF571E5D_B6EA_4B04_8378_47CAFBC9F04B__INCLUDED_)
|
||||
#define AFX_HOUSEOBJECTNODE_H__DF571E5D_B6EA_4B04_8378_47CAFBC9F04B__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SceneNode.h"
|
||||
#include "HouseObject.h"
|
||||
|
||||
class CImposterScene;
|
||||
|
||||
class CHouseObjectScene : public CSceneNode
|
||||
{
|
||||
public:
|
||||
bool m_SelfLoadOut,m_SelfLoadMed,m_SelfLoadIn,m_SelfLoadInObject;
|
||||
|
||||
long m_HouseSceneID;
|
||||
CHouseObject *m_HouseObject;
|
||||
|
||||
char m_strInName[MAX_NAMEBUFFER];
|
||||
char m_strMedName[MAX_NAMEBUFFER];
|
||||
char m_strOutName[MAX_NAMEBUFFER];
|
||||
char m_strFlag[MAX_NAMEBUFFER];
|
||||
|
||||
bool m_bOctree;
|
||||
bool m_bNotCull;
|
||||
bool m_bSkip;
|
||||
bool m_bMedCull;
|
||||
bool m_bInit;
|
||||
|
||||
bool m_bFlag;
|
||||
|
||||
CImposterScene* m_pImposterScene;
|
||||
|
||||
CHouseObjectScene();
|
||||
virtual ~CHouseObjectScene();
|
||||
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
|
||||
void SetSkipFlag(bool bSkip) { m_bSkip = bSkip;}
|
||||
bool GetSkipFlag() { return m_bSkip;}
|
||||
|
||||
void SetFlag(bool bFlag) { m_bFlag = bFlag; }
|
||||
bool GetFlag(void) { return m_bFlag; }
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
class CHouseObjectScene : public CSceneNode
|
||||
{
|
||||
public:
|
||||
void RenderGlare(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void DeleteBspPosition();
|
||||
void UpdateBspPosition();
|
||||
bool m_SelfLoadOut,m_SelfLoadMed,m_SelfLoadIn,m_SelfLoadInObject;
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
long m_HouseSceneID;
|
||||
CHouseObject *m_HouseObject;
|
||||
char m_strInName[MAX_NAMEBUFFER];
|
||||
char m_strMedName[MAX_NAMEBUFFER];
|
||||
char m_strOutName[MAX_NAMEBUFFER];
|
||||
char m_strBSPName[MAX_NAMEBUFFER];
|
||||
bool m_bOctree;
|
||||
bool m_bNotCull;
|
||||
bool m_bSkip;
|
||||
bool m_bMedCull;
|
||||
|
||||
CHouseObjectScene();
|
||||
virtual ~CHouseObjectScene();
|
||||
|
||||
void SetSkipFlag(bool bSkip) { m_bSkip = bSkip;}
|
||||
bool GetSkipFlag() { return m_bSkip;}
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
#endif // !defined(AFX_HOUSEOBJECTNODE_H__DF571E5D_B6EA_4B04_8378_47CAFBC9F04B__INCLUDED_)
|
||||
372
Engine/Zalla3D Scene Class/ImposterScene.cpp
Normal file
372
Engine/Zalla3D Scene Class/ImposterScene.cpp
Normal file
@@ -0,0 +1,372 @@
|
||||
#include ".\imposterscene.h"
|
||||
#include "BaseGraphicsLayer.h"
|
||||
#include "SceneManager.h"
|
||||
#include "NTexture.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
using namespace CROSSM;
|
||||
|
||||
struct ImposterVertex
|
||||
{
|
||||
enum { FVF = D3DFVF_XYZ|D3DFVF_TEX1 };
|
||||
D3DXVECTOR3 p;
|
||||
float u, v;
|
||||
};
|
||||
|
||||
CImposterScene* CImposterScene::ms_pScenesPool[IMP_TOTALSCENE_NUM];
|
||||
CImposterScene::COUNT_QUEUE CImposterScene::ms_UnusedSceneQueue;
|
||||
LPDIRECT3DTEXTURE8 CImposterScene::ms_pSceneTexture[IMP_LTEXTURE_NUM];
|
||||
LPDIRECT3DSURFACE8 CImposterScene::ms_pSceneZBuffer[IMP_LTEXTURE_NUM];
|
||||
LPDIRECT3DSURFACE8 CImposterScene::ms_pSceneSurface[IMP_LTEXTURE_NUM];
|
||||
LPDIRECT3DSURFACE8 CImposterScene::ms_pTempZBuffer;
|
||||
LPDIRECT3DSURFACE8 CImposterScene::ms_pTempSurface;
|
||||
D3DVIEWPORT8 CImposterScene::ms_TempViewport;
|
||||
float CImposterScene::ms_fViewRatio = 550.0f; //<2F><><EFBFBD><EFBFBD> Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD>̴<EFBFBD> <20><><EFBFBD>־<EFBFBD><D6BE><EFBFBD> Ŀ<><C4BF>
|
||||
float CImposterScene::ms_fViewDist = 20000.0f; //<2F>Ÿ<EFBFBD> <20><><EFBFBD>Ѱ<EFBFBD>
|
||||
bool CImposterScene::ms_bActivate;
|
||||
|
||||
CImposterScene::CImposterScene( int nIndex ) : m_nIndex(nIndex), m_vOldCamToScene(D3DXVECTOR3(0, 0, 0)), m_pSrcScene(NULL)
|
||||
{
|
||||
m_nTextureIndex = nIndex / IMP_PERTEXTURE_SCENE_NUM;
|
||||
int nTemp = m_nIndex % IMP_PERTEXTURE_SCENE_NUM;
|
||||
m_ViewPort.Width = IMP_STEXTURE_SIZE;
|
||||
m_ViewPort.Height = IMP_STEXTURE_SIZE;
|
||||
m_ViewPort.MinZ = 0;
|
||||
m_ViewPort.MaxZ = 1;
|
||||
m_ViewPort.X = (nTemp % (IMP_LTEXTURE_SIZE/IMP_STEXTURE_SIZE)) * IMP_STEXTURE_SIZE;
|
||||
m_ViewPort.Y = (nTemp / (IMP_LTEXTURE_SIZE/IMP_STEXTURE_SIZE)) * IMP_STEXTURE_SIZE;
|
||||
}
|
||||
|
||||
CImposterScene::~CImposterScene()
|
||||
{
|
||||
}
|
||||
|
||||
bool CImposterScene::Init()
|
||||
{
|
||||
LPDIRECT3DDEVICE8 pDevice = BaseGraphicsLayer::GetDevice();
|
||||
|
||||
int i;
|
||||
HRESULT hr;
|
||||
|
||||
for( i = 0; i < IMP_LTEXTURE_NUM; i++ )
|
||||
{
|
||||
hr = pDevice->CreateTexture( IMP_LTEXTURE_SIZE, IMP_LTEXTURE_SIZE, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, //BaseGraphicsLayer::m_d3dpp.BackBufferFormat,
|
||||
D3DPOOL_DEFAULT, &ms_pSceneTexture[i] );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
// MessageBox( 0, "<22>ؽ<EFBFBD>ó <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> : imposter", "Error", 0 );
|
||||
return false;
|
||||
}
|
||||
|
||||
hr = ms_pSceneTexture[i]->GetSurfaceLevel( 0, &ms_pSceneSurface[i] );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
Shutdown();
|
||||
MessageBox( 0, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> : imposter", "Error", 0 );
|
||||
return false;
|
||||
}
|
||||
|
||||
pDevice->CreateDepthStencilSurface( IMP_LTEXTURE_SIZE, IMP_LTEXTURE_SIZE, BaseGraphicsLayer::m_d3dpp.AutoDepthStencilFormat,
|
||||
D3DMULTISAMPLE_NONE, &ms_pSceneZBuffer[i] );
|
||||
if( FAILED(hr) )
|
||||
{
|
||||
Shutdown();
|
||||
MessageBox( 0, "Z<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> : imposter", "Error", 0 );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for( i = 0; i < IMP_TOTALSCENE_NUM; i++ )
|
||||
{
|
||||
ms_pScenesPool[i] = new CImposterScene(i);
|
||||
}
|
||||
|
||||
while( !ms_UnusedSceneQueue.empty() )
|
||||
{
|
||||
ms_UnusedSceneQueue.pop();
|
||||
}
|
||||
|
||||
for( i = 0; i < IMP_TOTALSCENE_NUM; i++ )
|
||||
{
|
||||
ms_UnusedSceneQueue.push(i);
|
||||
}
|
||||
|
||||
ms_bActivate = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CImposterScene::Shutdown()
|
||||
{
|
||||
for( int i = 0; i < IMP_LTEXTURE_NUM; i++ )
|
||||
{
|
||||
SAFE_RELEASE( ms_pSceneTexture[i] );
|
||||
SAFE_RELEASE( ms_pSceneZBuffer[i] );
|
||||
SAFE_RELEASE( ms_pSceneSurface[i] );
|
||||
}
|
||||
|
||||
for(int i = 0; i < IMP_TOTALSCENE_NUM; i++ )
|
||||
{
|
||||
SAFE_DELETE( ms_pScenesPool[i] );
|
||||
}
|
||||
|
||||
ms_bActivate = false;
|
||||
}
|
||||
|
||||
CImposterScene* CImposterScene::GetScene( CHouseObjectScene* pScene )
|
||||
{
|
||||
if( ms_bActivate == false || ms_UnusedSceneQueue.empty() )
|
||||
return NULL;
|
||||
|
||||
int nCount = ms_UnusedSceneQueue.front();
|
||||
ms_UnusedSceneQueue.pop();
|
||||
|
||||
CImposterScene* pImposter = ms_pScenesPool[nCount];
|
||||
pImposter->m_pSrcScene = pScene;
|
||||
|
||||
return pImposter;
|
||||
}
|
||||
|
||||
void CImposterScene::DeleteScene( CImposterScene* pScene )
|
||||
{
|
||||
if( pScene && ms_bActivate )
|
||||
{
|
||||
pScene->Clear();
|
||||
ms_UnusedSceneQueue.push( pScene->m_nIndex );
|
||||
}
|
||||
}
|
||||
|
||||
void CImposterScene::SetViewRatio( float f )
|
||||
{
|
||||
ms_fViewRatio = f;
|
||||
}
|
||||
|
||||
float CImposterScene::GetViewRatio()
|
||||
{
|
||||
return ms_fViewRatio;
|
||||
}
|
||||
|
||||
void CImposterScene::Render( D3DXVECTOR3& vCamPos, D3DXVECTOR3& vScenePos )
|
||||
{
|
||||
//<2F>ؽ<EFBFBD><D8BD>ĸ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ٷ<EFBFBD> <20><EFBFBD><D7B8><EFBFBD> <20>ʰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD> <20><EFBFBD><D7B8><EFBFBD>
|
||||
if( GenerateRenderTexture(vCamPos, vScenePos) ) return;
|
||||
|
||||
LPDIRECT3DDEVICE8 pDevice = BaseGraphicsLayer::GetDevice();
|
||||
|
||||
//Set RenderState !!
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTA_TEXTURE );
|
||||
pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
|
||||
pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
|
||||
pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
|
||||
pDevice->SetRenderState( D3DRS_ALPHAREF, 0xee );
|
||||
pDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
|
||||
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
||||
|
||||
pDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
|
||||
pDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
|
||||
|
||||
ImposterVertex Quad[4];
|
||||
Quad[0].p = D3DXVECTOR3( -m_pSrcScene->m_fRad, m_pSrcScene->m_fRad, 0 );
|
||||
Quad[0].u = (float)m_ViewPort.X / (float)IMP_LTEXTURE_SIZE;
|
||||
Quad[0].v = (float)m_ViewPort.Y / (float)IMP_LTEXTURE_SIZE;
|
||||
Quad[1].p = D3DXVECTOR3( m_pSrcScene->m_fRad, m_pSrcScene->m_fRad, 0 );
|
||||
Quad[1].u = ((float)m_ViewPort.X + (float)m_ViewPort.Width) / (float)IMP_LTEXTURE_SIZE;
|
||||
Quad[1].v = (float)m_ViewPort.Y / (float)IMP_LTEXTURE_SIZE;
|
||||
Quad[2].p = D3DXVECTOR3( -m_pSrcScene->m_fRad, -m_pSrcScene->m_fRad, 0 );
|
||||
Quad[2].u = (float)m_ViewPort.X / (float)IMP_LTEXTURE_SIZE;
|
||||
Quad[2].v = ((float)m_ViewPort.Y + (float)m_ViewPort.Height) / (float)IMP_LTEXTURE_SIZE;
|
||||
Quad[3].p = D3DXVECTOR3( m_pSrcScene->m_fRad, -m_pSrcScene->m_fRad, 0 );
|
||||
Quad[3].u = ((float)m_ViewPort.X + (float)m_ViewPort.Width) / (float)IMP_LTEXTURE_SIZE;
|
||||
Quad[3].v = ((float)m_ViewPort.Y + (float)m_ViewPort.Height) / (float)IMP_LTEXTURE_SIZE;
|
||||
|
||||
//Set RenderState
|
||||
pDevice->SetTexture( 0, ms_pSceneTexture[m_nTextureIndex] );
|
||||
|
||||
//DrawPrimitive
|
||||
D3DXMATRIX mBillboard;
|
||||
D3DXMatrixIdentity( &mBillboard );
|
||||
mBillboard._11 = CSceneManager::m_ViewCamera->GetMatView()->_11;
|
||||
mBillboard._13 = CSceneManager::m_ViewCamera->GetMatView()->_13;
|
||||
mBillboard._31 = CSceneManager::m_ViewCamera->GetMatView()->_31;
|
||||
mBillboard._33 = CSceneManager::m_ViewCamera->GetMatView()->_33;
|
||||
D3DXMatrixInverse( &mBillboard, NULL, &mBillboard );
|
||||
mBillboard._41 = m_pSrcScene->m_AccumulateTM._41;
|
||||
mBillboard._42 = m_pSrcScene->m_AccumulateTM._42;
|
||||
mBillboard._43 = m_pSrcScene->m_AccumulateTM._43;
|
||||
pDevice->SetVertexShader( ImposterVertex::FVF );
|
||||
pDevice->SetTransform( D3DTS_WORLD, &mBillboard );
|
||||
pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, Quad, sizeof(ImposterVertex) );
|
||||
pDevice->SetVertexShader(NULL);
|
||||
|
||||
//Back RenderState
|
||||
pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
|
||||
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
pDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
pDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
|
||||
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
|
||||
pDevice->SetRenderState( D3DRS_LIGHTING,TRUE);
|
||||
}
|
||||
|
||||
void CImposterScene::BeginImposter()
|
||||
{
|
||||
LPDIRECT3DDEVICE8 pDevice = BaseGraphicsLayer::GetDevice();
|
||||
pDevice->GetViewport( &ms_TempViewport );
|
||||
pDevice->GetRenderTarget( &ms_pTempSurface );
|
||||
pDevice->GetDepthStencilSurface( &ms_pTempZBuffer );
|
||||
pDevice->SetRenderTarget( ms_pSceneSurface[m_nTextureIndex], ms_pSceneZBuffer[m_nTextureIndex] );
|
||||
pDevice->EndScene();
|
||||
|
||||
D3DRECT rect;
|
||||
rect.x1 = m_ViewPort.X;
|
||||
rect.y1 = m_ViewPort.Y;
|
||||
rect.x2 = m_ViewPort.X + m_ViewPort.Width;
|
||||
rect.y2 = m_ViewPort.Y + m_ViewPort.Height;
|
||||
pDevice->Clear( 1, &rect, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00, 1.0f, 0 );
|
||||
pDevice->BeginScene();
|
||||
}
|
||||
|
||||
void CImposterScene::EndImposter()
|
||||
{
|
||||
LPDIRECT3DDEVICE8 pDevice = BaseGraphicsLayer::GetDevice();
|
||||
pDevice->EndScene();
|
||||
|
||||
pDevice->SetRenderTarget( ms_pTempSurface, ms_pTempZBuffer );
|
||||
pDevice->SetViewport( &ms_TempViewport );
|
||||
SAFE_RELEASE( ms_pTempZBuffer );
|
||||
SAFE_RELEASE( ms_pTempSurface );
|
||||
|
||||
pDevice->BeginScene();
|
||||
}
|
||||
|
||||
bool CImposterScene::GenerateRenderTexture( D3DXVECTOR3& vCamPos, D3DXVECTOR3& vScenePos )
|
||||
{
|
||||
D3DXVECTOR3 vCamToScene = vScenePos - vCamPos;
|
||||
D3DXVec3Normalize( &vCamToScene, &vCamToScene );
|
||||
if( D3DXVec3Dot(&m_vOldCamToScene, &vCamToScene) > 0.5f ) return false;
|
||||
|
||||
static int nLoadSchedule;
|
||||
++nLoadSchedule;
|
||||
if( nLoadSchedule % 5 != 0 ) return false;
|
||||
|
||||
//<2F><><EFBFBD>ż<EFBFBD><C5BC><EFBFBD> <20><EFBFBD><DEBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʱ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><CEB5><EFBFBD> <20>ٵɶ<D9B5><C9B6><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ٸ<EFBFBD><D9B8><EFBFBD>
|
||||
int nCompleteLoad = 0;
|
||||
|
||||
// 2005/01/06 yundi. CHouseObjectScene::m_HouseObject <20><> NULL <20><> <20><><EFBFBD><EFBFBD> ó<><C3B3>
|
||||
if( NULL == m_pSrcScene->m_HouseObject ||
|
||||
NULL == m_pSrcScene->m_HouseObject->m_pOutHouseObject ||
|
||||
false == m_pSrcScene->m_HouseObject->m_pOutHouseObject->IsLoaded() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int i = 0; i < (int)m_pSrcScene->m_HouseObject->m_pOutHouseObject->m_pMat.size(); ++i )
|
||||
{
|
||||
CNTexture* pTex = m_pSrcScene->m_HouseObject->m_pOutHouseObject->m_pMat[i];
|
||||
if( pTex->IsLoaded() )
|
||||
{
|
||||
++nCompleteLoad;
|
||||
}
|
||||
}
|
||||
if( nCompleteLoad < (int)m_pSrcScene->m_HouseObject->m_pOutHouseObject->m_pMat.size() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_vOldCamToScene = vCamToScene;
|
||||
|
||||
LPDIRECT3DDEVICE8 pd3dDevice = BaseGraphicsLayer::GetDevice();
|
||||
D3DXMATRIX mView, mSaveView;
|
||||
D3DXMatrixIdentity( &mView );
|
||||
D3DXMatrixLookAtLH( &mView, &vCamPos, &vScenePos, &D3DXVECTOR3(0, 1, 0) );
|
||||
pd3dDevice->GetTransform( D3DTS_VIEW, &mSaveView );
|
||||
pd3dDevice->SetTransform( D3DTS_VIEW, &mView );
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,(D3DMATRIX*)&m_pSrcScene->m_AccumulateTM);
|
||||
|
||||
D3DXMATRIX mProj, mSaveProj;
|
||||
D3DXMatrixOrthoLH( &mProj, m_pSrcScene->m_fRad*2, m_pSrcScene->m_fRad*2, 1.0f, 100000.0f);
|
||||
pd3dDevice->GetTransform( D3DTS_PROJECTION, &mSaveProj );
|
||||
pd3dDevice->SetTransform( D3DTS_PROJECTION, &mProj );
|
||||
|
||||
BeginImposter();
|
||||
pd3dDevice->SetViewport( &m_ViewPort );
|
||||
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2 );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
|
||||
pd3dDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0xee );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
|
||||
pd3dDevice->SetRenderState( D3DRS_LIGHTING,TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, 0xFFFFFFFF );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_COLORWRITEENABLE, 0x0000000F );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
|
||||
m_pSrcScene->m_HouseObject->Render( pd3dDevice );
|
||||
EndImposter();
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
|
||||
pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
|
||||
pd3dDevice->SetTransform( D3DTS_VIEW, &mSaveView );
|
||||
pd3dDevice->SetTransform( D3DTS_PROJECTION, &mSaveProj );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_FOGENABLE, TRUE );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int CImposterScene::GetSceneNum()
|
||||
{
|
||||
return IMP_TOTALSCENE_NUM - ms_UnusedSceneQueue.size();
|
||||
}
|
||||
|
||||
void CImposterScene::Clear()
|
||||
{
|
||||
memset( m_vOldCamToScene, 0, sizeof(D3DXVECTOR3) );
|
||||
m_pSrcScene = NULL;
|
||||
}
|
||||
|
||||
void CImposterScene::SetViewDistance( float f )
|
||||
{
|
||||
ms_fViewDist = f;
|
||||
}
|
||||
|
||||
float CImposterScene::GetViewDistance()
|
||||
{
|
||||
return ms_fViewDist;
|
||||
}
|
||||
|
||||
bool CImposterScene::IsRenderEnable( float fDist, CHouseObjectScene* pScene )
|
||||
{
|
||||
if( ms_bActivate == false )
|
||||
return false;
|
||||
|
||||
if( fDist > ms_fViewDist &&
|
||||
pScene->m_fRad*pScene->m_fRad/fDist < ms_fViewRatio )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CImposterScene::IsActivated()
|
||||
{
|
||||
return ms_bActivate;
|
||||
}
|
||||
61
Engine/Zalla3D Scene Class/ImposterScene.h
Normal file
61
Engine/Zalla3D Scene Class/ImposterScene.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "RenderTexture.h"
|
||||
#include "HouseObjectScene.h"
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
|
||||
const int IMP_LTEXTURE_NUM = 1;
|
||||
const int IMP_LTEXTURE_SIZE = 1024;
|
||||
const int IMP_STEXTURE_SIZE = 64;
|
||||
const int IMP_PERTEXTURE_SCENE_NUM = (IMP_LTEXTURE_SIZE/IMP_STEXTURE_SIZE)*(IMP_LTEXTURE_SIZE/IMP_STEXTURE_SIZE);
|
||||
const int IMP_TOTALSCENE_NUM = IMP_PERTEXTURE_SCENE_NUM*IMP_LTEXTURE_NUM;
|
||||
|
||||
class CImposterScene
|
||||
{
|
||||
typedef std::queue<int> COUNT_QUEUE;
|
||||
|
||||
public:
|
||||
static CImposterScene* ms_pScenesPool[IMP_TOTALSCENE_NUM];
|
||||
static COUNT_QUEUE ms_UnusedSceneQueue;
|
||||
static LPDIRECT3DTEXTURE8 ms_pSceneTexture[IMP_LTEXTURE_NUM];
|
||||
static LPDIRECT3DSURFACE8 ms_pSceneZBuffer[IMP_LTEXTURE_NUM];
|
||||
static LPDIRECT3DSURFACE8 ms_pSceneSurface[IMP_LTEXTURE_NUM];
|
||||
static LPDIRECT3DSURFACE8 ms_pTempZBuffer;
|
||||
static LPDIRECT3DSURFACE8 ms_pTempSurface;
|
||||
static D3DVIEWPORT8 ms_TempViewport;
|
||||
static float ms_fViewRatio;
|
||||
static float ms_fViewDist;
|
||||
static bool ms_bActivate;
|
||||
|
||||
int m_nIndex;
|
||||
int m_nTextureIndex;
|
||||
D3DXVECTOR3 m_vOldCamToScene;
|
||||
CHouseObjectScene* m_pSrcScene;
|
||||
D3DVIEWPORT8 m_ViewPort;
|
||||
|
||||
private:
|
||||
CImposterScene( int nIndex );
|
||||
virtual ~CImposterScene();
|
||||
void BeginImposter();
|
||||
void EndImposter();
|
||||
bool GenerateRenderTexture( D3DXVECTOR3& vCamPos, D3DXVECTOR3& vScenePos );
|
||||
void Clear();
|
||||
|
||||
public:
|
||||
static bool Init();
|
||||
static void Shutdown();
|
||||
static CImposterScene* GetScene( CHouseObjectScene* pScene );
|
||||
static void DeleteScene( CImposterScene* pScene );
|
||||
static void SetViewRatio( float f );
|
||||
static float GetViewRatio();
|
||||
static void SetViewDistance( float f );
|
||||
static float GetViewDistance();
|
||||
static int GetSceneNum();
|
||||
static bool IsRenderEnable( float fDist, CHouseObjectScene* pScene );
|
||||
static bool IsActivated();
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Render( D3DXVECTOR3& vCamPos, D3DXVECTOR3& vScenePos );
|
||||
};
|
||||
36
Engine/Zalla3D Scene Class/InHouseObjectMap.cpp
Normal file
36
Engine/Zalla3D Scene Class/InHouseObjectMap.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// InHouseObjectMap.cpp: implementation of the CInHouseObjectMap class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "InHouseObjectMap.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CInHouseObjectMap::CInHouseObjectMap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CInHouseObjectMap::~CInHouseObjectMap()
|
||||
{
|
||||
for(int i=0;i<(int)m_strObjectNameList.size();i++)
|
||||
{
|
||||
if(m_strObjectNameList[i]) {
|
||||
delete[] m_strObjectNameList[i];
|
||||
m_strObjectNameList[i] = NULL;
|
||||
}
|
||||
}
|
||||
m_strObjectNameList.clear();
|
||||
|
||||
for(int i=0;i<(int)m_strLightNameList.size();i++)
|
||||
{
|
||||
if(m_strLightNameList[i]) {
|
||||
delete[] m_strLightNameList[i];
|
||||
m_strLightNameList[i] = NULL;
|
||||
}
|
||||
}
|
||||
m_strLightNameList.clear();
|
||||
}
|
||||
40
Engine/Zalla3D Scene Class/InHouseObjectMap.h
Normal file
40
Engine/Zalla3D Scene Class/InHouseObjectMap.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// InHouseObjectMap.h: interface for the CInHouseObjectMap class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_INHOUSEOBJECTMAP_H__EBFE3FAB_0291_4FC1_83C5_403C61804DA4__INCLUDED_)
|
||||
#define AFX_INHOUSEOBJECTMAP_H__EBFE3FAB_0291_4FC1_83C5_403C61804DA4__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "3DMath.h"
|
||||
#include "BaseDataDefine.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
class CInHouseObjectMap
|
||||
{
|
||||
public:
|
||||
char m_strInName[MAX_NAMEBUFFER];
|
||||
char m_strMedName[MAX_NAMEBUFFER];
|
||||
char m_strOutName[MAX_NAMEBUFFER];
|
||||
char m_strBspName[MAX_NAMEBUFFER];
|
||||
std::vector<char*> m_strObjectNameList;
|
||||
std::vector<matrix> m_matObjectList;
|
||||
std::vector<bool> m_isAlpha;
|
||||
std::vector<bool> m_isLight;
|
||||
std::vector<long> m_ObjectID;
|
||||
|
||||
std::vector<char*> m_strLightNameList;
|
||||
std::vector<matrix> m_matLightList;
|
||||
std::vector<float> m_fLightRange;
|
||||
std::vector<color> m_LightColor;
|
||||
std::vector<long> m_LightID;
|
||||
|
||||
CInHouseObjectMap();
|
||||
virtual ~CInHouseObjectMap();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_INHOUSEOBJECTMAP_H__EBFE3FAB_0291_4FC1_83C5_403C61804DA4__INCLUDED_)
|
||||
96
Engine/Zalla3D Scene Class/InitValue.cpp
Normal file
96
Engine/Zalla3D Scene Class/InitValue.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
// InitValue.cpp: implementation of the CInitValue class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include "InitValue.h"
|
||||
#include "BaseDataDefine.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CInitValue::CInitValue()
|
||||
{
|
||||
m_nAdapter=m_nDevice=m_nMode=0;
|
||||
m_CharShadow=m_MapShadow=m_BuildShadow=0;
|
||||
m_TerrainDetail=m_CharDetail=m_ViewRange=0;
|
||||
m_WaterReflection=m_Lensflare=m_TreeDetail=0;
|
||||
}
|
||||
|
||||
CInitValue::~CInitValue()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CInitValue::Save(HKEY &hReg)
|
||||
{
|
||||
if(!hReg) return false;
|
||||
|
||||
long lResult;
|
||||
// long lResult = RegDeleteValue(hReg, "InitValue");
|
||||
// if(lResult != ERROR_SUCCESS) return false;
|
||||
|
||||
long lRegValue[16];
|
||||
lRegValue[0] = m_lScreenX;
|
||||
lRegValue[1] = m_lScreenY;
|
||||
lRegValue[2] = m_lScreenColorDepth;
|
||||
lRegValue[3] = m_nAdapter;
|
||||
lRegValue[4] = m_nDevice;
|
||||
lRegValue[5] = m_nMode;
|
||||
lRegValue[6] = m_CharShadow;
|
||||
lRegValue[7] = m_MapShadow;
|
||||
lRegValue[8] = m_BuildShadow;
|
||||
lRegValue[9] = m_TerrainDetail;
|
||||
lRegValue[10] = m_CharDetail;
|
||||
lRegValue[11] = m_ViewRange;
|
||||
lRegValue[12] = m_WaterReflection;
|
||||
lRegValue[13] = m_Lensflare;
|
||||
lRegValue[14] = m_TreeDetail;
|
||||
lRegValue[15] = m_MaxTextureSize;
|
||||
lResult = RegSetValueEx(hReg, "InitValue", 0, REG_BINARY, (LPBYTE)&lRegValue, sizeof(lRegValue));
|
||||
if(lResult == ERROR_SUCCESS) return true;
|
||||
|
||||
return false;
|
||||
/* FILE *fp=fopen(INITVALUEFILE,"wb");
|
||||
fwrite(this,sizeof(*this),1,fp);
|
||||
fclose(fp);*/
|
||||
}
|
||||
|
||||
bool CInitValue::Load(HKEY &hReg)
|
||||
{
|
||||
if(!hReg) return false;
|
||||
|
||||
long lRegValue[16];
|
||||
unsigned long dwReadLens = sizeof(lRegValue);
|
||||
long lResult = RegQueryValueEx(hReg, "InitValue", 0, NULL, (LPBYTE)&lRegValue, &dwReadLens);
|
||||
if(lResult != ERROR_SUCCESS) return false;
|
||||
m_lScreenX = lRegValue[0];
|
||||
m_lScreenY = lRegValue[1];
|
||||
m_lScreenColorDepth = lRegValue[2];
|
||||
m_nAdapter = lRegValue[3];
|
||||
m_nDevice = lRegValue[4];
|
||||
m_nMode = lRegValue[5];
|
||||
m_CharShadow = lRegValue[6];
|
||||
m_MapShadow = lRegValue[7];
|
||||
m_BuildShadow = lRegValue[8];
|
||||
m_TerrainDetail = lRegValue[9];
|
||||
m_CharDetail = lRegValue[10];
|
||||
m_ViewRange = lRegValue[11];
|
||||
m_WaterReflection = lRegValue[12];
|
||||
m_Lensflare = lRegValue[13];
|
||||
m_TreeDetail = lRegValue[14];
|
||||
m_MaxTextureSize = lRegValue[15];
|
||||
|
||||
return true;
|
||||
/* FILE *fp=fopen(INITVALUEFILE,"rb");
|
||||
fread(this,sizeof(*this),1,fp);
|
||||
fclose(fp);*/
|
||||
}
|
||||
|
||||
void CInitValue::Init()
|
||||
{
|
||||
|
||||
}
|
||||
29
Engine/Zalla3D Scene Class/InitValue.h
Normal file
29
Engine/Zalla3D Scene Class/InitValue.h
Normal file
@@ -0,0 +1,29 @@
|
||||
// InitValue.h: interface for the CInitValue class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_INITVALUE_H__902DD191_CD4A_4EB3_BEFE_33EBF57D1257__INCLUDED_)
|
||||
#define AFX_INITVALUE_H__902DD191_CD4A_4EB3_BEFE_33EBF57D1257__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CInitValue
|
||||
{
|
||||
public:
|
||||
void Init();
|
||||
bool Load(HKEY &hReg);
|
||||
bool Save(HKEY &hReg);
|
||||
|
||||
long m_lScreenX,m_lScreenY,m_lScreenColorDepth;
|
||||
long m_nAdapter,m_nDevice,m_nMode;
|
||||
long m_CharShadow,m_MapShadow,m_BuildShadow;
|
||||
long m_TerrainDetail,m_CharDetail,m_ViewRange;
|
||||
long m_WaterReflection,m_Lensflare,m_TreeDetail;
|
||||
long m_MaxTextureSize;
|
||||
CInitValue();
|
||||
virtual ~CInitValue();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_INITVALUE_H__902DD191_CD4A_4EB3_BEFE_33EBF57D1257__INCLUDED_)
|
||||
268
Engine/Zalla3D Scene Class/InstanceObjectManager.cpp
Normal file
268
Engine/Zalla3D Scene Class/InstanceObjectManager.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
// InstanceObjectManager.cpp: implementation of the CInstanceObjectManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "InstanceObjectManager.h"
|
||||
#include "SceneManager.h"
|
||||
#include "BaseGraphicsLayer.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CInstanceObjectManager::CInstanceObjectManager()
|
||||
{
|
||||
m_TotalInstanceObjectID=0;
|
||||
}
|
||||
|
||||
CInstanceObjectManager::~CInstanceObjectManager()
|
||||
{
|
||||
DeleteAllObject();
|
||||
}
|
||||
|
||||
///// Minotaurs <20>߰<EFBFBD>
|
||||
void CInstanceObjectManager::DeleteAllObject()
|
||||
{
|
||||
m_InstanceObjectList.clear();
|
||||
}
|
||||
|
||||
void CInstanceObjectManager::InstanceObjectRotation(int InstanceObjectID,float fDist)
|
||||
{
|
||||
for(int i=0;i<(int)m_InstanceObjectList.size();i++)
|
||||
{
|
||||
if(m_InstanceObjectList[i].m_ID==InstanceObjectID)
|
||||
{
|
||||
m_InstanceObjectList[i].m_fAngle += fDist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CInstanceObjectManager::AddInstanceObject(char *strObjectName, vector3 vecPos, float fAngle)
|
||||
{
|
||||
CSceneManager::m_MeshObjectContainer.SetPath(INSTANCEOBJECTPATH);
|
||||
InstanceObjectNode AddNode;
|
||||
AddNode.m_ID=m_TotalInstanceObjectID;
|
||||
AddNode.m_Color.c=0x0;
|
||||
if(strcmp(strObjectName,"")!=0)
|
||||
{
|
||||
AddNode.m_pMeshObject=CSceneManager::m_MeshObjectContainer.GetMeshObject(strObjectName);
|
||||
AddNode.m_pMeshObject->ConvertNormal();
|
||||
}
|
||||
else
|
||||
{
|
||||
AddNode.m_pMeshObject=NULL;
|
||||
}
|
||||
AddNode.m_vecPosition=vecPos;
|
||||
AddNode.m_fAngle = fAngle;
|
||||
strcpy(AddNode.m_strMeshName,strObjectName);
|
||||
m_InstanceObjectList.push_back(AddNode);
|
||||
m_TotalInstanceObjectID++;
|
||||
return AddNode.m_ID;
|
||||
}
|
||||
|
||||
void CInstanceObjectManager::DeleteInstanceObject(int InstanceObjectID)
|
||||
{
|
||||
for(int i=0;i<(int)m_InstanceObjectList.size();i++)
|
||||
{
|
||||
if(m_InstanceObjectList[i].m_ID==InstanceObjectID)
|
||||
{
|
||||
CSceneManager::m_MeshObjectContainer.DeleteMeshObject(m_InstanceObjectList[i].m_strMeshName);
|
||||
|
||||
m_InstanceObjectList.erase(m_InstanceObjectList.begin()+i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CInstanceObjectManager::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
//pd3dDevice->CaptureStateBlock(oldStateBlock);
|
||||
//pd3dDevice->ApplyStateBlock(m_ObjectRenderStateBlock);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
|
||||
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
|
||||
|
||||
pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);
|
||||
pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
|
||||
|
||||
|
||||
pd3dDevice->LightEnable(0,TRUE);
|
||||
|
||||
pd3dDevice->LightEnable(1,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(2,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(3,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(4,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(5,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(6,FALSE);
|
||||
pd3dDevice->LightEnable(7,FALSE);
|
||||
pd3dDevice->SetRenderState(D3DRS_LIGHTING,TRUE);
|
||||
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
|
||||
|
||||
|
||||
/////
|
||||
pd3dDevice->LightEnable(0,TRUE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE2X);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_CURRENT);
|
||||
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1);
|
||||
pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
|
||||
|
||||
pd3dDevice->SetTexture(0,NULL);
|
||||
pd3dDevice->SetTexture(1,NULL);
|
||||
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,FALSE);
|
||||
|
||||
D3DMATERIAL8 mtrl;
|
||||
ZeroMemory( &mtrl, sizeof(D3DMATERIAL8) );
|
||||
mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
|
||||
mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
|
||||
mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f;
|
||||
mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
|
||||
pd3dDevice->SetMaterial( &mtrl );
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_LIGHTING,TRUE);
|
||||
|
||||
matrix matTrans, matRotation;
|
||||
matRotation.MakeIdent();
|
||||
|
||||
CSceneNode SceneNode;
|
||||
SceneNode.m_fRad=200.0f;
|
||||
float w;
|
||||
vector3 vecResult;
|
||||
D3DLIGHT8 ColorLight=CSceneManager::m_WeatherManager.m_SunLight;
|
||||
|
||||
for(int cObject=0;cObject<(int)m_InstanceObjectList.size();++cObject)
|
||||
{
|
||||
matTrans.Translation(m_InstanceObjectList[cObject].m_vecPosition);
|
||||
|
||||
///// Minotaurs <20>߰<EFBFBD>
|
||||
matRotation.Rotation(vector3(0.f,1.f,0.f),m_InstanceObjectList[cObject].m_fAngle);//Minotaurs instanceObject
|
||||
matTrans = matRotation * matTrans;
|
||||
|
||||
SceneNode.m_AccumulateTM=matTrans;
|
||||
if(SceneNode.isCulling())
|
||||
{
|
||||
if(m_InstanceObjectList[cObject].m_Color.c!=0x0)
|
||||
{
|
||||
ColorLight.Diffuse.r=(float)m_InstanceObjectList[cObject].m_Color.r/255.0f;
|
||||
ColorLight.Diffuse.g=(float)m_InstanceObjectList[cObject].m_Color.g/255.0f;;
|
||||
ColorLight.Diffuse.b=(float)m_InstanceObjectList[cObject].m_Color.b/255.0f;;
|
||||
pd3dDevice->SetRenderState(D3DRS_AMBIENT,m_InstanceObjectList[cObject].m_Color.c);
|
||||
pd3dDevice->SetLight(0,&ColorLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
//pd3dDevice->SetRenderState(D3DRS_AMBIENT,CSceneManager::m_WeatherManager.m_InterObjectAmbientColor.c);
|
||||
//pd3dDevice->SetRenderState(D3DRS_AMBIENT,CSceneManager::m_WeatherManager.m_InterAmbientColor.c);
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_AMBIENT,0xffcccccc);
|
||||
pd3dDevice->SetLight(0,&CSceneManager::m_WeatherManager.m_SunLight);
|
||||
}
|
||||
pd3dDevice->SetTransform(D3DTS_WORLD,matTrans);
|
||||
BaseGraphicsLayer::TransformVector(m_InstanceObjectList[cObject].m_vecPosition,vecResult,w);
|
||||
m_InstanceObjectList[cObject].m_ptMousePick.x=(int)vecResult.x;
|
||||
m_InstanceObjectList[cObject].m_ptMousePick.y=(int)vecResult.y;
|
||||
if(m_InstanceObjectList[cObject].m_pMeshObject)
|
||||
m_InstanceObjectList[cObject].m_pMeshObject->Render(pd3dDevice);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_InstanceObjectList[cObject].m_ptMousePick.x=m_InstanceObjectList[cObject].m_ptMousePick.y=-1;
|
||||
}
|
||||
}
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE,FALSE);
|
||||
//pd3dDevice->ApplyStateBlock(oldStateBlock);
|
||||
}
|
||||
|
||||
void CInstanceObjectManager::Create(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
/* pd3dDevice->CreateStateBlock(D3DSBT_ALL,&m_ObjectRenderStateBlock);
|
||||
|
||||
pd3dDevice->BeginStateBlock();
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
|
||||
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_TEXTURE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);
|
||||
pd3dDevice->SetTextureStageState(0,D3DTSS_ALPHAARG2,D3DTA_DIFFUSE);
|
||||
|
||||
pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE);
|
||||
pd3dDevice->SetTextureStageState(1,D3DTSS_ALPHAOP,D3DTOP_DISABLE);
|
||||
|
||||
|
||||
pd3dDevice->LightEnable(0,TRUE);
|
||||
|
||||
pd3dDevice->LightEnable(1,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(2,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(3,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(4,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(5,FALSE);
|
||||
|
||||
pd3dDevice->LightEnable(6,FALSE);
|
||||
pd3dDevice->LightEnable(7,FALSE);
|
||||
pd3dDevice->SetRenderState(D3DRS_LIGHTING,TRUE);
|
||||
pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
|
||||
/*
|
||||
pd3dDevice->SetLight(0,&CSceneManager::m_WeatherManager.m_SunLight);
|
||||
pd3dDevice->SetRenderState(D3DRS_AMBIENT,CSceneManager::m_WeatherManager.m_AmbientColor->c);
|
||||
*/
|
||||
// pd3dDevice->EndStateBlock(&m_ObjectRenderStateBlock);
|
||||
}
|
||||
|
||||
int CInstanceObjectManager::MouseOnCheckInstanceObject(int px, int py)
|
||||
{
|
||||
for(int i=0;i<(int)m_InstanceObjectList.size();i++)
|
||||
{
|
||||
if(m_InstanceObjectList[i].m_ptMousePick.x!=-1)
|
||||
{
|
||||
if( m_InstanceObjectList[i].m_ptMousePick.x > px-30 &&
|
||||
m_InstanceObjectList[i].m_ptMousePick.x < px+30 &&
|
||||
m_InstanceObjectList[i].m_ptMousePick.y > py-30 &&
|
||||
m_InstanceObjectList[i].m_ptMousePick.y < py+30)
|
||||
{
|
||||
return m_InstanceObjectList[i].m_ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CInstanceObjectManager::SetInstanceObjectColor(int ID, color Color)
|
||||
{
|
||||
for(int i=0;i<(int)m_InstanceObjectList.size();i++)
|
||||
{
|
||||
if(m_InstanceObjectList[i].m_ID==ID)
|
||||
{
|
||||
m_InstanceObjectList[i].m_Color=Color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CInstanceObjectManager::SetAllObjectColor(color Color)
|
||||
{
|
||||
for(int i=0;i<(int)m_InstanceObjectList.size();i++)
|
||||
{
|
||||
m_InstanceObjectList[i].m_Color=Color;
|
||||
}
|
||||
}
|
||||
50
Engine/Zalla3D Scene Class/InstanceObjectManager.h
Normal file
50
Engine/Zalla3D Scene Class/InstanceObjectManager.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// InstanceObjectManager.h: interface for the CInstanceObjectManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_INSTANCEOBJECTMANAGER_H__6B3FA12E_A24E_49BC_8887_79BD0D6F0C70__INCLUDED_)
|
||||
#define AFX_INSTANCEOBJECTMANAGER_H__6B3FA12E_A24E_49BC_8887_79BD0D6F0C70__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "3DMath.h"
|
||||
#include <vector>
|
||||
#include "MeshObject.h"
|
||||
|
||||
class CInstanceObjectManager
|
||||
{
|
||||
class InstanceObjectNode
|
||||
{
|
||||
public:
|
||||
CMeshObject *m_pMeshObject;
|
||||
vector3 m_vecPosition;
|
||||
POINT m_ptMousePick;
|
||||
char m_strMeshName[256];
|
||||
int m_ID;
|
||||
color m_Color;
|
||||
float m_fAngle;
|
||||
};
|
||||
DWORD m_ObjectRenderStateBlock;
|
||||
public:
|
||||
void SetAllObjectColor(color Color);
|
||||
void SetInstanceObjectColor(int ID,color Color);
|
||||
int MouseOnCheckInstanceObject(int px,int py);
|
||||
void Create(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
long m_TotalInstanceObjectID;
|
||||
std::vector<InstanceObjectNode> m_InstanceObjectList;
|
||||
void DeleteInstanceObject(int InstanceObjectID);
|
||||
int AddInstanceObject(char *strObjectName,vector3 vecPos, float fAngle = 0.0f);
|
||||
|
||||
///// Minotaurs <20>߰<EFBFBD>
|
||||
void DeleteAllObject();
|
||||
void InstanceObjectRotation(int InstanceObjectID,float fDist = 0.0f);
|
||||
|
||||
CInstanceObjectManager();
|
||||
virtual ~CInstanceObjectManager();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_INSTANCEOBJECTMANAGER_H__6B3FA12E_A24E_49BC_8887_79BD0D6F0C70__INCLUDED_)
|
||||
196
Engine/Zalla3D Scene Class/LayerFogScene.cpp
Normal file
196
Engine/Zalla3D Scene Class/LayerFogScene.cpp
Normal file
@@ -0,0 +1,196 @@
|
||||
// LayerFogScene.cpp: implementation of the CLayerFogScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "LayerFogScene.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CLayerFogScene::CLayerFogScene()
|
||||
{
|
||||
m_pFogVertexBuffer=NULL;
|
||||
}
|
||||
|
||||
CLayerFogScene::~CLayerFogScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CLayerFogScene::Create()
|
||||
{
|
||||
m_FogTexture.CreateEmpty(SIZE_FOGTEXTURE,SIZE_FOGTEXTURE);
|
||||
|
||||
CSceneManager::GetDevice()->CreateVertexBuffer( sizeof(MultiVertex)*4,
|
||||
D3DUSAGE_WRITEONLY,MultiFVF,D3DPOOL_MANAGED,
|
||||
&m_pFogVertexBuffer);
|
||||
MultiVertex *pFogVertex;
|
||||
m_pFogVertexBuffer->Lock( 0, 0, (BYTE**)&pFogVertex, 0 );
|
||||
pFogVertex[0].v.x=0.0f;
|
||||
pFogVertex[0].v.z=0.0f;
|
||||
pFogVertex[0].diff.c=0xffffffff;
|
||||
pFogVertex[0].spec.c=0x0;
|
||||
pFogVertex[0].v.y=fFogHeight+fFogAddHeight;
|
||||
pFogVertex[0].tu=0.0f;
|
||||
pFogVertex[0].tv=0.0f;
|
||||
|
||||
pFogVertex[1].v.x=SECTORSIZE;
|
||||
pFogVertex[1].v.z=0.0f;
|
||||
pFogVertex[1].diff.c=0xffffffff;
|
||||
pFogVertex[1].spec.c=0x0;
|
||||
pFogVertex[1].v.y=fFogHeight+fFogAddHeight;
|
||||
pFogVertex[1].tu=10.0f;
|
||||
pFogVertex[1].tv=0.0f;
|
||||
|
||||
pFogVertex[2].v.x=0.0f;
|
||||
pFogVertex[2].v.z=SECTORSIZE;
|
||||
pFogVertex[2].diff.c=0xffffffff;
|
||||
pFogVertex[2].spec.c=0x0;
|
||||
pFogVertex[2].v.y=fFogHeight+fFogAddHeight;
|
||||
pFogVertex[2].tu=10.0f;
|
||||
pFogVertex[2].tv=10.0f;
|
||||
|
||||
pFogVertex[3].v.x=SECTORSIZE;
|
||||
pFogVertex[3].v.z=SECTORSIZE;
|
||||
pFogVertex[3].diff.c=0xffffffff;
|
||||
pFogVertex[3].spec.c=0x0;
|
||||
pFogVertex[3].v.y=fFogHeight+fFogAddHeight;
|
||||
pFogVertex[3].tu=0.0f;
|
||||
pFogVertex[3].tv=10.0f;
|
||||
|
||||
m_pFogVertexBuffer->Unlock();
|
||||
}
|
||||
|
||||
void CLayerFogScene::BuildFogTexture(float fMax, float fMin)
|
||||
{
|
||||
LPDIRECT3DTEXTURE8 pFogTexture;
|
||||
m_FogTexture.GetTexture()->QueryInterface(IID_IDirect3DTexture8, (void**)&pFogTexture);
|
||||
|
||||
D3DLOCKED_RECT LockedRect;
|
||||
pFogTexture->LockRect(0, &LockedRect, NULL, 0);
|
||||
float fObjectHeight=fMax-fMin;
|
||||
float fVertexHeight,fVertexRange;
|
||||
|
||||
matrix *matViewPosition=(matrix*)CSceneManager::GetCamera()->GetMatPosition();
|
||||
|
||||
vector3 vecViewPos;
|
||||
vecViewPos.x=matViewPosition->_41;
|
||||
vecViewPos.y=matViewPosition->_42;
|
||||
vecViewPos.z=matViewPosition->_43;
|
||||
color FogColor;
|
||||
|
||||
float fEyeHeight=vecViewPos.y;
|
||||
float fDeltaY,fDeltaX;
|
||||
float fFog;
|
||||
DWORD *pFog=(DWORD*)LockedRect.pBits;
|
||||
|
||||
for(int iy=0;iy<SIZE_FOGTEXTURE;iy++)
|
||||
{
|
||||
fVertexHeight=fObjectHeight*((float)iy/(float)SIZE_FOGTEXTURE)+fMin;
|
||||
for(int ix=0;ix<SIZE_FOGTEXTURE;ix++)
|
||||
{
|
||||
fVertexRange=fFogXRange*( (float)ix/(float)SIZE_FOGTEXTURE );
|
||||
if(fEyeHeight>fFogHeight)
|
||||
{
|
||||
if(fVertexHeight<fFogHeight)
|
||||
{
|
||||
fDeltaY = fFogHeight - fVertexHeight;
|
||||
fDeltaX = fVertexRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
fDeltaY=0.0f;
|
||||
fDeltaX=0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if(fVertexHeight<fFogHeight)
|
||||
{
|
||||
float fDeltaA=fFogHeight-fEyeHeight;
|
||||
float fDeltaB=fFogHeight-fVertexHeight;
|
||||
//fDeltaY = fabs(fDeltaA - fDeltaB);
|
||||
fDeltaY=0.0f;
|
||||
fDeltaX = fVertexRange;
|
||||
}
|
||||
else
|
||||
{
|
||||
//fDeltaY=(fabs(fFogHeight-fEyeHeight))*(0.5);
|
||||
//fDeltaX=fDeltaY;
|
||||
fDeltaY=0.0f;
|
||||
fDeltaX=0.0f;
|
||||
}
|
||||
}
|
||||
if(fDeltaY>fFogYRange || fDeltaX>fFogXRange)
|
||||
{
|
||||
fFog=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
fFog=fDeltaY/fFogYRange+fDeltaX/fFogXRange;
|
||||
}
|
||||
if(fFog>0.80f)
|
||||
fFog=0.80f;
|
||||
FogColor=FogColor.Interpolation(color(0,0,0),color(255,255,255),fFog);
|
||||
pFog[ix+iy*SIZE_FOGTEXTURE]=FogColor.c;
|
||||
}
|
||||
}
|
||||
pFogTexture->UnlockRect(NULL);
|
||||
pFogTexture->Release();
|
||||
}
|
||||
|
||||
void CLayerFogScene::Render(LPDIRECT3DDEVICE8 pd3dDevice)
|
||||
{
|
||||
matrix *matViewPosition=(matrix*)CSceneManager::GetCamera()->GetMatPosition();
|
||||
|
||||
vector3 vecViewPos;
|
||||
vecViewPos.x=matViewPosition->_41;
|
||||
vecViewPos.y=matViewPosition->_42;
|
||||
vecViewPos.z=matViewPosition->_43;
|
||||
if(vecViewPos.y > fFogHeight)
|
||||
return;
|
||||
float fFogDepth=fFogHeight-vecViewPos.y;
|
||||
fFogDepth=fFogDepth/fFogXRange;
|
||||
if(fFogDepth>1.0f)
|
||||
fFogDepth=1.0f;
|
||||
color FogColor=color::Interpolation(color(0,0,0),color(255,255,255),fFogDepth);
|
||||
float FogRate=fabs(vecViewPos.y-fFogHeight);
|
||||
|
||||
if(FogRate>fFogYRange)
|
||||
{
|
||||
FogRate=fFogYRange;
|
||||
}
|
||||
FogRate/=fFogYRange;
|
||||
MultiVertex *pFogVertex;
|
||||
m_pFogVertexBuffer->Lock( 0, 0, (BYTE**)&pFogVertex, 0 );
|
||||
pFogVertex[0].diff.a=(COLORVALUE)(FogRate*(0xff*0.8f));
|
||||
pFogVertex[1].diff.a=(COLORVALUE)(FogRate*(0xff*0.8f));
|
||||
pFogVertex[2].diff.a=(COLORVALUE)(FogRate*(0xff*0.8f));
|
||||
pFogVertex[3].diff.a=(COLORVALUE)(FogRate*(0xff*0.8f));
|
||||
|
||||
pFogVertex[0].tu+=0.0002f;
|
||||
pFogVertex[1].tu+=0.0002f;
|
||||
pFogVertex[2].tu+=0.0002f;
|
||||
pFogVertex[3].tu+=0.0002f;
|
||||
|
||||
m_pFogVertexBuffer->Unlock();
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE | D3DTA_COMPLEMENT );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
|
||||
pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
|
||||
pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
|
||||
pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
|
||||
pd3dDevice->SetStreamSource(0, m_pFogVertexBuffer, sizeof(SimpleVertex));
|
||||
pd3dDevice->SetVertexShader(MultiFVF);
|
||||
pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2 );
|
||||
pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
|
||||
pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW);
|
||||
}
|
||||
31
Engine/Zalla3D Scene Class/LayerFogScene.h
Normal file
31
Engine/Zalla3D Scene Class/LayerFogScene.h
Normal file
@@ -0,0 +1,31 @@
|
||||
// LayerFogScene.h: interface for the CLayerFogScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_LAYERFOGSCENE_H__A18D8107_BE6C_4D54_AD08_FD4692286A6C__INCLUDED_)
|
||||
#define AFX_LAYERFOGSCENE_H__A18D8107_BE6C_4D54_AD08_FD4692286A6C__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SectorDefine.h"
|
||||
#include <Texture.h>
|
||||
#include <3DMath.h>
|
||||
#include <d3d8.h>
|
||||
|
||||
|
||||
class CLayerFogScene
|
||||
{
|
||||
public:
|
||||
void Render(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
CTexture m_FogTexture;
|
||||
LPDIRECT3DVERTEXBUFFER8 m_pFogVertexBuffer;
|
||||
void BuildFogTexture(float fMax,float fMin);
|
||||
void Create();
|
||||
CLayerFogScene();
|
||||
virtual ~CLayerFogScene();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_LAYERFOGSCENE_H__A18D8107_BE6C_4D54_AD08_FD4692286A6C__INCLUDED_)
|
||||
100
Engine/Zalla3D Scene Class/LightContainer.cpp
Normal file
100
Engine/Zalla3D Scene Class/LightContainer.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
// LightContainer.cpp: implementation of the CLightContainer class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "LightContainer.h"
|
||||
#include "SceneManager.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CLightContainer::CLightContainer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CLightContainer::~CLightContainer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CLightObject * CLightContainer::GetLightObject(char *strLightObjectName,float fLightRange,color LightColor)
|
||||
{
|
||||
int i=0;
|
||||
for(;i<(int)m_LightContainer.size();i++)
|
||||
{
|
||||
if( strcmp(m_LightContainer[i]->m_strLightName,strLightObjectName)==0 &&
|
||||
m_LightContainer[i]->m_pLightObject->m_fLightRange==fLightRange &&
|
||||
m_LightContainer[i]->m_pLightObject->m_LightColor==LightColor)
|
||||
{
|
||||
m_LightContainer[i]->m_nUsed++;
|
||||
return m_LightContainer[i]->m_pLightObject;
|
||||
}
|
||||
}
|
||||
Load(strLightObjectName,fLightRange,LightColor);
|
||||
return m_LightContainer[i]->m_pLightObject;
|
||||
}
|
||||
|
||||
void CLightContainer::Load(char *strLightObjectName,float fLightRange, color LightColor)
|
||||
{
|
||||
CLightObject *pLightObject=new CLightObject();
|
||||
CSceneManager::m_MeshObjectContainer.SetPath(LIGHTOBJECTPATH);
|
||||
pLightObject->m_pLightObject=CSceneManager::m_MeshObjectContainer.GetMeshObject(strLightObjectName);
|
||||
pLightObject->m_fLightRange=fLightRange;
|
||||
pLightObject->m_LightColor=LightColor;
|
||||
strcpy(pLightObject->m_strLightObjectName,strLightObjectName);
|
||||
LightObjectNode *AddNode=new LightObjectNode(pLightObject,strLightObjectName);
|
||||
m_LightContainer.push_back(AddNode);
|
||||
}
|
||||
|
||||
void CLightContainer::DeleteLightObject(char *strLightObjectName, float fLightRange, color LightColor)
|
||||
{
|
||||
for(int i=0;i<(int)m_LightContainer.size();i++)
|
||||
{
|
||||
if( strcmp(m_LightContainer[i]->m_strLightName,strLightObjectName)==0 &&
|
||||
m_LightContainer[i]->m_pLightObject->m_fLightRange==fLightRange &&
|
||||
m_LightContainer[i]->m_pLightObject->m_LightColor==LightColor)
|
||||
{
|
||||
if(--m_LightContainer[i]->m_nUsed==0)
|
||||
{
|
||||
LightObjectNode *delNode=m_LightContainer[i];
|
||||
if(strcmp(delNode->m_strLightName,"hstone05.R3S")==0)
|
||||
{
|
||||
char debug[256];
|
||||
sprintf(debug,"File=%s,Line=%s",__FILE__,__LINE__);
|
||||
MessageBox(NULL,debug,0,0);
|
||||
}
|
||||
|
||||
CSceneManager::m_MeshObjectContainer.DeleteMeshObject(delNode->m_strLightName);
|
||||
delNode->m_pLightObject->m_pLightObject=NULL;
|
||||
|
||||
if(delNode->m_pLightObject) {
|
||||
delete delNode->m_pLightObject;
|
||||
delNode->m_pLightObject = NULL;
|
||||
}
|
||||
if(delNode) {
|
||||
delete delNode;
|
||||
delNode = NULL;
|
||||
}
|
||||
|
||||
m_LightContainer.erase(m_LightContainer.begin()+i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CLightContainer::DeleteAllObject()
|
||||
{
|
||||
for(int i=0;i<(int)m_LightContainer.size();i++)
|
||||
{
|
||||
LightObjectNode *delNode=m_LightContainer[i];
|
||||
if(delNode) {
|
||||
delete delNode;
|
||||
delNode = NULL;
|
||||
}
|
||||
}
|
||||
m_LightContainer.clear();
|
||||
}
|
||||
42
Engine/Zalla3D Scene Class/LightContainer.h
Normal file
42
Engine/Zalla3D Scene Class/LightContainer.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// LightContainer.h: interface for the CLightContainer class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_LIGHTCONTAINER_H__0471965C_61AD_4869_89DB_11720B5E2361__INCLUDED_)
|
||||
#define AFX_LIGHTCONTAINER_H__0471965C_61AD_4869_89DB_11720B5E2361__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "LightObject.h"
|
||||
#include "BaseDataDefine.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
class CLightContainer
|
||||
{
|
||||
class LightObjectNode
|
||||
{
|
||||
public:
|
||||
long m_nUsed;
|
||||
char m_strLightName[MAX_NAMEBUFFER];
|
||||
CLightObject *m_pLightObject;
|
||||
LightObjectNode(CLightObject *pLightObject,char *strLightName)
|
||||
{
|
||||
strcpy(m_strLightName,strLightName);
|
||||
m_pLightObject=pLightObject;
|
||||
m_nUsed=1;
|
||||
}
|
||||
};
|
||||
std::vector<LightObjectNode*> m_LightContainer;
|
||||
public:
|
||||
void DeleteAllObject();
|
||||
void DeleteLightObject(char *strLightObjectName,float fLightRange,color LightColor);
|
||||
void Load(char *strLightObjectName,float fLightRange,color LightColor);
|
||||
CLightObject * GetLightObject(char *strLightObjectName,float fLightRange,color LightColor);
|
||||
CLightContainer();
|
||||
virtual ~CLightContainer();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_LIGHTCONTAINER_H__0471965C_61AD_4869_89DB_11720B5E2361__INCLUDED_)
|
||||
1282
Engine/Zalla3D Scene Class/LightEffectManager.cpp
Normal file
1282
Engine/Zalla3D Scene Class/LightEffectManager.cpp
Normal file
File diff suppressed because it is too large
Load Diff
78
Engine/Zalla3D Scene Class/LightEffectManager.h
Normal file
78
Engine/Zalla3D Scene Class/LightEffectManager.h
Normal file
@@ -0,0 +1,78 @@
|
||||
// LightEffectManager.h: interface for the CLightEffectManager class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_LIGHTEFFECTMANAGER_H__94D2B529_2919_44A4_BCB1_145A7831704B__INCLUDED_)
|
||||
#define AFX_LIGHTEFFECTMANAGER_H__94D2B529_2919_44A4_BCB1_145A7831704B__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "RenderTextureMipmap.h"
|
||||
#include "RenderTexture.h"
|
||||
#include "GlareTexture.h"
|
||||
#include "MeshObject.h"
|
||||
#include "RenderEnvTexture.h"
|
||||
#include "ShadowMap.h"
|
||||
|
||||
class CLightEffectManager
|
||||
{
|
||||
public:
|
||||
|
||||
static int m_RenderSizeX;
|
||||
static int m_RenderSizeY;
|
||||
static void RenderDOFZBuffer(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
|
||||
static DWORD m_DepthAlphaShader;
|
||||
|
||||
static bool m_FullSceneAnti;
|
||||
|
||||
static DWORD m_dwMakeZBufferPixelShader;
|
||||
|
||||
static CRenderTextureMipmap m_GlareTexture;
|
||||
static CShadowMap m_FullSceneTexture;
|
||||
static CRenderTextureMipmap m_SpecularGlareTexture;
|
||||
static CRenderTexture m_GlareCompositeTexture;
|
||||
static CRenderTexture m_DOFZBuffer;
|
||||
static CRenderTexture m_NearDOFTexture;
|
||||
static CGlareTexture m_DOFSmoothTexture;
|
||||
|
||||
static CGlareTexture m_SmoothTexture;
|
||||
|
||||
static LPDIRECT3DSURFACE8 m_pTempRenderSurface;
|
||||
static LPDIRECT3DSURFACE8 m_pTempRenderZBuffer;
|
||||
static int m_nScreenSize;
|
||||
|
||||
class CGlareNode
|
||||
{
|
||||
public:
|
||||
CMeshObject *m_pMeshObject;
|
||||
matrix m_matPosition;
|
||||
bool m_bCubeEnv;
|
||||
};
|
||||
static List<CGlareNode> m_GlareList;
|
||||
static CTexture m_CharcterEnvTexture;
|
||||
static LPDIRECT3DCUBETEXTURE8 m_LightCubeTexture;
|
||||
|
||||
static CRenderEnvTexture m_DiffuseLightCubeTexture;
|
||||
static CRenderEnvTexture m_SpecularLightTexture;
|
||||
|
||||
static CRenderTexture m_SpGlareTexture;
|
||||
|
||||
|
||||
void RenderFullSceneTextureEnd(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderFullSceneAnti(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderFullSceneGlare(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderSpecularGlareTexture(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderGlareTexture(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderGlareScene(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void RenderFullSceneTextureBegin(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void PrepareLightingEnvmap(LPDIRECT3DDEVICE8 pd3dDevice);
|
||||
void Create(int nSize);
|
||||
CLightEffectManager();
|
||||
virtual ~CLightEffectManager();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_LIGHTEFFECTMANAGER_H__94D2B529_2919_44A4_BCB1_145A7831704B__INCLUDED_)
|
||||
20
Engine/Zalla3D Scene Class/LightObject.cpp
Normal file
20
Engine/Zalla3D Scene Class/LightObject.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// LightObject.cpp: implementation of the CLightObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "LightObject.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CLightObject::CLightObject()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CLightObject::~CLightObject()
|
||||
{
|
||||
|
||||
}
|
||||
27
Engine/Zalla3D Scene Class/LightObject.h
Normal file
27
Engine/Zalla3D Scene Class/LightObject.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// LightObject.h: interface for the CLightObject class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_LIGHTOBJECT_H__97B7497C_0ABB_40C7_A225_DB974DB7ECDC__INCLUDED_)
|
||||
#define AFX_LIGHTOBJECT_H__97B7497C_0ABB_40C7_A225_DB974DB7ECDC__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
#include "MeshObject.h"
|
||||
#include <3DMath.h>
|
||||
#include "BaseDataDefine.h"
|
||||
|
||||
|
||||
class CLightObject
|
||||
{
|
||||
public:
|
||||
float m_fLightRange;
|
||||
color m_LightColor;
|
||||
CMeshObject *m_pLightObject;
|
||||
char m_strLightObjectName[MAX_NAMEBUFFER];
|
||||
CLightObject();
|
||||
virtual ~CLightObject();
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_LIGHTOBJECT_H__97B7497C_0ABB_40C7_A225_DB974DB7ECDC__INCLUDED_)
|
||||
20
Engine/Zalla3D Scene Class/LightObjectScene.cpp
Normal file
20
Engine/Zalla3D Scene Class/LightObjectScene.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// LightObjectScene.cpp: implementation of the CLightObjectScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "LightObjectScene.h"
|
||||
#include "GMMemory.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CLightObjectScene::CLightObjectScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CLightObjectScene::~CLightObjectScene()
|
||||
{
|
||||
|
||||
}
|
||||
26
Engine/Zalla3D Scene Class/LightObjectScene.h
Normal file
26
Engine/Zalla3D Scene Class/LightObjectScene.h
Normal file
@@ -0,0 +1,26 @@
|
||||
// LightObjectScene.h: interface for the CLightObjectScene class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_LIGHTOBJECTSCENE_H__13B65361_54E6_433B_AA8A_CCB1D4B068C2__INCLUDED_)
|
||||
#define AFX_LIGHTOBJECTSCENE_H__13B65361_54E6_433B_AA8A_CCB1D4B068C2__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "SceneNode.h"
|
||||
#include "LightObject.h"
|
||||
|
||||
|
||||
class CLightObjectScene : public CSceneNode
|
||||
{
|
||||
public:
|
||||
long m_LightID;
|
||||
CLightObject *m_pLightObject;
|
||||
CLightObjectScene();
|
||||
virtual ~CLightObjectScene();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_LIGHTOBJECTSCENE_H__13B65361_54E6_433B_AA8A_CCB1D4B068C2__INCLUDED_)
|
||||
19
Engine/Zalla3D Scene Class/LightmapGenerator.cpp
Normal file
19
Engine/Zalla3D Scene Class/LightmapGenerator.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// LightmapGenerator.cpp: implementation of the CLightmapGenerator class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "LightmapGenerator.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
CLightmapGenerator::CLightmapGenerator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CLightmapGenerator::~CLightmapGenerator()
|
||||
{
|
||||
|
||||
}
|
||||
20
Engine/Zalla3D Scene Class/LightmapGenerator.h
Normal file
20
Engine/Zalla3D Scene Class/LightmapGenerator.h
Normal file
@@ -0,0 +1,20 @@
|
||||
// LightmapGenerator.h: interface for the CLightmapGenerator class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined(AFX_LIGHTMAPGENERATOR_H__25F039E5_2BC5_4544_80BB_090EAE2E5339__INCLUDED_)
|
||||
#define AFX_LIGHTMAPGENERATOR_H__25F039E5_2BC5_4544_80BB_090EAE2E5339__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
class CLightmapGenerator
|
||||
{
|
||||
public:
|
||||
CLightmapGenerator();
|
||||
virtual ~CLightmapGenerator();
|
||||
|
||||
};
|
||||
|
||||
#endif // !defined(AFX_LIGHTMAPGENERATOR_H__25F039E5_2BC5_4544_80BB_090EAE2E5339__INCLUDED_)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user