예제 #1
0
        private Vector3 AddNormalToVectorSum(Vector3 sum, XYZType normal)
        {
            var newSum = new Vector3()
            {
                X = sum[0] + normal.x,
                Y = sum[1] + normal.y,
                Z = sum[2] + normal.z
            };

            return(newSum);
        }
예제 #2
0
        private XYZType[] GetNewNormals()
        {
            var sampleHeight = _size.Height - 1;
            var sampleWidth  = _size.Width - 1;

            var normals = new XYZType[sampleHeight * sampleWidth];

            for (var z = 0; z < sampleHeight; ++z)
            {
                for (var x = 0; x < sampleWidth; ++x)
                {
                    var normal = GetNormalForPosition(x, z);

                    var sampleIndex = (z * sampleHeight) + x;

                    normals[sampleIndex] = normal;
                }
            }

            return(normals);
        }
예제 #3
0
        private XYZType GetNormalForPosition(int x, int z)
        {
            var index  = GetIndexFromPosition(x, z);
            var right  = GetRelativeIndex(RelativePosition.Right, index);
            var bottom = GetRelativeIndex(RelativePosition.BottomMiddle, index);

            var vertex1 = new Vector3(HeightMap[index].x, HeightMap[index].y, HeightMap[index].z);
            var vertex2 = new Vector3(HeightMap[right].x, HeightMap[right].y, HeightMap[right].z);
            var vertex3 = new Vector3(HeightMap[bottom].x, HeightMap[bottom].y, HeightMap[bottom].z);

            var vector1 = vertex1 - vertex3;
            var vector2 = vertex3 - vertex2;

            var crossProduct = Vector3.Cross(vector1, vector2);

            var normal = new XYZType()
            {
                x = crossProduct.X,
                y = crossProduct.Y,
                z = crossProduct.Z
            };

            return(normal);
        }