using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Text; using System.IO; using System.Runtime.InteropServices; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; // Local using statements using XNAEngine; using CollisionDetection; using LinearAlgebra; //written by Dr. Roger Webster 11-19-2009 CS375 Graphics namespace XNACollisionDetection { /// /// Summary description /// public class Bezier { //Bezier Curve vars //---------------------------------------------------------------- int NumInterpolationPoints; Vector2 BeginBoundary = new Vector2(); Vector2 EndBoundary = new Vector2(); Vector2[] ControlPoints = new Vector2[10000]; int numofControlPoints = 0; int numofBezierpoints = 0; public Bezier() { NumInterpolationPoints = 100; } //public void setNumInterpolationPoints(int n) //{ // NumInterpolationPoints = n; //} public int getNumInterpolationPoints() { return (NumInterpolationPoints); } // ------------------------------------------------- // BEZIER CURVE FUNCTIONS FOR GRAPH // ------------------------------------------------- private void BezierCalcBoundaries(Vector2 first, Vector2 second, Vector2 nexttolast, Vector2 last) { } // ------------------------------------------------- // simple linear interpolation between two points // ------------------------------------------------- private Vector2 lerp(Vector2 a, Vector2 b, float t) { float x, y; Vector2 dest = new Vector2(); x = a.X + (b.X - a.X) * t; y = a.Y + (b.Y - a.Y) * t; dest.X = x; dest.Y = y; return (dest); } // -------------------------------------------------------- // evaluate a point on a bezier-curve. t goes from 0 to 1.0 // -------------------------------------------------------- private Vector2 ComputeBezierPoint(Vector2 a, Vector2 b, Vector2 c, Vector2 d, float t) { Vector2 ab = new Vector2(); Vector2 bc = new Vector2(); Vector2 cd = new Vector2(); Vector2 abbc = new Vector2(); Vector2 bccd = new Vector2(); Vector2 dest = new Vector2(); ab = lerp(a, b, t); // point between a and b (green) bc = lerp(b, c, t); // point between b and c (green) cd = lerp(c, d, t); // point between c and d (green) abbc = lerp(ab, bc, t); // Vector2 between ab and bc (blue) bccd = lerp(bc, cd, t); // Vector2 between bc and cd (blue) dest = lerp(abbc, bccd, t); // Vector2 on the bezier-curve (black) return (dest); } public Vector2[] ComputeBezier(Vector2[] PointArray, int numberofPoints, out Vector2[] ControlPointsOut, out int numofControlPointsOut, out int totalBezierPoints) { ControlPointsOut = ControlPoints; numofControlPointsOut = numofControlPoints; totalBezierPoints = numofBezierpoints; return (bezier_curve_pts); } } }