I am wondering if is possible to send Vector3(float x, float y, float z) in some kind of shorter data type, because right now I am sending three floats (3*4 bytes). I am talking about normalized vector, which can hold only range from -1f to +1f for every vector part, thats why I am wondering if is possible to somehow shift bits (or something like that) and put all three values to only one 4 byte lenght value, or even shorter?
Asked
Active
Viewed 63 times
0
-
As a rule of thumb you can 'always' pack numbers into bits more tightly if you are willing to surrender precision - and the amount of precision you are willing to surrender governs the degree of compression compared with IEEE standard for floats. So tell us -- how much precision are you willing to surrender ? – High Performance Mark May 03 '18 at 19:47
-
I think that precision of 3 decimal places is ok – MrIncognito May 03 '18 at 19:53
-
You can pack 3 10-bit numbers into 4 bytes. A 10-bit number can have 1024 different values so you should be able to twiddle the bits to satisfy your needs. I suggest adding 1 to each number before encoding (and subtracting 1 after decoding) so you can forget about the sign. – High Performance Mark May 04 '18 at 12:25
-
Thanks. Adding 1 to solve sign is great idea. Unfortunately I am new in bitwise operations. Can you please give me example how can I pack some normalized vector? Thanks – MrIncognito May 04 '18 at 23:27
-
No. I'm writing comments because I'm not willing to write code. – High Performance Mark May 05 '18 at 08:26