Beispiel #1
0
        public void TargetCameraInterpolatesCorrectlyEdgeCase()
        {
            var entity = Substitute.For <IEntity>();

            entity.Position.ReturnsForAnyArgs(new Vector3(200, 300f, -400f));

            var camera       = new Camera();
            var targetCamera = new TargetCamera(camera)
            {
                Type          = 0,
                Radius        = 420f,
                YRotation     = 0f,
                BackYRotation = 0f,
                At            = new Vector4(100f, 300f, 500f, 1f),
                AtTarget      = new Vector4(200f, -470f, 500f, 1f),
                AtTargetPrev  = new Vector4(98f, -468f, 502f, 1f),
            };

            const int    FrameCount = 10;
            const double DeltaTime  = 1.0 / 30.0;

            for (var frame = 0; frame < FrameCount; frame++)
            {
                targetCamera.Update(entity, DeltaTime);
            }

            var expected = new Vector4(194.24677f, -425.70007f, 405.75323f, 1);

            Assert.Equal(expected, targetCamera.At);
        }
Beispiel #2
0
        /// <inheritdoc />
        public override void Initialize()
        {
            Camera = new TargetCamera(GraphicsDevice.Viewport.AspectRatio, new Vector3(1000, 600, 0),
                                      Vector3.UnitY * 150);

            base.Initialize();
        }
Beispiel #3
0
        void Render(bool instant = false)
        {
            if (Application.isPlaying && !instant)
            {
                m_renderQueued = true;
                return;
            }

            if (TargetCamera == null)
            {
                return;
            }

            var rect = new Rect(0, 0, (int)TextureSize.x, (int)TextureSize.y);

            RenderTexture.active = this.RenderTexture;

            GL.Clear(false, true, BackgroundColor);
            TargetCamera.Render();

            this.Texture2D.ReadPixels(rect, 0, 0);
            this.Texture2D.Apply();

            RenderTexture.active = null;
            m_renderQueued       = false;
        }
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
 }
Beispiel #5
0
        public void TargetCameraInterpolatesCorrectly(
            float src, float dst, float expected, int frameIndex)
        {
            var entity = Substitute.For <IEntity>();

            entity.Position.ReturnsForAnyArgs(new Vector3(dst, -170f, -500f));

            var camera       = new Camera();
            var targetCamera = new TargetCamera(camera)
            {
                Type          = 0,
                Radius        = 420f,
                YRotation     = 0f,
                BackYRotation = 0f,
                At            = new Vector4(src, 0f, 500f, 1f),
                AtTargetPrev  = new Vector4(dst, 0f, 500f, 1f),
            };

            const double DeltaTime = 1.0 / 30.0;

            while (frameIndex-- > 0)
            {
                targetCamera.Update(entity, DeltaTime);
            }

            Assert.Equal(expected, targetCamera.At.X, 3);
        }
Beispiel #6
0
        public void RenderReflection(Camera.Camera camera, GameTime gameTime)
        {
            var reflectedCameraPosition = camera.Position;

            reflectedCameraPosition.X = -reflectedCameraPosition.X + mirrorMesh.Position.X * 2;
            var reflectedCameraTarget = camera.Target;

            reflectedCameraTarget.X = -reflectedCameraTarget.X + mirrorMesh.Position.X * 2;
            var reflectionCamera = new TargetCamera(graphics)
            {
                Position = reflectedCameraPosition,
                Target   = reflectedCameraTarget
            };

            reflectionCamera.Update(gameTime);
            mirrorEffect.Parameters["ReflectedView"].SetValue(reflectionCamera.ViewMatrix);
            var clipPlane = new Vector4(1, 0, 0, -mirrorMesh.Position.X);

            graphics.SetRenderTarget(reflectionTarg);
            graphics.Clear(Color.Black);
            foreach (var renderable in Objects)
            {
                renderable.SetClipPlane(clipPlane);
                renderable.Draw(reflectionCamera);
                renderable.SetClipPlane(null);
            }
            graphics.SetRenderTarget(null);
            mirrorEffect.Parameters["ReflectionMap"].SetValue(reflectionTarg);
        }
