Наследование: MonoBehaviour
 public void OpAddition()
 {
     var acceleration1 = new Acceleration(3600, AccelerationUnit.MeterPerSecondSquared);
     var acceleration2 = new Acceleration(3.6, AccelerationUnit.KilometerPerSecondSquared);
     (acceleration1 + acceleration2).ShouldEqual(new Acceleration(7200, AccelerationUnit.MeterPerSecondSquared));
     (acceleration2 + acceleration1).ShouldEqual(new Acceleration(7.2, AccelerationUnit.KilometerPerSecondSquared));
 }
 public void VerifyAllEnums()
 {
     var acceleration = new Acceleration(1, AccelerationUnit.BaseUnit);
     var angle = new Angle(1, AngleUnit.BaseUnit);
     var angularAcceleration = new AngularAcceleration(1, AngularAccelerationUnit.BaseUnit);
     var area = new Area(1, AreaUnit.BaseUnit);
     var density = new MassDensity(1, MassDensityUnit.BaseUnit);
     var electricCurrent = new ElectricCurrent(1, ElectricCurrentUnit.BaseUnit);
     var electricResistance = new ElectricResistance(1, ElectricResistanceUnit.BaseUnit);
     var electricVoltage = new ElectricPotential(1, ElectricPotentialUnit.BaseUnit);
     var energy = new Energy(1, EnergyUnit.BaseUnit);
     var force = new Force(1, ForceUnit.BaseUnit);
     var frequency = new Frequency(1, FrequencyUnit.BaseUnit);
     var jerk = new Jerk(1, JerkUnit.BaseUnit);
     var length = new Length(1, LengthUnit.BaseUnit);
     var mass = new Mass(1, MassUnit.BaseUnit);
     var massFlowRate = new MassFlowRate(1, MassFlowRateUnit.BaseUnit);
     var momentum = new Momentum(1, MomentumUnit.BaseUnit);
     var numeric = new Numeric(1, NumericUnit.BaseUnit);
     var power = new Power(1, PowerUnit.BaseUnit);
     var pressure = new Pressure(1, PressureUnit.BaseUnit);
     var speed = new Speed(1, SpeedUnit.BaseUnit);
     var temperature = new Temperature(1, TemperatureUnit.BaseUnit);
     var time = new Time(1, TimeUnit.BaseUnit);
     var torque = new Torque(1, TorqueUnit.BaseUnit);
     var volume = new Volume(1, VolumeUnit.BaseUnit);
     var volumetricFlowRate = new VolumetricFlowRate(1, VolumetricFlowRateUnit.BaseUnit);
 }
        public void OpDivision()
        {
            var acceleration1 = new Acceleration(3600, AccelerationUnit.MeterPerSecondSquared);
            var acceleration2 = new Acceleration(3.6, AccelerationUnit.KilometerPerSecondSquared);
            (acceleration1 / acceleration2).ShouldBeWithinEpsilonOf(1);
            (acceleration2 / acceleration1).ShouldBeWithinEpsilonOf(1);

            (acceleration1 / 2).ShouldEqual(new Acceleration(1800, AccelerationUnit.MeterPerSecondSquared));
            (acceleration2 / 2).ShouldEqual(new Acceleration(1.8, AccelerationUnit.KilometerPerSecondSquared));
        }
 public void OpInverseEquals()
 {
     var acceleration1 = new Acceleration(3600, AccelerationUnit.MeterPerSecondSquared);
     var acceleration2 = new Acceleration(3.6, AccelerationUnit.KilometerPerSecondSquared);
     var acceleration3 = new Acceleration(4500, AccelerationUnit.MeterPerSecondSquared);
     (acceleration1 != acceleration2).ShouldBeFalse();
     (acceleration2 != acceleration1).ShouldBeFalse();
     (acceleration1 != acceleration3).ShouldBeTrue();
     (acceleration3 != acceleration1).ShouldBeTrue();
 }
 public void OpGreaterThanOrEqual()
 {
     var acceleration1 = new Acceleration(3600, AccelerationUnit.MeterPerSecondSquared);
     var acceleration2 = new Acceleration(3.6, AccelerationUnit.KilometerPerSecondSquared);
     var acceleration3 = new Acceleration(4500, AccelerationUnit.MeterPerSecondSquared);
     (acceleration1 >= acceleration3).ShouldBeFalse();
     (acceleration3 >= acceleration1).ShouldBeTrue();
     (acceleration1 >= acceleration2).ShouldBeTrue();
     (acceleration2 >= acceleration1).ShouldBeTrue();
 }
Пример #6
0
 static void Main(string[] args)
 {
     Time t = new Time(5);
     Speed v = new Speed(10);
     Distance s = new Distance(10);
     Acceleration a = new Acceleration(3);
     s = 2 + (a * (t^2)) / 2;
     Converter conv = new Converter();
     Console.WriteLine(a.GiveValueInSI());
     Console.ReadLine();
 }
Пример #7
0
        //---------------------------------------------------------------------
        public void add(float time_x, EbVector3 acce, float duration)
        {
            if (duration <= 0) return;

            if (mAcceleration.ContainsKey(time_x))
            {
                EbLog.Note("DynamicSystem::add::error.");
                return;
            }

            Acceleration acceleration = new Acceleration();
            acceleration.acceleration = acce;
            acceleration.duration = duration;
            mAcceleration.Add(time_x, acceleration);
        }
 public void OpEquals()
 {
     var acceleration1 = new Acceleration(3600, AccelerationUnit.MeterPerSecondSquared);
     var acceleration2 = new Acceleration(3.6, AccelerationUnit.KilometerPerSecondSquared);
     var acceleration3 = new Acceleration(1200, AccelerationUnit.MeterPerSecondSquared);
     (acceleration1 == acceleration2).ShouldBeTrue();
     (acceleration2 == acceleration1).ShouldBeTrue();
     (acceleration1 == acceleration3).ShouldBeFalse();
     (acceleration3 == acceleration1).ShouldBeFalse();
     acceleration1.Equals(acceleration2)
                  .ShouldBeTrue();
     acceleration1.Equals((object)acceleration2)
                  .ShouldBeTrue();
     acceleration2.Equals(acceleration1)
                  .ShouldBeTrue();
     acceleration2.Equals((object)acceleration1)
                  .ShouldBeTrue();
 }
    float[] tmpPlayerPosition; //Temporarily stores the player's position. Used in WallSlide()

    #endregion Fields

    #region Constructors

    public ScriptCharacterPhysics()
    {
        movedz = 0;
        curspeed = new Vector3Ref();
        jumpacceleration = 0;
        isplayeronground = false;
        acceleration = new Acceleration();
        jumpstartacceleration = 0;
        jumpstartaccelerationhalf = 0;
        movespeednow = 0;

        tmpPlayerPosition = new float[3];
        tmpBlockingBlockType = new IntRef();

        constGravity = 0.3f;
        constWaterGravityMultiplier = 3;
        constEnableAcceleration = true;
        constJump = 2.1f;
    }
 public void ConvertToSi( Acceleration a, string dimension)
 {
     if (dimension != "m/s^2")
     {
         if (dimension == "Gal (cm/s^2)")
         {
             a.Value *= 0.01;
         }
         else if (dimension == "ft/s^2")
         {
             a.Value *= 0.304800;
         }
         else if (dimension == "g")
         {
             a.Value *= 9.80665;
         }
         else
         {
             throw new IncorrectDimensionOfAccelerationException();
         }
     }
 }
        public void SetUnitPreferences()
        {
            UnitPreferences usPreferences = UnitPreferences.GetAmericanEnglishUnits();

            var time = new Time(3600, TimeUnit.MilliSecond);
            usPreferences.Fix(time);
            time.Units.Abbreviation.ShouldEqual(usPreferences.TimeUnits.Abbreviation);

            var acceleration = new Acceleration(5, AccelerationUnit.KilometerPerSecondSquared);
            usPreferences.Fix(acceleration);
            acceleration.Units.Abbreviation.ShouldEqual(usPreferences.AccelerationUnits.Abbreviation);

            var angle = new Angle(4, AngleUnit.Grad);
            usPreferences.Fix(angle);
            angle.Units.Abbreviation.ShouldEqual(usPreferences.AngleUnits.Abbreviation);

            var angularAcceleration = new AngularAcceleration(3, AngularAccelerationUnit.RevolutionsPerSecondSquared);
            usPreferences.Fix(angularAcceleration);
            angularAcceleration.Units.Abbreviation.ShouldEqual(usPreferences.AngularAccelerationUnits.Abbreviation);

            var area = new Area(10, AreaUnit.SquareMiles);
            usPreferences.Fix(area);
            area.Units.Abbreviation.ShouldEqual(usPreferences.AreaUnits.Abbreviation);
        }
