protected PathGeometry ConstructGeometry(Vector?offset) { PathGeometry g = new PathGeometry(); if ((Nodes.Count <= 0) || (Nodes[0].Point == null)) { return(g); } g.Figures.Add(new PathFigure { IsFilled = this.IsFilled }); foreach (DDNode node in Nodes) { if (node.Segment != null) { BezierSegment segment = node.Segment; if (offset.HasValue) { segment = segment.Clone(); segment.Point1 += offset.Value; segment.Point2 += offset.Value; segment.Point3 += offset.Value; } g.Figures[0].Segments.Add(segment); } } return(g); }
private void AdjustPosition() { collisionHelpers[0].Object.Position = this.Position - new Vector(-Width / 4, Height * 1 / 8); collisionHelpers[1].Object.Position = this.Position - new Vector(0, Height * 1 / 8); collisionHelpers[2].Object.Position = this.Position - new Vector(Width / 4, Height * 1 / 8); if (state == PlatformCharacterState.Jumping) { return; } PhysicsObject platform = FindPlatform(); if (platform != null && IsStandingOn(platform, lowTolerance)) { this.Y = GetPlatformTopY(platform) + this.Height / 2; if (lastPlatformPosition.HasValue) { this.X += platform.X - lastPlatformPosition.Value.X; } lastPlatformPosition = platform.Position; lastPlatform = platform; } else { IgnoresGravity = false; lastPlatformPosition = null; state = PlatformCharacterState.Falling; SetAnimation(AnimFall, LoopFallAnim); } }
public BridgeFrameBuffer(Vector?dpi = null) { _dpi = dpi ?? new Vector(192, 192); var instancePath = Locator.FindDfrDevice(); if (instancePath == null) { throw new Exception("DFR Display Device not found"); } _fd = NativeMethods.CreateFile( instancePath, FileAccess.Write, FileShare.None, IntPtr.Zero, FileMode.Open, FileOptions.None, IntPtr.Zero ); if (_fd == IntPtr.Zero) { throw new Exception("Error: " + Marshal.GetLastWin32Error()); } // At least for now, the DFR display spec is fully known and determined across all devices. // Should this changes, issue an IOCTL to retrieve device spec in the future. }
/// <summary> /// Returns whether or not there is a direct line of sight /// between the two vectors. (Not blocked by any geometry). /// This function must be run on a valid object in the area /// it will not work on the module or area. /// PLEASE NOTE: This is an expensive function and may /// degrade performance if used frequently. /// </summary> public static int LineOfSightVector(Vector?vSource, Vector?vTarget) { Internal.NativeFunctions.StackPushVector(vTarget.HasValue ? vTarget.Value : new Vector()); Internal.NativeFunctions.StackPushVector(vSource.HasValue ? vSource.Value : new Vector()); Internal.NativeFunctions.CallBuiltIn(753); return(Internal.NativeFunctions.StackPopInteger()); }
/// <summary> /// Places a structure in the world and replaces the placed structure block with the block which was there before the structure block was placed /// </summary> /// <param name="structureLocation">The location to place the structure at</param> /// <param name="structure">The structure to place</param> /// <param name="structureBlockLocation">The location of the structure block which places the structure</param> /// <param name="redstoneBlockDirection">The side of the structure block the redstoneblock is placed on</param> /// <param name="structurePlaceInformation">Extra information on how the structure should be placed</param> /// <returns>The placed structure</returns> public IStructure Place(Vector structureLocation, IStructure structure, Vector?structureBlockLocation = null, ID.FacingFull redstoneBlockDirection = ID.FacingFull.down, Blocks.StructureBlock?structurePlaceInformation = null) { var(structureOffset, blockLocation, redstoneLocation) = GetStructureCoords(structureLocation, structureBlockLocation, redstoneBlockDirection); ForFunction.Custom.GroupCommands(group => { Vector structureBlockHoldingLocation = ForFunction.PackNamespace.Datapack.GetItems <SharpCraftFiles>().GetStructureBlocksLocation(); Vector redstoneBlockHoldingLocation = structureBlockHoldingLocation + Vector.PositiveX; group.Block.Clone(blockLocation, blockLocation, structureBlockHoldingLocation); group.Block.Clone(redstoneLocation, redstoneLocation, redstoneBlockHoldingLocation); group.Block.Add(blockLocation, new Blocks.StructureBlock() { DIntegrity = structurePlaceInformation?.DIntegrity, DIgnoreEntities = structurePlaceInformation?.DIgnoreEntities ?? false, DMirror = structurePlaceInformation?.DMirror, DRotation = structurePlaceInformation?.DRotation, DCoords = structureOffset is null ? null : new IntVector((int)structureOffset.X, (int)structureOffset.Y, (int)structureOffset.Z), DStructure = structure, DMode = ID.StructureDataMode.LOAD, SMode = ID.StructureMode.load }); group.Block.Add(redstoneLocation, ID.Block.redstone_block); group.Execute.IfBlock(blockLocation, ID.Block.structure_block).Block.Clone(structureBlockHoldingLocation, structureBlockHoldingLocation, blockLocation); group.Execute.IfBlock(redstoneLocation, ID.Block.redstone_block).Block.Clone(redstoneBlockHoldingLocation, redstoneBlockHoldingLocation, redstoneLocation); });
public static void VelocityRot(Game game, string itemId, Vector vel, Vector?rot, Vector?mouseFwd, bool isMegaThrust, bool sendReliable) { var data = new Dictionary <byte, object> { { (byte)ParameterCode.Velocity, vel } }; if (itemId != null) { data.Add((byte)ParameterCode.ItemId, itemId); } if (rot != null) { data.Add((byte)ParameterCode.Rotation, rot); } if (mouseFwd != null) { data.Add((byte)ParameterCode.MouseFwd, mouseFwd); } if (isMegaThrust == true) { data.Add((byte)ParameterCode.IsMegaThrust, true); } game.SendOperation(OperationCode.VelocityRotation, data, sendReliable, Settings.ItemChannel); }
public static Vector?PuntoRectangulo(Vector RP1, Vector RP2, Vector RP3, Vector RP4, Vector RA, Vector RB) { Vector?A1 = Intersects(RP1, RP2, RA, RB); if (A1 != null) { return(A1); } A1 = Intersects(RP2, RP3, RA, RB); if (A1 != null) { return(A1); } A1 = Intersects(RP3, RP4, RA, RB); if (A1 != null) { return(A1); } A1 = Intersects(RP4, RP1, RA, RB); if (A1 != null) { return(A1); } return(RA); }
/// <summary> /// find the element located at the Pos within the Canvas. /// Return a reference to that element. Also return the vector between the /// upper left of the Canvas and the upper left of the found element. /// </summary> /// <param name="Canvas"></param> /// <param name="Pos"></param> /// <returns></returns> public static Tuple <FrameworkElement, Vector?> FindFrameworkElementAtPoint( this Canvas Canvas, Point Pos) { FrameworkElement found = null; Vector? rltvToElement = null; var posRect = Pos.GetRectAtPoint(); Debug.Print("mouse click pos. " + posRect.ToString()); foreach (var elem in Canvas.Children) { var fe = elem as FrameworkElement; if (fe != null) { var rect = fe.GetCanvasRect(); Debug.Print("frameworkElement:" + fe.ToString() + " location:" + rect.ToString()); if (rect.Contains(posRect)) { found = fe; rltvToElement = posRect.TopLeft - rect.TopLeft; } } } return(new Tuple <FrameworkElement, Vector?>(found, rltvToElement)); }
public void DrawEx(IntPtr rendererId, int x, int y, double angle, Vector?center, SDL.SDL_RendererFlip flipMode) { var source = new SDL.SDL_Rect() { x = this.X, y = this.Y, w = Width, h = Height }; var destination = new SDL.SDL_Rect() { x = x, y = y, w = Width, h = Height }; if (center.HasValue) { var centerPoint = new SDL.SDL_Point { x = (int)center.Value.X, y = (int)center.Value.Y }; SDL.SDL_RenderCopyEx(rendererId, TextureId, ref source, ref destination, angle, ref centerPoint, flipMode); } else { SDL.SDL_RenderCopyEx(rendererId, TextureId, ref source, ref destination, angle, IntPtr.Zero, flipMode); } }
public Sprite(SubTexture texture, Vector?size = null, Vector?origin = null, Mask?maskShape = null) { this.AnimationStrip = new AnimationStrip(texture); this.Size = size ?? texture.Size; this._origin = origin; this._maskShape = maskShape ?? Mask.Automatic; }
/// <summary> /// Liikuttaa kappaletta kohti määränpäätä. /// </summary> protected virtual void MoveToTarget() { if (!moveTarget.HasValue) { moveTimer.Stop(); return; } Vector d = moveTarget.Value - Position; double vt = moveSpeed * moveTimer.Interval; if (d.Magnitude < vt) { Vector targetLoc = moveTarget.Value; moveTimer.Stop(); Position = moveTarget.Value; moveTarget = null; if (arrivedAction != null) { arrivedAction(); } } else { Position += Vector.FromLengthAndAngle(vt, d.Angle); } }
private (Vector?structureOffset, Vector blockLocation, Vector redstoneLocation) GetStructureCoords(Vector structureLocation, Vector?structureBlockLocation, ID.FacingFull redstoneBlockDirection) { Vector structureBlockRealLocation = structureBlockLocation ?? structureLocation; Vector?structureOffset = structureBlockLocation is null ? null : structureLocation - structureBlockLocation; if (structureBlockLocation is LocalCoords) { throw new System.ArgumentException("StructureBlockLocation may not be of type LocalCoords", nameof(structureBlockLocation)); } if (!(structureBlockLocation is null)) { if (structureLocation is LocalCoords) { throw new System.ArgumentException("StructureLocation may not be of type LocalCoords if StructureBlockLocation is specified", nameof(structureLocation)); } if (structureLocation is Coords ^ structureBlockLocation is Coords) { throw new System.ArgumentException("StructureLocation may not be of a different type than StructureBlockLocation", nameof(structureLocation)); } } if (!(structureOffset is null)) { if (System.Math.Abs(structureOffset.X) > SharpCraft.Structure.StructureMaxSize || System.Math.Abs(structureOffset.Y) > SharpCraft.Structure.StructureMaxSize || System.Math.Abs(structureOffset.Z) > SharpCraft.Structure.StructureMaxSize) { throw new System.ArgumentException("The difference between structureLocation and structureBlockLocation may not be bigger than " + SharpCraft.Structure.StructureMaxSize, nameof(structureLocation)); } } Vector redstoneBlockRelativeLocation; switch (redstoneBlockDirection) { case ID.FacingFull.down: redstoneBlockRelativeLocation = Vector.NegativeY; break; case ID.FacingFull.east: redstoneBlockRelativeLocation = Vector.PositiveX; break; case ID.FacingFull.north: redstoneBlockRelativeLocation = Vector.NegativeZ; break; case ID.FacingFull.south: redstoneBlockRelativeLocation = Vector.PositiveZ; break; case ID.FacingFull.west: redstoneBlockRelativeLocation = Vector.NegativeX; break; case ID.FacingFull.up: default: redstoneBlockRelativeLocation = Vector.PositiveY; break; } return(structureOffset, structureBlockRealLocation, structureBlockRealLocation is Coords ? (Coords)structureBlockRealLocation + redstoneBlockRelativeLocation : structureBlockRealLocation + redstoneBlockRelativeLocation); }
public Sprite(AnimationStrip animationStrip, Vector?size = null, Vector?origin = null, Mask?maskShape = null) { this.AnimationStrip = animationStrip; this.Size = size ?? animationStrip.SubImage(0).Size; this._origin = origin; this._maskShape = maskShape ?? Mask.Automatic; }
public override Action <DrawingContext>[] PrepareToDrawing(Vector?vec, double PixelsPerDip, bool DrawOver = false) { var adcs = new Action <DrawingContext> [3]; if (Chart.TimeA != DateTime.FromBinary(0)) { var tA = Chart.TimeA - Chart.DeltaTime; var tB = Chart.TimeB + Chart.DeltaTime; dT = (Chart.TimeB - Chart.TimeA) / Chart.ChWidth; var Current = (from v in Data where v.TimeStamp > tA && v.TimeStamp < tB select v).ToList(); if (Current.Count > 2) { var LS = new LineSegment[Current.Count - 1]; Parallel.For(1, Current.Count, i => { LS[i - 1] = new LineSegment(GetPoint(Current[i].TimeStamp, Current[i].Price), true); LS[i - 1].Freeze(); }); var geo = new PathGeometry(new[] { new PathFigure(GetPoint(Current[0].TimeStamp, Current[0].Price), LS, false) }); geo.Freeze(); adcs[0] = dc => dc.DrawGeometry(null, LinePen, geo); } } return(adcs); }
/// <summary> /// Create a location. /// </summary> public static Location Location(uint oArea, Vector?vPosition, float fOrientation) { Internal.NativeFunctions.StackPushFloat(fOrientation); Internal.NativeFunctions.StackPushVector(vPosition.HasValue ? vPosition.Value : new Vector()); Internal.NativeFunctions.StackPushObject(oArea); Internal.NativeFunctions.CallBuiltIn(215); return(new Location(Internal.NativeFunctions.StackPopLocation())); }
/// <summary> /// Pysäyttää MoveTo-aliohjelmalla aloitetun liikkeen. /// </summary> public void StopMoveTo() { if (moveTimer != null) { moveTimer.Stop(); moveTarget = null; } }
public static void StackPushVector(Vector?value) { if (!value.HasValue) { value = new Vector(0.0f, 0.0f, 0.0f); } StackPushVector_Native(value.Value); }
public void Clear() { m_newStateNo = -1; m_newFacing = 0; m_newAnimNo = -1; m_newVel = null; m_newVelDelta = null; m_newPos = null; m_newPosDelta = null; }
private bool AddCurrentMousePosition() { Vector?position = this.mousePositionProvider.GetMousePosition(); if (position != null && (this.positions.Count == 0 || this.positions.Last.Value != position)) { this.toolApplierProvider().AddPosition(this.ActiveTool.ToolBrushName, this.positions, position.Value); } return(position.HasValue); }
private protected override void ChangeMethod(Vector?Changes) { if (Changes.HasValue) { this.NPrice = Chart.HeightToPrice(Chart.PriceToHeight(this.Price) + Changes.Value.Y); } else { this.NPrice = this.Price; } }
public bool VelocityRotation(Vector vel, Vector?rot, Vector?mouseFwd, bool isMegaThrust) { if (!this.Game.WorldData.BoundingBox.Contains2d(Position + vel * .051f)) { return(false); } this.Velocity = vel; // this.SetPositions(Position + vel * .05f, Position, (Vector)rot, Rotation); Operations.VelocityRot(this.Game, this.Id, vel, rot, mouseFwd, isMegaThrust, this.Game.Settings.SendReliable); return(true); }
protected void AdjustStartPoint(Geometry g, Vector?offset) { if ((g is PathGeometry) && ((g as PathGeometry).Figures.Count > 0) && (Nodes.Last != null) && (Nodes.Last.Point != null)) { (g as PathGeometry).Figures[0].StartPoint = Nodes.First.Point.Point; if (offset.HasValue) { (g as PathGeometry).Figures[0].StartPoint = (g as PathGeometry).Figures[0].StartPoint + offset.Value; } } }
public Player(string name, bool gender, Pokemon[] party, Bag bag = null, PC pc = null, int?trainerid = null, int?secretid = null, int?money = null, int?coin = null, int?bank = null, int?repel = null, string rival = null, byte[][] dex = null, TimeSpan?time = null, Vector?position = null, byte?follower = null, bool?creator = null, int?map = null, int?pokecenter = null, KeyValuePair <GymBadges, DateTime?>[] gym = null) : this(name : name, gender : gender, party : party, bag : bag != null ? bag.Contents : null, pc_poke : pc != null ? pc.AllBoxes : null, pc_items : pc != null ? pc.Items : null, pc_names : pc != null ? pc.BoxNames : null, pc_textures : pc != null ? pc.BoxTextures : null, pc_box : pc != null ? pc.ActiveBox : (byte?)null, trainerid : trainerid, secretid : secretid, money : money, coin : coin, bank : bank, repel : repel, rival : rival, dex : dex, time : time, position : position, follower : follower, creator : creator, map : map, pokecenter : pokecenter, gym : gym) { }
/// <summary> /// The constructor for the Tetrimino class. /// </summary> /// <param name="letter">The letter shape (type) of the Tetrimino.</param> /// <param name="offsets">The offsets used when rotating in the SRS system.</param> /// <param name="colour">The brush colour to be used when rendering it.</param> /// <param name="states">The states the Tetrimino cylces through in rotation.</param> /// <param name="shiftSpawn">Correction vector for spawning if one exists.</param> /// <param name="startState">The state the Tetrimino should spawn in.</param> /// <remarks> /// Only called in the static constructor, with existing Tetriminos obtained using dictionary. /// </remarks> public Tetrimino(char letter, Brush colour, Vector[][] offsets, Point[][] states, Vector?shiftSpawn = null, int startState = 0) { Type = letter; Colour = colour; this.offsets = offsets; this.states = states; this.shiftSpawn = shiftSpawn; this.startState = startState; Position = null; Types.TryAdd(letter, this); }
protected override Action TakeAction(double elapsedTime) { if (prevActMeetConstraint) { target = null; } prevActMeetConstraint = false; return(new Action() { Toward = target.HasValue ? target.Value - Body[0] : MathExtension.VZero }); }
private static bool ValidateFromToOrByValue(object value) { Vector?typedValue = (Vector?)value; if (typedValue.HasValue) { return(AnimatedTypeHelpers.IsValidAnimationValueVector(typedValue.Value)); } else { return(true); } }
private protected override void ChangeMethod(Vector?Changes) { if (Changes.HasValue) { NP1 = Point1.ToPoint(Chart) + Changes.Value; NP2 = Point2.ToPoint(Chart) + Changes.Value; } else { NP1 = Point1.ToPoint(Chart); NP2 = Point2.ToPoint(Chart); } }
private void Move() { if (Time.time > this.nextMoveTime) { if (this.lastMovePosition.HasValue) { Game.Avatar.MoveAbsolute(this.lastMovePosition.Value, Game.Avatar.Rotation); this.lastMovePosition = null; } // up to 20 times per second this.nextMoveTime = Time.time + 0.05f; } }
public static Vector?VectorOrDefault( this LuaTable table, string key, Vector?defaultValue = null) { if (table[key] is not LuaTable t) { return(defaultValue); } double x = (double)t[1]; double y = (double)t[2]; return(new Vector(x, y)); }
private IEnumerable <(BuildingResourceProduction, Vector?)> BuildingConnections(Vector pos, int buildingModel) { Vector?transportLink = this.buildingTransportLinkFinder.FindTransportLink(pos); if (transportLink.HasValue) { foreach (var connection in this.buildingConnectionFinder.FindConnections(transportLink.Value, buildingModel)) { yield return(connection); } } else { yield return(default, null);
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values[2] == DependencyProperty.UnsetValue) return new System.Windows.Thickness(-50, -50, 0, 0); //<Binding ElementName="offScreen" Path="PageWidth"/> //<Binding ElementName="offScreen" Path="PageHeight"/> //<Binding Path="Position"/> //<Binding ElementName="offScreen" Path="DeviceWidth"/> //<Binding ElementName="offScreen" Path="DeviceHeight"/> //<Binding ElementName="offScreen" Path="DeviceLocation"/> //<Binding ElementName="offScreen" Path="DeviceRotation"/> //<Binding ElementName="offScreen" Path="WidthFactor"/> //<Binding ElementName="offScreen" Path="HeightFactor"/> //<Binding RelativeSource="{RelativeSource AncestorType=ListBox}" Path="ActualWidth"/> //<Binding RelativeSource="{RelativeSource AncestorType=ListBox}" Path="ActualHeight"/> //<Binding ElementName="iArrow" Path="ActualWidth"/> //<Binding ElementName="offScreen" Path="UIRotation"/> var pageWidth = float.Parse(values[0].ToString()); var pageHeight = float.Parse(values[1].ToString()); var highlightPosition = (Point)values[2]; var deviceWidth = float.Parse(values[3].ToString()); var deviceHeight = float.Parse(values[4].ToString()); var deviceLoc = (Point)values[5]; var deviceAngle = double.Parse(values[6].ToString()); var widthFactor = float.Parse(values[7].ToString()); var heightFactor = float.Parse(values[8].ToString()); var controlWidth = float.Parse(values[9].ToString()); var controlHeight = float.Parse(values[10].ToString()); var sizeOffScreenIcon = float.Parse(values[11].ToString()); var uiAngle = double.Parse(values[12].ToString()); //The highlightPosition is not in cms, thus it must be converted to pixels highlightPosition.X = highlightPosition.X * widthFactor; highlightPosition.Y = highlightPosition.Y * heightFactor; Point deviceCenter = new Point(deviceLoc.X * widthFactor, deviceLoc.Y * heightFactor); Rect bounds = new Rect(-deviceWidth / 2, -deviceHeight / 2, deviceWidth, deviceHeight); bounds.Offset(new Vector(deviceCenter.X, deviceCenter.Y)); Point topLeft = bounds.TopLeft; Point topRight = bounds.TopRight; Point bottomRight = bounds.BottomRight; Point bottomLeft = bounds.BottomLeft; Matrix rotationM = Matrix.Identity; rotationM.RotateAt(deviceAngle, deviceCenter.X, deviceCenter.Y); topLeft = rotationM.Transform(topLeft); topRight = rotationM.Transform(topRight); bottomRight = rotationM.Transform(bottomRight); bottomLeft = rotationM.Transform(bottomLeft); //Taken from: http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry2 //Assuming you have two lines of the form Ax + By = C, you can find it pretty easily: //float delta = A1*B2 - A2*B1; //if(delta == 0) // throw new ArgumentException("Lines are parallel"); //float x = (B2*C1 - B1*C2)/delta; //float y = (A1*C2 - A2*C1)/delta; Line lineCenterToHL = new Line(deviceCenter, highlightPosition); Line topFrame = new Line(topLeft, topRight); Line rightFrame = new Line(topRight, bottomRight); Line bottomFrame = new Line(bottomRight, bottomLeft); Line leftFrame = new Line(bottomLeft, topLeft); Point? intersectWithTop = lineCenterToHL.Interset(topFrame); Point? intersectWithRight = lineCenterToHL.Interset(rightFrame); Point? intersectWithBottom = lineCenterToHL.Interset(bottomFrame); Point? intersectWithLeft = lineCenterToHL.Interset(leftFrame); Vector? distanceCenterToTopIntersect = CalculateDistance(deviceCenter, intersectWithTop); Vector? distanceCenterToRigthIntersect = CalculateDistance(deviceCenter, intersectWithRight); Vector? distanceCenterToBottomIntersect = CalculateDistance(deviceCenter, intersectWithBottom); Vector? distanceCenterToLeftIntersect = CalculateDistance(deviceCenter, intersectWithLeft); Vector? distanceHLToTopIntersect = CalculateDistance(highlightPosition, intersectWithTop); Vector? distanceHLToRightIntersect = CalculateDistance(highlightPosition, intersectWithRight); Vector? distanceHLToBottomIntersect = CalculateDistance(highlightPosition, intersectWithBottom); Vector? distanceHLToLeftIntersect = CalculateDistance(highlightPosition, intersectWithLeft); Point?[] intersects = new Point?[] { intersectWithTop, intersectWithRight, intersectWithBottom, intersectWithLeft }; Vector?[] distancesToCenter = new Vector?[] { distanceCenterToTopIntersect, distanceCenterToRigthIntersect, distanceCenterToBottomIntersect, distanceCenterToLeftIntersect }; Vector?[] distancesToHL = new Vector?[] { distanceHLToTopIntersect, distanceHLToRightIntersect, distanceHLToBottomIntersect, distanceHLToLeftIntersect }; double minDistanceToCenter = distancesToCenter.Min(tmp => tmp.HasValue ? tmp.Value.Length : double.PositiveInfinity); var closestDistanceToCenter = distancesToCenter.Where(tmp => !Equals(tmp.Value.Length, minDistanceToCenter, 1.5d)); foreach (Vector? distance in closestDistanceToCenter) { int tmpIndex = Array.IndexOf(distancesToCenter, distance); distancesToHL[tmpIndex] = null; } double minDistanceToHL = distancesToHL.Min(tmp => tmp.HasValue ? tmp.Value.Length : double.PositiveInfinity); var closestIntersectToHL = distancesToHL.Single(tmp => tmp.HasValue && tmp.Value.Length == minDistanceToHL); int index = Array.IndexOf<Vector?>(distancesToHL, closestIntersectToHL); Point intersect = intersects[index].Value; //Checks whether it's inside Vector directionHighlight = new Vector(highlightPosition.X - deviceCenter.X, highlightPosition.Y - deviceCenter.Y); Vector directionIntersect = new Vector(intersect.X - deviceCenter.X, intersect.Y - deviceCenter.Y); if (directionHighlight.Length < directionIntersect.Length) return new System.Windows.Thickness(-50, -50, 0, 0); //Now we calculate the position of the intersect in relation to the reference point of the fixed layers Point reference = topLeft; Point square = topRight; if (uiAngle == 90) { reference = topRight; square = bottomRight; } else if (uiAngle == 180) { reference = bottomRight; square = bottomLeft; } else if (uiAngle == 270) { reference = bottomLeft; square = topLeft; } //1- find the adjacent and hypotenuse of the triangle Vector adjacent = square - reference; Vector hypotenuse = intersect - reference; double refAngle = Vector.AngleBetween(adjacent, hypotenuse); double markerFixedX = hypotenuse.Length * Math.Cos(refAngle * Math.PI / 180.0); double markerFixedY = hypotenuse.Length * Math.Sin(refAngle * Math.PI / 180.0); if (markerFixedX >= controlWidth - 1) markerFixedX -= sizeOffScreenIcon; if (markerFixedY >= controlHeight - 1) markerFixedY -= sizeOffScreenIcon; return new System.Windows.Thickness(markerFixedX, markerFixedY, 0, 0); }
private void MoveAbsolute(Vector newPosition) { OnRadarUpdate(Game.Avatar.Id, Game.Avatar.Type, newPosition, false); this.lastMovePosition = newPosition; }
private void Update_StoreDirection(Vector lastFramesDir) { Vector3D currentVelocity = _bot.VelocityWorld; if (!Math3D.IsNearZero(currentVelocity)) { Vector currentVelocityFixed = new Vector(currentVelocity.X, -currentVelocity.Y); // Y is backward double angleVel = Math.Abs(Vector.AngleBetween(currentVelocityFixed, lastFramesDir)); if (angleVel > this.DNA.MaxAngle) { // Don't want to start ramming unless it's along the current velocity StopRamming(); return; } } _currentRamDirection = lastFramesDir; double accelMult = GetAccelerationMultiplier(); _bot.DraggingBot.MaxVelocity = _bot.DNAPartial.DraggingMaxVelocity.Value * accelMult; _bot.DraggingBot.Multiplier = _bot.DNAPartial.DraggingMultiplier.Value * accelMult; if (!_isVisualAdded && _viewport != null) { _sparklies = new List<Tuple<GeometryModel3D, AnimateRotation>>(); CreateVisual(); _viewport.Children.Add(_visual); _isVisualAdded = true; } #region CurDirection visual #if SHOWMOUSE _curDirectionLine = new Line() { Stroke = Brushes.Pink, StrokeThickness = 3d, X1 = _pointHistory[0].X, Y1 = _pointHistory[0].Y, X2 = _pointHistory[0].X + (_currentRamDirection.Value.X * 10), Y2 = _pointHistory[0].Y + (_currentRamDirection.Value.Y * 10) }; _canvas.Children.Add(_curDirectionLine); #endif #endregion }
private void StopRamming() { _currentRamDirection = null; _pointHistory.Clear(); _ramDirHistory.Clear(); if (_isVisualAdded) { foreach (var sparkly in _sparklies) { _modelGroup.Children.Remove(sparkly.Item1); } _sparklies.Clear(); if (_viewport != null) { _viewport.Children.Remove(_visual); } _isVisualAdded = false; } _bot.DraggingBot.MaxVelocity = _bot.DNAPartial.DraggingMaxVelocity.Value; _bot.DraggingBot.Multiplier = _bot.DNAPartial.DraggingMultiplier.Value; #if SHOWMOUSE foreach (Line line in _lines.SelectMany(o => o)) { _canvas.Children.Remove(line); } _lines.Clear(); if (_curDirectionLine != null) { _canvas.Children.Remove(_curDirectionLine); _curDirectionLine = null; } #endif }
public void Jump(JumpGate gate) { if (UniversalCoordinates == gate.UniversalCoordinates) gate.Jump(this); else { this.destination = null; this.target = gate; this.targetAction = ((ship, shipTarget) => { gate.Jump(ship); return false; }); } }