Esempio n. 1
0
    /// <summary>
    /// Calculate visibility (Maximum height to show) for this profile
    /// </summary>
    /// <returns></returns>
    private void UpdateVisibility(CameraProfile Profile)
    {
        if (Profile.VisibilityCalculation == CameraProfile.VisibilityCalcMode.PlayerEyeHeight)
        {
            SetVisibility(mWorldEyeLocation.y);
            return;
        }

        Point cameraPoint = new Point(
            Mathf.RoundToInt(Camera.main.transform.position.x * WorldManager.UnitToVoxelScale),
            Mathf.RoundToInt(Camera.main.transform.position.y * WorldManager.UnitToVoxelScale),
            Mathf.RoundToInt(Camera.main.transform.position.z * WorldManager.UnitToVoxelScale)
            );

        if (Profile.VisibilityCalculation == CameraProfile.VisibilityCalcMode.PlayerToCamera)
        {
            bCalcVisibility = true;
            StartCoroutine(CalculateVisibility(mWorldEyeLocation, cameraPoint));
            return;
        }


        if (Profile.VisibilityCalculation == CameraProfile.VisibilityCalcMode.PlayerToCameraAndSky)
        {
            bCalcVisibility = true;
            StartCoroutine(CalculateSkyVisibility(mWorldEyeLocation, cameraPoint));
            return;
        }
    }
Esempio n. 2
0
        public Camera BuildCamera(CameraProfile profile, CameraConfig config, byte[] thumbnail)
        {
            lock (_accessLock)
            {
                // 检查给定的源是否存在
                if (profile.FilterType == FilterType.LocalCamera ||
                    profile.FilterType == FilterType.LocalDesktop)
                {
                    if (!Locator.Get <IFilterManager>().IsFilterExist(profile.FilterType, profile.FilterId))
                    {
                        throw new FilterNotFoundException(string.Format(CultureInfo.InvariantCulture,
                                                                        "Cannot find filter by type [{0}] and id [{1}].",
                                                                        profile.FilterType, profile.FilterId));
                    }
                }

                Camera camera = _cameras.Find(c => c.Id == profile.Id);
                if (camera == null)
                {
                    camera = CameraBuilder.Create(profile, config);
                    _cameras.Add(camera);

                    camera.Thumbnail = thumbnail;
                }

                return(camera);
            }
        }
    public static void GenerateProfiles()
    {
        if (Profiles != null)
        {
            Debug.Log("Profiles already exist!");
        }

        Profiles = new CameraProfile[PlayerCount];

        //RenderTexture rtAsset = Resources.Load("/RenderTextures/Screen1") as RenderTexture;
        for (int i = 0; i < Profiles.Length; i++)
        {
            GameObject    g   = GameObject.Instantiate(CameraPrefab);
            RawImage      img = GameObject.Instantiate(UIImagePrefab, GameCon.Canvas.transform).GetComponent <RawImage>();
            RenderTexture rt  = GetNewRenderTexture();

            CameraProfile p = new CameraProfile
            {
                Camera       = g.GetComponent <Camera>(),
                Controller   = g.GetComponent <CameraController>(),
                Texture      = rt,
                ImageElement = img
            };

            p.Camera.targetTexture = p.Texture;
            img.texture            = rt;
            p.Controller.joystick  = i + 1;
            PlaceScreenRect(p);
        }
    }
    static void PlaceScreenRect(CameraProfile p)
    {
        RectTransform r    = p.ImageElement.rectTransform;
        float         hw   = GameCon.Canvas.GetComponent <CanvasScaler>().referenceResolution.x / 2f;
        float         hh   = GameCon.Canvas.GetComponent <CanvasScaler>().referenceResolution.y / 2f;
        bool          left = ((p.Controller.joystick - 1) % 2 == 0);
        bool          top  = (p.Controller.joystick < 3);

        switch (_playerCount)
        {
        case 1:
            r.offsetMin = Vector2.zero;
            r.offsetMax = Vector2.zero;
            break;

        case 2:
            r.offsetMin = new Vector2((left) ? 0f : (hw), 0f);
            r.offsetMax = new Vector2((left) ? (-hw) : 0f, 0f);
            break;

        default:
            r.offsetMin = new Vector2((left) ? 0f : (hw), (top) ? 0f : (hh));
            r.offsetMax = new Vector2((left) ? (-hw) : 0f, (top) ? (-hh) : 0f);
            break;
        }
    }
