public virtual void EditorHeightmapChanged(WorldViewProbe groundProbe)
        {
            var   ray = new Ray(Translation + Vector3.UnitZ * 1000, -Vector3.UnitZ);
            float d;

            if (groundProbe.Intersect(ray, this, out d))
            {
                Translation = ray.Position + ray.Direction * d + Vector3.UnitZ * EditorHeight;
            }
        }
Пример #2
0
        public void InitMap(Client.Game.Map.Map map)
        {
            Scene.Root.ClearChildren();
            if (sceneQuadtreeAutoSyncer != null)
            {
                sceneQuadtreeAutoSyncer.Disconnect();
            }

            Renderer.Settings.WaterLevel = map.Settings.WaterHeight;

            sceneQuadtree           = new Common.Quadtree <Entity>(10);
            sceneQuadtreeAutoSyncer = new SceneBVHAutoSyncer(Scene, sceneQuadtree);

            PlacementBoundings       = new Common.Quadtree <Entity>(10);
            placementBoundingsSyncer = new SceneBVHAutoSyncer(Scene, PlacementBoundings);
            placementBoundingsSyncer.GetLocalBounding =
                (e) => e is Client.Game.Map.GameEntity ? ((Client.Game.Map.GameEntity)e).EditorPlacementLocalBounding : null;
            placementBoundingsSyncer.GetWorldBounding =
                (e) => e is Client.Game.Map.GameEntity ? ((Client.Game.Map.GameEntity)e).EditorPlacementWorldBounding : null;
            placementBoundingsSyncer.RegisterLocalBoundingChangedEvent   = (e, eh) => { };
            placementBoundingsSyncer.UnregisterLocalBoundingChangedEvent = (e, eh) => { };

            Scene.Root.AddChild(map.Ground);
            Scene.Root.AddChild(map.StaticsRoot);
            Scene.Root.AddChild(map.DynamicsRoot);
            Scene.Root.AddChild(new Client.Game.Water(map));
            ((Graphics.LookatSphericalCamera)Scene.Camera).Lookat = map.MainCharacter.Translation;
            //cameraInputHandler.UpdateCamera();

            GroundProbe = new WorldViewProbe(this, Scene.Camera)
            {
                WorldProbe = new Client.Game.GroundProbe(map)
            };

            foreach (var v in Scene.AllEntities)
            {
                var ge = v as Client.Game.Map.GameEntity;
                if (ge != null)
                {
                    var   ray = new Ray(ge.Translation + Vector3.UnitZ * 1000, -Vector3.UnitZ);
                    float d;
                    if (GroundProbe.Intersect(ray, this, out d))
                    {
                        var p = ray.Position + ray.Direction * d;
                        ge.EditorHeight = (ge.Translation - p).Z;
                    }
                }
            }

            StartDefaultMode();
        }
 bool IntersectGround(out Vector3 world)
 {
     return(GroundProbe.Intersect(out world));
 }