Beispiel #7
0
        private IEnumerator DoConstantFocus(CameraFocus.Data focusData)
        {
            float targetOrthoSize = 0.5f * TargetCamera.GetFrustumHeightFromDistance(focusData.FocusPointOffset);

            Vector3 camStartPos         = _targetTransform.position;
            Vector3 camMoveDir          = Vector3.Normalize(focusData.CameraWorldPosition - camStartPos);
            float   distanceToTravel    = (camStartPos - focusData.CameraWorldPosition).magnitude;
            float   initialCamOrthoSize = TargetCamera.orthographicSize;

            _isDoingFocus = true;
            while (true)
            {
                _targetTransform.position += camMoveDir * FocusSettings.ConstantSpeed * Time.deltaTime;
                float t = 1.0f - (_targetTransform.position - focusData.CameraWorldPosition).magnitude / distanceToTravel;
                TargetCamera.orthographicSize = Mathf.Lerp(initialCamOrthoSize, targetOrthoSize, t);

                if (Vector3.Dot(camMoveDir, focusData.CameraWorldPosition - _targetTransform.position) <= 0.0f)
                {
                    _targetTransform.position     = focusData.CameraWorldPosition;
                    TargetCamera.orthographicSize = targetOrthoSize;
                    break;
                }
                yield return(null);
            }

            SetFocusPoint(focusData.FocusPoint);
            _lastFocusPoint = focusData.FocusPoint;
            _isDoingFocus   = false;
        }
Beispiel #8
0
    // Сравниваем два снимка. 1 - идеально подходит, <0 не подходит
    public static float Compare(Shot target, Shot test)
    {
        // Считаем отклонение камеры и удара от Raycast
        float posDev = (test.position - target.position).magnitude;
        float tarDev = (test.target - target.target).magnitude;

        float posAccPct, tarAccPct, posAP2, tarAP2; // Степень точности

        TargetCamera tc = TargetCamera.S;

        // Получаем значение точности, где 1 - идеально, 0 - кое как подходит
        posAccPct = 1 - (posDev / tc.maxPosDeviation);
        tarAccPct = 1 - (tarDev / tc.maxTarDeviation);

        // Смягчаем значения чтобы оно было более прощающее
        posAP2 = Easing.Ease(posAccPct, tc.deviationEasing);
        tarAP2 = Easing.Ease(tarAccPct, tc.deviationEasing);

        float accuracy = (posAP2 + tarAP2) / 2f;

        // Используем Utils чтобы оформить числа в хорошенькую строку
        string accText = Utils.RoundToPlaces(accuracy * 100).ToString() + "%";

        Utils.tr("Position:", posAccPct, posAP2, "Target:", tarAccPct, tarAP2, "Accuracy", accuracy);

        return(accuracy);
    }
Beispiel #9
0
        private IEnumerator DoSmoothFocus(CameraFocus.Data focusData)
        {
            float targetOrthoSize = 0.5f * TargetCamera.GetFrustumHeightFromDistance(focusData.FocusPointOffset);

            Vector3 camStartPos = _targetTransform.position;
            Vector3 camMoveDir  = Vector3.Normalize(focusData.CameraWorldPosition - camStartPos);
            float   elapsedTime = 0.0f;

            _isDoingFocus = true;
            while (true)
            {
                float t = elapsedTime / FocusSettings.SmoothTime;
                _targetTransform.position     = Vector3.Lerp(_targetTransform.position, focusData.CameraWorldPosition, t);
                TargetCamera.orthographicSize = Mathf.Lerp(TargetCamera.orthographicSize, targetOrthoSize, t);

                elapsedTime += Time.deltaTime;

                if (Vector3.Dot(camMoveDir, focusData.CameraWorldPosition - _targetTransform.position) <= 0.0f)
                {
                    _targetTransform.position     = focusData.CameraWorldPosition;
                    TargetCamera.orthographicSize = targetOrthoSize;
                    break;
                }
                yield return(null);
            }

            SetFocusPoint(focusData.FocusPoint);
            _lastFocusPoint = focusData.FocusPoint;
            _isDoingFocus   = false;
        }
Beispiel #10
0
    // Compare two Shots. 1 is a perfect match, while <0 is not valid
    public static float Compare(Shot target, Shot test)
    {
        // Get the postional deviation of both the camera and the Raycast hit
        float posDev = (test.position - target.position).magnitude;
        float tarDev = (test.target - target.target).magnitude;

        float        posAccPct, tarAccPct, posAP2, tarAP2;  // Accuracy percentages
        TargetCamera tc = TargetCamera.S;

        // Get a value for accuracy where 1 is perfect and 0 is barely okay
        posAccPct = 1 - (posDev / tc.maxPosDeviation);
        tarAccPct = 1 - (tarDev / tc.maxTarDeviation);

        // Curve the value so that it's more forgiving. This uses the same
        // Easing that we do for motion. You can curve ANY value between
        // 0 and 1, not just Interpolation values.
        posAP2 = Easing.Ease(posAccPct, tc.deviationEasing);
        tarAP2 = Easing.Ease(tarAccPct, tc.deviationEasing);

        float accuracy = (posAP2 + tarAP2) / 2f;

        // Remember that you can use Utills to format numbers nicely as strings
        string accText = Utils.RoundToPlaces(accuracy * 100).ToString() + "%";

        Utils.tr("Position:", posAccPct, posAP2, "Target:", tarAccPct, tarAP2, "Accuracy:", accText);

        return(accuracy);
    }
