@@ -2303,6 +2303,14 @@ public Action Command_ReloadZoneSettings(int client, int args)
2303
2303
return Plugin_Handled ;
2304
2304
}
2305
2305
2306
+ // Was originally used in beamer to replicate this gmod lua code:
2307
+ /*
2308
+ My code from tracegun.lua that I based this off of:
2309
+ local ang = tr.Normal:Angle() // calculate in SP with: ( traceRes.HitPos - traceRes.StartPos ):Normalize()
2310
+ ang:RotateAroundAxis(tr.HitNormal, 180)
2311
+ local dir = ang:Forward()*-1
2312
+ tr = util.TraceLine({start=tr.HitPos, endpos=tr.HitPos+(dir*100000), filter=players})
2313
+ */
2306
2314
stock void RotateAroundAxis (float v [3 ], const float in_k [3 ], float theta )
2307
2315
{
2308
2316
// https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula#Statement
@@ -2329,6 +2337,23 @@ stock void RotateAroundAxis(float v[3], const float in_k[3], float theta)
2329
2337
}
2330
2338
}
2331
2339
2340
+ stock void ReflectAngles (float direction [3 ], const float normal [3 ])
2341
+ {
2342
+ float fwd [3 ], reflected [3 ];
2343
+
2344
+ GetAngleVectors (direction , fwd , NULL_VECTOR , NULL_VECTOR );
2345
+
2346
+ float dot = GetVectorDotProduct (fwd , normal );
2347
+
2348
+ for (int i = 0 ; i < 3 ; i ++ )
2349
+ {
2350
+ reflected [i ] = fwd [i ] - 2.0 * dot * normal [i ];
2351
+ }
2352
+
2353
+ NormalizeVector (reflected , reflected );
2354
+ GetVectorAngles (reflected , direction );
2355
+ }
2356
+
2332
2357
public Action Command_Beamer (int client , int args )
2333
2358
{
2334
2359
static float rate_limit [MAXPLAYERS +1 ];
@@ -2348,15 +2373,6 @@ public Action Command_Beamer(int client, int args)
2348
2373
2349
2374
for (int C = 20 ; C >= 0 ; -- C )
2350
2375
{
2351
- /*
2352
- My code from tracegun.lua that I based this off of:
2353
- local ang = tr.Normal:Angle() // ( traceRes.HitPos - traceRes.StartPos ):Normalize()
2354
- ang:RotateAroundAxis(tr.HitNormal, 180)
2355
- local dir = ang:Forward()*-1
2356
-
2357
- tr = util.TraceLine({start=tr.HitPos, endpos=tr.HitPos+(dir*100000), filter=players})
2358
- */
2359
-
2360
2376
TR_TraceRayFilter (startpos , direction , MASK_ALL , RayType_Infinite , TRFilter_NoPlayers , client );
2361
2377
TR_GetEndPosition (endpos );
2362
2378
@@ -2381,16 +2397,12 @@ public Action Command_Beamer(int client, int args)
2381
2397
2382
2398
if (! C ) break ;
2383
2399
2384
- SubtractVectors (endpos , startpos , direction );
2385
- NormalizeVector (direction , direction );
2386
- GetVectorAngles (direction , direction );
2387
-
2388
2400
startpos = endpos ;
2389
2401
2390
2402
float hitnormal [3 ];
2391
2403
TR_GetPlaneNormal (INVALID_HANDLE , hitnormal );
2392
2404
2393
- RotateAroundAxis (direction , hitnormal , 180.0 );
2405
+ ReflectAngles (direction , hitnormal );
2394
2406
}
2395
2407
2396
2408
return Plugin_Handled ;
0 commit comments