Пример #12
0
        internal static void Parse(string fileName, out Train train)
        {
            train = new Train();

            CultureInfo culture = CultureInfo.InvariantCulture;

            string[] lines = File.ReadAllLines(fileName, TextEncoding.GetSystemEncodingFromFile(fileName));

            for (int i = 0; i < lines.Length; i++)
            {
                int j = lines[i].IndexOf(';');

                if (j >= 0)
                {
                    lines[i] = lines[i].Substring(0, j).Trim();
                }
                else
                {
                    lines[i] = lines[i].Trim();
                }
            }

            bool ver1220000 = false;

            foreach (string line in lines)
            {
                if (line.Length != 0)
                {
                    string s = line.ToLowerInvariant();

                    switch (s)
                    {
                    case "bve1200000":
                    case "bve1210000":
                    case "bve1220000":
                        ver1220000 = true;
                        break;

                    case "bve2000000":
                    case "openbve":
                        //No action
                        break;

                    default:
                        if (s.ToLowerInvariant().StartsWith("openbve"))
                        {
                            string tt = s.Substring(7, s.Length - 7);
                            int    v;

                            if (int.TryParse(tt, NumberStyles.Float, culture, out v))
                            {
                                if (v > currentVersion)
                                {
                                    Interface.AddMessage(MessageType.Warning, false, $"The train.dat {fileName} was created with a newer version of openBVE. Please check for an update.");
                                }
                            }
                            else
                            {
                                Interface.AddMessage(MessageType.Error, false, $"The train.dat version {lines[0].ToLowerInvariant()} is invalid in {fileName}");
                            }
                        }

                        break;
                    }

                    break;
                }
            }

            Acceleration acceleration = new Acceleration();
            Performance  performance  = new Performance();
            Delay        delay        = new Delay();
            Move         move         = new Move();
            Brake        brake        = new Brake();
            Pressure     pressure     = new Pressure();
            Motor        motor        = new Motor();

            double motorCarMass          = 40.0;
            int    numberOfMotorCars     = 1;
            double trailerCarMass        = 40.0;
            int    numberOfTrailerCars   = 1;
            double lengthOfACar          = 20.0;
            bool   frontCarIsAMotorCar   = false;
            double widthOfACar           = 2.6;
            double heightOfACar          = 3.2;
            double centerOfGravityHeight = 1.5;
            double exposedFrontalArea    = 5.0;
            double unexposedFrontalArea  = 1.6;

            for (int i = 0; i < lines.Length; i++)
            {
                int n = 0;

                switch (lines[i].ToLowerInvariant())
                {
                case "#acceleration":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (n == acceleration.Entries.Count)
                        {
                            acceleration.Entries.Add(new Acceleration.Entry());
                        }

                        string u = lines[i] + ",";
                        int    m = 0;

                        while (true)
                        {
                            int j = u.IndexOf(',');

                            if (j == -1)
                            {
                                break;
                            }

                            string s = u.Substring(0, j).Trim();
                            u = u.Substring(j + 1);
                            double a;

                            if (double.TryParse(s, NumberStyles.Float, culture, out a))
                            {
                                switch (m)
                                {
                                case 0:
                                    acceleration.Entries[n].A0 = Math.Max(a, 0.0);
                                    break;

                                case 1:
                                    acceleration.Entries[n].A1 = Math.Max(a, 0.0);
                                    break;

                                case 2:
                                    acceleration.Entries[n].V1 = Math.Max(a, 0.0);
                                    break;

                                case 3:
                                    acceleration.Entries[n].V2 = Math.Max(a, 0.0);

                                    if (acceleration.Entries[n].V2 < acceleration.Entries[n].V1)
                                    {
                                        double x = acceleration.Entries[n].V1;
                                        acceleration.Entries[n].V1 = acceleration.Entries[n].V2;
                                        acceleration.Entries[n].V2 = x;
                                    }

                                    break;

                                case 4:
                                    if (ver1220000)
                                    {
                                        if (a <= 0.0)
                                        {
                                            acceleration.Entries[n].E = 1.0;
                                        }
                                        else
                                        {
                                            const double c = 1.23315173118822;
                                            acceleration.Entries[n].E = 1.0 - Math.Log(a) * acceleration.Entries[n].V2 * c;

                                            if (acceleration.Entries[n].E > 4.0)
                                            {
                                                acceleration.Entries[n].E = 4.0;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        acceleration.Entries[n].E = a;
                                    }

                                    break;
                                }
                            }

                            m++;
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#performance":
                case "#deceleration":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            switch (n)
                            {
                            case 0:
                                if (a >= 0.0)
                                {
                                    performance.Deceleration = a;
                                }

                                break;

                            case 1:
                                if (a >= 0.0)
                                {
                                    performance.CoefficientOfStaticFriction = a;
                                }

                                break;

                            case 3:
                                if (a >= 0.0)
                                {
                                    performance.CoefficientOfRollingResistance = a;
                                }

                                break;

                            case 4:
                                if (a >= 0.0)
                                {
                                    performance.AerodynamicDragCoefficient = a;
                                }

                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#delay":
                    i++;

                    double[] delayPowerUp       = delay.DelayPower.Select(x => x.Up).ToArray();
                    double[] delayPowerDown     = delay.DelayPower.Select(x => x.Down).ToArray();
                    double[] delayBrakeUp       = delay.DelayBrake.Select(x => x.Up).ToArray();
                    double[] delayBrakeDown     = delay.DelayBrake.Select(x => x.Down).ToArray();
                    double[] delayLocoBrakeUp   = delay.DelayLocoBrake.Select(x => x.Up).ToArray();
                    double[] delayLocoBrakeDown = delay.DelayLocoBrake.Select(x => x.Down).ToArray();

                    delay.DelayPower.Clear();
                    delay.DelayBrake.Clear();
                    delay.DelayLocoBrake.Clear();

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            switch (n)
                            {
                            case 0:
                                if (a >= 0.0)
                                {
                                    delayPowerUp = new[] { a };
                                }

                                break;

                            case 1:
                                if (a >= 0.0)
                                {
                                    delayPowerDown = new[] { a };
                                }

                                break;

                            case 2:
                                if (a >= 0.0)
                                {
                                    delayBrakeUp = new[] { a };
                                }

                                break;

                            case 3:
                                if (a >= 0.0)
                                {
                                    delayBrakeDown = new[] { a };
                                }

                                break;
                            }
                        }
                        else if (lines[i].IndexOf(',') != -1)
                        {
                            switch (n)
                            {
                            case 0:
                                delayPowerUp = lines[i].Split(',').Select(x => double.Parse(x, culture)).ToArray();
                                break;

                            case 1:
                                delayPowerDown = lines[i].Split(',').Select(x => double.Parse(x, culture)).ToArray();
                                break;

                            case 2:
                                delayBrakeUp = lines[i].Split(',').Select(x => double.Parse(x, culture)).ToArray();
                                break;

                            case 3:
                                delayBrakeDown = lines[i].Split(',').Select(x => double.Parse(x, culture)).ToArray();
                                break;

                            case 4:
                                delayLocoBrakeUp = lines[i].Split(',').Select(x => double.Parse(x, culture)).ToArray();
                                break;

                            case 5:
                                delayLocoBrakeDown = lines[i].Split(',').Select(x => double.Parse(x, culture)).ToArray();
                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    for (int j = 0; j < Math.Max(delayPowerUp.Length, delayPowerDown.Length); j++)
                    {
                        Delay.Entry entry = new Delay.Entry();

                        if (j < delayPowerUp.Length)
                        {
                            entry.Up = delayPowerUp[j];
                        }

                        if (j < delayPowerDown.Length)
                        {
                            entry.Down = delayPowerDown[j];
                        }

                        delay.DelayPower.Add(entry);
                    }

                    for (int j = 0; j < Math.Max(delayBrakeUp.Length, delayBrakeDown.Length); j++)
                    {
                        Delay.Entry entry = new Delay.Entry();

                        if (j < delayBrakeUp.Length)
                        {
                            entry.Up = delayBrakeUp[j];
                        }

                        if (j < delayBrakeDown.Length)
                        {
                            entry.Down = delayBrakeDown[j];
                        }

                        delay.DelayBrake.Add(entry);
                    }

                    for (int j = 0; j < Math.Max(delayLocoBrakeUp.Length, delayLocoBrakeDown.Length); j++)
                    {
                        Delay.Entry entry = new Delay.Entry();

                        if (j < delayLocoBrakeUp.Length)
                        {
                            entry.Up = delayLocoBrakeUp[j];
                        }

                        if (j < delayLocoBrakeDown.Length)
                        {
                            entry.Down = delayLocoBrakeDown[j];
                        }

                        delay.DelayLocoBrake.Add(entry);
                    }

                    i--;
                    break;

                case "#move":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            switch (n)
                            {
                            case 0:
                                if (a >= 0.0)
                                {
                                    move.JerkPowerUp = a;
                                }

                                break;

                            case 1:
                                if (a >= 0.0)
                                {
                                    move.JerkPowerDown = a;
                                }

                                break;

                            case 2:
                                if (a >= 0.0)
                                {
                                    move.JerkBrakeUp = a;
                                }

                                break;

                            case 3:
                                if (a >= 0.0)
                                {
                                    move.JerkBrakeDown = a;
                                }

                                break;

                            case 4:
                                if (a >= 0.0)
                                {
                                    move.BrakeCylinderUp = a;
                                }

                                break;

                            case 5:
                                if (a >= 0.0)
                                {
                                    move.BrakeCylinderDown = a;
                                }

                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#brake":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            int b = (int)Math.Round(a);

                            switch (n)
                            {
                            case 0:
                                if (b >= 0 & b <= 2)
                                {
                                    brake.BrakeType = (BrakeSystemType)b;
                                }

                                break;

                            case 1:
                                if (b >= 0 & b <= 2)
                                {
                                    brake.BrakeControlSystem = (EletropneumaticBrakeType)b;
                                }

                                break;

                            case 2:
                                if (a >= 0.0)
                                {
                                    brake.BrakeControlSpeed = a;
                                }

                                break;

                            case 3:
                                if (a <= 0 && a > 3)
                                {
                                    brake.LocoBrakeType = (Brake.LocoBrakeTypes)b;
                                }

                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#pressure":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            switch (n)
                            {
                            case 0:
                                if (a > 0.0)
                                {
                                    pressure.BrakeCylinderServiceMaximumPressure = a;
                                }

                                break;

                            case 1:
                                if (a > 0.0)
                                {
                                    pressure.BrakeCylinderEmergencyMaximumPressure = a;
                                }

                                break;

                            case 2:
                                if (a > 0.0)
                                {
                                    pressure.MainReservoirMinimumPressure = a;
                                }

                                break;

                            case 3:
                                if (a > 0.0)
                                {
                                    pressure.MainReservoirMaximumPressure = a;
                                }

                                break;

                            case 4:
                                if (a > 0.0)
                                {
                                    pressure.BrakePipeNormalPressure = a;
                                }

                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#handle":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            int b = (int)Math.Round(a);

                            switch (n)
                            {
                            case 0:
                                if (b == 0 | b == 1)
                                {
                                    train.Handle.HandleType = (Handle.HandleTypes)b;
                                }

                                break;

                            case 1:
                                if (b > 0)
                                {
                                    train.Handle.PowerNotches = b;
                                }

                                break;

                            case 2:
                                if (b > 0)
                                {
                                    train.Handle.BrakeNotches = b;
                                }

                                break;

                            case 3:
                                if (b >= 0)
                                {
                                    train.Handle.PowerNotchReduceSteps = b;
                                }

                                break;

                            case 4:
                                if (a >= 0 && a < 4)
                                {
                                    train.Handle.HandleBehaviour = (EbHandleBehaviour)b;
                                }

                                break;

                            case 5:
                                if (b > 0)
                                {
                                    train.Handle.LocoBrakeNotches = b;
                                }

                                break;

                            case 6:
                                if (a <= 0 && a > 3)
                                {
                                    train.Handle.LocoBrake = (LocoBrakeType)b;
                                }

                                break;

                            case 7:
                                if (b > 0)
                                {
                                    train.Handle.DriverPowerNotches = b;
                                }

                                break;

                            case 8:
                                if (b > 0)
                                {
                                    train.Handle.DriverBrakeNotches = b;
                                }

                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#cockpit":
                case "#cab":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            switch (n)
                            {
                            case 0:
                                train.Cab.PositionX = a;
                                break;

                            case 1:
                                train.Cab.PositionY = a;
                                break;

                            case 2:
                                train.Cab.PositionZ = a;
                                break;

                            case 3:
                                train.Cab.DriverCar = (int)Math.Round(a);
                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#car":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            int b = (int)Math.Round(a);

                            switch (n)
                            {
                            case 0:
                                if (a > 0.0)
                                {
                                    motorCarMass = a;
                                }

                                break;

                            case 1:
                                if (b >= 1)
                                {
                                    numberOfMotorCars = b;
                                }

                                break;

                            case 2:
                                if (a > 0.0)
                                {
                                    trailerCarMass = a;
                                }

                                break;

                            case 3:
                                if (b >= 0)
                                {
                                    numberOfTrailerCars = b;
                                }

                                break;

                            case 4:
                                if (b > 0.0)
                                {
                                    lengthOfACar = a;
                                }

                                break;

                            case 5:
                                frontCarIsAMotorCar = a == 1.0;
                                break;

                            case 6:
                                if (a > 0.0)
                                {
                                    widthOfACar = a;
                                }

                                break;

                            case 7:
                                if (a > 0.0)
                                {
                                    heightOfACar = a;
                                }

                                break;

                            case 8:
                                centerOfGravityHeight = a;
                                break;

                            case 9:
                                if (a > 0.0)
                                {
                                    exposedFrontalArea = a;
                                }

                                break;

                            case 10:
                                if (a > 0.0)
                                {
                                    unexposedFrontalArea = a;
                                }

                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#device":
                    i++;

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        double a;

                        if (double.TryParse(lines[i], NumberStyles.Float, culture, out a))
                        {
                            int b = (int)Math.Round(a);

                            switch (n)
                            {
                            case 0:
                                if (b >= -1 & b <= 1)
                                {
                                    train.Device.Ats = (AtsModes)b;
                                }

                                break;

                            case 1:
                                if (b >= 0 & b <= 2)
                                {
                                    train.Device.Atc = (AtcModes)b;
                                }

                                break;

                            case 2:
                                train.Device.Eb = a == 1.0;
                                break;

                            case 3:
                                train.Device.ConstSpeed = a == 1.0;
                                break;

                            case 4:
                                train.Device.HoldBrake = a == 1.0;
                                break;

                            case 5:
                                if (b >= -1 & b <= 3)
                                {
                                    train.Device.ReAdhesionDevice = (ReadhesionDeviceType)b;
                                }

                                break;

                            case 6:
                                train.Device.LoadCompensatingDevice = a;
                                break;

                            case 7:
                                if (b >= 0 & b <= 2)
                                {
                                    train.Device.PassAlarm = (PassAlarmType)b;
                                }

                                break;

                            case 8:
                                if (b >= 0 & b <= 2)
                                {
                                    train.Device.DoorOpenMode = (DoorMode)b;
                                }

                                break;

                            case 9:
                                if (b >= 0 & b <= 2)
                                {
                                    train.Device.DoorCloseMode = (DoorMode)b;
                                }

                                break;

                            case 10:
                                if (a >= 0.0)
                                {
                                    train.Device.DoorWidth = a;
                                }

                                break;

                            case 11:
                                if (a >= 0.0)
                                {
                                    train.Device.DoorMaxTolerance = a;
                                }

                                break;
                            }
                        }

                        i++;
                        n++;
                    }

                    i--;
                    break;

                case "#motor_p1":
                case "#motor_p2":
                case "#motor_b1":
                case "#motor_b2":
                {
                    string section = lines[i].ToLowerInvariant();
                    i++;
                    BVEMotorSoundTableEntry[] entries = new BVEMotorSoundTableEntry[800];

                    while (i < lines.Length && !lines[i].StartsWith("#", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (n == entries.Length)
                        {
                            Array.Resize(ref entries, entries.Length << 1);
                        }

                        string u = lines[i] + ",";
                        int    k = 0;

                        while (true)
                        {
                            int j = u.IndexOf(',');

                            if (j == -1)
                            {
                                break;
                            }

                            string s = u.Substring(0, j).Trim();
                            u = u.Substring(j + 1);
                            double a;

                            if (double.TryParse(s, NumberStyles.Float, culture, out a))
                            {
                                int b = (int)Math.Round(a);

                                switch (k)
                                {
                                case 0:
                                    entries[n].SoundIndex = b >= 0 ? b : -1;
                                    break;

                                case 1:
                                    entries[n].Pitch = (float)Math.Max(a, 0.0);
                                    break;

                                case 2:
                                    entries[n].Gain = (float)Math.Max(a, 0.0);
                                    break;
                                }
                            }

                            k++;
                        }

                        i++;
                        n++;
                    }

                    Array.Resize(ref entries, n);
                    i--;

                    switch (section)
                    {
                    case "#motor_p1":
                        motor.Tracks[(int)Motor.TrackInfo.Power1] = Motor.Track.EntriesToTrack(entries);
                        break;

                    case "#motor_p2":
                        motor.Tracks[(int)Motor.TrackInfo.Power2] = Motor.Track.EntriesToTrack(entries);
                        break;

                    case "#motor_b1":
                        motor.Tracks[(int)Motor.TrackInfo.Brake1] = Motor.Track.EntriesToTrack(entries);
                        break;

                    case "#motor_b2":
                        motor.Tracks[(int)Motor.TrackInfo.Brake2] = Motor.Track.EntriesToTrack(entries);
                        break;
                    }
                }
                break;
                }
            }

            int numberOfCars = numberOfMotorCars + numberOfTrailerCars;

            bool[] isMotorCars = new bool[numberOfCars];
            if (numberOfMotorCars == 1)
            {
                if (frontCarIsAMotorCar | numberOfTrailerCars == 0)
                {
                    isMotorCars[0] = true;
                }
                else
                {
                    isMotorCars[numberOfCars - 1] = true;
                }
            }
            else if (numberOfMotorCars == 2)
            {
                if (frontCarIsAMotorCar | numberOfTrailerCars == 0)
                {
                    isMotorCars[0] = true;
                    isMotorCars[numberOfCars - 1] = true;
                }
                else if (numberOfTrailerCars == 1)
                {
                    isMotorCars[1] = true;
                    isMotorCars[2] = true;
                }
                else
                {
                    int i = (int)Math.Ceiling(0.25 * (numberOfCars - 1));
                    int j = (int)Math.Floor(0.75 * (numberOfCars - 1));
                    isMotorCars[i] = true;
                    isMotorCars[j] = true;
                }
            }
            else if (numberOfMotorCars > 0)
            {
                if (frontCarIsAMotorCar)
                {
                    isMotorCars[0] = true;
                    double t = 1.0 + numberOfTrailerCars / (double)(numberOfMotorCars - 1);
                    double r = 0.0;
                    double x = 0.0;

                    while (true)
                    {
                        double y = x + t - r;
                        x = Math.Ceiling(y);
                        r = x - y;
                        int i = (int)x;

                        if (i >= numberOfCars)
                        {
                            break;
                        }

                        isMotorCars[i] = true;
                    }
                }
                else
                {
                    isMotorCars[1] = true;
                    double t = 1.0 + (numberOfTrailerCars - 1) / (double)(numberOfMotorCars - 1);
                    double r = 0.0;
                    double x = 1.0;

                    while (true)
                    {
                        double y = x + t - r;
                        x = Math.Ceiling(y);
                        r = x - y;
                        int i = (int)x;

                        if (i >= numberOfCars)
                        {
                            break;
                        }

                        isMotorCars[i] = true;
                    }
                }
            }

            foreach (bool isMotorCar in isMotorCars)
            {
                Car car = isMotorCar ? (Car) new MotorCar() : new TrailerCar();

                car.Mass   = isMotorCar ? motorCarMass : trailerCarMass;
                car.Length = lengthOfACar;
                car.Width  = widthOfACar;
                car.Height = heightOfACar;
                car.CenterOfGravityHeight = centerOfGravityHeight;
                car.ExposedFrontalArea    = exposedFrontalArea;
                car.UnexposedFrontalArea  = unexposedFrontalArea;
                car.Performance           = (Performance)performance.Clone();
                car.Delay    = (Delay)delay.Clone();
                car.Move     = (Move)move.Clone();
                car.Brake    = (Brake)brake.Clone();
                car.Pressure = (Pressure)pressure.Clone();

                if (isMotorCar)
                {
                    ((MotorCar)car).Acceleration = (Acceleration)acceleration.Clone();
                    ((MotorCar)car).Motor        = (Motor)motor.Clone();
                }

                train.Cars.Add(car);
            }

            for (int i = 0; i < numberOfCars - 1; i++)
            {
                train.Couplers.Add(new Models.Trains.Coupler());
            }
        }
Пример #13
0
        public void ForceDividedByAccelerationEqualsMass()
        {
            Mass acceleration = Force.FromNewtons(200) / Acceleration.FromMeterPerSecondSquared(50);

            Assert.AreEqual(acceleration, Mass.FromKilograms(4));
        }
Пример #14
0
        public void MassByAccelerationEqualsForce()
        {
            Force force = Force.FromMassByAcceleration(Mass.FromKilograms(85), Acceleration.FromMeterPerSecondSquared(-4));

            Assert.AreEqual(force, Force.FromNewtons(-340));
        }
Пример #15
0
        public override void HandleAI()
        {
            if (Alive)
            {
                if (!charging)
                {
                    // find the closest ship
                    float closestDistance = 10000.0f;
                    Ship  closestShip     = null;

                    foreach (Ship s in ((GameplayScene)Scene).ShipManager.Ships)
                    {
                        if (s.Active && s.Alive)
                        {
                            float distance = (s.Position - Position).Length();
                            if (distance < closestDistance)
                            {
                                closestDistance = distance;
                                closestShip     = s;
                            }
                        }
                    }

                    if (closestShip != null)
                    {
                        if (closestDistance < 100.0f)
                        {
                            charging = true;
                            Velocity = Vector3.Zero;
                        }
                        else
                        {
                            Acceleration = closestShip.Position - Position;
                            Acceleration.Normalize();
                        }
                    }
                }
                else
                {
                    chargingCounter++;

                    if (chargingCounter > 100)
                    {
                        Die();

                        for (int i = 0; i < 5; i++)
                        {
                            Color color = new Color((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
                            ((GameplayScene)Scene).ParticleManager.CreateParticleEffect(10, Position, 100, color);
                        }

                        foreach (Ship s in ((GameplayScene)Scene).ShipManager.Ships)
                        {
                            if (Math.Abs((Position - s.Position).Length()) <= 100 + s.Radius)
                            {
                                if (s.Alive)
                                {
                                    s.Die();
                                }
                            }
                        }
                    }
                }
            }
        }
 private void ActionReturnNanNegativeTemp()
 {
     Provider.Use().GetService <IScienceAstrophysics>().Physics.GetGasLife(
         Mass.FromGrams(GlobalConstants.ATOMIC_NITROGEN), Temperature.FromKelvins(-100), Acceleration.FromStandardGravity(0.5), Length.FromKilometers(2440));
 }
 public void OpLessThan()
 {
     var acceleration1 = new Acceleration(3600, AccelerationUnit.MeterPerSecondSquared);
     var acceleration2 = new Acceleration(3.6, AccelerationUnit.KilometerPerSecondSquared);
     var acceleration3 = new Acceleration(4500, AccelerationUnit.MeterPerSecondSquared);
     (acceleration1 < acceleration3).ShouldBeTrue();
     (acceleration3 < acceleration1).ShouldBeFalse();
     (acceleration1 < acceleration2).ShouldBeFalse();
     (acceleration2 < acceleration1).ShouldBeFalse();
 }
Пример #18
0
 public CustomListener(SensorManager manager)
 {
     _sensorManager = manager;
     AccelerationProcessor = new Acceleration(_sensorManager);
     RotationProcessor = new Rotation(_sensorManager);
 }
 /// <inheritdoc cref="Acceleration.FromCentimeterPerSecondSquared(double)"/>
 public static Acceleration CentimeterPerSecondSquared(this decimal value) => Acceleration.FromCentimeterPerSecondSquared(Convert.ToDouble(value));
 /// <inheritdoc cref="Acceleration.FromCentimeterPerSecondSquared(double?)"/>
 public static Acceleration?CentimeterPerSecondSquared(this float?value) => Acceleration.FromCentimeterPerSecondSquared(value);
 /// <inheritdoc cref="Acceleration.FromCentimeterPerSecondSquared(double)"/>
 public static Acceleration CentimeterPerSecondSquared(this double value) => Acceleration.FromCentimeterPerSecondSquared(value);
 /// <inheritdoc cref="Acceleration.FromStandardGravity(double?)"/>
 public static Acceleration?StandardGravity(this decimal?value) => Acceleration.FromStandardGravity(value == null ? (double?)null : Convert.ToDouble(value.Value));
Пример #23
0
 public void SetSpeedAndAcceleration(MotorSelection motors, SpeedSetting speed, Acceleration acceleration)
 {
     lock (this)
     {
         SendCommand(new byte[] { (byte)RNCommands.SetSpeedAndAcceleration, (byte)motors, (byte)speed, (byte)acceleration });
     }
 }
Пример #24
0
        private void BuildGeometry(SceneMeshData SceneData, SceneMeshEntity[] sceneMesh, bool hasAreaLights = false, IEnumerable<SceneLightsource> areaLights = null)
        {
            topObject = new GeometryGroup(Session.OptixContext);
            Session.OptixContext["scene_sphere_radius"].Set(SceneData.BoundingSphereRadius);
            Session.OptixContext["scene_sphere_center"].SetFloat3(SceneData.BoundingSphereCenter);

            var vDesc = new BufferDesc { Width = (uint)SceneData.Positions.Count, Format = Format.Float3, Type = BufferType.Input };
            var nDesc = new BufferDesc { Width = (uint)SceneData.Normals.Count, Format = Format.Float3, Type = BufferType.Input };
            var tcDesc = new BufferDesc { Width = (uint)SceneData.TexCoords.Count, Format = Format.Float2, Type = BufferType.Input };

            var vBuffer = new Buffer(Session.OptixContext, vDesc);
            var nBuffer = new Buffer(Session.OptixContext, nDesc);
            var tcBuffer = new Buffer(Session.OptixContext, tcDesc);

            vBuffer.SetData(SceneData.Positions.ToArray());
            nBuffer.SetData(SceneData.Normals.ToArray());
            tcBuffer.SetData(SceneData.TexCoords.ToArray());

            var lightTriangleIndexes = new Dictionary<string, List<int>>(StringComparer.InvariantCultureIgnoreCase);

            var instances = new List<GeometryInstance>();
            var triLights = new List<TriangleLight>();
            int idx = 0;
            foreach (var group in sceneMesh)
            {
                //empty group

                if (group.VertexIndexes.Count == 0 && group.NormalIndexes.Count == 0 && group.TextureIndexes.Count == 0)
                    continue;

                var center = new Vector3();
                foreach (var vi in group.VertexIndexes)
                {
                    center += SceneData.Positions[vi.X];
                    center += SceneData.Positions[vi.Y];
                    center += SceneData.Positions[vi.Z];
                    center /= 3.0f;
                }
                //ValidateGroup( group );

                //var mat = this.ResolveMaterial(group.Material);

                bool normalsUseVIndices = GenerateNormals && group.NormalIndexes.Count == 0 && SceneData.Normals.Count > 0;

                if (normalsUseVIndices)
                    Debug.Assert(SceneData.Normals.Count == SceneData.Positions.Count);

                int numNormIndices = normalsUseVIndices ? group.VertexIndexes.Count : group.NormalIndexes.Count;

                var viDesc = new BufferDesc() { Width = (uint)group.VertexIndexes.Count, Format = Format.Int3, Type = BufferType.Input };
                var niDesc = new BufferDesc() { Width = (uint)numNormIndices, Format = Format.Int3, Type = BufferType.Input };
                var tiDesc = new BufferDesc() { Width = (uint)group.TextureIndexes.Count, Format = Format.Int3, Type = BufferType.Input };

                var viBuffer = new Buffer(Session.OptixContext, viDesc);
                var niBuffer = new Buffer(Session.OptixContext, niDesc);
                var tiBuffer = new Buffer(Session.OptixContext, tiDesc);

                viBuffer.SetData(group.VertexIndexes.ToArray());
                niBuffer.SetData(normalsUseVIndices ? group.VertexIndexes.ToArray() : group.NormalIndexes.ToArray());
                tiBuffer.SetData(group.TextureIndexes.ToArray());

                var geometry = new Geometry(Session.OptixContext);
                string intersect_program = "mesh_intersect";
                string isect_script = IntersectionScript;
                //if (!string.IsNullOrWhiteSpace(group.mtrl) && matTypes.ContainsKey(group.mtrl))
                //{
                //    if (matTypes[group.mtrl].Equals("Volume"))
                //    {
                //        intersect_program = "volume_mesh_intersect";
                //        isect_script = GetScript("triangle_mesh_iterative.ptx");
                //    }
                //}

                geometry.IntersectionProgram = new Program(Session.OptixContext, isect_script, intersect_program);
                geometry.BoundingBoxProgram = new Program(Session.OptixContext, isect_script, "mesh_bounds");
                geometry.PrimitiveCount = (uint)group.VertexIndexes.Count;

                geometry["vertex_buffer"].Set(vBuffer);
                geometry["normal_buffer"].Set(nBuffer);
                geometry["texcoord_buffer"].Set(tcBuffer);
                geometry["vindex_buffer"].Set(viBuffer);
                geometry["nindex_buffer"].Set(niBuffer);
                geometry["tindex_buffer"].Set(tiBuffer);

                var instance = new GeometryInstance(Session.OptixContext);
                instance.Geometry = geometry;
                instance["geometric_center"].SetFloat3(center);
                //instance.AddMaterial(mat);
                group.EngineEntity = geometry;
                if (group.Material != null)
                {
                    int lindex;
                    if (hasAreaLights && MeshIsLight(group.Name, out lindex))
                    {
                        instance.AddMaterial(this.GetLightMaterial(group.Material, lindex));
                    }
                    else
                    {
                        var mtrl = ResolveMaterial(group.Material);

                        if (mtrl != null)
                        {
                            group.Material.EngineEntity = mtrl;
                            instance.AddMaterial(mtrl);
                            SetDefaultMaterialProperties(instance, mtrl, group.Material);
                        }
                        else
                        {
                            Tracer.WriteLine("Mesh {0} missed material {1}", group.Name, group.Material.Name);
                        }
                    }
                }
                else
                {
                    Tracer.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ----Mesh {0} missed material {1}", group.Name, group.Material);
                    Console.ReadLine();
                }

                //if (!string.IsNullOrWhiteSpace(LightNameTemplate))
                //{
                //    Regex lightReg = new Regex(LightNameTemplate, RegexOptions.IgnoreCase);

                //    if (lightReg.IsMatch(group.Name))
                //    {
                //        var lt = new Lightsource()
                //        {
                //            Type = LightSourceTypes.Area,
                //            Emission = Scene.LightGain,
                //            Name = group.Name,
                //        };
                //        lt[Lightsource.AreaMeshName] = group.Name;
                //        Scene.Lights = Scene.Lights.Union(new[] { lt }).ToArray();
                //    }
                //}

                if (hasAreaLights)
                {
                    var light =
                        areaLights.FirstOrDefault(
                            lt => lt.Name.Equals(group.Name, StringComparison.InvariantCultureIgnoreCase));
                    //    SetDefaultLightProperties(instance, light);

                    if (light != null)
                    {
                        var ti = new List<int>();
                        lightTriangleIndexes.Add(group.Name, ti);
                        for (int index = 0; index < group.VertexIndexes.Count; index++)
                        {
                            var vIndex = group.VertexIndexes[index];
                            var v1 = SceneData.Positions[vIndex.X];
                            var v2 = SceneData.Positions[vIndex.Y];
                            var v3 = SceneData.Positions[vIndex.Z];
                            var e1 = v2 - v3;
                            var e2 = v1 - v3;
                            Vector3 n = Vector3.Cross(ref e1, ref e2);//SceneGraph.LightOrientation *
                            if (group.NormalIndexes.Any())
                            {
                                n = (SceneData.Normals[group.NormalIndexes[index].X]);//Scene.LightOrientation *
                            }

                            n.Normalize();
                            ti.Add(idx + 1);
                            triLights.Add(new TriangleLight()
                            {
                                color = light.Color, //Emission * emissionScale,
                                v1 = v1,
                                v2 = v2,
                                v3 = v3,
                                normal = n,
                                idx = idx++
                            });
                        }
                    }
                }
                instances.Add(instance);
            }

            var Builder = AccelBuilder.Sbvh;
            var Traverser = AccelTraverser.Bvh;

            //create an acceleration structure for the geometry
            var accel = new Acceleration(Session.OptixContext, Builder, Traverser);

            if (Builder == AccelBuilder.Sbvh || Builder == AccelBuilder.TriangleKdTree)
            {
                accel.VertexBufferName = "vertex_buffer";
                accel.IndexBufferName = "vindex_buffer";
            }

            //now attach the instance and accel to the geometry group
            topObject.Acceleration = accel;
            topObject.AddChildren(instances);
            topObject.Acceleration.MarkAsDirty();
            BuildCache.Add("LightTrianglesIndexes", lightTriangleIndexes);
            BuildCache.Add("LightTriangles", triLights);
        }
Пример #25
0
 private void moveTo(Point2Dmm target, Acceleration accelerationRamp, Speed speedLimit)
 {
     moveTo(new Point3Dmm(target.C1, target.C2, _currentLevel), accelerationRamp, speedLimit);
 }
Пример #26
0
        public void CompareToThrowsOnNull()
        {
            Acceleration meterpersecondsquared = Acceleration.FromMeterPerSecondSquared(1);

            Assert.Throws <ArgumentNullException>(() => meterpersecondsquared.CompareTo(null));
        }
 /// <inheritdoc cref="Acceleration.FromCentimeterPerSecondSquared(double?)"/>
 public static Acceleration?CentimeterPerSecondSquared(this decimal?value) => Acceleration.FromCentimeterPerSecondSquared(value == null ? (double?)null : Convert.ToDouble(value.Value));
 /// <inheritdoc cref="Acceleration.FromDecimeterPerSecondSquared(double)"/>
 public static Acceleration DecimeterPerSecondSquared(this long value) => Acceleration.FromDecimeterPerSecondSquared(value);
 /// <inheritdoc cref="Acceleration.FromDecimeterPerSecondSquared(double?)"/>
 public static Acceleration?DecimeterPerSecondSquared(this double?value) => Acceleration.FromDecimeterPerSecondSquared(value);
 private static void CheckGasValues(double exo, double surfG, double radius,
                                    IReadOnlyList <double> expected, IReadOnlyList <double> weights)
 {
     for (var i = 0; i < expected.Count; i++)
     {
         var e = expected[i];
         var w = weights[i];
         Assert.AreEqual(e, Provider.Use().GetService <IScienceAstrophysics>().Physics.GetGasLife(
                             Mass.FromGrams(w), Temperature.FromKelvins(exo), Acceleration.FromStandardGravity(surfG), Length.FromKilometers(radius)).Years365, 0.000001);
     }
 }
Пример #31
0
        /// <summary>
        /// Adds ramped line with specified number of steps.
        /// </summary>
        /// <param name="uSteps">Number of steps along u.</param>
        /// <param name="vSteps">Numer of steps along v.</param>
        /// <param name="xSteps">Number of steps along x.</param>
        /// <param name="ySteps">Numer of steps along y.</param>
        /// <param name="planeAcceleration">Acceleration used for ramping - calculated for both axis combined.</param>
        /// <param name="planeSpeedLimit">Maximal speed that could be achieved for both axis combined.</param>
        public void AddRampedLineUVXY(int uSteps, int vSteps, int xSteps, int ySteps, Acceleration planeAcceleration, Speed planeSpeedLimit)
        {
            if (uSteps == 0 && vSteps == 0 && xSteps == 0 && ySteps == 0)
            {
                //nothing to do
                return;
            }

            Speed speedLimitU, speedLimitV;

            DecomposeXY(uSteps, vSteps, planeSpeedLimit, out speedLimitU, out speedLimitV);

            Acceleration accelerationU, accelerationV;

            DecomposeXY(uSteps, vSteps, planeAcceleration, out accelerationU, out accelerationV);

            Speed speedLimitX, speedLimitY;

            DecomposeXY(xSteps, ySteps, planeSpeedLimit, out speedLimitX, out speedLimitY);

            Acceleration accelerationX, accelerationY;

            DecomposeXY(xSteps, ySteps, planeAcceleration, out accelerationX, out accelerationY);

            Speed reachedU, reachedV, reachedX, reachedY;
            int   accelerationStepsU, accelerationStepsV, accelerationStepsX, accelerationStepsY;
            var   timeU = AccelerationBuilder.CalculateTime(Speed.Zero, speedLimitU, accelerationU, uSteps / 2, out reachedU, out accelerationStepsU);
            var   timeV = AccelerationBuilder.CalculateTime(Speed.Zero, speedLimitV, accelerationV, vSteps / 2, out reachedV, out accelerationStepsV);
            var   timeX = AccelerationBuilder.CalculateTime(Speed.Zero, speedLimitX, accelerationX, xSteps / 2, out reachedX, out accelerationStepsX);
            var   timeY = AccelerationBuilder.CalculateTime(Speed.Zero, speedLimitY, accelerationY, ySteps / 2, out reachedY, out accelerationStepsY);

            //take acceleration time according to axis with more precision
            var accelerationTime = Math.Max(Math.Max(timeU, timeV), Math.Max(timeX, timeY));

            var accelerationProfileU = AccelerationBuilder.FromTo(Speed.Zero, reachedU, accelerationStepsU, accelerationTime);
            var accelerationProfileV = AccelerationBuilder.FromTo(Speed.Zero, reachedV, accelerationStepsV, accelerationTime);
            var accelerationProfileX = AccelerationBuilder.FromTo(Speed.Zero, reachedX, accelerationStepsX, accelerationTime);
            var accelerationProfileY = AccelerationBuilder.FromTo(Speed.Zero, reachedY, accelerationStepsY, accelerationTime);

            var reachedSpeedU = Speed.FromDeltaT(accelerationProfileU.EndDelta + accelerationProfileU.BaseDeltaT);
            var reachedSpeedV = Speed.FromDeltaT(accelerationProfileV.EndDelta + accelerationProfileV.BaseDeltaT);
            var reachedSpeedX = Speed.FromDeltaT(accelerationProfileX.EndDelta + accelerationProfileX.BaseDeltaT);
            var reachedSpeedY = Speed.FromDeltaT(accelerationProfileY.EndDelta + accelerationProfileY.BaseDeltaT);

            var reachedSpeedUV = ComposeSpeeds(reachedSpeedU, reachedSpeedV);
            var reachedSpeedXY = ComposeSpeeds(reachedSpeedX, reachedSpeedY);

            var decelerationProfileU = AccelerationBuilder.FromTo(reachedU, Speed.Zero, accelerationStepsU, accelerationTime);
            var decelerationProfileV = AccelerationBuilder.FromTo(reachedV, Speed.Zero, accelerationStepsV, accelerationTime);
            var decelerationProfileX = AccelerationBuilder.FromTo(reachedX, Speed.Zero, accelerationStepsX, accelerationTime);
            var decelerationProfileY = AccelerationBuilder.FromTo(reachedY, Speed.Zero, accelerationStepsY, accelerationTime);

            var remainingU = uSteps - accelerationProfileU.StepCount - decelerationProfileU.StepCount;
            var remainingV = vSteps - accelerationProfileV.StepCount - decelerationProfileV.StepCount;
            var remainingX = xSteps - accelerationProfileX.StepCount - decelerationProfileX.StepCount;
            var remainingY = ySteps - accelerationProfileY.StepCount - decelerationProfileY.StepCount;

            //send ramp
            AddAccelerationUVXY(accelerationProfileU, accelerationProfileV, accelerationProfileX, accelerationProfileY);
            AddConstantSpeedTransitionUVXY(remainingU, remainingV, reachedSpeedUV, remainingX, remainingY, reachedSpeedXY);
            AddAccelerationUVXY(decelerationProfileU, decelerationProfileV, decelerationProfileX, decelerationProfileY);
        }
Пример #32
0
        public void MassTimesAccelerationEqualsForce()
        {
            Force force = Mass.FromKilograms(18) * Acceleration.FromMetersPerSecondSquared(3);

            Assert.Equal(force, Force.FromNewtons(54));
        }
Пример #33
0
        /// <summary>
        /// Decomposes plane acceleration into separate axes accelerations in a direction specified by step counts.
        /// </summary>
        public void DecomposeXY(int stepsX, int stepsY, Acceleration planeAcceleration, out Acceleration accelerationX, out Acceleration accelerationY)
        {
            checked
            {
                Speed speedX, speedY;
                DecomposeXY(stepsX, stepsY, planeAcceleration.Speed, out speedX, out speedY);

                accelerationX = new Acceleration(speedX, planeAcceleration.Ticks);
                accelerationY = new Acceleration(speedY, planeAcceleration.Ticks);
            }
        }
Пример #34
0
 // 加速度を受信
 public void UpdateAcceleration(string msg)
 {
     acceleration = JsonUtility.FromJson<Acceleration>(msg);
     UpdateText();
 }
Пример #35
0
    public override Gene CopyGene()
    {
        Gene copied = new Acceleration(this.value);

        return(copied);
    }
Пример #36
0
        public void ForceDividedByMassEqualsAcceleration()
        {
            Acceleration acceleration = Force.FromNewtons(27) / Mass.FromKilograms(9);

            Assert.AreEqual(acceleration, Acceleration.FromMeterPerSecondSquared(3));
        }
Пример #37
0
 public static Force FromMassByAcceleration(Mass mass, Acceleration acceleration)
 {
     return new Force(mass.Kilograms*acceleration.MeterPerSecondSquared);
 }
Пример #38
0
        public void EqualsReturnsFalseOnNull()
        {
            Acceleration meterpersecondsquared = Acceleration.FromMeterPerSecondSquared(1);

            Assert.False(meterpersecondsquared.Equals(null));
        }
Пример #39
0
 //---------------------------------------------------------------------
 EbVector3 calAcc(Acceleration acceleration, float time)
 {
     return acceleration.t * EbMath.Sin(acceleration.m * time);
 }
Пример #40
0
 public PlanBuilder3D(double transitionLevel, double zeroLevel, Speed cuttingSpeed, Speed transitionSpeed, Acceleration planeAcceleration)
 {
     CuttingSpeed      = cuttingSpeed;
     TransitionSpeed   = transitionSpeed;
     PlaneAcceleration = planeAcceleration;
     _transitionLevel  = transitionLevel;
     _zeroLevel        = zeroLevel;
 }
 public void OpMultiplicationScaler()
 {
     var acceleration = new Acceleration(1, AccelerationUnit.MeterPerSecondSquared);
     var expected = new Acceleration(2, AccelerationUnit.MeterPerSecondSquared);
     (acceleration * 2).ShouldEqual(expected);
     (2 * acceleration).ShouldEqual(expected);
 }
Пример #42
0
        public void CompareToThrowsOnTypeMismatch()
        {
            Acceleration meterpersecondsquared = Acceleration.FromMeterPerSecondSquared(1);

            Assert.Throws <ArgumentException>(() => meterpersecondsquared.CompareTo(new object()));
        }
Пример #43
0
        public void OpMultiplicationAcceleration()
        {
            Speed speedBase = new Time(20, TimeUnit.Second) * new Acceleration(3, AccelerationUnit.MeterPerSecondSquared);
            speedBase.ShouldEqual(new Speed(60, SpeedUnit.MeterPerSecond));

            var time = new Time(1, TimeUnit.Minutes);
            var acceleration = new Acceleration(1, AccelerationUnit.MilePerHourPerSecond);
            Speed speed = time * acceleration;
            speed.Units = SpeedUnit.MilesPerHour;
            speed.ShouldEqual(new Speed(60, SpeedUnit.MilesPerHour));
        }
Пример #44
0
        public void EqualsReturnsFalseOnTypeMismatch()
        {
            Acceleration meterpersecondsquared = Acceleration.FromMeterPerSecondSquared(1);

            Assert.False(meterpersecondsquared.Equals(new object()));
        }
Пример #45
0
 public static Acceleration operator /(Speed speed, Time time)
 {
     Acceleration acceleration = new Acceleration();
     acceleration.Value = speed.Value / time.Value;
     return acceleration;
 }
Пример #46
0
 public static Acceleration operator /(Force force, Mass mass)
 {
     Acceleration acceleration = new Acceleration();
     acceleration.Value = force.Value / mass.Value;
     return acceleration;
 }
 protected void SetScalarValue(DependencyProperty property, Acceleration? quantity)
 {
     // we set this flag to prevent from setting scalar value changing quantity values.
     this.isUpdatingScalarValue = true;
     var value = quantity != null
         ? this.Unit.GetScalarValue(quantity.Value)
         : (double?)null;
     this.SetCurrentValue(property, value);
     this.isUpdatingScalarValue = false;
 }
Пример #48
0
        public override void SetScene(IRayEngineScene secn)
        {
            string shaderPath = Path.GetFullPath(@"G:\Git\RayDen\RayDen.OptixEngine\Cuda\Scripts\CudaScripts\hitkernel.ptx");

            Tracer.TraceLine("OptixIntersectionDevice  -  Initializing Optix");
            this.scene = (RayEngineScene) secn;
            var scn = scene.SceneGeometry;

            Material material = new Material(Context);
            material.Programs[0] = new SurfaceProgram(Context, RayHitType.Closest, shaderPath, "first_hit");
            //            material.Programs[1] = new SurfaceProgram(Context, RayHitType.Any, shaderPath, "shadow");


            var mVertices = scn.Vertices.ToList();
            var mNormals = scn.Normals.ToList();
            List<UV> mTexcoords = null;
            mTexcoords = scn.TexCoords == null ? new List<UV>() : scn.TexCoords.Select(it=>new UV(it.x,it.y)).ToList();

            var vDesc = new BufferDesc() { Width = (uint)mVertices.Count, Format = Format.Float3, Type = BufferType.Input };
            var nDesc = new BufferDesc() { Width = (uint)mNormals.Count, Format = Format.Float3, Type = BufferType.Input };
            var tcDesc = new BufferDesc() { Width = (uint)mTexcoords.Count, Format = Format.Float2, Type = BufferType.Input };

            // Create the buffers to hold our geometry data
            var vBuffer = new  DeviceBuffer(Context, vDesc);
            var nBuffer = new  DeviceBuffer(Context, nDesc);
            var tcBuffer = new DeviceBuffer(Context, tcDesc);


            vBuffer.SetData(mVertices.ToArray());
            nBuffer.SetData(mNormals.ToArray());
            tcBuffer.SetData(mTexcoords.ToArray());


            foreach (var triangleMesh in scene.Meshes.Cast<TriangleMeshInfo>())
            {
                var group = triangleMesh;


                var viDesc = new BufferDesc() { Width = (uint)(group.TrianglesCount), Format = Format.Int3, Type = BufferType.Input };
                var niDesc = new BufferDesc() { Width = (uint)(group.TrianglesCount), Format = Format.Int3, Type = BufferType.Input };
                var tiDesc = new BufferDesc() { Width = (uint)(group.TrianglesCount), Format = Format.Int3, Type = BufferType.Input };
                var ofsDesc = new BufferDesc()
                    {
                        Width = (uint) (group.TrianglesCount),
                        Format = Format.UInt,
                        Type = BufferType.Input
                    };

                var viBuffer = new DeviceBuffer(Context, viDesc);
                var niBuffer = new DeviceBuffer(Context, niDesc);
                var tiBuffer = new DeviceBuffer(Context, tiDesc);

                var gIndexes =
                    scene.Triangles.ToList().GetRange(group.StartTriangle, group.TrianglesCount)
                         .SelectMany(tri => new []
                             {
                                 tri.v0.VertexIndex,
                                 tri.v1.VertexIndex,
                                 tri.v2.VertexIndex
                             })
                         .ToArray();

                var gNIndexes =
                    scene.Triangles.ToList().GetRange(group.StartTriangle, group.TrianglesCount)
                         .SelectMany(tri => new[]
                             {
                                 tri.v0.NormalIndex,
                                 tri.v1.NormalIndex,
                                 tri.v2.NormalIndex
                             })
                         .ToArray();
                var gTIndexes =
                    scene.Triangles.ToList().GetRange(group.StartTriangle, group.TrianglesCount)
                         .SelectMany(tri => new []
                             {
                                 tri.v0.TexCoordIndex,
                                 tri.v1.TexCoordIndex,
                                 tri.v2.TexCoordIndex
                             })
                         .ToArray();

                viBuffer.SetData(Convert(gIndexes).ToArray());
                niBuffer.SetData(Convert(gNIndexes).ToArray());
                tiBuffer.SetData(Convert(gTIndexes).ToArray());

                var geometry = new Geometry(Context);
                geometry.IntersectionProgram = new Program(Context, IntersecitonProgPath, IntersecitonProgName);
                geometry.BoundingBoxProgram = new Program(Context, BoundingBoxProgPath, BoundingBoxProgName);
                geometry.PrimitiveCount = (uint)(group.EndTriangle - group.StartTriangle);

                geometry["vertex_buffer"].Set(vBuffer);
                geometry["normal_buffer"].Set(nBuffer);
                geometry["texcoord_buffer"].Set(tcBuffer);
                geometry["vindex_buffer"].Set(viBuffer);
                geometry["nindex_buffer"].Set(niBuffer);
                geometry["tindex_buffer"].Set(tiBuffer);
                geometry["mesh_offset"].SetInt4(group.StartTriangle);
                //geometry[ "material_buffer" ].Set(mtBuffer);

                //create a geometry instance
                var instance = new GeometryInstance(Context);
                instance.Geometry = geometry;
                instance.AddMaterial(material);
                //create an acceleration structure for the geometry
                Acceleration accel = new Acceleration(Context, Builder, Traverser);

                if (Builder == AccelBuilder.Sbvh || Builder == AccelBuilder.TriangleKdTree)
                {
                    accel.VertexBufferName = "vertex_buffer";
                    accel.IndexBufferName = "vindex_buffer";
                }

                //now attach the instance and accel to the geometry group
                GeoGroup.Acceleration = accel;
                GeoGroup.AddChildren(new[] { instance });
            }

            Program rayGen = new Program(Context, shaderPath, "intersector_camera");
            Program exception = new Program(Context, shaderPath, "exception");
            Program miss = new Program(Context, shaderPath, "miss");
            Context["intersect_ray_type"].Set(0u);
            Context["scene_epsilon"].Set(0.0001f);
            Context.SetRayGenerationProgram(0, rayGen);
            Context.SetExceptionProgram(0, exception);
            Context.SetRayMissProgram(0, miss);
            Context["top_object"].Set(GeoGroup);
            Tracer.TraceLine("OptixIntersectionDevice  -  Compiling Optix contex");
            Context.Compile();
            Context.BuildAccelTree();
            Tracer.TraceLine("OptixIntersectionDevice  -  Complete");
        }
 public void OpSubtraction()
 {
     var acceleration1 = new Acceleration(7200, AccelerationUnit.MeterPerSecondSquared);
     var acceleration2 = new Acceleration(3.6, AccelerationUnit.KilometerPerSecondSquared);
     (acceleration1 - acceleration2).ShouldEqual(new Acceleration(3600, AccelerationUnit.MeterPerSecondSquared));
     (acceleration2 - acceleration1).ShouldEqual(new Acceleration(-3.6, AccelerationUnit.KilometerPerSecondSquared));
 }
Пример #50
0
    public virtual void AnalogChanged(UniVRPNity.AnalogEvent e)
    {
        accelerationWiimote = new Acceleration(
            (float)e.Channel((int)Wiimote.Analog.Roll) + offsetWiimote.Roll,
            (float)e.Channel((int)Wiimote.Analog.Pitch) + offsetWiimote.Pitch,
            (float)e.Channel((int)Wiimote.Analog.Yaw) + offsetWiimote.Yaw
            );

        accelerationNunchuck = new Acceleration(
            (float)e.Channel((int)Wiimote.Analog.NunchuckRoll) + offsetNunchuck.Roll,
            (float)e.Channel((int)Wiimote.Analog.NunchuckPitch) + offsetNunchuck.Pitch,
            (float)e.Channel((int)Wiimote.Analog.NunchuckYaw) + offsetNunchuck.Yaw
            );
    }
Пример #51
0
    public static void AddEngine(GameObject entity, Acceleration acceleration, MaxSpeed max, TurnSpeed turn, Engine.FuelRegenerationStyle fuelRegenerationStyle)
    {
        Engine e = entity.AddComponent <Engine>();

        AdjustStats(e, acceleration, max, turn, fuelRegenerationStyle);
    }
Пример #52
0
 public Acceleration clone()
 {
     Acceleration acc = new Acceleration();
     acc.acceleration = acceleration;
     acc.duration = duration;
     return acc;
 }
Пример #53
0
        public async Task HandlePackedResponseAsync()
        {
            Acceleration[] expected = null, actual = new Acceleration[3];
            byte[]         response = null;

            int i     = 0;
            var route = await accelerometer.PackedAcceleration.AddRouteAsync(source => source.Stream(data => actual[i++] = data.Value <Acceleration>()));

            if (accelerometer is IAccelerometerMma8452q)
            {
                expected = new Acceleration[] {
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x12, 0x83, 0x94, 0xc0 }, 0),
                        BitConverter.ToSingle(new byte[] { 0x9a, 0x99, 0xb5, 0x40 }, 0),
                        BitConverter.ToSingle(new byte[] { 0xd7, 0xa3, 0x70, 0xbe }, 0)
                        ),
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0xa6, 0x9b, 0xb4, 0xbf }, 0),
                        BitConverter.ToSingle(new byte[] { 0x73, 0x68, 0xa1, 0x3f }, 0),
                        BitConverter.ToSingle(new byte[] { 0xb0, 0x72, 0x30, 0x40 }, 0)
                        ),
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x68, 0x91, 0x9d, 0xbf }, 0),
                        BitConverter.ToSingle(new byte[] { 0xac, 0x1c, 0xea, 0xbf }, 0),
                        BitConverter.ToSingle(new byte[] { 0x06, 0x81, 0x5d, 0xc0 }, 0)
                        )
                };
                response = new byte[] { 0x03, 0x12, 0xdf, 0xed, 0x2b, 0x16, 0x15, 0xff, 0x7d, 0xfa,
                                        0xed, 0x04, 0xc5, 0x0a, 0x31, 0xfb, 0xdb, 0xf8, 0x7b, 0xf2 };
            }
            else if (accelerometer is IAccelerometerBmi160)
            {
                expected = new Acceleration[] {
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x00, 0x3c, 0x91, 0xc0 }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0x30, 0x55, 0x3f }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0xc0, 0x05, 0xbe }, 0)
                        ),
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x00, 0xa8, 0x3f, 0xc0 }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0xd0, 0x64, 0x3f }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0xc0, 0x15, 0x3e }, 0)
                        ),
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x00, 0x00, 0xec, 0xbc }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0x20, 0xb4, 0x3e }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0x00, 0x85, 0x3d }, 0)
                        )
                };
                response = new byte[] { 0x03, 0x1c, 0x62, 0xb7, 0x53, 0x0d, 0xe9, 0xfd, 0x16, 0xd0, 0x4d,
                                        0x0e, 0x57, 0x02, 0x8a, 0xff, 0xa1, 0x05, 0x0a, 0x01 };

                accelerometer.Configure(range: 8f);
            }
            else if (accelerometer is IAccelerometerBma255)
            {
                expected = new Acceleration[] {
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x00, 0xc4, 0x98, 0x3f }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0x60, 0x55, 0xbe }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0xca, 0x6e, 0x40 }, 0)
                        ),
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x00, 0xe4, 0xa4, 0x3f }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0xdc, 0x91, 0xbf }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0xfa, 0x7f, 0x40 }, 0)
                        ),
                    new Acceleration(
                        BitConverter.ToSingle(new byte[] { 0x00, 0x54, 0xf6, 0x3f }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0x7c, 0xfa, 0xbf }, 0),
                        BitConverter.ToSingle(new byte[] { 0x00, 0xe2, 0x7f, 0x40 }, 0)
                        )
                };
                response = new byte[] { 0x03, 0x1c, 0x31, 0x26, 0x55, 0xf9, 0x65, 0x77, 0x39, 0x29, 0x89, 0xdb,
                                        0xfd, 0x7f, 0x95, 0x3d, 0x61, 0xc1, 0xf1, 0x7f };

                accelerometer.Configure(range: 4f);
            }

            platform.sendMockResponse(response);
            Assert.That(actual, Is.EqualTo(expected));
            Assert.That(route.Subscribers[0].Identifier, Is.EqualTo("acceleration"));
        }