Beispiel #11
0
        public bool IsViewportHoveredByDevice()
        {
            Vector2 devicePos     = RTInputDevice.Get.Device.GetPositionYAxisUp();
            Vector3 viewportPoint = TargetCamera.ScreenToViewportPoint(devicePos);

            return(TargetCamera.rect.Contains(viewportPoint));
        }
Beispiel #12
0
        public virtual void OnPointerDown(PointerEventData data)
        {
            mCanvasGroup.alpha = PressedOpacity;

            if (ParentCanvasRenderMode == RenderMode.ScreenSpaceCamera)
            {
                mNewTargetPosition = TargetCamera.ScreenToWorldPoint(data.position);
            }
            else
            {
                mNewTargetPosition = data.position;
            }

            mNewTargetPosition = Vector2.ClampMagnitude(mNewTargetPosition - mCenterPosition, MaxRange);

            if (!HorizontalAxisEnabled)
            {
                mNewTargetPosition.x = 0;
            }
            if (!VerticalAxisEnabled)
            {
                mNewTargetPosition.y = 0;
            }

            mJoystickValue.x = EvaluateInputValue(mNewTargetPosition.x);
            mJoystickValue.y = EvaluateInputValue(mNewTargetPosition.y);

            mNewJoystickPosition   = mCenterPosition + mNewTargetPosition;
            mNewJoystickPosition.z = mInitZPosition;

            if (TargetJoystickKnob != null)
            {
                TargetJoystickKnob.position = mNewJoystickPosition;
            }
        }
Beispiel #13
0
        public bool IsViewportHoveredByDevice()
        {
            Vector2 devicePos     = RTInputDevice.Get.Device.GetPositionYAxisUp();
            Vector3 viewportPoint = TargetCamera.ScreenToViewportPoint(devicePos);

            return(viewportPoint.x >= 0.0f && viewportPoint.x <= 1.0f &&
                   viewportPoint.y >= 0.0f && viewportPoint.y <= 1.0f);
        }
Beispiel #14
0
    private void UpdatePosition()
    {
        Vector3    position;
        Quaternion rotation;

        TargetCamera.CalcCameraPosition(out position, out rotation, this.mTargetPosition, this.mYawPitchRoll, this.CameraDistance);
        this.mTransform.set_position(position);
        this.mTransform.set_rotation(rotation);
    }
Beispiel #15
0
 private void OnEnable()
 {
     targetCamera = (TargetCamera)target;
     mode         = serializedObject.FindProperty("mode");
     attachTo     = serializedObject.FindProperty("attachTo");
     smoothFollow = serializedObject.FindProperty("smoothFollow");
     mouseOrbit   = serializedObject.FindProperty("mouseOrbit");
     lookAt       = serializedObject.FindProperty("lookAt");
     supervisory  = serializedObject.FindProperty("supervisory");
 }
