Created
June 30, 2012 09:16
-
-
Save alexesDev/3023064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
manualObject->begin("Island", Ogre::RenderOperation::OT_TRIANGLE_LIST); | |
for(uint z = 0; z < mapSize; ++z) | |
{ | |
for(uint x = 0; x < mapSize; ++x) | |
{ | |
if(mapData[z * mapSize + x] == 0) | |
continue; | |
//TOP AND DOWN QUADS | |
for(uint level = 0; level < 2; ++level) | |
{ | |
for(uint zq = 0, index = 0; zq < 2; ++zq) | |
{ | |
for(uint xq = 0; xq < 2; ++xq, ++index) | |
{ | |
position = Vector3(x + xq, heigth * level, z + zq); | |
positionIterator = std::find(positions.begin(), positions.end(), position); | |
if(positionIterator == positions.end()) | |
{ | |
positions.push_back(position); | |
manualObject->position(position); | |
quadIndexes[index] = indexesCount++; | |
} | |
else | |
quadIndexes[index] = positionIterator - positions.begin(); | |
} | |
} | |
if(level == 0) | |
manualObject->quad(quadIndexes[0], quadIndexes[1], quadIndexes[3], quadIndexes[2]); | |
else | |
manualObject->quad(quadIndexes[0], quadIndexes[2], quadIndexes[3], quadIndexes[1]); | |
} | |
//SIDE QUADS | |
for(uint level = 0; level < subCount; ++level) | |
{ | |
Real baseLevel = subHeight * level + subHeight; | |
uint16 directionAndHeightShifts[4][2] = { { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } }; | |
for(uint direction = 0; direction < 2; ++direction) | |
{ | |
for(uint front = 0; front < 2; ++front) | |
{ | |
if(mapData[(z + (direction == 0 ? (front == 0 ? 1 : -1) : 0)) * mapSize + x + (direction == 1 ? (front == 0 ? -1 : 1) : 0)] > 0) | |
continue; | |
for(uint index = 0; index < 4; ++index) | |
{ | |
position = Vector3( | |
(direction == 0 ? directionAndHeightShifts[index][0] : 0) + x + (direction == 1 ? (front == 0 ? 0 : 1) : 0), | |
baseLevel - directionAndHeightShifts[index][1] * subHeight, | |
(direction == 1 ? directionAndHeightShifts[index][0] : 0) + z + (direction == 0 ? (front == 0 ? 1 : 0) : 0) | |
); | |
if((positionIterator = std::find(positions.begin(), positions.end(), position)) == positions.end()) | |
{ | |
positions.push_back(position); | |
manualObject->position(position); | |
quadIndexes[index] = indexesCount++; | |
} | |
else | |
quadIndexes[index] = positionIterator - positions.begin(); | |
} | |
if(front == 0) | |
manualObject->quad(quadIndexes[0], quadIndexes[2], quadIndexes[3], quadIndexes[1]); | |
else | |
manualObject->quad(quadIndexes[0], quadIndexes[1], quadIndexes[3], quadIndexes[2]); | |
} | |
} | |
} | |
} | |
} | |
manualObject->end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment