Example #1
0
        }         // end func. redirect

        public List <Scientrace.Trace> partialReflectRefract(Scientrace.Object3d fromObject3d, Scientrace.Object3d toObject3d,
                                                             Scientrace.Intersection intersection, UnitVector surfaceNormal)
        {
            /*double oldrefindex = fromObject3d.materialproperties.refractiveindex(this);
             * double newrefindex = toObject3d.materialproperties.refractiveindex(this);*/
            List <Scientrace.Trace> newTraces = new List <Trace>();

            Scientrace.Trace refractTrace = this.fork("_pr");

            refractTrace.currentObject           = toObject3d;
            refractTrace.traceline.startingpoint = intersection.enter.loc;

            Scientrace.UnitVector normal = intersection.enter.flatshape.plane.getNorm()
                                           .orientedAgainst(this.traceline.direction)
                                           .tryToUnitVector();
            // Evaluate absorption by toObject3d
            refractTrace.absorpByObject(toObject3d, normal, fromObject3d);
            if (refractTrace.isEmpty())
            {
                newTraces.Add(refractTrace);
                return(newTraces);
            }

            // CHECK whether (partial) reflection occurs...
            if ((toObject3d.materialproperties.reflects) || ((intersection.leaving) && (fromObject3d.materialproperties.reflects)))
            {
                //double refcoef = toObject3d.materialproperties.reflection(refractTrace, surfaceNormal, this.currentObject);
                double refcoef = toObject3d.materialproperties.reflection(refractTrace, surfaceNormal, fromObject3d.materialproperties);

                Scientrace.Trace reflectTrace = refractTrace.fork("_R");         //.clone();	reflectrace.nodecount++;
                reflectTrace.intensity = refractTrace.intensity * refcoef;
                //intensity shouldn't spawn nor disappear here
                refractTrace.intensity = refractTrace.intensity - reflectTrace.intensity;
                //Scientrace.Spot normspot = new Scientrace.Spot(norm.toLocation()+intersection.enter.loc, null, 1);

                //CHANGED 20131030
                //reflectrace.traceline = newtrace.reflectAt(intersection.enter.flatshape.plane);
                reflectTrace.traceline = refractTrace.reflectLineAbout(reflectTrace.traceline, surfaceNormal);

                //ADDED @ 20130122: the parial internal reflected trace should have the current object as oldobject.
                reflectTrace.currentObject = this.currentObject;         //CURRENT OBJECT DOES NOT CHANGE FOR (partial)INTERNAL REFLECTION!
                newTraces.Add(reflectTrace);
            }

            this.initCreatedRefractTrace(refractTrace, surfaceNormal, fromObject3d, toObject3d);
            newTraces.Add(refractTrace);
            return(newTraces);
        }         // end func partialReflectRefract