예제 #1
0
        public VirtualProjector(string name, string uuid, Size imageSize, PointF principal, double focalLength, Screen screen, Chessboard chessboard, CaptureCamera captureCamera)
            : base(name, uuid, imageSize, principal, focalLength, screen, chessboard, captureCamera)
        {
            OrbitCamera = new OrbitCamera("{0} Orbit".FormatWith(name), "N/A", imageSize, principal, focalLength,
                Intrinsics.NearPlaneDistance, Intrinsics.FarPlaneDistance) { Color = Color.DarkCyan.Alpha(0.7f), };
            Color = Color.DarkKhaki.Alpha(0.6f);
            
            ProgramTask.AttachInputToCamera(Program.WhenInput.Where(input => !input.KeyPressed(Keys.C)), Window, OrbitCamera);

            Program.WhenInput.Where(input => input.KeyDown(Keys.P)).Subscribe(input =>
            {
                var frustum = new Frustum(OrbitCamera, Intrinsics.ImageSize);

                var plane = new Plane(Vector3.UnitZ, 0);

                var p0 = frustum.IntersectWithPlane(ProjectorQuadCorners[0].X, ProjectorQuadCorners[0].Y, plane).ToPointF();
                var p1 = frustum.IntersectWithPlane(ProjectorQuadCorners[1].X, ProjectorQuadCorners[1].Y, plane).ToPointF();
                var p2 = frustum.IntersectWithPlane(ProjectorQuadCorners[2].X, ProjectorQuadCorners[2].Y, plane).ToPointF();
                var p3 = frustum.IntersectWithPlane(ProjectorQuadCorners[3].X, ProjectorQuadCorners[3].Y, plane).ToPointF();

                var quadCorners = new[] { p0, p1, p2, p3, };

                // Chessboard.HomographTo(quadCorners);
            });
        }
예제 #2
0
        public VirtualProjector(Window window, OrbitCamera orbitCamera)
            : base("Null", "N/A", orbitCamera.Intrinsics.ImageSize, orbitCamera.Intrinsics.PrincipalPoint, orbitCamera.Intrinsics.FocalLength)
        {
            Color = Color.Yellow;
            Scene = new Scene(ViewProject.Identity);
            Window = window;

            View = orbitCamera.View;
            World = orbitCamera.World;

            OrbitCamera = orbitCamera;
        }
예제 #3
0
        public ProgramTask()
        {
            Monitor.ClientSize = new Size(640, 480);
            ColoredChessboard = new ColoredChessboard(Chessboard, Color.CornflowerBlue.Alpha(0.9f), Color.Orange.Alpha(0.3f));

            var maybeSecondaryScreen = Screen.AllScreens.Where(s => s != Screen.PrimaryScreen).FirstOrDefault() ?? Screen.PrimaryScreen;

            // Projector = new RealProjector("Optoma EW1610", "1018", maybeSecondaryScreen.Bounds.Size, maybeSecondaryScreen);
            var virtualProjectorOrbit = new OrbitCamera("Virtual Projector Orbit", "N/A", new Size(1280, 800), new PointF(640, 850), 100, 2, 134);
            Projector = new VirtualProjector(Monitor, virtualProjectorOrbit);

            WorldCamera = new OrbitCamera("World Orbit", "1018", Monitor.Size, Monitor.Size.CenterF(), Monitor.Size.Width, 0.1f, 100)
            {
                Center = Chessboard.VertexCenter,
                Distance = 56,
                YawPitch = new Vector2(0.2f, -0.2f),
            };

            WorldScene = new Scene(WorldCamera)
            {
                // MakeColoredAxisOfLength(Vector3.UnitX, Color.Red, length: 20.0f),
                // MakeColoredAxisOfLength(Vector3.UnitY, Color.Green, length: 20.0f),
                // MakeColoredAxisOfLength(Vector3.UnitZ, Color.Blue, length: 20.0f),
                
                // ColoredChessboard,

                // new Grid(Matrix.CreateRotationX(MathHelper.PiOver2),  Color.Red.Lerp(Color.White, 0.9f).Alpha(0.3f), Color.Red.Alpha(0.5f)),
                // new Grid(Matrix.CreateRotationY(-MathHelper.PiOver2), Color.Green.Lerp(Color.White, 0.9f).Alpha(0.1f), Color.Green.Alpha(0.3f)),
                // new Grid(Matrix.Identity,                             Color.Blue.Lerp(Color.White, 0.9f).Alpha(0.1f), Color.Blue.Alpha(0.4f)),

                new MeshModel("ManStanding", Matrix.CreateScale(0.1f) * Matrix.CreateRotationY(-MathHelper.PiOver2) * Matrix.CreateTranslation(4, 0, 2)) { ProjectorViewProject = Projector },
                new MeshModel("MutantStanding", Matrix.CreateScale(0.4f) * Matrix.CreateRotationY(0) * Matrix.CreateTranslation(8, 0, 1)) { ProjectorViewProject = Projector },
                new MeshModel("HeadFemale", Matrix.CreateScale(0.2f) * Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateTranslation(-3, 6, 0)) { ProjectorViewProject = Projector },
            };

            CaptureCameras = CreateCaptureCameras().ToList();
            if (CaptureCameras.IsEmpty())
                AddVirtualCaptureCamera("VirCam 1", "1018", Color.Red);

            CaptureCameraSelectionPictureGray = new Picture2D(CaptureCameraSelected.Intrinsics.ImageSize.LimitProportional(290, 290).AnchorWithin(Monitor.ClientRectangle, AnchorPoints.BottomLeft), CaptureCameraSelected.Capture.GrayTexture2D);
            CaptureCameraSelectionPictureRgba = new Picture2D(CaptureCameraSelected.Intrinsics.ImageSize.LimitProportional(290, 290).ToRect(CaptureCameraSelectionPictureGray.Rectangle.Left, CaptureCameraSelectionPictureGray.Rectangle.Top, AnchorPoints.BottomLeft), CaptureCameraSelected.Capture.RgbaTexture2D);
            CaptureCameraSelected.Highlight = true;

            WorldScene.Add(CaptureCameras);
            WorldScene.Add(Projector);

            Monitor.Scene = new Scene(new ScreenCamera(Monitor))
            {
                new Clear(Color.LightGray),
                WorldScene,
                CaptureCameraSelectionPictureGray,
                CaptureCameraSelectionPictureRgba,
            };

            LocateTrigger = new Trigger(() => new LocateTask(Monitor, CaptureCameraSelected, Chessboard).Run(), Keys.L);
            CalibrateTrigger = new Trigger(() => new CalibrateTask(Monitor, CaptureCameraSelected, Chessboard).Run(CaptureCameraSelected), Keys.C);
            ChessboardShapeTrigger = new Trigger(() => new ChessboardShapeTask(Monitor, Projector, Chessboard).Run(), Keys.S);
            CalibrateIndirectlyTrigger = new Trigger(() => { WorldScene.Remove(ColoredChessboard); return new CalibrateIndirectlyTask(Monitor, CaptureCameras, Projector, Chessboard).Run(WorldScene); }, Keys.I);
            GrayScanTrigger = new Trigger(() => new GrayScanTask(Monitor, CaptureCameras.First(), Projector).Run(WorldScene), Keys.G);

            AttachInputToCamera(Program.WhenInput.Where(input => !input.KeyPressed(Keys.LeftAlt)), Monitor, WorldCamera);
            AttachInputToCamera(Program.WhenInput.Where(input => input.KeyPressed(Keys.LeftAlt)), Monitor, virtualProjectorOrbit);

            AttachPerformanceBar();

            Program.WhenInput.Where(input => input.KeyDown(Keys.Tab)).Subscribe(input =>
                {
                    CaptureCameraSelected.Highlight = false;
                    CaptureCameraSelectionIdx = (CaptureCameraSelectionIdx + 1) % CaptureCameras.Count;
                    CaptureCameraSelected.Highlight = true;
                    CaptureCameraSelectionPictureGray.Texture2D = CaptureCameraSelected.Capture.GrayTexture2D;
                    CaptureCameraSelectionPictureRgba.Texture2D = CaptureCameraSelected.Capture.RgbaTexture2D;

                });
        }
