MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / StepMenu

Method StepMenu

StereoKit/Framework/HandMenu/HandMenuRadial.cs:212–277  ·  view source on GitHub ↗
(Hand hand)

Source from the content-addressed store, hash-verified

210 }
211
212 void StepMenu(Hand hand)
213 {
214 // Animate the menu a bit
215 float time = Math.Min(1, Time.StepUnscaledf * 24);
216 menuPose.position = Vec3 .Lerp (menuPose.position, destPose.position, time);
217 menuPose.orientation = Quat .Slerp(menuPose.orientation, destPose.orientation, time);
218 activation = SKMath.Lerp (activation, 1, time);
219 menuScale = SKMath.Lerp (menuScale, 1, time);
220
221 // Pre-calculate some circle traversal values
222 HandRadialLayer layer = activeLayer;
223 int count = layer.items.Length;
224 float step = 360 / count;
225 float halfStep = step/2;
226
227 // Push the Menu's pose onto the stack, so we can draw, and work
228 // in local space.
229 Hierarchy.Push(menuPose.ToMatrix(menuScale));
230
231 // Calculate the status of the menu!
232 Vec3 tipWorld = hand[FingerId.Index, JointId.Tip].position;
233 Vec3 tipLocal = destPose.ToMatrix().Inverse.Transform(tipWorld);
234 float magSq = tipLocal.MagnitudeSq;
235 bool onMenu = tipLocal.z > -0.02f && tipLocal.z < 0.02f;
236 bool focused = onMenu && magSq > minDist * minDist;
237 bool selected = onMenu && magSq > midDist * midDist;
238 bool cancel = magSq > maxDist*maxDist;
239 float arcLength = midDist * Math.Min(90, step) * Units.deg2rad;
240
241 // Find where our finger is pointing to, and draw that
242 float fingerAngle = (float)Math.Atan2(tipLocal.y, tipLocal.x) * Units.rad2deg - (layer.startAngle + angleOffset);
243 while (fingerAngle < 0) fingerAngle += 360;
244 int angleId = (int)(fingerAngle / step);
245 Lines.Add(V.XYZ(0,0,-0.008f), V.XYZ(tipLocal.x, tipLocal.y, -0.008f), Color.White, 0.006f);
246
247 // Now draw each of the menu items!
248 Color colorPrimary = UI.GetThemeColor(UIColor.Primary ).ToLinear();
249 Color colorCommon = UI.GetThemeColor(UIColor.Background).ToLinear();
250 for (int i = 0; i < count; i++)
251 {
252 float currAngle = i*step + layer.startAngle + angleOffset;
253 bool highlight = focused && angleId == i && activation >= 0.99f;
254 float depth = highlight ? -0.005f : 0.0f;
255 Vec3 at = Vec3.AngleXY(currAngle + halfStep) * midDist;
256 at.z = depth;
257
258 Matrix r = Matrix.TR(0,0,depth, Quat.FromAngles( 0, 0, currAngle ));
259 background .Draw(Material.UI, r, colorCommon * (highlight ? 2.0f:1.0f));
260 backgroundEdge.Draw(Material.UI, r, colorPrimary * (highlight ? 2.0f:1.0f));
261 if (layer.items[i].action == HandMenuAction.Layer || layer.items[i].action == HandMenuAction.Back )
262 childIndicator.Draw(Material.UI, Matrix.TR(0, 0, depth, Quat.FromAngles(0, 0, currAngle + halfStep)));
263 layer.items[i].Draw(at, arcLength, currAngle + halfStep, highlight);
264 }
265
266 // Done with local work
267 Hierarchy.Pop();
268
269 // Execute any actions that were discovered

Callers

nothing calls this directly

Calls 15

SlerpMethod · 0.80
PushMethod · 0.80
ToMatrixMethod · 0.80
TransformMethod · 0.80
ToLinearMethod · 0.80
GetThemeColorMethod · 0.80
AngleXYMethod · 0.80
TRMethod · 0.80
FromAnglesMethod · 0.80
PopMethod · 0.80
MinMethod · 0.45
LerpMethod · 0.45

Tested by

no test coverage detected