Created
July 1, 2012 11:40
-
-
Save alexesDev/3028102 to your computer and use it in GitHub Desktop.
Island mesh
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
for(uint z = 0; z < mapSize; ++z) | |
{ | |
for(uint x = 0; x < mapSize; ++x) | |
{ | |
int index = z * mapSize + x; | |
if(mapData[index] == 0) | |
continue; | |
positionsMap[index] = Vector3(x, mapData[index] * 0.05, z); | |
indexesMap[index] = indexesCount; | |
indexesCount += 1; | |
manualObject->position(positionsMap[index]); | |
if(z == 0 || x == 0) | |
continue; | |
//Has quad? | |
// 3 2 | |
// * - * | |
// | \ | | |
// * - * | |
// 1 0 | |
bool hasPoint1 = mapData[index - 1] != 0; | |
bool hasPoint2 = mapData[(z - 1) * mapSize + x] != 0; | |
bool hasPoint3 = mapData[(z - 1) * mapSize + x - 1] != 0; | |
if(hasPoint1 && hasPoint2 && hasPoint3) | |
{ | |
uint32 index0 = indexesCount - 1; | |
uint32 index1 = indexesMap[index - 1]; | |
uint32 index2 = indexesMap[(z - 1) * mapSize + x]; | |
uint32 index3 = indexesMap[(z - 1) * mapSize + x - 1]; | |
manualObject->quad(index0, index2, index3, index1); | |
} | |
// 3 | |
// * | |
// | \ | |
// * - * | |
// 1 0 | |
else if(hasPoint1 && !hasPoint2 && hasPoint3) | |
{ | |
uint32 index0 = indexesCount - 1; | |
uint32 index1 = indexesMap[index - 1]; | |
uint32 index3 = indexesMap[(z - 1) * mapSize + x - 1]; | |
manualObject->triangle(index0, index3, index1); | |
} | |
// 2 | |
// * | |
// / | | |
// * - * | |
// 1 0 | |
else if(hasPoint1 && hasPoint2 && !hasPoint3) | |
{ | |
uint32 index0 = indexesCount - 1; | |
uint32 index1 = indexesMap[index - 1]; | |
uint32 index2 = indexesMap[(z - 1) * mapSize + x]; | |
manualObject->triangle(index0, index2, index1); | |
} | |
// 3 2 | |
// * - * | |
// \ | | |
// * | |
// 0 | |
else if(!hasPoint1 && hasPoint2 && hasPoint3) | |
{ | |
uint32 index0 = indexesCount - 1; | |
uint32 index2 = indexesMap[(z - 1) * mapSize + x]; | |
uint32 index3 = indexesMap[(z - 1) * mapSize + x - 1]; | |
manualObject->triangle(index0, index2, index3); | |
} | |
} | |
} | |
manualObject->end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment