コード例 #1
0
ファイル: Bounds.cs プロジェクト: mikecrews/FFWD
 public void Encapsulate(Vector3 point)
 {
     if (box.Contains(point) == ContainmentType.Disjoint)
     {
         box = BoundingBox.CreateFromPoints(new Microsoft.Xna.Framework.Vector3[] { point, box.Min, box.Max });
     }
 }
コード例 #2
0
ファイル: Bounding.cs プロジェクト: BrainSlugs83/MonoGame
        public void BoundingBoxContainsBoundingSphere()
        {
            var testSphere = new BoundingSphere(Vector3.Zero, 1);
            var testBox = new BoundingBox(-Vector3.One, Vector3.One);

            Assert.AreEqual(testBox.Contains(testSphere), ContainmentType.Contains);

            testSphere.Center -= Vector3.One;

            Assert.AreEqual(testBox.Contains(testSphere), ContainmentType.Intersects);

            testSphere.Center -= Vector3.One;

            Assert.AreEqual(testBox.Contains(testSphere), ContainmentType.Disjoint);
        }
コード例 #3
0
        protected void PerformKDRegionSearch(KDNode<TriangleGraph> node, ref BoundingBox region, List<TriangleGraph> triangleCollection)
        {
            if (node != null)
            {
                if (region.Contains(node.element.Centroid) != ContainmentType.Disjoint
                    || region.Contains(node.element.GetVertex0()) != ContainmentType.Disjoint
                    || region.Contains(node.element.GetVertex1()) != ContainmentType.Disjoint
                    || region.Contains(node.element.GetVertex2()) != ContainmentType.Disjoint)
                {
                    triangleCollection.Add(node.element);
                }
                PerformKDRegionSearch(node.leftChild, ref region, triangleCollection);

                PerformKDRegionSearch(node.rightChild, ref region, triangleCollection);
            }
        }
コード例 #4
0
ファイル: Terrain.cs プロジェクト: MattVitelli/Nosferatu
        protected void PerformKDRegionSearch(KDNode<TriangleGraph> node, ref BoundingBox region, List<TriangleGraph> triangleCollection, bool isLandmark)
        {
            if (node != null && (isLandmark || !usedLandmarkTriangles.ContainsKey(node.element.ID)))
            {
                if (region.Contains(node.element.Centroid) != ContainmentType.Disjoint
                    || region.Contains(node.element.GetVertex0()) != ContainmentType.Disjoint
                    || region.Contains(node.element.GetVertex1()) != ContainmentType.Disjoint
                    || region.Contains(node.element.GetVertex2()) != ContainmentType.Disjoint)
                {
                    triangleCollection.Add(node.element);
                }
                PerformKDRegionSearch(node.leftChild, ref region, triangleCollection, isLandmark);

                PerformKDRegionSearch(node.rightChild, ref region, triangleCollection, isLandmark);
            }
        }
コード例 #5
0
ファイル: PursuitEnemy.cs プロジェクト: 11614765/assignment2
        public override void Update(GameTime gametime)
        {
            min = MIN + CurrentPosition;
            max = MAX + CurrentPosition;
            tankBox = new BoundingBox(min, max);
            //float distance = Vector3.Subtract(targetTank.CurrentPosition, this.CurrentPosition).Length();
            //distance > Tank.destinationThreshold &&
            //if (tankBox.Contains(tankBox) == ContainmentType.Disjoint)
            if (tankBox.Contains(targetTank.tankBox) == ContainmentType.Disjoint)
            {

            //if (Mouse.GetState().LeftButton == ButtonState.Pressed && mousepick.GetCollisionPosition().HasValue == true)
            //{
                //pickPosition = mousepick.GetCollisionPosition().Value;
                Point start = Map.WorldToMap(CurrentPosition);

                Point end = Map.WorldToMap(targetTank.CurrentPosition);
                //Point end = Map.WorldToMap(pickPosition);
                if (end.X < 20 && end.X>=0&&end.Y < 20&&end.Y>=0)
                {
                pathfinder = new Pathfinder(map);
                path = pathfinder.FindPath(start, end);
                //pathdebug = path;
                }

            }

            if(path!=null&& moveorder<path.Count)
            {
                distanceTopickPosition = Vector3.Distance(path[moveorder], CurrentPosition);
                if (distanceTopickPosition > desThresholdtoplayer)
                {
                    speed = velocity.Length();
                    currentAngle = (float)Math.Atan2(velocity.Z, velocity.X);
                    moveAngle = currentAngle - initialAngle;
                    rotation = Matrix.CreateRotationY(-moveAngle);
                    //wheelRotationValue = (float)gametime.TotalGameTime.TotalSeconds * 10;
                    //canonRotationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 0.25f) * 0.333f - 0.333f;
                    //hatchRotationValue = MathHelper.Clamp((float)Math.Sin(gametime.TotalGameTime.TotalSeconds * 2) * 2, -1, 0);
                    velocity += steer.seek(path[moveorder], CurrentPosition, velocity) * (float)gametime.ElapsedGameTime.TotalSeconds;
                    CurrentPosition += velocity * (float)gametime.ElapsedGameTime.TotalSeconds;
                    translation = Matrix.CreateTranslation(CurrentPosition);
                }
                else moveorder++;

            }
            else
            {
                moveorder = 0;
                if (path != null) path.Clear();
            }
            //base.Update(gametime);
            //turretRorationValue = (float)Math.Sin(gametime.TotalGameTime.TotalSeconds);
        }
コード例 #6
0
ファイル: Projectile.cs プロジェクト: Brandon-T/XNA-FPS
        public bool isColliding(BoundingBox box)
        {
            for (int I = 0; I < this.model.Meshes.Count; ++I)
            {
                BoundingSphere sphere1 = this.model.Meshes[I].BoundingSphere;
                sphere1 = sphere1.Transform(this.World);

                if (box.Contains(sphere1) == ContainmentType.Intersects)
                    return true;
            }
            return false;
        }
コード例 #7
0
        private static bool ContaiseGeomertry(BoundingBox box, Geomertry geomertry)
        {
            if (geomertry is Triangle)
            {
                Triangle triangle = (Triangle) geomertry;

                Vector3 at = Vector3.Transform(triangle.A, triangle.Transform);
                Vector3 bt = Vector3.Transform(triangle.B, triangle.Transform);
                Vector3 ct = Vector3.Transform(triangle.C, triangle.Transform);

                return box.Contains(at) == ContainmentType.Contains ||
                       box.Contains(bt) == ContainmentType.Contains ||
                       box.Contains(ct) == ContainmentType.Contains;
            }
            else if (geomertry is Sphere)
            {
                Sphere sphere = (Sphere) geomertry;

                Vector3 center = Vector3.Transform(sphere.Center, sphere.Transform);
                float rx = sphere.Radius*sphere.Transform.M11;
                float ry = sphere.Radius*sphere.Transform.M22;
                float rz = sphere.Radius*sphere.Transform.M33;
                float maxR = Math.Max(rx, Math.Max(ry, rz));

                float a = box.Max.X - box.Min.X;
                float b = box.Max.Y - box.Min.Y;
                float c = box.Max.Z - box.Min.Z;

                float halfDiagonal = (float) ((Math.Sqrt(a*a + b*b + c*c))/2.0);
                float distance = Vector3.Distance(center, (box.Max + box.Min)/2.0f);

                return distance <= halfDiagonal + maxR;
            }

            throw new Exception("Unsupported geometry");
        }
コード例 #8
0
        public bool BoundingBoxVisible(BoundingBox bounds)
        {
            if (bounds.Contains(camPos) != ContainmentType.Disjoint)
                return true;
            for (int i = 0; i < 6; i++)
            {
                Vector3 vec;
                vec.X = (planes[i].a >= 0) ? bounds.Max.X : bounds.Min.X;
                vec.Y = (planes[i].b >= 0) ? bounds.Max.Y : bounds.Min.Y;
                vec.Z = (planes[i].c >= 0) ? bounds.Max.Z : bounds.Min.Z;

                if (planes[i].PointBehindPlane(vec))
                    return false;
            }
            return true;
        }
コード例 #9
0
ファイル: Laser.cs プロジェクト: cmsboyd/LPProject
        public bool IsColliding(BoundingBox boundingBox)
        {
            /* If the bounding box '''contains''' either of our end-points, we're definitely colliding */
            if ( boundingBox.Contains(new Vector3(Start, 0f)) == ContainmentType.Contains ||
                 boundingBox.Contains(new Vector3(End, 0f)) == ContainmentType.Contains ) {
                return true;
            }

            float intersection = findIntersection(boundingBox);
            if (intersection > 0 && intersection < Length) {
                return true;
            }

            return false;
        }
コード例 #10
0
ファイル: MapComponent.cs プロジェクト: paulius-m/darkcave
        public void PreUpdate(BoundingBox area)
        {
            area.Contains(waterSource);

            ForeGround[(int)waterSource.X, (int)waterSource.Y].SetType(NodeFactory.Get(NodeTypes.Water));
        }
コード例 #11
0
ファイル: MapComponent.cs プロジェクト: paulius-m/darkcave
        public void PreUpdate(BoundingBox area)
        {
            sun.Clear();
            sky.Clear();
            foreach (var light in lights)
            {
                light.Clear();
            }

            sun.Update(area);
            sky.Update(area);

            foreach (var light in lights)
            {
                if (area.Contains(light.Source.Postion) == ContainmentType.Contains)
                    light.Update(area);
            }

            for (int i1 = (int)area.Min.X; i1 < area.Max.X; i1++)
            {
                for (int i2 = (int) area.Min.Y; i2 < area.Max.Y; i2++)
                {
                    var node = ForeGround[i1, i2];
                    if (node.Type.Opacity != 0)
                        LightField[0][i1, i2] = (node.Incident + node.Emmision) * node.Type.Color + node.Type.Emission;
                    else
                        LightField[0][i1, i2] = (node.Incident + node.Emmision) + node.Type.Emission;
                    LightField[1][i1, i2] = (node.Emmision) * node.Type.Color;
                }
            }
        }
コード例 #12
0
 public bool IsColliding(BoundingBox box)
 {
     //Check if the given box is colliding with any other box
     foreach (BoundingBox b in levelBoxes)
     {
         if (b.Intersects(box) || b.Contains(box) == ContainmentType.Contains || box.Contains(b) == ContainmentType.Contains)
         {
             return true;
         }
     }
     return false;
 }
