public RaycastCamera()
        {
            Position  = new Vector2(1.5f, 1.5f);
            Direction = new Vector2(1, 0);
            Vector2Ext.Normalize(ref Direction);

            CameraPlane = new Vector2(0, -1) * VectorPlaneLength;
            Move(Position, Direction);
        }
예제 #2
0
        private void UpdateCameraCenterSmoothFollow()
        {
            //
            // Not a good effect
            //
            float delta  = Raylib.GetFrameTime();
            int   width  = Global.SceneWidth;
            int   height = Global.SceneHeight;
            //float minSpeed = 30;
            float minEffectLength = 10;
            //float fractionSpeed = 0.8f;
            float speed = 4.0f;

            Camera.offset = new Vector2(width / 2, height / 2);
            Vector2 diff   = Vector2.Subtract(CameraEntityToFollow.Get <Transform>().Position, Camera.target);
            float   length = Vector2Ext.Length(diff);

            if (length > minEffectLength)
            {
                //float speed = fmaxf(fractionSpeed * length, minSpeed);
                Camera.target = Vector2.Add(Camera.target, Vector2Ext.Scale(diff, speed * delta / length));
            }
        }
        private void Rotate(Double target, Int32 direction)
        {
            var length = Math.PI / 2;

            Movement = (gameTime) =>
            {
                float rotation = 0.004f * direction * 40.0f;
                rotation = (float)Math.Min(length, rotation);
                length  -= Math.Abs(rotation);

                // Convert rotation to direction
                Matrix2D rotMatrix = Matrix2D.CreateRotationZ(rotation);

                Vector2 newDirection = Vector2.Transform(Direction, Matrix2D.Convert(rotMatrix));
                Direction = newDirection;

                Vector2 newVectorPlane = Vector2.Transform(CameraPlane, Matrix2D.Convert(rotMatrix));
                CameraPlane = newVectorPlane;

                if (length <= 0)
                {
                    // set the direction vector and update
                    Direction.X = (float)Math.Cos(target);
                    Direction.Y = (float)Math.Sin(target);

                    // Set the vector plane as the normal to the direction vector
                    CameraPlane.X = Direction.Y;
                    CameraPlane.Y = -1 * Direction.X;

                    Vector2Ext.Normalize(ref CameraPlane);
                    CameraPlane *= VectorPlaneLength;

                    Movement = null;
                }
            };
        }