private void UpdateInput() { try { int mouseRelativeX = 0; int mouseRelativeY = 0; int mouseAbsoluteX = 0; int mouseAbsoluteY = 0; int mouseScroll = 0; bool mouseB1 = false; bool mouseB2 = false; bool mouseB3 = false; bool mouseB4 = false; core.Input.GetMouseState(ref mouseRelativeX, ref mouseRelativeY, ref mouseB1, ref mouseB2, ref mouseB3, ref mouseB4, ref mouseScroll); core.Input.GetAbsMouseState(ref mouseAbsoluteX, ref mouseAbsoluteY, ref mouseB1, ref mouseB2, ref mouseB3); core.CollisionResult = core.Scene.MousePick(mouseAbsoluteX, mouseAbsoluteY, (int)CONST_TV_OBJECT_TYPE.TV_OBJECT_MESH); FPSCamera(0, 0, mouseScroll, false); if (mouseB1 && !core.PreviewingScene) { if (selectedTool == Tool.None && core.CollisionResult.IsCollision()) { DeselectAllObjects(); TVMesh colMesh = core.CollisionResult.GetCollisionMesh(); selectedObject = core.GetObjectByUniqueId(colMesh.GetMeshName()); selectedObject.Select(); propertyGrid.SelectedObject = selectedObject; } if (selectedObject != null) { if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFTCONTROL) && !creatingObjectCopy) { creatingObjectCopy = true; selectedObject = CreateObjectCopy(selectedObject); } switch (selectedTool) { case Tool.MoveHorizontal: MoveHorizontal(mouseAbsoluteX, mouseAbsoluteY); break; case Tool.MoveVertical: MoveVertical(mouseAbsoluteX, mouseAbsoluteY); break; } } } else if (core.PreviewingScene) { if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_ESCAPE)) { core.PreviewingScene = false; PrepareObjectsForPreview(false); Thread.Sleep(200); } else if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_F6)) { PreviewReset(); } else { Cursor.Position = oldMousePosition; pnlRenderer.Focus(); core.Engine.ShowWinCursor(false); core.SoundFactory.StartAllSounds(); FPSCamera(mouseRelativeX, mouseRelativeY, mouseScroll, true); } } else if (mouseB2) { Cursor.Position = oldMousePosition; pnlRenderer.Focus(); core.Engine.ShowWinCursor(false); core.SoundFactory.StartAllSounds(); FPSCamera(mouseRelativeX, mouseRelativeY, mouseScroll, true); } else { if (selectedTool != Tool.None) { DeselectAllObjects(); if (core.CollisionResult.IsCollision()) { ChangeMouseCursor(); mousePosition3D = core.Globals.Vector3(0, 0, 0); TVMesh colMesh = core.CollisionResult.GetCollisionMesh(); selectedObject = core.GetObjectByUniqueId(colMesh.GetMeshName()); selectedObject.Select(); propertyGrid.SelectedObject = selectedObject; } else { Cursor = Cursors.Default; } } if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_DELETE)) { RemoveSelectedObject(); } else if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_ESCAPE) || core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_SPACE)) { core.PreviewingScene = false; selectedTool = Tool.None; Cursor = Cursors.Default; DeselectAllObjects(); } else if (!core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFTCONTROL)) { creatingObjectCopy = false; } if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_Q)) { SelectHorizontalTool(); } if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_E)) { SelectVerticalTool(); } if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_C)) { PutObjectOnGround(); } if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_F6)) { StartPreview(); } if (core.Input.IsKeyPressed(CONST_TV_KEY.TV_KEY_F5)) { RunProgram(); } oldMousePosition = Cursor.Position; core.Engine.ShowWinCursor(true); core.SoundFactory.StopAllSounds(); UpdateMenu(); } // Update all objects if not scene preview. if (!core.PreviewingScene) core.AllObjects.ForEach(o => o.Update()); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool SelectObject(ObjectBase obj) { if (obj != null) { var o = core.GetObjectByUniqueId(obj.UniqueId); if (o != null) { DeselectAllObjects(); selectedObject = o; selectedObject.Select(); propertyGrid.SelectedObject = selectedObject; return true; } return false; } return false; }