public InteractiveSceneManager()
 {
     //Clickables = new Common.Quadtree<Entity>(10);
     Clickables = new Common.BruteForceBoundingVolumeHierarchy<Entity>();
     ClickablesProbe = new WorldViewProbe
     {
         WorldProbe = new Common.BVHProbe<Entity>(Clickables)
     };
 }
 public InteractiveSceneManager()
 {
     //Clickables = new Common.Quadtree<Entity>(10);
     Clickables      = new Common.BruteForceBoundingVolumeHierarchy <Entity>();
     ClickablesProbe = new WorldViewProbe
     {
         WorldProbe = new Common.BVHProbe <Entity>(Clickables)
     };
 }
Ejemplo n.º 3
0
 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;
 }
        public override void Init()
        {
            if (DesignMode)
            {
                return;
            }

            Content.ContentPath = "Data";

            scene      = new Scene();
            scene.View = this;

            scene.Camera = new LookatCartesianCamera()
            {
                Lookat      = Vector3.Zero,
                Position    = new Vector3(-15, 15, 15),
                FOV         = 0.5f,
                ZFar        = 400,
                AspectRatio = AspectRatio
            };

            renderer = new Graphics.Renderer.Renderer(Device9)
            {
                Scene        = scene,
                Settings     = new Graphics.Renderer.Settings(),
                StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9)
            };
            renderer.Initialize(this);
            sceneQuadtree          = new Common.Quadtree <Entity>(10);
            sbau                   = new SceneBVHAutoSyncer(scene, sceneQuadtree);
            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Renderer = renderer,
                Scene    = scene
            };
            sceneRendererConnector.Initialize();

            navMesh = new Common.Pathing.NavMesh();

            worldViewProbe = new Graphics.WorldViewProbe(this, scene.Camera);
            editor         = new Graphics.Editors.BoundingRegionEditor(this, worldViewProbe);
            editor.Region  = navMesh.BoundingRegion;

            editorRenderer = new Graphics.Editors.BoundingRegionEditor.Renderer9(editor)
            {
                StateManager = new Graphics.GraphicsDevice.Device9StateManager(Device9),
                Camera       = scene.Camera
            };
            InputHandler = editor;
            inputHandlers.Add(editor);
            inputHandlers.Add(new WalkaroundCameraInputHandler
            {
                Camera       = (LookatCartesianCamera)scene.Camera,
                InputHandler = new InteractiveSceneManager {
                    Scene = scene
                },
                //FilteredMessages = new MessageType[] { }
            });

            var sim = new Common.Motion.Simulation(navMesh);

            ((Common.Motion.Simulation)sim).SetHeightMap(new float[][] { new float[] { 0.5f } }, new Vector2(400, 400), new Vector2(-200, -200));
            motionSimulation = sim;
            //motionSimulation = new Common.Motion.ThreadSimulationProxy(sim);

            var ground = CreateBlock(new Vector3(-200, -200, -0.5f), new Vector3(400, 400, 1), "Models/GroundTextures/Grass1.png");

            scene.Add(ground);
            motionSimulation.Insert(ground.MotionObject);

            npc = CreateNPC(new Vector2(-2, -2));
            scene.Add(npc);
            motionSimulation.Insert(npc.MotionObject);
            ((Common.IMotion.IUnit)npc.MotionObject).VelocityImpulse(new Vector3(0, 0, 0.1f));
            ((Common.IMotion.INPC)npc.MotionObject).Weight = 10000000f;
            AddCreatedGridEvent(npc);
            //((Common.Motion.NPC)npc.MotionObject).DebugSolidAsARock = true;


            int     amount = 25;
            Vector2 offset = new Vector2(-4, -4);

            for (int i = 0; i < amount; i++)
            {
                int x = i / (int)System.Math.Sqrt(amount);
                int y = i % (int)System.Math.Sqrt(amount);
                var n = CreateNPC(new Vector2(x, y));
                pursuers.Add(n);
                scene.Add(n);
                motionSimulation.Insert(n.MotionObject);
                ((Common.IMotion.IUnit)n.MotionObject).VelocityImpulse(new Vector3(0, 0, 0.1f));
                AddCreatedGridEvent(n);
            }
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
 public override void EditorHeightmapChanged(WorldViewProbe groundProbe)
 {
     Invalidate();
 }