Пример #54
0
        public void SpeedDividedByDurationEqualsAcceleration()
        {
            Acceleration acceleration = Speed.FromMetersPerSecond(20) / Duration.FromSeconds(2);

            Assert.Equal(acceleration, Acceleration.FromMeterPerSecondSquared(10));
        }
Пример #55
0
        public override object ReadJson(JsonReader reader, Type objectType, object?existingValue, JsonSerializer serializer)
        {
            var stringValue = (string)reader.Value !;

            return(Acceleration.Parse(stringValue, serializer.Culture));
        }
Пример #56
0
        private Acceleration ReadI2CAccel()
        {
            const int ACCEL_RES = 1024;
            const int ACCEL_DYN_RANGE_G = 8;
            const int UNITS_PER_G = ACCEL_RES / ACCEL_DYN_RANGE_G;

            byte[] RegAddrBuf = new byte[] { ACCEL_REG_X };
            byte[] ReadBuf = new byte[6];

            I2CAccel.WriteRead(RegAddrBuf, ReadBuf);

            short rx = BitConverter.ToInt16(ReadBuf, 0);
            short ry = BitConverter.ToInt16(ReadBuf, 2);
            short rz = BitConverter.ToInt16(ReadBuf, 4);

            Acceleration accel = new Acceleration();
            accel.X = (double)rx / UNITS_PER_G;
            accel.Y = (double)ry / UNITS_PER_G;
            accel.Z = (double)rz / UNITS_PER_G;
            return accel;
        }
