// </SnippetHitTestingOverviewSnippet10> // <SnippetHitTestingOverviewSnippet11> // Return the result of the hit test to the callback. public HitTestResultBehavior MyHitTestResultCallback(HitTestResult result) { // Retrieve the results of the hit test. IntersectionDetail intersectionDetail = ((GeometryHitTestResult)result).IntersectionDetail; switch (intersectionDetail) { case IntersectionDetail.FullyContains: // Add the hit test result to the list that will be processed after the enumeration. hitResultsList.Add(result.VisualHit); return(HitTestResultBehavior.Continue); case IntersectionDetail.Intersects: // Set the behavior to return visuals at all z-order levels. return(HitTestResultBehavior.Continue); case IntersectionDetail.FullyInside: // Set the behavior to return visuals at all z-order levels. return(HitTestResultBehavior.Continue); default: return(HitTestResultBehavior.Stop); } }
/// <summary> /// 2つのGeometryが一部でも重なっていたらTrueを返す /// </summary> /// <param name="g1"></param> /// <param name="g2"></param> /// <returns></returns> private bool IsOverlapping(Geometry g1, Geometry g2) { IntersectionDetail detail = g1.FillContainsWithDetail(g2); return(detail != IntersectionDetail.Empty); //return (detail != IntersectionDetail.Empty || detail != IntersectionDetail.NotCalculated, detail); }
public HitTestResultBehavior HitTestCallback(HitTestResult result) { // Retrieve the results of the hit test. IntersectionDetail intersectionDetail = ((GeometryHitTestResult)result).IntersectionDetail; switch (intersectionDetail) { case IntersectionDetail.FullyContains: // Add the hit test result to the list: hitList.Add((Rectangle)result.VisualHit); return(HitTestResultBehavior.Continue); case IntersectionDetail.Intersects: // Set the behavior to return visuals at all z-order levels. return(HitTestResultBehavior.Continue); case IntersectionDetail.FullyInside: // Set the behavior to return visuals at all z-order levels. return(HitTestResultBehavior.Continue); default: return(HitTestResultBehavior.Stop); } }
public WpfHitTestResult HitTest(Rect rect, IntersectionDetail detail) { var svgDrawing = this.PerformHitTest(rect, detail); if (svgDrawing == null) { return(WpfHitTestResult.Empty); } string uniqueId = SvgObject.GetUniqueId(svgDrawing); if (string.IsNullOrWhiteSpace(uniqueId)) { return(new WpfHitTestResult(rect, null, svgDrawing)); // return WpfHitTestResult.Empty; } var svgElement = this.GetSvgByUniqueId(uniqueId); if (svgElement == null) { return(new WpfHitTestResult(rect, null, svgDrawing)); // return WpfHitTestResult.Empty; } return(new WpfHitTestResult(rect, svgElement, svgDrawing)); }
//called when data for any output pin is requested public void Evaluate(int SpreadMax) { if (!(FGeometryIn.IsChanged || FGeometryIn2.IsChanged || FTolerance.IsChanged)) { return; } FFullyInside.SliceCount = FFullyContained.SliceCount = FIntersects.SliceCount = SpreadMax; for (int i = 0; i < SpreadMax; i++) { try { IntersectionDetail detail = FGeometryIn[i].FillContainsWithDetail(FGeometryIn2[i], FTolerance[i], ToleranceType.Absolute); FFullyInside[i] = (detail == IntersectionDetail.FullyInside); FFullyContained[i] = (detail == IntersectionDetail.FullyContains); FIntersects[i] = (detail == IntersectionDetail.Intersects); } catch (Exception e) { FFullyInside[i] = false; FFullyContained[i] = false; FIntersects[i] = false; } } }
/// <summary> /// 2つのRectが一部でも重なっていたらtrueを返す /// </summary> /// <param name="r1"></param> /// <param name="r2"></param> /// <returns></returns> private (bool, IntersectionDetail) IsOverlapping(Rect r1, Rect r2) { RectangleGeometry geo1 = new(r1); IntersectionDetail detail = geo1.FillContainsWithDetail(new RectangleGeometry(r2)); return(detail != IntersectionDetail.Empty, detail); //return (detail != IntersectionDetail.Empty || detail != IntersectionDetail.NotCalculated, detail); }
// <SnippetHitTestingOverviewSnippet13> // Override default hit test support in visual object. protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters) { IntersectionDetail intersectionDetail = IntersectionDetail.NotCalculated; // Perform custom actions during the hit test processing. return(new GeometryHitTestResult(this, intersectionDetail)); }
public override int Impact(Tank currentPlayer, Tank[] enemyTankArray) { bounces++; projectile_Finished = false; projectile_Damage = bouncer_BaseDamage * bounces; foreach (Tank tank in enemyTankArray) { IntersectionDetail projectileEnemyIntersection = geometry.FillContainsWithDetail (tank.GetGeometry()); if (projectileEnemyIntersection == IntersectionDetail.Intersects) { game.PlayExplosionSound(); bounces = 0; projectile_Finished = true; currentPlayer.DealDamage(this); return(tank.TakeDamage(this)); } } projectile_Damage = bouncer_BaseDamage; if (bounces >= 3) { game.PlayExplosionSound(); bounces = 0; projectile_Finished = true; return(0); } game.PlaySound(bouncer_SoftHitSoundUri); if (projectile_AngleRadians > Math.PI) { projectile_AngleRadians = Math.PI - (projectile_AngleRadians - Math.PI); } else if (projectile_AngleRadians < 0) { projectile_AngleRadians = Math.Abs(projectile_AngleRadians); } SetAndStartTrajectory( new Point(projectile_TranslateTransform.X, projectile_TranslateTransform.Y - 20), projectile_AngleRadians, projectile_InitialVelocity * 0.9); return(0); }
internal static IntersectionDetail HitTestWithPathGeometry( Geometry geometry1, Geometry geometry2, double tolerance, ToleranceType type) { IntersectionDetail detail = IntersectionDetail.NotCalculated; unsafe { PathGeometryData data1 = geometry1.GetPathGeometryData(); PathGeometryData data2 = geometry2.GetPathGeometryData(); fixed(byte *pbPathData1 = data1.SerializedData) { Debug.Assert(pbPathData1 != (byte *)0); fixed(byte *pbPathData2 = data2.SerializedData) { Debug.Assert(pbPathData2 != (byte *)0); int hr = MilCoreApi.MilUtility_PathGeometryHitTestPathGeometry( &data1.Matrix, data1.FillRule, pbPathData1, data1.Size, &data2.Matrix, data2.FillRule, pbPathData2, data2.Size, tolerance, type == ToleranceType.Relative, &detail); if (hr == (int)MILErrors.WGXERR_BADNUMBER) { // When we encounter NaNs in the renderer, we absorb the error and draw // nothing. To be consistent, we report that the geometry is never hittable. detail = IntersectionDetail.Empty; } else { HRESULT.Check(hr); } } } } Debug.Assert(detail != IntersectionDetail.NotCalculated); return(detail); }
public HitTestResultBehavior MyHitTestResultCallback(HitTestResult result) { // Retrieve the results of the hit test. IntersectionDetail intersectionDetail = ((GeometryHitTestResult)result).IntersectionDetail; ControlOnCanvas controlAdd = null; if (result.VisualHit is Image) { if (((Image)result.VisualHit).TemplatedParent is ControlOnCanvas) { controlAdd = ((Image)result.VisualHit).TemplatedParent as ControlOnCanvas; } } switch (intersectionDetail) { case IntersectionDetail.FullyContains: // Add the hit test result to the list that will be processed after the enumeration. if (controlAdd != null) { hitResultsList.Add(controlAdd); } return(HitTestResultBehavior.Continue); case IntersectionDetail.Intersects: // Set the behavior to return visuals at all z-order levels. if (controlAdd != null) { hitResultsList.Add(controlAdd); } return(HitTestResultBehavior.Continue); case IntersectionDetail.FullyInside: // Set the behavior to return visuals at all z-order levels. if (controlAdd != null) { hitResultsList.Add(controlAdd); } return(HitTestResultBehavior.Continue); default: return(HitTestResultBehavior.Stop); } }
protected HitTestResultBehavior GeometryHitTestResult(HitTestResult result) { IntersectionDetail id = (result as GeometryHitTestResult).IntersectionDetail; if (!AllowIntersectionHits && (id != IntersectionDetail.FullyInside)) { return(HitTestResultBehavior.Continue); } // Insert instead on Add to preserve order of elements from canvas _hitList.Insert(0, result.VisualHit); return(HitTestResultBehavior.Continue); }
private bool HitTestDrawing(GlyphRunDrawing drawing, Geometry geomDisplay, IntersectionDetail detail) { if (drawing != null) { var textBounds = new RectangleGeometry(drawing.Bounds); if (textBounds.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } return(false); }
public bool IntersectsPathSegment(Point startPoint, PathSegment pathSegment, IntersectionDetail intersectionDetail) { return((new PathGeometry() { Figures = { new PathFigure() { StartPoint = startPoint, Segments = { pathSegment } } } }.StrokeContainsWithDetail(GeometryIntersection.stroke, this.geometry) & intersectionDetail) != IntersectionDetail.NotCalculated); }
protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters) { var source = (BitmapSource)Source; var rect = new Int32Rect((int)hitTestParameters.HitGeometry.Bounds.Left, (int)hitTestParameters.HitGeometry.Bounds.Top, (int)hitTestParameters.HitGeometry.Bounds.Width, (int)hitTestParameters.HitGeometry.Bounds.Height); int stride = (int)source.PixelWidth * (source.Format.BitsPerPixel / 8); byte[] pixels = new byte[(int)rect.Height * stride]; source.CopyPixels(rect, pixels, stride, 0); if (!pixels.Contains((byte)0)) { } IntersectionDetail intersectionDetail = IntersectionDetail.NotCalculated; // Perform custom actions during the hit test processing. return(new GeometryHitTestResult(this, intersectionDetail)); }
public override int Impact(Tank currentPlayer, Tank[] enemyTankArray) { game.PlayExplosionSound(); int damage = 0; projectile_Finished = false; projectile_Detonated = true; RemoveFromCanvas(); game.GetGame_MainCanvas().Children.Add( grenade_ExplosionPath); grenade_AnimationIncrement = 0; CompositionTarget.Rendering += AnimationEvent; projectile_Damage = grenade_ExplosionDamage; foreach (Tank tank in enemyTankArray) { IntersectionDetail tankExplosionIntersection = tank.GetGeometry().FillContainsWithDetail( grenade_ExplosionGeometry); if (tankExplosionIntersection == IntersectionDetail.Intersects || tankExplosionIntersection == IntersectionDetail.FullyInside || tankExplosionIntersection == IntersectionDetail.FullyContains) { tank.TakeDamage(this); currentPlayer.DealDamage(this); damage += projectile_Damage; } } projectile_Damage = grenade_ImpactDamage; return(damage); }
private void UpdateEvent(object Sender, EventArgs e) { foreach (Tank tank in game_TankArray) { Point point1 = game_Player.GetTankPosition(); IntersectionDetail innerTankMapIntersection = tank.GetTank_Path(false).Data.FillContainsWithDetail(game_Map.GetMap_Path().Data); IntersectionDetail outerTankMapIntersection = tank.GetTank_Path(true).Data.FillContainsWithDetail(game_Map.GetMap_Path().Data); if (outerTankMapIntersection == IntersectionDetail.Empty) { tank.MoveTankDown(); } if (innerTankMapIntersection == IntersectionDetail.Intersects) { tank.MoveTankUp(); } //game_Player.ChangeAngle(point1); } }
HitTestResultBehavior MyHitTestResultCallback(HitTestResult result) { IntersectionDetail intersectionDetail = ((GeometryHitTestResult)result).IntersectionDetail; switch (intersectionDetail) { case IntersectionDetail.FullyContains: { if (!hitResultsList.Contains(result.VisualHit) && (result.VisualHit as FrameworkElement).DataContext is ISelected) { hitResultsTempList.Add(result.VisualHit); } return(HitTestResultBehavior.Continue); } case IntersectionDetail.Intersects: { if (!hitResultsList.Contains(result.VisualHit) && (result.VisualHit as FrameworkElement).DataContext is ISelected) { hitResultsTempList.Add(result.VisualHit); } return(HitTestResultBehavior.Continue); } case IntersectionDetail.FullyInside: { if (!hitResultsList.Contains(result.VisualHit) && (result.VisualHit as FrameworkElement).DataContext is ISelected) { hitResultsTempList.Add(result.VisualHit); } return(HitTestResultBehavior.Continue); } default: { return(HitTestResultBehavior.Stop); } } }
/// <summary> /// This constructor takes a visual and point respresenting a hit. /// </summary> public GeometryHitTestResult( Visual visualHit, IntersectionDetail intersectionDetail) : base(visualHit) { _intersectionDetail = intersectionDetail; }
protected void BaseUpdateEvent(Tank[] enemyTankArray) { foreach (Tank tank in game_TankArray) { int i = game_Gravity; //Assigns a temporary integer variable the value of gravity //for use as a decrement in the following while loop. bool intersectionFound = false; //Assigns a temporary Boolean variable the value false for //use as an argument in the following while loop. while (i > 0 & !intersectionFound) { tank.MoveDown(); IntersectionDetail tankMapIntersection = tank.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); //Assigns the results from a hitbox test between the //Tank and the Map to a new variable. if (tankMapIntersection == IntersectionDetail.Intersects) { tank.MoveUp(); tank.MoveUp(); intersectionFound = true; //Will stop the while loop if the tank intersects //with the map, stopping gravity from pulling the //tank through the map. tank.SetTank_RotateTransformAngle(game_MapData.angleArray[Convert.ToInt32 (Math.Truncate(tank.GetTank_TranslateTransform().X / game_MapData.angleStep))]); } i--; //Will move the tank down according to the value of //gravity. } if (tank.GetTank_TranslateTransform().X < game_LeftBoundary) { tank.MoveRight(); tank.IncrementFuel(); tank.IncrementFuel(); tank.DecrementDistanceTravelled(); tank.DecrementDistanceTravelled(); //Moves the tank object right if it crosses the left //boundary and corrects the fuel and distance travelled //values. } if (tank.GetPath().ActualWidth + 15 > game_RightBoundary) { tank.MoveLeft(); tank.IncrementFuel(); tank.IncrementFuel(); tank.DecrementDistanceTravelled(); tank.DecrementDistanceTravelled(); //Moves the tank object left if it crosses the right //boundary and corrects the fuel and distance travelled //values. } //This code is done for all Tank objects in the array. } if (game_Projectile.GetProjectile_InMotion()) { if (!game_ProjectileDetonated) { game_Projectile.MoveAlongTrajectory(game_Gravity); } IntersectionDetail projectileMapIntersection = game_Projectile.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); bool enemyHit = false; foreach (Tank tank in enemyTankArray) { IntersectionDetail projectileEnemyIntersection = game_Projectile.GetGeometry().FillContainsWithDetail (tank.GetGeometry()); if (projectileEnemyIntersection == IntersectionDetail.Intersects && !enemyHit) { if (!game_ProjectileDetonated) { game_TurnDamage = game_Projectile.Impact(game_CurrentPlayer, enemyTankArray); } if (game_Projectile.GetProjectile_Finished()) { EndTurn(tank.TakeDamage(game_Projectile) + game_TurnDamage); game_CurrentPlayer.DealDamage(game_Projectile); } else { if (game_Projectile.GetProjectile_Detonated()) { game_ProjectileDetonated = true; } } enemyHit = true; } } if ((projectileMapIntersection == IntersectionDetail.Intersects | projectileMapIntersection == IntersectionDetail.FullyInside) && !enemyHit) { if (!game_ProjectileDetonated) { game_TurnDamage = game_Projectile.Impact(game_CurrentPlayer, enemyTankArray); } if (game_Projectile.GetProjectile_Finished()) { EndTurn(game_TurnDamage); } else { if (game_Projectile.GetProjectile_Detonated()) { game_ProjectileDetonated = true; } } } else if ((game_Projectile.GetProjectile_TranslateTransform().X <game_LeftBoundary | game_Projectile.GetProjectile_TranslateTransform().X> game_RightBoundary) && !enemyHit) { EndTurn(0); } } else if (game_DemoMode) { if (game_NextXLoc > game_CurrentPlayer.GetTank_TranslateTransform().X && game_CurrentPlayer.GetTank_Fuel() != 0) { game_CurrentPlayer.MoveRight(); //Moves the tank right if the game_NextXLoc is to its right. IntersectionDetail tankMapIntersection = game_CurrentPlayer.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); //Assigns the results from a hitbox test between the //Tank and the Map to a new variable. if (tankMapIntersection == IntersectionDetail.Intersects) { game_CurrentPlayer.MoveUp(); game_CurrentPlayer.MoveUp(); game_CurrentPlayer.SetTank_RotateTransformAngle(game_MapData.angleArray[Convert.ToInt32 (Math.Truncate(game_CurrentPlayer.GetTank_TranslateTransform().X / game_MapData.angleStep))]); } } else if (game_NextXLoc < game_CurrentPlayer.GetTank_TranslateTransform().X && game_CurrentPlayer.GetTank_Fuel() != 0) { game_CurrentPlayer.MoveLeft(); //Moves the tank left if the game_NextXLoc is to its left. IntersectionDetail tankMapIntersection = game_CurrentPlayer.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); //Assigns the results from a hitbox test between the //Tank and the Map to a new variable. if (tankMapIntersection == IntersectionDetail.Intersects) { game_CurrentPlayer.MoveUp(); game_CurrentPlayer.MoveUp(); game_CurrentPlayer.SetTank_RotateTransformAngle(game_MapData.angleArray[Convert.ToInt32 (Math.Truncate(game_CurrentPlayer.GetTank_TranslateTransform().X / game_MapData.angleStep))]); } } else { FireProjectileRandom(); //Fires the projectile on a random trajectory. } } else { if (game_CurrentPlayer.GetTank_Fuel() != 0) { if (Keyboard.IsKeyDown(Key.A)) { game_CurrentPlayer.MoveLeft(); //Moves the player's Tank object left if the 'A' key is //pressed down. IntersectionDetail tankMapIntersection = game_CurrentPlayer.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); //Assigns the results from a hitbox test between the //Tank and the Map to a new variable. if (tankMapIntersection == IntersectionDetail.Intersects) { game_CurrentPlayer.MoveUp(); game_CurrentPlayer.MoveUp(); game_CurrentPlayer.SetTank_RotateTransformAngle(game_MapData.angleArray[Convert.ToInt32 (Math.Truncate(game_CurrentPlayer.GetTank_TranslateTransform().X / game_MapData.angleStep))]); } } if (Keyboard.IsKeyDown(Key.D)) { game_CurrentPlayer.MoveRight(); //Moves the player's Tank object right if the 'D' key is //pressed down. IntersectionDetail tankMapIntersection = game_CurrentPlayer.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); //Assigns the results from a hitbox test between the //Tank and the Map to a new variable. if (tankMapIntersection == IntersectionDetail.Intersects) { game_CurrentPlayer.MoveUp(); game_CurrentPlayer.MoveUp(); game_CurrentPlayer.SetTank_RotateTransformAngle(game_MapData.angleArray[Convert.ToInt32 (Math.Truncate(game_CurrentPlayer.GetTank_TranslateTransform().X / game_MapData.angleStep))]); } } } if (game_AimingIcon.BeingDragged()) { game_AimingIcon.DragIconEvent(); } } }
/// <summary> /// AccumulateIntersectionDetail - accepts a new IntersectionDetail which is the result /// of "drawingCommandGeometry.FillContainsWithDetail(hitTestGeometry)" and updates /// the current _intersectionDetail, setting _contains as appropriate. /// </summary> /// <param name="intersectionDetail"> /// The IntersectionDetail from hit-testing the current node. /// </param> private void AccumulateIntersectionDetail(IntersectionDetail intersectionDetail) { // Note that: // * "FullyContains" means that the target node contains the hit test-geometry, // * "FullyInside" means that the target node is fully inside the hit-test geometry // The old result cannot be FullyContain, because that would have // triggered a StopWalk and we wouldn't be here Debug.Assert(_intersectionDetail != IntersectionDetail.FullyContains); // The new result cannot be NotCalculated, because we just // calculated! Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated); // The current _intersectionDetail is computed from its old value and the // new result according the the following table: // \ old + // New \ + NotCalc | Empty | Intersects | FullyInside There // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ is // Empty + Empty | Empty | Intersects | Intersects no // ------------+------------------------------------------------------- Contains // Intersects + Intersects | Intersects | Intersects | Intersects column // ------------+------------------------------------------------------- (see // Contains + Contains | Contains | Contains | Contains assertion // ------------+-------------------------------------------------------- above) // FullyInside + FullInside | Intersects | Intersects | FullyInside if (_intersectionDetail == IntersectionDetail.NotCalculated) // This is the first node { _intersectionDetail = intersectionDetail; // Takes care of the first column. } else if (intersectionDetail == IntersectionDetail.FullyInside // This node is fully inside the hit geometry -- && _intersectionDetail != IntersectionDetail.FullyInside) // -- but we have already encountered a previous node that was not fully inside { _intersectionDetail = IntersectionDetail.Intersects; // Taking care of the second-to-left bottom cell } else if (intersectionDetail == IntersectionDetail.Empty // This node does not touch the hit geometry -- && _intersectionDetail != IntersectionDetail.Empty) // -- but we have already encountered a previous node that was touched { _intersectionDetail = IntersectionDetail.Intersects; // Taking care of the third and fourth cells in the first row } else { // Accept the new result as is _intersectionDetail = intersectionDetail; // Taking care of the second and third row and the diagonal } if (_intersectionDetail == IntersectionDetail.FullyContains) { // The hit geometry is fully contained in the visual, so signal a StopWalk _contains = true; } }
public GeometryHitTestResult(Visual visualHit, IntersectionDetail intersectionDetail) { }
protected void BaseUpdateEvent(Tank[] enemyTankArray) { foreach (Tank tank in game_TankArray) { int i = game_Gravity; //Assigns a temporary integer variable the value of gravity //for use as a decrement in the following while loop. bool intersectionFound = false; //Assigns a temporary Boolean variable the value false for //use as an argument in the following while loop. while (i > 0 & !intersectionFound) { tank.MoveDown(); IntersectionDetail tankMapIntersection = tank.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); //Assigns the results from a hitbox test between the //Tank and the Map to a new variable. if (tankMapIntersection == IntersectionDetail.Intersects) { tank.MoveUp(); intersectionFound = true; //Will stop the while loop if the tank intersects //with the map, stopping gravity from pulling the //tank through the map. } i--; //Will move the tank down according to the value of //gravity. } if (tank.GetTank_TranslateTransform().X < game_LeftBoundary) { tank.MoveRight(); tank.IncrementFuel(); tank.IncrementFuel(); tank.DecrementDistanceTravelled(); tank.DecrementDistanceTravelled(); //Moves the tank object right if it crosses the left //boundary and corrects the fuel and distance travelled //values. } if (tank.GetPath().ActualWidth + 15 > game_RightBoundary) { tank.MoveLeft(); tank.IncrementFuel(); tank.IncrementFuel(); tank.DecrementDistanceTravelled(); tank.DecrementDistanceTravelled(); //Moves the tank object left if it crosses the right //boundary and corrects the fuel and distance travelled //values. } //This code is done for all Tank objects in the array. } if (game_Projectile.GetProjectile_InMotion()) { double i = game_Projectile.GetProjectile_Speed() * game_Projectile.GetXVelocity(); //Assigns a temporary integer variable for use as a decrement //In the following while loop. bool intersectionFound = false; //Assigns a temporary Boolean variable the value false for //use as an argument in the following while loop. while (i > 0 & !intersectionFound) { game_Projectile.MoveAlongTrajectory(game_Gravity); //Moves the Projectile along its trajectory. IntersectionDetail projectileMapIntersection = game_Projectile.GetGeometry().FillContainsWithDetail (game_Map.GetGeometry()); //Assigns the results from a hitbox test between the Projectile //object and the Map object to a variable. foreach (Tank tank in enemyTankArray) { IntersectionDetail projectileEnemyIntersection = game_Projectile.GetGeometry().FillContainsWithDetail (tank.GetGeometry()); //Assigns the results from a hitbox test between the Projectile //object and the tank object to a variable. if (projectileEnemyIntersection == IntersectionDetail.Intersects & !intersectionFound) { game_MediaPlayer.Open(game_ExplosionSoundUri); game_MediaPlayer.Play(); EndTurn(tank.TakeDamage(game_Projectile)); game_CurrentPlayer.DealDamage(game_Projectile); intersectionFound = true; //If the projectile hits the enemy it will deal damage and //stop the while loop. } } if ((projectileMapIntersection == IntersectionDetail.Intersects | projectileMapIntersection == IntersectionDetail.FullyInside) & !intersectionFound) { game_MediaPlayer.Open(game_ExplosionSoundUri); game_MediaPlayer.Play(); EndTurn(0); intersectionFound = true; //If the projectile hits the map it stops the while loop. } else if ((game_Projectile.GetProjectile_TranslateTransform().X <game_LeftBoundary | game_Projectile.GetProjectile_TranslateTransform().X> game_RightBoundary) & !intersectionFound) { EndTurn(0); intersectionFound = true; //If the projectile leaves the map it stops the while loop. } i--; //Decrements the while loop. } } else if (game_DemoMode) { if (game_NextXLoc > game_CurrentPlayer.GetTank_TranslateTransform().X && game_CurrentPlayer.GetTank_Fuel() != 0) { game_CurrentPlayer.MoveRight(); //Moves the tank right if the game_NextXLoc is to its right. } else if (game_NextXLoc < game_CurrentPlayer.GetTank_TranslateTransform().X && game_CurrentPlayer.GetTank_Fuel() != 0) { game_CurrentPlayer.MoveLeft(); //Moves the tank left if the game_NextXLoc is to its left. } else { FireProjectileRandom(); //Fires the projectile on a random trajectory. } } else { if (game_CurrentPlayer.GetTank_Fuel() != 0) { if (Keyboard.IsKeyDown(Key.A)) { game_CurrentPlayer.MoveLeft(); //Moves the player's Tank object left if the 'A' key is //pressed down. } if (Keyboard.IsKeyDown(Key.D)) { game_CurrentPlayer.MoveRight(); //Moves the player's Tank object right if the 'D' key is //pressed down. } } if (game_AimingIcon.BeingDragged()) { game_AimingIcon.DragIconEvent(); } } }
protected override void UpdateEvent(object sender, EventArgs e) { int i = game_Gravity; bool intersectionFound = false; while (i > 0 & !intersectionFound) { mapLoader_AngleMeasurer.MoveDown(); IntersectionDetail angleMeasurerMapIntersection = mapLoader_AngleMeasurer.GetGeometry(). FillContainsWithDetail(game_Map.GetGeometry()); if (angleMeasurerMapIntersection == IntersectionDetail.Intersects) { mapLoader_AngleMeasurer.MoveUp(); mapLoader_AngleMeasurer.MoveUp(); intersectionFound = true; mapLoader_AngleMeasurer.angleMeasurer_Start = true; } i--; } if (game_NewTurn) { mapLoader_CurrentMapIndex++; if (mapLoader_CurrentMapIndex == mapLoader_MapDataList.Count) { mapLoader_CalculatingAngles = false; } else { game_MainCanvas.Children.Remove(game_Map.GetPath()); game_Map = new Map(this, mapLoader_MapDataList[mapLoader_CurrentMapIndex]); mapLoader_AngleMeasurer.ResetPosition(); mapLoader_AngleMeasurer.angleMeasurer_AngleList = new List <double>(); mapLoader_AngleMeasurer.angleMeasurer_Start = false; } game_NewTurn = false; } else { if (mapLoader_AngleMeasurer.angleMeasurer_TranslateTransform.X >= game_RightBoundary) { string mapName = mapLoader_MapDataList[mapLoader_CurrentMapIndex].mapName; Point[] mapPointArray = mapLoader_MapDataList[mapLoader_CurrentMapIndex].pointArray; mapLoader_MapDataList[mapLoader_CurrentMapIndex] = new Framework.MapData(mapName, mapPointArray, mapLoader_Step) { angleArray = mapLoader_AngleMeasurer.angleMeasurer_AngleList.ToArray() }; game_NewTurn = true; } else if (mapLoader_AngleMeasurer.angleMeasurer_Start) { mapLoader_AngleMeasurer.angleMeasurer_PrevY = mapLoader_AngleMeasurer.angleMeasurer_TranslateTransform.Y; for (int s = 0; s < mapLoader_Step; s++) { mapLoader_AngleMeasurer.MoveRight(); int j = game_Gravity; intersectionFound = false; while (j > 0 & !intersectionFound) { mapLoader_AngleMeasurer.MoveDown(); IntersectionDetail angleMeasurerMapIntersection = mapLoader_AngleMeasurer.GetGeometry(). FillContainsWithDetail(game_Map.GetGeometry()); if (angleMeasurerMapIntersection == IntersectionDetail.Intersects) { mapLoader_AngleMeasurer.MoveUp(); mapLoader_AngleMeasurer.MoveUp(); intersectionFound = true; } j--; } } mapLoader_AngleMeasurer.CalculateNextAngle(); } } }
private bool HitTestDrawing(GeometryDrawing drawing, Geometry geomDisplay, IntersectionDetail detail) { Pen pen = drawing.Pen; Brush brush = drawing.Brush; if (pen != null && brush == null) { if (drawing.Geometry.StrokeContainsWithDetail(pen, geomDisplay) == detail) { return(true); } Geometry geometry = drawing.Geometry; LineGeometry line = null; EllipseGeometry ellipse = null; RectangleGeometry rectangle = null; PathGeometry path = null; if (TryCast.Cast(geometry, out path)) { PathFigureCollection pathFigures = path.Figures; int itemCount = pathFigures.Count; if (itemCount == 1) { if (pathFigures[0].IsClosed && path.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } else { for (int f = 0; f < itemCount; f++) { PathFigure pathFigure = pathFigures[f]; if (pathFigure.IsClosed) { PathFigureCollection testFigures = new PathFigureCollection(); testFigures.Add(pathFigure); PathGeometry testPath = new PathGeometry(); testPath.Figures = testFigures; if (testPath.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } } } } else if (TryCast.Cast(geometry, out line)) { if (line.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } else if (TryCast.Cast(geometry, out ellipse)) { if (ellipse.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } else if (TryCast.Cast(geometry, out rectangle)) { if (rectangle.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } } else if (brush != null && drawing.Geometry.FillContainsWithDetail(geomDisplay) == detail) { return(true); } return(false); }
private bool HitTestDrawing(DrawingGroup group, Geometry geomDisplay, out Drawing hitDrawing, IntersectionDetail detail) { hitDrawing = null; var geomBounds = new RectangleGeometry(group.Bounds); if (geomBounds.FillContainsWithDetail(geomDisplay) == detail) { DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; DrawingCollection drawings = group.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, geomDisplay, detail)) { hitDrawing = geometryDrawing; return(true); } } else if (TryCast.Cast(drawing, out groupDrawing)) { SvgObjectType objectType = SvgObject.GetType(groupDrawing); if (objectType == SvgObjectType.Text) { var textBounds = new RectangleGeometry(groupDrawing.Bounds); if (textBounds.FillContainsWithDetail(geomDisplay) == detail) { hitDrawing = groupDrawing; return(true); } } if (HitTestDrawing(groupDrawing, geomDisplay, out hitDrawing, detail)) { return(true); } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, geomDisplay, detail)) { hitDrawing = glyRunDrawing; return(true); } } } return(true); } return(false); }
private Drawing PerformHitTest(Rect rect, IntersectionDetail detail) { if (_svgDrawing == null) { return(null); } var rectDisplay = _displayTransform.TransformBounds(rect); var geomDisplay = new RectangleGeometry(rectDisplay); DrawingGroup groupDrawing = null; GlyphRunDrawing glyRunDrawing = null; GeometryDrawing geometryDrawing = null; Drawing foundDrawing = null; DrawingCollection drawings = _svgDrawing.Children; for (int i = drawings.Count - 1; i >= 0; i--) { Drawing drawing = drawings[i]; if (TryCast.Cast(drawing, out geometryDrawing)) { if (HitTestDrawing(geometryDrawing, geomDisplay, detail)) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } else if (TryCast.Cast(drawing, out groupDrawing)) { if (SvgObject.GetType(groupDrawing) == SvgObjectType.Text) { var textBounds = new RectangleGeometry(groupDrawing.Bounds); if (textBounds.FillContainsWithDetail(geomDisplay) == detail) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } if (HitTestDrawing(groupDrawing, geomDisplay, out foundDrawing, detail)) { string uniqueId = SvgObject.GetUniqueId(drawing); if (!string.IsNullOrWhiteSpace(uniqueId)) { foundDrawing = drawing; break; } } } else if (TryCast.Cast(drawing, out glyRunDrawing)) { if (HitTestDrawing(glyRunDrawing, geomDisplay, detail)) { foundDrawing = drawing; break; } } } return(foundDrawing); }
internal unsafe static extern int MilUtility_PathGeometryHitTestPathGeometry( MilMatrix3x2D *pMatrix1, FillRule fillRule1, byte *pPathData1, UInt32 nSize1, MilMatrix3x2D *pMatrix2, FillRule fillRule2, byte *pPathData2, UInt32 nSize2, double rTolerance, bool fRelative, IntersectionDetail* pDetail);
private void MissileEvent(object sender, EventArgs e) { bool fin = true; foreach (Missile missile in airStrike_MissileArray) { if (missile.GetProjectile_InMotion()) { fin = false; if (!missile.GetProjectile_Detonated()) { missile.MoveAlongTrajectory(game.GetGame_Gravity()); } IntersectionDetail projectileMapIntersection = missile.GetGeometry().FillContainsWithDetail (game.GetGame_Map().GetGeometry()); bool enemyHit = false; foreach (Tank tank in airStrike_EnemyTankArray) { IntersectionDetail projectileEnemyIntersection = missile.GetGeometry().FillContainsWithDetail (tank.GetGeometry()); if (projectileEnemyIntersection == IntersectionDetail.Intersects && !enemyHit) { if (!missile.GetProjectile_Detonated()) { game.PlayExplosionSound(); airStrike_TotalDamage += missile.Impact(airStrike_CurrentPlayer, airStrike_EnemyTankArray); } if (missile.GetProjectile_Finished()) { missile.StopTrajectory(); tank.TakeDamage(missile); airStrike_CurrentPlayer.DealDamage(missile); } enemyHit = true; } } if ((projectileMapIntersection == IntersectionDetail.Intersects | projectileMapIntersection == IntersectionDetail.FullyInside) && !enemyHit) { if (!missile.GetProjectile_Detonated()) { game.PlayExplosionSound(); missile.Impact(airStrike_CurrentPlayer, airStrike_EnemyTankArray); } if (missile.GetProjectile_Finished()) { missile.StopTrajectory(); } } else if ((missile.GetProjectile_TranslateTransform().X < game.GetGame_Boundaries()[0] | missile.GetProjectile_TranslateTransform().X > game.GetGame_Boundaries()[1]) && !enemyHit) { missile.StopTrajectory(); } } } if (fin) { CompositionTarget.Rendering -= MissileEvent; projectile_Finished = true; projectile_Detonated = false; game.EndTurn(airStrike_TotalDamage); airStrike_TotalDamage = 0; } }
/// <summary> /// AccumulateIntersectionDetail - accepts a new IntersectionDetail which is the result /// of "drawingCommandGeometry.FillContainsWithDetail(hitTestGeometry)" and updates /// the current _intersectionDetail, setting _contains as appropriate. /// </summary> /// <param name="intersectionDetail"> /// The IntersectionDetail from hit-testing the current node. /// </param> private void AccumulateIntersectionDetail(IntersectionDetail intersectionDetail) { // Note that: // * "FullyContains" means that the target node contains the hit test-geometry, // * "FullyInside" means that the target node is fully inside the hit-test geometry // The old result cannot be FullyContain, because that would have // triggered a StopWalk and we wouldn't be here Debug.Assert(_intersectionDetail != IntersectionDetail.FullyContains); // The new result cannot be NotCalculated, because we just // calculated! Debug.Assert(intersectionDetail != IntersectionDetail.NotCalculated); // The current _intersectionDetail is computed from its old value and the // new result according the the following table: // \ old + // New \ + NotCalc | Empty | Intersects | FullyInside There // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ is // Empty + Empty | Empty | Intersects | Intersects no // ------------+------------------------------------------------------- Contains // Intersects + Intersects | Intersects | Intersects | Intersects column // ------------+------------------------------------------------------- (see // Contains + Contains | Contains | Contains | Contains assertion // ------------+------------------------------------------------------- above) // FullyInside + FullInside | Intersects | Intersects | FullyInside if (_intersectionDetail == IntersectionDetail.NotCalculated) // This is the first node { _intersectionDetail = intersectionDetail; // Takes care of the first column. } else if (intersectionDetail == IntersectionDetail.FullyInside // This node is fully inside the hit geometry -- && _intersectionDetail != IntersectionDetail.FullyInside) // -- but we have already encountered a previous node that was not fully inside { _intersectionDetail = IntersectionDetail.Intersects; // Taking care of the second-to-left bottom cell } else if (intersectionDetail == IntersectionDetail.Empty // This node does not touch the hit geometry -- && _intersectionDetail != IntersectionDetail.Empty) // -- but we have already encountered a previous node that was touched { _intersectionDetail = IntersectionDetail.Intersects; // Taking care of the third and fourth cells in the first row } else { // Accept the new result as is _intersectionDetail = intersectionDetail; // Taking care of the second and third row and the diagonal } if (_intersectionDetail == IntersectionDetail.FullyContains) { // The hit geometry is fully contained in the visual, so signal a StopWalk _contains = true; } }
private void UpdateEvent(object sender, EventArgs e) { //This is the method that will run every time a new frame is //rendered, and so will be used to update the game. IntersectionDetail playerTankBarrierRightIntersection = game_Player.GetTank_Path().Data.FillContainsWithDetail (game_TankBarrierRight.GetTankBarrier_Path().Data); IntersectionDetail playerTankBarrierLeftIntersection = game_Player.GetTank_Path().Data.FillContainsWithDetail (game_TankBarrierLeft.GetTankBarrier_Path().Data); //Assigns the results from hitbox tests between the Tank object //and TankBarrier objects to variables. if (playerTankBarrierRightIntersection == IntersectionDetail.Intersects) { game_Player.MoveLeft(); //Moves the player's Tank left if it is intersecting with //the TankBarrier object to its right. } if (playerTankBarrierLeftIntersection == IntersectionDetail.Intersects) { game_Player.MoveRight(); //Moves the player's Tank right if it is intersecting with //the TankBarrier object to its left. } foreach (Tank tank in game_TankArray) { int i = game_Gravity; //Assigns a temporary integer variable the value of gravity //for use as a decrement in the following while loop. bool intersectionFound = false; //Assigns a temporary Boolean variable the value false for //use as an argument in the following while loop. while (i > 0 & !intersectionFound) { tank.MoveDown(); IntersectionDetail tankMapIntersection = tank.GetTank_Path().Data.FillContainsWithDetail (game_Map.GetMap_Path().Data); //Assigns the results from a hitbox test between the //Tank and the Map to a new variable. if (tankMapIntersection == IntersectionDetail.Intersects) { tank.MoveUp(); intersectionFound = true; //Will stop the while loop if the tank intersects //with the map, stopping gravity from pulling the //tank through the map. } i--; //Will move the tank down according to the value of //gravity. } //This code is done for all Tank objects in the array. } if (game_CurrentProjectile.GetProjectile_InMotion()) { double i = game_CurrentProjectile.GetProjectile_Speed() * game_CurrentProjectile.GetXVelocity(); //Assigns a temporary integer variable for use as a decrement //In the following while loop. bool intersectionFound = false; //Assigns a temporary Boolean variable the value false for //use as an argument in the following while loop. while (i > 0 & !intersectionFound) { game_CurrentProjectile.MoveAlongTrajectory(game_Gravity); //Moves the Projectile along its trajectory. IntersectionDetail projectileMapIntersection = game_CurrentProjectile.GetProjectile_Path().Data.FillContainsWithDetail (game_Map.GetMap_Path().Data); IntersectionDetail projectileEnemyIntersection = game_CurrentProjectile.GetProjectile_Path().Data.FillContainsWithDetail (game_Enemy.GetTank_Path().Data); //Assigns the results from hitbox tests between the Projectile //object and the Map and Enemy Tank objects to variables. if (projectileEnemyIntersection == IntersectionDetail.Intersects) { EndTurn(game_Enemy.TakeDamage(game_CurrentProjectile)); intersectionFound = true; //If the projectile hits the enemy it will deal damage and //stop the while loop. } else if (projectileMapIntersection == IntersectionDetail.Intersects | projectileMapIntersection == IntersectionDetail.FullyInside) { EndTurn(0); intersectionFound = true; //If the projectile hits the map it stop the while loop. } else if (game_CurrentProjectile.GetProjectile_TranslateTransform().X <game_LeftProjectileLimit | game_CurrentProjectile.GetProjectile_TranslateTransform().X> game_RightProjectileLimit) { EndTurn(0); intersectionFound = true; //If the projectile leaves the map it stop the while loop. } i--; //Decrements the while loop. } } else { if (Keyboard.IsKeyDown(Key.A)) { game_Player.MoveLeft(); //Moves the player's Tank object left if the 'A' key is //pressed down. } if (Keyboard.IsKeyDown(Key.D)) { game_Player.MoveRight(); //Moves the player's Tank object right if the 'D' key is //pressed down. } if (game_AimingIcon.GetAimingIcon_BeingDragged()) { game_AimingIcon.DragIconEvent(); } } }
/// <summary> /// Returns true if a given geometry is contained inside this geometry. /// </summary> /// <param name="geometry">The geometry tested for containment</param> /// <param name="tolerance">Acceptable margin of error in distance computation</param> /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param> public bool FillContains(Geometry geometry, double tolerance, ToleranceType type) { IntersectionDetail detail = FillContainsWithDetail(geometry, tolerance, type); return(detail == IntersectionDetail.FullyContains); }