]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Porto launch: fix laser tracer
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 13 Mar 2016 09:31:56 +0000 (20:31 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 13 Mar 2016 09:31:56 +0000 (20:31 +1100)
qcsrc/client/main.qc
qcsrc/client/view.qc
qcsrc/lib/vector.qh

index 7fbdd9d183b44ad29185d0fff1bf28145840e1fc..ded6d5b32a9f2d1d4321dbea3b8b37254533684b 100644 (file)
@@ -332,7 +332,6 @@ void Playerchecker_Think()
        this.nextthink = time + 0.2;
 }
 
        this.nextthink = time + 0.2;
 }
 
-void Porto_Init();
 void TrueAim_Init();
 void PostInit()
 {
 void TrueAim_Init();
 void PostInit()
 {
@@ -340,7 +339,6 @@ void PostInit()
        playerchecker.think = Playerchecker_Think;
        playerchecker.nextthink = time + 0.2;
 
        playerchecker.think = Playerchecker_Think;
        playerchecker.nextthink = time + 0.2;
 
-       Porto_Init();
        TrueAim_Init();
 
        postinit = true;
        TrueAim_Init();
 
        postinit = true;
index c1786f41f111330766afefda95f0322a1eda6a5e..70a4f2eeb1d579a0f894998cb4b999a902c5b5e2 100644 (file)
@@ -340,90 +340,75 @@ STATIC_INIT(viewmodel) {
     viewmodel = new(viewmodel);
 }
 
     viewmodel = new(viewmodel);
 }
 
-entity porto;
-vector polyline[16];
-void Porto_Draw(entity this)
+void Porto_Draw(entity this);
+STATIC_INIT(Porto)
 {
 {
-       vector p, dir, ang, q, nextdir;
-       float portal_number, portal1_idx;
-
-       if(activeweapon != WEP_PORTO || spectatee_status || gametype == MAPINFO_TYPE_NEXBALL)
-               return;
-       if(WEP_CVAR(porto, secondary))
-               return;
-       if(intermission == 1)
-               return;
-       if(intermission == 2)
-               return;
-       if (STAT(HEALTH) <= 0)
-               return;
+       entity e = new_pure(porto);
+       e.draw = Porto_Draw;
+       e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
+}
 
 
-       dir = view_forward;
+const int polyline_length = 16;
+vector polyline[polyline_length];
+void Porto_Draw(entity this)
+{
+       if (activeweapon != WEP_PORTO) return;
+       if (spectatee_status) return;
+       if (WEP_CVAR(porto, secondary)) return;
+       if (intermission == 1) return;
+       if (intermission == 2) return;
+       if (STAT(HEALTH) <= 0) return;
 
 
-       if(angles_held_status)
+       vector pos = view_origin;
+       vector dir = view_forward;
+       if (angles_held_status)
        {
                makevectors(angles_held);
                dir = v_forward;
        }
 
        {
                makevectors(angles_held);
                dir = v_forward;
        }
 
-       p = view_origin;
-
-       polyline[0] = p;
-       int idx = 1;
-       portal_number = 0;
-       nextdir = dir;
+       polyline[0] = pos;
 
 
-       for (;;)
+       int portal_number = 0, portal1_idx = 1, portal_max = 2;
+       int n = 1 + 2;  // 2 lines == 3 points
+       for (int idx = 0; idx < n && idx < polyline_length - 1; )
        {
        {
-               dir = nextdir;
-               traceline(p, p + 65536 * dir, true, porto);
-               if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
-                       return;
-               nextdir = dir - 2 * (dir * trace_plane_normal) * trace_plane_normal; // mirror dir at trace_plane_normal
-               p = trace_endpos;
-               polyline[idx] = p;
-               ++idx;
-               if(idx >= 16)
-                       return;
-               if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
-                       continue;
-               ++portal_number;
-               ang = vectoangles2(trace_plane_normal, dir);
-               ang.x = -ang.x;
-               makevectors(ang);
-               if(!CheckWireframeBox(porto, p - 48 * v_right - 48 * v_up + 16 * v_forward, 96 * v_right, 96 * v_up, 96 * v_forward))
-                       return;
-               if(portal_number == 1)
+               traceline(pos, pos + 65536 * dir, true, this);
+               dir = reflect(dir, trace_plane_normal);
+               pos = trace_endpos;
+               polyline[++idx] = pos;
+               if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK || trace_dphitcontents & DPCONTENTS_PLAYERCLIP)
                {
                {
-                       portal1_idx = idx;
-                       if(portal_number >= 2)
-                               break;
+                       n += 1;
+                       continue;
                }
                }
-       }
-
-       while(idx >= 2)
-       {
-               p = polyline[idx-2];
-               q = polyline[idx-1];
-               if(idx == 2)
-                       p = p - view_up * 16;
-               if(idx-1 >= portal1_idx)
+               if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT)
                {
                {
-                       Draw_CylindricLine(p, q, 4, "", 1, 0, '0 0 1', 0.5, DRAWFLAG_NORMAL, view_origin);
+                       n = max(2, idx);
+                       break;
                }
                }
-               else
+               // check size
                {
                {
-                       Draw_CylindricLine(p, q, 4, "", 1, 0, '1 0 0', 0.5, DRAWFLAG_NORMAL, view_origin);
+                       vector ang = vectoangles2(trace_plane_normal, dir);
+                       ang.x = -ang.x;
+                       makevectors(ang);
+                       if (!CheckWireframeBox(this, pos - 48 * v_right - 48 * v_up + 16 * v_forward, 96 * v_right, 96 * v_up, 96 * v_forward))
+                       {
+                               n = max(2, idx);
+                               break;
+                       }
                }
                }
-               --idx;
+               portal_number += 1;
+               if (portal_number >= portal_max) break;
+               if (portal_number == 1) portal1_idx = idx;
+       }
+       for (int idx = 0; idx < n - 1; ++idx)
+       {
+               vector p = polyline[idx], q = polyline[idx + 1];
+               if (idx == 0) p -= view_up * 16;  // line from player
+               vector rgb = (idx < portal1_idx) ? '1 0 0' : '0 0 1';
+               Draw_CylindricLine(p, q, 4, "", 1, 0, rgb, 0.5, DRAWFLAG_NORMAL, view_origin);
        }
        }
-}
-
-void Porto_Init()
-{
-       porto = new_pure(porto);
-       porto.draw = Porto_Draw;
-       porto.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
 }
 
 float drawtime;
 }
 
 float drawtime;
