Ejemplo n.º 1
0
        public Ball(MyVector position, DoubleVector origDirectionFacing, double radius, double mass)
            : base(position, origDirectionFacing, radius)
        {
            // I use the property sets to enforce the values
            this.Mass = mass;
            this.Elasticity = 1d;

            _usesBoundingBox = false;
            _boundingLower = null;
            _boundingUpper = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This overload is used if you plan to do collisions
        /// </summary>
        public Ball(MyVector position, DoubleVector origDirectionFacing, double radius, double mass, double elasticity, double kineticFriction, double staticFriction, MyVector boundingBoxLower, MyVector boundingBoxUpper)
            : base(position, origDirectionFacing, radius)
        {
            // I use the property sets to enforce the values
            this.Mass = mass;
            this.Elasticity = elasticity;
            this.KineticFriction = kineticFriction;
            this.StaticFriction = staticFriction;

            _usesBoundingBox = true;
            _boundingLower = boundingBoxLower;
            _boundingUpper = boundingBoxUpper;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// This overload is used if you plan to do collisions
 /// </summary>
 public RigidBody(MyVector position, DoubleVector origDirectionFacing, double radius, double elasticity, double kineticFriction, double staticFriction, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, radius, 0, elasticity, kineticFriction, staticFriction, boundingBoxLower, boundingBoxUpper)
 {
     _constructorCalled = true;
 }
Ejemplo n.º 4
0
 public RigidBody(MyVector position, DoubleVector origDirectionFacing, double radius)
     : base(position, origDirectionFacing, radius, 0)
 {
     _constructorCalled = true;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Use this overload when you don't care about the position and radius
 /// </summary>
 public Sphere(DoubleVector origDirectionFacing)
     : this(new MyVector(0, 0, 0), origDirectionFacing, 0) { }
Ejemplo n.º 6
0
        public DoubleVector GetRotatedVectorReverse(DoubleVector doubleVector, bool isQuatNormalized)
        {
            if (!isQuatNormalized)
            {
                // I'm not normalized, clone myself and normalize it
                MyQuaternion myUnitClone = new MyQuaternion(this.X, this.Y, this.Z, this.W);
                myUnitClone.BecomeUnitQuaternion();

                return myUnitClone.GetRotatedVectorReverse(doubleVector, true);
            }

            return new DoubleVector(GetRotatedVectorReverse(doubleVector.Standard, true), GetRotatedVectorReverse(doubleVector.Orth, true));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This function takes in a destination double vector, and I will tell you how much you need to rotate me in order for me to end up
        /// along that destination double vector.
        /// </summary>
        /// <remarks>
        /// This function is a mutated copy of MyVector.GetAngleBetweenVectors.  It is almost identical, but slightly more complex  :)
        /// 
        /// If I am already aligned with the vector passed in, then I will return an arbitrary orthoganal, and an angle of zero.
        /// </remarks>
        /// <param name="destination">This is the double vector you want me to align myself with</param>
        public MyQuaternion GetAngleAroundAxis(DoubleVector destination)
        {
            #region Standard

            // Get the angle
            double rotationRadians = MyVector.GetAngleBetweenVectors(this.Standard, destination.Standard);
            if (Double.IsNaN(rotationRadians))
            {
                rotationRadians = 0d;
            }

            // I need to pull the cross product from me to the vector passed in
            MyVector rotationAxis = MyVector.Cross(this.Standard, destination.Standard);

            // If the cross product is zero, then there are two possibilities.  The vectors point in the same direction, or opposite directions.
            if (rotationAxis.IsNearZero)
            {
                // If I am here, then the angle will either be 0 or PI.
                if (Utility3D.IsNearZero(rotationRadians))
                {
                    // The vectors sit on top of each other.  I will set the orthoganal to an arbitrary value, and return zero for the radians
                    rotationAxis.X = 1d;
                    rotationAxis.Y = 0d;
                    rotationAxis.Z = 0d;
                    rotationRadians = 0d;
                }
                else
                {
                    // The vectors are pointing directly away from each other, because this is a double vector, I must rotate along an axis that
                    // is orthogonal to my standard and orth
                    rotationAxis = this.Orth; //MyVector.Cross(this.Standard, this.Orth);
                }
            }

            MyQuaternion quatStandard = new MyQuaternion(rotationAxis, rotationRadians);



            //return quatStandard;




            #endregion

            // I only need to rotate the orth, because I already know where the standard will be
            MyVector rotatedOrth = quatStandard.GetRotatedVector(this.Orth, true);

            #region Orthogonal

            // Grab the angle
            rotationRadians = MyVector.GetAngleBetweenVectors(rotatedOrth, destination.Orth);
            if (Double.IsNaN(rotationRadians))
            {
                rotationRadians = 0d;
            }

            // Since I've rotated the standards onto each other, the rotation axis of the orth is the standard (asumming it was truely orthogonal
            // to begin with)
            rotationAxis = destination.Standard.Clone();

            MyQuaternion quatOrth = new MyQuaternion(rotationAxis, rotationRadians);

            #endregion

            // Exit Function
            //return MyQuaternion.Multiply(quatOrth, quatStandard);
            return MyQuaternion.Multiply(quatStandard, quatOrth);
        }
Ejemplo n.º 8
0
        private void AddMultiBall(double radius, double mass)
        {
            // Physical Ball
            MyVector pos = Utility3D.GetRandomVector(BOUNDRY);
            DoubleVector dirFacing = new DoubleVector(1, 0, 0, 0, 1, 0);

            Ball ball = new Ball(pos, dirFacing, radius, mass, ELASTICITY, KINETICFRICTION, STATICFRICTION, _boundryLower, _boundryUpper);

            BallBlip blip = new BallBlip(ball, CollisionStyle.Standard, RadarBlipQual.BallUserDefined00, TokenGenerator.NextToken());
            _map.Add(blip);

            // WPF Rendering
            Geometry3D geometry = UtilityWPF.GetSphere(5, radius);
            Material material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, Convert.ToByte(_rand.Next(256)), Convert.ToByte(_rand.Next(256)), Convert.ToByte(_rand.Next(256)))));
            GeometryModel3D geometryModel = new GeometryModel3D(geometry, material);
            geometryModel.Transform = new Transform3DGroup();

            //TODO:  Tie this transform directly to the ball's velocity (the shpere class should take the transform group)
            Transform3DGroup group = geometryModel.Transform as Transform3DGroup;
            group.Children.Clear();
            group.Children.Add(new TranslateTransform3D(pos.X, pos.Y, pos.Z));

            _geometries.Add(geometryModel);
            _modelGroup.Children.Add(geometryModel);
        }
Ejemplo n.º 9
0
 public TriangleTest(MyVector position, DoubleVector origDirFacing, Triangle triangle)
     : base(position, origDirFacing, 150)
 {
     this.Triangle = triangle;
     _rotateHandle = new MyVector(this.Radius, this.Radius, 0);
 }
Ejemplo n.º 10
0
 public PolygonTest(MyVector position, DoubleVector origDirFacing, MyPolygon polygon, double radius)
     : base(position, origDirFacing, polygon, radius)
 {
     _rotateHandleX = new MyVector(this.Radius + DOTRADIUS, 0, 0);
     _rotateHandleY = new MyVector(this.Radius + (DOTRADIUS * 3), 0, 0);
     _rotateHandleZ = new MyVector(this.Radius + (DOTRADIUS * 5), 0, 0);
     _rotationX = new MyQuaternion(new MyVector(0, 0, 1), 0);
     _rotationY = new MyQuaternion(new MyVector(0, 0, 1), 0);
     _rotationZ = new MyQuaternion(new MyVector(0, 0, 1), 0);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Use this overload for clone
 /// </summary>
 protected TorqueBall(MyVector position, DoubleVector origDirectionFacing, MyQuaternion rotation, double radius, double mass, double elasticity, double kineticFriction, double staticFriction, bool usesBoundingBox, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, rotation, radius, mass, elasticity, kineticFriction, staticFriction, usesBoundingBox, boundingBoxLower, boundingBoxUpper)
 {
     ResetInertiaTensorAndCenterOfMass();
 }
Ejemplo n.º 12
0
        private double _elapsedTime = 0;		// the ball also has a private by this name.  it should probably be protected, but it just feels cleaner for me to have my own

        #endregion

        #region Constructor

        /// <summary>
        /// Use this overload for standard instantiations by the outside user
        /// </summary>
        protected TorqueBall(MyVector position, DoubleVector origDirectionFacing, double radius, double mass)
            : base(position, origDirectionFacing, radius, mass)
        {
            ResetInertiaTensorAndCenterOfMass();
        }
Ejemplo n.º 13
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            const int MINMASS = 10;
            const int MAXMASS = 1000;
            const int MINCOLOR = 75;
            const double MAXVELOCITY = 7;

            // Figure out ball properties
            int radius = _rand.Next(2, 31);
            MyVector position = Utility3D.GetRandomVector(new MyVector(radius, radius, 0), new MyVector(pictureBox1.Width - radius, pictureBox1.Height - radius, 0));
            DoubleVector dirFacing = new DoubleVector(new MyVector(1, 0, 0), new MyVector(0, 1, 0));
            int mass = _rand.Next(MINMASS, MAXMASS);
            MyVector boundingLower = new MyVector(0, 0, -1);
            MyVector boundingUpper = new MyVector(pictureBox1.Width, pictureBox1.Height, 1);

            double massPercent = Convert.ToDouble(mass - MINMASS) / Convert.ToDouble(MAXMASS - MINMASS);
            int colorValue = MINCOLOR + Convert.ToInt32((255 - MINCOLOR) * massPercent);

            // Make the ball
            _balls.Add(new Ball(position, dirFacing, radius, mass, boundingLower, boundingUpper));

            // Calculate the shell color
            if (chkRandVelocity.Checked)
            {
                _balls[_balls.Count - 1].Velocity.Add(Utility3D.GetRandomVector(MAXVELOCITY));
            }

            _ballColors.Add(Color.FromArgb(colorValue, colorValue, colorValue));

            // Make a tail
            _ballTails.Add(new Trail(100));
            _ballTails[_ballTails.Count - 1].SetColors(Color.MediumOrchid, Color.Black);
            _ballTails[_ballTails.Count - 1].SetWidths(3f, 1f);

            // Make sure the checkbox is checked
            if (!chkRunningGravBalls.Checked)
            {
                chkRunningGravBalls.Checked = true;
            }
        }
Ejemplo n.º 14
0
        public TractorBeamCone(SimpleMap map, BallBlip ship, MyVector offset, DoubleVector dirFacing, BeamMode mode, bool isSoft, double sweepAngle, double maxDistance, double forceAtZero, double forceAtMax, double maxForcePerTick)
        {
            _map = map;

            _ship = ship;

            _offset = offset;
            _dirFacing = dirFacing;

            _mode = mode;

            _isSoft = isSoft;

            _sweepAngle = sweepAngle;
            _maxDistance = maxDistance;
            _forceAtZero = forceAtZero;
            _forceAtMax = forceAtMax;
            _maxForcePerTick = maxForcePerTick;
        }
Ejemplo n.º 15
0
 /// <summary>
 /// This overload is used if you plan to do collisions
 /// </summary>
 public SolidBall(MyVector position, DoubleVector origDirectionFacing, double radius, double mass, double elasticity, double kineticFriction, double staticFriction, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, radius, mass, elasticity, kineticFriction, staticFriction, boundingBoxLower, boundingBoxUpper) { }
Ejemplo n.º 16
0
 /// <summary>
 /// This one is used to assist with the clone method (especially for my derived classes)
 /// </summary>
 /// <param name="usesBoundingBox">Just pass in what you have</param>
 /// <param name="boundingBoxLower">Set this to null if bounding box is false</param>
 /// <param name="boundingBoxUpper">Set this to null if bounding box is false</param>
 protected SolidBall(MyVector position, DoubleVector origDirectionFacing, MyQuaternion rotation, double radius, double mass, double elasticity, double kineticFriction, double staticFriction, bool usesBoundingBox, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, rotation, radius, mass, elasticity, kineticFriction, staticFriction, usesBoundingBox, boundingBoxLower, boundingBoxUpper) { }
Ejemplo n.º 17
0
 /// <summary>
 /// This overload should only be used during a clone.  I simply trust the values passed to me
 /// </summary>
 protected SpherePolygon(MyVector position, DoubleVector origDirectionFacing, MyQuaternion rotation, MyPolygonSyncedRotation polygon, double radius)
     : base(position, origDirectionFacing, rotation, radius)
 {
     _polygon = polygon;
 }
Ejemplo n.º 18
0
        /// <summary>
        /// This does a deep clone
        /// </summary>
        public static DoubleVector[] GetClonedArray(DoubleVector[] vectorPairs)
        {
            DoubleVector[] retVal = new DoubleVector[vectorPairs.Length];

            for (int cntr = 0; cntr < vectorPairs.Length; cntr++)
            {
                retVal[cntr] = vectorPairs[cntr].Clone();
            }

            return retVal;
        }
Ejemplo n.º 19
0
 public SolidBallPolygon(MyVector position, DoubleVector origDirectionFacing, MyPolygon polygon, double radius, double mass, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, radius, mass, boundingBoxLower, boundingBoxUpper)
 {
     _polygon = new MyPolygonSyncedRotation(polygon.UniquePoints, polygon.Triangles, this.Rotation);
 }
Ejemplo n.º 20
0
        private void CreateGravityBall(Random rand)
        {

            const int MINMASS = 500;
            const int MAXMASS = 5000;
            const int MINCOLOR = 75;

            // Figure out ball properties
            int radius = rand.Next(100, 500);
            MyVector position = Utility3D.GetRandomVector(_boundryLower, _boundryUpper);
            DoubleVector dirFacing = new DoubleVector(new MyVector(1, 0, 0), new MyVector(0, 1, 0));
            int mass = rand.Next(MINMASS, MAXMASS);

            double massPercent = Convert.ToDouble(mass - MINMASS) / Convert.ToDouble(MAXMASS - MINMASS);
            int colorValue = MINCOLOR + Convert.ToInt32((255 - MINCOLOR) * massPercent);

            // Make the ball
            _gravityBalls.Add(new Ball(position, dirFacing, radius, mass, _boundryLower, _boundryUpper));
            _gravityBallColors.Add(Color.FromArgb(colorValue, colorValue, colorValue));

        }
Ejemplo n.º 21
0
 public RigidBodyPolygon(MyVector position, DoubleVector origDirectionFacing, MyPolygon polygon, double radius)
     : base(position, origDirectionFacing, radius)
 {
     _polygon = new MyPolygonSyncedRotation(polygon.UniquePoints, polygon.Triangles, this.Rotation);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// This overload should only be used during a clone.  I simply trust the values passed to me
 /// </summary>
 protected Sphere(MyVector position, DoubleVector origDirectionFacing, MyQuaternion rotation, double radius)
 {
     _position = position;
     _radius = radius;
     _origDirFacing = origDirectionFacing;
     _rotation = rotation;
 }
Ejemplo n.º 23
0
 /// <summary>
 /// This overload is used if you plan to do collisions
 /// </summary>
 public RigidBodyPolygon(MyVector position, DoubleVector origDirectionFacing, MyPolygon polygon, double radius, double elasticity, double kineticFriction, double staticFriction, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, radius, elasticity, kineticFriction, staticFriction, boundingBoxLower, boundingBoxUpper)
 {
     _polygon = new MyPolygonSyncedRotation(polygon.UniquePoints, polygon.Triangles, this.Rotation);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// This sets up everything in one shot
        /// </summary>
        public Sphere(MyVector position, DoubleVector origDirectionFacing, double radius)
        {
            // Store what was passed in
            _position = position;
            _radius = radius;
            _origDirFacing = origDirectionFacing;

            // Force the original direction facing to be unit vectors
            _origDirFacing.Standard.BecomeUnitVector();
            _origDirFacing.Orth.BecomeUnitVector();

            // Create a default quaternion (I don't want to instantiate dirfacing until it's requested)
            _rotation = new MyQuaternion(new MyVector(0, 0, 0), 0);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// This one is used to assist with the clone method (especially for my derived classes)
 /// </summary>
 /// <param name="usesBoundingBox">Just pass in what you have</param>
 /// <param name="boundingBoxLower">Set this to null if bounding box is false</param>
 /// <param name="boundingBoxUpper">Set this to null if bounding box is false</param>
 protected RigidBodyPolygon(MyVector position, DoubleVector origDirectionFacing, MyQuaternion rotation, MyPolygonSyncedRotation polygon, double radius, double elasticity, double kineticFriction, double staticFriction, bool usesBoundingBox, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, rotation, radius, elasticity, kineticFriction, staticFriction, usesBoundingBox, boundingBoxLower, boundingBoxUpper)
 {
     _polygon = polygon;
 }
Ejemplo n.º 26
0
 public RigidBody(MyVector position, DoubleVector origDirectionFacing, double radius, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, radius, 0, 1, 1, 1, boundingBoxLower, boundingBoxUpper)
 {
     _constructorCalled = true;
 }
Ejemplo n.º 27
0
 public SolidBall(MyVector position, DoubleVector origDirectionFacing, double radius, double mass)
     : base(position, origDirectionFacing, radius, mass) { }
Ejemplo n.º 28
0
 /// <summary>
 /// This one is used to assist with the clone method (especially for my derived classes)
 /// </summary>
 /// <param name="usesBoundingBox">Just pass in what you have</param>
 /// <param name="boundingBoxLower">Set this to null if bounding box is false</param>
 /// <param name="boundingBoxUpper">Set this to null if bounding box is false</param>
 protected RigidBody(MyVector position, DoubleVector origDirectionFacing, MyQuaternion rotation, double radius, double elasticity, double kineticFriction, double staticFriction, bool usesBoundingBox, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, rotation, radius, 0, elasticity, kineticFriction, staticFriction, usesBoundingBox, boundingBoxLower, boundingBoxUpper)
 {
     _constructorCalled = true;
 }
Ejemplo n.º 29
0
 public SolidBall(MyVector position, DoubleVector origDirectionFacing, double radius, double mass, MyVector boundingBoxLower, MyVector boundingBoxUpper)
     : base(position, origDirectionFacing, radius, mass, 1, 1, 1, boundingBoxLower, boundingBoxUpper) { }