protected override void RayTrace() { hits = mTraversal.Query(); }
private static void IntersectionTest() { ICamera Camera; int Width = 320, Height = 200; Camera = new Camera(); Camera.Aspect = (float)Width / (float)Height; Camera.Fov = 30; Camera.RotationVel = 100.0f; Camera.TranslationVel = 500.0f; //sibenik camera position //Camera.LookAt(new Vector3(-19.5f, -10.3f, .8f), new Vector3(0.0f, -13.3f, .8f), Vector3.UnitY); PrimeEngine.Ray[] CreateRays() { var rays = new PrimeEngine.Ray[Width * Height]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { Vector2 d = new Vector2(x, y) / new Vector2(Width, Height) * 2.0f - new Vector2(1.0f); PrimeEngine.Ray ray = new PrimeEngine.Ray { origin = Camera.Position, tmin = 1e-4f, dir = (d.X * Camera.Right + d.Y * Camera.Up + Camera.Look).NormalizedCopy(), tmax = 1e34f }; rays[y * Width + x] = ray; } } return(rays); } using (var engine = new PrimeEngine(RayFormat.OriginDirectionMinMaxInterleaved, RayHitType.Closest, RTPBufferType.CudaLinear, false)) { var modelName = "teapot.obj"; var modelPath = Path.GetFullPath(@"..\..\..\..\Assets\Models\" + modelName); var model = new OBJLoader(modelPath); model.ParseMaterials = false; model.ParseNormals = false; model.GenerateNormals = false; model.GenerateGeometry = false; model.LoadContent(); Camera.CenterOnBoundingBox(model.BBox); var verts = new Vector3[model.Positions.Count]; var tris = new Int3[model.Groups[0].VIndices.Count]; model.Positions.CopyTo(verts); model.Groups[0].VIndices.CopyTo(tris); var indexes = tris.SelectMany(c => new[] { Math.Abs(c.X), Math.Abs(c.Y), Math.Abs(c.Z) }).ToArray(); Console.WriteLine("Setting Mesh"); engine.SetMesh(verts, indexes); Console.WriteLine("Setting Rays"); engine.SetRays(CreateRays()); Console.WriteLine("Querying Prime"); var hits = engine.Query(); Console.WriteLine($"Successful hits {hits.Count(p => p.t < 1e34f && p.t > 1e-4f)}"); } }