Guest User

Untitled

a guest
Dec 14th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. public Vector getPoint(Vector p0,Vector p1,Vector p2,Vector p3,float x)
  2. {
  3. Vector ans = new Vector ();
  4.  
  5. Vector p0t = new Vector (p0);
  6. Vector p1t = new Vector (p1);
  7. Vector p2t = new Vector (p2);
  8. Vector p3t = new Vector (p3);
  9. float c3;
  10. float c2;
  11. float c1;
  12. float c0;
  13.  
  14. c3 = (2 * x * x * x) - (3 * x * x) + 1;
  15. c2 = (x * x * x) - (2 * x * x) + x;
  16. c1 = (-2 * x * x * x) + (3 * x * x);
  17. c0 = (x * x * x) - (x * x);
  18.  
  19. p0t.multiply (c3);
  20. p1t.multiply (c1);
  21. p2t.multiply (c2);
  22. p3t.multiply (c0);
  23.  
  24. ans.add (p0t);
  25. ans.add (p1t);
  26. ans.add (p2t);
  27. ans.add (p3t);
  28.  
  29. return ans;
  30. }
  31.  
  32. public void renderCurve()
  33. {
  34. Vector p0,p1,p2,p3,p;
  35. for (int i = 0; i < points.Length; i = i + 4)
  36. {
  37. p0 = new Vector (points[i].x,points[i].y,points[i].z);
  38. p1 = new Vector (points[i + 1].x,points[i + 1].y,points[i + 1].z);
  39. p2 = new Vector (points[i + 2].x,points[i + 2].y,points[i + 2].z);
  40. p3 = new Vector (points[i + 3].x,points[i + 3].y,points[i + 3].z);
  41. for (float t = 0; t <= 1; t = (t + Time.deltaTime * 10))
  42. {
  43. p = hermite.getPoint (p0,p1,p2,p3,t);
  44. GameObject pobj = Instantiate (pointObject, new Vector3(p.x,p.y,0.0f), Quaternion.identity) as GameObject;
  45. }
  46. }
  47. }
Add Comment
Please, Sign In to add comment