Beispiel #16
0
        public List <GameObject> GetVisibleObjects()
        {
            if (_isObjectVisibilityDirty)
            {
                _visibleObjects          = TargetCamera.GetVisibleObjects(new CameraViewVolume(TargetCamera));
                _isObjectVisibilityDirty = false;
            }

            return(new List <GameObject>(_visibleObjects));
        }
 private void Start()
 {
     Time.timeScale  = 1f;
     _sm             = SpawnManager.instance;
     _playerMovement = PlayerMovement.instance;
     _uiManager      = UIManager.instance;
     _soundManager   = SoundManager.instance;
     _targetCamera   = Camera.main.GetComponent <TargetCamera>();
     levels[level - 1].SetActive(true);
 }
    protected override void Update()
    {
        base.Update();

        // move iTween on mouse double-click
        if (Input.GetMouseButtonDown(0))
        {
            if (!one_click)
            {
                one_click = true;
                timer_for_double_click = Time.time;
            }
            else
            {
                one_click = false;
                // do double click

                timer_idle = Time.time;

                rigidbody.velocity = new Vector3(0, 0, 0);

                Vector3 pos_mouse = TargetCamera.ScreenToWorldPoint(Input.mousePosition);
                pos_mouse.z = 0;
                Vector3[] path = new Vector3[2];
                path[0] = transform.position;
                path[1] = pos_mouse;
                iTween.Init(this.gameObject);
                iTween.MoveTo(this.gameObject,
                              iTween.Hash("path", path, "time", SpeedITweenMove, "oncomplete", "complete", "oncompletetarget", this.gameObject, "easetype", iTween.EaseType.easeOutSine));

                if (path[0].x - path[1].x >= 0)
                {
                    transform.localScale = new Vector3(1, -1, 1);
                }
                else
                {
                    transform.localScale = new Vector3(-1, -1, 1);
                }

                if (ScriptsGame)
                {
                    ScriptsGame.GetComponent <server>().SendMessage_Move(m_id, pos_mouse);
                }
            }
        }
        if (one_click)
        {
            if ((Time.time - timer_for_double_click) > delay)
            {
                one_click = false;

                Shoot(TargetCamera.ScreenToWorldPoint(Input.mousePosition));
            }
        }
    }
        public override void GoToEndState()
        {
            GameSettings instance = GameSettings.Instance;

            if (this.Speed == EventAction_MoveCamera.CameraMoveSpeeds.Immediate)
            {
                EventAction_MoveCamera actionMoveCamera = this;
                actionMoveCamera.TargetPosition = Vector3.op_Addition(actionMoveCamera.TargetPosition, Vector3.op_Multiply(Vector3.get_up(), instance.GameCamera_UnitHeightOffset));
                this.UpdateCameraPosition(1f);
            }
            else
            {
                TargetCamera targetCamera = TargetCamera.Get((Component)Camera.get_main());
                targetCamera.Reset();
                if (this.MoveMode == EventAction_MoveCamera.CameraMoveModes.InterpolateToPoint)
                {
                    this.StartTargetPosition      = targetCamera.TargetPosition;
                    this.StartRotation            = targetCamera.Yaw;
                    this.StartCameraDistanceScale = targetCamera.CameraDistance / instance.GameCamera_DefaultDistance;
                }
                else if (this.MoveMode == EventAction_MoveCamera.CameraMoveModes.SpecificActor)
                {
                    this.StartRotation            = targetCamera.Yaw;
                    this.StartTargetPosition      = targetCamera.TargetPosition;
                    this.StartCameraDistanceScale = targetCamera.CameraDistance / instance.GameCamera_DefaultDistance;
                    GameObject actor = EventAction.FindActor(this.ActorID);
                    if (Object.op_Equality((Object)actor, (Object)null))
                    {
                        return;
                    }
                    this.TargetPosition = actor.get_transform().get_position();
                    if ((double)this.TargetRotation < 0.0)
                    {
                        this.TargetRotation = this.StartRotation;
                    }
                }
                else
                {
                    if (this.SnapToGround)
                    {
                        this.StartTargetPosition = GameUtility.RaycastGround(this.StartTargetPosition);
                    }
                    EventAction_MoveCamera actionMoveCamera = this;
                    actionMoveCamera.StartTargetPosition = Vector3.op_Addition(actionMoveCamera.StartTargetPosition, Vector3.op_Multiply(Vector3.get_up(), instance.GameCamera_UnitHeightOffset));
                }
                if (this.SnapToGround)
                {
                    this.TargetPosition = GameUtility.RaycastGround(this.TargetPosition);
                }
                EventAction_MoveCamera actionMoveCamera1 = this;
                actionMoveCamera1.TargetPosition = Vector3.op_Addition(actionMoveCamera1.TargetPosition, Vector3.op_Multiply(Vector3.get_up(), instance.GameCamera_UnitHeightOffset));
                this.UpdateCameraPosition(2f);
            }
        }
            public bool TryInitEdgeMode()
            {
                var mouseUv = TargetCamera.GetMouseUvPosition();
                var result  = TryFindNearestEdge(mouseUv);

                if (result)
                {
                    InitMouseUvPosition(mouseUv);
                }
                return(result);
            }
        /// <inheritdoc />
        public override void Initialize()
        {
            Camera = new TargetCamera(GraphicsDevice.Viewport.AspectRatio, new Vector3(0, 100, 1500), Vector3.Zero, 1,
                                      3000);

            Sun   = new SpherePrimitive(GraphicsDevice, 20, 32, Color.MonoGameOrange);
            Earth = new SpherePrimitive(GraphicsDevice, 20, 32, Color.LightSkyBlue);
            Moon  = new SpherePrimitive(GraphicsDevice, 20, 32, Color.LightSlateGray);

            base.Initialize();
        }
