From cf3ff53e2c777de6e8821d4b5e8811005a3b1cef Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Jun 2013 18:08:11 -0700 Subject: [PATCH] copy and paste working --- interface/src/Application.cpp | 2 +- libraries/shared/src/OctalCode.cpp | 33 ++++++++++++++++----------- libraries/shared/src/OctalCode.h | 8 +++++++ libraries/voxels/src/VoxelConstants.h | 7 +----- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b2bd7b22e6..8cc313b4bb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2397,7 +2397,7 @@ void Application::deleteVoxelUnderCursor() { for (int i = 0; i < 5000; i++) { voxelInjector->addSample(10000 * sin((i * 2 * PIE) / (500 * sin((i + 1) / 500.0)))); //FM 3 resonant pulse - // voxelInjector->addSample(20000 * sin((i) /((4 / _mouseVoxel.s) * sin((i)/(20 * _mouseVoxel.s / .001))))); //FM 2 comb filter + //voxelInjector->addSample(20000 * sin((i) /((4 / _mouseVoxel.s) * sin((i)/(20 * _mouseVoxel.s / .001))))); //FM 2 comb filter } AudioInjectionManager::threadInjector(voxelInjector); diff --git a/libraries/shared/src/OctalCode.cpp b/libraries/shared/src/OctalCode.cpp index 150789bec8..d51f058459 100644 --- a/libraries/shared/src/OctalCode.cpp +++ b/libraries/shared/src/OctalCode.cpp @@ -170,22 +170,21 @@ OctalCodeComparison compareOctalCodes(unsigned char* codeA, unsigned char* codeB char getOctalCodeSectionValue(unsigned char* octalCode, int section) { - int startAtByte = 1 + (3 * section / 8); - char startIndexInByte = (3 * section) % 8; + int startAtByte = 1 + (BITS_IN_OCTAL * section / BITS_IN_BYTE); + char startIndexInByte = (BITS_IN_OCTAL * section) % BITS_IN_BYTE; unsigned char* startByte = octalCode + startAtByte; return sectionValue(startByte, startIndexInByte); } void setOctalCodeSectionValue(unsigned char* octalCode, int section, char sectionValue) { - unsigned char* byteAt = octalCode + 1 + (3 * section / 8); - char bitInByte = (3 * section) % 8; - char shiftBy = 8 - bitInByte - 3; + int byteForSection = (BITS_IN_OCTAL * section / BITS_IN_BYTE); + unsigned char* byteAt = octalCode + 1 + byteForSection; + char bitInByte = (BITS_IN_OCTAL * section) % BITS_IN_BYTE; + char shiftBy = BITS_IN_BYTE - bitInByte - BITS_IN_OCTAL; const unsigned char UNSHIFTED_MASK = 0x07; unsigned char shiftedMask; unsigned char shiftedValue; - - if (shiftBy >=0) { shiftedMask = UNSHIFTED_MASK << shiftBy; shiftedValue = sectionValue << shiftBy; @@ -193,15 +192,24 @@ void setOctalCodeSectionValue(unsigned char* octalCode, int section, char sectio shiftedMask = UNSHIFTED_MASK >> -shiftBy; shiftedValue = sectionValue >> -shiftBy; } - unsigned char oldValue = *byteAt & ~shiftedMask; unsigned char newValue = oldValue | shiftedValue; *byteAt = newValue; - if (bitInByte >= 6) { - shiftBy = bitInByte + 1; + + // If the requested section is partially in the byte, then we + // need to also set the portion of the section value in the next byte + // there's only two cases where this happens, if the bit in byte is + // 6, then it means that 1 extra bit lives in the next byte. If the + // bit in this byte is 7 then 2 extra bits live in the next byte. + const int FIRST_PARTIAL_BIT = 6; + if (bitInByte >= FIRST_PARTIAL_BIT) { + int bitsInFirstByte = BITS_IN_BYTE - bitInByte; + int bitsInSecondByte = BITS_IN_OCTAL - bitsInFirstByte; + shiftBy = BITS_IN_BYTE - bitsInSecondByte; + shiftedMask = UNSHIFTED_MASK << shiftBy; shiftedValue = sectionValue << shiftBy; - + oldValue = byteAt[1] & ~shiftedMask; newValue = oldValue | shiftedValue; byteAt[1] = newValue; @@ -228,8 +236,7 @@ unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* int oldCodeLength = numberOfThreeBitSectionsInCode(originalOctalCode); int newParentCodeLength = numberOfThreeBitSectionsInCode(newParentOctalCode); int newCodeLength = newParentCodeLength + oldCodeLength; - const int COLOR_SPACE = 3; - int bufferLength = newCodeLength + (includeColorSpace ? COLOR_SPACE : 0); + int bufferLength = newCodeLength + (includeColorSpace ? SIZE_OF_COLOR_DATA : 0); unsigned char* newCode = new unsigned char[bufferLength]; *newCode = newCodeLength; // set the length byte diff --git a/libraries/shared/src/OctalCode.h b/libraries/shared/src/OctalCode.h index bfed24a87c..761eac1953 100644 --- a/libraries/shared/src/OctalCode.h +++ b/libraries/shared/src/OctalCode.h @@ -11,6 +11,14 @@ #include +const int BITS_IN_BYTE = 8; +const int BITS_IN_OCTAL = 3; +const int NUMBER_OF_COLORS = 3; // RGB! +const int SIZE_OF_COLOR_DATA = NUMBER_OF_COLORS * sizeof(unsigned char); // size in bytes +const int RED_INDEX = 0; +const int GREEN_INDEX = 1; +const int BLUE_INDEX = 2; + void printOctalCode(unsigned char * octalCode); int bytesRequiredForCodeLength(unsigned char threeBitCodes); bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode); diff --git a/libraries/voxels/src/VoxelConstants.h b/libraries/voxels/src/VoxelConstants.h index b18315402a..5bf1345d73 100644 --- a/libraries/voxels/src/VoxelConstants.h +++ b/libraries/voxels/src/VoxelConstants.h @@ -13,6 +13,7 @@ #define __hifi_VoxelConstants_h__ #include +#include const int TREE_SCALE = 128; @@ -23,12 +24,6 @@ const int MAX_VOXELS_PER_SYSTEM = 200000; const int VERTICES_PER_VOXEL = 24; const int VERTEX_POINTS_PER_VOXEL = 3 * VERTICES_PER_VOXEL; const int INDICES_PER_VOXEL = 3 * 12; - -const int NUMBER_OF_COLORS = 3; // RGB! -const int SIZE_OF_COLOR_DATA = NUMBER_OF_COLORS * sizeof(unsigned char); // size in bytes -const int RED_INDEX = 0; -const int GREEN_INDEX = 1; -const int BLUE_INDEX = 2; const int COLOR_VALUES_PER_VOXEL = NUMBER_OF_COLORS * VERTICES_PER_VOXEL; typedef unsigned long int glBufferIndex;