コード例 #1
0
ファイル: Tracer.cs プロジェクト: tgjones/rasteracer
        public bool IsShadowed(Primitive currentPrimitive, Ray tRayToLight, float fDistanceToLight)
        {
            // check every other sphere
            foreach (Primitive primitive in m_pScene.Primitives)
            {
                // spheres don't self-shadow
                if (primitive == currentPrimitive)
                {
                    continue;
                }

            // check for intersection
                float fDistance;
                if (primitive.Intersect(tRayToLight, out fDistance))
                {
                    // check that intersection is not past the light
                    if (fDistance < fDistanceToLight)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
コード例 #2
0
ファイル: Tracer.cs プロジェクト: tgjones/rasteracer
        public FloatColour TraceRay(Primitive pIgnorePrimitive, Ray tRay, int nDepth)
        {
            // check whether we have reached maximum recursion depth
            if (nDepth > 6)
            {
                //return new Colour(0, 0, 0);
                return new FloatColour(1);
            }

            // declare intersection variables
            float fClosestIntersectionDistance = float.MaxValue;
            Primitive closestIntersectedPrimitive = null;

            // loop through all objects in scene
            foreach (Primitive primitive in m_pScene.Primitives)
            {
                // test for intersection
                float fDistance;
                if (primitive.Intersect(tRay, out fDistance))
                {
                    // check that we are closer than the last intersection
                    if (fDistance < fClosestIntersectionDistance)
                    {
                        // set closest intersection
                        fClosestIntersectionDistance = fDistance;
                        closestIntersectedPrimitive = primitive;
                    }
                }
            }

            // if nothing was intersected, set to background colour
            FloatColour tColour = new FloatColour(Color.CornflowerBlue);
            if (closestIntersectedPrimitive != null) // test for intersection
            {
                tColour = closestIntersectedPrimitive.Shade(this,
                    tRay, fClosestIntersectionDistance, nDepth + 1);
            }

            tColour = FloatColour.Min(tColour, new FloatColour(1));

            // return colour
            return tColour;
        }