()
| 25 | Vec3 screenshotAt = new Vec3(0,0,0); |
| 26 | |
| 27 | public void Step() |
| 28 | { |
| 29 | Color colIntersect = Color.HSV(0, 0.8f, 1); |
| 30 | Color colTest = Color.HSV(0, 0.6f, 1); |
| 31 | Color colObj = Color.HSV(0.05f, 0.7f, 1); |
| 32 | Color active = new Color(1,1,1,0.7f); |
| 33 | Color notActive = new Color(1, 1, 1, 1); |
| 34 | |
| 35 | // Plane and Ray |
| 36 | bool planeRayActive = UI.HandleBegin("PlaneRay", ref posePlaneRay, new Bounds(Vec3.One*0.1f)); |
| 37 | Mesh.Cube.Draw(Material.UIBox, Matrix.S(0.1f), planeRayActive ? active:notActive); |
| 38 | |
| 39 | Plane ground = new Plane(new Vec3(1,2,0), 0); |
| 40 | Ray groundRay = new Ray(Vec3.Zero + new Vec3(0,0.05f,0), Vec3.AngleXZ(Time.Totalf*90, -2).Normalized); |
| 41 | |
| 42 | Lines.Add(groundRay.position, groundRay.At(0.1f), new Color32(255, 0, 0, 255), 2 * Units.mm2m); |
| 43 | planeMesh.Draw(Material.Default, Matrix.TRS(Vec3.Zero, Quat.LookDir(ground.normal), 0.0625f), colObj); |
| 44 | if (groundRay.Intersect(ground, out Vec3 groundAt)) |
| 45 | Mesh.Sphere.Draw(Material.Default, Matrix.TS(groundAt, 0.005f), colIntersect); |
| 46 | |
| 47 | UI.HandleEnd(); |
| 48 | |
| 49 | Tests.Screenshot("RayIntersectPlane.jpg", 0, 400, 400, 20, posePlaneRay.position + screenshotFrom, posePlaneRay.position + screenshotAt); |
| 50 | |
| 51 | // Line and Plane |
| 52 | bool linePlaneActive = UI.HandleBegin("LinePlane", ref poseLinePlane, new Bounds(Vec3.One * 0.1f)); |
| 53 | Mesh.Cube.Draw(Material.UIBox, Matrix.S(0.1f), linePlaneActive ? active : notActive); |
| 54 | |
| 55 | Plane groundLinePlane = new Plane(new Vec3(1,2,0), 0); |
| 56 | Ray groundLineRay = new Ray (Vec3.Zero + new Vec3(0,0.0625f,0), Vec3.AngleXZ(Time.Totalf*90, -2).Normalized); |
| 57 | Vec3 groundLineP1 = groundLineRay.At((SKMath.Cos(Time.Totalf*3)+1)*0.05f); |
| 58 | Vec3 groundLineP2 = groundLineRay.At((SKMath.Cos(Time.Totalf*3)+1)*0.05f+ 0.025f); |
| 59 | |
| 60 | Lines.Add(groundLineP1, groundLineP2, colTest, 2 * Units.mm2m); |
| 61 | Mesh.Sphere.Draw(Material.Default, Matrix.TS(groundLineP1, 0.0025f), colTest); |
| 62 | Mesh.Sphere.Draw(Material.Default, Matrix.TS(groundLineP2, 0.0025f), colTest); |
| 63 | bool groundLineIntersects = groundLinePlane.Intersect(groundLineP1, groundLineP2, out Vec3 groundLineAt); |
| 64 | planeMesh.Draw(Material.Default, Matrix.TRS(Vec3.Zero, Quat.LookDir(groundLinePlane.normal), 0.0625f), groundLineIntersects? colIntersect : colObj); |
| 65 | if (groundLineIntersects) |
| 66 | Mesh.Sphere.Draw(Material.Default, Matrix.TS(groundLineAt, 0.005f), colIntersect); |
| 67 | |
| 68 | UI.HandleEnd(); |
| 69 | |
| 70 | Tests.Screenshot("LineIntersectPlane.jpg", 0, 400, 400, 20, poseLinePlane.position + screenshotFrom, poseLinePlane.position + screenshotAt); |
| 71 | |
| 72 | // Sphere and Ray |
| 73 | bool sphereRayActive = UI.HandleBegin("SphereRay", ref poseSphereRay, new Bounds(Vec3.One * 0.1f)); |
| 74 | Mesh.Cube.Draw(Material.UIBox, Matrix.S(0.1f), sphereRayActive ? active : notActive); |
| 75 | |
| 76 | Sphere sphere = new Sphere(Vec3.Zero, 0.0625f); |
| 77 | Vec3 sphereDir = Vec3.AngleXZ(Time.Totalf*90, SKMath.Cos(Time.Totalf * 3) * 0.375f + 0.05f).Normalized; |
| 78 | Ray sphereRay = new Ray(sphere.center - sphereDir * 0.0875f, sphereDir); |
| 79 | |
| 80 | Lines.Add(sphereRay.position, sphereRay.At(0.05f), colTest, 2 * Units.mm2m); |
| 81 | if (sphereRay.Intersect(sphere, out Vec3 sphereAt)) |
| 82 | Mesh.Sphere.Draw(Material.Default, Matrix.TS(sphereAt, 0.005f), colIntersect); |
| 83 | Mesh.Sphere.Draw(Material.Default, Matrix.TS(sphere.center, 0.0625f), colObj); |
| 84 |
nothing calls this directly
no test coverage detected