Advertisement
Guest User

Untitled

a guest
Mar 1st, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BitPacking;
  7.  
  8. namespace Edgy
  9. {
  10.  
  11.     public class QuaternionQuantizer
  12.     {
  13.  
  14.         private float resolution;
  15.  
  16.         public QuaternionQuantizer(float resolution)
  17.         {
  18.             this.resolution = resolution;
  19.         }
  20.  
  21.         public void Read(IBitReaderStream bitReaderStream, out Quaternion quaternion)
  22.         {
  23.             quaternion = new Quaternion(0f, 0f, 0f, 1f);
  24.  
  25.             int a = bitReaderStream.ReadLimitedInt32(0, 3);
  26.             float t = 0f;
  27.  
  28.             for (int i = 0; i < 4; i++)
  29.             {
  30.                 if (i != a)
  31.                 {
  32.                     float b = bitReaderStream.ReadLimitedFloat(-1f, 1f, this.resolution);
  33.  
  34.                     if (i == 0)
  35.                         quaternion.X = b;
  36.                     else if (i == 1)
  37.                         quaternion.Y = b;
  38.                     else if (i == 2)
  39.                         quaternion.Z = b;
  40.                     else if (i == 3)
  41.                         quaternion.W = b;
  42.  
  43.                     t = (b * b);
  44.                 }
  45.             }
  46.  
  47.             if (a == 0)
  48.                 quaternion.X = (float) Math.Sqrt(1f - t);
  49.             else if (a == 1)
  50.                 quaternion.Y = (float) Math.Sqrt(1f - t);
  51.             else if (a == 2)
  52.                 quaternion.Z = (float) Math.Sqrt(1f - t);
  53.             else if (a == 3)
  54.                 quaternion.W = (float) Math.Sqrt(1f - t);
  55.         }
  56.  
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement