Пример #1
0
        /// <summary>
        /// This function can be called many times with different elapsed times passed in.  This function will only figure out a new
        /// position based on the previous tick's velocity and the time passed in.  Every time this function gets called, the starting point
        /// is the last call to PrepareForNewCycle.
        /// </summary>
        public virtual void TimerTestPosition(double elapsedTime)
        {
            // Make sure position is where it was when PrepareForNew was called
            if (_savedPosition == null)
            {
                // This is the first time I've been called since PrepareForNew.  Remember the current position
                _savedPosition = this.Position.Clone();
            }
            else
            {
                // I've been called before.  Reset my position
                this.Position.StoreNewValues(_savedPosition);
            }

            // Remember the elapsed time that was passed in
            _elapsedTime = elapsedTime;

            // Get the change in position
            MyVector changeInPos = _velocity * elapsedTime;

            // See if I'm about to clip the box boundry (If I am, the ChangeInPos will be changed so that I don't cross the boundry line.)
            if (_usesBoundingBox)
            {
                TimerBoxBoundry(this.Position, ref changeInPos, elapsedTime);
            }

            // ChangeInPos is now a position.  I will add it to the current position
            this.Position.Add(changeInPos);
        }
Пример #2
0
 /// <summary>
 /// Transforms a vector by a matrix.
 /// </summary>
 /// <remarks>
 /// I've seen this in other code as matrix * vector
 /// </remarks>
 public static MyVector Transform(MyMatrix3 matrix, MyVector vector)
 {
     return(new MyVector(
                (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z),
                (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z),
                (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z)));
 }
Пример #3
0
        /// <summary>
        /// This function returns a vector that is rotated by the opposite of me
        /// </summary>
        public MyVector GetRotatedVectorReverse(MyVector vector, 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(vector, true));
            }

            MyVector qvec = new MyVector(this.X, this.Y, this.Z);

            //Vector uv = qvec.Cross(vector);
            MyVector uv = MyVector.Cross(qvec, vector);

            //Vector uuv = qvec.Cross(uv);
            MyVector uuv = MyVector.Cross(qvec, uv);

            //uv *= (2.0f * quat.w);
            uv.Multiply(this.W * -2d);

            //uuv *= 2.0f;
            uuv.Multiply(2d);

            //return vector + uv + uuv;
            MyVector retVal = vector.Clone();

            retVal.Add(uv);
            retVal.Add(uuv);
            return(retVal);
        }
Пример #4
0
        /// <summary>
        /// This function will check to see if I've clipped the box boundry.  If I have, I will change the ChangeInPosition, so that the ball
        /// won't cross the boundry line.
        /// </summary>
        /// <param name="curPositionCloned">The values of this will be changed if there is a boundry collision</param>
        /// <param name="changeInPos">This will get reset if there is a collision with the boundry</param>
        /// <param name="elapsedTime">This is needed to recalculate changeInPos if there is a boundry collision</param>
        private void TimerBoxBoundry(MyVector position, ref MyVector changeInPos, double elapsedTime)
        {
            List <Coords> affectedAxiis = new List <Coords>();

            // Clone the Position in order to start generating the ProposedPosition
            MyVector proposedPosition = this.Position.Clone();

            // Add the change in position to the proposed position to make it a real proposed position
            proposedPosition.Add(changeInPos);

            // Now compare the proposed position with the stated corner stones to see if I went to far
            #region X

            if (proposedPosition.X < _boundingLower.X)
            {
                affectedAxiis.Add(Coords.X);
                position.X = _boundingLower.X;
            }
            else if (proposedPosition.X > _boundingUpper.X)
            {
                affectedAxiis.Add(Coords.X);
                position.X = _boundingUpper.X;
            }

            #endregion
            #region Y

            if (proposedPosition.Y < _boundingLower.Y)
            {
                affectedAxiis.Add(Coords.Y);
                position.Y = _boundingLower.Y;
            }
            else if (proposedPosition.Y > _boundingUpper.Y)
            {
                affectedAxiis.Add(Coords.Y);
                position.Y = _boundingUpper.Y;
            }

            #endregion
            #region Z

            if (proposedPosition.Z < _boundingLower.Z)
            {
                affectedAxiis.Add(Coords.Z);
                position.Z = _boundingLower.Z;
            }
            else if (proposedPosition.Z > _boundingUpper.Z)
            {
                affectedAxiis.Add(Coords.Z);
                position.Z = _boundingUpper.Z;
            }

            #endregion

            if (affectedAxiis.Count > 0)
            {
                // Bounce the ball
                changeInPos = TimerBoxBoundrySprtBounceIt(affectedAxiis, elapsedTime);
            }
        }