Esempio n. 5
0
    void Update()
    {
        CameraProfile current = CurrentCameraProfile;

        mDownViewAngle             = StepVar(mDownViewAngle, current.ViewAngle);
        transform.localEulerAngles = new Vector3(mDownViewAngle, 0, 0);

        mDistance = StepVar(mDistance, current.Distance);
        transform.localPosition = new Vector3(0, Mathf.Sin(mDownViewAngle * Mathf.Deg2Rad), -Mathf.Cos(mDownViewAngle * Mathf.Deg2Rad)) * mDistance;
    }
        internal static CameraProfile Translate(CameraProfileData data)
        {
            CameraProfile profile = new CameraProfile(data.Id, Translate(data.FilterType), data.FilterId)
            {
                Name        = data.Name,
                Description = data.Description,
                Tags        = data.Tags
            };

            return(profile);
        }
        internal static CameraProfileData Translate(CameraProfile profile)
        {
            CameraProfileData data = new CameraProfileData()
            {
                Id          = profile.Id,
                Name        = profile.Name,
                FilterType  = Translate(profile.FilterType),
                FilterId    = profile.FilterId,
                Description = profile.Description,
                Tags        = profile.Tags
            };

            return(data);
        }
Esempio n. 8
0
        internal static DACameraProfile Translate(CameraProfile profile)
        {
            DACameraProfile data = new DACameraProfile()
            {
                Id          = profile.Id,
                Name        = profile.Name,
                FilterType  = (int)profile.FilterType,
                FilterId    = profile.FilterId,
                Description = profile.Description,
                Tags        = profile.Tags
            };

            return(data);
        }
 private void DelProfile()
 {
     if (string.IsNullOrWhiteSpace(CameraProfile?.Id))
     {
         return;
     }
     if (MessageBox.Show("Do you realy want to delete the selected profile", "Warning", MessageBoxButton.YesNo,
                         MessageBoxImage.Question) == MessageBoxResult.Yes)
     {
         CameraProfile.Delete();
         CameraProfiles.Remove(CameraProfile);
         CameraProfile = CameraProfiles[0];
     }
 }
Esempio n. 10
0
        internal static Camera Create(CameraProfile profile, CameraConfig config)
        {
            switch (profile.FilterType)
            {
            case FilterType.LocalCamera:
                return(Create(profile, config,
                              new VideoCaptureDeviceVideoSource(config.OriginalSourceString)
                {
                    DesiredFrameRate = 10000000 / config.FrameRate, // 1 fps, 30 fps = 10000000 / 30 = 333333
                    DesiredFrameSize = new System.Drawing.Size(config.Resolution.Width, config.Resolution.Height),
                    DesiredSnapshotSize = new System.Drawing.Size(config.Resolution.Width, config.Resolution.Height),
                }));

            case FilterType.LocalDesktop:
                return(Create(profile, config,
                              new DesktopVideoSource(int.Parse(config.OriginalSourceString, CultureInfo.InvariantCulture))
                {
                    FrameInterval = config.FrameInterval, // default 1000 == 1 fps, 30 fps = 1000 / 30 = 33
                    IsResized = true,
                    ResizeWidth = config.Resolution.Width,
                    ResizeHeight = config.Resolution.Height,
                }));

            case FilterType.LocalAVIFile:
                return(Create(profile, config,
                              new FileVideoSource(config.OriginalSourceString)));

            case FilterType.NetworkJPEG:
                return(Create(profile, config,
                              new JpegVideoSource(config.OriginalSourceString)
                {
                    FrameInterval = config.FrameInterval,
                    HttpUserAgent = config.UserAgent,
                    Login = config.UserName,
                    Password = config.Password,
                }));

            case FilterType.NetworkMJPEG:
                return(Create(profile, config,
                              new MJpegVideoSource(config.OriginalSourceString)
                {
                    HttpUserAgent = config.UserAgent,
                    Login = config.UserName,
                    Password = config.Password,
                }));

            default:
                throw new NotSupportedException("Do not support the given filter type " + profile.FilterType.ToString());
            }
        }