Beispiel #22
0
 public static TargetCamera GetMainTargetCamera()
 {
     if (_main_camera == null)
     {
         if (Camera.main != null)
         {
             _main_camera = Camera.main.GetComponent <TargetCamera>();
         }
     }
     return(_main_camera);
 }
        /// <inheritdoc />
        public override void Initialize()
        {
            var screenSize = new Point(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);

            Camera = new FreeCamera(GraphicsDevice.Viewport.AspectRatio, new Vector3(-600, 250, 1500), screenSize);
            Camera.BuildProjection(GraphicsDevice.Viewport.AspectRatio, 0.1f, 3000f, MathHelper.PiOver4);

            TargetLightCamera = new TargetCamera(1f, LightPosition, Vector3.Zero);
            TargetLightCamera.BuildProjection(1f, LightCameraNearPlaneDistance, LightCameraFarPlaneDistance,
                                              MathHelper.PiOver2);

            base.Initialize();
        }
Beispiel #24
0
        void DisableAOVCapture(RecordingSession session)
        {
            var aovRecorderSettings = session.settings as AOVRecorderSettings;

            if (aovRecorderSettings != null)
            {
                var add = TargetCamera.GetComponent <HDAdditionalCameraData>();
                if (add != null)
                {
                    add.SetAOVRequests(null);
                }
            }
        }
Beispiel #25
0
        private void LateUpdate()
        {
            if (!Target || !_isVisible)
            {
                return;
            }

            _group.alpha       = (Transform.position.z > 0 && Target.gameObject.activeInHierarchy)? 1 : 0;
            Transform.position = TargetCamera.WorldToScreenPoint(Target.position);
            if (Transform.position.z > 100)
            {
                Transform.position = new Vector3(Transform.position.x, Transform.position.y, 100);
            }
        }
Beispiel #26
0
        /// <inheritdoc />
        public override void Initialize()
        {
            Game.Background = Color.CornflowerBlue;
            Camera          = new TargetCamera(GraphicsDevice.Viewport.AspectRatio, new Vector3(0, 20, 60), Vector3.Zero);

            Effect = new BasicEffect(GraphicsDevice);
            Effect.VertexColorEnabled = true;

            CreateVertexBuffer(Vector3.One * 25, Vector3.Zero, Color.Cyan, Color.Black, Color.Magenta, Color.Yellow,
                               Color.Green, Color.Blue, Color.Red, Color.White);
            CreateIndexBuffer(GraphicsDevice);

            base.Initialize();
        }
Beispiel #27
0
    /// <summary>
    /// Zoom objetivo con tiempo y camra hacia klaus
    /// </summary>
    /// <param name="time">Time to ReachNewZoom</param>
    public void ChangueZoomToK1(float espZoom, float time)
    {
        ZoomEspecialForK1 = espZoom;

        if (currentTargetK1 == TargetCamera.K1)
        {
            currentTargetK1  = TargetCamera.EspecialK1;
            TargetEspecialK1 = K1;
            if (currentTargetGlobal == TargetCamera.K1 ||
                currentTargetGlobal == TargetCamera.EspecialK1)
            {
                SetZoomToK1(time);
            }
        }
    }
Beispiel #28
0
    public void RemoveEspecialZoomForK1()
    {
        TargetEspecialK1  = K1;
        ZoomEspecialForK1 = ZoomK1;

        if (currentTargetK1 == TargetCamera.EspecialK1)
        {
            currentTargetK1 = TargetCamera.K1;
            if (currentTargetGlobal == TargetCamera.K1 ||
                currentTargetGlobal == TargetCamera.EspecialK1)
            {
                SetZoomToK1();
            }
        }
    }
Beispiel #29
0
        public void GetVisibleObjects(List <GameObject> visibleObjects)
        {
            visibleObjects.Clear();

            if (_isObjectVisibilityDirty)
            {
                TargetCamera.GetVisibleObjects(new CameraViewVolume(TargetCamera), _visibleObjects);
                _isObjectVisibilityDirty = false;
            }

            if (_visibleObjects.Count != 0)
            {
                visibleObjects.AddRange(_visibleObjects);
            }
        }
Beispiel #30
0
    /// <summary>
    /// Zoom objetivo con tiempo y camra hacia klaus
    /// </summary>
    /// <param name="time">Time to ReachNewZoom</param>
    public void ChangueZoomToKlaus(float espZoom, float time)
    {
        ZoomEspecialForKlaus = espZoom;
        TargetEspecialKlaus  = Klaus;
        if (currentTargetKlaus == TargetCamera.Klaus)
        {
            currentTargetKlaus = TargetCamera.EspecialKlaus;

            if (currentTargetGlobal == TargetCamera.Klaus ||
                currentTargetGlobal == TargetCamera.EspecialKlaus)
            {
                SetZoomToKlaus(time);
            }
        }
    }
Beispiel #31
0
	void Awake() {
		S = this;
	}