add method to return the start vertex for an octal code

This commit is contained in:
Stephen Birarda 2013-03-20 13:24:18 -07:00
parent f8f098cf2c
commit adb45c825b
2 changed files with 15 additions and 0 deletions

View file

@ -102,3 +102,17 @@ unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber
return newCode;
}
float * firstVertexForCode(unsigned char * octalCode) {
float * firstVertex = new float[3];
memset(firstVertex, 0, 3 * sizeof(float));
for (int i = 0; i < numberOfThreeBitSectionsInCode(octalCode); i++) {
int8_t sectionIndex = sectionValue(octalCode + 1 + (3 * i / 8), (3 * i) % 8);
for (int j = 0; j < 3; j++) {
firstVertex[j] += 0.5 * (int)oneAtBit(sectionIndex, 7 -j);
}
}
return firstVertex;
}

View file

@ -16,5 +16,6 @@ int bytesRequiredForCodeLength(unsigned char threeBitCodes);
bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode);
char branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode);
unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber);
float * firstVertexForCode(unsigned char * octalCode);
#endif /* defined(__hifi__OctalCode__) */