ActivateToolButton add_tool_button(Cockpit cockpit, string sName, float fHUDRadius, float dx, float dy, float fButtonRadius, Material bgMaterial, Material activeMaterial, toolInfo info) { ActivateToolButton button = new ActivateToolButton() { TargetScene = cockpit.Scene, ToolType = info.identifier }; button.CreateMeshIconButton(fButtonRadius, info.sMeshPath, bgMaterial, info.fMeshScaleFudge); HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy); button.Name = sName; if (info.identifier == "cancel") { button.OnClicked += (s, e) => { int nSide = InputState.IsHandedDevice(e.device) ? (int)e.side : 1; cockpit.Context.ToolManager.DeactivateTool((ToolSide)nSide); if (activeButtons[nSide] != null) { activeButtons[nSide].SetBackgroundMaterial(bgMaterial); activeButtons[nSide] = null; } }; } else { button.OnClicked += (s, e) => { int nSide = InputState.IsHandedDevice(e.device) ? (int)e.side : 1; cockpit.Context.ToolManager.SetActiveToolType(info.identifier, (ToolSide)nSide); cockpit.Context.ToolManager.ActivateTool((ToolSide)nSide); if (activeButtons[nSide] != null) { activeButtons[nSide].SetBackgroundMaterial(bgMaterial); } activeButtons[nSide] = button; button.SetBackgroundMaterial(activeMaterial); }; } return(button); }
DropPrimitiveButton add_primitive_button(Cockpit cockpit, string sName, float fHUDRadius, float dx, float dy, PrimitiveType primType, SOType soType, float fPrimRadiusScale, Material bgMaterial, Material primMaterial, Func <SceneObject> CreatePrimitiveF, IGameObjectGenerator customGenerator = null ) { float fButtonRadius = 0.08f; DropPrimitiveButton button = new DropPrimitiveButton() { TargetScene = cockpit.Scene, CreatePrimitive = CreatePrimitiveF }; button.Create(fButtonRadius, bgMaterial); var gen = (customGenerator != null) ? customGenerator : new primitiveIconGenerator() { PrimType = primType, PrimMaterial = primMaterial, PrimSize = fButtonRadius * fPrimRadiusScale }; button.AddVisualElements(gen.Generate(), true); HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy); button.Name = sName; button.OnClicked += (s, e) => { cockpit.Scene.DefaultPrimitiveType = soType; }; button.OnDoubleClicked += (s, e) => { // [TODO] could have a lighter record here because we can easily recreate primitive... cockpit.Scene.History.PushChange( new AddSOChange() { scene = cockpit.Scene, so = CreatePrimitiveF() }); cockpit.Scene.History.PushInteractionCheckpoint(); }; return(button); }
public override Capture BeginCapture(InputState input, CaptureSide eSide) { if (input.LeftCaptureActive || input.RightCaptureActive || popup != null) { DebugUtil.Warning("SceneRightClickBehavior.BeginCapture - we should not be here..."); return(Capture.Ignore); } Ray3f useRay = new Ray3f(Vector3f.Zero, Vector3f.AxisY); if (input.IsForDevice(InputDevice.Mouse) || input.IsForDevice(InputDevice.Gamepad)) { useRay = (input.bRightMousePressed) ? input.vMouseWorldRay : input.vGamepadWorldRay; } else if (input.IsForDevice(InputDevice.AnySpatialDevice)) { useRay = (eSide == CaptureSide.Left) ? input.vLeftSpatialWorldRay : input.vRightSpatialWorldRay; } // raycast into scene to find hit object/position for menu. We try Pivots first, // because they are special and have priority (?? always ??). Then we cast into general scene. SORayHit pivotHit; bool bHitPivot = cockpit.Scene.FindSORayIntersection(useRay, out pivotHit, (x) => { return(x is PivotSO); }); AnyRayHit rayHit; if (bHitPivot) { rayHit = new AnyRayHit(pivotHit); } else { if (cockpit.Scene.FindSceneRayIntersection(useRay, out rayHit) == false) { return(Capture.Ignore); } } // find center of menu in space Vector3f vHUDCenter = cockpit.RootGameObject.GetPosition(); Vector3f menuLocation = rayHit.hitPos; if (Placement == PlacementMode.OnHUDSphere) { float fRayT; bool bHit = RayIntersection.Sphere(useRay.Origin, useRay.Direction, vHUDCenter, HUDRadius, out fRayT); Debug.Assert(bHit); menuLocation = useRay.Origin + fRayT * useRay.Direction; } // compute extents float fDiameter = VRUtil.GetVRRadiusForVisualAngle( menuLocation, cockpit.ActiveCamera.GetPosition(), VisualDiameter); if (rayHit.eType == HitType.SceneObjectHit && rayHit.hitSO is PivotSO) { popup = GeneratePivotRadialMenu(fDiameter, rayHit.hitSO as PivotSO); } else if (rayHit.eType == HitType.SceneObjectHit) { popup = GenerateSceneObjectRadialMenu(fDiameter, rayHit); } else { popup = GenerateDefaultRadialMenu(fDiameter, rayHit); } popup.Create(); popup.Name = "popup_menu"; if (Placement == PlacementMode.InScene) { HUDUtil.PlaceInScene(popup, vHUDCenter, menuLocation); } else { HUDUtil.PlaceInSphere(popup, HUDRadius, vHUDCenter, menuLocation); } // this is a bit of a hack...radial menu lives in-scene, if we attach it to // cockpit then it will move with cockpit, which is wrong. So we want to // stick it in the scene. But, at least for now, we still want it to be // drawn in the cockpit layer, so we add to cockpit first, them remove and // re-add to the scene cockpit.AddUIElement(popup, false); cockpit.RemoveUIElement(popup, false); cockpit.Scene.AddUIElement(popup, false); HUDUtil.AnimatedShow(popup, 0.2f); return(Capture.Begin(this, eSide)); }