public override void Render() { base.Render(); DrawOrigin(); Point result = new Point(); foreach (Line line in lines) { if (LinesAndRays.LinecastAABB(line, aabb, out result)) { GL.Color3(1f, 0f, 1f); result.Render(); GL.Color3(0f, 2f, 0f); } else { GL.Color3(1f, 0f, 0f); } line.Render(); } GL.Color3(0f, 0f, 1f); aabb.Render(); }
public override void Render() { base.Render(); DrawOrigin(); GL.Color3(1f, 1f, 1f); test.Render(5f); float t; foreach (Ray ray in rays) { if (LinesAndRays.RaycastPlane(ray, test, out t)) { Point colPoint = new Point(); LinesAndRays.RaycastPlane(ray, test, out colPoint); GL.Color3(0f, 1f, 0f); colPoint.Render(); GL.Color3(1f, 0f, 0f); } else { GL.Color3(0f, 0f, 1f); } ray.Render(); } }
public override void Render() { //GL.Enable(EnableCap.CullFace); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); base.Render(); DrawOrigin(); GL.Color3(1f, 0f, 0f); for (int i = 0; i < 3; ++i) { touples[i].sphere.Render(); } GL.Color3(0f, 1f, 0f); foreach (Touple touple in touples) { touple.ray.Render(); if (touple.result) { Point p = new Point(); LinesAndRays.RaycastSphere(touple.ray, touple.sphere, out p); GL.Color3(0f, 0f, 1f); p.Render(); GL.Color3(0f, 1f, 0f); } } }
public static bool OBJRaycast(OBJ model, Ray ray, out float t) { if (model.IsEmpty) { t = -1; return(false); } Matrix4 inverseWorld = Matrix4.Inverse(model.WorldMatrix); Vector3 newRayPos = Matrix4.MultiplyPoint(inverseWorld, ray.Position.ToVector()); Vector3 newRayNorm = Matrix4.MultiplyVector(inverseWorld, ray.Normal); Ray newRay = new Ray(newRayPos, newRayNorm); //ray boundingbox if (!LinesAndRays.RaycastAABB(newRay, model.BoundingBox, out t)) { return(false); } //ray boundingSphere if (!LinesAndRays.RaycastSphere(newRay, model.BoundingSphere, out t)) { return(false); } return(LinesAndRays.RaycastBVH(newRay, model.BVHRoot, out t)); }
public override void Initialize(int width, int height) { GL.Enable(EnableCap.DepthTest); GL.PointSize(5f); GL.Enable(EnableCap.CullFace); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); foreach (Touple touple in touples) { float t = 0f; if (LinesAndRays.RaycastSphere(touple.ray, touple.sphere, out t) != touple.result) { LogError("Expected ray: " + touple.ray + "\nTo " + (touple.result ? "intersect" : "not intersect") + " sphere: " + touple.sphere); } } }
public OBJ Raycast(Ray ray, out float t) { debugVisited = true; //none leaf nodes if (Children != null) { foreach (OctreeNode child in Children) { //AABB Ray intersection? if (LinesAndRays.RaycastAABB(ray, child.Bounds, out t)) { //recursively call raycast OBJ result = child.Raycast(ray, out t); //return whatever is hit if (result != null) { return(result); } } } } //leaf node //bounds already intersect ray else if (Contents != null) { //loop through all children foreach (OBJ content in Contents) { //return first hit child if (Intersects.OBJRaycast(ray, content, out t)) { return(content); } } } t = 0f; return(null); }
public override void Initialize(int width, int height) { GL.Enable(EnableCap.DepthTest); GL.PointSize(5f); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); aabb.Max = new Point(2, 2, 2); aabb.Min = new Point(-2, -2, -2); bool[] results = new bool[] { false, false, true, true }; Point result = new Point(); for (int i = 0; i < results.Length; ++i) { if (LinesAndRays.LinecastAABB(lines[i], aabb, out result) != results[i]) { LogError("Line at index " + i + " was " + (results[i] ? " expected" : " not expected") + " to intersect the test aabb"); } } }
public override void Initialize(int width, int height) { GL.Enable(EnableCap.DepthTest); GL.PointSize(5f); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); bool[] results = new bool[] { false, false, false, false, true, true, true }; float t; for (int i = 0; i < results.Length; ++i) { if (LinesAndRays.RaycastPlane(rays[i], test, out t) != results[i]) { LogError("Expected ray at index: " + i + " to " + (results[i] ? "intersect" : "not intersect") + " the plane"); } } }
public override void Initialize(int width, int height) { GL.Enable(EnableCap.DepthTest); GL.PointSize(5f); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); plane.Normal = new Vector3(1, 1, 0); plane.Distance = 1; bool[] results = new bool[] { false, true, false, false, true, false }; Point result = new Point(); for (int i = 0; i < results.Length; ++i) { if (LinesAndRays.LinecastPlane(lines[i], plane, out result) != results[i]) { LogError("Line at index " + i + " was " + (results[i] ? "expected" : "not expected") + "to intersect the test plane"); } } }
public override void Render() { base.Render(); DrawOrigin(); GL.Color3(0f, 1f, 0f); test.Render(); float t; foreach (Ray ray in rays) { if (LinesAndRays.RaycastAABB(ray, test, out t)) { GL.Color3(1f, 0f, 0f); } else { GL.Color3(0f, 0f, 1f); } ray.Render(); } }
public override void Initialize(int width, int height) { GL.Enable(EnableCap.DepthTest); GL.PointSize(5f); GL.Enable(EnableCap.CullFace); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); sphere.Position = new Point(0f, 0f, 0f); sphere.Radius = 2; bool[] results = new bool[] { false, false, true }; Point result = new Point(); for (int i = 0; i < results.Length; ++i) { if (LinesAndRays.LinecastSphere(lines[i], sphere, out result) != results[i]) { LogError("Line at index " + i + " was " + (results[i] ? "expected" : "not expected") + "to intersect the test SPHERE"); } } }
public override void Update(float deltaTime) { // Don't rotate the scene //base.Update(deltaTime); float[] viewport = new float[] { 0f, 0f, Window.Width, Window.Height }; Vector3 near = Matrix4.Unproject(new Vector3(Window.Mouse.X, Window.Mouse.Y, 0.0f), modelView, projection, viewport); Vector3 far = Matrix4.Unproject(new Vector3(Window.Mouse.X, Window.Mouse.Y, 1.0f), modelView, projection, viewport); debugRay = new Ray(near, Vector3.Normalize(far - near)); Point p = new Point(); if (LinesAndRays.RaycastAABB(debugRay, debugBox, out p)) { debugSphere.Position = p; } else { // Off-screen debugSphere.Position = new Point(-5000, -5000, -5000); } }