index 21b931e9319352f663f0773aa5280ac0eeda8e49..def1dae2d489f512a0c677087943814c00f8b8a7 100644 (file)
@@ -87,7 +87,9 @@ float boxinsidebox(vector smins, vector smaxs, vector bmins, vector bmaxs) { ret
 } MACRO_END
 
 noref vector _vec2;
 } MACRO_END
 
 noref vector _vec2;
-#define vec2(v) (_vec2 = (v), _vec2.z = 0, _vec2)
+#define vec2(...) EVAL(OVERLOAD(vec2, __VA_ARGS__))
+#define vec2_1(v) (_vec2 = (v), _vec2.z = 0, _vec2)
+#define vec2_2(x, y) (_vec2_x = (x), _vec2_y = (y), _vec2)
 
 noref vector _vec3;
 #define vec3(_x, _y, _z) (_vec3.x = (_x), _vec3.y = (_y), _vec3.z = (_z), _vec3)
 
 noref vector _vec3;
 #define vec3(_x, _y, _z) (_vec3.x = (_x), _vec3.y = (_y), _vec3.z = (_z), _vec3)
@@ -104,6 +106,16 @@ vector rotate(vector v, float a)
 noref vector _yinvert;
 #define yinvert(v) (_yinvert = (v), _yinvert.y = 1 - _yinvert.y, _yinvert)
 
 noref vector _yinvert;
 #define yinvert(v) (_yinvert = (v), _yinvert.y = 1 - _yinvert.y, _yinvert)
 
+/**
+ * @param dir the directional vector
+ * @param norm the normalized normal
+ * @returns dir reflected by norm
+ */
+vector reflect(vector dir, vector norm)
+{
+       return dir - 2 * (dir * norm) * norm;
+}
+
 #ifndef MENUQC
        vector get_corner_position(entity box, int corner)
        {
 #ifndef MENUQC
        vector get_corner_position(entity box, int corner)
        {