| 6 | using StereoKit; |
| 7 | |
| 8 | class DemoControllers : ITest |
| 9 | { |
| 10 | string title = "Controllers"; |
| 11 | string description = "While StereoKit prioritizes hand input, sometimes a controller has more precision! StereoKit provides access to any controllers via the Input.Controller function. This is a debug visualization of the controller data provided there.\n\nStereoKit will simulate hands if only controllers are present, but it will not simulate controllers if only hands are present."; |
| 12 | |
| 13 | public void Initialize() |
| 14 | { |
| 15 | Default.MaterialHand[MatParamName.ColorTint] = new Color(1,1,1,0.4f); |
| 16 | } |
| 17 | |
| 18 | public void Shutdown() |
| 19 | { |
| 20 | Default.MaterialHand[MatParamName.ColorTint] = new Color(1,1,1,1); |
| 21 | } |
| 22 | |
| 23 | public void Step() |
| 24 | { |
| 25 | ShowController(Handed.Right); |
| 26 | ShowController(Handed.Left); |
| 27 | |
| 28 | Demo.ShowSummary(title, description, new Bounds(.2f, .1f, 0)); |
| 29 | } |
| 30 | |
| 31 | /// :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 |
| 32 | /// ### Controller Debug Visualizer |
| 33 | /// This function shows a debug visualization of the current state of |
| 34 | /// the controller! It's not something you'd show to users, but it's |
| 35 | /// nice for just seeing how the API works, or as a temporary |
| 36 | /// visualization. |
| 37 | void ShowController(Handed hand) |
| 38 | { |
| 39 | Controller c = Input.Controller(hand); |
| 40 | if (!c.IsTracked) return; |
| 41 | |
| 42 | Hierarchy.Push(c.pose.ToMatrix()); |
| 43 | // Pick the controller color based on trackin info state |
| 44 | Color color = Color.Black; |
| 45 | if (c.trackedPos == TrackState.Inferred) color.g = 0.5f; |
| 46 | if (c.trackedPos == TrackState.Known) color.g = 1; |
| 47 | if (c.trackedRot == TrackState.Inferred) color.b = 0.5f; |
| 48 | if (c.trackedRot == TrackState.Known) color.b = 1; |
| 49 | Default.MeshCube.Draw(Default.Material, Matrix.S(new Vec3(3, 3, 8) * U.cm), color); |
| 50 | |
| 51 | // Show button info on the back of the controller |
| 52 | Hierarchy.Push(Matrix.TR(0,1.6f*U.cm,0, Quat.LookAt(Vec3.Zero, new Vec3(0,1,0), new Vec3(0,0,-1)))); |
| 53 | |
| 54 | // Show the tracking states as text |
| 55 | Text.Add(c.trackedPos==TrackState.Known?"(pos)":(c.trackedPos==TrackState.Inferred?"~pos~":"pos"), Matrix.TS(0,-0.03f,0, 0.25f)); |
| 56 | Text.Add(c.trackedRot==TrackState.Known?"(rot)":(c.trackedRot==TrackState.Inferred?"~rot~":"rot"), Matrix.TS(0,-0.02f,0, 0.25f)); |
| 57 | |
| 58 | // Show the controller's buttons |
| 59 | Text.Add(Input.ControllerMenuButton.IsActive()?"(menu)":"menu", Matrix.TS(0,-0.01f,0, 0.25f)); |
| 60 | Text.Add(c.IsX1Pressed?"(X1)":"X1", Matrix.TS(0,0.00f,0, 0.25f)); |
| 61 | Text.Add(c.IsX2Pressed?"(X2)":"X2", Matrix.TS(0,0.01f,0, 0.25f)); |
| 62 | |
| 63 | // Show the analog stick's information |
| 64 | Vec3 stickAt = new Vec3(0, 0.03f, 0); |
| 65 | Lines.Add(stickAt, stickAt + c.stick.XY0*0.01f, Color.White, 0.001f); |
nothing calls this directly
no outgoing calls
no test coverage detected