Пример #5
0
        /// <summary>
        /// This function will pick an arbitrary orthogonal to the vector passed in.  This will only be usefull if you are going
        /// to rotate 180
        /// </summary>
        public static MyVector GetArbitraryOrhonganal(MyVector vector)
        {
            // Clone the vector passed in
            MyVector retVal = vector.Clone();

            // Make sure that none of the values are equal to zero.
            if (retVal.X == 0)
            {
                retVal.X = 0.000000001d;
            }
            if (retVal.Y == 0)
            {
                retVal.Y = 0.000000001d;
            }
            if (retVal.Z == 0)
            {
                retVal.Z = 0.000000001d;
            }

            // Figure out the orthogonal X and Y slopes
            double orthM = (retVal.X * -1) / retVal.Y;
            double orthN = (retVal.Y * -1) / retVal.Z;

            // When calculating the new coords, I will default Y to 1, and find an X and Z that satisfy that.  I will go ahead and reuse the retVal
            retVal.Y = 1;
            retVal.X = 1 / orthM;
            retVal.Z = orthN;

            // Exit Function
            return(retVal);
        }
Пример #6
0
        /// <summary>
        /// I only made this public so I could hook a tester to it
        /// </summary>
        public static void OrthonormalizeOrientation(MyMatrix3 orientation)
        {
            // Do some crazy math (something about constraining 9 degrees of freedom of a matrix down to 3)
            MyVector x = new MyVector(orientation.M11, orientation.M21, orientation.M31);

            x.BecomeUnitVector();

            MyVector y = new MyVector(orientation.M12, orientation.M22, orientation.M32);               // just store a temp variable into y (until I calculate z)

            MyVector z = MyVector.Cross(x, y);

            z.BecomeUnitVector();

            y = MyVector.Cross(z, x);
            y.BecomeUnitVector();

            // Overwrite the matrix passed in
            orientation.M11 = x.X;
            orientation.M12 = y.X;
            orientation.M13 = z.X;

            orientation.M21 = x.Y;
            orientation.M22 = y.Y;
            orientation.M23 = z.Y;

            orientation.M31 = x.Z;
            orientation.M32 = y.Z;
            orientation.M33 = z.Z;
        }
Пример #7
0
        /// <summary>
        /// This function returns the vector from returnList that is closest to testVect
        /// </summary>
        public static MyVector GetNearestVector(MyVector testVect, MyVector[] returnList)
        {
            // Find the closest point
            double minDist      = double.MaxValue;
            int    minDistIndex = -1;

            double x, y, z, curDist;

            for (int returnCntr = 0; returnCntr < returnList.Length; returnCntr++)
            {
                // Get dist squared
                x = returnList[returnCntr].X - testVect.X;
                y = returnList[returnCntr].Y - testVect.Y;
                z = returnList[returnCntr].Z - testVect.Z;

                curDist = (x * x) + (y * y) + (z * z);          // no need to use sqrt

                // See if this is nearer
                if (curDist < minDist)
                {
                    minDist      = curDist;
                    minDistIndex = returnCntr;
                }
            }

            // Exit Function
            return(returnList[minDistIndex]);
        }
Пример #8
0
 /// <summary>
 /// This gives the dot product between the two vectors passed in
 /// NOTE:  This overload does not normalize them first (a standard dot product)
 /// </summary>
 public static double Dot(MyVector v1, MyVector v2)
 {
     // For speed reasons, I want to rewrite the function, rather than call my overload with false
     return((v1.X * v2.X) +
            (v1.Y * v2.Y) +
            (v1.Z * v2.Z));
 }
Пример #9
0
        /// <summary>
        /// This function takes in a destination vector, and I will tell you how much you need to rotate me in order for me to end up along
        /// that destination vector.
        /// </summary>
        /// <remarks>
        /// I gave up trying to return this in YawPitchRoll form.  I think it can be done, but there are all kinds of strange contridictions
        /// and order of operation that I've decided that is not the way things are done.  Use YawPitchRoll when receiving input from a
        /// joystick.  But when all you know is vectors, and you want to know how to rotate them, use this function.
        ///
        /// 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 vector you want me to align myself with</param>
        /// <param name="rotationAxis">This is a vector that is orthoganal to me and the vector passed in (cross product)</param>
        /// <param name="rotationRadians">This is the number of radians you must rotate me around the rotation axis in order to be aligned with the vector passed in</param>
        public void GetAngleAroundAxis(out MyVector rotationAxis, out double rotationRadians, MyVector destination)
        {
            // Grab the angle
            rotationRadians = GetAngleBetweenVectors(this, destination);
            if (Double.IsNaN(rotationRadians))
            {
                rotationRadians = 0;
            }

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

            // If the cross product is zero, then there are two possibilities.  The vectors point in the same direction, or opposite directions.
            if (rotationAxis.IsZero)
            {
                // If I am here, then the angle will either be 0 or PI.
                if (rotationRadians == 0)
                {
                    // 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  = 1;
                    rotationRadians = 0;
                }
                else
                {
                    // The vectors are pointing directly away from each other, so I will need to be more careful when I create my orthoganal.
                    rotationAxis = GetArbitraryOrhonganal(rotationAxis);
                }
            }

            //rotationAxis.BecomeUnitVector();		// It would be nice to be tidy, but not nessassary, and I don't want slow code
        }
Пример #10
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;
 }
Пример #11
0
        /// <summary>
        /// This creates a new vector that is the vector with a length of one
        /// </summary>
        public static MyVector BecomeUnitVector(MyVector vector)
        {
            MyVector retVal = vector.Clone();

            retVal.BecomeUnitVector();

            return(retVal);
        }
Пример #12
0
        public void SetPointers(MyVector boundryLower, MyVector boundryUpper)
		{
			_boundryLower = boundryLower;
			_boundryUpper = boundryUpper;

			// Apply Settings
			trkWidth_Scroll(this, new EventArgs());
			trkHeight_Scroll(this, new EventArgs());
		}
Пример #13
0
        public void GetAngleAroundAxis(out MyQuaternion rotation, MyVector destination)
        {
            MyVector axis;
            double   radians;

            GetAngleAroundAxis(out axis, out radians, destination);

            rotation = new MyQuaternion(axis, radians);
        }
Пример #14
0
        public Triangle(MyVector vertex1, MyVector vertex2, MyVector vertex3)
        {
            this.Vertex1 = vertex1;
            this.Vertex2 = vertex2;
            this.Vertex3 = vertex3;

            this.Pointer1 = -1;
            this.Pointer2 = -1;
            this.Pointer3 = -1;
        }
Пример #15
0
        public Triangle()
        {
            this.Vertex1 = null;
            this.Vertex2 = null;
            this.Vertex3 = null;

            this.Pointer1 = -1;
            this.Pointer2 = -1;
            this.Pointer3 = -1;
        }
Пример #16
0
        public SolidBallTester()
        {
            InitializeComponent();

            _bitmap = new Bitmap(pictureBox1.DisplayRectangle.Width, pictureBox1.DisplayRectangle.Height);
            _graphics = Graphics.FromImage(_bitmap);

            _boundryLower = new MyVector(0, 0, 0);
            _boundryUpper = new MyVector(pictureBox1.DisplayRectangle.Width, pictureBox1.DisplayRectangle.Height, 0);
        }
Пример #17
0
        public Triangle(double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3)
        {
            this.Vertex1 = new MyVector(x1, y1, z1);
            this.Vertex2 = new MyVector(x2, y2, z2);
            this.Vertex3 = new MyVector(x3, y3, z3);

            this.Pointer1 = -1;
            this.Pointer2 = -1;
            this.Pointer3 = -1;
        }
Пример #18
0
        /// <summary>
        /// Get a random vector between maxValue*-1 and maxValue
        /// </summary>
        public static MyVector GetRandomVector(double maxValue)
        {
            MyVector retVal = new MyVector();

            retVal.X = GetNearZeroValue(maxValue);
            retVal.Y = GetNearZeroValue(maxValue);
            retVal.Z = GetNearZeroValue(maxValue);

            return(retVal);
        }
Пример #19
0
        public Triangle(MyVector[] uniquePoints, int pointer1, int pointer2, int pointer3)
        {
            this.Vertex1 = uniquePoints[pointer1];
            this.Vertex2 = uniquePoints[pointer2];
            this.Vertex3 = uniquePoints[pointer3];

            this.Pointer1 = pointer1;
            this.Pointer2 = pointer2;
            this.Pointer3 = pointer3;
        }
Пример #20
0
        /// <summary>
        /// I will internally rotate the vectors around, get the Z component to drop out, and only return Theta.  I will not change the values
        /// of the vectors passed in
        /// </summary>
        public static double GetAngleBetweenVectors(MyVector v1, MyVector v2)
        {
            // Get the dot product of the two vectors (I use retVal, just because it makes a convenient temp variable)
            double retVal = Dot(MyVector.BecomeUnitVector(v1), MyVector.BecomeUnitVector(v2));

            // Now pull the arccos of the dot product
            retVal = Math.Acos(retVal);

            // Exit Function
            return(retVal);
        }
Пример #21
0
        public static MyVector GetRandomVectorSpherical2D(double maxRadius)
        {
            MyVector retVal = new MyVector(GetNearZeroValue(maxRadius), 0, 0);

            MyVector rotateAxis = new MyVector(0, 0, 1);
            double   radians    = GetNearZeroValue(2d * Math.PI);

            retVal.RotateAroundAxis(rotateAxis, radians);

            return(retVal);
        }
Пример #22
0
        /// <summary>
        /// This function will calculate the new velocity based on the current acceleration and elapsed time.  I will store the result back into
        /// my velocity property.
        /// </summary>
        private void TimerSprtVel(double elapsedTime)
        {
            // Clone the current accel
            MyVector changeInVel = _acceleration.Clone();

            // Now make the ChangeInVel a velocity instead of an acceleration by multiplying it by time
            changeInVel.Multiply(elapsedTime);

            // I have the change in velocity, so I will add it to the current velocity in order to make a new velocity
            _velocity.Add(changeInVel);
        }
Пример #23
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;
        }
Пример #24
0
        /// <summary>
        /// This function needs to be called before the timer is called.  Between this function and the timer function is when all the outside
        /// forces have a chance to influence the object (gravity, explosion blasts, conveyor belts, etc)
        /// </summary>
        /// <remarks>
        /// I've given this function a bit of thought.  It's really not needed, because when TimerFinish is done, that should be the equivalent
        /// of a new cycle.  But I like having more defined phases (even though there is an extra round of function calls to make)
        /// </remarks>
        public virtual void PrepareForNewTimerCycle()
        {
            // I can't decide whether to put this here, or the timerfinish
            _savedPosition = null;
            _elapsedTime   = 0;

            // Reset stuff
            _internalForce.Multiply(0);
            _externalForce.Multiply(0);
            _acceleration.Multiply(0);
        }
Пример #25
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;
        }
Пример #26
0
        private void button2_Click(object sender, EventArgs e)
        {
            MyVector v1 = new MyVector(1, 0, 0);
            MyVector v2 = new MyVector(0, 1, 0);

            MyVector rotationAxis;
            double radians;
            v1.GetAngleAroundAxis(out rotationAxis, out radians, v2);

            v2.GetAngleAroundAxis(out rotationAxis, out radians, v1);
        }
Пример #27
0
        /// <summary>
        /// Every frame, angular velocity is wiped out and recalculated based on angular momentum.  So this function actually
        /// sets angular momentum to produce the velocity passed in.
        /// </summary>
        /// <remarks>
        /// This function is the opposite of the calculation in ApplyTorque
        /// </remarks>
        public void SetAngularVelocity(MyVector angularVelocity)
        {
            // Figure out the world frame's inertia tensor
            // (Rotation * bodyInertialTensorInverse * Transposed Rotation)
            MyMatrix3 curRotation = base.RotationMatrix.Clone();

            MyMatrix3 worldInertiaTensor = MyMatrix3.Multiply(MyMatrix3.Multiply(curRotation, _inertialTensorBody), MyMatrix3.Transpose(curRotation));

            // Now store the angular momentum required to generate this velocity
            _angularMomentum.StoreNewValues(MyMatrix3.Multiply(worldInertiaTensor, angularVelocity));
        }
Пример #28
0
        /// <summary>
        /// This does a deep clone
        /// </summary>
        public static MyVector[] GetClonedArray(MyVector[] vectors)
        {
            MyVector[] retVal = new MyVector[vectors.Length];

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

            return(retVal);
        }
Пример #29
0
        /// <summary>
        /// This function will compute the new acceleration based on the force pushing against the ball.  The result will overwrite the
        /// current acceleration
        /// </summary>
        private void TimerSprtAccel(MyVector force)
        {
            // Make the PartialAccel into a clone of the force passed in
            MyVector partialAccel = force.Clone();

            // I will divide by mass, and it will no longer be force, it will be change in accel (the property guarantees that mass
            // isn't zero)
            partialAccel.Divide(_mass);

            // Add the partial accel to this ball's accel
            _acceleration.Add(partialAccel);
        }
Пример #30
0
        /// <summary>
        /// This constructs a unit quaternion that represents the rotation
        /// </summary>
        public MyQuaternion(MyVector rotationAxis, double radians)
        {
            double halfAngle = radians / 2d;
            double sinHalfAngle = Math.Sin(halfAngle);
            MyVector rotateAroundUnit = MyVector.BecomeUnitVector(rotationAxis);

            // Set my values
            this.X = rotateAroundUnit.X * sinHalfAngle;
            this.Y = rotateAroundUnit.Y * sinHalfAngle;
            this.Z = rotateAroundUnit.Z * sinHalfAngle;
            this.W = Math.Cos(halfAngle);
        }
Пример #31
0
        private static void SplitForceIntoTranslationAndTorque(out MyVector translationForce, out MyVector torque, MyVector centerOfMass, MyVector offset, MyVector force)
        {
            // The offset passed in is relative to position.  I need it to be relative to the center of mass
            MyVector trueOffset = offset - centerOfMass;

            // Torque is how much of the force is applied perpendicular to the radius
            torque = MyVector.Cross(trueOffset, force);

            // I'm still not convinced this is totally right, but none of the articles I've read seem to do anything
            // different
            translationForce = force.Clone();
        }
Пример #32
0
        /// <summary>
        /// This constructs a unit quaternion that represents the rotation
        /// </summary>
        public MyQuaternion(MyVector rotationAxis, double radians)
        {
            double   halfAngle        = radians / 2d;
            double   sinHalfAngle     = Math.Sin(halfAngle);
            MyVector rotateAroundUnit = MyVector.BecomeUnitVector(rotationAxis);

            // Set my values
            this.X = rotateAroundUnit.X * sinHalfAngle;
            this.Y = rotateAroundUnit.Y * sinHalfAngle;
            this.Z = rotateAroundUnit.Z * sinHalfAngle;
            this.W = Math.Cos(halfAngle);
        }
Пример #33
0
        /// <summary>
        /// Get a random vector between boundry lower and boundry upper
        /// </summary>
        public static MyVector GetRandomVector(MyVector boundryLower, MyVector boundryUpper)
        {
            MyVector retVal = new MyVector();

            Random rand = StaticRandom.GetRandomForThread();

            retVal.X = boundryLower.X + (rand.NextDouble() * (boundryUpper.X - boundryLower.X));
            retVal.Y = boundryLower.Y + (rand.NextDouble() * (boundryUpper.Y - boundryLower.Y));
            retVal.Z = boundryLower.Z + (rand.NextDouble() * (boundryUpper.Z - boundryLower.Z));

            return(retVal);
        }
Пример #34
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;
        }
Пример #35
0
        /// <summary>
        /// This function is used to calculate the new velocity based on all the forces that occured from Prepare to Now
        /// </summary>
        public virtual void TimerFinish()
        {
            // Combine the internal and external force
            MyVector force = TimerSprtCombineForce();

            // Figure out the new acceleration
            TimerSprtAccel(force);

            // Figure out the new velocity
            TimerSprtVel(_elapsedTime);

            // I could set the saved position to null here, but I'll just wait until PrepareForNew is called
        }
Пример #36
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 Ball(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)
        {
            // I use the property sets to enforce the values
            this.Mass            = mass;
            this.Elasticity      = elasticity;
            this.KineticFriction = kineticFriction;
            this.StaticFriction  = staticFriction;

            _usesBoundingBox = usesBoundingBox;
            _boundingLower   = boundingBoxLower;
            _boundingUpper   = boundingBoxUpper;
        }
Пример #37
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyVector v1 = new MyVector(3, 4, 5);

            v1.Add(1, 2, 3);

            v1.BecomeUnitVector();

            MyVector v2 = v1.Clone();

            v2.Multiply(3);

            v1.Divide(3);
        }
Пример #38
0
        private Ball _drawingBall = null;		// ball is the lowest base class.  it could also be solidball or rigidbody

        //private double _diminishPercent = 1d;

        #endregion

        #region Constructor

        public BallAdder(LargeMapViewer2D picturebox, ObjectRenderer renderer, BallProps newBallProps, SimpleMap map, MyVector boundryLower, MyVector boundryUpper, List<long> tempObjects)
        {
            _picturebox = picturebox;
            _renderer = renderer;
            _newBallProps = newBallProps;
            _map = map;
            _boundryLower = boundryLower;
            _boundryUpper = boundryUpper;
            _tempObjects = tempObjects;

            _picturebox.MouseDown += new MouseEventHandler(picturebox_MouseDown);
            _picturebox.MouseUp += new MouseEventHandler(picturebox_MouseUp);
            _picturebox.MouseMove += new MouseEventHandler(picturebox_MouseMove);
        }
Пример #39
0
        private void DoGravityDown()
        {
            const double ACCELDOWN = .1d;

            MyVector accel = new MyVector(0, ACCELDOWN * _gravityMultiplier, 0);

            foreach(BallBlip blip in _map.GetAllBlips())
            {
                if (blip.CollisionStyle != CollisionStyle.Standard)
                {
                    continue;
                }

                blip.Ball.Acceleration.Add(accel);       // I do acceleration instead of force so they all fall at the same rate
            }
        }
Пример #40
0
        public GravMouse(LargeMapViewer2D picturebox, SimpleMap map, MyVector boundryLower, MyVector boundryUpper)
        {
            const double RADIUS = 400;

            _picturebox = picturebox;
            _map = map;
            _boundryLower = boundryLower;
            _boundryUpper = boundryUpper;

            _cursorBlip = new BallBlip(new Ball(new MyVector(), new DoubleVector(1, 0, 0, 0, 1, 0), RADIUS, UtilityCore.GetMassForRadius(RADIUS, 1d), 1, 0, 0, _boundryLower, _boundryUpper), CollisionStyle.Stationary, RadarBlipQual.BallUserDefined05, TokenGenerator.NextToken());

            _picturebox.MouseDown += new MouseEventHandler(picturebox_MouseDown);
            _picturebox.MouseUp += new MouseEventHandler(picturebox_MouseUp);
            _picturebox.MouseMove += new MouseEventHandler(picturebox_MouseMove);
            _picturebox.MouseLeave += new EventHandler(picturebox_MouseLeave);
        }
Пример #41
0
        /// <summary>
        /// This constructor is meant to assist the clone function
        /// </summary>
        protected Trail(MyVector[] points, int curPtr, int startRed, int startGreen, int startBlue, int endRed, int endGreen, int endBlue)
        {

            // Store stuff passed in
            _points = points;
            _curPtr = curPtr;
            _startRed = startRed;
            _startGreen = startGreen;
            _startBlue = startBlue;
            _endRed = endRed;
            _endGreen = endGreen;
            _endBlue = endBlue;

            // Set up the other misc stuff
            _isInitialized = true;

        }
Пример #42
0
        public VectorField2D(VectorField2DMode fieldMode, double sizeX, double sizeY, int squaresPerSideX, int squaresPerSideY, double strength, MyVector position)
        {
            // I use the property sets to enforce constraints
            this.FieldMode = fieldMode;

            this.SizeX = sizeX;
            this.SizeY = sizeY;

            this.SquaresPerSideX = squaresPerSideX;
            this.SquaresPerSideY = squaresPerSideY;

            this.Strength = strength;

            // By waiting until now to set the position, I've kept ResetField from running (called by the property sets)
            _position = position;

            ResetField();
        }
Пример #43
0
 public void FillRectangle(Brush brush, MyVector lower, MyVector upper)
 {
     try
     {
         _graphics.FillRectangle(brush,
             PosWToV_X(lower.X), PosWToV_Y(lower.Y),
             DistWToV(upper.X - lower.X), DistWToV(upper.Y - lower.Y));
     }
     catch (OverflowException)
     {
         // Oh well
     }
 }
Пример #44
0
 public void FillRectangle(Color color, MyVector lower, MyVector upper)
 {
     using (SolidBrush brush = new SolidBrush(color))
     {
         FillRectangle(brush, lower, upper);
     }
 }
Пример #45
0
        public void FillTriangle(Brush brush, MyVector point1, MyVector point2, MyVector point3)
        {
            try
            {
                PointF[] points = new PointF[3];

                points[0].X = PosWToV_X(point1.X);
                points[0].Y = PosWToV_Y(point1.Y);

                points[1].X = PosWToV_X(point2.X);
                points[1].Y = PosWToV_Y(point2.Y);

                points[2].X = PosWToV_X(point3.X);
                points[2].Y = PosWToV_Y(point3.Y);

                _graphics.FillPolygon(brush, points);
            }
            catch (OverflowException)
            {
                // Oh well
            }
        }
Пример #46
0
        public void FillPolygon(Brush brush1, Brush brush2, MyVector centerPoint, IMyPolygon polygon)
        {
            try
            {
                //TODO: sort the triangles by z

                // Children
                if (polygon.ChildPolygons != null)
                {
                    foreach (IMyPolygon childPoly in polygon.ChildPolygons)
                    {
                        FillPolygon(brush1, brush2, centerPoint, childPoly);
                    }
                }

                // Current
                if (polygon.Triangles != null)
                {
                    Triangle[] cachedTriangles = polygon.Triangles;

                    for (int triangleCntr = 0; triangleCntr < cachedTriangles.Length; triangleCntr++)
                    {
                        PointF[] points = new PointF[3];

                        points[0].X = PosWToV_X(cachedTriangles[triangleCntr].Vertex1.X + centerPoint.X);
                        points[0].Y = PosWToV_Y(cachedTriangles[triangleCntr].Vertex1.Y + centerPoint.Y);

                        points[1].X = PosWToV_X(cachedTriangles[triangleCntr].Vertex2.X + centerPoint.X);
                        points[1].Y = PosWToV_Y(cachedTriangles[triangleCntr].Vertex2.Y + centerPoint.Y);

                        points[2].X = PosWToV_X(cachedTriangles[triangleCntr].Vertex3.X + centerPoint.X);
                        points[2].Y = PosWToV_Y(cachedTriangles[triangleCntr].Vertex3.Y + centerPoint.Y);

                        if (triangleCntr % 2 == 0)
                        {
                            _graphics.FillPolygon(brush1, points);
                        }
                        else
                        {
                            _graphics.FillPolygon(brush2, points);
                        }
                    }
                }
            }
            catch (OverflowException)
            {
                // Oh well
            }
        }
