Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using BitPacking;
- namespace Edgy
- {
- public class QuaternionQuantizer
- {
- private float resolution;
- public QuaternionQuantizer(float resolution)
- {
- this.resolution = resolution;
- }
- public void Read(IBitReaderStream bitReaderStream, out Quaternion quaternion)
- {
- quaternion = new Quaternion(0f, 0f, 0f, 1f);
- int a = bitReaderStream.ReadLimitedInt32(0, 3);
- float t = 0f;
- for (int i = 0; i < 4; i++)
- {
- if (i != a)
- {
- float b = bitReaderStream.ReadLimitedFloat(-1f, 1f, this.resolution);
- if (i == 0)
- quaternion.X = b;
- else if (i == 1)
- quaternion.Y = b;
- else if (i == 2)
- quaternion.Z = b;
- else if (i == 3)
- quaternion.W = b;
- t = (b * b);
- }
- }
- if (a == 0)
- quaternion.X = (float) Math.Sqrt(1f - t);
- else if (a == 1)
- quaternion.Y = (float) Math.Sqrt(1f - t);
- else if (a == 2)
- quaternion.Z = (float) Math.Sqrt(1f - t);
- else if (a == 3)
- quaternion.W = (float) Math.Sqrt(1f - t);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement