Example #1
0
        // Construct a rotation matrix
        public static Mat4D Rotation(double degrees, Double3 vec)
        {
            vec.Normalize();
            var alpha = degrees * Pi / 180.0f;
            var s     = System.Math.Sin(alpha);
            var c     = System.Math.Cos(alpha);
            var t     = 1.0f - c;

            return(new Mat4D(0.0f)
            {
                Data =
                {
                    [0] = t * vec.X * vec.X + c,
                    [1] = t * vec.X * vec.Y - s * vec.Z,
                    [2] = t * vec.X * vec.Z + s * vec.Y,
                    [4] = t * vec.X * vec.Y + s * vec.Z,
                    [5] = t * vec.Y * vec.Y + c,
                    [6] = t * vec.Y * vec.Z - s * vec.X,
                    [8] = t * vec.X * vec.Z - s * vec.Y,
                    [9] = t * vec.Y * vec.Z + s * vec.X,
                    [10] = t * vec.Z * vec.Z + c,
                    [15] = 1.0f
                }
            });
        }
Example #2
0
        // Defines the error metric used in the optimization process of the mappings
        // The goal is that the direction from base point on a triangle in of the low resoltuion mesh to the high resolution point is identical
        // to the direction of the interpolated normal at this location
        // o is the point in the high resolution mesh
        // a, b, c are the quantities at the 3 corners of a triangle (simple names since the corners are always labelled a, b, c)
        public static double ErrorMeasure(Double3 o, double u, double v, Double3 a, Double3 b, Double3 c, Double3 nA, Double3 nB, Double3 nC)
        {
            double  w = 1 - u - v;
            Double3 p = u * a + v * b + w * c;    //Base point on low resolution mesh
            Double3 n = u * nA + v * nB + w * nC; //Interpolated normal

            n.Normalize();
            // Don't normalize p-o since the further a point is away from it's base triangle,
            // the more important it gets that the direction matches the one of the normal
            return(Double3.Cross(n, p - o).LengthSquared); // The magnitude of the cross product becomes zero if the vectors point in the same direction
        }
Example #3
0
        public Double3 GetHighResPoint(PointMapping m)
        {
            Double3 a = pointsLowRes[m.Triangle.A];
            Double3 b = pointsLowRes[m.Triangle.B];
            Double3 c = pointsLowRes[m.Triangle.C];

            Double3 p = m.BarycentricCoordinates.X * a + m.BarycentricCoordinates.Y * b + m.BarycentricCoordinates.Z * c;


            Double3 nA = normalsLowRes[m.Triangle.A];
            Double3 nB = normalsLowRes[m.Triangle.B];
            Double3 nC = normalsLowRes[m.Triangle.C];
            Double3 n  = m.BarycentricCoordinates.X * nA + m.BarycentricCoordinates.Y * nB + m.BarycentricCoordinates.Z * nC;

            //Double3 triangleNormal = Double3.Cross(b - a, c - a).Normalized();
            n.Normalize();

            return(p + m.Offset * n);
        }