////////////////////// public void Init() { Material floorMat = new Material(Shader.FromFile("floor_shader.hlsl")); floorMat.Transparency = Transparency.Blend; floorMat.SetVector("radius", new Vec4(5, 10, 0, 0)); floorMat.QueueOffset = -11; floorMesh = Model.FromMesh(Mesh.GeneratePlane(new Vec2(40, 40), Vec3.Up, Vec3.Forward), floorMat); floorTr = Matrix.TR(new Vec3(0, -1.5f, 0), Quat.Identity); demoSelectPose.position = new Vec3(0, 0, -0.6f); demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward); Tests.FindTests(); Tests.SetTestActive(startTest); Tests.Initialize(); for (int i = 0; i < Tests.DemoCount; i++) { demoNames.Add(Tests.GetDemoName(i).Substring("Demo".Length)); } if (!Tests.IsTesting) { SK.AddStepper(new RenderCamera(new Pose(0.3f, 0, .5f, Quat.FromAngles(0, -90, 0)), 1000, 1000)); } }
public void Update() { UI.WindowBegin("Direction", ref windowPose, new Vec2(20 * Units.cm2m, 0)); UI.Label("Mode"); if (UI.Radio("Lights", mode == LightMode.Lights)) { mode = LightMode.Lights; } UI.SameLine(); if (UI.Radio("Image", mode == LightMode.Image)) { mode = LightMode.Image; } if (mode == LightMode.Lights) { UI.Label("Lights"); if (UI.Button("Add")) { lights.Add(new Light { pose = new Pose(Vec3.Up * Units.cm2m * 25, Quat.LookDir(-Vec3.Forward)), color = Vec3.One }); UpdateLights(); } UI.SameLine(); if (UI.Button("Remove") && lights.Count > 1) { lights.RemoveAt(lights.Count - 1); UpdateLights(); } } if (mode == LightMode.Image) { UI.Label("Image"); if (!FilePicker.Active && UI.Button("Open")) { ShowPicker(); } } UI.WindowEnd(); lightMesh.Draw(lightProbeMat, Matrix.TS(Vec3.Zero, 0.04f)); if (mode == LightMode.Lights) { bool needsUpdate = false; for (int i = 0; i < lights.Count; i++) { needsUpdate = LightHandle(i) || needsUpdate; } if (needsUpdate) { UpdateLights(); } } }
public void Update() { Color32 col = new Color32(0, 255, 0, 255); Hierarchy.Push(Matrix.T(-0.06f, .05f, 0)); Text.Add("Y Top", Matrix.TR(new Vec3(0, .04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.TopCenter); Lines.Add(new Vec3(-0.05f, .04f, 0), new Vec3(.05f, .04f, 0), col, 0.001f); Text.Add("Y Center", Matrix.TR(new Vec3(0, .0f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.Center); Lines.Add(new Vec3(-0.05f, 0, 0), new Vec3(.05f, 0, 0), col, 0.001f); Text.Add("Y Bottom", Matrix.TR(new Vec3(0, -.04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.BottomCenter); Lines.Add(new Vec3(-0.05f, -.04f, 0), new Vec3(.05f, -.04f, 0), col, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(0.02f, 0.05f, 0)); Text.Add("2cm Tall", Matrix.R(Quat.LookDir(0, 0, 1)), style, TextAlign.CenterLeft); Lines.Add(new Vec3(0, -.01f, 0), new Vec3(.11f, -.01f, 0), col, 0.001f); Lines.Add(new Vec3(0, .01f, 0), new Vec3(.11f, .01f, 0), col, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(0, -0.06f, 0)); Text.Add("X Left", Matrix.TR(new Vec3(0, 0.04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.CenterLeft); Text.Add("X Center", Matrix.TR(new Vec3(0, 0, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.Center); Text.Add("X Right", Matrix.TR(new Vec3(0, -0.04f, 0), Quat.LookDir(0, 0, 1)), style, TextAlign.CenterRight); Lines.Add(new Vec3(0, .06f, 0), new Vec3(0, -.06f, 0), col, 0.001f); Hierarchy.Pop(); Tests.Screenshot("Tests/FontSizing.jpg", 600, 600, new Vec3(0, 0, .15f), Vec3.Zero); }
public void Update() { Hierarchy.Push(Matrix.T(-0.3f, 0.1f, -0.7f)); logo.Draw(Matrix.TRS(V.XYZ(logoHalfWidth, 0.3f, 0), Quat.LookDir(0, 0, 1), V.XYZ(logo.Aspect, 1, 1) * 0.25f)); Text.Add(message, Matrix.TRS(V.XYZ(-logoHalfWidth, 0, 0), Quat.LookDir(0, 0, 1), 1.25f), V.XY(logoHalfWidth / 1.25f, 0), TextFit.Wrap, TextAlign.TopLeft, TextAlign.TopLeft); Hierarchy.Pop(); }
/////////////////////////////////////////// static void ShowTerrainWidget() { // Create an affordance for the pedestal that the terrain and UI will // rest on. The user can drag this around the environment, but it // doesn't rotate at all. The pedestal model asset has a diameter of // 1, or radius of 0.5, so the proper scale is radius * 2! float pedestalScale = terrain.clipRadius * 2; UI.HandleBegin("TerrainWidget", ref terrainPose, pedestalModel.Bounds * pedestalScale, false, UIMove.PosOnly); pedestalModel.Draw(Matrix.TS(Vec3.Zero, pedestalScale)); // We've got a simple UI attached to the pedestal, just a list of // places we can display, and a scale slider. It'll face towards the // user at fixed intervals, and won't slide around. This means it's // easy to access, but not hard to touch. Vec3 uiDir = CalcPedestalUIDir(); Pose uiPose = new Pose(uiDir * (terrain.clipRadius + 0.04f), Quat.LookDir(uiDir + Vec3.Up)); compassModel.Draw(Matrix.TS(uiDir * (terrain.clipRadius + 0.01f) + Vec3.Up * 0.02f, 0.4f)); UI.WindowBegin("TerrainOptions", ref uiPose, new Vec2(30, 0) * Units.cm2m, UIWin.Empty); // Show location buttons Vec2 btnSize = new Vec2(6, 3) * Units.cm2m; if (UI.Radio("Kauai", locationId == 0, btnSize)) { LoadLocation(0); } UI.SameLine(); if (UI.Radio("Grand Canyon", locationId == 1, btnSize)) { LoadLocation(1); } UI.SameLine(); if (UI.Radio("Mt. Everest", locationId == 2, btnSize)) { LoadLocation(2); } UI.SameLine(); if (UI.Radio("Machu Picchu", locationId == 3, btnSize)) { LoadLocation(3); } // Scale slider to zoom in and out float uiScale = terrainScale; if (UI.HSlider("Scale", ref uiScale, 0.00003f, 0.00005f, 0, 27 * Units.cm2m)) { SetScale(uiScale); } UI.WindowEnd(); // End TerrainOptions // Now we'll display the terrain on top of the pedestal! ShowTerrain(); UI.HandleEnd(); // End TerrainWidget }
public void Update() { _srcModel.Draw(Matrix.TR(-1, -1.3f, -1, Quat.LookDir(-Vec3.Forward))); _anim1.Draw(Matrix.TR(0, -1.3f, -1, Quat.LookDir(-Vec3.Forward))); _anim2.Draw(Matrix.TR(1, -1.3f, -1, Quat.LookDir(-Vec3.Forward))); Tests.Screenshot("Tests/MultiAnimation.jpg", 10, 600, 400, 90, V.XYZ(0, -.3f, .5f), V.XYZ(0, -.3f, 0)); }
public void Update() { Text.Add( "Zwölf Boxkämpfer jagen Viktor quer über den großen Sylter Deich.", Matrix.TR(new Vec3(0, 0, 0), Quat.LookDir(0, 0, 1)), new Vec2(40, 100) * U.cm, TextFit.Wrap); Tests.Screenshot(400, 400, "GermanText.jpg", new Vec3(0, 0, .2f), Vec3.Zero); }
static void CommonInit() { Material floorMat = Default.Material.Copy(); floorMat[MatParamName.DiffuseTex] = Tex.FromFile("Floor.png"); floorMat[MatParamName.TexScale] = 16; floorMesh = Model.FromMesh(Mesh.GenerateCube(Vec3.One), floorMat); floorTr = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(20, 1, 20)); demoSelectPose.position = new Vec3(0, 0, -0.25f); demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward); }
public void Update() { Tests.Screenshot("Tests/Layout.jpg", 1, 400, 600, 90, V.XYZ(0, -0.1f, 0.25f), V.XYZ(0, -0.1f, 0)); Pose pose = new Pose(Vec3.Zero, Quat.LookDir(0, 0, 1)); UI.WindowBegin("Layout", ref pose); Bounds layout = UI.LayoutReserve(Vec2.Zero, false, U.cm); Mesh.Cube.Draw(Material.Default, Matrix.TS(layout.center, layout.dimensions)); Lines.Add(UI.LayoutAt, UI.LayoutAt + V.XYZ(0, 0, -U.cm * 3), Color32.Black, 0.004f); layout = UI.LayoutReserve(Vec2.Zero, false, U.cm); Mesh.Cube.Draw(Material.Default, Matrix.TS(layout.center, layout.dimensions)); layout = UI.LayoutReserve(V.XY(4 * U.cm, 0), false, U.cm); Mesh.Cube.Draw(Material.Default, Matrix.TS(layout.center, layout.dimensions)); UI.SameLine(); UI.LayoutReserve(V.XY(4 * U.cm, 0), false, U.cm); layout = UI.LayoutLast; layout.center.z -= U.cm / 2; layout.dimensions.z = U.cm; Mesh.Cube.Draw(Material.Default, Matrix.TS(layout.center, layout.dimensions)); UI.LayoutReserve(V.XY(4 * U.cm, 0), true); layout = UI.LayoutLast; layout.center.z -= U.cm / 2; layout.dimensions.z = U.cm; Mesh.Cube.Draw(Material.Default, Matrix.TS(layout.center, layout.dimensions)); UI.SameLine(); layout = UI.LayoutReserve(V.XY(4 * U.cm, 0), true, U.cm); Mesh.Cube.Draw(Material.Default, Matrix.TS(layout.center, layout.dimensions)); UI.Button("hi", V.XY(4 * U.cm, UI.LineHeight)); UI.SameLine(); UI.Button("hi2", V.XY(4 * U.cm, UI.LineHeight)); UI.Button("hi3"); UI.SameLine(); Lines.Add(UI.LayoutAt, UI.LayoutAt + V.XYZ(0, 0, -U.cm * 3), Color32.Black, 0.004f); UI.Button("hi4"); UI.WindowEnd(); }
static void CommonInit() { Material floorMat = new Material(Shader.FromFile("floor_shader.hlsl")); floorMat.Transparency = Transparency.Blend; floorMat.SetVector("radius", new Vec4(5, 10, 0, 0)); floorMat.QueueOffset = -11; floorMesh = Model.FromMesh(Mesh.GenerateCube(Vec3.One), floorMat); floorTr = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(40, .01f, 40)); demoSelectPose.position = new Vec3(0, 0, -0.4f); demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward); }
static void CommonInit() { Material floorMat = Material.Copy(DefaultIds.material); floorMat["diffuse"] = new Tex("Floor.png"); floorMat["tex_scale"] = 4; floorMesh = new Model(Mesh.GenerateCube(Vec3.One), floorMat); floorTr = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(5, 1, 5)); floorSolid = new Solid(new Vec3(0, -1.5f, 0), Quat.Identity, SolidType.Immovable); floorSolid.AddBox(new Vec3(5, 1, 5)); demoSelectPose.position = new Vec3(0, 0, -0.25f); demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward); }
static void CommonInit() { Log.Subscribe(OnLog); Material floorMat = Material.Copy(DefaultIds.material); floorMat["diffuse"] = Tex.FromFile("Floor.png"); floorMat["tex_scale"] = 16; floorMesh = Model.FromMesh(Mesh.GenerateCube(Vec3.One), floorMat); floorTr = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(20, 1, 20)); floorSolid = new Solid(new Vec3(0, -1.5f, 0), Quat.Identity, SolidType.Immovable); floorSolid.AddBox(new Vec3(20, 1, 20)); demoSelectPose.position = new Vec3(0, 0, -0.25f); demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward); }
public void Update() { Hierarchy.Push(Matrix.T(0, 0, -0.3f)); UI.WindowBegin("Alignment", ref alignWindow, new Vec2(20, 0) * Units.cm2m); if (UI.Button("Left")) { align = TextAlign.YCenter | TextAlign.XLeft; } UI.SameLine(); if (UI.Button("Center")) { align = TextAlign.YCenter | TextAlign.XCenter; } UI.SameLine(); if (UI.Button("Right")) { align = TextAlign.YCenter | TextAlign.XRight; } UI.WindowEnd(); Hierarchy.Push(Matrix.T(0.1f, 0, 0)); Text.Add("X Center", Matrix.TRS(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XCenter | TextAlign.YCenter, align); Text.Add("X Left", Matrix.TRS(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XLeft | TextAlign.YCenter, align); Text.Add("X Right", Matrix.TRS(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XRight | TextAlign.YCenter, align); Lines.Add(new Vec3(0, .05f, 0), new Vec3(0, .25f, 0), Color32.White, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(-0.1f, 0, 0)); Text.Add("Y Center", Matrix.TRS(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YCenter | TextAlign.XCenter, align); Lines.Add(new Vec3(-0.05f, .1f, 0), new Vec3(.05f, .1f, 0), Color32.White, 0.001f); Text.Add("Y Top", Matrix.TRS(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YTop | TextAlign.XCenter, align); Lines.Add(new Vec3(-0.05f, .15f, 0), new Vec3(.05f, .15f, 0), Color32.White, 0.001f); Text.Add("Y Bottom", Matrix.TRS(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YBottom | TextAlign.XCenter, align); Lines.Add(new Vec3(-0.05f, .2f, 0), new Vec3(.05f, .2f, 0), Color32.White, 0.001f); Hierarchy.Pop(); Text.Add("Here's\nSome\nMulti-line\nText!!", Matrix.TRS(Vec3.Zero, Quat.LookDir(0, 0, 1)), TextAlign.Center, align); Hierarchy.Pop(); }
static void CommonInit() { /// :CodeSample: Log.Subscribe Log /// Then you add the OnLog method into the log events like this in your initialization /// code! Log.Subscribe(OnLog); /// :End: Material floorMat = Default.Material.Copy(); floorMat["diffuse"] = Tex.FromFile("Floor.png"); floorMat["tex_scale"] = 16; floorMesh = Model.FromMesh(Mesh.GenerateCube(Vec3.One), floorMat); floorTr = Matrix.TRS(new Vec3(0, -1.5f, 0), Quat.Identity, new Vec3(20, 1, 20)); demoSelectPose.position = new Vec3(0, 0, -0.25f); demoSelectPose.orientation = Quat.LookDir(-Vec3.Forward); }
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() { Pose solidPose; for (int i = 0; i < objects.Count; i++) { objects[i].GetPose(out solidPose); Renderer.Add(gltf, solidPose.ToMatrix(0.25f), Color.White); } for (int i = 0; i < (int)Handed.Max; i++) { Hand h = Input.Hand((Handed)i); if (h.IsJustGripped) { Input.HandSolid((Handed)i, true); Default.MaterialHand[MatParamName.ColorTint] = new Color(1, 1, 1, 1); } if (h.IsJustUngripped) { Input.HandSolid((Handed)i, false); Default.MaterialHand[MatParamName.ColorTint] = new Color(1, 1, 1, 0.4f); } } UI.WindowBegin("Objects", ref optionsPose); if (UI.Button("Add")) { objects.Add(new Solid(new Vec3(0, 3, -.6f), Quat.LookDir(0, 0, 1))); objects.Last().AddSphere(.45f, 40, V.XYZ(0, 0, 0.05f)); objects.Last().AddBox(Vec3.One * .35f, 40, V.XYZ(0, 0, 0.05f)); } if (UI.Button("Clear")) { objects.Clear(); } UI.WindowEnd(); Text.Add(title, titlePose); Text.Add(description, descPose, V.XY(0.4f, 0), TextFit.Wrap, TextAlign.TopCenter, TextAlign.TopLeft); }
public void Update() { Plane plane = new Plane(new Vec3(0.5f, 0, -0.5f), V.XYZ(-0.5f, 0, 0.5f)); Mesh.Quad.Draw(Material.Default, Matrix.TRS(new Vec3(0.54f, 0, -0.468f), Quat.LookDir(plane.normal), 0.5f)); if (Input.Eyes.Ray.Intersect(plane, out Vec3 at)) { Color stateColor = Input.EyesTracked.IsActive() ? new Color(0, 1, 0) : new Color(1, 0, 0); Default.MeshSphere.Draw(Default.Material, Matrix.TS(at, 3 * U.cm), stateColor); if (Vec3.DistanceSq(at, previous) > U.cm * U.cm) { previous = at; points.Add(new LinePoint { pt = at, color = Color.White }); if (points.Count > 20) { points.RemoveAt(0); } } LinePoint pt = points[points.Count - 1]; pt.pt = at; points[points.Count - 1] = pt; } for (int i = 0; i < points.Count; i++) { LinePoint pt = points[i]; pt.thickness = (i / (float)points.Count) * 3 * U.cm; points[i] = pt; } Lines.Add(points.ToArray()); Text.Add(title, titlePose); Text.Add(description, descPose, V.XY(0.4f, 0), TextFit.Wrap, TextAlign.TopCenter, TextAlign.TopLeft); }
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: }
public void Update() { Tests.Screenshot("Tests/TextStyle.jpg", 1, 400, 600, 90, V.XYZ(0, -0.15f, 0.25f), V.XYZ(0, -0.15f, 0)); Pose pose = new Pose(Vec3.Zero, Quat.LookDir(0, 0, 1)); UI.PushTextStyle(style1); UI.WindowBegin("Text Style", ref pose); UI.Label("Should be red"); UI.HSeparator(); UI.PushTextStyle(style2); UI.Text("Should also be in times new roman, or possibly the default font."); UI.Button("Boop here"); UI.PopTextStyle(); UI.Toggle("Toggle here", ref toggle); UI.Input("Input", ref input); UI.Radio("Radio", toggle); UI.WindowEnd(); UI.PopTextStyle(); }
public void Update() { UI.WindowBegin("Alignment", ref alignWindow, new Vec2(20, 0) * Units.cm2m); if (UI.Button("TL")) { align = TextAlign.YTop | TextAlign.XLeft; } UI.SameLine(); if (UI.Button("TC")) { align = TextAlign.YTop | TextAlign.XCenter; } UI.SameLine(); if (UI.Button("TR")) { align = TextAlign.YTop | TextAlign.XRight; } if (UI.Button("CL")) { align = TextAlign.YCenter | TextAlign.XLeft; } UI.SameLine(); if (UI.Button("CC")) { align = TextAlign.YCenter | TextAlign.XCenter; } UI.SameLine(); if (UI.Button("CR")) { align = TextAlign.YCenter | TextAlign.XRight; } if (UI.Button("BL")) { align = TextAlign.YBottom | TextAlign.XLeft; } UI.SameLine(); if (UI.Button("BC")) { align = TextAlign.YBottom | TextAlign.XCenter; } UI.SameLine(); if (UI.Button("BR")) { align = TextAlign.YBottom | TextAlign.XRight; } UI.WindowEnd(); Hierarchy.Push(Matrix.T(0.05f, 0, 0)); Text.Add("X Center", Matrix.TRS(new Vec3(0, .1f, 0.3f), Quat.LookDir(0, 0, 1)), TextAlign.XCenter, align); Text.Add("X Left", Matrix.TRS(new Vec3(0, .15f, 0.3f), Quat.LookDir(0, 0, 1)), TextAlign.XLeft, align); Text.Add("X Right", Matrix.TRS(new Vec3(0, .2f, 0.3f), Quat.LookDir(0, 0, 1)), TextAlign.XRight, align); Lines.Add(new Vec3(0, -1, 0.3f), new Vec3(0, 1, 0.3f), new Color32(0, 255, 0, 255), 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(-0.05f, 0, 0)); Text.Add("Y Center", Matrix.TRS(new Vec3(0, .1f, 0.3f), Quat.LookDir(0, 0, 1)), TextAlign.YCenter, align); Lines.Add(new Vec3(-0.05f, .1f, 0.3f), new Vec3(.05f, .1f, 0.3f), new Color32(0, 255, 0, 255), 0.001f); Text.Add("Y Top", Matrix.TRS(new Vec3(0, .15f, 0.3f), Quat.LookDir(0, 0, 1)), TextAlign.YTop, align); Lines.Add(new Vec3(-0.05f, .15f, 0.3f), new Vec3(.05f, .15f, 0.3f), new Color32(0, 255, 0, 255), 0.001f); Text.Add("Y Bottom", Matrix.TRS(new Vec3(0, .2f, 0.3f), Quat.LookDir(0, 0, 1)), TextAlign.YBottom, align); Lines.Add(new Vec3(-0.05f, .2f, 0.3f), new Vec3(.05f, .2f, 0.3f), new Color32(0, 255, 0, 255), 0.001f); Hierarchy.Pop(); Text.Add("Here's\nSome\nMulti-line\nText!!", Matrix.TRS(new Vec3(0, 0, 0.1f), Quat.LookDir(0, 0, 1))); }
public void Update() { Hierarchy.Push(Matrix.T(0, 0, -0.3f)); UI.WindowBegin("Alignment", ref alignWindow, new Vec2(20, 0) * Units.cm2m); if (UI.Button("Left")) { align = TextAlign.YCenter | TextAlign.XLeft; } UI.SameLine(); if (UI.Button("Center")) { align = TextAlign.YCenter | TextAlign.XCenter; } UI.SameLine(); if (UI.Button("Right")) { align = TextAlign.YCenter | TextAlign.XRight; } UI.WindowEnd(); Hierarchy.Push(Matrix.T(0.1f, 0, 0)); Text.Add("X Center", Matrix.TRS(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XCenter | TextAlign.YCenter, align); Text.Add("X Left", Matrix.TRS(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XLeft | TextAlign.YCenter, align); Text.Add("X Right", Matrix.TRS(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XRight | TextAlign.YCenter, align); Lines.Add(new Vec3(0, .05f, 0), new Vec3(0, .25f, 0), Color32.White, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(-0.1f, 0, 0)); Text.Add("Y Center", Matrix.TRS(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YCenter | TextAlign.XCenter, align); Lines.Add(new Vec3(-0.05f, .1f, 0), new Vec3(.05f, .1f, 0), Color32.White, 0.001f); Text.Add("Y Top", Matrix.TRS(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YTop | TextAlign.XCenter, align); Lines.Add(new Vec3(-0.05f, .15f, 0), new Vec3(.05f, .15f, 0), Color32.White, 0.001f); Text.Add("Y Bottom", Matrix.TRS(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YBottom | TextAlign.XCenter, align); Lines.Add(new Vec3(-0.05f, .2f, 0), new Vec3(.05f, .2f, 0), Color32.White, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(0, -0.1f, 0)); if (Demos.TestMode) { Renderer.Screenshot(Hierarchy.ToWorld(new Vec3(0, 0, 0.09f)), Hierarchy.ToWorld(Vec3.Zero), 600, 300, "../../../docs/img/screenshots/BasicText.jpg"); } /// :CodeSample: Text.MakeStyle Font.FromFile Text.Add /// Then it's pretty trivial to just draw some text on the screen! Just call /// Text.Add on update. If you don't have a TextStyle available, calling it /// without one will just fall back on the default style. // Text with an explicit text style Text.Add( "Here's\nSome\nMulti-line\nText!!", Matrix.TRS(new Vec3(0.1f, 0, 0), Quat.LookDir(0, 0, 1)), style); // Text using the default text style Text.Add( "Here's\nSome\nMulti-line\nText!!", Matrix.TRS(new Vec3(-0.1f, 0, 0), Quat.LookDir(0, 0, 1))); /// :End: Hierarchy.Pop(); Hierarchy.Pop(); }
/////////////////////////////////////////// static void Main(string[] args) { StereoKitApp.settings.assetsFolder = "Assets"; if (!StereoKitApp.Initialize("StereoKit_BingMaps", Runtime.MixedReality)) { Environment.Exit(1); } Model cube = Model.FromMesh( Mesh.GenerateRoundedCube(Vec3.One, 0.2f), Default.Material); cylinderMesh = Mesh.GenerateCylinder(1, 1, Vec3.Up, 64); compassModel = Model.FromFile("Compass.glb"); terrain = new Terrain(128, 1, 3); terrain.ClipRadius = 0.3f; LoadLocation(0); while (StereoKitApp.Step(() => { UI.AffordanceBegin("Terrain", ref terrainPose, new Bounds(new Vec3(terrain.ClipRadius * 2, 0.1f, terrain.ClipRadius * 2))); terrainPose.orientation = Quat.Identity; UI.AffordanceEnd(); Hand hand = Input.Hand(Handed.Right); if (hand.IsJustPinched) { justStart = terrain.Translation; justFinger = hand[FingerId.Index, JointId.Tip].position; } if (hand.IsPinched) { Vec3 newPos = justStart + (hand[FingerId.Index, JointId.Tip].position - justFinger); newPos.y = 0; terrain.Translation = newPos; terrain.ClipCenter = -newPos; } terrain.Update(); cylinderMesh.Draw(Default.Material, Matrix.TS(Vec3.Up * -0.04f, new Vec3(terrain.ClipRadius * 2, 0.05f, terrain.ClipRadius * 2)), Color.White * 0.25f); Vec3 pos = Vec3.Zero; Vec3 dir = (Input.Head.position - pos); dir.y = 0; dir.Normalize(); float angle = MathF.Atan2(dir.z, dir.x) * Units.rad2deg; if (angle < 0) { angle = 360 + angle; } angle = (int)(angle / 60) * 60 + 30; dir = Vec3.AngleXZ(angle); Vec3 lookat = dir + Vec3.Up; Vec3 menuAt = pos + dir * (terrain.ClipRadius + 0.04f); compassModel.Draw(Matrix.TS(pos + dir * (terrain.ClipRadius + 0.01f) + Vec3.Up * 0.02f, 0.4f)); Pose uiPose = new Pose(menuAt, Quat.LookDir(lookat)); UI.WindowBegin("TerrainOptions", ref uiPose, new Vec2(30, 0) * Units.cm2m, false); // Show location buttons Vec2 btnSize = new Vec2(6, 3) * Units.cm2m; if (UI.Radio("Kauai", locationId == 0, btnSize)) { LoadLocation(0); } UI.SameLine(); if (UI.Radio("Grand Canyon", locationId == 1, btnSize)) { LoadLocation(1); } UI.SameLine(); if (UI.Radio("Mt. Everest", locationId == 2, btnSize)) { LoadLocation(2); } UI.SameLine(); if (UI.Radio("Machu Picchu", locationId == 3, btnSize)) { LoadLocation(3); } // Scale slider to zoom in and out if (UI.HSlider("Scale", ref uiWorldScale, 0.00002f, 0.00004f, 0, 27 * Units.cm2m)) { SetScale(uiWorldScale); } UI.WindowEnd(); })) { ; } StereoKitApp.Shutdown(); }
public void Update() { Hierarchy.Push(Matrix.T(0, 0, -0.3f)); UI.WindowBegin("Alignment", ref alignWindow, new Vec2(20, 0) * Units.cm2m); Vec2 size = new Vec2(5 * Units.cm2m, UI.LineHeight); if (UI.Radio("Left", alignX == TextAlign.XLeft, size)) { alignX = TextAlign.XLeft; } UI.SameLine(); if (UI.Radio("CenterX", alignX == TextAlign.XCenter, size)) { alignX = TextAlign.XCenter; } UI.SameLine(); if (UI.Radio("Right", alignX == TextAlign.XRight, size)) { alignX = TextAlign.XRight; } if (UI.Radio("Top", alignY == TextAlign.YTop, size)) { alignY = TextAlign.YTop; } UI.SameLine(); if (UI.Radio("CenterY", alignY == TextAlign.YCenter, size)) { alignY = TextAlign.YCenter; } UI.SameLine(); if (UI.Radio("Bottom", alignY == TextAlign.YBottom, size)) { alignY = TextAlign.YBottom; } UI.WindowEnd(); Hierarchy.Push(Matrix.T(0.1f, 0, 0)); Text.Add("X Center", Matrix.TRS(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XCenter | TextAlign.YCenter, alignX | alignY); Text.Add("X Left", Matrix.TRS(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XLeft | TextAlign.YCenter, alignX | alignY); Text.Add("X Right", Matrix.TRS(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.XRight | TextAlign.YCenter, alignX | alignY); Lines.Add(new Vec3(0, .05f, 0), new Vec3(0, .25f, 0), Color32.White, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(-0.1f, 0, 0)); Text.Add("Y Center", Matrix.TRS(new Vec3(0, .1f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YCenter | TextAlign.XCenter, alignX | alignY); Lines.Add(new Vec3(-0.05f, .1f, 0), new Vec3(.05f, .1f, 0), Color32.White, 0.001f); Text.Add("Y Top", Matrix.TRS(new Vec3(0, .15f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YTop | TextAlign.XCenter, alignX | alignY); Lines.Add(new Vec3(-0.05f, .15f, 0), new Vec3(.05f, .15f, 0), Color32.White, 0.001f); Text.Add("Y Bottom", Matrix.TRS(new Vec3(0, .2f, 0), Quat.LookDir(0, 0, 1)), TextAlign.YBottom | TextAlign.XCenter, alignX | alignY); Lines.Add(new Vec3(-0.05f, .2f, 0), new Vec3(.05f, .2f, 0), Color32.White, 0.001f); Hierarchy.Pop(); Hierarchy.Push(Matrix.T(0, -0.1f, 0)); if (Tests.IsTesting) { Renderer.Screenshot(Hierarchy.ToWorld(new Vec3(0, 0, 0.09f)), Hierarchy.ToWorld(Vec3.Zero), 600, 300, "../../../docs/img/screenshots/BasicText.jpg"); } /// :CodeSample: Text.MakeStyle Font.FromFile Text.Add /// Then it's pretty trivial to just draw some text on the screen! Just call /// Text.Add on update. If you don't have a TextStyle available, calling it /// without one will just fall back on the default style. // Text with an explicit text style Text.Add( "Here's\nSome\nMulti-line\nText!!", Matrix.TRS(new Vec3(0.1f, 0, 0), Quat.LookDir(0, 0, 1)), style); // Text using the default text style Text.Add( "Here's\nSome\nMulti-line\nText!!", Matrix.TRS(new Vec3(-0.1f, 0, 0), Quat.LookDir(0, 0, 1))); /// :End: Hierarchy.Push(Matrix.T(0, -0.2f, 0)); Text.Add( "Here's Some Multi-line Text!!", Matrix.TRS(new Vec3(0, 0.0f, 0), Quat.LookDir(0, 0, 1)), new Vec2(SKMath.Cos(Time.Totalf) * 10 + 11, 20) * Units.cm2m, TextFit.Clip, style, TextAlign.Center, alignX | alignY); Hierarchy.Pop(); Hierarchy.Pop(); Hierarchy.Pop(); }
public void Update() { Color colIntersect = Color.HSV(0, 0.8f, 1); Color colTest = Color.HSV(0, 0.6f, 1); Color colObj = Color.HSV(0.05f, 0.7f, 1); Color active = new Color(1, 1, 1, 0.7f); Color notActive = new Color(1, 1, 1, 1); // Plane and Ray bool planeRayActive = UI.AffordanceBegin("PlaneRay", ref posePlaneRay, new Bounds(Vec3.One * 0.4f)); boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), planeRayActive ? active:notActive); Plane ground = new Plane(Vec3.Zero, new Vec3(1, 2, 0)); Ray groundRay = new Ray(Vec3.Zero + new Vec3(0, 0.2f, 0), Vec3.AngleXZ(Time.Totalf * 90, -2).Normalized()); Lines.Add(groundRay.position, groundRay.position + groundRay.direction * 0.1f, new Color32(255, 0, 0, 255), 2 * Units.mm2m); planeMesh.Draw(material, Matrix.TRS(Vec3.Zero, Quat.LookDir(ground.normal), 0.25f), colObj); if (groundRay.Intersect(ground, out Vec3 groundAt)) { sphereMesh.Draw(material, Matrix.TS(groundAt, 0.02f), colIntersect); } UI.AffordanceEnd(); if (Demos.TestMode) { Renderer.Screenshot(posePlaneRay.position + new Vec3(0.0f, 0.3f, 0.15f), posePlaneRay.position + Vec3.Up * 0.1f, 400, 400, "../../../docs/img/screenshots/RayIntersectPlane.jpg"); } // Line and Plane bool linePlaneActive = UI.AffordanceBegin("LinePlane", ref poseLinePlane, new Bounds(Vec3.One * 0.4f)); boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), linePlaneActive ? active : notActive); Plane groundLinePlane = new Plane(Vec3.Zero, new Vec3(1, 2, 0)); Ray groundLineRay = new Ray(Vec3.Zero + new Vec3(0, 0.25f, 0), Vec3.AngleXZ(Time.Totalf * 90, -2).Normalized()); Vec3 groundLineP1 = groundLineRay.position + groundLineRay.direction * (SKMath.Cos(Time.Totalf * 3) + 1) * 0.2f; Vec3 groundLineP2 = groundLineRay.position + groundLineRay.direction * ((SKMath.Cos(Time.Totalf * 3) + 1) * 0.2f + 0.1f); Lines.Add(groundLineP1, groundLineP2, colTest, 2 * Units.mm2m); sphereMesh.Draw(material, Matrix.TS(groundLineP1, 0.01f), colTest); sphereMesh.Draw(material, Matrix.TS(groundLineP2, 0.01f), colTest); bool groundLineIntersects = groundLinePlane.Intersect(groundLineP1, groundLineP2, out Vec3 groundLineAt); planeMesh.Draw(material, Matrix.TRS(Vec3.Zero, Quat.LookDir(groundLinePlane.normal), 0.25f), groundLineIntersects? colIntersect : colObj); if (groundLineIntersects) { sphereMesh.Draw(material, Matrix.TS(groundLineAt, 0.02f), colIntersect); } UI.AffordanceEnd(); if (Demos.TestMode) { Renderer.Screenshot(poseLinePlane.position + new Vec3(0.0f, 0.3f, 0.15f), poseLinePlane.position + Vec3.Up * 0.1f, 400, 400, "../../../docs/img/screenshots/LineIntersectPlane.jpg"); } // Sphere and Ray bool sphereRayActive = UI.AffordanceBegin("SphereRay", ref poseSphereRay, new Bounds(Vec3.One * 0.4f)); boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), sphereRayActive ? active : notActive); Sphere sphere = new Sphere(Vec3.Zero, 0.25f); Vec3 sphereDir = Vec3.AngleXZ(Time.Totalf * 90, SKMath.Cos(Time.Totalf * 3) * 1.5f + 0.1f).Normalized(); Ray sphereRay = new Ray(sphere.center - sphereDir * 0.35f, sphereDir); Lines.Add(sphereRay.position, sphereRay.position + sphereRay.direction * 0.1f, colTest, 2 * Units.mm2m); if (sphereRay.Intersect(sphere, out Vec3 sphereAt)) { sphereMesh.Draw(material, Matrix.TS(sphereAt, 0.02f), colIntersect); } sphereMesh.Draw(material, Matrix.TS(sphere.center, 0.25f), colObj); UI.AffordanceEnd(); if (Demos.TestMode) { Renderer.Screenshot(poseSphereRay.position + new Vec3(0.0f, 0.3f, 0.15f), poseSphereRay.position, 400, 400, "../../../docs/img/screenshots/RayIntersectSphere.jpg"); } // Bounds and Ray bool boundsRayActive = UI.AffordanceBegin("BoundsRay", ref poseBoundsRay, new Bounds(Vec3.One * 0.4f)); boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), boundsRayActive ? active : notActive); Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * 0.25f); Vec3 boundsDir = Vec3.AngleXZ(Time.Totalf * 90, SKMath.Cos(Time.Totalf * 3) * 1.5f).Normalized(); Ray boundsRay = new Ray(bounds.center - boundsDir * 0.35f, boundsDir); Lines.Add(boundsRay.position, boundsRay.position + boundsRay.direction * 0.1f, colTest, 2 * Units.mm2m); if (boundsRay.Intersect(bounds, out Vec3 boundsAt)) { sphereMesh.Draw(material, Matrix.TS(boundsAt, 0.02f), colIntersect); } cubeMesh.Draw(material, Matrix.TS(bounds.center, 0.25f), colObj); UI.AffordanceEnd(); if (Demos.TestMode) { Renderer.Screenshot(poseBoundsRay.position + new Vec3(0.0f, 0.3f, 0.15f), poseBoundsRay.position, 400, 400, "../../../docs/img/screenshots/RayIntersectBounds.jpg"); } // Bounds and Line bool boundsLineActive = UI.AffordanceBegin("BoundsLine", ref poseBoundsLine, new Bounds(Vec3.One * 0.4f)); boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), boundsLineActive ? active : notActive); Bounds boundsLine = new Bounds(Vec3.Zero, Vec3.One * 0.25f); Vec3 boundsLineP1 = boundsLine.center + Vec3.AngleXZ(Time.Totalf * 45, SKMath.Cos(Time.Totalf * 3)) * 0.35f; Vec3 boundsLineP2 = boundsLine.center + Vec3.AngleXZ(Time.Totalf * 90, SKMath.Cos(Time.Totalf * 6)) * SKMath.Cos(Time.Totalf) * 0.35f; Lines.Add(boundsLineP1, boundsLineP2, colTest, 2 * Units.mm2m); sphereMesh.Draw(material, Matrix.TS(boundsLineP1, 0.01f), colTest); sphereMesh.Draw(material, Matrix.TS(boundsLineP2, 0.01f), colTest); cubeMesh.Draw(material, Matrix.TS(boundsLine.center, 0.25f), boundsLine.Contains(boundsLineP1, boundsLineP2) ? colIntersect : colObj); UI.AffordanceEnd(); if (Demos.TestMode) { Renderer.Screenshot(poseBoundsLine.position + new Vec3(0.0f, 0.3f, 0.15f), poseBoundsLine.position, 400, 400, "../../../docs/img/screenshots/LineIntersectBounds.jpg"); } // Cross product bool crossActive = UI.AffordanceBegin("Cross", ref poseCross, new Bounds(Vec3.One * 0.4f)); boundsMesh.Draw(boundsMat, Matrix.TS(Vec3.Zero, 0.4f), crossActive ? active : notActive); Vec3 crossStart = Vec3.Zero; //Vec3 right = Vec3.Cross(Vec3.Forward, Vec3.Up); // These are the same! Vec3 right = Vec3.PerpendicularRight(Vec3.Forward, Vec3.Up); Lines.Add(crossStart, crossStart + Vec3.Up * 0.1f, new Color32(255, 255, 255, 255), 2 * Units.mm2m); Lines.Add(crossStart, crossStart + Vec3.Forward * 0.1f, new Color32(255, 255, 255, 255), 2 * Units.mm2m); Lines.Add(crossStart, crossStart + right * 0.1f, new Color32(0, 255, 0, 255), 2 * Units.mm2m); Text.Add("Up", Matrix.TRS(crossStart + Vec3.Up * 0.1f, Quat.LookDir(-Vec3.Forward), 1), TextAlign.XCenter | TextAlign.YBottom); Text.Add("Fwd", Matrix.TRS(crossStart + Vec3.Forward * 0.1f, Quat.LookDir(-Vec3.Forward), 1), TextAlign.XCenter | TextAlign.YBottom); Text.Add("Vec3.Cross(Fwd,Up)", Matrix.TRS(crossStart + right * 0.1f, Quat.LookDir(-Vec3.Forward), 1), TextAlign.XCenter | TextAlign.YBottom); UI.AffordanceEnd(); if (Demos.TestMode) { Renderer.Screenshot(poseCross.position + new Vec3(0.075f, 0.1f, 0.15f), poseCross.position + new Vec3(0.075f, 0, 0), 400, 400, "../../../docs/img/screenshots/CrossProduct.jpg"); } }
public void Initialize() { /// :CodeSample: Model Model.AddNode Model.FindNode ModelNode.AddChild /// ### Assembling a Model /// While normally you'll load Models from file, you can also assemble /// them yourself procedurally! This example shows assembling a simple /// hierarchy of visual and empty nodes. Model model = new Model(); model .AddNode("Root", Matrix.S(0.2f), Mesh.Cube, Material.Default) .AddChild("Sub", Matrix.TR(V.XYZ(0.5f, 0, 0), Quat.FromAngles(0, 0, 45)), Mesh.Cube, Material.Default) .AddChild("Surface", Matrix.TRS(V.XYZ(0.5f, 0, 0), Quat.LookDir(V.XYZ(1, 0, 0)), V.XYZ(1, 1, 1))); ModelNode surfaceNode = model.FindNode("Surface"); surfaceNode.AddChild("UnitX", Matrix.T(Vec3.UnitX)); surfaceNode.AddChild("UnitY", Matrix.T(Vec3.UnitY)); surfaceNode.AddChild("UnitZ", Matrix.T(Vec3.UnitZ)); /// :End: Tests.Test(() => model.FindNode("NotPresent") == null); /// :CodeSample: Model Model.Nodes /// ### Simple iteration /// Walking through the Model's list of nodes is pretty /// straightforward! This will touch every ModelNode in the Model, /// in the order they were defined, regardless of hierarchy position /// or contents. Log.Info("Iterate nodes:"); foreach (ModelNode node in model.Nodes) { Log.Info(" " + node.Name); } /// :End: /// :CodeSample: Model Model.Visuals /// ### Simple iteration of visual nodes /// This will iterate through every ModelNode in the Model with visual /// data attached to it! Log.Info("Iterate visuals:"); foreach (ModelNode node in model.Visuals) { Log.Info(" " + node.Name); } /// :End: /// :CodeSample: Model Model.Visuals Model.Nodes /// ### Tagged Nodes /// You can search through Visuals and Nodes var nodes = model.Visuals .Where(n => n.Name.StartsWith("[Wire]")); foreach (var node in nodes) { node.Material = node.Material.Copy(); node.Material.Wireframe = true; } /// :End: Log.Info("Recursive ModelNode traversal:"); RecursiveTraversal(model.RootNode); Log.Info("Depth first ModelNode traversal:"); DepthFirstTraversal(model); for (int i = 0; i < model.Nodes.Count; i++) { Log.Info($"{model.Nodes[i].Name} using shader {model.Nodes[i].Material?.Shader.Name}"); } _model = model; _surfaceNode = surfaceNode; }
static void Main(string[] args) { if (!StereoKitApp.Initialize("StereoKit_day00", Runtime.Flatscreen)) { Environment.Exit(1); } Balloon balloon = new Balloon(1f); String txt_format = String.Format("Game Over!\nBallon life was: " + (int)Time.Total + " secs\n Tap again to exit"); bool gameOver = false; //Time.SetTime //Time.SetTime(0); while (StereoKitApp.Step(() => { Hand right_hand = Input.Hand(Handed.Right); if (right_hand.IsPinched && !balloon.GetGameStarted()) { Console.WriteLine("GAME STARTED"); Time.SetTime(0.0f); } Console.WriteLine(Time.Total); if (balloon.balloonAir > 5f) { if (!gameOver) { txt_format = String.Format("Game Over!\nBallon life was: " + (int)Time.Total + " secs\n Tap again to exit"); } Text.Add( txt_format, Matrix.TRS(Vec3.Zero, Quat.LookDir(0, 0, 1))); gameOver = true; if (right_hand.IsJustPinched) { StereoKitApp.Quit(); } } else if (balloon.balloonAir < 0.5f) { //Matrix //Quat Text.Add( "YOU LOST!\n", Matrix.TRS(Vec3.Zero, Quat.LookDir(0, 0, 1))); if (right_hand.IsJustPinched) { StereoKitApp.Quit(); } gameOver = true; } if (!gameOver) { balloon.DrawBalloon(); balloon.Steps(right_hand); } })) { ; } StereoKitApp.Shutdown(); }
public void Update() { UI.WindowBegin("Direction", ref windowPose, new Vec2(20 * U.cm, 0)); UI.Label("Mode"); if (UI.Radio("Lights", mode == LightMode.Lights)) { mode = LightMode.Lights; } UI.SameLine(); if (UI.Radio("Image", mode == LightMode.Image)) { mode = LightMode.Image; } if (mode == LightMode.Lights) { UI.Label("Lights"); if (UI.Button("Add")) { lights.Add(new Light { pose = new Pose(Vec3.Up * 25 * U.cm, Quat.LookDir(-Vec3.Forward)), color = Vec3.One }); UpdateLights(); } UI.SameLine(); if (UI.Button("Remove") && lights.Count > 1) { lights.RemoveAt(lights.Count - 1); UpdateLights(); } } if (mode == LightMode.Image) { UI.Label("Image"); if (!Platform.FilePickerVisible && UI.Button("Open")) { ShowPicker(); } } if (UI.Button("Print SH")) { Vec3[] c = Renderer.SkyLight.ToArray(); string shStr = "new SphericalHarmonics(new Vec3[]{"; for (int i = 0; i < c.Length; i++) { shStr += $"new Vec3({c[i].x:F2}f, {c[i].y:F2}f, {c[i].z:F2}f),"; } shStr += "});"; Log.Info(shStr); } UI.WindowEnd(); lightMesh.Draw(lightProbeMat, Matrix.TS(Vec3.Zero, 0.04f)); UI.Handle("Preview", ref previewPose, previewModel.Bounds * 0.1f); previewModel.Draw(previewPose.ToMatrix(0.1f)); if (mode == LightMode.Lights) { bool needsUpdate = false; for (int i = 0; i < lights.Count; i++) { needsUpdate = LightHandle(i) || needsUpdate; } if (needsUpdate) { UpdateLights(); } } }
static void Main(string[] args) { Sound song; Queue <Note>[] noteQueues = null; int positionInNotes = 0; double songStartTime = 0; DateTime watcherStart = DateTime.Now; // Initialize StereoKit SKSettings settings = new SKSettings { appName = "DrumMR", assetsFolder = "Assets", }; if (!SK.Initialize(settings)) { Environment.Exit(1); } SerialPort port = new SerialPort(); port.PortName = "COM3"; port.BaudRate = 9600; //port.Open(); port.DataReceived += (sender, dataArgs) => { SerialPort sp = (SerialPort)sender; string result = sp.ReadExisting(); Debug.WriteLine("Serial data received: " + result); //buffer[Int32.Parse(result)] = true; }; Vec3[] unitVectors = createNewUnitVectors(); //x, y, and z Mesh boardMesh = Mesh.GenerateCube(new Vec3(1f, 2f, 0)); Mesh noteMesh = Mesh.GenerateCube(new Vec3(.04f, .048f, 0)); Model boardModel = Model.FromMesh(boardMesh, Default.Material); Model noteModel = Model.FromMesh(noteMesh, Default.Material); Debug.WriteLine(unitVectors[0]); Quat boardQuat = new Quat((float)0, (float).7, (float).7, (float)0); Vec3 boardLocation = new Vec3(drumLocations[1].orientation.x + .05f * (unitVectors[0].x + unitVectors[1].x + unitVectors[2].x), drumLocations[1].orientation.y + .05f * ((unitVectors[0].y + unitVectors[1].y + unitVectors[2].y)), drumLocations[1].orientation.z + (((unitVectors[0].z + unitVectors[1].z + unitVectors[2].z)))); Pose boardPose = new Pose(boardLocation, boardQuat); boardModel.Draw(boardPose.ToMatrix(), Color.Black); //TODO: SET THIS QUAT TO BE PARALLEL TO UNITVECTORS[0] //TODO: MAKE DIFFERENTLY COLORED NOTE MESHES FOR EACH LANE //TODO: ROTATION IS GOING TO NEED TO BE FIGURED OUT. IT CAN'T TURN DYNAMICALLY BECAUSE THE NOTES WOULD NEED TO TURN AS WELL // Core application loop InitializeDrumLocations(); while (SK.Step(() => { if (!PoseIsInitialized(drumLocations[0])) { getDrumLocation(0); } else if (!PoseIsInitialized(drumLocations[1])) { getDrumLocation(1); } else if (!PoseIsInitialized(drumLocations[2])) { getDrumLocation(2); } else if (!PoseIsInitialized(drumLocations[3])) { getDrumLocation(3); } else if (notes is null) { //TODO: CHANGE THIS TO MOVE WITH THE USER USING INPUT.HEAD.POSITION? Pose windowPose = new Pose(-.4f, 0, 0, Quat.LookDir(1, 0, 1)); UI.WindowBegin("Window", ref windowPose, new Vec2(20, 0) * U.cm, UIWin.Normal); for (int i = 0; i < songs.Length; i++) { if (UI.Button(songs[i])) { Debug.WriteLine(songs[i]); string jsonString = getJSONStringOfSong(songs[i] + ".json"); notes = parseJSONSong(jsonString); notes = sortNotes(notes); song = Sound.FromFile(songs[i] + ".wav"); song.Play(Input.Head.position); songStartTime = Time.Total; noteQueues = new Queue <Note> [4]; for (int j = 0; j < 4; j++) { noteQueues[j] = new Queue <Note> { }; } } } UI.WindowEnd(); } else { //calculates x values for note lanes float midpoint = (drumLocations[0].position.x + drumLocations[3].position.x) / 2; float notePoint = midpoint / 8; //draws the board boardModel.Draw(boardPose.ToMatrix(), Color.Black); while (positionInNotes < notes.Length && notes[positionInNotes].time - (Time.Total - songStartTime) < GAME_BOARD_TIME) { Note noteToPush = notes[positionInNotes]; Debug.WriteLine(noteToPush.pad); Debug.WriteLine(noteQueues[noteToPush.pad].Count); noteQueues[noteToPush.pad].Enqueue(noteToPush); positionInNotes++; } for (int i = 0; i < noteQueues.Length; i++) { for (int j = 0; j < noteQueues[i].Count; j++) { Note noteToRender = noteQueues[i].Dequeue(); Pose notePose = new Pose(notePoint * i, (float)(noteToRender.time - songStartTime) * (float)(2 / 1.5), boardLocation.z + (float).1, boardQuat); Debug.WriteLine("note " + i); noteModel.Draw(notePose.ToMatrix(), Color.White); //TODO: RENDER THE NOTE HERE //unitVectors[3] contains vectors representing if (j == 0 && buffer[i] && noteToRender.time - songStartTime < NOTE_HIT_TIME_MARGIN) { //TODO: ONLY DO THIS IF THE NOTE IS CLOSE TO THE BOTTOM buffer[i] = false; } else { noteQueues[i].Enqueue(noteToRender); } } } if (positionInNotes == notes.Length) { notes = null; } } })) { ; } SK.Shutdown(); }
private void BlownObject() { Hand rightHand = Input.Hand(Handed.Right); Vec3 position; var style = Text.MakeStyle( Font.FromFile("C:/Windows/Fonts/Calibri.ttf"), 4 * Units.cm2m, Material.Copy(DefaultIds.materialFont), Color.HSV(40.2f, 22.7f, 54.6f)); if (rightHand.IsJustPinched && !game_over) { position = rightHand[FingerId.Index, JointId.Tip].position; position.y -= 0.2f; size += 0.1f; //start = true; } if (size >= 0.1f && size <= 2.0f) { sphereModel.Draw(Matrix.TS(Vec3.Zero, size)); if (start == true) { size -= Time.Elapsedf / 20; } } else { objects.Clear(); if (time1 == "") { time1 = String.Format("{00:00:00} sec", Time.Total); } Text.Add("Geme over! Balloon life time sec.: " + time1, Matrix.TRS(new Vec3(0f, 0, 0), Quat.LookDir(0, 0, 1)), style); game_over = true; } }
public void Update() { Hierarchy.Push(Matrix.TRS(V.XYZ(0.5f, -0.25f, -0.5f), Quat.LookDir(-1, 0, 1), 0.2f)); Tests.Screenshot("ProceduralGeometry.jpg", 600, 600, V.XYZ(0.3f, -0.25f, -0.3f), V.XYZ(0.5f, -0.25f, -0.5f)); Tests.Screenshot("ProceduralGrid.jpg", 600, 600, Hierarchy.ToWorld(V.X0Z(-2, -0.7f)), Hierarchy.ToWorld(V.X0Z(-2, 0))); // Plane! Mesh planeMesh = demoPlaneMesh; Model planeModel = demoPlaneModel; /// :CodeSample: Mesh.GeneratePlane /// Drawing both a Mesh and a Model generated this way is reasonably simple, /// here's a short example! For the Mesh, you'll need to create your own material, /// we just loaded up the default Material here. Matrix planeTransform = Matrix.T(-.5f, -1, 0); planeMesh.Draw(Default.Material, planeTransform); planeTransform = Matrix.T(.5f, -1, 0); planeModel.Draw(planeTransform); /// :End: // Cube! Mesh cubeMesh = demoCubeMesh; Model cubeModel = demoCubeModel; /// :CodeSample: Mesh.GenerateCube /// Drawing both a Mesh and a Model generated this way is reasonably simple, /// here's a short example! For the Mesh, you'll need to create your own material, /// we just loaded up the default Material here. // Call this code every Step Matrix cubeTransform = Matrix.T(-.5f, -.5f, 0); cubeMesh.Draw(Default.Material, cubeTransform); cubeTransform = Matrix.T(.5f, -.5f, 0); cubeModel.Draw(cubeTransform); /// :End: // Rounded Cube! Mesh roundedCubeMesh = demoRoundedCubeMesh; Model roundedCubeModel = demoRoundedCubeModel; /// :CodeSample: Mesh Mesh.GenerateRoundedCube Mesh.Draw /// Drawing both a Mesh and a Model generated this way is reasonably simple, /// here's a short example! For the Mesh, you'll need to create your own material, /// we just loaded up the default Material here. // Call this code every Step Matrix roundedCubeTransform = Matrix.T(-.5f, 0, 0); roundedCubeMesh.Draw(Default.Material, roundedCubeTransform); roundedCubeTransform = Matrix.T(.5f, 0, 0); roundedCubeModel.Draw(roundedCubeTransform); /// :End: // Rounded Sphere! Mesh sphereMesh = demoSphereMesh; Model sphereModel = demoSphereModel; /// :CodeSample: Mesh.GenerateSphere /// Drawing both a Mesh and a Model generated this way is reasonably simple, /// here's a short example! For the Mesh, you'll need to create your own material, /// we just loaded up the default Material here. // Call this code every Step Matrix sphereTransform = Matrix.T(-.5f, .5f, 0); sphereMesh.Draw(Default.Material, sphereTransform); sphereTransform = Matrix.T(.5f, .5f, 0); sphereModel.Draw(sphereTransform); /// :End: // Cylinder! Mesh cylinderMesh = demoCylinderMesh; Model cylinderModel = demoCylinderModel; /// :CodeSample: Mesh.GenerateCylinder /// Drawing both a Mesh and a Model generated this way is reasonably simple, /// here's a short example! For the Mesh, you'll need to create your own material, /// we just loaded up the default Material here. // Call this code every Step Matrix cylinderTransform = Matrix.T(-.5f, 1, 0); cylinderMesh.Draw(Default.Material, cylinderTransform); cylinderTransform = Matrix.T(.5f, 1, 0); cylinderModel.Draw(cylinderTransform); /// :End: demoProcMesh.Draw(Default.Material, Matrix.TR(-2, 0, 0, Quat.FromAngles(-90, 0, 0))); Hierarchy.Pop(); Text.Add(title, titlePose); Text.Add(description, descPose, V.XY(0.4f, 0), TextFit.Wrap, TextAlign.TopCenter, TextAlign.TopLeft); }