Ejemplo n.º 1
0
        public RayGroup(bool divide, double maxLength,
                        Rectangle area, ISceneManager scene, IRayDispatch dispatch,
                        FrameData frameData, CameraView view)
        {
            this.divide = divide;
            this.maxLength = maxLength;
            this.area = area;

            this.scene = scene;
            this.dispatch = dispatch;
            this.frameData = frameData;
            this.view = view;
        }
Ejemplo n.º 2
0
        public void CollectData()
        {
            //Rectangle3D rect = new Rectangle3D(new Vector3D(-5, 0, -5), new Vector3D(5, 0, 5), new PlaneD(new Vector3D(0, 1, 0), 0));
            //Vector3D iPoint;
            //bool result = rect.IntersectWithLine(new Vector3D(5, 5, 0), new Vector3D(0, -1, 0), out iPoint);

            // create frame buffer to store data
            buffer = new FrameData(viewArea.Width, viewArea.Height, false, Color.Black);

            CameraView cView = new CameraView();

            cView.Centre    = new Vector3D(3, 5, 3);
            cView.Direction = cView.Centre - new Vector3D(0, 0, 0);
            cView.Direction.Normalize();
            cView.XUV = Vector3D.Cross(cView.Direction, Vector3D.Up);
            cView.XUV.Normalize();
            cView.YUV = Vector3D.Cross(cView.XUV, cView.Direction);
            cView.YUV.Normalize();
            cView.ViewArea = new Vector2D(1, 1);
            Vector3D halfX = cView.XUV * 0.5 * cView.ViewArea.X;
            Vector3D halfY = cView.YUV * 0.5 * cView.ViewArea.Y;

            cView.Corners = new Vector3D[] { cView.Centre - halfX + halfY, // top left
                                             cView.Centre + halfX + halfY, // top right
                                             cView.Centre - halfX - halfY, // bottom left
                                             cView.Centre + halfX - halfY  // bottom right
            };
            cView.Frustum = new PlaneD[] { PlaneD.FromPointNormal(cView.Corners[0], -cView.XUV),
                                           PlaneD.FromPointNormal(cView.Corners[1], cView.XUV),
                                           PlaneD.FromPointNormal(cView.Corners[2], cView.YUV),
                                           PlaneD.FromPointNormal(cView.Corners[3], -cView.YUV) };
            cView.Area            = viewArea;
            cView.ProjectionScale = new Vector2D(0.2, 0.2);

            texture = Bitmap.FromFile("c:/checkers2.bmp");
            //Bitmap texture2 = (Bitmap)Bitmap.FromFile("c:/newheightmap.jpg");

            // setup temp scene
            SimpleSceneManager scene = new SimpleSceneManager(new RGBA_D(0.2, 0.2, 0.2, 1));

            /*scene.AddObject(new TriangleGroupSceneObject(new Vector3D(0, 0, 2),
             *                                           new MaterialShader(new RGBA_D(1, 1, 1, 1),
             *                                                              15, 0.1, 0, 0, 1),
             *                                           1.1));*/
            /*scene.AddObject(new SphereSceneObject(new Vector3D(0, 0, 0),
             *                                    new MaterialShader(new RGBA_D(0, 0, 1, 1),
             *                                                       15, 0, 0, 0, 1),
             *                                    1));*/
            /*scene.AddObject(new SphereSceneObject(new Vector3D(0, 0, 0),
             *                                    new MaterialShader(new RGBA_D(1, 0, 0, 1),
             *                                                       15, 1, 0, 0, 1),
             *                                    1));
             * scene.AddObject(new SphereSceneObject(new Vector3D(-3, -1, -3),
             *                                    new MaterialShader(new RGBA_D(0.2, 1, 0.1, 1),
             *                                                       15, 0, 0, 0, 1, texture2),
             *                                    1));
             * scene.AddObject(new SphereSceneObject(new Vector3D(2, 0, 0),
             *                                    new MaterialShader(new RGBA_D(1, 1, 0, 1),
             *                                                       10, 0.1, 0, 0, 1),
             *                                    1));
             * scene.AddObject(new SphereSceneObject(new Vector3D(0.5, 1, 0),
             *                                    new MaterialShader(new RGBA_D(1, 1, 1, 1),
             *                                                       5, 0, 0, 0, 1, texture),
             *                                    0.8));
             *
             * scene.AddObject(new PlaneSceneObject(new Vector3D(0, -5, 0), new Vector3D(0, 1, 0),
             *                                   new MaterialShader(new RGBA_D(0.1, 0.1, 0.1, 1.0),
             *                                                      5, 0, 0, 0, 1), -1));
             */
            scene.AddObject(new HeightFieldObject(new Vector3D(),
                                                  new MaterialShader(new RGBA_D(1, 1, 1, 1),
                                                                     5, 0, 0, 0, 1, texture),
                                                  new Vector2D(2, 2), (Bitmap)texture));

            /*
             * IOpticalSceneObject obj;
             * Vector3D iPos;
             * double iDist;
             * uint subIdx;
             * scene.GetFirstIntersection(new Vector3D(10, 0.5, 0), new Vector3D(1, 0, 0), 100, out obj, out iPos, out iDist, out subIdx);
             */
            // collect data
            DateTime start        = DateTime.Now;
            RayGroup initialGroup = new RayGroup(true, 100,
                                                 cView.Area, scene, null, buffer, cView);

            rayDispatch.DispatchRayGroupReq(initialGroup);

            rayDispatch.WaitForCompletion();
            DateTime end  = DateTime.Now;
            TimeSpan time = end - start;

            string aaFilter = buffer.AALayer != null ? "true[5_point_star]" : "false";

            stats = string.Format("threads={0} rays={1} pixels={2} time={3}ms AA={4}", rayDispatch.ProcessedThreads,
                                  rayDispatch.ProcessedRays,
                                  viewArea.Width * viewArea.Height,
                                  time.TotalMilliseconds,
                                  aaFilter);
        }