コード例 #13
0
 public static ContainmentType Contains(ref BoundingBox b1, ref BoundingSphere s1)
 {
     return b1.Contains(s1);
 }
コード例 #14
0
ファイル: MovingGroupsHost.cs プロジェクト: tanis2000/FEZ
    private void TrackGroupConnectivePath(int groupId)
    {
      Vector3 vector3_1 = FezMath.ScreenSpaceMask(this.CameraManager.Viewpoint);
      Vector3 b = FezMath.Abs(FezMath.ForwardVector(this.CameraManager.Viewpoint));
      this.connectedAos.Clear();
      foreach (ArtObjectInstance artObjectInstance in this.LevelMaterializer.LevelArtObjects)
      {
        int? attachedGroup = artObjectInstance.ActorSettings.AttachedGroup;
        int num = groupId;
        if ((attachedGroup.GetValueOrDefault() != num ? 0 : (attachedGroup.HasValue ? 1 : 0)) != 0)
          this.connectedAos.Add(artObjectInstance);
      }
      foreach (ArtObjectInstance artObjectInstance1 in this.connectedAos)
      {
        if (artObjectInstance1.ActorSettings.NextNode.HasValue)
          artObjectInstance1.ActorSettings.NextNodeAo = this.LevelManager.ArtObjects[artObjectInstance1.ActorSettings.NextNode.Value];
        foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
        {
          if (artObjectInstance2.ActorSettings.NextNode.HasValue && artObjectInstance2.ActorSettings.NextNode.Value == artObjectInstance1.Id)
            artObjectInstance1.ActorSettings.PrecedingNodeAo = artObjectInstance2;
        }
      }
      TrileGroup group;
      if (!this.LevelManager.Groups.TryGetValue(groupId, out group))
      {
        Logger.Log("MovingGroupsHost::TrackGroupConnectivePath", LogSeverity.Warning, "Node is connected to a group that doesn't exist!");
      }
      else
      {
        if (group.MoveToEnd)
        {
          ArtObjectInstance artObjectInstance1 = (ArtObjectInstance) null;
          foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
          {
            if (!artObjectInstance2.ActorSettings.NextNode.HasValue && artObjectInstance2.ArtObject.ActorType == ActorType.ConnectiveRail)
            {
              artObjectInstance1 = artObjectInstance2;
              break;
            }
          }
          if (artObjectInstance1 == null)
            throw new InvalidOperationException("No end-node! Can't move to end.");
          Vector3 zero = Vector3.Zero;
          foreach (TrileInstance trileInstance in group.Triles)
            zero += trileInstance.Center;
          Vector3 vector3_2 = zero / (float) group.Triles.Count;
          Vector3 ordering = artObjectInstance1.Position - vector3_2;
          group.Triles.Sort((IComparer<TrileInstance>) new MovingTrileInstanceComparer(ordering));
          foreach (TrileInstance instance in group.Triles)
          {
            instance.Position += ordering;
            this.LevelManager.UpdateInstance(instance);
          }
        }
        BoundingBox boundingBox1 = new BoundingBox(new Vector3(float.MaxValue), new Vector3(float.MinValue));
        Vector3 zero1 = Vector3.Zero;
        foreach (TrileInstance trileInstance in group.Triles)
        {
          Vector3 vector3_2 = trileInstance.TransformedSize / 2f;
          boundingBox1.Min = Vector3.Min(boundingBox1.Min, (trileInstance.Center - vector3_2) * vector3_1);
          boundingBox1.Max = Vector3.Max(boundingBox1.Max, (trileInstance.Center + vector3_2) * vector3_1 + b);
          zero1 += trileInstance.Center;
        }
        Vector3 vector3_3 = zero1 / (float) group.Triles.Count;
        BoundingBox boundingBox2 = new BoundingBox();
        foreach (ArtObjectInstance artObjectInstance in this.connectedAos)
        {
          if (artObjectInstance.ArtObject.ActorType == ActorType.None)
          {
            Vector3 vector3_2 = artObjectInstance.Scale * artObjectInstance.ArtObject.Size / 2f;
            boundingBox2 = new BoundingBox(artObjectInstance.Position - vector3_2, artObjectInstance.Position + vector3_2);
            Quaternion rotation = artObjectInstance.Rotation;
            FezMath.RotateOnCenter(ref boundingBox2, ref rotation);
            boundingBox2.Min *= vector3_1;
            boundingBox2.Max = boundingBox2.Max * vector3_1 + b;
            if (boundingBox1.Intersects(boundingBox2))
              break;
          }
        }
        ArtObjectInstance artObjectInstance3 = (ArtObjectInstance) null;
        foreach (ArtObjectInstance artObjectInstance1 in this.connectedAos)
        {
          if (artObjectInstance1.ArtObject.ActorType == ActorType.ConnectiveRail)
          {
            Vector3 vector3_2 = artObjectInstance1.Scale * artObjectInstance1.ArtObject.Size / 2f;
            BoundingBox box = new BoundingBox((artObjectInstance1.Position - vector3_2) * vector3_1, (artObjectInstance1.Position + vector3_2) * vector3_1 + b);
            if (boundingBox2.Intersects(box))
            {
              artObjectInstance3 = artObjectInstance1;
              break;
            }
          }
        }
        if (artObjectInstance3 == null)
        {
          InvalidOperationException operationException = new InvalidOperationException("Nodeless branch!");
          Logger.Log("Connective Groups", LogSeverity.Warning, operationException.Message);
          throw operationException;
        }
        else
        {
          ArtObjectInstance artObjectInstance1;
          for (; artObjectInstance3.ActorSettings.PrecedingNodeAo != null; artObjectInstance3 = artObjectInstance3.ActorSettings.PrecedingNodeAo)
          {
            Vector3 a = artObjectInstance3.ActorSettings.PrecedingNodeAo.Position - artObjectInstance3.Position;
            if ((double) Math.Abs(FezMath.Dot(a, b)) <= (double) Math.Abs(FezMath.Dot(a, FezMath.XZMask - b)))
            {
              bool flag = false;
              Vector3 point = a / 2f + artObjectInstance3.Position;
              foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
              {
                if (artObjectInstance2.ArtObject.ActorType == ActorType.None)
                {
                  Vector3 vector3_2 = artObjectInstance2.Scale * artObjectInstance2.ArtObject.Size / 2f;
                  BoundingBox boundingBox3 = new BoundingBox(artObjectInstance2.Position - vector3_2, artObjectInstance2.Position + vector3_2);
                  Quaternion rotation = artObjectInstance2.Rotation;
                  FezMath.RotateOnCenter(ref boundingBox3, ref rotation);
                  if (boundingBox3.Contains(point) != ContainmentType.Disjoint)
                  {
                    flag = true;
                    break;
                  }
                }
              }
              if (!flag)
              {
                artObjectInstance1 = artObjectInstance3;
                goto label_72;
              }
            }
          }
          artObjectInstance1 = artObjectInstance3;
label_72:
          Vector3 ordering = artObjectInstance1.Position - vector3_3;
          group.Triles.Sort((IComparer<TrileInstance>) new MovingTrileInstanceComparer(ordering));
          foreach (TrileInstance instance in group.Triles)
          {
            instance.Position += ordering;
            this.LevelManager.UpdateInstance(instance);
          }
          MovementPath movementPath = new MovementPath()
          {
            EndBehavior = PathEndBehavior.Bounce
          };
          ArtObjectInstance artObjectInstance4 = artObjectInstance1;
          PathSegment pathSegment1 = (PathSegment) null;
          while (true)
          {
            ArtObjectInstance nextNodeAo = artObjectInstance4.ActorSettings.NextNodeAo;
            if (nextNodeAo != null)
            {
              Vector3 a = nextNodeAo.Position - artObjectInstance4.Position;
              bool flag1 = (double) Math.Abs(FezMath.Dot(a, b)) > (double) Math.Abs(FezMath.Dot(a, FezMath.XZMask - b));
              bool flag2 = false;
              Vector3 point = a / 2f + artObjectInstance4.Position;
              foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
              {
                if (artObjectInstance2.ArtObject.ActorType == ActorType.None)
                {
                  Vector3 vector3_2 = artObjectInstance2.Scale * artObjectInstance2.ArtObject.Size / 2f;
                  BoundingBox boundingBox3 = new BoundingBox(artObjectInstance2.Position - vector3_2, artObjectInstance2.Position + vector3_2);
                  Quaternion rotation = artObjectInstance2.Rotation;
                  FezMath.RotateOnCenter(ref boundingBox3, ref rotation);
                  if (boundingBox3.Contains(point) != ContainmentType.Disjoint)
                  {
                    flag2 = true;
                    break;
                  }
                }
              }
              if (flag2 || flag1)
              {
                PathSegment pathSegment2 = nextNodeAo.ActorSettings.Segment.Clone();
                pathSegment2.Destination = (pathSegment1 == null ? Vector3.Zero : pathSegment1.Destination) + nextNodeAo.Position - artObjectInstance4.Position;
                if (!flag2)
                  pathSegment2.Duration = TimeSpan.Zero;
                movementPath.Segments.Add(pathSegment2);
                pathSegment1 = pathSegment2;
                artObjectInstance4 = nextNodeAo;
              }
              else
                break;
            }
            else
              break;
          }
          group.Path = movementPath;
          MovingGroupsHost.MovingGroupState movingGroupState = new MovingGroupsHost.MovingGroupState(group, true)
          {
            Enabled = false
          };
          this.trackedGroups.Add(movingGroupState);
          if (group.MoveToEnd)
          {
            group.MoveToEnd = false;
            movingGroupState.MoveToEnd();
          }
          foreach (ArtObjectInstance artObjectInstance2 in this.connectedAos)
            artObjectInstance2.Enabled = true;
        }
      }
    }
