Skip to content

Commit

Permalink
#10 bezier calculation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicloay committed Feb 11, 2014
1 parent 36b50bb commit 99bb956
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ static float parseFloat(JsonData jsonData){
// p1, p2 - conrol points
// t - value on x [0,1]
public static Vector2 getBezierPoint(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float t){
return (1 - t) * (1 - t) * (1 - t) * p0 +
3 * t * (1 - t) * (1 - t) * p1 +
3 * t * t * (1 - t) * p2 +
t * t * t * p3;
float y = (1 - t) * (1 - t) * (1 - t) * p0.y +
3 * t * (1 - t) * (1 - t) * p1.y +
3 * t * t * (1 - t) * p2.y +
t * t * t * p3.y;
return new Vector2(t,y);
}

// a - start point
Expand All @@ -553,16 +554,17 @@ public static void setCustomTangents(AnimationCurve curve, int i, int nextI, Jso
float cx2 = parseFloat(tangentArray[2]);
float cy2 = parseFloat(tangentArray[3]);
Vector2 p0 = new Vector2(0 , 0 );
Vector2 p3 = new Vector2(1 , diff );
Vector2 cOrig1 = new Vector2(cx1, cy1 * diff);
Vector2 cOrig2 = new Vector2(cx2, cy2 * diff);
Vector2 p3 = new Vector2(1 , 1 );
Vector2 cOrig1 = new Vector2(cx1, cy1);
Vector2 cOrig2 = new Vector2(cx2, cy2);
Vector2 p1 = getBezierPoint(p0, cOrig1, cOrig2, p3, 1.0f / 3.0f);
Vector2 p2 = getBezierPoint(p0, cOrig1, cOrig2, p3, 2.0f / 3.0f);


Vector2 c1,c2;
calcControlPoints(p0,p1,p2,p3, out c1, out c2);

/* test method
//* test method
bool ok = true;
for (float test=0.01f; test < 1.0f; test+=0.01f) {

Expand All @@ -574,13 +576,14 @@ public static void setCustomTangents(AnimationCurve curve, int i, int nextI, Jso
}
}
Debug.Log("ewerything is "+(ok?"ok":"bad"));
*/
//*/

c2 = c2 - p3;

float outTangent = c1.y / c1.x;
Debug.Log(c1.x + " " + (1.0f/3.0f));
float inTangent = c2.y / c2.x;

Debug.Log(c2.x + " " + (2.0f/3.0f));
if (diff < 0){
inTangent *= -1;
outTangent *= -1;
Expand Down

0 comments on commit 99bb956

Please sign in to comment.