예제 #1
0
        ActivateToolButton add_tool_button(Cockpit cockpit, string sName,
                                           float fHUDRadius, float dx, float dy,
                                           float fButtonRadius, toolInfo info)
        {
            ActivateToolButton button = new ActivateToolButton()
            {
                TargetScene = cockpit.Scene,
                ToolType    = info.identifier
            };

            button.CreateMeshIconButton(fButtonRadius, info.sMeshPath, defaultMaterial, info.fMeshScaleFudge);
            HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy);
            button.Name = sName;

            if (info.identifier == "cancel")
            {
                button.OnClicked += (s, e) => {
                    bool bIsSpatial = InputState.IsDevice(e.device, InputDevice.AnySpatialDevice);
                    int  nSide      = bIsSpatial ? (int)e.side : 1;
                    cockpit.Context.ToolManager.DeactivateTool((ToolSide)nSide);

                    // remove icon from hand
                    if (bIsSpatial)
                    {
                        cockpit.Context.SpatialController.ClearHandIcon(nSide);
                    }

                    // hide indicator
                    remove_indicator(nSide);
                };
            }
            else
            {
                button.OnClicked += (s, e) => {
                    bool bIsSpatial = InputState.IsDevice(e.device, InputDevice.AnySpatialDevice);
                    int  nSide      = bIsSpatial ? (int)e.side : 1;
                    remove_indicator(nSide);

                    cockpit.Context.ToolManager.SetActiveToolType(info.identifier, (ToolSide)nSide);
                    if (cockpit.Context.ToolManager.ActivateTool((ToolSide)nSide))
                    {
                        if (bIsSpatial)
                        {
                            Mesh iconmesh = Resources.Load <Mesh>(info.sMeshPath);
                            if (iconmesh != null)
                            {
                                cockpit.Context.SpatialController.SetHandIcon(iconmesh, nSide);
                            }
                        }

                        add_indicator(button, nSide);
                    }
                };
            }
            return(button);
        }
예제 #2
0
        override public bool UpdateCapture(InputEvent e)
        {
            if (eState == CaptureState.ClickType && FindHitGO(e.ray) != null)
            {
                return(true);
            }

            // otherwise we fall into drag state
            eState = CaptureState.DragType;

            if (newPrimitive == null)
            {
                newPrimitive = CreatePrimitive();

                fPrimScale = 1.0f;

                if (newPrimitive is PivotSO)
                {
                    fPrimShift = 0.0f;
                }
                else
                {
                    if (newPrimitive is PrimitiveSO)
                    {
                        if (SavedSettings.Restore("DropPrimButton_scale") != null)
                        {
                            fPrimScale = (float)SavedSettings.Restore("DropPrimButton_scale");
                            newPrimitive.SetLocalScale(fPrimScale * Vector3f.One);
                        }
                    }
                    fPrimShift = newPrimitive.GetLocalBoundingBox().Extents[1] * TargetScene.GetSceneScale();
                }

                // [RMS] this is kind of cheating - we are going to tell this SO
                //   it is part of the scene, but not actually put it in the scene.
                //   This is because sometimes the SO needs to query the scene/camera
                //   (eg for pivot resizing)
                TargetScene.ReparentSceneObject(newPrimitive, false);
                newPrimitive.SetScene(TargetScene);

                lastHitF = UnityUtil.GetGameObjectFrame(TargetScene.RootGameObject, CoordSpace.WorldCoords);
                newPrimitive.SetLocalFrame(lastHitF.Translated(fPrimShift, 1), CoordSpace.WorldCoords);
            }

            // [RMS] only Touch for this??
            if (InputState.IsDevice(e.device, InputDevice.OculusTouch) && newPrimitive is PrimitiveSO)
            {
                Vector2f vStick = e.input.StickDelta2D((int)e.side);
                if (vStick[1] != 0)
                {
                    fPrimScale = fPrimScale * (1.0f + vStick[1] * 0.1f);
                    fPrimScale = MathUtil.Clamp(fPrimScale, 0.01f, 10.0f);
                    newPrimitive.SetLocalScale(fPrimScale * Vector3f.One);
                    fPrimShift = newPrimitive.GetLocalBoundingBox().Extents[1] * TargetScene.GetSceneScale();
                }
            }

            AnyRayHit hit = null;

            if (TargetScene.FindSceneRayIntersection(e.ray, out hit))
            {
                update_position(hit);
                newPrimitive.SetLocalFrame(lastHitF.Translated(fPrimShift, 1), CoordSpace.WorldCoords);
            }

            // [RMS] have to do this because prim is not part of scene yet,
            //   and things like pivots need to be resized
            if (newPrimitive != null)
            {
                newPrimitive.PreRender();
            }

            return(true);
        }