Esempio n. 1
0
        public static Quaternion ParseQuaternion(ARTMatrix artM)
        {
            Matrix4x4 mat       = UnityParser.ParseMatrix(artM, true);
            Vector3   targetDir = mat.MultiplyVector(Vector3.forward);
            Vector3   targetUp  = mat.MultiplyVector(Vector3.up);

            return(UnityParser.ParseQuaternion(targetDir, targetUp));
        }
Esempio n. 2
0
        /// <summary>
        /// Method used for parsing ARTMatrices to Unity3d matrices (Matrix4x4).
        /// </summary>
        ///<returns>
        /// Returns the converted Matrix4x4 object.
        /// </returns>
        /// <param name="artM">
        /// To be converted ARTMatrix
        /// </param>
        public static Matrix4x4 ParseMatrix(ARTMatrix artM, bool transposed)
        {
            uM = new Matrix4x4();
            Vector4 v4_0   = new Vector4(artM.getB0(), artM.getB1(), artM.getB2(), 0);
            Vector4 v4_1   = new Vector4(artM.getB3(), artM.getB4(), artM.getB5(), 0);
            Vector4 v4_2   = new Vector4(artM.getB6(), artM.getB7(), artM.getB8(), 0);
            Vector4 v4_end = new Vector4(0, 0, 0, 1);

            uM.SetColumn(0, v4_0);
            uM.SetColumn(1, v4_1);
            uM.SetColumn(2, v4_2);
            uM.SetColumn(3, v4_end);
            if (transposed)
            {
                return(uM.transpose);
            }
            return(uM);
        }
Esempio n. 3
0
        /// <summary>
        /// This method parses various input objects and computes a quaternion to use with a camera object in Unity3d.
        /// E.g. mapping the rotation of a ART 6d object to the camera.
        ///
        /// If you wish to inverse an axis just change the correspondent boolean to true.
        /// </summary>
        /// <param name="artM">Input ARTMatrix</param>
        /// <param name="invX">Boolean used to inverse X axis</param>
        /// <param name="invY">Boolean used to inverse Y axis</param>
        /// <param name="invZ">Boolean used to inverse Z axis</param>
        /// <returns>Returns a quaternion</returns>
        public static Quaternion ParseCameraQuaternion(ARTMatrix artM, bool invX, bool invY, bool invZ)
        {
            Quaternion target = UnityParser.ParseQuaternion(artM);
            float      angle  = 0;
            Vector3    axis   = Vector3.zero;

            target.ToAngleAxis(out angle, out axis);
            if (invX)
            {
                axis.x *= -1;
            }
            if (invY)
            {
                axis.y *= -1;
            }
            if (invZ)
            {
                axis.z *= -1;
            }
            return(target = Quaternion.AngleAxis(angle, axis));
        }
Esempio n. 4
0
        protected void parse6d(String msg)
        {
            int       id       = 0;
            ARTPoint  position = ARTPoint.Empty();
            ARTAngle  angle    = ARTAngle.Empty();
            ARTMatrix matrix   = ARTMatrix.Empty();


            msg = msg.Replace("]", "");
            msg = msg.Replace("[", "x");
            String[] tmp = msg.Split('x');
            if (tmp.Length >= 4)
            {
                numberOf6dTargets = parseInt(tmp[0]);
                String[] tmp2 = tmp[1].Split(' ');
                if (tmp2.Length >= 2)
                {
                    id = parseInt(tmp2[0]);
                }
                tmp2 = tmp[2].Split(' ');
                if (tmp2.Length >= 6)
                {
                    position = new ARTPoint(parseFloat(tmp2[0]),
                                            parseFloat(tmp2[1]), parseFloat(tmp2[2]));
                    angle = new ARTAngle(parseFloat(tmp2[3]), parseFloat(tmp2[4]),
                                         parseFloat(tmp2[5]));
                }
                tmp2 = tmp[3].Split(' ');
                if (tmp2.Length >= 9)
                {
                    matrix = new ARTMatrix(parseFloatArray(tmp2));
                }
                add6dObject(new ART6d(id, position, angle, matrix));
                for (int i = 0; i < observers.Count; i++)
                {
                    ((ARTObserver)observers[i]).on6dUpdate(this);
                }
            }
        }
