Beispiel #1
0
        public override UtilityNewt.IObjectMassBreakdown GetMassBreakdown(double cellSize)
        {
            if (_massBreakdown != null && _massBreakdown.Scale == Scale && _massBreakdown.CellSize == cellSize)
            {
                // This has already been built for this size
                return(_massBreakdown.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use (mass breakdown wants height along X, and scale is for radius, but the mass breakdown wants diameter
            // Reducing Z a bit, because the energy tank has a rounded cap
            Vector3D size = new Vector3D(this.Scale.Z * HEIGHTPERCENTOFSCALE, this.Scale.X * RADIUSPERCENTOFSCALE * 2d, this.Scale.Y * RADIUSPERCENTOFSCALE * 2d);

            // Cylinder
            UtilityNewt.ObjectMassBreakdown cylinder = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Cylinder, UtilityNewt.MassDistribution.Uniform, size, cellSize);

            Transform3D transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90));          // the physics hull is along x, but dna is along z

            // Rotated
            UtilityNewt.ObjectMassBreakdownSet combined = new UtilityNewt.ObjectMassBreakdownSet(
                new UtilityNewt.ObjectMassBreakdown[] { cylinder },
                new Transform3D[] { transform });

            // Store this
            _massBreakdown = new MassBreakdownCache(combined, Scale, cellSize);

            return(_massBreakdown.Breakdown);
        }
Beispiel #2
0
        internal static UtilityNewt.IObjectMassBreakdown GetSensorMassBreakdown(ref MassBreakdownCache existing, Vector3D scale, double cellSize)
        {
            if (existing != null && existing.Scale == scale && existing.CellSize == cellSize)
            {
                // This has already been built for this size
                return(existing.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use (mass breakdown wants height along X, and scale is for radius, but the mass breakdown wants diameter)
            Vector3D size = new Vector3D(scale.Z * SIZEPERCENTOFSCALE_Z, scale.X * SIZEPERCENTOFSCALE_XY * 2, scale.Y * SIZEPERCENTOFSCALE_XY * 2);

            var cylinder = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Cylinder, UtilityNewt.MassDistribution.Uniform, size, cellSize);

            Transform3D transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90));          // the physics hull is along x, but dna is along z

            // Rotated
            UtilityNewt.ObjectMassBreakdownSet combined = new UtilityNewt.ObjectMassBreakdownSet(
                new UtilityNewt.ObjectMassBreakdown[] { cylinder },
                new Transform3D[] { transform });

            // Store this
            existing = new MassBreakdownCache(combined, scale, cellSize);

            return(existing.Breakdown);
        }
Beispiel #3
0
        public override UtilityNewt.IObjectMassBreakdown GetMassBreakdown(double cellSize)
        {
            if (_massBreakdown != null && _massBreakdown.Scale == Scale && _massBreakdown.CellSize == cellSize)
            {
                // This has already been built for this size
                return(_massBreakdown.Breakdown);
            }

            var breakdown = GetMassBreakdown(this.Scale, cellSize);

            // Store this
            _massBreakdown = new MassBreakdownCache(breakdown, Scale, cellSize);

            return(_massBreakdown.Breakdown);
        }
Beispiel #4
0
        public override UtilityNewt.IObjectMassBreakdown GetMassBreakdown(double cellSize)
        {
            if (_massBreakdown != null && _massBreakdown.Scale == Scale && _massBreakdown.CellSize == cellSize)
            {
                // This has already been built for this size
                return(_massBreakdown.Breakdown);
            }

            var breakdown = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Box, UtilityNewt.MassDistribution.Uniform, this.Scale, cellSize);

            // Store this
            _massBreakdown = new MassBreakdownCache(breakdown, Scale, cellSize);

            return(_massBreakdown.Breakdown);
        }
