public MousePositionService(MyGame game, SharpDXHost control, GameSurfaceView surfaceView) { m_game = game; m_control = control; m_surfaceView = surfaceView; //m_control.MouseMove += OnMouseMove; //m_control.MouseLeave += OnMouseLeave; }
public MyGame(MapControl3D mainHost) { //SharpDX.Configuration.EnableObjectTracking = true; this.Camera = new Camera(); this.Camera.LookAt(new Vector3(4, 0, 0), new Vector3(0, 0, 0), Vector3.UnitZ); this.CameraMoveService = new CameraMoveService(this.Camera); base.Updatables.Add(this.CameraMoveService); this.ViewGridAdjusterService = new ViewGridAdjusterService(this, mainHost); base.Updatables.Add(this.ViewGridAdjusterService); this.ViewGridProvider = new ViewGridProvider(this); this.CameraKeyHandler = new CameraKeyHandler(this, mainHost); base.Updatables.Add(this.CameraKeyHandler); m_fpsCounter = new FPSCounter(this); base.Updatables.Add(m_fpsCounter); this.CursorService = new CursorService(this, mainHost); var mainView = new GameSurfaceView(this.GraphicsDevice) { Camera = this.Camera, }; var axesView = new GameSurfaceView(this.GraphicsDevice) { Camera = this.Camera, }; var surface = ToDispose(new GameSurface(this.GraphicsDevice, mainHost)); surface.Views.Add(mainView); surface.Views.Add(axesView); surface.SizeChanged += (w, h) => { var vp = new ViewportF(0, 0, w, h); mainView.ViewPort = vp; mainView.Camera.SetAspect(vp.AspectRatio); axesView.ViewPort = new ViewportF(0, 0, 50, 50); }; base.Surfaces.Add(surface); this.MousePositionService = new MousePositionService(this, mainHost, mainView); base.Updatables.Add(this.MousePositionService); this.SelectionService = new Client.SelectionService(this, mainHost, this.Camera); this.TerrainRenderer = ToDispose(new TerrainRenderer(this, this.Camera, this.ViewGridProvider)); base.Updatables.Add(this.TerrainRenderer); mainView.Drawables.Add(this.TerrainRenderer); m_symbolRenderer = ToDispose(new SymbolRenderer(this, this.ViewGridProvider)); base.Updatables.Add(m_symbolRenderer); mainView.Drawables.Add(m_symbolRenderer); m_selectionRenderer = ToDispose(new SelectionRenderer(this)); base.Updatables.Add(m_selectionRenderer); mainView.Drawables.Add(m_selectionRenderer); m_designationRenderer = ToDispose(new DesignationRenderer(this)); base.Updatables.Add(m_designationRenderer); mainView.Drawables.Add(m_designationRenderer); m_debugAxesRenderer = ToDispose(new DebugAxesRenderer(this)); base.Updatables.Add(m_debugAxesRenderer); axesView.Drawables.Add(m_debugAxesRenderer); #if OUTLINERENDERER m_outlineRenderer = ToDispose(new ChunkOutlineRenderer(this, this.TerrainRenderer.ChunkManager)); base.Updatables.Add(m_outlineRenderer); mainView.Drawables.Add(m_outlineRenderer); #endif #if TESTCUBERENDERER m_testCubeRenderer = ToDispose(new TestCubeRenderer(this)); base.Updatables.Add(m_testCubeRenderer); mainView.Drawables.Add(m_testCubeRenderer); #endif this.RasterizerState = this.GraphicsDevice.RasterizerStates.CullBack; }
public static bool PickVoxel(EnvironmentObject env, GameSurfaceView view, IntVector2 screenPos, IntGrid3 cropGrid, MapControlPickMode pickMode, out IntVector3 pos, out Direction face) { var camera = view.Camera; var ray = Ray.GetPickRay(screenPos.X, screenPos.Y, view.ViewPort, view.Camera.View * view.Camera.Projection); IntVector3 outpos = new IntVector3(); Direction outdir = Direction.None; var corner = cropGrid.Corner2; var size = new IntSize3(corner.X + 1, corner.Y + 1, corner.Z + 1); IntVector3 prevoutpos = new IntVector3(); Direction prevoutdir = Direction.None; VoxelRayCast.RunRayCast(size, ray.Position, ray.Direction, view.Camera.FarZ, (x, y, z, dir) => { var p = new IntVector3(x, y, z); if (cropGrid.Contains(p) == false) return false; var td = env.GetTileData(p); switch (pickMode) { case MapControlPickMode.Underground: if (!td.IsUndefined && !td.IsWall) return false; outpos = p; outdir = dir; return true; case MapControlPickMode.AboveGround: if (!td.IsUndefined && !td.IsWall) { prevoutpos = p; prevoutdir = dir; return false; } if (prevoutpos.IsNull) { outpos = p; outdir = dir; } else { outpos = prevoutpos; outdir = prevoutdir; } return true; case MapControlPickMode.Constant: if (p.Z > cropGrid.Z2) return false; outpos = p; outdir = dir; return true; default: throw new NotImplementedException(); } }); pos = outpos; face = outdir; return face != Direction.None; }
public static bool PickVoxel(EnvironmentObject env, GameSurfaceView view, IntVector2 screenPos, IntGrid3 cropGrid, MapControlPickMode pickMode, out IntVector3 pos, out Direction face) { var camera = view.Camera; var ray = Ray.GetPickRay(screenPos.X, screenPos.Y, view.ViewPort, view.Camera.View * view.Camera.Projection); IntVector3 outpos = new IntVector3(); Direction outdir = Direction.None; var corner = cropGrid.Corner2; var size = new IntSize3(corner.X + 1, corner.Y + 1, corner.Z + 1); IntVector3 prevoutpos = new IntVector3(); Direction prevoutdir = Direction.None; VoxelRayCast.RunRayCast(size, ray.Position, ray.Direction, view.Camera.FarZ, (x, y, z, dir) => { var p = new IntVector3(x, y, z); if (cropGrid.Contains(p) == false) { return(false); } var td = env.GetTileData(p); switch (pickMode) { case MapControlPickMode.Underground: if (!td.IsUndefined && !td.IsWall) { return(false); } outpos = p; outdir = dir; return(true); case MapControlPickMode.AboveGround: if (!td.IsUndefined && !td.IsWall) { prevoutpos = p; prevoutdir = dir; return(false); } if (prevoutpos.IsNull) { outpos = p; outdir = dir; } else { outpos = prevoutpos; outdir = prevoutdir; } return(true); case MapControlPickMode.Constant: if (p.Z > cropGrid.Z2) { return(false); } outpos = p; outdir = dir; return(true); default: throw new NotImplementedException(); } }); pos = outpos; face = outdir; return(face != Direction.None); }