0
我有一個std::vector<Chunk*> m_vpChunks
對象,它包含一個塊的向量。 另外我有一個世界和X,Y,Z座標。使用X,Y,Z索引std :: vector
我創建塊:
// Go through all chunks
for(int x = 0; x < m_iSize; x+=CHUNK_SIZE_X)
{
for(int y = 0; y < m_iSize; y+=CHUNK_SIZE_Y)
{
for(int z = 0; z < m_iSize; z+=CHUNK_SIZE_Z)
{
// Create new chunk
CChunk *pChunk = NULL;
pChunk = new CChunk(CVector3(x,y,z));
assert(pChunk);
// Add it to our list
m_vpChunks.push_back(pChunk);
}
}
}
而想要索引與X,Y,Z像塊向量:
CChunk *GetChunk(int X, int Y, int Z)
{
return m_vpChunks[ *** ];
}
任何想法?
定義'布爾運算符<(const的CVector3&V1,常量CVector3&V2)'和存儲在該塊'std :: map'而不是'std :: vector'。 – 2012-07-13 17:21:24
重載CChunk比較(==)運算符,然後循環檢查x,y,z – peacemaker 2012-07-13 17:22:39
上的匹配項'm_vpChunks'或使用std :: map來存儲,並使用查找函數 – peacemaker 2012-07-13 17:26:35