Esempio n. 11
0
    public void setProfile(CameraProfile profile)
    {
        if (profile == null)
        {
            return;
        }

        transform.position = profile.position;
        transform.rotation = Quaternion.Euler(profile.rotation);
        smoothFollow       = profile.smoothFollow;
        smoothSpeed        = profile.smoothSpeed;
        followRadius       = profile.followRadius;

        //zoom (profile.zoomLevel);
    }
Esempio n. 12
0
 public void Deserialize(ref SerializeContext context, ref NetworkReader reader)
 {
     this.tick       = reader.ReadInt32();
     velocity        = reader.ReadVector3Q();
     action          = (Action)reader.ReadInt32();
     actionStartTick = reader.ReadInt32();
     locoState       = (LocoState)reader.ReadInt32();
     locoStartTick   = reader.ReadInt32();
     position        = reader.ReadVector3Q();
     jumpCount       = reader.ReadInt32();
     sprinting       = reader.ReadBoolean() ? 1 : 0;
     cameraProfile   = (CameraProfile)reader.ReadByte();
     damageTick      = reader.ReadInt32();
     damageDirection = reader.ReadVector3Q();
 }
        public void Init()
        {
            try
            {
                // load camera profiles
                CameraProfiles.Clear();
                CameraProfiles.Add(_noneProfile);

                var files = Directory.GetFiles(Settings.Instance.CameraProfileFolder, "*.json");
                foreach (var file in files)
                {
                    var p = CameraProfile.Load(file);
                    if (p != null)
                    {
                        CameraProfiles.Add(p);
                    }
                }
                RaisePropertyChanged(() => CameraProfile);
                // camera profiles
                Profiles.Clear();
                files = Directory.GetFiles(Settings.Instance.ProfileFolder, "*.json");
                foreach (var file in files)
                {
                    var p = Profile.Load(file);
                    if (p != null)
                    {
                        Profiles.Add(p);
                    }
                }
                if (Profiles.Count == 0)
                {
                    var newP = GetNewProfile("Profile1");
                    newP.Save();
                    Profiles.Add(newP);
                }
                Profile = Profiles[0];
                if (!string.IsNullOrWhiteSpace(Profile?.CameraProfileId))
                {
                    CameraProfile = CameraProfiles.FirstOrDefault(x => x.Id == Profile.CameraProfileId);
                }
            }
            catch (Exception e)
            {
                Log.Debug("Unable to load profile list ", e);
            }
        }
        private void AddProfile()
        {
            var profile = new CameraProfile(SelectedCameraDevice)
            {
                Name = "CameraProfile"
            };
            var dlg = new CameraProfilerView {
                DataContext = new CameraProfilerViewModel(profile)
            };

            if (dlg.ShowDialog() == true)
            {
                profile.Save();
                CameraProfiles.Add(profile);
                CameraProfile = profile;
            }
        }
Esempio n. 15
0
        public Camera(CameraProfile profile, CameraConfig config, IVideoSource videoSource)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (videoSource == null)
            {
                throw new ArgumentNullException("videoSource");
            }

            _profile     = profile;
            _config      = config;
            _videoSource = videoSource;
        }
Esempio n. 16
0
        public Camera(int id, SettingsGeneralCameraSystem settings, ImageResolution imageResolution)
        {
            ID              = id;
            Settings        = settings;
            ImageResolution = imageResolution;
            Model           = GetModelName(settings.Model);
            Orientation     = settings.Orientation;
            Profile         = new CameraProfile();

            PageTitle = "#" + ID + " " + Model;

            LensControlEnabled = CheckForLensControl();

            // TODO: this should not have to be done in the constructor
            if (IsImageMode())
            {
                EnableImageMode(false);
            }
        }
