示例#1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            var processor = FactoryProcessing.GetFileProcessor(FileProcessing.Abstract.SupportedFile.XYZ);
            var points    = processor.GetPointsFromFile($"Data/{EngineSettings.Instance.PointCloudName}.xyz");

            points = NormalizePoints(points, processor.GetMinPoint());

            #region compute world size
            var min           = Vector3.Zero;
            var max           = processor.GetMaxPoint() - processor.GetMinPoint();
            var centerOfWorld = new Vector3(min.X + (max.X - min.X) * 0.5f,
                                            min.Y + (max.Y - min.Y) * 0.5f,
                                            min.Z + (max.Z - min.Z) * 0.5f);
            var worldSize = new List <float>()
            {
                max.X, max.Y, max.Z
            }.Max();
            #endregion

            #region compute octree
            _octree        = new Octree(centerOfWorld, worldSize);
            _points        = new Dictionary <Color, List <ColoredPoint> >();
            _allRealColors = new List <Color>();
            Parallel.ForEach(points, point =>
            {
                var coloredPoint = new Domain.ColoredPoint(point);
                lock (_locker)
                {
                    if (!_allRealColors.Contains(coloredPoint.CurrentlyUsedColor))
                    {
                        _allRealColors.Add(coloredPoint.CurrentlyUsedColor);
                    }
                    _octree.AddObject(coloredPoint);
                }
            });
            _octree.ComputeLevelOfDetail();
            #endregion

            #region init camera
            _camera = new Camera(GraphicsDevice, _octree);
            _camera.SetPosition(centerOfWorld.X, centerOfWorld.Y + 5f, centerOfWorld.Z, -1.6f, -0.25f);
            _camera.UpdateCamera(0, _isPaused);
            #endregion

            base.Initialize();
        }