Esempio n. 5
0
        protected void parse6df2(String msg)
        {
            int       id = 1;
            int       numberOfButtons     = 0;
            int       numberOfControllers = 0;
            bool      visible             = false;
            ARTPoint  position            = ARTPoint.Empty();
            ARTMatrix matrix           = ARTMatrix.Empty();
            int       buttonStates     = 0;
            var       controllerStates = new float[0];


            msg = msg.Replace("]", "");
            msg = msg.Replace("[", "x");
            String[] tmp = msg.Split('x');
            if (tmp.Length >= 5)
            {
                numberOfFlysticks = parseInt(tmp[0]);
                String[] tmp2 = tmp[1].Split(' ');
                if (tmp2.Length >= 4)
                {
                    id = parseInt(tmp2[0]);
                    if (parseFloat(tmp2[1]) > 0.0F)
                    {
                        visible = true;
                    }
                    numberOfButtons     = parseInt(tmp2[2]);
                    numberOfControllers = parseInt(tmp2[3]);
                }
                tmp2 = tmp[2].Split(' ');
                if (tmp2.Length >= 3)
                {
                    position = new ARTPoint(parseFloat(tmp2[0]),
                                            parseFloat(tmp2[1]), parseFloat(tmp2[2]));
                }
                tmp2 = tmp[3].Split(' ');
                if (tmp2.Length >= 9)
                {
                    matrix = new ARTMatrix(parseFloatArray(tmp2));
                }
                tmp2 = tmp[4].Split(' ');
                if (tmp2.Length >= 1)
                {
                    if (numberOfButtons > 0)
                    {
                        buttonStates     = parseInt(tmp2[0]);
                        controllerStates = new float[tmp2.Length - 1];
                        for (int i = 0; i < controllerStates.Length; i++)
                        {
                            controllerStates[i] = parseFloat(tmp2[(i + 1)]);
                        }
                    }
                    else
                    {
                        controllerStates = new float[tmp2.Length];
                        for (int i = 0; i < controllerStates.Length; i++)
                        {
                            controllerStates[i] = parseFloat(tmp2[i]);
                        }
                    }
                }
                addFlystick(new ARTFlystick(id, visible, numberOfButtons,
                                            buttonStates, numberOfControllers, controllerStates,
                                            position, matrix));
                for (int i = 0; i < observers.Count; i++)
                {
                    ((ARTObserver)observers[i]).onFlystickUpdate(this);
                }
                foreach (IFlystickListener listener in flystickListener)
                {
                    UpdateFlystickListener(listener);
                }
            }
        }
Esempio n. 6
0
 public ART6d(int id, ARTPoint position, ARTAngle angle, ARTMatrix matrix) : base(id, position, matrix)
 {
     this.angle = angle;
 }
Esempio n. 7
0
 public static ART6d Empty()
 {
     return(new ART6d(-1, ARTPoint.Empty(), ARTAngle.Empty(), ARTMatrix.Empty()));
 }
Esempio n. 8
0
 public ARTFlystick(int id, bool visible, int numberOfButtons, int buttonStates, int numberOfControllers, float[] controllerStates, ARTPoint position, ARTMatrix matrix) : base(id, position, matrix)
 {
     this.visible             = visible;
     this.numberOfButtons     = numberOfButtons;
     this.numberOfControllers = numberOfControllers;
     this.buttonStates        = buttonStates;
     this.controllerStates    = controllerStates;
 }
Esempio n. 9
0
 public static ARTFlystick Empty()
 {
     return(new ARTFlystick(-1, false, 0, 0, 0, new float[0], ARTPoint.Empty(), ARTMatrix.Empty()));
 }
Esempio n. 10
0
 public ARTObject(int id, ARTPoint position, ARTMatrix matrix)
 {
     this.id       = id;
     this.position = position;
     this.matrix   = matrix;
 }