private void DisplayButtonPanel() { Vec3 headPosition = Input.Head.position; Vec3 windowPosition = new Vec3(0.4f, 0f, 0.1f); Pose windowPose = new Pose(windowPosition, Quat.LookAt(windowPosition, headPosition)); UI.WindowBegin("Button Panel", ref windowPose, new Vec2(25f, 25f) * Units.cm2m, false); if (UI.Button("Cube")) { whichObject = "cube"; } if (UI.Button("Sphere")) { whichObject = "sphere"; } if (UI.Button("Reset")) { spawnedModels.Clear(); objects.Clear(); spawnedModels.Add(Model.FromMesh( Mesh.GenerateCube(new Vec3(20f, 1f, 20f)), Default.Material )); objects.Add(floor); } if (UI.Button("Exit")) { StereoKitApp.Quit(); } UI.WindowEnd(); }
/// Once you have that information, it's simply a matter of placing a /// window off to the side of the hand! The palm pose Right direction /// points to different sides of each hand, so a different X offset /// is required for each hand. public static void DrawHandMenu(Handed handed) { if (!HandFacingHead(handed)) { return; } // Decide the size and offset of the menu Vec2 size = new Vec2(4, 16); float offset = handed == Handed.Left ? -2 - size.x : 2 + size.x; // Position the menu relative to the side of the hand Hand hand = Input.Hand(handed); Vec3 at = hand[FingerId.Little, JointId.KnuckleMajor].position; Vec3 down = hand[FingerId.Little, JointId.Root].position; Vec3 across = hand[FingerId.Index, JointId.KnuckleMajor].position; Pose menuPose = new Pose( at, Quat.LookAt(at, across, at - down) * Quat.FromAngles(0, handed == Handed.Left ? 90 : -90, 0)); menuPose.position += menuPose.Right * offset * U.cm; menuPose.position += menuPose.Up * (size.y / 2) * U.cm; // And make a menu! UI.WindowBegin("HandMenu", ref menuPose, size * U.cm, UIWin.Empty); UI.Button("Test"); UI.Button("That"); UI.Button("Hand"); UI.WindowEnd(); }
void StepMenuIndicator(Hand hand) { // Scale the indicator based on the 'activation' of the grip motion float dist = Math.Min( Vec3.Distance( hand[FingerId.Little, JointId.Tip].position, hand[FingerId.Ring, JointId.Root].position), Vec3.Distance( hand[FingerId.Middle, JointId.Tip].position, hand[FingerId.Ring, JointId.Root].position)); const float previewDist = 10 * Units.cm2m; activation = minScale + (Math.Max(0, previewDist - dist) / previewDist) * 0.2f; // Show the indicator towards the middle of the fingers that control // the grip motion, the help show the user menuPose.position = (hand[FingerId.Ring, JointId.Tip].position + hand[FingerId.Little, JointId.Root].position + hand[FingerId.Middle, JointId.Root].position) * 0.3333f; menuPose.orientation = Quat.LookAt(menuPose.position, Input.Head.position); menuPose.position += menuPose.Forward * Units.cm2m; // Draw the menu circle! Hierarchy.Push(menuPose.ToMatrix(activation)); Lines.Add(circle); Hierarchy.Pop(); // And if the user grips, show the menu! if (hand.IsJustGripped) { Show(hand[FingerId.Index, JointId.Tip].position); } }
/// <summary>Force the hand menu to show at a specific location. /// This will close the hand menu if it was already open, and resets /// it to the root menu layer. Also plays an opening sound.</summary> /// <param name="at">A world space position for the hand menu.</param> public void Show(Vec3 at) { if (active) { Close(); } Default.SoundClick.Play(at); destPose.position = at; destPose.orientation = Quat.LookAt(menuPose.position, Input.Head.position); activeLayer = 0; active = true; }
// Update is called once per frame void Update() { Move(); Trigger.enabled = !mov; if (transform.position == currentTarget.position) { currentTarget.GetComponent <Player>().Ready = true; transform.rotation = Quat.LookAt(transform, GetOtherTrgt(), -90f); } else { transform.rotation = Quat.LookAt(transform, currentTarget, -90f); } }
/// <summary>Show a file picker to the user! If one is already up, it'll be cancelled out, /// and this one will replace it.</summary> /// <param name="mode">For opening files, or for saving them?</param> /// <param name="initialFolder">The starting folder. By default (or null), this'll just be /// the working directory.</param> /// <param name="onSelectFile">The function to call when the user has selected a file.</param> /// <param name="onCancel">If the file selection has been cancelled, this'll get called!</param> /// <param name="filters">What file types should show up in the picker?</param> public static void Show(FilePickerMode mode, string initialFolder, Action <string> onSelectFile, Action onCancel, params FileFilter[] filters) { if (_inst != null) { _inst._onCancel?.Invoke(); } if (_inst == null) { _inst = StereoKitApp.AddStepper(new FilePicker()); Vec3 pos = Input.Head.position + Input.Head.Forward * .5f + Input.Head.Up * 0.2f; _inst._windowPose = new Pose(pos, Quat.LookAt(pos, Input.Head.position)); } _inst.Setup(mode, initialFolder, onSelectFile, onCancel, filters); }
private void DisplayButtonPanel() { Vec3 headPosition = Input.Head.position; Vec3 windowPosition = new Vec3(0.4f, 0f, 0.1f); Pose windowPose = new Pose(windowPosition, Quat.LookAt(windowPosition, headPosition)); UI.WindowBegin("Button Panel", ref windowPose, new Vec2(20f, 20f) * Units.cm2m, false); if (UI.Button("Start")) { start = true; } if (UI.Button("Exit")) { StereoKitApp.Quit(); } UI.WindowEnd(); }
public void Step() { UI.PushId("RenderCameraWidget"); UI.Handle("from", ref from, new Bounds(Vec3.One * 0.02f), true); UI.HandleBegin("at", ref at, new Bounds(Vec3.One * 0.02f), true); UI.ToggleAt("On", ref _previewing, new Vec3(4, -2, 0) * U.cm, new Vec2(8 * U.cm, UI.LineHeight)); if (_previewing && UI.ToggleAt("Record", ref _recording, new Vec3(4, -6, 0) * U.cm, new Vec2(8 * U.cm, UI.LineHeight))) { _frameTime = Time.ElapsedUnscaledf; _frameIndex = 0; } UI.HandleEnd(); UI.PopId(); float fov = 10 + Math.Max(0, Math.Min(1, (Vec3.Distance(from.position, at.position) - 0.1f) / 0.2f)) * 110; Vec3 previewAt = at.position + at.orientation * Vec3.Up * 0.06f; Vec3 renderFrom = at.position + (at.position - from.position).Normalized * 0.06f; _renderFrom = Pose.Lerp(_renderFrom, new Pose(renderFrom, Quat.LookDir(at.position - from.position)), Time.Elapsedf * damping); Lines.Add(from.position, at.position, Color.White, 0.005f); from.orientation = at.orientation = Quat.LookDir(from.position - at.position); if (_previewing) { Hierarchy.Push(Matrix.TR(previewAt, Quat.LookAt(previewAt, Input.Head.position))); Default.MeshQuad.Draw(_frameMaterial, Matrix.S(V.XYZ(0.08f * ((float)Width / Height), 0.08f, 1))); Text.Add("" + (int)fov, Matrix.TS(-0.03f, 0, 0, 0.5f), TextAlign.CenterLeft); Hierarchy.Pop(); Renderer.RenderTo(_frameSurface, _renderFrom.ToMatrix(), Matrix.Perspective(fov, (float)Width / Height, 0.01f, 100)); } if (_recording) { SaveFrame(FrameRate); } }
public void Update() { /// :CodeSample: Quat Quat.LookAt /// Quat.LookAt and LookDir are probably one of the easiest ways to /// work with quaternions in StereoKit! They're handy functions to /// have a good understanding of. Here's an example of how you might /// use them. // Draw a box that always rotates to face the user Vec3 boxPos = new Vec3(1, 0, 1); Quat boxRot = Quat.LookAt(boxPos, Input.Head.position); Mesh.Cube.Draw(Material.Default, Matrix.TR(boxPos, boxRot)); // Make a Window that faces a user that enters the app looking // Forward. Pose winPose = new Pose(0, 0, -0.5f, Quat.LookDir(0, 0, 1)); UI.WindowBegin("Posed Window", ref winPose); UI.WindowEnd(); /// :End: }
void StepMenuIndicator(Hand hand) { // Scale the indicator based on the 'activation' of the grip motion activation = Math.Max(0.02f, hand.gripActivation * 0.2f); // Show the indicator towards the middle of the fingers that control // the grip motion, the help show the user menuPose.position = (hand[FingerId.Ring, JointId.Tip].position + hand[FingerId.Ring, JointId.Root].position) * 0.5f; menuPose.orientation = Quat.LookAt(menuPose.position, Input.Head.position); menuPose.position += menuPose.Forward * U.cm; // Draw the menu circle! Hierarchy.Push(menuPose.ToMatrix(activation)); Lines.Add(circle); Hierarchy.Pop(); // And if the user grips, show the menu! if (hand.IsJustGripped) { Show(hand[FingerId.Index, JointId.Tip].position); } }
/// :CodeSample: Controller Input.Controller TrackState Input.ControllerMenuButton Controller.IsTracked Controller.trackedPos Controller.trackedRot Controller.IsX1Pressed Controller.IsX2Pressed Controller.IsStickClicked Controller.stick Controller.aim Controller.grip Controller.trigger Controller.pose /// ### Controller Debug Visualizer /// This function shows a debug visualization of the current state of /// the controller! It's not something you'd show to users, but it's /// nice for just seeing how the API works, or as a temporary /// visualization. void ShowController(Handed hand) { Controller c = Input.Controller(hand); if (!c.IsTracked) { return; } Hierarchy.Push(c.pose.ToMatrix()); // Pick the controller color based on trackin info state Color color = Color.Black; if (c.trackedPos == TrackState.Inferred) { color.g = 0.5f; } if (c.trackedPos == TrackState.Known) { color.g = 1; } if (c.trackedRot == TrackState.Inferred) { color.b = 0.5f; } if (c.trackedRot == TrackState.Known) { color.b = 1; } Default.MeshCube.Draw(Default.Material, Matrix.S(new Vec3(3, 3, 8) * U.cm), color); // Show button info on the back of the controller Hierarchy.Push(Matrix.TR(0, 1.6f * U.cm, 0, Quat.LookAt(Vec3.Zero, new Vec3(0, 1, 0), new Vec3(0, 0, -1)))); // Show the tracking states as text Text.Add(c.trackedPos == TrackState.Known?"(pos)":(c.trackedPos == TrackState.Inferred?"~pos~":"pos"), Matrix.TS(0, -0.03f, 0, 0.25f)); Text.Add(c.trackedRot == TrackState.Known?"(rot)":(c.trackedRot == TrackState.Inferred?"~rot~":"rot"), Matrix.TS(0, -0.02f, 0, 0.25f)); // Show the controller's buttons Text.Add(Input.ControllerMenuButton.IsActive()?"(menu)":"menu", Matrix.TS(0, -0.01f, 0, 0.25f)); Text.Add(c.IsX1Pressed?"(X1)":"X1", Matrix.TS(0, 0.00f, 0, 0.25f)); Text.Add(c.IsX2Pressed?"(X2)":"X2", Matrix.TS(0, 0.01f, 0, 0.25f)); // Show the analog stick's information Vec3 stickAt = new Vec3(0, 0.03f, 0); Lines.Add(stickAt, stickAt + c.stick.XY0 * 0.01f, Color.White, 0.001f); if (c.IsStickClicked) { Text.Add("O", Matrix.TS(stickAt, 0.25f)); } // And show the trigger and grip buttons Default.MeshCube.Draw(Default.Material, Matrix.TS(0, -0.015f, -0.005f, new Vec3(0.01f, 0.04f, 0.01f)) * Matrix.TR(new Vec3(0, 0.02f, 0.03f), Quat.FromAngles(-45 + c.trigger * 40, 0, 0))); Default.MeshCube.Draw(Default.Material, Matrix.TS(0.0149f * (hand == Handed.Right?1:-1), 0, 0.015f, new Vec3(0.01f * (1 - c.grip), 0.04f, 0.01f))); Hierarchy.Pop(); Hierarchy.Pop(); // And show the pointer Default.MeshCube.Draw(Default.Material, c.aim.ToMatrix(new Vec3(1, 1, 4) * U.cm), Color.HSV(0, 0.5f, 0.8f).ToLinear()); }
public static Quat LookAt(Vector3f eye, Vector3f center, Vector3f up) { return(Quat.LookAt(eye, center, up)); }