Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- //how to use from an actor:
- DSH_kBezier bez = DSH_kBezier(new("DSH_kBezier"));
- bez.BeginCurveExplicit(/*vec3, vec3,vec3,vec3*/);
- bez.ExtendCurveExplicit(/*vec3, vec3, vec3*/);
- //continue calling ExtendCurveExplicit as many times as you want
- bez.SpawnBeams();
- */
- class DSH_cPoint: object
- {
- vector3 pos;
- static DSH_cPoint init(vector3 pushPos)
- {
- let p = new("DSH_cPoint");
- p.pos = pushPos;
- return p;
- }
- }
- class DSH_kBezier : object play
- {
- array<DSH_cPoint> cPoints;
- array<actor> actors;
- static Vector3 PointOnCurve(double t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
- {
- double u = 1 - t;
- double tt = t*t;
- double uu = u*u;
- double uuu = uu * u;
- double ttt = tt * t;
- Vector3 p = uuu * p0; //first term
- p += 3 * uu * t * p1; //second term
- p += 3 * u * tt * p2; //third term
- p += ttt * p3; //fourth term
- return p;
- }
- void BeginCurveExplicit(vector3 p0, vector3 p1, vector3 p2, vector3 p3)
- {
- //the first curve in the spline needs to have 4 control points.
- cPoints.Push(DSH_cPoint.init(p0));
- cPoints.Push(DSH_cPoint.init(p1));
- cPoints.Push(DSH_cPoint.init(p2));
- cPoints.Push(DSH_cPoint.init(p3));
- }
- void ExtendCurveExplicit(vector3 p0, vector3 p1, vector3 p2)
- {
- //the second one and all later ones will share a control point with the last curve.
- cPoints.Push(DSH_cPoint.init(p0));
- cPoints.Push(DSH_cPoint.init(p1));
- cPoints.Push(DSH_cPoint.init(p2));
- }
- void SpawnBeams()
- {
- int siz = cPoints.size();
- for(int k = 0; k<siz; k++)
- {
- if(true) //debug
- {
- actor.spawn("DSH_Dot",cPoints[k].pos);
- }
- }
- if(siz <= 4)
- {
- return;
- //TODO: will need special case for this
- }
- int limit = 10;
- limit = max(4, limit);
- for(int i = 3; i< siz; i+=3)
- {
- for(int j = 0; j<limit; j++)
- {
- if(true)
- {
- vector3 spawnpos = PointOnCurve(j / double(limit), cPoints[i].pos, cPoints[i-1].pos, cPoints[i-2].pos, cPoints[i-3].pos);
- vector3 nextpos = PointOnCurve((j+1) / double(limit), cPoints[i].pos, cPoints[i-1].pos, cPoints[i-2].pos, cPoints[i-3].pos);
- actor beam = actor.spawn("DSH_BasicBeam",spawnpos);
- //actors.push(beam);
- vector3 dif = level.Vec3Diff(spawnpos,nextpos);
- vector2 angs = DSH_kMath.AnglesFromVec3(dif);
- beam.angle = angs.x;
- beam.pitch = angs.y;
- beam.scale = (1.0,dif.length());
- }
- }
- }
- }
- }
- class DSH_Dot : actor
- {
- default
- {
- +noblockmap;
- +nogravity;
- +nointeraction;
- renderstyle "shaded";
- StencilColor "FF0000";
- scale 0.4;
- }
- Override void PostBeginPlay()
- {
- self.pitch -= 90.0;
- }
- states
- {
- spawn:
- TNT1 A 0 nodelay;
- BAL1 A 1 bright;
- stop;
- }
- }
- Class DSH_BasicBeam : actor
- {
- default
- {
- +noblockmap;
- +nogravity;
- +nointeraction;
- renderstyle "shaded";
- StencilColor "aaFFFF";
- alpha 3;
- }
- Override void PostBeginPlay()
- {
- self.pitch -= 90.0;
- }
- states
- {
- spawn:
- TNT1 A 0 nodelay;
- goto fadeloop;
- Fadeloop:
- MODL A 1 bright;
- stop;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement