/// <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); }
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); }
/// <summary> /// This function will set the center position to the center of the rectangle passed in, and set the zoom so that I can /// see everything inside the rectangle /// </summary> /// <remarks> /// I will be in static mode after this call (as opposed to chase mode) /// </remarks> public void ZoomRectangle(MyVector cornerLower, MyVector cornerUpper) { // Figure out the position. By setting it to a new vector, I've gone into static mode _centerPoint = cornerLower + cornerUpper; _centerPoint.Divide(2); // Set temp X and Y to the zoom rectangle width and height double tempX = cornerUpper.X - cornerLower.X; double tempY = cornerUpper.Y - cornerLower.Y; // Now set temp X and Y to the corresponding zoom factors tempX = this.Width / tempX; tempY = this.Height / tempY; // Store the lower of the two if (tempX < tempY) { _zoom = tempX; } else { _zoom = tempY; } }
private void Copy() { if (_mode != SelectionMode.Selected || _selectedObjects.Count == 0) { return; } _myClipboard.Clear(); _clipboardPositionCenter = new MyVector(); foreach (RadarBlip blip in _map.GetAllBlips()) { if (_selectedObjects.Contains(blip.Token)) { _myClipboard.Add(Scenes.CloneBlip(blip, _map)); _clipboardPositionCenter.Add(blip.Sphere.Position); } } if (_myClipboard.Count > 0) { _clipboardPositionCenter.Divide(_myClipboard.Count); } }
/// <summary> /// This function prunes the list of positions that are too old. It then figures out the average velocity /// of the remaining positions. /// </summary> private MyVector TimerSprtCalculateVelocity() { const int RETENTION = 75; // milliseconds int curTick = Environment.TickCount; // Add the current to the list _prevMousePositions.Add(new MousePosition(_curMousePoint.Clone())); #region Prune List int lastIndex = -1; for (int cntr = _prevMousePositions.Count - 1; cntr >= 0; cntr--) { if (curTick - _prevMousePositions[cntr].Tick > RETENTION) { // This item is too old. And since the list is in time order, all the entries before this are also too old lastIndex = cntr; break; } } if (lastIndex >= 0) { //_prevMousePositions.RemoveRange(lastIndex, _prevMousePositions.Count - lastIndex); _prevMousePositions.RemoveRange(0, lastIndex + 1); } #endregion #region Calculate Velocity MyVector retVal = new MyVector(0, 0, 0); // Add up all the instantaneous velocities for (int cntr = 0; cntr < _prevMousePositions.Count - 1; cntr++) { retVal.Add(_prevMousePositions[cntr + 1].Position - _prevMousePositions[cntr].Position); } // Take the average if (_prevMousePositions.Count > 2) // if count is 0 or 1, then retVal will still be (0,0,0). If it's 2, then I would be dividing by 1, which is pointless { retVal.Divide(_prevMousePositions.Count - 1); } #endregion // Exit Function return retVal; }
protected void GetCollisionNormalAndPointsOfContact_SphereSphere(out MyVector normal, out double normalMagnitude, out MyVector pointOfContact1, out MyVector pointOfContact2, BallBlip ball1, BallBlip ball2) { // Vector that is perpendicular to the tangent of the collision, and it points in the direction of object 1. Real // easy when dealing with spheres :) normal = ball2.Ball.Position - ball1.Ball.Position; // Remember this length normalMagnitude = normal.GetMagnitude(); // This needs to be returned as a unit vector normal.Divide(normalMagnitude); // Start them off as unit vectors pointOfContact1 = normal.Clone(); pointOfContact2 = normal.Clone(); // Finish (use the ratio of their radii) pointOfContact1.Multiply((ball1.Ball.Radius / (ball1.Ball.Radius + ball2.Ball.Radius)) * normalMagnitude); pointOfContact2.Multiply((ball2.Ball.Radius / (ball1.Ball.Radius + ball2.Ball.Radius)) * normalMagnitude * -1); // I want this one pointing the other direction // Now that I have the points of contact relative to the centers of position, I need to make them // relative to the centers of mass if (ball1.TorqueBall != null) { pointOfContact1.Subtract(ball1.TorqueBall.CenterOfMass); } if (ball2.TorqueBall != null) { pointOfContact2.Subtract(ball2.TorqueBall.CenterOfMass); } }