Exemplo n.º 1
0
        public void SetBufferValue(int x, int y, float value, OutOfBoundsSetMode mode)
        {
            if (IsOutOfBounds(x, y))
            {
                switch (mode)
                {
                case OutOfBoundsSetMode.Extend:
                    x = MathExtension.Clamp(x, 0, width);
                    y = MathExtension.Clamp(y, 0, height);
                    break;

                case OutOfBoundsSetMode.Wrap:
                    x = MathExtension.Wrap(x, 0, width);
                    y = MathExtension.Wrap(y, 0, height);
                    break;

                case OutOfBoundsSetMode.Ignore:
                    return;

                default:
                    throw new IndexOutOfRangeException();
                }
            }

            buffer[x, y] = value;
        }
Exemplo n.º 2
0
        /// <summary>
        /// The camera is updated once per frame automatically by the renderer.
        /// </summary>
        public override void Update()
        {
            // Check if no target.
            if (Target == null)
            {
                return;
            }

            // Check if target last position is set. It isn't on the first frame.
            if (_targetLastPosition == Vector2.Zero)
            {
                _targetLastPosition = Target.Center;
            }

            // Get mouse location.
            Vector2 mouseLocation = ScreenToWorld(Engine.InputManager.GetMousePosition());

            // Smooth between the mouse location and the target.
            float lx = MathExtension.Lerp(Target.Center.X, mouseLocation.X, MathExtension.Clamp(Speed * Engine.FrameTime, 0, CameraMaxDistance));
            float ly = MathExtension.Lerp(Target.Center.Y, mouseLocation.Y, MathExtension.Clamp(Speed * Engine.FrameTime, 0, CameraMaxDistance));

            Center = new Vector2(lx, ly);

            // Record position.
            _targetLastPosition = Target.Center;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 指定の時間に対する色を取得します。
        /// </summary>
        /// <param name="time">時間 ([0, 1])。</param>
        /// <param name="result">色。</param>
        public void GetColor(float time, out Vector3 result)
        {
            int baseIndex = 0;

            for (baseIndex = 0; baseIndex < entries.Count; baseIndex++)
            {
                if (time < entries[baseIndex].Time)
                {
                    break;
                }
            }

            if (entries.Count <= baseIndex)
            {
                result = Color.CornflowerBlue.ToVector3();
                return;
            }

            var index0 = MathExtension.Clamp(baseIndex - 1, 0, entries.Count);
            var index1 = MathExtension.Clamp(baseIndex, 0, entries.Count);

            if (index0 == index1)
            {
                result = entries[index1].Color;
                return;
            }

            var color0 = entries[index0].Color;
            var color1 = entries[index1].Color;
            var time0  = entries[index0].Time;
            var time1  = entries[index1].Time;
            var amount = (time - time0) / (time1 - time0);

            Vector3.Lerp(ref color0, ref color1, amount, out result);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Performs linear interpolation of <see cref="Color" />.
 /// </summary>
 /// <param name="value1">Source <see cref="Color" />.</param>
 /// <param name="value2">Destination <see cref="Color" />.</param>
 /// <param name="amount">Interpolation factor.</param>
 /// <returns>Interpolated <see cref="Color" />.</returns>
 public static Color Lerp(Color value1, Color value2, float amount)
 {
     amount = MathExtension.Clamp(amount, 0, 1);
     return(new Color(
                (byte)MathExtension.Lerp(value1.R, value2.R, amount),
                (byte)MathExtension.Lerp(value1.G, value2.G, amount),
                (byte)MathExtension.Lerp(value1.B, value2.B, amount),
                (byte)MathExtension.Lerp(value1.A, value2.A, amount)));
 }
Exemplo n.º 5
0
        public void Update(float deltatime)
        {
            float progress = MathExtension.Clamp(mReactivity * deltatime / 16.0f, 0.0f, 1.0f);

            // Update the mouse and keyboard
            UpdateMouse(deltatime);
            UpdateKeyboard(deltatime);

            // We mix the actual vectors with the camera vector to get a smoother movement
            mCamera.mRotation = MathExtension.Mix(mCamera.mRotation, mRotation, progress);
            mCamera.mLocation = MathExtension.Mix(mCamera.mLocation, mLocation, progress);
        }
Exemplo n.º 6
0
        public string FormatTCode(HashSet <ChannelValueModel> values)
        {
            var tCode = new StringBuilder();

            foreach (var value in values)
            {
                var minValue     = SettingsHandler.AvailableAxis.GetValue(value.Channel).Min;
                var maxValue     = SettingsHandler.AvailableAxis.GetValue(value.Channel).Max;
                var clampedValue = maxValue == 0 ? value.Value : MathExtension.Clamp(value.Value, minValue, maxValue);
                tCode.Append($"{value.Channel}{(clampedValue < 10 ? "0" : "")}{clampedValue}S{SettingsHandler.Speed} ");
            }
            return($"{tCode.ToString().Trim()}\n");
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            VideoFileReader reader = new VideoFileReader();

            reader.Open(videoPath);

            float frameRate = (float)reader.FrameRate.ToDouble();

            int startFrame = MathExtension.Clamp((int)Math.Floor(startTime * frameRate), 0, (int)reader.FrameCount);
            int endFrame   = MathExtension.Clamp((int)Math.Floor(endTime * frameRate), 0, (int)reader.FrameCount);

            int  frameCount = endFrame - startFrame;
            Size size       = new Size(imageWidth, imageWidth * reader.Height / reader.Width);

            float[][,] frames = new float[frameCount][, ];

            Console.Write("Reading frames".PadRight(30));
            for (int videoIndex = startFrame, frameIndex = 0; videoIndex < endFrame; videoIndex++, frameIndex++)
            {
                using (Bitmap bitmap = new Bitmap(reader.ReadVideoFrame(videoIndex), size))
                {
                    frames[frameIndex] = bitmap.ConvertToGrayscaleImage();
                }

                if (frameIndex % ((int)Math.Floor(frameCount / 10f)) == 0)
                {
                    Console.Write(".");
                }
            }
            Console.Write(" Done\n");

            MotionDetector detector = new MotionDetector(frames, frameRate);

            detector.Process();

            Console.Write("Closing in 10 seconds...");
            System.Threading.Thread.Sleep(10000);
        }
Exemplo n.º 8
0
        public float GetValue(int x, int y, OutOfBoundsGetMode mode)
        {
            if (IsOutOfBounds(x, y))
            {
                switch (mode)
                {
                case OutOfBoundsGetMode.Extend:
                    x = MathExtension.Clamp(x, 0, width);
                    y = MathExtension.Clamp(y, 0, height);
                    break;

                case OutOfBoundsGetMode.Wrap:
                    x = MathExtension.Wrap(x, 0, width);
                    y = MathExtension.Wrap(y, 0, height);
                    break;

                default:
                    throw new IndexOutOfRangeException();
                }
            }

            return(frame[x, y]);
        }
Exemplo n.º 9
0
        public void Update(float deltatime)
        {
            mMoving = false;

            if (mLock)
            {
                return;
            }

            float progress = MathExtension.Clamp(mReactivity * deltatime / 16.0f, 0.0f, 1.0f);

            // Update the mouse and keyboard
            UpdateMouse(deltatime);
            UpdateKeyboard(deltatime);

            // We mix the actual vectors with the camera vector to get a smoother movement
            mCamera.mRotation = MathExtension.Mix(mCamera.mRotation, mRotation, progress);
            mCamera.mLocation = MathExtension.Mix(mCamera.mLocation, mLocation, progress);

            if (mCamera.mThirdPerson)
            {
                mCamera.mThirdPersonDistance = MathExtension.Mix(mCamera.mThirdPersonDistance, mDistance, progress * 0.25f);
            }
        }
Exemplo n.º 10
0
        private void Insert(int index, UIVisual item)
        {
            index = MathExtension.Clamp(index, 0, children.Count);

            if (item.Parent != null)
            {
                item.Parent.Remove(item);
            }

            Debug.Assert(item.Parent == null);

            item.Parent = this;

            if (index < children.Count)
            {
                children.Insert(index, item);
            }
            else
            {
                children.Add(item);
            }

            OnChildAdded(item);
        }