Example #1
0
 public override void Initialise()
 {
     camera          = new Camera();
     camera.position = position + eyePosition;
     base.Initialise();
     EntityCollider = BoundingBoxExtensions.FromSize(.6f, 1.8f, 0.6f);
     DoCalculateRay = true;
 }
Example #2
0
 private void UpdateBoundingBox()
 {
     if (cachedPrimitive != null)
     {
         boundingBox = BoundingBoxExtensions.CreateAxisAligned(cachedPrimitive.BoundingBox, AbsoluteTransform);
         if (boundingBoxChanged != null)
         {
             boundingBoxChanged(this, EventArgs.Empty);
         }
     }
 }
Example #3
0
        private void InitializeViewport()
        {
            if (ActualWidth.IsNanOrZero())
            {
                return;
            }

            if (double.IsNaN(Map.Viewport.Resolution)) // only when not set yet
            {
                if (!BoundingBoxExtensions.IsInitialized(_map.Envelope))
                {
                    return;
                }
                if (_map.Envelope.GetCentroid() == null)
                {
                    return;
                }

                if (Math.Abs(_map.Envelope.Width) > Constants.Epsilon)
                {
                    Map.Viewport.Resolution = _map.Envelope.Width / ActualWidth;
                }
                else
                {
                    // An envelope width of zero can happen when there is no data in the Maps' layers (yet).
                    // It should be possible to start with an empty map.
                    Map.Viewport.Resolution = Constants.DefaultResolution;
                }
            }
            if (double.IsNaN(Map.Viewport.Center.X) || double.IsNaN(Map.Viewport.Center.Y)) // only when not set yet
            {
                if (!BoundingBoxExtensions.IsInitialized(_map.Envelope))
                {
                    return;
                }
                if (_map.Envelope.GetCentroid() == null)
                {
                    return;
                }

                Map.Viewport.Center = _map.Envelope.GetCentroid();
            }

            Map.Viewport.Width  = ActualWidth;
            Map.Viewport.Height = ActualHeight;

            Map.Viewport.RenderResolutionMultiplier = 1.0;

            _viewportInitialized = true;

            Map.ViewChanged(true);
        }
Example #4
0
        public Player(ulong id) : base(id, Vector3.Zero)
        {
            base.eyePosition = new Vector3(0, 1.45f, 0);
            _coll            = BoundingBoxExtensions.FromSize(.6f, 1.8f, 0.6f);
            inventory        = new Inventory(9 * 4 + 4 + 1);      //Inventory storage + armor + offhand

            //init inventory
            for (int i = 0; i < inventory.items.Length; i++)
            {
                inventory.items[i].ItemCount = 1;
                inventory.items[i].ItemID    = (ushort)FastMath.FastClamp(i + 1, 0, 7);
            }
        }
Example #5
0
 /// <summary>
 /// Manually call this function to update AABB and Bounding Sphere
 /// </summary>
 public virtual void UpdateBounds()
 {
     if (position == null || position.Count == 0)
     {
         Bound          = new BoundingBox();
         BoundingSphere = new BoundingSphere();
     }
     else
     {
         Bound          = BoundingBoxExtensions.FromPoints(Positions);
         BoundingSphere = BoundingSphereExtensions.FromPoints(Positions);
     }
     if (Bound.Maximum.IsUndefined() || Bound.Minimum.IsUndefined() || BoundingSphere.Center.IsUndefined())
     {
         throw new Exception("Position vertex contains invalid value(Example: Float.NaN).");
     }
 }
 protected override BoundingBox GetMaxBound()
 {
     return(BoundingBoxExtensions.FromPoints(Positions));
 }
Example #7
0
        /// <summary>
        /// Returns a line geometry of the axis-aligned bounding-box of the given mesh.
        /// </summary>
        /// <param name="mesh">Input mesh for the computation of the b-box</param>
        /// <returns></returns>
        public static LineGeometry3D GenerateBoundingBox(Geometry3D mesh)
        {
            var bb = BoundingBoxExtensions.FromPoints(mesh.Positions);

            return(GenerateBoundingBox(bb));
        }
 public EntityItemStack(ItemStack stack, Vector3 position, ulong id) : base(id, position)
 {
     base.Collidable     = false;
     base.EntityCollider = BoundingBoxExtensions.FromSize(0.25f, 0.25f, 0.25f);
 }
Example #9
0
        private static Heightmap CreateHeightmapFromScene(Scene scene, float step)
        {
            var surfaces  = new List <SurfacePatch>();
            var obstacles = new List <ModelMesh>();

            // FIXME:
            //scene.FindAll(surfaces);
            //scene.FindAll(obstacles);

            var bounds = BoundingBoxExtensions.CreateMerged(
                surfaces.Select(patch => patch.BoundingBox).Concat(obstacles.Select(obstacle => obstacle.Model.BoundingBox)));

            var width  = (int)Math.Round((bounds.Max.X - bounds.Min.X) / step) + 1;
            var height = (int)Math.Round((bounds.Max.Y - bounds.Min.Y) / step) + 1;

            var heightmap = new float[width * height];

            /*
             * Parallel.For(0, height, y =>
             * //for (int y = 0; y < height; ++y)
             * {
             *  var rayPicks = new List<FindResult>();
             *
             *  for (int x = 0; x < width; ++x)
             *  {
             *      var pickRay = new Ray();
             *      pickRay.Position.X = bounds.Min.X + x * step;
             *      pickRay.Position.Y = bounds.Min.Y + y * step;
             *      pickRay.Position.Z = bounds.Max.Z;
             *      pickRay.Direction.Z = -1;
             *
             *      lock (SyncRoot)
             *      {
             *          scene.FindAll(ref pickRay, rayPicks);
             *      }
             *
             *      float min = float.MaxValue;
             *      foreach (var pick in rayPicks)
             *      {
             *          if (!(pick.OriginalTarget is SurfacePatch))
             *              continue;
             *
             *          var geometry = pick.OriginalTarget as IGeometry;
             *          if (geometry != null)
             *          {
             *              int i = 0;
             *              lock (SyncRoot)
             *              {
             *                  // Force lazy initialization;
             *                  i += indices.Length;
             *                  i += positions.Length;
             *
             *                  var pickResult = pickRay.Intersects(geometry);
             *                  if (pickResult.HasValue && pickResult.Value < min)
             *                  {
             *                      min = pickResult.Value;
             *                      heightmap[x + y * width] = pickRay.Position.Z - min;
             *                  }
             *              }
             *          }
             *      }
             *      rayPicks.Clear();
             *  }
             * //}
             * });
             */
            return(new Heightmap(heightmap, step, width - 1, height - 1));
        }