Exemple #1
0
        public static SCNVector3 TransformPosition(SCNVector3 pos, SCNMatrix4 mat)
        {
            SCNVector3 p;

            p.X = SCNVector3.Dot(pos, new SCNVector3(mat.Column0)) + mat.Row3.X;
            p.Y = SCNVector3.Dot(pos, new SCNVector3(mat.Column1)) + mat.Row3.Y;
            p.Z = SCNVector3.Dot(pos, new SCNVector3(mat.Column2)) + mat.Row3.Z;
            return(p);
        }
Exemple #2
0
        public static void TransformPerspective(ref SCNVector3 vec, ref SCNMatrix4 mat, out SCNVector3 result)
        {
            SCNVector4 h;

            SCNVector3.Transform(ref vec, ref mat, out h);
            result.X = h.X / h.W;
            result.Y = h.Y / h.W;
            result.Z = h.Z / h.W;
        }
Exemple #3
0
        public static SCNVector3 TransformNormalInverse(SCNVector3 norm, SCNMatrix4 invMat)
        {
            SCNVector3 n;

            n.X = SCNVector3.Dot(norm, new SCNVector3(invMat.Row0));
            n.Y = SCNVector3.Dot(norm, new SCNVector3(invMat.Row1));
            n.Z = SCNVector3.Dot(norm, new SCNVector3(invMat.Row2));
            return(n);
        }
Exemple #4
0
        public static SCNVector3 TransformVector(SCNVector3 vec, SCNMatrix4 mat)
        {
            SCNVector3 v;

            v.X = SCNVector3.Dot(vec, new SCNVector3(mat.Column0));
            v.Y = SCNVector3.Dot(vec, new SCNVector3(mat.Column1));
            v.Z = SCNVector3.Dot(vec, new SCNVector3(mat.Column2));
            return(v);
        }
Exemple #5
0
        /// <summary>Transform a Vector by the given Matrix</summary>
        /// <param name="vec">The vector to transform</param>
        /// <param name="mat">The desired transformation</param>
        /// <returns>The transformed vector</returns>
        public static SCNVector4 Transform(SCNVector4 vec, SCNMatrix4 mat)
        {
            SCNVector4 result;

            result.X = SCNVector4.Dot(vec, mat.Column0);
            result.Y = SCNVector4.Dot(vec, mat.Column1);
            result.Z = SCNVector4.Dot(vec, mat.Column2);
            result.W = SCNVector4.Dot(vec, mat.Column3);
            return(result);
        }
Exemple #6
0
        public static SCNVector4 Transform(SCNVector3 vec, SCNMatrix4 mat)
        {
            SCNVector4 v4 = new SCNVector4(vec.X, vec.Y, vec.Z, 1.0f);
            SCNVector4 result;

            result.X = SCNVector4.Dot(v4, mat.Column0);
            result.Y = SCNVector4.Dot(v4, mat.Column1);
            result.Z = SCNVector4.Dot(v4, mat.Column2);
            result.W = SCNVector4.Dot(v4, mat.Column3);
            return(result);
        }
Exemple #7
0
        public static void TransformNormalInverse(ref SCNVector3 norm, ref SCNMatrix4 invMat, out SCNVector3 result)
        {
            result.X = norm.X * invMat.Row0.X +
                       norm.Y * invMat.Row0.Y +
                       norm.Z * invMat.Row0.Z;

            result.Y = norm.X * invMat.Row1.X +
                       norm.Y * invMat.Row1.Y +
                       norm.Z * invMat.Row1.Z;

            result.Z = norm.X * invMat.Row2.X +
                       norm.Y * invMat.Row2.Y +
                       norm.Z * invMat.Row2.Z;
        }
Exemple #8
0
        public static void TransformVector(ref SCNVector3 vec, ref SCNMatrix4 mat, out SCNVector3 result)
        {
            result.X = vec.X * mat.Row0.X +
                       vec.Y * mat.Row1.X +
                       vec.Z * mat.Row2.X;

            result.Y = vec.X * mat.Row0.Y +
                       vec.Y * mat.Row1.Y +
                       vec.Z * mat.Row2.Y;

            result.Z = vec.X * mat.Row0.Z +
                       vec.Y * mat.Row1.Z +
                       vec.Z * mat.Row2.Z;
        }
Exemple #9
0
        public static void TransformPosition(ref SCNVector3 pos, ref SCNMatrix4 mat, out SCNVector3 result)
        {
            result.X = pos.X * mat.Row0.X +
                       pos.Y * mat.Row1.X +
                       pos.Z * mat.Row2.X +
                       mat.Row3.X;

            result.Y = pos.X * mat.Row0.Y +
                       pos.Y * mat.Row1.Y +
                       pos.Z * mat.Row2.Y +
                       mat.Row3.Y;

            result.Z = pos.X * mat.Row0.Z +
                       pos.Y * mat.Row1.Z +
                       pos.Z * mat.Row2.Z +
                       mat.Row3.Z;
        }
Exemple #10
0
        static SCNMatrix4 []? FromNSArray(NSArray?nsa)
        {
            if (nsa is null)
            {
                return(null);
            }

            var count = nsa.Count;
            var ret   = new SCNMatrix4 [count];

            for (nuint i = 0; i < count; i++)
            {
                ret [i] = Runtime.GetNSObject <NSValue> (nsa.ValueAt(i)) !.SCNMatrix4Value;
            }

            return(ret);
        }
Exemple #11
0
        /// <summary>Transform a Vector by the given Matrix</summary>
        /// <param name="vec">The vector to transform</param>
        /// <param name="mat">The desired transformation</param>
        /// <param name="result">The transformed vector</param>
        public static void Transform(ref SCNVector4 vec, ref SCNMatrix4 mat, out SCNVector4 result)
        {
            result.X = vec.X * mat.Row0.X +
                       vec.Y * mat.Row1.X +
                       vec.Z * mat.Row2.X +
                       vec.W * mat.Row3.X;

            result.Y = vec.X * mat.Row0.Y +
                       vec.Y * mat.Row1.Y +
                       vec.Z * mat.Row2.Y +
                       vec.W * mat.Row3.Y;

            result.Z = vec.X * mat.Row0.Z +
                       vec.Y * mat.Row1.Z +
                       vec.Z * mat.Row2.Z +
                       vec.W * mat.Row3.Z;

            result.W = vec.X * mat.Row0.W +
                       vec.Y * mat.Row1.W +
                       vec.Z * mat.Row2.W +
                       vec.W * mat.Row3.W;
        }
Exemple #12
0
        public static SCNVector3 TransformPerspective(SCNVector3 vec, SCNMatrix4 mat)
        {
            SCNVector4 h = Transform(vec, mat);

            return(new SCNVector3(h.X / h.W, h.Y / h.W, h.Z / h.W));
        }
Exemple #13
0
        public static void Transform(ref SCNVector3 vec, ref SCNMatrix4 mat, out SCNVector4 result)
        {
            SCNVector4 v4 = new SCNVector4(vec.X, vec.Y, vec.Z, 1.0f);

            SCNVector4.Transform(ref v4, ref mat, out result);
        }
Exemple #14
0
        public static void TransformNormal(ref SCNVector3 norm, ref SCNMatrix4 mat, out SCNVector3 result)
        {
            SCNMatrix4 Inverse = SCNMatrix4.Invert(mat);

            SCNVector3.TransformNormalInverse(ref norm, ref Inverse, out result);
        }
Exemple #15
0
 public static SCNVector3 TransformNormal(SCNVector3 norm, SCNMatrix4 mat)
 {
     mat.Invert();
     return(TransformNormalInverse(norm, mat));
 }