private static ShipPartDNA[] GetRandomThrusters(int count, bool randomOrientations, ThrusterTypeValues thrustType, bool someDestroyed) { const double MINRADIUS = 1.5; const double MAXRADIUS = 3; const double MINSIZE = .5; const double MAXSIZE = 1.5; if (count < 2) { throw new ApplicationException("Must have at least two thrusters"); } List <ShipPartDNA> retVal = new List <ShipPartDNA>(); Random rand = StaticRandom.GetRandomForThread(); double stepAngle = 360d / count; double rangeAngle = 120d / count; // the sum of these pie slices should cover 2/3 of the area Vector3D axis = new Vector3D(0, 0, 1); double startAngle = rand.NextDouble(360); for (int cntr = 0; cntr < count; cntr++) { double angle = startAngle + (cntr * stepAngle); angle += rand.NextDouble(-rangeAngle, rangeAngle); Vector3D position = new Vector3D(rand.NextDouble(MINRADIUS, MAXRADIUS), 0, 0); position = position.GetRotatedVector(axis, angle); double size = rand.NextDouble(MINSIZE, MAXSIZE); //Random direction Quaternion orientation = Quaternion.Identity; if (randomOrientations) { Vector3D standardVect = new Vector3D(0, 0, 1); Vector3D rotatedVect = Math3D.GetRandomVector_Cone(axis, 0, 90, 1, 1); orientation = Math3D.GetRotation(standardVect, rotatedVect); } ThrusterType type; switch (thrustType) { case ThrusterTypeValues.Single: type = ThrusterType.One; break; case ThrusterTypeValues.Dual: type = ThrusterType.Two; break; case ThrusterTypeValues.Six: type = ThrusterType.Two_Two_Two; break; case ThrusterTypeValues.Random: type = UtilityCore.GetRandomEnum <ThrusterType>(ThrusterType.Custom); break; default: throw new ApplicationException("Unknown ThrusterTypeValues: " + thrustType.ToString()); } double percentDamaged = 0d; if (someDestroyed && rand.NextDouble() < .15) { percentDamaged = 1d; } retVal.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = orientation, Position = position.ToPoint(), Scale = new Vector3D(size, size, size), ThrusterType = type, PercentDamaged = percentDamaged, }); } return(retVal.ToArray()); }
private static ShipPartDNA[] GetRandomThrusters(int count, bool randomOrientations, ThrusterTypeValues thrustType) { const double MINRADIUS = 1.5; const double MAXRADIUS = 3; const double MINSIZE = .5; const double MAXSIZE = 1.5; if (count < 2) { throw new ApplicationException("Must have at least two thrusters"); } List<ShipPartDNA> retVal = new List<ShipPartDNA>(); Random rand = StaticRandom.GetRandomForThread(); double stepAngle = 360d / count; double rangeAngle = 120d / count; // the sum of these pie slices should cover 2/3 of the area Vector3D axis = new Vector3D(0, 0, 1); double startAngle = rand.NextDouble(360); for (int cntr = 0; cntr < count; cntr++) { double angle = startAngle + (cntr * stepAngle); angle += rand.NextDouble(-rangeAngle, rangeAngle); Vector3D position = new Vector3D(rand.NextDouble(MINRADIUS, MAXRADIUS), 0, 0); position = position.GetRotatedVector(axis, angle); double size = rand.NextDouble(MINSIZE, MAXSIZE); //Random direction Quaternion orientation = Quaternion.Identity; if (randomOrientations) { Vector3D standardVect = new Vector3D(0, 0, 1); Vector3D rotatedVect = Math3D.GetRandomVector_Cone(axis, 90); orientation = Math3D.GetRotation(standardVect, rotatedVect); } ThrusterType type; switch (thrustType) { case ThrusterTypeValues.Single: type = ThrusterType.One; break; case ThrusterTypeValues.Dual: type = ThrusterType.Two; break; case ThrusterTypeValues.Six: type = ThrusterType.Two_Two_Two; break; case ThrusterTypeValues.Random: type = UtilityCore.GetRandomEnum<ThrusterType>(ThrusterType.Custom); break; default: throw new ApplicationException("Unknown ThrusterTypeValues: " + thrustType.ToString()); } retVal.Add(new ThrusterDNA() { PartType = Thruster.PARTTYPE, Orientation = orientation, Position = position.ToPoint(), Scale = new Vector3D(size, size, size), ThrusterType = type }); } return retVal.ToArray(); }