public void Factor_120()
        {
            PrimeEngine e = new PrimeEngine(int.MaxValue);

            IEnumerable<int> factors = e.GetPrimeFactors(120);

            string joined = String.Join(",", factors.Select(x => x.ToString()).ToArray());
            Assert.IsTrue(joined.Equals("2,2,2,3,5"));
        }
Esempio n. 2
0
        protected override void Initialize()
        {
            base.Initialize();
            var modelName = "sibenik.obj";
            var modelPath = Path.GetFullPath(@"..\..\..\..\..\Assets\Models\" + modelName);

            mTraversal = new PrimeEngine(RayFormat.OriginDirectionMinMaxInterleaved, RayHitType.Closest);

            var model = new OBJLoader(modelPath);

            model.ParseMaterials   = false;
            model.ParseNormals     = false;
            model.GenerateNormals  = false;
            model.GenerateGeometry = false;
            model.LoadContent();
            SetCamera(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[] { c.X, c.Y, c.Z }).ToArray();

            mTraversal.SetMesh(verts, indexes);

            var numRays = Width * Height;

            rays = CreateRays();
            mTraversal.SetRays(rays);

            mDepths  = new float[numRays];
            mNormals = new Vector3[numRays];

            RaysTracedPerFrame = numRays;
        }
        public void Factor_TooLarge()
        {
            PrimeEngine e = new PrimeEngine(1000);

            IEnumerable<int> factors = e.GetPrimeFactors(5000);
        }
Esempio n. 4
0
        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)}");
            }
        }