コード例 #15
0
ファイル: Util.cs プロジェクト: Shmaug/Voxel-Generator
        public static BoundingBox Intersect(BoundingBox b1, BoundingBox b2)
        {
            if (b1.Contains(b2) == ContainmentType.Contains)
                return b2;
            if (b2.Contains(b1) == ContainmentType.Contains)
                return b1;

            return new BoundingBox(
                new Vector3(
                    Math.Max(b1.Min.X, b2.Min.X),
                    Math.Max(b1.Min.Y, b2.Min.Y),
                    Math.Max(b1.Min.Z, b2.Min.Z)
                    ),
                new Vector3(
                    Math.Min(b1.Max.X, b2.Max.X),
                    Math.Min(b1.Max.Y, b2.Max.Y),
                    Math.Min(b1.Max.Z, b2.Max.Z)
                    ));
        }
コード例 #16
0
 /// <summary>
 /// How many of the triangles corners are inside the bounding box
 /// </summary>
 public int PointsInside(BoundingBox box)
 {
     int count = 0;
     for (int i = 0; i < Vertex.Length; i++)
     {
         if (box.Contains(Vertex[i]) != ContainmentType.Disjoint)
         {
             count++;
         }
     }
     return count;
 }
コード例 #17
0
ファイル: Octree.cs プロジェクト: DelBero/XnaScrap
 public void getElements(BoundingBox bb, ISelectionExecutor executor)
 {
     ContainmentType t = bb.Contains(BoundingBox);
     if (t == ContainmentType.Contains)
     {
         foreach (SceneElement e in m_elements)
         {
             executor.execute(e);
             if (m_children != null)
             {
                 foreach (OctreeNode node in m_children)
                 {
                     node.getElements(bb, executor);
                 }
             }
         }
     }
     else if (t == ContainmentType.Intersects)
     {
         foreach (SceneElement se in m_elements)
         {
             t = bb.Contains(se.BoundingBox);
             if (t == ContainmentType.Contains || t == ContainmentType.Intersects)
             {
                 executor.execute(se);
             }
         }
         if (m_children != null)
         {
             foreach (OctreeNode node in m_children)
             {
                 node.getElements(bb, executor);
             }
         }
     }
     return;
 }
