Exemplo n.º 1
0
        public void AddComponent(H1RayTracerComponent InComponent)
        {
            H1RayTracerComponent Component = RayTracerComponents.Find((e) => { return(InComponent.Descriptor.Id == e.Descriptor.Id); });

            if (Component == null)
            {
                // making sure that there is no overlapped adding on the list
                RayTracerComponents.Add(InComponent);
            }
        }
Exemplo n.º 2
0
        public void RemoveComponent(H1RayTracerComponent InComponent)
        {
            // making sure that there is no dangling
            H1RayTracerComponent Component = RayTracerComponents.Find((e) => { return(InComponent.Descriptor.Id == e.Descriptor.Id); });

            if (Component != null)
            {
                RayTracerComponents.Remove(InComponent);
            }
        }
Exemplo n.º 3
0
        public bool Render()
        {
            H1Entity CameraObject = new H1Entity();
            H1RayTracerCameraComponent RayTracerCameraComponent = new H1RayTracerCameraComponent(CameraObject);

            Int32 ResolutionX = BackBuffer.Width;
            Int32 ResolutionY = BackBuffer.Height;

            H1Vector3 Direction = H1Vector3.Normalize(new H1Vector3(0, 1, -1));

            RayTracerCameraComponent.UpdateCamera(new H1Vector3(0, 0, 500), Direction);
            RayTracerCameraComponent.SetViewFrustum(100, 1000, (float)(30.0 / Math.PI), ResolutionX, ResolutionY);

            // test ray tracer component entity
            H1RayTracerComponent OneComponent = new H1RayTracerComponent(CameraObject);

            OneComponent.Activate();

            float Extent = 25.0f;

            OneComponent.CreateBoxBound(new H1Vector3(0, 500, 0), new H1Vector3(Extent, Extent, Extent));

            H1Ray Ray = new H1Ray(new H1Vector3(0, 0, 500), Direction);
            float T0, T1;

            bool bCollide = OneComponent.IsCollide(Ray, out T0, out T1);

            H1Ray[] Rays = RayTracerCameraComponent.GenerateRays();
            H1RayTracerSystem.Singleton.RayCast(Rays, ref BackBuffer);

            Bitmap NewBitmap = new Bitmap(ResolutionX, ResolutionY);

            for (Int32 PixelY = 0; PixelY < ResolutionY; ++PixelY)
            {
                for (Int32 PixelX = 0; PixelX < ResolutionX; ++PixelX)
                {
                    H1Color PixelColor = BackBuffer[PixelX, PixelY];
                    Color   OutColor   = Color.FromArgb(PixelColor.A, PixelColor.R, PixelColor.G, PixelColor.B);

                    NewBitmap.SetPixel(PixelX, PixelY, OutColor);
                }
            }

            NewBitmap.Save("RayTracerOutput.png", ImageFormat.Png);

            return(true);
        }