1. ## Any comments on this algorithm...

I am writing a animator/format converter for Unreal Tournament...game related, I know.

Anyway, I need a little help with this algorithm from 3DS2UNR developed by Legend Entertainment:

Packed Vertex = ( int( v.X * 8.0 ) & 0x7ff ) |
(( int( v.Y * 8.0 ) & 0x7ff ) << 11 ) |
(( int( v.Z * 4.0 ) & 0x3ff ) << 22 )

I can tell you also that:

* v.X, v.Y, and v.Z are all 4-byte floats
* Packed Vertex is a single 4-byte signed integer

Now I'm guessing that the program multplies each vertex by either 8.0 (x, y ) or 4.0 (z). However, I am not too sure as what exactly the bitwise AND operator (&) or the | operator do.

I know it would be asking a lot for the exact manner in which this algorithm works but if anyone could shed any light it would be greatly appreciated!

Thanks

The result of an AND operation is only 1 if both of the bitwise arguments are true. Here's an example:

0x23 & 0x76 = 0x22

in binary, this looks like

00100011 & 01110110 = 00100010

i.e. only bit positions where both values are 1 equate to 1 in the result.

An OR operation is just what it says. I.e.

0x23 | 0x76 = 0x77

in binary

00100011 & 01110110 = 01110111

bit position where either value is 1 equate to 1 in the result.

There are other bitwise operations, such as XOR (^). The double arrows in your code example refer to bit shifting - either left (<<) or right (<<). If you shift a number left by one bit, you effectively multiply it by 2.

3. Thanks that helps a lot. Sure glad I'm doing a discrete mathematics paper...