Beispiel #5
0
        public override UtilityNewt.IObjectMassBreakdown GetMassBreakdown(double cellSize)
        {
            if (_massBreakdown != null && _massBreakdown.Scale == Scale && _massBreakdown.CellSize == cellSize)
            {
                // This has already been built for this size
                return(_massBreakdown.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use (mass breakdown wants height along X)

            //DNA plays with X and Z as the 2D axis and height is along Y

            //Vector3D size = new Vector3D(Scale.X, Scale.Y, Scale.Z * THICKNESS);
            //Vector3D size = new Vector3D(Scale.Z * THICKNESS, Scale.X, Scale.Y);
            //Vector3D size = new Vector3D(Scale.X, Scale.Z * THICKNESS, Scale.Y);
            Vector3D size = new Vector3D(Scale.X, Scale.Y * THICKNESS, Scale.Z);

            //Vector3D size = new Vector3D(Scale.Z, Scale.X, Scale.Y);

            UtilityNewt.IObjectMassBreakdown breakdown = null;

            switch (this.Shape)
            {
            case SolarPanelShape.Square:
                breakdown = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Box, UtilityNewt.MassDistribution.Uniform, size, cellSize);
                break;

            case SolarPanelShape.Right_Triangle:
            case SolarPanelShape.Triangle:
                var triangleBreakdown = GetMassBreakdown_Triangle(size, cellSize, this.Shape == SolarPanelShape.Right_Triangle);
                breakdown = UtilityNewt.Combine(new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>[] { new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>(triangleBreakdown.Item1, triangleBreakdown.Item2.ToPoint(), Quaternion.Identity, 1d) });
                break;

            case SolarPanelShape.Right_Trapazoid:
            case SolarPanelShape.Trapazoid:
                breakdown = GetMassBreakdown_Trapazoid(this.Vertices.ToArray(), size, cellSize, this.Shape == SolarPanelShape.Right_Trapazoid);
                break;

            default:
                throw new ApplicationException("Unknown SolarPanelShape: " + this.Shape.ToString());
            }

            // Store this
            _massBreakdown = new MassBreakdownCache(breakdown, Scale, cellSize);

            return(_massBreakdown.Breakdown);
        }
Beispiel #6
0
        internal static UtilityNewt.IObjectMassBreakdown GetCameraMassBreakdown(ref MassBreakdownCache existing, Vector3D scale, double cellSize)
        {
            if (existing != null && existing.Scale == scale && existing.CellSize == cellSize)
            {
                // This has already been built for this size
                return(existing.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use
            Vector3D size = new Vector3D(scale.X * SCALE, scale.Y * SCALE, scale.Z * SCALE);

            var breakdown = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Sphere, UtilityNewt.MassDistribution.Uniform, size, cellSize);

            // Store this
            existing = new MassBreakdownCache(breakdown, scale, cellSize);

            return(existing.Breakdown);
        }
Beispiel #7
0
        public override UtilityNewt.IObjectMassBreakdown GetMassBreakdown(double cellSize)
        {
            if (_massBreakdown != null && _massBreakdown.Scale == Scale && _massBreakdown.CellSize == cellSize)
            {
                // This has already been built for this size
                return(_massBreakdown.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use
            Vector3D size = new Vector3D(this.Scale.X, this.Scale.Y * RATIOY, this.Scale.Z * RATIOZ);

            var breakdown = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Box, UtilityNewt.MassDistribution.Uniform, size, cellSize);

            // Store this
            _massBreakdown = new MassBreakdownCache(breakdown, Scale, cellSize);

            return(_massBreakdown.Breakdown);
        }
Beispiel #8
0
        public override UtilityNewt.IObjectMassBreakdown GetMassBreakdown(double cellSize)
        {
            if (_massBreakdown != null && _massBreakdown.Scale == Scale && _massBreakdown.CellSize == cellSize)
            {
                // This has already been built for this size
                return(_massBreakdown.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use
            Vector3D size = new Vector3D(this.Scale.X * DirectionControllerRingDesign.SIZEPERCENTOFSCALE, this.Scale.Y * DirectionControllerRingDesign.SIZEPERCENTOFSCALE, this.Scale.Z * DirectionControllerRingDesign.SIZEPERCENTOFSCALE);

            var breakdown = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Sphere, UtilityNewt.MassDistribution.Uniform, size, cellSize);

            // Store this
            _massBreakdown = new MassBreakdownCache(breakdown, Scale, cellSize);

            return(_massBreakdown.Breakdown);
        }
Beispiel #9
0
        public override UtilityNewt.IObjectMassBreakdown GetMassBreakdown(double cellSize)
        {
            if (_massBreakdown != null && _massBreakdown.Scale == Scale && _massBreakdown.CellSize == cellSize)
            {
                // This has already been built for this size
                return(_massBreakdown.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use (mass breakdown wants height along X, and scale is for radius, but the mass breakdown wants diameter
            Vector3D size = new Vector3D(this.Scale.Z * HEIGHTPERCENTOFSCALE * 2d, this.Scale.X * RADIUSPERCENTOFSCALE * 2d, this.Scale.Y * RADIUSPERCENTOFSCALE * 2d);         // HEIGHTPERCENTOFSCALE is a radius, so it needs to be doubled too

            // Center
            Vector3D centerSize     = new Vector3D(size.X * .5d, size.Y, size.Z);
            double   centerVolume   = Math.Pow((centerSize.Y + centerSize.Z) / 4d, 2d) * Math.PI * centerSize.X;        // dividing by 4, because div 2 is the average, then another 2 is to convert diameter to radius
            var      centerCylinder = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Cylinder, UtilityNewt.MassDistribution.Uniform, centerSize, cellSize);

            // Cap
            Vector3D capSize     = new Vector3D(size.X * .25d, size.Y * .6d, size.Z * .6d);
            double   capVolume   = Math.Pow((capSize.Y + capSize.Z) / 4d, 2d) * Math.PI * capSize.X;
            var      capCylinder = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Cylinder, UtilityNewt.MassDistribution.Uniform, capSize, cellSize);

            // Combined shape
            double     offsetX = (centerSize.X * .5d) + (capSize.X * .5d);
            Quaternion rotate  = new Quaternion(new Vector3D(0, 1, 0), 90);

            var objects = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double> [3];

            objects[0] = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>(centerCylinder, new Point3D(0, 0, 0), rotate, centerVolume);
            objects[1] = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>(capCylinder, new Point3D(0, 0, offsetX), rotate, capVolume);           // the breakdowns were build along X, but now putting them back along Z
            objects[2] = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>(capCylinder, new Point3D(0, 0, -offsetX), rotate, capVolume);

            var combined = UtilityNewt.Combine(objects);

            // Store this
            _massBreakdown = new MassBreakdownCache(combined, Scale, cellSize);

            return(_massBreakdown.Breakdown);
        }
Beispiel #10
0
        internal static UtilityNewt.IObjectMassBreakdown GetTankMassBreakdown(ref MassBreakdownCache existing, Vector3D scale, double cellSize)
        {
            if (existing != null && existing.Scale == scale && existing.CellSize == cellSize)
            {
                // This has already been built for this size
                return(existing.Breakdown);
            }

            // Convert this.Scale into a size that the mass breakdown will use (mass breakdown wants height along X, and scale is for radius, but the mass breakdown wants diameter
            Vector3D size = new Vector3D(scale.Z, scale.X * RADIUSPERCENTOFSCALE * 2d, scale.Y * RADIUSPERCENTOFSCALE * 2d);

            // Main Cylinder
            Vector3D mainSize     = new Vector3D(size.X * .75d, size.Y, size.Z);
            double   mainVolume   = Math.Pow((mainSize.Y + mainSize.Z) / 4d, 2d) * Math.PI * mainSize.X;        // dividing by 4, because div 2 is the average, then another 2 is to convert diameter to radius
            var      mainCylinder = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Cylinder, UtilityNewt.MassDistribution.Uniform, mainSize, cellSize);

            // End Caps
            Vector3D capSize     = new Vector3D(size.X * .125d, size.Y * .5d, size.Z * .5d);
            double   capVolume   = Math.Pow((capSize.Y + capSize.Z) / 4d, 2d) * Math.PI * capSize.X;
            var      capCylinder = UtilityNewt.GetMassBreakdown(UtilityNewt.ObjectBreakdownType.Cylinder, UtilityNewt.MassDistribution.Uniform, capSize, cellSize);

            // Combined shape
            double     offsetX = (mainSize.X * .5d) + (capSize.X * .5d);
            Quaternion rotate  = new Quaternion(new Vector3D(0, 1, 0), 90);

            var objects = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double> [3];

            objects[0] = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>(mainCylinder, new Point3D(0, 0, 0), rotate, mainVolume);
            objects[1] = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>(capCylinder, new Point3D(0, 0, offsetX), rotate, capVolume);           // the breakdowns were build along X, but now putting them back along Z
            objects[2] = new Tuple <UtilityNewt.ObjectMassBreakdown, Point3D, Quaternion, double>(capCylinder, new Point3D(0, 0, -offsetX), rotate, capVolume);
            var combined = UtilityNewt.Combine(objects);

            // Store this
            existing = new MassBreakdownCache(combined, scale, cellSize);

            return(existing.Breakdown);
        }