コード例 #18
0
        public static ActionAnimationScript MakeScript(IList<Tile> path, ActorBase actor)
        {
            var scriptBuilder = new ActionAnimationScriptBuilder().Name(actor.ActorId + "Move");
            for (int pathIndex = 1; pathIndex < path.Count; pathIndex++)
            {
                var tile = path[pathIndex];
                float tileYPos = tile.CreateBoundingBox().Max.Y;
                var tilePosition = tile.GetTopCenter();
                BoundingBox centerCheckBox = new BoundingBox(tilePosition - new Vector3(5.0f), tilePosition + new Vector3(5.0f));
                scriptBuilder = scriptBuilder
                    .Segment()
                    .OnStart((sv) =>
                    {
                        Vector3 directionToMove = actor.GetDirectionToPoint(tilePosition);
                        FaceAndMoveToPoint(tilePosition, actor);
                        if (directionToMove.Y > 0.0f)
                        {
                            actor.Velocity.Y *= 2;
                            sv.SetVariable("evalFunc", new Func<Vector3, bool>((v) => v.Y >= tileYPos));
                        }
                        else if (directionToMove.Y <= 0)
                        {
                            Vector3 currentPosition = actor.Position;
                            if (directionToMove.X >= 0.9f)
                            {
                                sv.SetVariable("evalFunc", new Func<Vector3, bool>((v) => v.X >= currentPosition.X + 32f));
                            }
                            else if (directionToMove.X <= -0.9f)
                            {
                                sv.SetVariable("evalFunc", new Func<Vector3, bool>((v) => v.X <= currentPosition.X - 32f));
                            }
                            else if (directionToMove.Z <= -0.9f)
                            {
                                sv.SetVariable("evalFunc", new Func<Vector3, bool>((v) => v.Z <= currentPosition.Z - 32f));
                            }
                            else if (directionToMove.Z >= 0.9f)
                            {
                                sv.SetVariable("evalFunc", new Func<Vector3, bool>((v) => v.Z >= currentPosition.Z + 32f));
                            }
                            actor.Velocity.Y = 0;
                        }
                    })
                    .EndCondition((sv) =>
                    {
                        bool result = sv.GetVariable<Func<Vector3, bool>>("evalFunc")(actor.Position);
                        return result;
                    });

                if (pathIndex == path.Count - 1)
                {
                    var removeFromTileEvent = new ActorEvent(DoomEventType.RemoveFromCurrentTile, actor);
                    scriptBuilder = scriptBuilder
                        .Segment()
                        .OnStart(() =>
                        {
                            if (path.Count == 2) MessagingSystem.DispatchEvent(removeFromTileEvent, actor.ActorId);
                            FaceAndMoveToPoint(tilePosition, actor);
                        })
                        .EndCondition(() =>
                        {
                            return centerCheckBox.Contains(actor.Position) == ContainmentType.Contains;
                        })
                        .OnComplete(() =>
                        {
                            actor.Velocity = Vector3.Zero;
                            actor.SnapToTile(tile);
                            tile.SetActor(actor);
                        });
                }
                else if (pathIndex == 1)
                {
                    var removeFromTileEvent = new ActorEvent(DoomEventType.RemoveFromCurrentTile, actor);
                    scriptBuilder = scriptBuilder
                        .Segment()
                        .OnStart(() =>
                        {
                            MessagingSystem.DispatchEvent(removeFromTileEvent, actor.ActorId);
                            FaceAndMoveToPoint(tilePosition, actor);
                        })
                        .EndCondition(() =>
                        {
                            return centerCheckBox.Contains(actor.Position) == ContainmentType.Contains;
                        });
                }
                else if (pathIndex != path.Count - 1)
                {
                    scriptBuilder = scriptBuilder
                        .Segment()
                        .OnStart(() =>
                        {
                            FaceAndMoveToPoint(tilePosition, actor);
                        })
                        .EndCondition(() =>
                        {
                            return centerCheckBox.Contains(actor.Position) == ContainmentType.Contains;
                        });
                }

            }
            return scriptBuilder.Build();
        }
