Ejemplo n.º 1
0
        public Scientrace.Vector modifyVectorForSubElements(Scientrace.Vector aVector, XElement xe)
        {
            Scientrace.Vector retvec = aVector;

            foreach (XAttribute xat in xe.Attributes())
            {
                string attributeName = xat.Name.ToString();
                switch (attributeName)
                {
                case "Multiply":
                    retvec = retvec * Convert.ToDouble(xat.Value);
                    break;

                case "NewLength":
                    double newlength = Convert.ToDouble(xat.Value);
                    if (newlength == 0)
                    {
                        retvec = retvec * 0;
                        break;
                    }
                    retvec = retvec.normaliseIfNotZero() * newlength;
                    break;

                case "Tag":
                    //do nothing
                    break;

                default:
                    //Console.WriteLine("WARNING: Unknown vector attribute modification {"+attributeName+"} detected.");
                    break;
                }
            }
            foreach (XElement xel in xe.Elements())
            {
                string elementName = xel.Name.ToString();
                switch (elementName)
                {
                case "Rotate":
                    retvec = this.rotateVector(retvec, xel);
                    break;

                case "Translate":
                    retvec = this.translateVector(retvec, xel);
                    break;

                case "AverageWith":
                    retvec = this.averageVector(retvec, xel);
                    break;

                case "Multiply":
                    retvec = this.multiplyVector(retvec, xel);
                    break;

                case "Formula":
                    retvec = this.formulaVector(retvec, xel);
                    break;

                default:
                    Console.WriteLine("WARNING: Unknown vector modification {" + elementName + "} detected. Perhaps the tense has changed? Should be active (Rotate instead of Rotated etc).");
                    break;
                }
            }
            return(retvec);
        }