Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1.  
  2. void GenerateActorPoints(int pointsPerCurve = 4)
  3. {
  4. //cPoints is an array that contains every control point of the polybezier
  5. int siz = cPoints.size();
  6. int halfway = floor(siz*0.5);
  7.  
  8. //will need special case later on probably.
  9. if(siz <= 4)
  10. return;
  11.  
  12. //not strictly needed perhaps, but cubic curves don't make sense with less than 4 segments per curve imo
  13. pointsPerCurve = max(4, pointsPerCurve);
  14.  
  15. //increased every time we create and actor point
  16. int counter = 0;
  17.  
  18. for(int i = 3; i< siz; i+=3) //three steps forward because we check backwards in the nested loop
  19. {
  20. for(int j = pointsPerCurve; j>=0; j--)
  21. {
  22. vector3 newPoint = PointOnCurve(j / double(pointsPerCurve), cPoints[i].pos, cPoints[i-1].pos, cPoints[i-2].pos, cPoints[i-3].pos,false);
  23.  
  24. //old method. We don't want to have to sample twice per point, since we can set/get from or on previous points.
  25. //vector3 endpoint = PointOnCurve((j+1) / double(pointsPerCurve), cPoints[i].pos, cPoints[i-1].pos, cPoints[i-2].pos, cPoints[i-3].pos,False);
  26.  
  27. DSH_ActorPoint pt = DSH_ActorPoint(DSH_actorPoint.init(newPoint));
  28.  
  29. //the idea the block below is to orient the pos/nextpos of the
  30. //actor points so their pos (i.e where the real actor will be
  31. //spawned is oriented outward to the end points from the midddle
  32. //point. Like this: <<<<<<<<middle>>>>>>>>>>
  33.  
  34. //|||||||||||||||||||||||||||
  35. if(i < halfway)
  36. {
  37. pt.pos = newPoint;
  38. if(counter>0)
  39. {
  40. actorPoints[counter-1].nextpos = newPoint;
  41. }
  42. }
  43.  
  44. else if(i <= halfway+1 && j == pointsPerCurve) //this is supposed to happen once, exactly after the halfway mark.
  45. {
  46. actorPoints[counter-1].nextpos = newPoint;
  47. //current actor will be effectively invisible here, but this makes everything work.
  48. //TODO: send halp
  49. pt.pos = newPoint;
  50. pt.nextpos = newPoint;
  51. }
  52. else
  53. {
  54. pt.pos = actorPoints[counter-1].nextPos;
  55. pt.nextPos = newPoint;
  56. }
  57. //|||||||||||||||||||||||||||
  58.  
  59. actorPoints.push(pt);
  60. counter++;
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement