public void Update() { UpdateTime(); _Camera3d.Update(gameTime); Engine.CameraPosition = _Camera3d.CameraPos; Engine.View = Camera.viewMatrix; Engine.Projection = Camera.projMatrix; UpdateGizmo(); ray = RayHelpers.ConvertMouseToRay(STATIC_GLOBAL_INPUT.GetMousePos(), GraphicsDevice, Camera.viewMatrix, Camera.projMatrix); }
public Form1() { InitializeComponent(); STATIC_EDITOR_MODE.LevelInstance = new Level(); // manage subscriptions to selected objects propertychange notifications STATIC_EDITOR_MODE.SelectionChanged += OnStaticEditorModeOnSelectionChanged; this.MouseWheel += new MouseEventHandler(this.OnMouseWheel); //initialise input handlers STATIC_GLOBAL_INPUT.InitialiseInputHandlers(editorControl1); PopulateHeirarchy(); InitPivotModes(); InitDrawModes(); STATIC_EDITOR_MODE.SelectionChanged += hierarchyTreeViewSelectionChanged; STATIC_EDITOR_MODE.SelectionChanged += OnStaticEditorModeOnSelectionChanged; }
private void UpdateGizmo() { // update camera properties for rendering and ray-casting. Gizmo.UpdateCameraProperties(Engine.View, Engine.Projection, Engine.CameraPosition); if (this.Focused) { // select entities with your cursor (add the desired keys for add-to / remove-from -selection) if (STATIC_GLOBAL_INPUT.IsNewLeftClick()) { //if (System.Windows.Input.Mouse.LeftButton == MouseButtonState.Pressed) Gizmo.SelectEntities(STATIC_GLOBAL_INPUT.currMouse.Position.ToVector2(), STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.LeftControl), STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.LeftAlt)); SelectionChange?.Invoke(); } // set the active mode like translate or rotate if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.D1)) { Gizmo.ActiveMode = GizmoMode.Translate; Translation_GUI_Update?.Invoke(null, null); } if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.D2)) { Gizmo.ActiveMode = GizmoMode.Rotate; Rotation_GUI_Update?.Invoke(null, null); } if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.D3)) { Gizmo.ActiveMode = GizmoMode.NonUniformScale; ScaleNonUniform_GUI_Update?.Invoke(null, null); } if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.D4)) { Gizmo.ActiveMode = GizmoMode.UniformScale; ScaleUniform_GUI_Update?.Invoke(null, null); } // toggle precision mode if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.LeftShift) || STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.RightShift)) { Gizmo.PrecisionModeEnabled = true; } else { Gizmo.PrecisionModeEnabled = false; } // toggle active space if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.O)) { Gizmo.ToggleActiveSpace(); } // toggle snapping if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.I)) { Gizmo.SnapEnabled = !Gizmo.SnapEnabled; } // select pivot types if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.P)) { Gizmo.NextPivotType(); } // clear selection if (STATIC_GLOBAL_INPUT.currKeys.IsKeyDown(Keys.Escape)) { Gizmo.Clear(); } } Gizmo.Update(gameTime); Engine.Update(); }
private void OnMouseWheel(object sender, MouseEventArgs e) { STATIC_GLOBAL_INPUT.HandleMouseWheel(e); }
private void editorControl1_MouseUp(object sender, MouseEventArgs e) { STATIC_GLOBAL_INPUT.HandleMouseButtons(e, false); }
private void editorControl1_MouseDown(object sender, MouseEventArgs e) { STATIC_GLOBAL_INPUT.HandleMouseButtons(e, true); switch (editorControl1.Gizmo.ActiveMode) { case GizmoMode.Placement: { if (tabControl1.SelectedTab == tabPage1) { // we are on the model page if (e.Button == MouseButtons.Left) { if (listBox_Models.SelectedItem != null) { if (IsValidContentFile(@"Models\" + listBox_Models.SelectedItem, typeof(Model))) { BoundingBox bb = new BoundingBox(); var useTerrain = false; var terrains = STATIC_EDITOR_MODE.LevelInstance.Entities.Where(entity => entity is TerrainEntity).ToList(); if (terrains.Count > 0) { bb = terrains[0].BoundingBox; terrains.Remove(terrains[0]); useTerrain = true; foreach (var terrain in terrains) { bb = BoundingBox.CreateMerged(bb, terrain.BoundingBox); } } terrains = null; var rayHitPos = RayHelpers.GetHitPoint(editorControl1.ray, (useTerrain? bb : Grid3D.BB)); if (rayHitPos != null) { var fileName = listBox_Models.SelectedItem.ToString(); var obj = STATIC_EDITOR_MODE.contentMan.Load <object>(Path.Combine("Models", fileName)); var se = new SceneEntity(obj as Model, fileName) { Position = (Vector3)rayHitPos }; se.LoadAsset(STATIC_EDITOR_MODE.contentMan); Engine.Entities.Add(se); STATIC_EDITOR_MODE.LevelInstance.Entities.Add(se); AddTreeNodeFromSceneEntity(se, hierarchyTreeView); editorControl1.SetSelectionTo(se); } } } else { MessageBox.Show("This is not a Model asset", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else if (tabControl1.SelectedTab == tabPage2) { // we are on the texture page if (listBox_Heights.SelectedItem != null) { if (IsValidContentFile(@"HeightMaps\" + listBox_Heights.SelectedItem, typeof(Texture2D))) { // ?? to a default position var rayHitPos = RayHelpers.GetHitPoint(editorControl1.ray, Grid3D.BB) ?? new Vector3(0, 0, 0); var fileName = listBox_Heights.SelectedItem.ToString(); var obj = STATIC_EDITOR_MODE.contentMan.Load <object>(Path.Combine("HeightMaps", fileName)); var se = new TerrainEntity(obj as Texture2D, fileName) { Position = rayHitPos }; se.LoadAsset(STATIC_EDITOR_MODE.contentMan); //remove all terrains //Engine.Entities.RemoveAll(entity => entity is TerrainEntity); Engine.Entities.Add(se); STATIC_EDITOR_MODE.LevelInstance.Entities.Add(se); //STATIC_EDITOR_MODE.LevelInstance.Terrain = se; // rebuild the tree PopulateHeirarchy(); editorControl1.SetSelectionTo(se); } } } break; } } }
private void editorControl1_MouseMove(object sender, MouseEventArgs e) { STATIC_GLOBAL_INPUT.HandleMouseMove(e); }