Skip to content
Snippets Groups Projects
WorldAnalysisUnityHelper.cs 2.22 KiB
Newer Older
using System;
using UnityEngine;

public class WorldAnalysisUnityHelper 
{
    /// <summary>
    /// Convert a float array of length 3 to a Vector3
    /// </summary>
    /// <param name="value">the values to convert</param>
    /// <returns></returns>
    /// <exception cref="ArgumentException"></exception>
    public static Vector3 ConvertETSIVector3ToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Vector3 value)
    {
        if (value.Count == 3) return new Vector3(value[0], value[1], value[2]);
        throw new ArgumentException("The numer of floats in the value parameter must be 3!");
    }

    /// <summary>
    ///  Convert a float array of length 4 to a Quaternion
    /// </summary>
    /// <param name="value">the values to convert</param>
    /// <returns></returns>
    /// <exception cref="ArgumentException"></exception>
    public static Quaternion ConvertETSIARFQuaternionToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Quaternion value)
    {
        if (value.Count == 4) return new Quaternion(value[0], value[1], value[2], value[3]);
        throw new ArgumentException("The numer of floats in the value parameter must be 4!");
    }

    /// <summary>
    /// Convert a float array of length 16 to a Matrix
    /// </summary>
    /// <param name="matrix"></param>
    /// <returns></returns>
    public static Matrix4x4 ConvertETSIARFTransform3DToUnity(ETSI.ARF.OpenAPI.WorldAnalysis.Transform3D value)
    {
        if (value.Count == 16)
        {
            Matrix4x4 resul = new Matrix4x4();
            resul[0, 0] = value[0];
            resul[0, 1] = value[1];
            resul[0, 2] = value[2];
            resul[0, 3] = value[3];

            resul[1, 0] = value[4];
            resul[1, 1] = value[5];
            resul[1, 2] = value[6];
            resul[1, 3] = value[7];

            resul[2, 0] = value[8];
            resul[2, 1] = value[9];
            resul[2, 2] = value[10];
            resul[2, 3] = value[11];

            resul[3, 0] = value[12];
            resul[3, 1] = value[13];
            resul[3, 2] = value[14];
            resul[3, 3] = value[15];

            return resul;
        }
        else
        {
            throw new ArgumentException("The numer of floats in the value parameter must be 16!");
        }  
    }
}