Esempio n. 1
0
        private void AddBoxAndBoxBooleanTest()
        {
            RayTracer.BoxShape box1 = new RayTracer.BoxShape(new Vector3(.5, .5, .5), new Vector3(1.5, 1.5, 1.5),
                                                             new RayTracer.SolidMaterial(RGBA_Floats.Green, .01, 0.0, 2.0));

            List <RayTracer.IRayTraceable> subtractShapes = new List <RayTracer.IRayTraceable>();

            RayTracer.SolidMaterial material = new RayTracer.SolidMaterial(RGBA_Floats.Red, 0, 0, 0);
            subtractShapes.Add(new BoxShape(new Vector3(), new Vector3(1, 1, 1), material));

            RayTracer.IRayTraceable subtractGroup = RayTracer.BoundingVolumeHierarchy.CreateNewHierachy(subtractShapes);
            Difference merge = new Difference(box1, subtractGroup);

            renderCollection.Add(merge);
        }
Esempio n. 2
0
        public override void OnMouseDown(MouseEventArgs mouseEvent)
        {
            base.OnMouseDown(mouseEvent);

            Vector2 lastMouseMovePoint;

            lastMouseMovePoint.x = mouseEvent.X;
            lastMouseMovePoint.y = mouseEvent.Y;

            if (Focused && MouseCaptured)
            {
                if (trackBallController.CurrentTrackingType == TrackBallController.MouseDownType.None)
                {
                    if (Focused && MouseCaptured && mouseEvent.Button == MouseButtons.Left)
                    {
                        trackBallController.OnMouseDown(lastMouseMovePoint, Matrix4X4.Identity);
                    }
                    else if (mouseEvent.Button == MouseButtons.Middle)
                    {
                        trackBallController.OnMouseDown(lastMouseMovePoint, Matrix4X4.Identity, TrackBallController.MouseDownType.Translation);
                    }
                }

                if (MouseCaptured)
                {
                    lastMouseMovePoint.x             = mouseEvent.X;
                    lastMouseMovePoint.y             = mouseEvent.Y;
                    cameraDataAtStartOfMouseTracking = cameraData;
                    cameraDataAtStartOfMouseTracking.cameraMatrix = scene.camera.axisToWorld;

                    Ray rayAtPoint = scene.camera.GetRay(lastMouseMovePoint.x, lastMouseMovePoint.y);

                    IntersectInfo info = raytracer.TestIntersection(rayAtPoint, scene);
                    if (info != null)
                    {
                        focusedObject = (BaseShape)info.closestHitObject;
                        if (focusedObject != null && mouseEvent.Clicks == 2)
                        {
                            cameraData.lookAtPoint = focusedObject.GetAxisAlignedBoundingBox().Center;
                            OrientCamera();
                        }
                    }
                }
                needRedraw = true;
                Invalidate();
            }
        }
Esempio n. 3
0
        private void SetupScene(int width, int height)
        {
            //Vector3D bunnyCenter = loadedPlyFile.GetScanAsSpheres().GetAxisAlignedBoundingBox().Center;

            scene            = new RayTracer.Scene();
            scene.camera     = new RayTracer.Camera(width, height, MathHelper.DegreesToRadians(40));
            scene.background = new RayTracer.Background(new RGBA_Floats(0.5, .5, .5), 0.4);

            //AddBoxAndSheresBooleanTest();
            //AddBoxAndBoxBooleanTest();
#if false
            renderCollection.Add(new BoxShape(new Vector3(), new Vector3(1, 1, 1),
                                              new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0)));
            renderCollection.Add(new BoxShape(new Vector3(.5, .5, .5), new Vector3(1.5, 1.5, 1.5),
                                              new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0)));
