Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1.  
  2. /*
  3. //how to use from an actor:
  4. DSH_kBezier bez = DSH_kBezier(new("DSH_kBezier"));
  5. bez.BeginCurveExplicit(/*vec3, vec3,vec3,vec3*/);
  6. bez.ExtendCurveExplicit(/*vec3, vec3, vec3*/);
  7. //continue calling ExtendCurveExplicit as many times as you want
  8. bez.SpawnBeams();
  9. */
  10.  
  11. class DSH_cPoint: object
  12. {
  13. vector3 pos;
  14. static DSH_cPoint init(vector3 pushPos)
  15. {
  16. let p = new("DSH_cPoint");
  17. p.pos = pushPos;
  18. return p;
  19. }
  20. }
  21.  
  22. class DSH_kBezier : object play
  23. {
  24. array<DSH_cPoint> cPoints;
  25. array<actor> actors;
  26.  
  27. static Vector3 PointOnCurve(double t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
  28. {
  29. double u = 1 - t;
  30. double tt = t*t;
  31. double uu = u*u;
  32. double uuu = uu * u;
  33. double ttt = tt * t;
  34. Vector3 p = uuu * p0; //first term
  35. p += 3 * uu * t * p1; //second term
  36. p += 3 * u * tt * p2; //third term
  37. p += ttt * p3; //fourth term
  38. return p;
  39. }
  40.  
  41. void BeginCurveExplicit(vector3 p0, vector3 p1, vector3 p2, vector3 p3)
  42. {
  43. //the first curve in the spline needs to have 4 control points.
  44. cPoints.Push(DSH_cPoint.init(p0));
  45. cPoints.Push(DSH_cPoint.init(p1));
  46. cPoints.Push(DSH_cPoint.init(p2));
  47. cPoints.Push(DSH_cPoint.init(p3));
  48. }
  49.  
  50. void ExtendCurveExplicit(vector3 p0, vector3 p1, vector3 p2)
  51. {
  52. //the second one and all later ones will share a control point with the last curve.
  53. cPoints.Push(DSH_cPoint.init(p0));
  54. cPoints.Push(DSH_cPoint.init(p1));
  55. cPoints.Push(DSH_cPoint.init(p2));
  56. }
  57.  
  58. void SpawnBeams()
  59. {
  60. int siz = cPoints.size();
  61. for(int k = 0; k<siz; k++)
  62. {
  63. if(true) //debug
  64. {
  65. actor.spawn("DSH_Dot",cPoints[k].pos);
  66. }
  67. }
  68. if(siz <= 4)
  69. {
  70. return;
  71. //TODO: will need special case for this
  72. }
  73. int limit = 10;
  74. limit = max(4, limit);
  75.  
  76. for(int i = 3; i< siz; i+=3)
  77. {
  78.  
  79. for(int j = 0; j<limit; j++)
  80. {
  81. if(true)
  82. {
  83. vector3 spawnpos = PointOnCurve(j / double(limit), cPoints[i].pos, cPoints[i-1].pos, cPoints[i-2].pos, cPoints[i-3].pos);
  84. vector3 nextpos = PointOnCurve((j+1) / double(limit), cPoints[i].pos, cPoints[i-1].pos, cPoints[i-2].pos, cPoints[i-3].pos);
  85. actor beam = actor.spawn("DSH_BasicBeam",spawnpos);
  86. //actors.push(beam);
  87. vector3 dif = level.Vec3Diff(spawnpos,nextpos);
  88. vector2 angs = DSH_kMath.AnglesFromVec3(dif);
  89. beam.angle = angs.x;
  90. beam.pitch = angs.y;
  91. beam.scale = (1.0,dif.length());
  92. }
  93. }
  94. }
  95. }
  96.  
  97. }
  98.  
  99. class DSH_Dot : actor
  100. {
  101. default
  102. {
  103. +noblockmap;
  104. +nogravity;
  105. +nointeraction;
  106. renderstyle "shaded";
  107. StencilColor "FF0000";
  108. scale 0.4;
  109. }
  110. Override void PostBeginPlay()
  111. {
  112. self.pitch -= 90.0;
  113. }
  114. states
  115. {
  116.  
  117. spawn:
  118. TNT1 A 0 nodelay;
  119. BAL1 A 1 bright;
  120. stop;
  121. }
  122. }
  123. Class DSH_BasicBeam : actor
  124. {
  125. default
  126. {
  127. +noblockmap;
  128. +nogravity;
  129. +nointeraction;
  130. renderstyle "shaded";
  131. StencilColor "aaFFFF";
  132. alpha 3;
  133. }
  134. Override void PostBeginPlay()
  135. {
  136. self.pitch -= 90.0;
  137. }
  138. states
  139. {
  140.  
  141. spawn:
  142. TNT1 A 0 nodelay;
  143. goto fadeloop;
  144. Fadeloop:
  145. MODL A 1 bright;
  146. stop;
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement