public static void readCameraSettings(XElement x3d_or_xenv_element)
 {
     CustomXMLDocumentOperations X = new CustomXMLDocumentOperations();
     Scientrace.Vector cameraviewpoint = Scientrace.TraceJournal.Instance.cameraviewpoint;
     Scientrace.Vector camrotationvec = Scientrace.TraceJournal.Instance.camrotationvector;
     Scientrace.TraceJournal.Instance.labelaxes = X.getXBool(x3d_or_xenv_element, "DrawAxes", Scientrace.TraceJournal.Instance.labelaxes);
     double camrotationangle = Scientrace.TraceJournal.Instance.camrotationangle;
     XElement camfrom = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraFrom"));
     XElement camrot = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraRotation"));
     if (camfrom !=null) {
     cameraviewpoint = X.getXNzVector(camfrom);
     Scientrace.Vector camdirvec = cameraviewpoint.negative();
     Scientrace.NonzeroVector defvec = new Scientrace.NonzeroVector(0,0,-1);
     camrotationangle = defvec.angleWith(camdirvec);
     camrotationvec = defvec.crossProduct(camdirvec);
     }
     if (camrot != null) {
     camrotationvec = X.getXVectorByName(camrot, "Vector");
     camrotationangle = X.getXAngleByName(camrot, "Angle");
     }
     Scientrace.TraceJournal.Instance.cameraviewpoint = X.getXVectorByName(x3d_or_xenv_element, "CameraViewpoint", cameraviewpoint);
     Scientrace.TraceJournal.Instance.camrotationangle = camrotationangle;
     if (camrotationvec != null)
     Scientrace.TraceJournal.Instance.camrotationvector = camrotationvec;
 }
Beispiel #2
0
        public static void readCameraSettings(XElement x3d_or_xenv_element)
        {
            CustomXMLDocumentOperations X = new CustomXMLDocumentOperations();

            Scientrace.Vector cameraviewpoint = Scientrace.TraceJournal.Instance.cameraviewpoint;
            Scientrace.Vector camrotationvec  = Scientrace.TraceJournal.Instance.camrotationvector;
            Scientrace.TraceJournal.Instance.labelaxes = X.getXBool(x3d_or_xenv_element, "DrawAxes", Scientrace.TraceJournal.Instance.labelaxes);
            double   camrotationangle = Scientrace.TraceJournal.Instance.camrotationangle;
            XElement camfrom          = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraFrom"));
            XElement camrot           = (x3d_or_xenv_element == null? null:x3d_or_xenv_element.Element("CameraRotation"));

            if (camfrom != null)
            {
                cameraviewpoint = X.getXNzVector(camfrom);
                Scientrace.Vector        camdirvec = cameraviewpoint.negative();
                Scientrace.NonzeroVector defvec    = new Scientrace.NonzeroVector(0, 0, -1);
                camrotationangle = defvec.angleWith(camdirvec);
                camrotationvec   = defvec.crossProduct(camdirvec);
            }
            if (camrot != null)
            {
                camrotationvec   = X.getXVectorByName(camrot, "Vector");
                camrotationangle = X.getXAngleByName(camrot, "Angle");
            }
            Scientrace.TraceJournal.Instance.cameraviewpoint  = X.getXVectorByName(x3d_or_xenv_element, "CameraViewpoint", cameraviewpoint);
            Scientrace.TraceJournal.Instance.camrotationangle = camrotationangle;
            if (camrotationvec != null)
            {
                Scientrace.TraceJournal.Instance.camrotationvector = camrotationvec;
            }
        }
        public string angleToRGB(Scientrace.Spot aCasualty, PhysicalObject3d physObj)
        {
            UnitVector inAngle = aCasualty.trace.traceline.direction;

            Scientrace.Parallelogram pg   = physObj.getDistributionSurface();
            Scientrace.NonzeroVector norm = physObj.getSurfaceNormal();

            UnitVector y = pg.plane.v.toUnitVector();
            UnitVector x = null;

            try {
                x = norm.crossProduct(y).tryToUnitVector();
            } catch { throw new ZeroNonzeroVectorException("The vertical vector (plane.v) is parallel to the unit normal."); }
            double dx = x.dotProduct(inAngle);
            double dy = y.dotProduct(inAngle);

            double lengthFraction = Math.Sqrt((dx * dx) + (dy * dy));
            //Console.WriteLine("Length: "+lengthFraction+ " vs: "+((x*dx)+(y*dy)).length);

            double angle = Math.Atan2(dy, dx);

            return(this.angleToHTML(angle, 2 * Math.Asin(lengthFraction) / Math.PI));

            //physObj.getSurfaceNormal()
            //aCasualty.object3d.
//		throw new Exception("Not yet implemented");
        }
Beispiel #4
0
 protected void init_Loc_width_height(Scientrace.Location loc, Scientrace.NonzeroVector u, Scientrace.NonzeroVector v)
 {
     this.parallelogram          = new Scientrace.Parallelogram(loc, u, v);
     this.front_normal_direction = u.crossProduct(v).tryToUnitVector();
     this.preserveSVGRatio();
     this.addSurfaceMarkers();
 }
 public void fillOrtogonalVectors(ref Scientrace.NonzeroVector refVec1, ref Scientrace.NonzeroVector refVec2)
 {
     Scientrace.UnitVector tRefvec = Scientrace.UnitVector.x1vector();
     if (Math.Abs(this.toUnitVector().dotProduct(tRefvec)) > 0.8)
     {
         tRefvec = Scientrace.UnitVector.y1vector();
     }
     refVec1 = tRefvec.crossProduct(this).tryToUnitVector();
     refVec2 = refVec1.crossProduct(this).tryToUnitVector();
 }
        public string getX3DRotationTag(Scientrace.NonzeroVector fromVector, Scientrace.NonzeroVector toVector)
        {
            Scientrace.Vector r     = fromVector.crossProduct(toVector);
            double            angle =
                Math.Acos(toVector.normalized().dotProduct(fromVector.normalized()))         // the angle to be rotated
                * Math.Sign(r.crossProduct(fromVector).dotProduct(toVector));

            try {
                return("<Transform rotation='" + r.tryToUnitVector().trico() + " " + angle + "' >");
            } catch {                  // if fromVector has the same direction as toVector, the crossProduct is a zerovector which cannot be normalized.
                return("<Transform>"); //no transformation, just open so it can be closed afterwards
            }
        }
Beispiel #7
0
        /// <summary>
        /// Use function below to transform a vector over any angle v. Keep in mind that this
        /// function uses significantly more processingpower than the aboutX,Y,Z functions.
        /// </summary>
        /// <param name="v">
        /// A <see cref="Scientrace.NonzeroVector"/> about which the vector should be rotated
        /// </param>
        /// <param name="radians">
        /// A <see cref="System.Double"/> an angle in radians about which the vetor should be rotated
        /// anticlockwise with the vector V rising towards the viewer.
        /// </param>
        /// <returns>
        /// A <see cref="Vector"/> which is the result of the rotating operation. The original (this)
        /// vector is not modified during this operation.
        /// </returns>
        public Vector rotateAboutVector(Scientrace.NonzeroVector v, double radians)
        {
            NonzeroVector tv1;

            if (Math.Abs(new NonzeroVector(1, 0, 0).normalized().dotProduct(v.normalized())) < 0.9)
            {
                //throw new Exception("A: "+v.trico()+" cross: "+new NonzeroVector(1,0,0).crossProduct(v));
                tv1 = new NonzeroVector(1, 0, 0).crossProduct(v).tryToNonzeroVector().normalized();
            }
            else
            {
                tv1 = new NonzeroVector(0, 1, 0).crossProduct(v).tryToNonzeroVector().normalized();
            }
            NonzeroVector tv2 = v.crossProduct(tv1).tryToNonzeroVector().normalized();
            VectorTransformOrthonormal vtrf = new VectorTransformOrthonormal(tv1, tv2, v);
            Vector tvec = vtrf.transform(this);

            tvec = tvec.rotateAboutZ(radians);
            return(vtrf.transformback(tvec));
        }
        public VectorTransform(Scientrace.NonzeroVector u, Scientrace.NonzeroVector v, int swapz)
        {
            //third base coordinate orthogonal on both u and v.
            Scientrace.Vector w = u.crossProduct(v).tryToUnitVector();
            switch (swapz)
            {
            case VectorTransform.SWAP_U_WITH_W:
                //for some reasons it might be usefull to change u and w
                this.inituvw(w, v, u);
                break;

            case VectorTransform.SWAP_V_WITH_W:
                //or v and w
                this.inituvw(u, w, v);
                break;

            default:
                //normal init
                this.inituvw(u, v, w);
                break;
            }
        }
Beispiel #9
0
        public Scientrace.SpiralLightSource setSpiralLightFromXData(XElement xlight, List <Scientrace.UniformTraceModifier> utms,
                                                                    Scientrace.Object3dEnvironment env)
        {
            /* "Spiral"
             * d class.radius, d class.loops, d distance, i beamcount, i maxinteractions, d minintensity
             * i modulomultiplier, str spectrum, vec location, vec direction */
            double radius = this.X.getXDouble(xlight.Attribute("Radius"));

            if (radius < 0)
            {
                throw new ArgumentOutOfRangeException("Radius " + radius + " out of range");
            }
            double distance  = this.X.getXDouble(xlight.Attribute("Distance"), 0);
            int    beamcount = this.X.getXInt(xlight.Attribute("RayCount"), this.X.getXInt(xlight.Attribute("BeamCount")));
            //int maxinteractions = this.X.getXInt(xlight, "MaxInteractions", 8); //default value max_interactions -> 8
            double minintensity = this.X.getXDouble(xlight, "MinIntensity", 0.2);             //default minimum intensity for tracing set to 1%
            //Spiralspecific

            double loops = this.X.getXDouble(xlight, "Loops", -1);

            if (loops == -1)
            {
                loops = 1.0154 * Math.Pow(Math.PI * 2 * (1 - Math.Sqrt(((double)beamcount - 1) / (double)beamcount)), -0.5);
                Console.WriteLine("Number of loops for " + beamcount + " beams set to: {" + loops.ToString("#,0.000") + "}.");
            }

            Scientrace.NonzeroVector light_direction = this.X.getXNzVector(xlight.Element("Direction"));
            Scientrace.NonzeroVector spiral_axis     = this.X.getXNzVector(xlight.Element("SpiralAxis"));
            Scientrace.Location      centerloc       = this.X.getXVector(xlight.Element("Location")).toLocation();

            /*Scientrace.Location locoffset = (light_direction.toVector().negative()*distance).toLocation(); //distance cm above surface
             * Scientrace.Location loc = locoffset + centerloc; */
            XMLSpectrumParser xsp = new XMLSpectrumParser();

            Scientrace.LightSpectrum spectrum = xsp.parseLightSpectrum(xlight.Element("Spectrum"));
            if (spectrum == null)
            {
                throw new Exception("LightSpectrum " + xlight.Element("Spectrum").ToString() + " unknown");
            }

            double divangle    = 0;
            double divdistance = 0;

            Scientrace.NonzeroVector divpinvec = null;             //=  new Scientrace.NonzeroVector(0,1,0);
            int  divsteps       = 1;
            bool divincludebase = true;

            this.getDivergence(xlight, ref divangle, ref divpinvec, ref divdistance, ref divincludebase, ref divsteps);
            if (divangle > 0)
            {
                if (divpinvec.crossProduct(light_direction).length == 0)
                {
                    throw new ArgumentOutOfRangeException("divpinvec", "Divergence Pinvector (" + divpinvec.trico() + ") is parallel to light directon (" +
                                                          light_direction.trico() + ")");
                }
            }

            // INSERT OPERATION THAT MAKES BOTH SPIRAL PLANE VECTORS ORTHOGONAL TO DIRECTION
            Scientrace.Plane spiralplane = Scientrace.Plane.newPlaneOrthogonalTo(centerloc, spiral_axis);
            //Scientrace.NonzeroVector direction = light_direction.tryToUnitVector();


            Scientrace.SpiralLightSource retlight = new Scientrace.SpiralLightSource(env, centerloc, light_direction.toUnitVector(),
                                                                                     spiralplane, beamcount, radius, loops, distance, spectrum);


/* BEFORE REMOVAL OF DISPERSION_STEPS			Scientrace.LightSource retlight = new Scientrace.SpiralLightSource(env, loc, light_direction.toUnitVector(),
 *                              spiralplane, beamcount, radius, loops, spectrum,
 *                              divangle, divpinvec, divdistance, divincludebase, divsteps);  */
            //retlight.max_interactions = maxinteractions;
            retlight.minimum_intensity_fraction = minintensity;
            retlight.lightsource_modifiers.AddRange(utms);
            //retlight.createStartTraces();
            return(retlight);
        }
 public VectorTransform(Scientrace.NonzeroVector u, Scientrace.NonzeroVector v)
 {
     //third base coordinate orthogonal on both u and v.
     this.inituvw(u, v, u.crossProduct(v).tryToUnitVector());
 }