Mathematics for Computer Games Development using Unity
A right angle triangle has three sides denoted the hypotenuse for the longest side (the side opposite the right angle) and two others known as the adjacent or opposite depending on their relationship to the angles. For example, for the angle β, b would be opposite and a would be adjacent. For the other angle the roles of a and b would be reversed.
The formula are:
- Example of use this:
For example: We have a three values A = 1001111, B = 10110, C = 0011 (Length of these values = 16); And we want to pack these values into 16-bit value X:
- A = 1001111 packing into 16-bit X value:
- B = 10110 packing into 16-bit X Value:
- C = 0011 packing into 16-bit X value:
- Another Example: put three values into INTEGER (32-bit value):
For unpacking bits we need create a mask that will get all of the you're interested in for each value, and shifting to right. Example:
- UnPack to A(7-bit) from X(16-bit):
- UnPack to B(5-bit) from X(16-bit):
- UnPack to C(4-bit) from X(16-bit):
- If you need to Toggling of Bits, you need use XOR (^) operation