예제 #1
0
        internal override Intersection Intersect(
            Vector3 start, Vector3 end,
            ref FootprintDebugInfo debugInfo)
        {
            int stepCount = 5;

            //float near = 2;
            //float far = 10;
            //Vector2 start = (near / (float)ray.Direction.Z) * new Vector2((float)ray.Origin.X, (float)ray.Origin.Y);
            //Vector3d rayEnd = ray.Origin + ray.Direction;
            //Vector2 end = (far / (float)ray.Direction.Z) * new Vector2((float)rayEnd.X, (float)rayEnd.Y);

            Vector2 startXY = start.Xy;
            Vector2 endXY   = end.Xy;

            float depthSize    = 1;
            float currentDepth = 0;
            float isecDepth    = 1;

            Vector2 position = startXY;

            for (int i = 0; i < stepCount; i++)
            {
                depthSize *= 0.5f;
                position   = startXY + currentDepth * endXY;
                float hfDepth = HeightField.GetDepthBilinear(position, 0);
                if (currentDepth >= hfDepth)
                {
                    isecDepth     = currentDepth;
                    currentDepth -= 2 * depthSize;
                }
                currentDepth += depthSize;
            }
            if (isecDepth < (1 - 0.0001))
            {
                return(new Intersection(new Vector3d(position.X, position.Y, isecDepth)));
            }
            else
            {
                return(null);
            }
        }
        internal override Intersection Intersect(Vector3 start, Vector3 end, ref FootprintDebugInfo debugInfo)
        {
            int     steps   = (int)Math.Floor(Math.Max((end - start).Xy.Length, 1));
            Vector3 rayStep = (end - start) / (float)steps;
            //Vector3 rayStep = (end - start) / (float)Steps;

            Vector3 currentPos    = start;
            int     prevIndicator = GetRayLayerIndicator(start.Z, HeightField.GetDepthBilinear(start.Xy, 0));
            int     isecLayer     = 0;

            for (int i = 0; i < steps; i++)
            {
                currentPos += rayStep;
                float layerDepth = HeightField.GetDepthBilinear(currentPos.Xy, 0);
                int   indicator  = GetRayLayerIndicator(currentPos.Z, layerDepth);
                if (layerDepth > 0)
                {
                    // some data present

                    // Find the first layer with indicator value 1. In case
                    // of a single layer it is the single value.
                    int indicatorDiff = prevIndicator - indicator;
                    if (indicatorDiff == 1)
                    {
                        isecLayer = 1;
                    }
                    if (isecLayer != 0)
                    {
                        if (debugInfo != null)
                        {
                            debugInfo.LayerOfIntersection = isecLayer - 1;
                        }
                        return(new Intersection((Vector3d)currentPos));
                        // TODO: grab color from the particular color layer
                    }
                }
                prevIndicator = indicator;
            }
            return(null);
        }