void CLightmapMgr::Create(CGndRes *gnd)
{
CLMInfo lminfo;
int surfaceId;
int i,j;
int u,v;
float u0,v0;
float u1,v1;
int row,col;
int buffer[256 * 256];
int* pPixel;
char* pAlpha;
char* pColor;
CLightmap* pLightmap;
CTexture* pTexture;
this->m_lightmaps.erase();
this->m_lmSurfaces.erase();
this->m_numLightmaps = gnd->m_numLightmap;
this->m_lightmaps.resize(this->m_numLightmaps);
this->m_numLmSurfaces = (lightmapMgr->m_numLightmaps + 1023) / 1024;
this->m_lmSurfaces.reserve(this->m_numLmSurfaces);
for( i = 0; i < this->m_numLightmaps; i += 1024 )
{
surfaceId = i / 1024;
for( j = 0; i + j < this->m_numLightmaps && j < 1024 ; ++j )
{
gnd->GetLMInfo(i + j, &lminfo);
pLightmap = &this->m_lightmaps[i];
u = (i + j - (surfaceId * 1024)) / 32;
v = (i + j - (surfaceId * 1024)) % 32;
pPixel = &buffer[(u + v * 256) * 32];
pAlpha = &lminfo.idata[0][0];
pColor = &lminfo.sdata[0][0];
for( row = 8; row > 0; --row )
{
for( col = 0; col < 8; ++col )
{
pPixel[col] = (int)((unsigned char)pColor[2]
+ (((unsigned char)pColor[1]
+ (((unsigned char)pColor[0] + ((unsigned char)*pAlpha) << 8)) << 8)) << 8);
pColor += 3;
pAlpha += 1;
}
pPixel += 256;
}
u0 = (8 * u + 1) * (1 / 256.0);
v0 = (8 * v + 1) * (1 / 256.0);
u1 = (8 * u + 7) * (1 / 256.0);
v1 = (8 * v + 7) * (1 / 256.0);
if( u0 <= 0.0 ) u0 = 0.0;
else if( u0 >= 1.0 ) u0 = 1.0;
if( v0 <= 0.0 ) v0 = 0.0;
else if( v0 >= 1.0 ) v0 = 1.0;
if( u1 <= 0.0 ) u1 = 0.0;
else if( u1 >= 1.0 ) u1 = 1.0;
if( v1 <= 0.0 ) v1 = 0.0;
else if( v1 >= 1.0 ) v1 = 1.0;
pLightmap->coor[0].u = u0;
pLightmap->coor[0].v = v0;
pLightmap->coor[1].u = u1;
pLightmap->coor[1].v = v0;
pLightmap->coor[2].u = u0;
pLightmap->coor[2].v = v1;
pLightmap->coor[3].u = u1;
pLightmap->coor[3].v = v1;
pLightmap->brightObj[0] = lminfo.sdata[4][4][0];
pLightmap->brightObj[1] = lminfo.sdata[4][4][1];
pLightmap->brightObj[2] = lminfo.sdata[4][4][2];
pLightmap->intensity[0].a = lminfo.idata[1][1];
pLightmap->intensity[0].r = lminfo.sdata[1][1][0];
pLightmap->intensity[0].g = lminfo.sdata[1][1][1];
pLightmap->intensity[0].b = lminfo.sdata[1][1][2];
pLightmap->intensity[1].a = lminfo.idata[1][5];
pLightmap->intensity[1].r = lminfo.sdata[1][5][0];
pLightmap->intensity[1].g = lminfo.sdata[1][5][1];
pLightmap->intensity[1].b = lminfo.sdata[1][5][2];
pLightmap->intensity[2].a = lminfo.idata[5][1];
pLightmap->intensity[2].r = lminfo.sdata[5][1][0];
pLightmap->intensity[2].g = lminfo.sdata[5][1][1];
pLightmap->intensity[2].b = lminfo.sdata[5][1][2];
pLightmap->intensity[3].a = lminfo.idata[5][5];
pLightmap->intensity[3].r = lminfo.sdata[5][5][0];
pLightmap->intensity[3].g = lminfo.sdata[5][5][1];
pLightmap->intensity[3].b = lminfo.sdata[5][5][2];
}
pTexture = g_texMgr.CreateTexture(256, 256, &buffer, PF_A4R4G4B4, 0);
this->m_lmSurfaces.push_back(pTexture);
}
for( i = 0; i < this->m_numLightmaps; ++i )
{
surfaceId = i / 1024;
this->m_lightmaps[i].surface = this->m_lmSurfaces[surfaceId];
}
}
Mostrar mensagens com a etiqueta 2004-03-09aSakexe. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta 2004-03-09aSakexe. Mostrar todas as mensagens
segunda-feira, 2 de abril de 2012
void CLightmapMgr::Create(CGndRes*)
quinta-feira, 13 de outubro de 2011
void CSoundMaker::SendMsg(CGameObject*,int,int,int,int)
void CSoundMaker::SendMsg(CGameObject* sender, int message, int arg1, int arg2, int arg3)
{
switch( message )
{
default:
this->CRenderObject::SendMsg(sender,message,arg1,arg2,arg3);
return;
case 0xE:
{
C3dWorldRes::soundSrcInfo* sound = (C3dWorldRes::soundSrcInfo*)arg1;
m_waveName = sound->waveName;// std::string <- char[80]
m_vol = sound->vol;// float <- float
m_width = sound->width;// int <- int
m_height = sound->height;// int <- int
m_pos.x = sound->pos.x;// float <- float
m_pos.y = sound->pos.y;// float <- float
m_pos.z = sound->pos.z;// float <- float
m_diagonal = sqrt(m_width*m_width + m_height*m_height);// float
m_cycle = ftol(sound->cycle*1000.0f);
m_lastPlayTime = timeGetTime() - m_cycle;
return;
}
}
}
void CSoundMaker::OnProcess()
// FUNC: float CRenderObject::CalcDist(float x, float y);
// FUNC: PlayWave(const char *waveFileName, float x, float y, float z, int volumeMaxDist, int volumeMinDist, float vFactor);
// VAR: float CSoundMaker::m_diagonal = sqrt(m_width*m_width + m_height*m_height);
void CSoundMaker::OnProcess()
{
CPlayer* player = g_modeMgr.GetGameMode()->m_world->m_player;
if( CalcDist(player->m_pos.x,player->m_pos.z) - (m_diagonal+m_range) <= 130.0f )
{// passed circular range
float dist_x = player.m_pos.x - m_pos.x
float dist_z = player.m_pos.z - m_pos.z
float sign_x = (dist_x >= 0.0f)? 1.0f: -1.0f;
float sign_z = (dist_z >= 0.0f)? 1.0f: -1.0f;
float cZ = dist_z / dist_x;
float todo_x;
float todo_z;
if( (double)abs(cZ) <= (double)(m_height / m_width) )
{// TODO it's probably getting the point in the elipse for the direction between this soundmaker and the player
todo_x = m_width * sign_x * 0.5;
todo_z = todo_x * cZ;
}
else
{
todo_z = m_height * sign_z * 0.5;
todo_x = todo_z / cZ;
}
float point_x = todo_x + m_pos.x;
float point_z = todo_z + m_pos.y;
if( player->CalcDist(point_x,point_z) - m_range <= 75.0f && m_waveName.length() > 0 && timeGetTime() > m_lastPlayTime + m_cycle )
{// TODO passed elliptic range?
m_lastPlayTime = timeGetTime();
float x = point_x - player->m_pos.x;
float y = 0.0f;
float z = point_z - player->m_pos.z;
int volumeMaxDist = ftol(m_range);
int volumeMinDist = ftol(m_range*(1.0f/6.0f));
float vFactor = m_vol;
PlayWave(m_waveName.c_str(),x,y,z,volumeMaxDist,volumeMinDist,vFactor);
}
}
}
Subscrever:
Mensagens (Atom)