Any comments on this algorithm...

This is a discussion on Any comments on this algorithm... within the C++ Programming forums, part of the General Programming Boards category; I am writing a animator/format converter for Unreal Tournament...game related, I know. Anyway, I need a little help with this ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    2

    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

  2. #2
    Davros
    Guest
    Can't help you on 3DS2UNR, but I can tell you about bitwise operators.

    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. #3
    Registered User
    Join Date
    May 2002
    Posts
    2
    Thanks that helps a lot. Sure glad I'm doing a discrete mathematics paper...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. The Art of Writing Comments :: Software Engineering
    By kuphryn in forum C++ Programming
    Replies: 15
    Last Post: 11-23-2002, 05:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21