Cyberman, I posted your code exactly and it’s not working for me.
if ( Odd ) {
baEachNumber[0] = (*baData <<8) & 0xFF00 | *(baData + 1);
baEachNumber[0] &= 0xFFF;
baData += 2;
baEachNumber[1] = (*baData <<8) & 0xFF00 | *(baData + 1);
baEachNumber[1] >>= 4;
baData++;
baEachNumber[2] = (*baData <<8) & 0xFF00 | *(baData + 1);
baEachNumber[2] &= 0xFFF;
baData +=2;
}
else {
baEachNumber[0] = (*baData <<8) & 0xFF00 | *(baData + 1);
baEachNumber[0] >>= 4;
baData++;
baEachNumber[1] = (*baData <<8) & 0xFF00 | *(baData + 1);
baEachNumber[1] &=0xFFF;
baData += 2;
baEachNumber[2] = (*baData <<8) & 0xFF00 | *(baData + 1);
baEachNumber[2] >>= 4;
baData++;
}
Odd = !Odd;
fTemp0 = baEachNumber[0] * 360.0f / 4096.0f;
fTemp1 = baEachNumber[1] * 360.0f / 4096.0f;
fTemp2 = baEachNumber[2] * 360.0f / 4096.0f;
AttachRotationToBone( 0, iCount, fTemp0, fTemp1, fTemp2 );
baData is your A_Decode and it is where I stored the entire list of data bytes for the animation.
baEachNumber is clearly where I have store each byte from that array temporarily.
In this case I am doing exactly as you were (shifting my pointer up along the line to get each byte) but I rewrote it to use an index instead but the results were exactly the same.
As for how I am loading it…
I am creating a dynamic byte array
byte * baData = new byte[iChunkSize];
and then reading directly into it
if ( !fread( baData, iChunkSize, 1, file ) ) { return; }
.
The bytes are aligned correctly because I can walk them in the debugger and view them with my hex viewer to see that they match the data file exactly.
I am reading at the correct offset inside the file as well. baData starts as “00 00 00 00 0C…â€.
Your method is giving me these results:
< 0.000 0.000 0.000 >
< 0.000 1.230 0.000 >
< 0.126 20.13 0.879 >
< 16.44 0.703 16.52 >
These numers are all so low it makes me suspect your shifts are in the opposite direction of mine.
In my original code, I shifted << (left) to decrease the bytes.
I notice in your code you shift by 4’s going right.
Sigh. This is the whole reason for any confusion at all. If machines and operating systems didn’t switch the lower-end bits all the time…
I tried switching your >>’s to <<’s and <<’s to >>’s but that failed also.
For a moment, I am going back to my original code.
iCurrentBit = I * 12; // Calculate the current bit.
iBytewiseOffset = iCurrentBit / 8; // Get the offset of the byte that has that bit.
iBitwiseOffset = iCurrentBit % 8; // Calculate how many bits we need to shift.
iTemp = * (unsigned int *)(&baData[iBytewiseOffset]);
iTemp = iTemp << iBitwiseOffset;
SwapAllBytes( (byte *) &iTemp, sizeof( iTemp ) );
iTemp = iTemp & 0xFFF;
if ( I % 3 == 0 ) {
fTemp0 = (float)iTemp * 360.0f / 4096.0f;
}
if ( I % 3 == 1 ) {
fTemp1 = (float)iTemp * 360.0f / 4096.0f;
}
if ( I % 3 == 2 ) {
fTemp2 = (float)iTemp * 360.0f / 4096.0f;
AttachRotationToBone( 0, iCount, fTemp0, fTemp1, fTemp2 );
iCount++;
}
What this does is…
Calculate the current bit.
Calculate which byte has that bit (iCurrentBit /

.
Calculate the shifting offset (iCurrentBit %

.
Cast a 4-byte unsigned integer to the value at “iBytewiseOffset†in the array.
iTemp = * (unsigned int *)(&baData[iBytewiseOffset]);
Now the four bytes that make up “iTemp†are the same four bytes that are in the “iBytewiseOffset†location in the stored data array.
baData[3] is “00 0C 00 EC†(EC 00 0C 00 on Windows® Calculator) which makes iTemp 3959426048.
We shift those four bytes left by “iBitwiseOffset†(which toggles between 0 and 4 appropriately, via the math used).
3959426048 becomes 3221274624, or “00 C0 00 C0†(C0 00 C0 00 on Windows® Calculator).
Then we take only the first three byte halves, so we “iTemp &= 0xFFF;â€.
Do the math from there to get the results.
How can this not work? We go right to the byte that holds our data and shift it by either 0 or 4 appropriately. Then take only the first 12 bits and do the math on them. It’s perfectly logical. Check the formulas to see that my math to go to the appropriate byte and to calculate between 0 and 4 bitwise shift IS correct and it works perfectly.
I have modified this in every way. I changed the unsigned int to an unsigned short (to read only the first two bytes). I have changed the order and directiono f the shifting.
Everything.