Ejemplo n.º 3
0
        public void CollectData()
        {
            //Rectangle3D rect = new Rectangle3D(new Vector3D(-5, 0, -5), new Vector3D(5, 0, 5), new PlaneD(new Vector3D(0, 1, 0), 0));
            //Vector3D iPoint;
            //bool result = rect.IntersectWithLine(new Vector3D(5, 5, 0), new Vector3D(0, -1, 0), out iPoint);

            // create frame buffer to store data
            buffer = new FrameData(viewArea.Width, viewArea.Height, false, Color.Black);

            CameraView cView = new CameraView();
            cView.Centre = new Vector3D(3, 5, 3);
            cView.Direction = cView.Centre - new Vector3D(0, 0, 0);
            cView.Direction.Normalize();
            cView.XUV = Vector3D.Cross(cView.Direction, Vector3D.Up);
            cView.XUV.Normalize();
            cView.YUV = Vector3D.Cross(cView.XUV, cView.Direction);
            cView.YUV.Normalize();
            cView.ViewArea = new Vector2D(1, 1);
            Vector3D halfX = cView.XUV * 0.5 * cView.ViewArea.X;
            Vector3D halfY = cView.YUV * 0.5 * cView.ViewArea.Y;
            cView.Corners = new Vector3D[] { cView.Centre - halfX + halfY, // top left
                                             cView.Centre + halfX + halfY, // top right
                                             cView.Centre - halfX - halfY, // bottom left
                                             cView.Centre + halfX - halfY // bottom right
                                           };
            cView.Frustum = new PlaneD[] { PlaneD.FromPointNormal(cView.Corners[0], -cView.XUV),
                                           PlaneD.FromPointNormal(cView.Corners[1], cView.XUV),
                                           PlaneD.FromPointNormal(cView.Corners[2], cView.YUV),
                                           PlaneD.FromPointNormal(cView.Corners[3], -cView.YUV)
                                         };
            cView.Area = viewArea;
            cView.ProjectionScale = new Vector2D(0.2, 0.2);

            texture = Bitmap.FromFile("c:/checkers2.bmp");
            //Bitmap texture2 = (Bitmap)Bitmap.FromFile("c:/newheightmap.jpg");

            // setup temp scene
            SimpleSceneManager scene = new SimpleSceneManager(new RGBA_D(0.2, 0.2, 0.2, 1));

            /*scene.AddObject(new TriangleGroupSceneObject(new Vector3D(0, 0, 2),
                                                         new MaterialShader(new RGBA_D(1, 1, 1, 1),
                                                                            15, 0.1, 0, 0, 1),
                                                         1.1));*/
            /*scene.AddObject(new SphereSceneObject(new Vector3D(0, 0, 0),
                                                  new MaterialShader(new RGBA_D(0, 0, 1, 1),
                                                                     15, 0, 0, 0, 1),
                                                  1));*/
            /*scene.AddObject(new SphereSceneObject(new Vector3D(0, 0, 0),
                                                  new MaterialShader(new RGBA_D(1, 0, 0, 1),
                                                                     15, 1, 0, 0, 1),
                                                  1));
            scene.AddObject(new SphereSceneObject(new Vector3D(-3, -1, -3),
                                                  new MaterialShader(new RGBA_D(0.2, 1, 0.1, 1),
                                                                     15, 0, 0, 0, 1, texture2),
                                                  1));
            scene.AddObject(new SphereSceneObject(new Vector3D(2, 0, 0),
                                                  new MaterialShader(new RGBA_D(1, 1, 0, 1),
                                                                     10, 0.1, 0, 0, 1),
                                                  1));
            scene.AddObject(new SphereSceneObject(new Vector3D(0.5, 1, 0),
                                                  new MaterialShader(new RGBA_D(1, 1, 1, 1),
                                                                     5, 0, 0, 0, 1, texture),
                                                  0.8));
            
            scene.AddObject(new PlaneSceneObject(new Vector3D(0, -5, 0), new Vector3D(0, 1, 0),
                                                 new MaterialShader(new RGBA_D(0.1, 0.1, 0.1, 1.0),
                                                                    5, 0, 0, 0, 1), -1));
            */
            scene.AddObject(new HeightFieldObject(new Vector3D(),
                                                  new MaterialShader(new RGBA_D(1, 1, 1, 1),
                                                                     5, 0, 0, 0, 1, texture),
                                                  new Vector2D(2, 2), (Bitmap)texture));
            /*
            IOpticalSceneObject obj;
            Vector3D iPos;
            double iDist;
            uint subIdx;
            scene.GetFirstIntersection(new Vector3D(10, 0.5, 0), new Vector3D(1, 0, 0), 100, out obj, out iPos, out iDist, out subIdx);
            */
            // collect data
            DateTime start = DateTime.Now;
            RayGroup initialGroup = new RayGroup(true, 100,
                                                 cView.Area, scene, null, buffer, cView);
            rayDispatch.DispatchRayGroupReq(initialGroup);

            rayDispatch.WaitForCompletion();
            DateTime end = DateTime.Now;
            TimeSpan time = end - start;

            string aaFilter = buffer.AALayer != null ? "true[5_point_star]" : "false"; 
            stats = string.Format("threads={0} rays={1} pixels={2} time={3}ms AA={4}", rayDispatch.ProcessedThreads,
                                                                                rayDispatch.ProcessedRays,
                                                                                viewArea.Width * viewArea.Height,
                                                                                time.TotalMilliseconds,
                                                                                aaFilter);
        }