コード例 #19
0
ファイル: MailboxesHost.cs プロジェクト: Zeludon/FEZ
 public void Update()
 {
   Vector3 position = this.MailboxAo.Position;
   Vector3 center = this.PlayerManager.Center;
   Vector3 b1 = FezMath.SideMask(this.CameraManager.Viewpoint);
   Vector3 b2 = FezMath.ForwardVector(this.CameraManager.Viewpoint);
   Vector3 vector3 = new Vector3(FezMath.Dot(position, b1), position.Y, 0.0f);
   BoundingBox boundingBox = new BoundingBox(vector3 - new Vector3(0.5f, 0.75f, 0.5f), vector3 + new Vector3(0.5f, 0.75f, 0.5f));
   Vector3 point = new Vector3(FezMath.Dot(center, b1), center.Y, 0.0f);
   if ((double) FezMath.Dot(center, b2) >= (double) FezMath.Dot(this.MailboxAo.Position, b2) || boundingBox.Contains(point) == ContainmentType.Disjoint || this.InputManager.GrabThrow != FezButtonState.Pressed)
     return;
   this.GameState.SaveData.ThisLevel.InactiveArtObjects.Add(this.MailboxAo.Id);
   ServiceHelper.AddComponent((IGameComponent) new LetterViewer(ServiceHelper.Game, this.MailboxAo.ActorSettings.TreasureMapName));
   this.GomezService.OnReadMail();
   this.Empty = true;
 }
コード例 #20
0
ファイル: PointsOfInterestHost.cs プロジェクト: tanis2000/FEZ
 public override void Update(GameTime gameTime)
 {
   if (this.GameState.Loading || this.GameState.InMap || (this.PointsList.Length == 0 || this.Dot.PreventPoI) || (this.GameState.Paused || this.GameState.InMenuCube || this.Dot.Owner != null && this.Dot.Owner != this) || (this.GameState.FarawaySettings.InTransition || ActionTypeExtensions.IsEnteringDoor(this.PlayerManager.Action)))
     return;
   Vector3 vector3 = FezMath.DepthMask(this.CameraManager.Viewpoint);
   BoundingBox boundingBox1 = new BoundingBox(this.PlayerManager.Center - new Vector3(6f), this.PlayerManager.Center + new Vector3(6f));
   Volume volume1 = (Volume) null;
   foreach (Volume volume2 in this.PointsList)
   {
     if (volume2.Enabled)
     {
       BoundingBox boundingBox2 = volume2.BoundingBox;
       boundingBox2.Min -= vector3 * 1000f;
       boundingBox2.Max += vector3 * 1000f;
       if (boundingBox1.Contains(boundingBox2) != ContainmentType.Disjoint)
       {
         this.Dot.ComeOut();
         this.Dot.Behaviour = DotHost.BehaviourType.RoamInVolume;
         this.Dot.RoamingVolume = volume1 = volume2;
       }
       if (this.SpeechBubble.Hidden)
       {
         if (this.talkWaiter != null && this.talkWaiter.Alive)
           this.talkWaiter.Cancel();
         if (this.eDotTalk != null && !this.eDotTalk.Dead)
           this.eDotTalk.FadeOutAndPause(0.1f);
       }
       if (!this.SpeechBubble.Hidden && this.PlayerManager.CurrentVolumes.Contains(volume2) && volume2.ActorSettings.DotDialogue.Count > 0 && (this.PlayerManager.Action == ActionType.Suffering || this.PlayerManager.Action == ActionType.SuckedIn || (this.PlayerManager.Action == ActionType.LesserWarp || this.PlayerManager.Action == ActionType.GateWarp)))
       {
         this.SpeechBubble.Hide();
         this.Dot.Behaviour = DotHost.BehaviourType.ReadyToTalk;
         this.InGroup = false;
       }
       if (!this.GameState.InFpsMode && this.PlayerManager.CurrentVolumes.Contains(volume2) && volume2.ActorSettings.DotDialogue.Count > 0)
       {
         if (this.SpeechBubble.Hidden && (this.InputManager.CancelTalk == FezButtonState.Pressed || this.InGroup))
         {
           switch (this.PlayerManager.Action)
           {
             case ActionType.Sliding:
             case ActionType.Landing:
             case ActionType.IdlePlay:
             case ActionType.IdleSleep:
             case ActionType.IdleLookAround:
             case ActionType.IdleYawn:
             case ActionType.Idle:
             case ActionType.Walking:
             case ActionType.Running:
               volume2.ActorSettings.NextLine = (volume2.ActorSettings.NextLine + 1) % volume2.ActorSettings.DotDialogue.Count;
               int index1 = (volume2.ActorSettings.NextLine + 1) % volume2.ActorSettings.DotDialogue.Count;
               this.InGroup = volume2.ActorSettings.DotDialogue[volume2.ActorSettings.NextLine].Grouped && volume2.ActorSettings.DotDialogue[index1].Grouped && index1 != 0;
               volume2.ActorSettings.PreventHey = true;
               string index2 = volume2.ActorSettings.DotDialogue[volume2.ActorSettings.NextLine].ResourceText;
               bool flag;
               if (this.GameState.SaveData.OneTimeTutorials.TryGetValue(index2, out flag) && !flag)
               {
                 this.GameState.SaveData.OneTimeTutorials[index2] = true;
                 this.SyncTutorials();
               }
               if (this.talkWaiter != null && this.talkWaiter.Alive)
                 this.talkWaiter.Cancel();
               string @string = GameText.GetString(index2);
               this.SpeechBubble.ChangeText(@string);
               this.PlayerManager.Action = ActionType.ReadingSign;
               if (this.eDotTalk == null || this.eDotTalk.Dead)
               {
                 this.eDotTalk = SoundEffectExtensions.EmitAt(this.sDotTalk, this.Dot.Position, true);
               }
               else
               {
                 this.eDotTalk.Position = this.Dot.Position;
                 Waiters.Wait(0.100000001490116, (Action) (() =>
                 {
                   this.eDotTalk.Cue.Resume();
                   this.eDotTalk.VolumeFactor = 1f;
                 })).AutoPause = true;
               }
               this.talkWaiter = Waiters.Wait(0.100000001490116 + 0.0750000029802322 * (double) Util.StripPunctuation(@string).Length * (Culture.IsCJK ? 2.0 : 1.0), (Action) (() =>
               {
                 if (this.eDotTalk == null)
                   return;
                 this.eDotTalk.FadeOutAndPause(0.1f);
               }));
               this.talkWaiter.AutoPause = true;
               break;
           }
         }
         if (this.SpeechBubble.Hidden && !volume2.ActorSettings.PreventHey)
         {
           if (this.PlayerManager.Grounded)
           {
             switch (this.PlayerManager.Action)
             {
               case ActionType.Sliding:
               case ActionType.Landing:
               case ActionType.IdlePlay:
               case ActionType.IdleSleep:
               case ActionType.IdleLookAround:
               case ActionType.IdleYawn:
               case ActionType.Idle:
               case ActionType.Walking:
               case ActionType.Running:
                 this.Dot.Behaviour = DotHost.BehaviourType.ThoughtBubble;
                 this.Dot.FaceButton = DotFaceButton.B;
                 if (this.Dot.Owner != this)
                   this.Dot.Hey();
                 this.Dot.Owner = (object) this;
                 break;
               default:
                 this.Dot.Behaviour = DotHost.BehaviourType.ReadyToTalk;
                 break;
             }
           }
         }
         else
           this.Dot.Behaviour = DotHost.BehaviourType.ReadyToTalk;
         if (!this.SpeechBubble.Hidden)
           this.SpeechBubble.Origin = this.Dot.Position;
         if (this.Dot.Behaviour == DotHost.BehaviourType.ReadyToTalk || this.Dot.Behaviour == DotHost.BehaviourType.ThoughtBubble)
           break;
       }
     }
   }
   if (this.Dot.Behaviour != DotHost.BehaviourType.ThoughtBubble && this.Dot.Owner == this && this.SpeechBubble.Hidden)
     this.Dot.Owner = (object) null;
   if (volume1 != null || this.Dot.RoamingVolume == null)
     return;
   this.Dot.Burrow();
 }
