• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

Posted 26 April 2013 - 02:52 PM

Corned beef hash in the oven.

The above post I made is correct. You need to map a float in the range -1.0 to 1.0 into the range 0 - 1023.

So you do this:

float_val += 1.0; // map into range 0.0 - 2.0

float_val /= 2.0; // map into range 0.0 - 1.0

float_val *= 1023; // map into range 0.0 - 1023.0

then cast to an int (EDIT: You probably want to add on 0.5 before the cast for rounding purposes), shift into the required position, and you are done. (logical or all the other components into the 32 bit int as well).

For unsigned floats in range 0.0 - 1.0, you don't need to add 1 or divide by 2, just multiply by 1023.

For the w value, multiply by 3 (= 2*2 - 1) instead.

Posted 26 April 2013 - 02:44 PM

Corned beef hash in the oven.

The above post I made is correct. You need to map a float in the range -1.0 to 1.0 into the range 0 - 1023.

So you do this:

float_val += 1.0; // map into range 0.0 - 2.0

float_val /= 2.0; // map into range 0.0 - 1.0

float_val *= 1023; // map into range 0.0 - 1023.0

then cast to an int, shift into the required position, and you are done. (logical or all the other components into the 32 bit int as well).

For unsigned floats in range 0.0 - 1.0, you don't need to add 1 or divide by 2, just multiply by 1023.

For the w value, multiply by 3 (= 2*2 - 1) instead.

Posted 26 April 2013 - 02:43 PM

Corned beef hash in the oven.

The above post I made is correct. You need to map a float in the range -1.0 to 1.0 into the range 0 - 1023.

So you do this:

float_val += 1.0; // map into range 0.0 - 2.0

float_val /= 2.0; // map into range 0.0 - 1.0

float_val *= 1023; // map into range 0.0 - 1023.0

then cast to an int, shift into the required position, and you are done.

For unsigned floats in range 0.0 - 1.0, you don't need to add 1 or divide by 2, just multiply by 1023.

Posted 26 April 2013 - 02:42 PM

Corned beef hash in the oven.

The above post I made is correct. You need to map a float in the range -1.0 to 1.0 into the range 0 - 1023.

So you do this:

float_val += 1; // map into range 0.0 - 2.0

float_val /= 2; // map into range 0.0 - 1.0

float_val *= 1023; // map into range 0.0 - 1023.0

then cast to an int, shift into the required position, and you are done.

For unsigned floats in range 0.0 - 1.0, you don't need to add 1 or divide by 2, just multiply by 1023.

PARTNERS