Пример #47
0
        public void FillPie(Brush brush, MyVector centerPoint, double radius, double startDegrees, double sweepDegrees)
        {
            try
            {
                float widthAndHeight = DistWToV(radius * 2d);

                _graphics.FillPie(brush,
                    PosWToV_X(centerPoint.X - radius), PosWToV_Y(centerPoint.Y - radius),
                    widthAndHeight, widthAndHeight,
                    Convert.ToSingle(startDegrees), Convert.ToSingle(sweepDegrees));
            }
            catch (OverflowException)
            {
                // Oh well
            }
        }
Пример #48
0
        public LargeMapViewer2D()
        {
            InitializeComponent();

            // Default to viewing everything
            _centerPoint = new MyVector();
            ZoomFit();

            // AutoScroll Emulator
            _autoscroll = new AutoScrollEmulator();
            _autoscroll.AutoScroll += new AutoScrollHandler(Autoscroll_AutoScroll);
            _autoscroll.CursorChanged += new EventHandler(Autoscroll_CursorChanged);
        }
Пример #49
0
        public void DrawTriangle_Selected(MyVector point1, MyVector point2, MyVector point3)
        {
            try
            {
                float x1 = PosWToV_X(point1.X);
                float y1 = PosWToV_Y(point1.Y);
                float x2 = PosWToV_X(point2.X);
                float y2 = PosWToV_Y(point2.Y);
                float x3 = PosWToV_X(point3.X);
                float y3 = PosWToV_Y(point3.Y);

                _graphics.DrawLine(_selectionPen, x1, y1, x2, y2);
                _graphics.DrawLine(_selectionPen, x2, y2, x3, y3);
                _graphics.DrawLine(_selectionPen, x3, y3, x1, y1);
            }
            catch (OverflowException)
            {
                // Oh well
            }
        }
Пример #50
0
 public void FillPie(Color color, MyVector centerPoint, double radius, MyVector centerLine, double sweepRadians)
 {
     using (SolidBrush brush = new SolidBrush(color))
     {
         FillPie(brush, centerPoint, radius, centerLine, sweepRadians);
     }
 }
Пример #51
0
        public void FillPie(Brush brush, MyVector centerPoint, double radius, MyVector centerLine, double sweepRadians)
        {
            // Turn the centerline and sweep radians into angles that GDI likes
            MyVector dummy = new MyVector(1, 0, 0);
            double startDegrees;
            dummy.GetAngleAroundAxis(out dummy, out startDegrees, centerLine);
            startDegrees = Utility3D.GetRadiansToDegrees(startDegrees);

            if (centerLine.Y < 0)
            {
                startDegrees *= -1;
            }

            double sweepDegrees = Utility3D.GetRadiansToDegrees(sweepRadians);

            startDegrees -= sweepDegrees / 2d;

            // Call my overload
            FillPie(brush, centerPoint, radius, startDegrees, sweepDegrees);
        }
Пример #52
0
        public void DrawArc(Color penColor, double penWidth, MyVector[] points, bool closed)
        {
            try
            {
                using (Pen pen = new Pen(penColor, DistWToV(penWidth)))
                {
                    // Transform the points to view coords
                    PointF[] scaledPoints = new PointF[points.Length];
                    for (int cntr = 0; cntr < points.Length; cntr++)
                    {
                        scaledPoints[cntr] = new PointF(PosWToV_X(points[cntr].X), PosWToV_Y(points[cntr].Y));
                    }

                    // Draw the curve
                    if (closed)
                    {
                        _graphics.DrawClosedCurve(pen, scaledPoints);
                    }
                    else
                    {
                        _graphics.DrawCurve(pen, scaledPoints);
                    }
                }
            }
            catch (OverflowException)
            {
                // Oh well
            }
        }
Пример #53
0
 public void FillPie(Color color, MyVector centerPoint, double radius, double startDegrees, double sweepDegrees)
 {
     using (SolidBrush brush = new SolidBrush(color))
     {
         FillPie(brush, centerPoint, radius, startDegrees, sweepDegrees);
     }
 }
