Example #1
0
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                var         obj  = (Quaternion)value;
                TQuaternion tobj = new TQuaternion()
                {
                    x = obj.x, y = obj.y, z = obj.z, w = obj.w
                };

                serializer.Serialize(writer, tobj);
            }
Example #2
0
    public static TQuaternion Parse(string str)
    {
        var sps  = str.Trim('(', ')').Split(',');
        var data = new TQuaternion
        {
            x = float.Parse(sps[0]),
            y = float.Parse(sps[1]),
            z = float.Parse(sps[2])
        };

        return(data);
    }
Example #3
0
        // Поворот с помощью кватерниона
        public TVector RotateByQuaternion(TQuaternion Q)
        {
            TVector     Result = new TVector(Vector);
            TQuaternion ResultQ;
            TQuaternion vector = new TQuaternion(0, this);

            ResultQ = Q.Mult(vector);
            ResultQ = ResultQ.Mult(Q.Conjugate());
            for (int i = 1; i < 4; i++)
            {
                Result.Vector[i - 1] = ResultQ.Vec[i];
            }
            return(Result);
        }
Example #4
0
        // Поворот на угол вокруг оси (через кватернионы)
        public TVector RotateByAngleOnAxis(double phi, TVector V)
        {
            TQuaternion Q = new TQuaternion(phi, V);

            Q = Q.Normalization();
            TQuaternion ThisVecQ = new TQuaternion(0, Vector[0], Vector[1], Vector[2]);
            TQuaternion ResultQ  = Q.Mult(ThisVecQ);

            ResultQ = ResultQ.Mult(Q.Conjugate());
            TVector Result = new TVector(Vector);

            for (int i = 1; i < 4; i++)
            {
                Result.Vector[i - 1] = ResultQ.Vec[i];
            }
            return(Result);
        }
Example #5
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                TQuaternion tObj = serializer.Deserialize <TQuaternion>(reader);

                return(new Quaternion(tObj.x, tObj.y, tObj.z, tObj.w));
            }