コード例 #21
0
        public void OnUpdate()
        {
            Vector3 camPos = view.GetPosition();
            Vector3 halfBox = new Vector3(grassPerPatch, terrain.MaximumHeight*0.5f, grassPerPatch);// new Vector3((float)grassPerPatch / (float)terrain.GetWidth(), 1, (float)grassPerPatch / (float)terrain.GetDepth());
            halfBox *= (float)numVisiblePatches*0.75f;//*terrain.Transformation.GetScale();
            BoundingBox clipBounds = new BoundingBox(camPos-halfBox, camPos+halfBox);

            for (int i = 0; i < patches.Keys.Count; i++)
            {
                int key = patches.Keys[i];
                GrassPatch currPatch = patches[key];
                Vector3[] corners = new Vector3[8];
                currPatch.Bounds.GetCorners(corners);
                currPatch.CanRender = false;
                for (int j = 0; j < corners.Length; j++)
                {
                    if (Vector3.Distance(corners[j], camPos) < GFXShaderConstants.GRASSFALLOFF)
                    {
                        currPatch.CanRender = true;
                        break;
                    }
                }

                if (clipBounds.Contains(currPatch.Bounds) == ContainmentType.Disjoint)
                {
                    patches.Remove(key);
                }
            }

            PlaceGrass();
        }