Пример #54
0
        public void DrawArc_Selected(MyVector[] points, bool closed)
        {
            try
            {
                // Transform the points to view coords
                PointF[] scaledPoints = new PointF[points.Length];
                for (int cntr = 0; cntr < points.Length; cntr++)
                {
                    scaledPoints[cntr] = new PointF(PosWToV_X(points[cntr].X), PosWToV_Y(points[cntr].Y));
                }

                // Draw the curve
                if (closed)
                {
                    _graphics.DrawClosedCurve(_selectionPen, scaledPoints);
                }
                else
                {
                    _graphics.DrawCurve(_selectionPen, scaledPoints);
                }
            }
            catch (OverflowException)
            {
                // Oh well
            }
        }
Пример #55
0
 public void FillPolygon(Color color1, Color color2, MyVector centerPoint, IMyPolygon polygon)
 {
     using (SolidBrush brush1 = new SolidBrush(color1))
     {
         using (SolidBrush brush2 = new SolidBrush(color2))
         {
             FillPolygon(brush1, brush2, centerPoint, polygon);
         }
     }
 }
Пример #56
0
        public void DrawString(string message, Font font, Brush brush, MyVector position, ContentAlignment textAlign)
        {
            try
            {
                if (textAlign == ContentAlignment.TopLeft)
                {
                    _graphics.DrawString(message, font, brush, PosWToV_X(position.X), PosWToV_Y(position.Y));
                }
                else
                {
                    SizeF textSize = _graphics.MeasureString(message, font);
                    float worldX = PosWToV_X(position.X);
                    float worldY = PosWToV_Y(position.Y);

                    switch (textAlign)
                    {
                        case ContentAlignment.TopCenter:
                            _graphics.DrawString(message, font, brush, worldX - (textSize.Width / 2f), worldY);
                            break;

                        case ContentAlignment.TopRight:
                            _graphics.DrawString(message, font, brush, worldX - textSize.Width, worldY);
                            break;

                        case ContentAlignment.MiddleLeft:
                            _graphics.DrawString(message, font, brush, worldX, worldY - (textSize.Height / 2f));
                            break;

                        case ContentAlignment.MiddleCenter:
                            _graphics.DrawString(message, font, brush, worldX - (textSize.Width / 2f), worldY - (textSize.Height / 2f));
                            break;

                        case ContentAlignment.MiddleRight:
                            _graphics.DrawString(message, font, brush, worldX - textSize.Width, worldY - (textSize.Height / 2f));
                            break;

                        case ContentAlignment.BottomLeft:
                            _graphics.DrawString(message, font, brush, worldX, worldY - textSize.Height);
                            break;

                        case ContentAlignment.BottomCenter:
                            _graphics.DrawString(message, font, brush, worldX - (textSize.Width / 2f), worldY - textSize.Height);
                            break;

                        case ContentAlignment.BottomRight:
                            _graphics.DrawString(message, font, brush, worldX - textSize.Width, worldY - textSize.Height);
                            break;

                        default:
                            // Oh well
                            return;
                    }
                }

            }
            catch (OverflowException)
            {
                // Oh well
            }
        }
Пример #57
0
 public void FillTriangle(Color color, MyVector point1, MyVector point2, MyVector point3)
 {
     using (SolidBrush brush = new SolidBrush(color))
     {
         FillTriangle(brush, point1, point2, point3);
     }
 }
Пример #58
0
 public void FillCircle(Color color, MyVector centerPoint, double radius)
 {
     using (SolidBrush brush = new SolidBrush(color))
     {
         FillCircle(brush, centerPoint, radius);
     }
 }
Пример #59
0
        /// <summary>
        /// If the user clicks on a picture box, you need to run those coords through this function to figure out where they
        /// clicked in world coords
        /// </summary>
        /// <param name="position">A point in PictureBox coords</param>
        /// <returns>The point in World Coords</returns>
        public MyVector GetPositionViewToWorld(MyVector position)
        {
            MyVector retVal = position.Clone();

            // Figure out the world coords that the top left of the picturebox represents
            double picLeft = _centerPoint.X - ((this.Width / 2d) / _zoom);
            double picTop = _centerPoint.Y - ((this.Height / 2d) / _zoom);

            // The point passed in is a distance from the top left of the picture box to where they clicked.  Turn this view
            // coords into world coords
            retVal.Divide(_zoom);

            // Add these world coords to the top left of the picture box
            retVal.X += picLeft;
            retVal.Y += picTop;

            // It's now what it needs to be
            return retVal;
        }
Пример #60
0
        public void FillCircle(Brush brush, MyVector centerPoint, double radius)
        {
            try
            {
                float widthAndHeight = DistWToV(radius * 2d);

                _graphics.FillEllipse(brush,
                    PosWToV_X(centerPoint.X - radius), PosWToV_Y(centerPoint.Y - radius),
                    widthAndHeight, widthAndHeight);
            }
            catch (OverflowException)
            {
                // Oh well
            }
        }