Example #1
0
        //---------------------------------------------------------------------------

        public void Tick()
        {
            foreach (CameraFuseData data in m_FusedCameras)
            {
                CameraComponent first  = ComponentManager.Get().Find <CameraComponent>(data.First);
                CameraComponent second = ComponentManager.Get().Find <CameraComponent>(data.Second);

                if (first != null && second != null)
                {
                    Camera camera1 = EntityManager.Get().Find <Camera>(first.Entity);
                    Camera camera2 = EntityManager.Get().Find <Camera>(second.Entity);
                    if (camera1 != null && camera2 != null)
                    {
                        switch (data.Mode)
                        {
                        case ECameraMode.Split:
                            if (Vector3.Distance(first.GetCenter(ECameraTargetGroup.One), second.GetCenter(ECameraTargetGroup.One)) < data.Distance)
                            {
                                data.UpdateMode(ECameraMode.Fused);
                                first.SetCameraMode(ECameraMode.Fused, second);
                                second.SetCameraMode(ECameraMode.Fused, first);
                            }
                            break;

                        case ECameraMode.Fused:
                            if (Vector3.Distance(first.GetCenter(ECameraTargetGroup.One), second.GetCenter(ECameraTargetGroup.One)) > data.Distance)
                            {
                                data.UpdateMode(ECameraMode.Split);
                                first.SetCameraMode(ECameraMode.Split);
                                second.SetCameraMode(ECameraMode.Split);
                            }
                            else
                            {
                                Vector3 firstLocation  = camera1.Transform.Location;
                                Vector3 secondLocation = camera2.Transform.Location;
                                if (Math.Abs(firstLocation.X - secondLocation.X) <= (first.Width + second.Width) / 2 && Math.Abs(firstLocation.Y - secondLocation.Y) <= 0.0f)
                                {
                                    MergeCameras(camera1, camera2);
                                    data.UpdateMode(ECameraMode.Merged);
                                    first.SetCameraMode(ECameraMode.Merged);
                                    second.SetCameraMode(ECameraMode.Merged);
                                }
                            }
                            break;

                        case ECameraMode.Merged:
                            if (Vector3.Distance(first.GetCenter(ECameraTargetGroup.One), second.GetCenter(ECameraTargetGroup.One)) > data.Distance)
                            {
                                SplitCameras(camera1, camera2);
                                data.UpdateMode(ECameraMode.Split);
                                first.SetCameraMode(ECameraMode.Split);
                                second.SetCameraMode(ECameraMode.Split);
                            }
                            break;
                        }
                    }
                }
            }
        }