Esempio n. 17
0
        public Camera CreateCamera(CameraProfile profile, CameraConfig config)
        {
            lock (_accessLock)
            {
                // 检查给定的源是否存在
                if (profile.FilterType == FilterType.LocalCamera ||
                    profile.FilterType == FilterType.LocalDesktop)
                {
                    if (!Locator.Get <IFilterManager>().IsFilterExist(profile.FilterType, profile.FilterId))
                    {
                        throw new FilterNotFoundException(string.Format(CultureInfo.InvariantCulture,
                                                                        "Cannot find filter by type [{0}] and id [{1}].",
                                                                        profile.FilterType, profile.FilterId));
                    }
                }
                else if (profile.FilterType == FilterType.LocalAVIFile)
                {
                    if (!File.Exists(profile.FilterId))
                    {
                        throw new FilterNotFoundException(string.Format(CultureInfo.InvariantCulture,
                                                                        "Cannot find filter by type [{0}] and id [{1}].",
                                                                        profile.FilterType, profile.FilterId));
                    }
                }

                // 构造摄像机
                Camera camera = _cameras.Find(c => c.Id == profile.Id);
                if (camera == null)
                {
                    camera = CameraBuilder.Create(profile, config);
                    _cameras.Add(camera);

                    camera.Thumbnail = Locator.Get <IStreamingManager>().GetCameraSnapshot(camera.Id);

                    Locator.Get <ICameraRepository>().Save(CameraBuilder.Translate(camera));
                }

                return(camera);
            }
        }
Esempio n. 18
0
 internal static Camera Create(CameraProfile profile, CameraConfig config, IVideoSource videoSource)
 {
     return(new Camera(profile, config, videoSource));
 }
Esempio n. 19
0
 public CameraProfilerViewModel()
 {
     ClearCommand  = new RelayCommand <string>(Clear);
     CameraProfile = new CameraProfile();
 }
Esempio n. 20
0
 public CameraProfilerViewModel(CameraProfile cameraProfile)
 {
     CameraProfile = cameraProfile;
     ClearCommand  = new RelayCommand <string>(Clear);
 }
Esempio n. 21
0
        private static void LoadCamera()
        {
            // get local filters
            List <DesktopFilter> desktopFilters = Locator.Get <IFilterManager>().GetDesktopFilters().ToList();
            List <CameraFilter>  cameraFilters  = Locator.Get <IFilterManager>().GetCameraFilters().ToList();

            // get cameras from db and published status
            List <CameraData>          cameraDatas          = Locator.Get <ICameraRepository>().FindAll().ToList();
            List <PublishedCameraData> publishedCameraDatas = Locator.Get <IPublishedCameraRepository>().FindAll().ToList();

            // matching local filters and db cameras
            foreach (var camera in cameraDatas)
            {
                if ((FilterType)camera.Profile.FilterType == FilterType.LocalDesktop ||
                    (FilterType)camera.Profile.FilterType == FilterType.LocalCamera)
                {
                    IFilter filter = null;
                    if ((FilterType)camera.Profile.FilterType == FilterType.LocalDesktop)
                    {
                        filter = desktopFilters.FirstOrDefault(d => d.Id == camera.Profile.FilterId);
                    }
                    else if ((FilterType)camera.Profile.FilterType == FilterType.LocalCamera)
                    {
                        filter = cameraFilters.FirstOrDefault(d => d.Id == camera.Profile.FilterId);
                    }

                    if (filter != null)
                    {
                        CameraProfile profile = CameraBuilder.FromFilter(camera.Id, filter);
                        profile.Name        = camera.Profile.Name;
                        profile.Description = camera.Profile.Description;
                        profile.Tags        = camera.Profile.Tags;

                        Locator.Get <ICameraManager>().BuildCamera(
                            profile,
                            CameraBuilder.Translate(camera.Config),
                            camera.Thumbnail);
                    }
                    else
                    {
                        // camera filter is not found, maybe it has been removed, this camera is invalid
                        Locator.Get <ICameraRepository>().Remove(camera.Id);
                    }
                }
                else
                {
                    // AVIFile, JPEG, MJPEG
                    Locator.Get <ICameraManager>().BuildCamera(
                        CameraBuilder.Translate(camera.Profile),
                        CameraBuilder.Translate(camera.Config),
                        camera.Thumbnail);
                }
            }

            foreach (var item in publishedCameraDatas)
            {
                Camera camera = Locator.Get <ICameraManager>().GetCamera(item.Id);
                if (camera != null)
                {
                    if (item.Destinations != null && item.Destinations.Count > 0)
                    {
                        Locator.Get <IStreamingManager>().PublishCamera(camera.Id,
                                                                        (from d in item.Destinations select new PublishDestination(d.Address, d.Port)).ToList());
                    }
                }
                else
                {
                    // camera filter is not found, maybe it has been removed, this camera is invalid
                    Locator.Get <IPublishedCameraRepository>().Remove(item.Id);
                }
            }
        }