/// <summary> /// Adds the radar blip. /// </summary> /// <param name="go"> GameObject to Track</param> /// <param name="clr"> Color to pass to particle</param> public void AddRadarBlip(GameObject go, Color clr, float size) { // Create a Blip for each item on screen RadarBlip rb = new RadarBlip() { Target = go, BlipColor = clr, BlipSize = size, BlipOpacity = 1.0f, BlipHeight = new GameObject("Line") }; if (drawLineHeights) { // Assign a line renderer for each RadarBlip to draw heights LineRenderer line = rb.BlipHeight.AddComponent <LineRenderer> (); rb.BlipHeight.layer = bit; rb.BlipHeight.transform.parent = this.transform; line.material = new Material(Shader.Find("Mobile/Particles/Additive")); line.startColor = clr; line.endColor = clr; line.startWidth = 0.04f; line.endWidth = 0.04f; line.startWidth = 0.04f; line.endWidth = 0.04f; //line.SetVertexCount (2); line.positionCount = 2; line.useWorldSpace = false; rb.BlipHeight.name = "Line " + go.name; } _RadarBlips.Add(rb); }
/// <summary> /// Adds the radar blip. /// </summary> /// <param name="go"> GameObject to Track</param> /// <param name="clr"> Color to pass to particle</param> public void AddRadarBlip(GameObject go, Color clr, float size) { // Create a Blip for each item on screen RadarBlip rb = new RadarBlip () { Target = go, BlipColor = clr, BlipSize = size, BlipOpacity = 1.0f, BlipHeight = new GameObject ("Line") }; if (drawLineHeights) { // Assign a line renderer for each RadarBlip to draw heights LineRenderer line = rb.BlipHeight.AddComponent<LineRenderer> (); rb.BlipHeight.layer = bit; rb.BlipHeight.transform.parent = this.transform; line.material = new Material (Shader.Find ("Mobile/Particles/Additive")); line.SetColors (Color.white, Color.white); line.SetWidth (0.02F, 0.02F); line.SetVertexCount (2); line.useWorldSpace = false; rb.BlipHeight.name = "Line " + go.name; } _RadarBlips.Add (rb); }
private void Paste() { if (_myClipboard.Count == 0) { return; } _selectedObjects.Clear(); foreach (RadarBlip blip in _myClipboard) { // Clone this object RadarBlip tempBlip = Scenes.CloneBlip(blip, _map); // Figure out where to place the pasted object MyVector newPosition = tempBlip.Sphere.Position - _clipboardPositionCenter; newPosition.Add(_curMousePoint); tempBlip.Sphere.Position.StoreNewValues(newPosition); // Add it _selectedObjects.Add(tempBlip.Token); _map.Add(tempBlip); } _mode = SelectionMode.Selected; }
private bool SelectionTest(RadarBlip blip, MyVector point) { // Just worry about spheres for now MyVector line = point - blip.Sphere.Position; return(line.GetMagnitude() <= blip.Sphere.Radius); }
public static RadarBlip CloneBlip(RadarBlip blip, SimpleMap map) { BallBlip retVal = new BallBlip((Ball)blip.Sphere.Clone(), blip.CollisionStyle, blip.Qual, TokenGenerator.NextToken()); retVal.Ball.Velocity.StoreNewValues(((Ball)blip.Sphere).Velocity); if (blip.Sphere is TorqueBall) { ((TorqueBall)retVal.Sphere).AngularMomentum.StoreNewValues(((TorqueBall)blip.Sphere).AngularMomentum); } return(retVal); }
private RadarBlip FindAndRemove(long token, List <RadarBlip> blips) { for (int cntr = 0; cntr < blips.Count; cntr++) { if (blips[cntr].Token == token) { RadarBlip retVal = blips[cntr]; blips.RemoveAt(cntr); return(retVal); } } return(null); }
private bool SelectionTest(RadarBlip blip, MyVector rectCorner1, MyVector rectCorner2) { // Just worry about spheres for now // I'll just cheat and let the rectangle do the work for me. There are several flaws with this, but it // works for now MyVector topLeft, bottomRight; GetProperCorners(out topLeft, out bottomRight, rectCorner1, rectCorner2); RectangleF rect = new RectangleF(topLeft.ToPointF(), new SizeF(Convert.ToSingle(bottomRight.X - topLeft.X), Convert.ToSingle(bottomRight.Y - topLeft.Y))); return(rect.Contains(blip.Sphere.Position.ToPointF())); }
private bool WillCollide(Ball ball) { // Make a temp blip to be a wrapper for this RadarBlip blip = new RadarBlip(ball, CollisionStyle.Standard, RadarBlipQual.BallUserDefined10, TokenGenerator.NextToken()); foreach (RadarBlip existingBlip in _map.GetAllBlips()) { if (_map.CollisionHandler.IsColliding(blip, existingBlip) != CollisionDepth.NotColliding) { // It's colliding return(true); } } return(false); }
private void ApplyExplosionForce(RadarBlip blip) { if (!(blip is BallBlip)) { return; } BallBlip castBlip = (BallBlip)blip; MyVector force = castBlip.Ball.Position - this.Ball.Position; force.BecomeUnitVector(); force.Multiply(_explosion.Force); // Setting the force does no good, because PrepareForNewTick is called before it can take affect //castBlip.Ball.ExternalForce.Add(force); force.Divide(castBlip.Ball.Mass); // F=MA castBlip.Ball.Velocity.Add(force); }
private void HurtBlip(Projectile projectile, RadarBlip blip) { #region See if a split should occur if (blip.CollisionStyle != CollisionStyle.Standard) { return; } if (!(blip is BallBlip)) { return; } BallBlip castBlip = (BallBlip)blip; double ratio = projectile.Pain / castBlip.Ball.Mass; double rand = _rand.NextDouble(); if (ratio < rand) { return; } #endregion #region Calculate Split Percents int numParts = 2 + _rand.Next(3); // between 2 and 4 parts double[] splitPercents = new double[numParts]; double remainder = 1d; for (int cntr = 0; cntr < numParts - 1; cntr++) { splitPercents[cntr] = _rand.NextDouble() * remainder; remainder -= splitPercents[cntr]; } splitPercents[numParts - 1] = remainder; #endregion #region Build Objects _map.Remove(blip.Token); foreach (double percent in splitPercents) { double size = castBlip.Ball.Mass * percent; if (size < 20) { continue; } Ball ball; if (castBlip.Ball is SolidBall) { ball = new SolidBall(castBlip.Ball.Position.Clone(), castBlip.Ball.OriginalDirectionFacing.Clone(), size, size, castBlip.Ball.Elasticity, castBlip.Ball.KineticFriction, castBlip.Ball.StaticFriction, _boundryLower, _boundryUpper); } else { ball = new Ball(castBlip.Ball.Position.Clone(), castBlip.Ball.OriginalDirectionFacing.Clone(), size, size, castBlip.Ball.Elasticity, castBlip.Ball.KineticFriction, castBlip.Ball.StaticFriction, _boundryLower, _boundryUpper); } ball.Velocity.StoreNewValues(castBlip.Ball.Velocity); //TODO: Lay them out so they aren't touching each other. The smallest ones should be closest // to the point of impact (maybe give them slightly tweaked velocities as well so they explode // outward) _map.Add(new BallBlip(ball, blip.CollisionStyle, blip.Qual, TokenGenerator.NextToken())); } #endregion }
void picturebox_MouseDown(object sender, MouseEventArgs e) { if (!_active) { return; } if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) { _mouseDownPoint = _picturebox.GetPositionViewToWorld(new MyVector(e.X, e.Y, 0)); _curMousePoint = _mouseDownPoint.Clone(); _prevMousePositions.Clear(); _tempStationaryObjects.Clear(); // this should be cleared by now anyway } if (e.Button == MouseButtons.Left) { #region Left _isMouseDown = MouseButtonDown.Left; // Get all the blips List <RadarBlip> remainingBlips = new List <RadarBlip>(_map.GetAllBlips()); bool selectedPrevious = false; #region See if they selected one of the previously selected objects foreach (long token in _selectedObjects) { RadarBlip blip = FindAndRemove(token, remainingBlips); if (blip == null) { continue; } if (selectedPrevious) { // I just wanted to remove this blip from the total list continue; } if (SelectionTest(blip, _curMousePoint)) { selectedPrevious = true; } } #endregion // Check for ctrl or shift key being pressed (if they are, don't clear the previous) if (!selectedPrevious && !(_isShiftPressed || _isCtrlPressed)) { _selectedObjects.Clear(); } bool selectedNew = false; #region See if they clicked on any other objects foreach (RadarBlip blip in remainingBlips) { if (SelectionTest(blip, _curMousePoint)) { _selectedObjects.Add(blip.Token); selectedNew = true; } } #endregion // Set my mode if (selectedPrevious || selectedNew) { _mode = SelectionMode.Selected; #region Rebuild the offsets list (and temp stationary) _draggingPositionOffsets.Clear(); foreach (RadarBlip blip in _map.GetAllBlips()) { if (_selectedObjects.Contains(blip.Token)) { _draggingPositionOffsets.Add(blip.Token, blip.Sphere.Position - _curMousePoint); if (blip.CollisionStyle == CollisionStyle.Standard) { _tempStationaryObjects.Add(blip.Token); blip.CollisionStyle = CollisionStyle.Stationary; } } } #endregion } else { _mode = SelectionMode.Rectangle; } #endregion } else if (e.Button == MouseButtons.Right) { #region Right if (_mode == SelectionMode.Selected && _selectedObjects.Count > 0) { _isMouseDown = MouseButtonDown.Right; } else { // If nothing is selected, then there is nothing for me to do _isMouseDown = MouseButtonDown.None; } #endregion } }