/*
 * Curve是用來計算出內插值的類別
 * 
 * 本類別 Curve3D 組合三個Curve類別，提供可算出3D點的內插值的類別
  GC_Curve3D Path3D = new GC_Curve3D(CurveLoopType.CycleOffset); // 建立一個Curve3D物件
  float ElapsedGameTime = 0; //累積經過的時間
  
  Path3D.AddPoint(new Vector3(100, 100, 0), 0);    // 加入關鍵值
  Path3D.AddPoint(new Vector3(500, 100, 0), 2000); // 加入關鍵值
  Path3D.AddPoint(new Vector3(500, 500, 0), 4000); // 加入關鍵值
  Path3D.AddPoint(new Vector3(100, 500, 0), 6000); // 加入關鍵值
  Path3D.AddPoint(new Vector3(100, 100, 0), 8000); // 加入關鍵值
  Path3D.SetTangents(CurveTangent.Flat); //.Smooth);//Linear); // 內插值 計算的方式
  
  // 在 Update(GameTime gameTime) 函數內 累積經過的時間 並且計算出 內插值

  ElapsedGameTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
  Vector3 position = Path3D.GetPointOnCurve(ElapsedGameTime);
  
  gc.SetPos(new Vector2(position.X, position.Y)); // 將得到的 內插值 拿來使用 
 * */
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace WindowsGame1
{
    class curvemove
    {
        Curve curveX = new Curve();
        Curve curveY = new Curve();
        Curve curveZ = new Curve();

        // CurveLoopType.Constant  停在第一個點 或 最後的點
        // CurveLoopType.Cycle     回到第一個點
        // CurveLoopType.CycleOffset  回到第一個點 並且要扣除差額
        // CurveLoopType.Linear     以線性方式沿線推估
        // CurveLoopType.Oscillate  往回走
        public curvemove(CurveLoopType curveLoopType)
        {
            curveX.PostLoop = curveLoopType;
            curveY.PostLoop = curveLoopType;
            curveZ.PostLoop = curveLoopType;

            curveX.PreLoop = curveLoopType;
            curveY.PreLoop = curveLoopType;
            curveZ.PreLoop = curveLoopType;
        }

        // CurveTangent.Flat
        // CurveTangent.Linear
        // CurveTangent.Smooth
        public void SetTangents(CurveTangent curveTangent)
        {
            curveX.ComputeTangents(curveTangent);
            curveY.ComputeTangents(curveTangent);
            curveZ.ComputeTangents(curveTangent);
        }

        public void AddPoint(Vector3 point, float time)
        {
            curveX.Keys.Add(new CurveKey(time, point.X));
            curveY.Keys.Add(new CurveKey(time, point.Y));
            curveZ.Keys.Add(new CurveKey(time, point.Z));
        }
        public Vector3 GetPointOnCurve(float time)
        {
            Vector3 point = new Vector3();
            point.X = curveX.Evaluate(time);
            point.Y = curveY.Evaluate(time);
            point.Z = curveZ.Evaluate(time);
            return point;
        }
    }
}