コード例 #22
0
 public ValveState(ValvesBoltsTimeswitchesHost host, ArtObjectInstance ao)
 {
   ServiceHelper.InjectServices((object) this);
   this.Host = host;
   this.ArtObject = ao;
   this.IsBolt = this.ArtObject.ArtObject.ActorType == ActorType.BoltHandle;
   this.IsTimeswitch = this.ArtObject.ArtObject.ActorType == ActorType.Timeswitch;
   BoundingBox boundingBox = new BoundingBox(this.ArtObject.Position - this.ArtObject.ArtObject.Size / 2f, this.ArtObject.Position + this.ArtObject.ArtObject.Size / 2f);
   if (this.ArtObject.ActorSettings.AttachedGroup.HasValue)
     this.AttachedGroup = this.LevelManager.Groups[this.ArtObject.ActorSettings.AttachedGroup.Value];
   if (this.IsTimeswitch)
   {
     this.eTimeswitchWindBack = SoundEffectExtensions.EmitAt(this.Host.TimeswitchWindBackSound, ao.Position, true, true);
     foreach (ArtObjectInstance artObjectInstance in (IEnumerable<ArtObjectInstance>) this.LevelManager.ArtObjects.Values)
     {
       if (artObjectInstance != ao && artObjectInstance.ArtObject.ActorType == ActorType.TimeswitchMovingPart)
       {
         BoundingBox box = new BoundingBox(artObjectInstance.Position - artObjectInstance.ArtObject.Size / 2f, artObjectInstance.Position + artObjectInstance.ArtObject.Size / 2f);
         if (boundingBox.Intersects(box))
         {
           this.TimeswitchScrewAo = artObjectInstance;
           break;
         }
       }
     }
   }
   int num1;
   if (!this.IsBolt && !this.IsTimeswitch && (this.GameState.SaveData.ThisLevel.PivotRotations.TryGetValue(this.ArtObject.Id, out num1) && num1 != 0))
   {
     int num2 = Math.Abs(num1);
     int num3 = Math.Sign(num1);
     for (int index = 0; index < num2; ++index)
       this.ArtObject.Rotation *= Quaternion.CreateFromAxisAngle(Vector3.UnitY, 1.570796f * (float) num3);
   }
   if (this.IsBolt)
   {
     foreach (TrileInstance instance in this.AttachedGroup.Triles)
       instance.PhysicsState = new InstancePhysicsState(instance);
   }
   foreach (Volume volume in (IEnumerable<Volume>) this.LevelManager.Volumes.Values)
   {
     Vector3 vector3 = FezMath.Abs(volume.To - volume.From);
     if ((double) vector3.X == 3.0 && (double) vector3.Z == 3.0 && ((double) vector3.Y == 1.0 && boundingBox.Contains(volume.BoundingBox) == ContainmentType.Contains))
     {
       this.CenterOffset = (volume.From + volume.To) / 2f - this.ArtObject.Position;
       break;
     }
   }
 }
コード例 #23
0
ファイル: Caco.cs プロジェクト: doomtactics/doomtactics
        private ActionAnimationScript ShootFireballAction(Level level, AbilityDetails abilityDetails, Tile selectedTile)
        {
            // calculate damages
            var damageList = abilityDetails.CalculateDamages(level, selectedTile);

            // animation
            CurrentAnimation = ActorAnimationManager.Make("cacoshoot", ActorId);
            CurrentAnimation.OnComplete = Idle;

            var tilebox = selectedTile.CreateBoundingBox();
            var average = tilebox.Min + (tilebox.Max - tilebox.Min) / 2.0f;
            Vector3 target = new Vector3(average.X, tilebox.Max.Y + Height / 2.0f, average.Z);
            BoundingBox targetBoundingBox = new BoundingBox(target - new Vector3(20, 20, 20), target + new Vector3(20, 20, 20));
            Vector3 source = new Vector3(Position.X, Position.Y + Height / 3.0f, Position.Z);
            var direction = target - source;
            var velocity = Vector3.Normalize(direction) * 5.0f;
            var cacoFireball = ActorSpawnMethods.GetSpawnMethod(ActorType.CacoFireball).Invoke(source, velocity);
            var spawnEvent = new ActorEvent(DoomEventType.SpawnActor, cacoFireball);
            var soundEvent = new SoundEvent(DoomEventType.PlaySound, FireballShootSound);

            var script = new ActionAnimationScriptBuilder().Name(ActorId + "shootFireball")
                .Segment()
                    .OnStart(() =>
                    {
                        FacePoint(selectedTile.GetTopCenter(), false);
                        MessagingSystem.DispatchEvent(spawnEvent, ActorId);
                        MessagingSystem.DispatchEvent(soundEvent, ActorId);
                    })
                    .EndCondition(() => targetBoundingBox.Contains(cacoFireball.Position) == ContainmentType.Contains)
                    .OnComplete(() =>
                    {
                        ApplyAndDisplayDamages(damageList);
                        cacoFireball.Die();
                    })
                .Segment()
                    .EndOnEvent(DoomEventType.AnimationEnd, cacoFireball.ActorId)
                    .OnComplete(() =>
                        MessagingSystem.DispatchEvent(new DespawnActorEvent(DoomEventType.DespawnActor, cacoFireball), ActorId)
                        )
                .Build();

            return script;
        }
コード例 #24
0
ファイル: Collider.cs プロジェクト: Brandon-T/XNA-FPS
        public bool isColliding(BoundingBox box, Camera cam, Vector3 playerDimensions)
        {
            BoundingBox cameraBox = new BoundingBox(
                new Vector3(cam.GetPosition.X - (playerDimensions.X / 2), cam.GetPosition.Y - (playerDimensions.Y), cam.GetPosition.Z - (playerDimensions.Z / 2)),
                new Vector3(cam.GetPosition.X + (playerDimensions.X / 2), cam.GetPosition.Y, cam.GetPosition.Z + (playerDimensions.Z / 2))
            );

            return box.Contains(cameraBox) != ContainmentType.Disjoint;
        }