#endif
            //renderCollection.Add(new CylinderShape(.25, 1, new SolidMaterial(RGBA_Floats.Cyan, 0, 0, 0)));

            //AddSphereAndBox();
            //AddAxisMarker();
            //AddCubeOfShperes();

            renderCollection.Add(MakerGearXCariage());

            allObjects         = BoundingVolumeHierarchy.CreateNewHierachy(renderCollection);
            trackBallTransform = new Transform(allObjects);
            //allObjects = root;
            scene.shapes.Add(trackBallTransform);

            //AddAFloor();

            //add two lights for better lighting effects
            scene.lights.Add(new Light(new Vector3(50, -10, 100), new RGBA_Floats(0.8, 0.8, 0.8)));
            scene.lights.Add(new Light(new Vector3(-30, -150, 50), new RGBA_Floats(0.8, 0.8, 0.8)));

            OrientCamera();
        }
        public override void OnMouseDown(MouseEventArgs mouseEvent)
        {
            base.OnMouseDown(mouseEvent);

            Vector2 lastMouseMovePoint;
            lastMouseMovePoint.x = mouseEvent.X;
            lastMouseMovePoint.y = mouseEvent.Y;

            if (Focused && MouseCaptured)
            {
                if (trackBallController.CurrentTrackingType == TrackBallController.MouseDownType.None)
                {
                    if (Focused && MouseCaptured && mouseEvent.Button == MouseButtons.Left)
                    {
                        trackBallController.OnMouseDown(lastMouseMovePoint, Matrix4X4.Identity);
                    }
                    else if (mouseEvent.Button == MouseButtons.Middle)
                    {
                        trackBallController.OnMouseDown(lastMouseMovePoint, Matrix4X4.Identity, TrackBallController.MouseDownType.Translation);
                    }
                }

                if (MouseCaptured)
                {
                    lastMouseMovePoint.x = mouseEvent.X;
                    lastMouseMovePoint.y = mouseEvent.Y;
                    cameraDataAtStartOfMouseTracking = cameraData;
                    cameraDataAtStartOfMouseTracking.cameraMatrix = scene.camera.axisToWorld;

                    Ray rayAtPoint = scene.camera.GetRay(lastMouseMovePoint.x, lastMouseMovePoint.y);

                    IntersectInfo info = raytracer.TestIntersection(rayAtPoint, scene);
                    if (info != null)
                    {
                        focusedObject = (BaseShape)info.closestHitObject;
                        if (focusedObject != null && mouseEvent.Clicks == 2)
                        {
                            cameraData.lookAtPoint = focusedObject.GetAxisAlignedBoundingBox().Center;
                            OrientCamera();
                        }
                    }
                }
                needRedraw = true;
                Invalidate();
            }
        }
        private void SetupScene(int width, int height)
        {
            //Vector3D bunnyCenter = loadedPlyFile.GetScanAsSpheres().GetAxisAlignedBoundingBox().Center;

            scene = new RayTracer.Scene();
            scene.camera = new RayTracer.Camera(width, height, MathHelper.DegreesToRadians(40));
            scene.background = new RayTracer.Background(new RGBA_Floats(0.5, .5, .5), 0.4);
            
            //AddBoxAndSheresBooleanTest();
            //AddBoxAndBoxBooleanTest();
#if false
            renderCollection.Add(new BoxShape(new Vector3(), new Vector3(1, 1, 1),
                               new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0)));
            renderCollection.Add(new BoxShape(new Vector3(.5,.5,.5), new Vector3(1.5, 1.5, 1.5),
                               new SolidMaterial(new RGBA_Floats(.9, .2, .1), .01, 0.0, 2.0)));
#endif
            //renderCollection.Add(new CylinderShape(.25, 1, new SolidMaterial(RGBA_Floats.Cyan, 0, 0, 0)));

            //AddSphereAndBox();
            //AddAxisMarker();
            //AddCubeOfShperes();

            renderCollection.Add(MakerGearXCariage());

            allObjects = BoundingVolumeHierarchy.CreateNewHierachy(renderCollection);
            trackBallTransform = new Transform(allObjects);
            //allObjects = root;
            scene.shapes.Add(trackBallTransform);

            //AddAFloor();

            //add two lights for better lighting effects
            scene.lights.Add(new Light(new Vector3(50, -10, 100), new RGBA_Floats(0.8, 0.8, 0.8)));
            scene.lights.Add(new Light(new Vector3(-30, -150, 50), new RGBA_Floats(0.8, 0.8, 0.8)));

            OrientCamera();
        }