Ejemplo n.º 4
0
        public bool TestForContents(CameraView view, Rectangle area, double length)
        {
            // TODO: Not working when y is high and other axis are low
            double xScale = 0.5 / view.Area.Width;//area.Width;
            double yScale = 0.5 / view.Area.Height;//area.Height;

            // project a simple rectangle out (6xplane)
            double xShift = -0.25 + (xScale * area.Left);
            double yShift = 0;
            Vector3D offset = ((view.XUV * xShift) + (view.YUV * yShift));
            Vector3D rayDir = offset + view.Direction;
            rayDir.Normalize();
            PlaneD left = PlaneD.FromPointNormal(view.Centre, rayDir.Cross(Vector3D.Up));

            xShift = -0.25 + (xScale * area.Right);
            offset = ((view.XUV * xShift) + (view.YUV * yShift));
            rayDir = offset + view.Direction;
            rayDir.Normalize();
            PlaneD right = PlaneD.FromPointNormal(view.Centre, -rayDir.Cross(Vector3D.Up));

            xShift = 0;
            yShift = -0.25 + (yScale * area.Top);
            offset = ((view.XUV * xShift) + (view.YUV * yShift));
            rayDir = offset + view.Direction;
            rayDir.Normalize();
            PlaneD top = PlaneD.FromPointNormal(view.Centre, -rayDir.Cross(view.XUV));

            yShift = -0.25 + (yScale * area.Bottom);
            offset = (view.XUV * xShift) + (view.YUV * yShift);
            rayDir = offset + view.Direction;
            rayDir.Normalize();
            PlaneD bottom = PlaneD.FromPointNormal(view.Centre, rayDir.Cross(view.XUV));

            // test all objects until we get a hit
            foreach (IOpticalSceneObject obj in objects)
            {
                if (obj.Radius != -1)
                {
                    double leftD = left.DistanceToPoint(obj.Origin);
                    double rightD = right.DistanceToPoint(obj.Origin);
                    double topD = top.DistanceToPoint(obj.Origin);
                    double bottomD = bottom.DistanceToPoint(obj.Origin);
                    if (leftD - obj.Radius <= 0 &&
                        rightD - obj.Radius <= 0 &&
                        topD - obj.Radius <= 0 &&
                        bottomD - obj.Radius <= 0)
                        return true;
                }
                else
                    return true;
            }
            return false;
        }