Пример #57
0
        protected override void CreateGeometry()
        {
            base.CreateGeometry();

            if (!GenerateGeometry)
            {
                return;
            }

            //create buffer descriptions
            var vDesc = new BufferDesc()
            {
                Width = (uint)Positions.Count, Format = Format.Float3, Type = BufferType.Input
            };
            var nDesc = new BufferDesc()
            {
                Width = (uint)Normals.Count, Format = Format.Float3, Type = BufferType.Input
            };
            var tcDesc = new BufferDesc()
            {
                Width = (uint)Texcoords.Count, Format = Format.Float2, Type = BufferType.Input
            };

            // Create the buffers to hold our geometry data
            var vBuffer  = new OptixBuffer(Context, vDesc);
            var nBuffer  = new OptixBuffer(Context, nDesc);
            var tcBuffer = new OptixBuffer(Context, tcDesc);

            vBuffer.SetData <Vector3>(Positions.ToArray());
            nBuffer.SetData <Vector3>(Normals.ToArray());
            tcBuffer.SetData <Vector2>(Texcoords.ToArray());

            List <GeometryInstance> instances = new List <GeometryInstance>();

            foreach (ObjGroup group in Groups)
            {
                //empty group
                if (group.VIndices.Count == 0 && group.NIndices.Count == 0 && group.TIndices.Count == 0)
                {
                    continue;
                }

                //ValidateGroup( group );

                var normalsUseVIndices = GenerateNormals && group.NIndices.Count == 0 && Normals.Count > 0;

                if (normalsUseVIndices)
                {
                    Debug.Assert(Normals.Count == Positions.Count);
                }

                var numNormIndices = normalsUseVIndices ? group.VIndices.Count : group.NIndices.Count;

                var viDesc = new BufferDesc {
                    Width = (uint)group.VIndices.Count, Format = Format.Int3, Type = BufferType.Input
                };
                var niDesc = new BufferDesc {
                    Width = (uint)numNormIndices, Format = Format.Int3, Type = BufferType.Input
                };
                var tiDesc = new BufferDesc {
                    Width = (uint)group.TIndices.Count, Format = Format.Int3, Type = BufferType.Input
                };

                var viBuffer = new OptixBuffer(Context, viDesc);
                var niBuffer = new OptixBuffer(Context, niDesc);
                var tiBuffer = new OptixBuffer(Context, tiDesc);

                viBuffer.SetData(group.VIndices.ToArray());
                //if normals weren't in the obj and we genereated them, use the vertex indices
                niBuffer.SetData(normalsUseVIndices ? group.VIndices.ToArray() : group.NIndices.ToArray());
                tiBuffer.SetData(group.TIndices.ToArray());

                //create a geometry node and set the buffers
                var geometry = new Geometry(Context);
                geometry.IntersectionProgram = new OptixProgram(Context, IntersecitonProgPath, IntersecitonProgName);
                geometry.BoundingBoxProgram  = new OptixProgram(Context, BoundingBoxProgPath, BoundingBoxProgName);
                geometry.PrimitiveCount      = (uint)group.VIndices.Count;

                geometry["vertex_buffer"].Set(vBuffer);
                geometry["normal_buffer"].Set(nBuffer);
                geometry["texcoord_buffer"].Set(tcBuffer);
                geometry["vindex_buffer"].Set(viBuffer);
                geometry["nindex_buffer"].Set(niBuffer);
                geometry["tindex_buffer"].Set(tiBuffer);

                //create a geometry instance
                GeometryInstance instance = new GeometryInstance(Context);
                instance.Geometry = geometry;
                instance.AddMaterial(Material);

                if (group.mtrl != null)
                {
                    ObjMaterial mtrl = mMtrls[group.mtrl];
                    instance["diffuse_color"].SetFloat3(ref mtrl.Kd);
                    instance["emission_color"].SetFloat3(ref mtrl.Ke);
                }
                else
                {
                    instance["diffuse_color"].Set(1.0f, 1.0f, 1.0f);
                }

                instances.Add(instance);
            }

            //create an acceleration structure for the geometry
            var accel = new Acceleration(Context, Builder, Traverser);

            if (Builder == AccelBuilder.Sbvh || Builder == AccelBuilder.TriangleKdTree)
            {
                accel.VertexBufferName = "vertex_buffer";
                accel.IndexBufferName  = "vindex_buffer";
            }

            //now attach the instance and accel to the geometry group
            GeoGroup.Acceleration = accel;
            GeoGroup.AddChildren(instances);
        }
Пример #58
0
			internal Train () {
				this.Acceleration = new Acceleration();
				this.Performance = new Performance();
				this.Delay = new Delay();
				this.Move = new Move();
				this.Brake = new Brake();
				this.Pressure = new Pressure();
				this.Handle = new Handle();
				this.Cab = new Cab();
				this.Car = new Car();
				this.Device = new Device();
				this.MotorP1 = new Motor();
				this.MotorP2 = new Motor();
				this.MotorB1 = new Motor();
				this.MotorB2 = new Motor();
			}
 protected virtual void OnMaxValueChanged(Acceleration? oldValue, Acceleration? newValue)
 {
     this.SetScalarValue(ScalarMaxValueProperty, newValue);
 }