public void SimpleAABBTree_TreeRaySingleHitDetection_RunOnEmptyTree() { SimpleAABBTree myTree = new SimpleAABBTree(); Ray aRay = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0)); RayCastHit <Object> myHit = myTree.RaycastReturnFirst <Object>(aRay); Assert.AreEqual(myHit.Count, 0); }
public void SimpleAABBTree_BoundingBoxHitDetection_HitOne_TreeOnlyHasNone() { SimpleAABBTree myTree = new SimpleAABBTree(); BoundingBox myTestBox = new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(2, 2, 2)); RayCastHit <Object> myHit = myTree.BoundingPrimativeCast <Object>(myTestBox); Assert.AreEqual(0, myHit.Count); }
public RayCastHit <T> BoundingPrimativeCast <T>(BoundingBox myTestBox) //TODO: parallel { RayCastHit <T> myRayCast = new RayCastHit <T>(); foreach (var A in myViewedTree) { myRayCast.MergeWith(A.BoundingPrimativeCast <T>(myTestBox)); } return(myRayCast); }
public RayCastHit <T> Raycast <T>(Ray aRay) { RayCastHit <T> myRayCast = new RayCastHit <T>(); foreach (var A in myViewedTree) { myRayCast.MergeWith(A.Raycast <T>(aRay)); } return(myRayCast); }
public void SimpleAABBTree_BoundingBoxHitDetection_HitOne_TreeOnlyHasOne() { SimpleAABBTree myTree = new SimpleAABBTree(); var myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1))); myTree.Insert(myEntity); BoundingBox myTestBox = new BoundingBox(new Vector3(0f, 0f, 0f), new Vector3(2, 2, 2)); RayCastHit <Object> myHit = myTree.BoundingPrimativeCast <Object>(myTestBox); Assert.AreEqual(1, myHit.Count); }
public void SimpleAABBTree_TreeRaySingleHitDetection_OneItemInTree() { SimpleAABBTree myTree = new SimpleAABBTree(); BoundingBox myBox = new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1)); var myEntity = new SimpleAABBTreeStaticOBJ(myBox); myTree.Insert(myEntity); Ray aRay = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0)); RayCastHit <Object> myHit = myTree.RaycastReturnFirst <Object>(aRay); Assert.AreEqual(myHit.Count, 1); }
public RayCastHit <T> RaycastReturnFirst <T>(Ray aRay) { RayCastHit <T> myRayCast = new RayCastHit <T>(); foreach (var A in myViewedTree) { var Result = A.RaycastReturnFirst <T>(aRay); if (Result.Count != 0) { myRayCast = Result; return(myRayCast); } } return(myRayCast); }
public override void Initialize(Microsoft.Xna.Framework.Content.ContentManager Content) { EventManager.Get.SendEvent(new ExplosionEvent()); base.Initialize(Content); CreateFramesFromXML("Chickens_Frames"); CurrentFrame = "bird-boom-00005"; ResetDimensions(); Width = Height = initialRadius;// JabMath.LinearInterpolate(initialRadius, maxRadius, Timer); UniformScale = 1.0f; Colour = new Color(1.0f, 1.0f, 1.0f, 0.0f); int angleIterations = 16; for (int j = 0; j <= angleIterations; j++) { float part = (float)j / (float)angleIterations * 2.0f * (float)Math.PI; Vector2 dir = new Vector2((float)Math.Cos((float)part), (float)Math.Sin((float)part)); dir.Normalize(); RayCastHit hit = World.RayCast(Position, Position + dir * maxRadius); if (hit.actor != null && hit.Distance <= maxRadius && hit.actor.BodyState != JabActor.BodyType.STATIC) { float totalDistProportion = (maxRadius - hit.Distance) / maxRadius; if (hit.actor.UserData is Fox) { Fox f = hit.actor.UserData as Fox; if (f.IsBox) { f.SwitchActiveBody(); f.AnimSprite.Animation = "Roll"; } } hit.actor.AddLinearImpulse(dir * 15 * totalDistProportion, hit.worldImpact); if (hit.actor.UserData is BreakableBody) { (hit.actor.UserData as BreakableBody).TakeHit(totalDistProportion * 2.0f); } } } }
private async Task <(bool success, RayCastHit hit)> PointerDataToRemoteRayCast(IMixedRealityPointer pointer, HitCollectionPolicy hitPolicy = HitCollectionPolicy.ClosestHit) { RayCastHit hit; var result = pointer.Result; if (result != null) { var endPoint = result.Details.Point; var direction = pointer.Rays[pointer.Result.RayStepIndex].Direction; Debug.DrawRay(endPoint, direction, Color.green, 0); hit = (await RemoteRayCaster.RemoteRayCast(endPoint, direction, hitPolicy)).FirstOrDefault(); } else { hit = new RayCastHit(); } return(hit.HitEntity != null, hit); }
void UpdateTrajectory() { if (currentFireDir == LastDir) { return; } LastDir = currentFireDir; trajectorypositions.Clear(); if (currentFireDir.Length() > 0) { JabActor circle = projectileWorld.CreateSphere(75, Position, JabActor.BodyType.DYNAMIC); circle.LinearVelocity = (currentFireDir); Vector2 LastPos = Vector2.Zero; for (int i = 0; i < 200; i++) { if (i > 0 && i % 4 == 0) { RayCastHit hit = screen.withChicks.World.RayCast(LastPos, circle.Position); if (hit.actor != null) { trajectorypositions.Add(hit.worldImpact); break; } } if (circle.PosY < 0) { break; } if (i % 4 == 0) { trajectorypositions.Add(circle.Position); LastPos = circle.Position; } projectileWorld.Update(new GameTime(new TimeSpan(0, 0, 0, 0, 33), new TimeSpan(0, 0, 0, 0, 33))); } circle.RaiseFlag(Jabber.Flags.DELETE); } }
/* * JabActor Other * { * get * { * if (Body == box) * { * return circle; * } * else * { * return box; * } * } * } */ void SetPos() { Vector2 offset = Vector2.Zero; offset.X = (float)Math.Sin((float)Body.Rot); offset.Y = (float)Math.Cos((float)Body.Rot); Vector2 posToUse = offset * 18.0f + Body.Position; float rotToUse = Body.Rot; if (IsBox) { Body.IgnoreRayCast = true; RayCastHit hit = ActorStandingOn; //World.RayCast(Body.Position, new Vector2(0, -Height / 1.8f) + Body.Position); if (hit.actor != null) { rotToUse = (float)Math.Atan2((float)hit.worldNormal.X, (float)hit.worldNormal.Y); offset = hit.worldNormal * 18.0f; posToUse = Body.Position + offset; } Body.IgnoreRayCast = false; PhysicsRotate = false; } else { PhysicsRotate = true; } // Other.Position = posToUse; // Other.Rot = rotToUse; AsType.Position = posToUse; AsType.Rot = rotToUse; }
public void SimpleAABBTree_TreeRaySingleHitDetection_CheckIsOne() { SimpleAABBTree myTree = new SimpleAABBTree(); var myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0, 0, 0), new Vector3(1, 1, 1))); myTree.Insert(myEntity); myEntity = new SimpleAABBTreeStaticOBJ(new BoundingBox(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(2, 2, 2))); myTree.Insert(myEntity); Ray aRay = new Ray(new Vector3(0, 0, 0), new Vector3(0, 1, 0)); RayCastHit <Object> myHit = myTree.RaycastReturnFirst <Object>(aRay); Assert.AreEqual(myHit.Count, 1); aRay = new Ray(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0, 1, 0)); myHit = myTree.RaycastReturnFirst <Object>(aRay); Assert.AreEqual(myHit.Count, 1); aRay = new Ray(new Vector3(0.5f, -1, 0.5f), new Vector3(0, 1, 0)); myHit = myTree.RaycastReturnFirst <Object>(aRay); Assert.AreEqual(myHit.Count, 1); aRay = new Ray(new Vector3(1.5f, 1.5f, 1.5f), new Vector3(0, 1, 0)); myHit = myTree.RaycastReturnFirst <Object>(aRay); Assert.AreEqual(myHit.Count, 1); }
internal void MergeWith(RayCastHit <T> p) { list.AddRange(p); }
public override void Initialize(ContentManager _Content) { base.Initialize(_Content); ResetDimensions(); CreateFramesFromXML("Chickens_Frames"); //Animation = "Fire"; ResetDimensions(); baseBarrel = new Sprite("chickens"); baseBarrel.Initialize(_Content); baseBarrel.CreateFramesFromXML("Chickens_Frames"); baseBarrel.UniformScale = 2.0f; baseBarrel.CurrentFrame = "cannon-base00000"; Animation = "Barrel"; CurrentFrame = "cannon-seq-00000"; baseBarrel.ResetDimensions(); ResetDimensions(); baseBarrel.UniformScale = 2.0f; UniformScale = 2.0f; RayCastHit ah = screen.scene.World.RayCast(Position, new Vector2(0, -500) + Position); if (ah.actor != null) { Vector2 worldPos = ah.worldImpact + new Vector2(0, Height * UniformScale) / 2.7f; Position = worldPos; } Handle = SpriteHandle.CUSTOM; CustomOrigin = new Vector2(Width / 2.0f, Height / 2.0f + 7); FrameChanges += OnFrameChange; smoke = new AnimSprite("chickens"); smoke.Initialize(_Content); smoke.CreateFramesFromXML("Chickens_Frames"); smoke.Animation = "Barrel"; smoke.UniformScale = UniformScale; smoke.Width = Width; smoke.Height = Height; smoke.Handle = SpriteHandle.CENTERLEFT; smoke.RaiseFlag(Jabber.Flags.PASSRENDER); smoke.FrameChanges += OnSmokeFrameChange; trajectory = new AnimSprite("chickens"); trajectory.Initialize(_Content); trajectory.CreateFramesFromXML("Chickens_Frames"); trajectory.CurrentFrame = "feather-00000"; trajectory.ResetDimensions(); trajectory.UniformScale = 6.0f; trajectory.Width = 10; trajectory.Height = 10; trajectory.Handle = SpriteHandle.CENTER; arrow = new AnimSprite("ui/ui"); arrow.Initialize(_Content); arrow.CreateFramesFromXML("ui/ui_frames"); arrow.CurrentFrame = "arrow_dir"; arrow.ResetDimensions(); arrow.UniformScale = 1.0f; arrow.Width = 10; arrow.Height = 10; arrow.Handle = SpriteHandle.CENTER; }
public override void Update(GameTime gameTime) { if (invincibilityTime < maxTime) { invincibilityTime += gttf(gameTime); Body.Awake = true; return; } else { invincibilityTime += gttf(gameTime); } if (screen == null) { for (int i = 0; i < ScreenManager.Get.Screens.Count; i++) { if (ScreenManager.Get.Screens[i] is GameplayScreen) { screen = ScreenManager.Get.Screens[i] as GameplayScreen; } } } if (health > 0) { if (ThingStandingOnIsMoving && IsBox) { // SwitchActiveBody(); } if ((Body.LinearVelocity.Length() + Math.Abs(Body.AngularVelocity) >= 0.5f && IsBox) || (!StandingOnSomething && IsBox)) { SwitchActiveBody(); if (AsType.Animation != "Roll") { AsType.Animation = "Roll"; } } else if ((!IsBox && Body.LinearVelocity.Length() + Math.Abs(Body.AngularVelocity) < 0.5f) && StandingOnSomething && !ThingStandingOnIsMoving) { SwitchActiveBody(); if (AsType.Animation != "Idle" && chicksScene.ActiveChicken == null) { AsType.Animation = "Idle"; } else { Chicken active = chicksScene.ActiveChicken; AsType.Animation = ""; AsType.CurrentFrame = "fox-watch-00010"; } } if (AsType.Animation == "Idle" && CarryingSomething) { AsType.Animation = "Carrying"; } else if (AsType.Animation == "Carrying" && !CarryingSomething) { AsType.Animation = "Idle"; } if ((AsType.Animation == "Idle" || AsType.Animation == "") && chicksScene.ActiveMotion != null) { Chicken active = chicksScene.ActiveMotion; AsType.Animation = ""; Vector2 dirToChicken = active.Position - AsType.Position; dirToChicken.Normalize(); float rotToChicken = (float)Math.Atan2((float)-dirToChicken.X, (float)-dirToChicken.Y); rotToChicken -= 0.5f * (float)Math.PI + AsType.Rot; while (rotToChicken < 0) { rotToChicken += 2 * (float)Math.PI; } while (rotToChicken > 2 * (float)Math.PI) { rotToChicken -= 2 * (float)Math.PI; } rotToChicken /= 2 * (float)Math.PI; int num = (int)(rotToChicken * 11); if (num.ToString().Length == 2) { AsType.CurrentFrame = "fox-watch-000" + num.ToString(); } else { AsType.CurrentFrame = "fox-watch-0000" + num.ToString(); } } else if (AsType.Animation == "") { AsType.Animation = "Idle"; } if (health > 0) { if (PosX > screen.scene.GetRightMaxPos() + 1000 || PosX < screen.scene.startPos.X - 1000 || PosY < -10 || PosY > 10000) { health = -1; } if (!(ScreenManager.Get.TopScreen is PauseScreen) && ScreenManager.Get.TopScreen != screen) { if (AsType.Animation != "Celebrate" && AsType.Animation != "Roll" && AsType.Animation != "Carrying") { AsType.Animation = "Celebrate"; } } else if (AsType.Animation == "Celebrate") { AsType.Animation = "Idle"; } } SetPos(); } else { if (AsType.Animation == "Roll") { SetPos(); if (Body.LinearVelocity.Length() < 0.3f && StandingOnSomething) { if (AsType.Animation != "Die") { AudioQueue.PlayOnce("Sounds/Fox_Death_2" + Jabber.BaseGame.Random.Next(0, 3)); } AsType.Animation = "Die"; } else if (Body.LinearVelocity.Length() < 0.3f || InFan) { deadWhileInRollButStillTimer += gttf(gameTime); if (deadWhileInRollButStillTimer > 1.0f) { if (AsType.Animation != "Die") { AudioQueue.PlayOnce("Sounds/Fox_Death_2" + Jabber.BaseGame.Random.Next(0, 3)); } AsType.Animation = "Die"; } } else { deadWhileInRollButStillTimer = 0.0f; } } else if (AsType.Animation != "Die" && AsType.Animation != "Corpse") { if (AsType.Animation != "Die") { AudioQueue.PlayOnce("Sounds/Fox_Death_2" + Jabber.BaseGame.Random.Next(0, 3)); } AsType.Animation = "Die"; Body.CollisionGroup = FOX_NONE_COLLISION_GROUP; Body.IgnoreRayCast = true; PhysicsPosition = false; PhysicsRotate = false; } else if (AsType.Animation == "Die" || AsType.Animation == "Corpse") { Body.CollisionGroup = FOX_NONE_COLLISION_GROUP; Body.IgnoreRayCast = true; PhysicsPosition = false; PhysicsRotate = false; RayCastHit hit = World.RayCast(AsType.Position, AsType.Position + new Vector2(0, -(AsType.Height / 1.4f))); if (hit.actor != null) { if (true)//AsType.PosY - (hit.worldImpact.Y + AsType.Height / 2.0f) > 0) todo: fix { AsType.PosY = hit.worldImpact.Y + AsType.Height / 2.0f; AsType.Rot = (float)Math.Atan2((float)hit.worldNormal.X, (float)hit.worldNormal.Y); deathFallTimer = 0; } if (AsType.Animation == "Corpse") { alphaOutTimer += gttf(gameTime); } if (alphaOutTimer > 1.0f) { alphaingOut += gttf(gameTime); float val = 1.0f - alphaingOut; if (alphaingOut > 1) { RaiseFlag(Jabber.Flags.DELETE); } else { Colour = new Color(val, val, val, val); } } } else { alphaOutTimer = 0.0f; deathFallTimer += gttf(gameTime); AsType.PosY -= deathFallTimer * 9.8f; } Body.IgnoreRayCast = true; } } base.Update(gameTime); if (InFan) { Body.LinearDamping = 0.0f; } else if (InFanLastFrame) { Body.Friction = 0.5f; Body.AngularDamping = 0.5f; Body.LinearDamping = 0.5f; AsType.Animation = "Roll"; } InFanLastFrame = InFan; InFan = false; if (AsType.Animation == "Roll" || AsType.Animation == "Die" || AsType.Animation == "Corpse") { if (WearHat && invincibilityTime > maxTime * 2.0f) { ThrownHat hat = new ThrownHat(LocationToHat); hat.Initialize(Jabber.BaseGame.Get.Content); hat.Position = Body.Position + ActorStandingOn.worldNormal * 64; hat.Rot = Rot; chicksScene.AddNode(hat); WearHat = false; } } }