예제 #4
0
        public static IDisposable AttachInputToCamera(IObservable<Input> whenInput, Window window, OrbitCamera camera)
        {
            var whenFocusedInput = whenInput.Where(input => window.Focused);

            var whenLeftMouseDown = whenFocusedInput.Where(input => input.LeftMouseDown);
            var whenLeftMouseUp = whenFocusedInput.Where(input => input.LeftMouseUp);

            var whenFocusedDrag = from begin in whenLeftMouseDown
                                  let fro = new { YawPitch = camera.YawPitch, Center = camera.Center }
                                  from during in whenFocusedInput.TakeUntil(whenLeftMouseUp)
                                  select new
                                  {
                                      From = fro,
                                      To = during,
                                      Delta = during.MousePosition - begin.MousePosition
                                  };

            var halfOrbitPerPixel = MathHelper.Pi / window.Width * new Vector2(-1, -1);
            var meterPerPixel = 27.0f / window.Width;

            return new CompositeDisposable(

                // Scroll Wheel Camera Distance
                whenFocusedInput.Where(input => input.WheelDelta != 0).Subscribe(input => camera.Distance -= input.WheelDelta),

                // Shift Drag Camera Centroid Translate 
                whenFocusedDrag.Where(d => d.To.KeyPressed(Keys.LeftShift))
                               .Subscribe(drag => camera.Center = drag.From.Center
                                                                + drag.Delta.X * meterPerPixel * camera.World.Left
                                                                + drag.Delta.Y * meterPerPixel * camera.World.Up),

                // Normal Drag Camera Orbit Rotate 
                whenFocusedDrag.Where(d => !d.To.KeyPressed(Keys.LeftShift))
                               .Subscribe(drag => camera.YawPitch = drag.From.YawPitch + drag.Delta * halfOrbitPerPixel));
        }
예제 #5
0
        private void AddVirtualCaptureCamera(string name, string uuid, Color color)
        {
            var size = new Size(1600, 1200);
            var principal = new PointF(392.713f * 2, 274.4965f * 2);
            var orbitCamera = new OrbitCamera("{0} Orbit".FormatWith(name), uuid, size, principal, size.Width, nearPlaneDistance: 2, farPlaneDistance: 40)
            {
                Color = Color.DarkCyan,
                Center = new Vector3(5, 4, 0),
                Distance = 30,
                YawPitch = new Vector2(0.1f, 0.1f),
            };
            var virtualCapture = new VirtualCapture(name, uuid, size, fps: 10)
            {
                Scene = new Scene(orbitCamera)
                { 
                    new Clear(Color.White),
                    Chessboard
                }
            };

            var virtualCaptureCamera = new CaptureCamera(virtualCapture, 0) { Color = color };

            WorldScene.Add(orbitCamera);
            CaptureCameras.Add(virtualCaptureCamera);
        }