rituals_ppc.cpp 208 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#line 1 "src\\rituals_main.cpp"












 






William Bundy's avatar
William Bundy committed
21 22 23 24 25 26 27 28
#line 21 "src\\rituals_main.cpp"







29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59































William Bundy's avatar
William Bundy committed
60
#line 1 "c:\\users\\william\\stuff\\development\\rituals\\src\\rituals_defines.h"
61 62 63 64 65 66 67 68 69 70










William Bundy's avatar
William Bundy committed
71 72
#pragma once

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

typedef float real32;
typedef double real64;



typedef real32 real;




William Bundy's avatar
William Bundy committed
93 94 95 96 97 98 99 100 101
#line 34 "c:\\users\\william\\stuff\\development\\rituals\\src\\rituals_defines.h"



typedef int32 integer;
typedef real32 real;



102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

typedef ptrdiff_t isize;
typedef size_t usize;





























William Bundy's avatar
William Bundy committed
134 135 136 137 138 139 140 141 142 143 144










#line 60 "src\\rituals_main.cpp"
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171











#line 1 "c:\\users\\william\\stuff\\development\\rituals\\src\\rituals_math.cpp"













 

William Bundy's avatar
William Bundy committed
172

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
inline real clamp(real x, real min, real max)
{
	if(x < min) x = min;
	else if(x > max) x = max;
	return x;
}

real clamp_01(real x)
{
	return clamp(x, 0.0f, 1.0f);	
}

real lerp(real a, real b, real t)
{
	return (1.0f - t) * a + t * b;
}

William Bundy's avatar
William Bundy committed
190 191 192



193 194 195 196 197 198 199 200
union Vec2 
{
	struct {
		real x, y;
	};
	real e[2];
};

William Bundy's avatar
William Bundy committed
201 202 203 204 205 206 207
union Vec3
{
	struct {
		real x, y, z;
	};
	real e[3];
};
208

William Bundy's avatar
William Bundy committed
209
union Vec4
210
{
William Bundy's avatar
William Bundy committed
211 212 213 214 215 216
	struct {
		real x, y, z, w;
	};
	real e[4];
	
};
217

William Bundy's avatar
William Bundy committed
218
union Vec2i
219
{
William Bundy's avatar
William Bundy committed
220 221 222 223 224
	struct {
		integer x, y;
	};
	integer e[2];
};
225

William Bundy's avatar
William Bundy committed
226
union Vec3i
227
{
William Bundy's avatar
William Bundy committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	struct {
		integer x, y, z;
	};
	integer e[3];
};

union Vec4i
{
	struct {
		integer x, y, z, w;
	};
	integer e[4];
	
};

#line 88 "c:\\users\\william\\stuff\\development\\rituals\\src\\rituals_math.cpp"



static inline Vec2 v2(real x, real y)
{
	return Vec2{x, y};
250 251
}

William Bundy's avatar
William Bundy committed
252
static inline Vec3 v3(real x, real y, real z)
253
{
William Bundy's avatar
William Bundy committed
254 255 256
	return Vec3{
		x, y, z
	};
257 258
}

William Bundy's avatar
William Bundy committed
259
static inline Vec4 v4(real x, real y, real z, real w)
260
{
William Bundy's avatar
William Bundy committed
261 262 263
	return Vec4{
		x, y, z, w
	};
264
}
William Bundy's avatar
William Bundy committed
265 266

static inline Vec2i v2i(integer x, integer y)
267
{
William Bundy's avatar
William Bundy committed
268 269 270
	return Vec2i {
		x, y
	};
271 272
}

William Bundy's avatar
William Bundy committed
273
static inline Vec3i v3i(integer x, integer y, integer z)
274
{
William Bundy's avatar
William Bundy committed
275 276 277
	return Vec3i{
		x, y, z
	};
278 279
}

William Bundy's avatar
William Bundy committed
280
static inline Vec4i v4i(integer x, integer y, integer z, integer w)
281
{
William Bundy's avatar
William Bundy committed
282 283 284
	return Vec4i{
		x, y, z, w
	};
285 286
}

William Bundy's avatar
William Bundy committed
287 288 289


static inline Vec2 v2(Vec2i vi)
290
{
William Bundy's avatar
William Bundy committed
291
	return v2(vi.x, vi.y);
292 293
}

William Bundy's avatar
William Bundy committed
294
static inline Vec2 v2(Vec3 vi)
295
{
William Bundy's avatar
William Bundy committed
296
	return v2(vi.x, vi.y);
297 298
}

William Bundy's avatar
William Bundy committed
299
static inline Vec3 v3(Vec3i vi)
300
{
William Bundy's avatar
William Bundy committed
301
    return v3(vi.x, vi.y, vi.z);
302 303
}

William Bundy's avatar
William Bundy committed
304
static inline Vec3 v3(Vec2 vi)
305
{
William Bundy's avatar
William Bundy committed
306 307
    return v3(vi.x, vi.y, 0);
}
308

William Bundy's avatar
William Bundy committed
309 310 311 312
static inline Vec3 v3(Vec2 vi, real z)
{
    return v3(vi.x, vi.y, z);
}
313

William Bundy's avatar
William Bundy committed
314
static inline Vec4 v4(Vec4i vi)
315
{
William Bundy's avatar
William Bundy committed
316 317
    return v4(vi.x, vi.y, vi.z, vi.w);
}
318

William Bundy's avatar
William Bundy committed
319
static inline Vec4 v4(Vec2 vi)
320
{
William Bundy's avatar
William Bundy committed
321
    return v4(vi.x, vi.y, 0, 0);
322 323
}

William Bundy's avatar
William Bundy committed
324
static inline Vec4 v4(Vec2 vi, real z, real w)
325
{
William Bundy's avatar
William Bundy committed
326
    return v4(vi.x, vi.y, z, w);
327 328
}

William Bundy's avatar
William Bundy committed
329
static inline Vec4 v4(Vec3 vi)
330
{
William Bundy's avatar
William Bundy committed
331
    return v4(vi.x, vi.y, vi.z, 0);
332 333
}

William Bundy's avatar
William Bundy committed
334
static inline Vec4 v4(Vec3 vi, real w)
335
{
William Bundy's avatar
William Bundy committed
336
    return v4(vi.x, vi.y, vi.z, w);
337 338
}

William Bundy's avatar
William Bundy committed
339
static inline Vec2i v2i(Vec2 vi)
340
{
William Bundy's avatar
William Bundy committed
341
    return v2i((integer)vi.x, (integer)vi.y);
342 343
}

William Bundy's avatar
William Bundy committed
344
static inline Vec3i v3i(Vec3 vi)
345
{
William Bundy's avatar
William Bundy committed
346
    return v3i((integer)vi.x, (integer)vi.y, (integer)vi.z);
347 348
}

William Bundy's avatar
William Bundy committed
349
static inline Vec4i v4i(Vec4 vi)
350
{
William Bundy's avatar
William Bundy committed
351
    return v4i((integer)vi.x, (integer)vi.y, (integer)vi.z, (integer)vi.w);
352
}
William Bundy's avatar
William Bundy committed
353 354 355 356 357 358
#line 198 "c:\\users\\william\\stuff\\development\\rituals\\src\\rituals_math.cpp"





359

William Bundy's avatar
William Bundy committed
360 361 362 363 364 365 366 367 368 369 370










static inline Vec2 v2_negate(Vec2 a)
371
{
William Bundy's avatar
William Bundy committed
372
	return Vec2{-a.x, -a.y};
373
}
William Bundy's avatar
William Bundy committed
374 375

static inline Vec2 v2_sub(Vec2 a, Vec2 b)
376
{
William Bundy's avatar
William Bundy committed
377
	return Vec2{a.x - b.x, a.y - b.y};
378 379
}

William Bundy's avatar
William Bundy committed
380
static inline Vec2 v2_add(Vec2 a, Vec2 b)
381
{
William Bundy's avatar
William Bundy committed
382
	return Vec2{a.x + b.x, a.y + b.y};
383 384
}

William Bundy's avatar
William Bundy committed
385
static inline Vec2 v2_add_scaled(Vec2 a, Vec2 b, real scale)
386
{
William Bundy's avatar
William Bundy committed
387
	return Vec2{a.x + b.x * scale, a.y + b.y * scale};
388 389
}

William Bundy's avatar
William Bundy committed
390 391

static inline Vec2 v2_mul(Vec2 a, real s)
392
{
William Bundy's avatar
William Bundy committed
393
	return Vec2{a.x * s, a.y * s};
394 395
}

William Bundy's avatar
William Bundy committed
396
static inline Vec2 v2_div(Vec2 a, real s)
397
{
William Bundy's avatar
William Bundy committed
398
	return v2_mul(a, 1.0f / s);
399 400
}

William Bundy's avatar
William Bundy committed
401
static inline Vec2 v2_component_mul(Vec2 a, Vec2 b)
402
{
William Bundy's avatar
William Bundy committed
403
	return Vec2{a.x * b.x, a.y * b.y};
404 405 406 407
}



William Bundy's avatar
William Bundy committed
408 409 410 411
static inline Vec3 v3_negate(Vec3 a)
{
	return Vec3{-a.x, -a.y, -a.z};
}
412

William Bundy's avatar
William Bundy committed
413
static inline Vec3 v3_sub(Vec3 a, Vec3 b)
414
{
William Bundy's avatar
William Bundy committed
415
	return Vec3{a.x - b.x, a.y - b.y, a.z - b.z};
416 417
}

William Bundy's avatar
William Bundy committed
418
static inline Vec3 v3_add(Vec3 a, Vec3 b)
419
{
William Bundy's avatar
William Bundy committed
420
	return Vec3{a.x + b.x, a.y + b.y, a.z + b.z};
421
}
William Bundy's avatar
William Bundy committed
422 423

static inline Vec3 v3_add_scaled(Vec3 a, Vec3 b, real scale)
424
{
William Bundy's avatar
William Bundy committed
425
	return Vec3{a.x + b.x * scale, a.y + b.y * scale, a.z + b.z * scale};
426 427
}

William Bundy's avatar
William Bundy committed
428
static inline Vec3 v3_mul(Vec3 a, real s)
429
{
William Bundy's avatar
William Bundy committed
430
	return Vec3{a.x * s, a.y * s, a.z * s};
431
}
William Bundy's avatar
William Bundy committed
432 433

static inline Vec3 v3_div(Vec3 a, real s)
434
{
William Bundy's avatar
William Bundy committed
435
	return v3_mul(a, 1.0f/s);
436 437
}

William Bundy's avatar
William Bundy committed
438
static inline Vec3 v3_component_mul(Vec3 a, Vec3 b)
439
{
William Bundy's avatar
William Bundy committed
440
	return Vec3{a.x * b.x, a.y * b.y, a.z * b.z};
441 442 443
}


William Bundy's avatar
William Bundy committed
444 445

static inline Vec4 v4_negate(Vec4 a)
446
{
William Bundy's avatar
William Bundy committed
447
    return Vec4{-a.x, -a.y, -a.z, -a.w};
448 449
}

William Bundy's avatar
William Bundy committed
450
static inline Vec4 v4_add(Vec4 a, Vec4 b)
451
{
William Bundy's avatar
William Bundy committed
452
	return Vec4{a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w};
453 454
}

William Bundy's avatar
William Bundy committed
455 456 457 458
static inline Vec4 v4_add_scaled(Vec4 a, Vec4 b, real scale)
{
	return Vec4{a.x + b.x * scale, a.y + b.y * scale, a.z + b.z * scale, a.w + b.w * scale};
}
459

William Bundy's avatar
William Bundy committed
460
static inline Vec4 v4_sub(Vec4 a, Vec4 b)
461
{
William Bundy's avatar
William Bundy committed
462
	return Vec4{a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w};
463
}
William Bundy's avatar
William Bundy committed
464 465

static inline Vec4 v4_compenent_mul(Vec4 a, Vec4 b)
466
{
William Bundy's avatar
William Bundy committed
467
	return Vec4{a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w};
468 469
}

William Bundy's avatar
William Bundy committed
470
static inline Vec4 v4_mul(Vec4 a, real b)
471
{
William Bundy's avatar
William Bundy committed
472
	return Vec4{a.x * b, a.y * b, a.z * b, a.w * b};
473 474
}

William Bundy's avatar
William Bundy committed
475
static inline Vec4 v4_div(Vec4 a, real b)
476
{
William Bundy's avatar
William Bundy committed
477
	return  v4_mul(a, 1.0f/b);
478 479 480 481
}



William Bundy's avatar
William Bundy committed
482
static inline Vec2i v2i_negate(Vec2i a)
483
{
William Bundy's avatar
William Bundy committed
484
	return Vec2i{-a.x, -a.y};
485 486
}

William Bundy's avatar
William Bundy committed
487
static inline Vec2i v2i_sub(Vec2i a, Vec2i b)
488
{
William Bundy's avatar
William Bundy committed
489
	return Vec2i{a.x - b.x, a.y - b.y};
490 491
}

William Bundy's avatar
William Bundy committed
492
static inline Vec2i v2i_add(Vec2i a, Vec2i b)
493
{
William Bundy's avatar
William Bundy committed
494
	return Vec2i{a.x + b.x, a.y + b.y};
495 496
}

William Bundy's avatar
William Bundy committed
497
static inline Vec2i v2i_add_scaled(Vec2i a, Vec2i b, real scale)
498
{
William Bundy's avatar
William Bundy committed
499
	return Vec2i{a.x + (integer)(b.x * scale), a.y + (integer)(b.y * scale)};
500
}
William Bundy's avatar
William Bundy committed
501
static inline Vec2i v2i_addi_scaled(Vec2i a, Vec2i b, integer scale)
502
{
William Bundy's avatar
William Bundy committed
503
	return Vec2i{a.x + (integer)(b.x * scale), a.y + (integer)(b.y * scale)};
504 505
}

William Bundy's avatar
William Bundy committed
506
static inline Vec2i v2i_mul(Vec2i a, real s)
507
{
William Bundy's avatar
William Bundy committed
508
	return Vec2i{(integer)(a.x * s), (integer)(a.y * s)};
509 510
}

William Bundy's avatar
William Bundy committed
511
static inline Vec2i v2i_muli(Vec2i a, integer s)
512
{
William Bundy's avatar
William Bundy committed
513 514
	return Vec2i{(integer)(a.x * s), (integer)(a.y * s)};
}
515

William Bundy's avatar
William Bundy committed
516 517 518 519
static inline Vec2i v2i_div(Vec2i a, real s)
{
	return v2i_mul(a, 1.0f / s);
}
520

William Bundy's avatar
William Bundy committed
521 522 523 524
static inline Vec2i v2i_divi(Vec2i a, integer s)
{
	return Vec2i{a.x / s, a.y / s};
}
525 526


William Bundy's avatar
William Bundy committed
527 528 529 530
static inline Vec2i v2i_component_mul(Vec2i a, Vec2i b)
{
	return Vec2i{a.x * b.x, a.y * b.y};
}
531 532 533



William Bundy's avatar
William Bundy committed
534
static inline Vec3i v3i_negate(Vec3i a)
535
{
William Bundy's avatar
William Bundy committed
536 537
	return Vec3i{-a.x, -a.y, -a.z};
}
538

William Bundy's avatar
William Bundy committed
539
static inline Vec3i v3i_sub(Vec3i a, Vec3i b)
540
{
William Bundy's avatar
William Bundy committed
541
	return Vec3i{a.x - b.x, a.y - b.y, a.z - b.z};
542 543
}

William Bundy's avatar
William Bundy committed
544
static inline Vec3i v3i_add(Vec3i a, Vec3i b)
545
{
William Bundy's avatar
William Bundy committed
546 547
	return Vec3i{a.x + b.x, a.y + b.y, a.z + b.z};
}
548

William Bundy's avatar
William Bundy committed
549
static inline Vec3i v3i_add_scaled(Vec3i a, Vec3i b, real scale)
550
{
William Bundy's avatar
William Bundy committed
551
	return Vec3i{a.x + (integer)(b.x * scale), a.y + (integer)(b.y * scale), a.z + (integer)(b.z * scale)};
552 553
}

William Bundy's avatar
William Bundy committed
554
static inline Vec3i v3i_addi_scaled(Vec3i a, Vec3i b, integer scale)
555
{
William Bundy's avatar
William Bundy committed
556 557
	return Vec3i{a.x + (integer)(b.x * scale), a.y + (integer)(b.y * scale), a.z + (integer)(b.z * scale)};
}
558

William Bundy's avatar
William Bundy committed
559
static inline Vec3i v3i_mul(Vec3i a, real s)
560
{
William Bundy's avatar
William Bundy committed
561
	return Vec3i{(integer)(a.x * s), (integer)(a.y * s), (integer)(a.z * s)};
562 563
}

William Bundy's avatar
William Bundy committed
564
static inline Vec3i v3i_muli(Vec3i a, integer s)
565
{
William Bundy's avatar
William Bundy committed
566
	return Vec3i{a.x * s, a.y * s, a.z * s};
567 568
}

William Bundy's avatar
William Bundy committed
569
static inline Vec3i v3i_div(Vec3i a, real s)
570
{
William Bundy's avatar
William Bundy committed
571
	return v3i_mul(a, 1.0f/s);
572 573
}

William Bundy's avatar
William Bundy committed
574
static inline Vec3i v3i_divi(Vec3i a, integer s)
575
{
William Bundy's avatar
William Bundy committed
576
	return Vec3i{a.x / s, a.y / s, a.z / s};
577 578 579
}


William Bundy's avatar
William Bundy committed
580
static inline Vec3i v3i_component_mul(Vec3i a, Vec3i b)
581
{
William Bundy's avatar
William Bundy committed
582
	return Vec3i{a.x * b.x, a.y * b.y, a.z * b.z};
583 584 585
}


William Bundy's avatar
William Bundy committed
586 587

static inline Vec4i v4i_negate(Vec4i a)
588
{
William Bundy's avatar
William Bundy committed
589
    return Vec4i{-a.x, -a.y, -a.z, -a.w};
590 591
}

William Bundy's avatar
William Bundy committed
592
static inline Vec4i v4i_add(Vec4i a, Vec4i b)
593
{
William Bundy's avatar
William Bundy committed
594
	return Vec4i{a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w};
595 596
}

William Bundy's avatar
William Bundy committed
597
static inline Vec4i v4i_add_scaled(Vec4i a, Vec4i b, real scale)
598
{
William Bundy's avatar
William Bundy committed
599
	return Vec4i{a.x + (integer)(b.x * scale), a.y + (integer)(b.y * scale), a.z + (integer)(b.z * scale), a.w + (integer)(b.w * scale)};
600 601
}

William Bundy's avatar
William Bundy committed
602
static inline Vec4i v4i_addi_scaled(Vec4i a, Vec4i b, integer scale)
603
{
William Bundy's avatar
William Bundy committed
604
	return Vec4i{a.x + (integer)(b.x * scale), a.y + (integer)(b.y * scale), a.z + (integer)(b.z * scale), a.w + (integer)(b.w * scale)};
605 606
}

William Bundy's avatar
William Bundy committed
607
static inline Vec4i v4i_sub(Vec4i a, Vec4i b)
608
{
William Bundy's avatar
William Bundy committed
609 610
	return Vec4i{a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w};
}
611

William Bundy's avatar
William Bundy committed
612
static inline Vec4i v4i_compenent_mul(Vec4i a, Vec4i b)
613
{
William Bundy's avatar
William Bundy committed
614
	return Vec4i{a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w};
615 616
}

William Bundy's avatar
William Bundy committed
617
static inline Vec4i v4i_mul(Vec4i a, real b)
618
{
William Bundy's avatar
William Bundy committed
619
	return Vec4i{(integer)(a.x * b), (integer)(a.y * b), (integer)(a.z * b), (integer)(a.w * b)};
620
}
William Bundy's avatar
William Bundy committed
621
static inline Vec4i v4i_muli(Vec4i a, integer b)
622
{
William Bundy's avatar
William Bundy committed
623
	return Vec4i{(integer)(a.x * b), (integer)(a.y * b), (integer)(a.z * b), (integer)(a.w * b)};
624 625
}

William Bundy's avatar
William Bundy committed
626 627 628 629
static inline Vec4i v4i_divi(Vec4i a, real b)
{
	return Vec4i{(integer)(a.x / b), (integer)(a.y / b), (integer)(a.z / b), (integer)(a.w / b)};
}
630

William Bundy's avatar
William Bundy committed
631 632 633 634
static inline Vec4i v4i_div(Vec4i a, real b)
{
	return  v4i_mul(a, 1.0f/b);
}
635 636 637 638 639 640






William Bundy's avatar
William Bundy committed
641 642 643 644
static inline Vec2 operator-(Vec2 a)
{
	return Vec2{-a.x, -a.y};
}
645

William Bundy's avatar
William Bundy committed
646 647 648 649
static inline Vec2 operator-(Vec2 a, Vec2 b)
{
	return Vec2{a.x - b.x, a.y - b.y};
}
650

William Bundy's avatar
William Bundy committed
651 652 653 654
static inline Vec2 operator+(Vec2 a, Vec2 b)
{
	return Vec2{a.x + b.x, a.y + b.y};
}
655

William Bundy's avatar
William Bundy committed
656 657 658 659
static inline Vec2 operator*(Vec2 a, real s)
{
	return Vec2{a.x * s, a.y * s};
}
660

William Bundy's avatar
William Bundy committed
661 662 663 664
static inline Vec2 operator*(real s, Vec2 a)
{
	return Vec2{a.x * s, a.y * s};
}
665

William Bundy's avatar
William Bundy committed
666 667 668 669
static inline Vec2 operator/(Vec2 a, real s)
{
	return a * (1.0f / s);
}
670

William Bundy's avatar
William Bundy committed
671 672 673 674
static inline Vec2 operator*(Vec2 a, Vec2 b)
{
	return Vec2{a.x * b.x, a.y * b.y};
}
675

William Bundy's avatar
William Bundy committed
676 677 678 679 680
static inline Vec2& operator+=(Vec2& a, Vec2 b)
{
	a = a + b;
	return a;
}
681

William Bundy's avatar
William Bundy committed
682 683 684 685 686
static inline Vec2& operator-=(Vec2& a, Vec2 b)
{
	a = a - b;
	return a;
}
687

William Bundy's avatar
William Bundy committed
688 689 690 691 692
static inline Vec2& operator*=(Vec2& a, real b)
{
	a = a * b;
	return a;
}
693

William Bundy's avatar
William Bundy committed
694 695 696 697 698
static inline Vec2& operator*=(Vec2& a, Vec2 b)
{
	a = a * b;
	return a;
}
699

William Bundy's avatar
William Bundy committed
700 701 702 703 704
static inline Vec2& operator/=(Vec2& a, real b)
{
	a = a / b;
	return a;
}
705 706 707



William Bundy's avatar
William Bundy committed
708 709 710 711
static inline Vec3 operator-(Vec3 a)
{
	return Vec3{-a.x, -a.y, -a.z};
}
712

William Bundy's avatar
William Bundy committed
713 714 715 716
static inline Vec3 operator-(Vec3 a, Vec3 b)
{
	return Vec3{a.x - b.x, a.y - b.y, a.z - b.z};
}
717

William Bundy's avatar
William Bundy committed
718 719 720 721
static inline Vec3 operator+(Vec3 a, Vec3 b)
{
	return Vec3{a.x + b.x, a.y + b.y, a.z + b.z};
}
722

William Bundy's avatar
William Bundy committed
723 724 725 726
static inline Vec3 operator*(Vec3 a, real s)
{
	return Vec3{a.x * s, a.y * s, a.z * s};
}
727

William Bundy's avatar
William Bundy committed
728 729 730 731
static inline Vec3 operator*(real s, Vec3 a)
{
	return Vec3{a.x * s, a.y * s, a.z * s};
}
732

William Bundy's avatar
William Bundy committed
733 734 735 736
static inline Vec3 operator/(Vec3 a, real s)
{
	return a * (1.0f / s);
}
737

William Bundy's avatar
William Bundy committed
738 739 740 741
static inline Vec3 operator*(Vec3 a, Vec3 b)
{
	return Vec3{a.x * b.x, a.y * b.y, a.z * b.z};
}
742

William Bundy's avatar
William Bundy committed
743 744 745 746 747
static inline Vec3& operator+=(Vec3& a, Vec3 b)
{
	a = a + b;
	return a;
}
748

William Bundy's avatar
William Bundy committed
749 750 751 752 753
static inline Vec3& operator-=(Vec3& a, Vec3 b)
{
	a = a - b;
	return a;
}
754

William Bundy's avatar
William Bundy committed
755 756 757 758 759
static inline Vec3& operator*=(Vec3& a, real b)
{
	a = a * b;
	return a;
}
760

William Bundy's avatar
William Bundy committed
761 762 763 764 765
static inline Vec3& operator*=(Vec3& a, Vec3 b)
{
	a = a * b;
	return a;
}
766

William Bundy's avatar
William Bundy committed
767 768 769 770 771
static inline Vec3& operator/=(Vec3& a, real b)
{
	a = a / b;
	return a;
}
772 773 774 775




William Bundy's avatar
William Bundy committed
776 777 778 779
static inline Vec4 operator-(Vec4 a)
{
    return Vec4{-a.x, -a.y, -a.z, -a.w};
}
780

William Bundy's avatar
William Bundy committed
781 782 783 784
static inline Vec4 operator+(Vec4 a, Vec4 b)
{
	return Vec4{a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w};
}
785

William Bundy's avatar
William Bundy committed
786 787 788 789
static inline Vec4 operator-(Vec4 a, Vec4 b)
{
	return Vec4{a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w};
}
790

William Bundy's avatar
William Bundy committed
791 792 793 794
static inline Vec4 operator*(Vec4 a, Vec4 b)
{
	return Vec4{a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w};
}
795

William Bundy's avatar
William Bundy committed
796 797 798 799 800 801 802 803 804 805 806 807
static inline Vec4 operator*(Vec4 a, real b)
{
	return Vec4{a.x * b, a.y * b, a.z * b, a.w * b};
}
static inline Vec4 operator*(real b, Vec4 a) 
{
	return a * b;
}
static inline Vec4 operator/(Vec4 a, real b)
{
	return a * (1.0f/b);
}
808

William Bundy's avatar
William Bundy committed
809 810 811 812 813
static inline Vec4 operator+=(Vec4& a, Vec4 b)
{
    a = a + b;
    return a;
}
814

William Bundy's avatar
William Bundy committed
815 816 817 818 819
static inline Vec4 operator-=(Vec4& a, Vec4 b)
{
    a = a - b;
    return a;
}
820

William Bundy's avatar
William Bundy committed
821 822 823 824 825
static inline Vec4 operator*=(Vec4& a, real b)
{
	a = a * b;
	return a;
}
826

William Bundy's avatar
William Bundy committed
827 828 829 830 831
static inline Vec4 operator/=(Vec4& a, real b)
{
	a = a / b;
	return a;
}
832 833


William Bundy's avatar
William Bundy committed
834 835 836 837 838
static inline Vec4 operator*=(Vec4& a, Vec4 b)
{
    a = a * b;
    return a;
}
839 840 841



William Bundy's avatar
William Bundy committed
842 843 844 845
static inline Vec2i operator-(Vec2i a)
{
	return Vec2i{-a.x, -a.y};
}
846

William Bundy's avatar
William Bundy committed
847 848 849 850
static inline Vec2i operator-(Vec2i a, Vec2i b)
{
	return Vec2i{a.x - b.x, a.y - b.y};
}
851

William Bundy's avatar
William Bundy committed
852 853 854 855
static inline Vec2i operator+(Vec2i a, Vec2i b)
{
	return Vec2i{a.x + b.x, a.y + b.y};
}
856

William Bundy's avatar
William Bundy committed
857 858 859 860
static inline Vec2i operator*(Vec2i a, integer s)
{
	return Vec2i{a.x * s, a.y * s};
}
861

William Bundy's avatar
William Bundy committed
862 863 864 865
static inline Vec2i operator*(integer s, Vec2i a)
{
	return Vec2i{a.x * s, a.y * s};
}
866

William Bundy's avatar
William Bundy committed
867 868 869 870
static inline Vec2i operator/(Vec2i a, integer s)
{
	return a * (1.0f / s);
}
871

William Bundy's avatar
William Bundy committed
872 873 874 875
static inline Vec2i operator*(Vec2i a, Vec2i b)
{
	return Vec2i{a.x * b.x, a.y * b.y};
}
876

William Bundy's avatar
William Bundy committed
877 878 879 880 881
static inline Vec2i& operator+=(Vec2i& a, Vec2i b)
{
	a = a + b;
	return a;
}
882

William Bundy's avatar
William Bundy committed
883 884 885 886 887
static inline Vec2i& operator-=(Vec2i& a, Vec2i b)
{
	a = a - b;
	return a;
}
888

William Bundy's avatar
William Bundy committed
889 890 891 892 893
static inline Vec2i& operator*=(Vec2i& a, integer b)
{
	a = a * b;
	return a;
}
894

William Bundy's avatar
William Bundy committed
895 896 897 898 899
static inline Vec2i& operator*=(Vec2i& a, Vec2i b)
{
	a = a * b;
	return a;
}
900

William Bundy's avatar
William Bundy committed
901 902 903 904 905
static inline Vec2i& operator/=(Vec2i& a, integer b)
{
	a = a / b;
	return a;
}
906 907 908



William Bundy's avatar
William Bundy committed
909 910 911 912
static inline Vec3i operator-(Vec3i a)
{
	return Vec3i{-a.x, -a.y, -a.z};
}
913

William Bundy's avatar
William Bundy committed
914 915 916 917
static inline Vec3i operator-(Vec3i a, Vec3i b)
{
	return Vec3i{a.x - b.x, a.y - b.y, a.z - b.z};
}
918

William Bundy's avatar
William Bundy committed
919 920 921 922
static inline Vec3i operator+(Vec3i a, Vec3i b)
{
	return Vec3i{a.x + b.x, a.y + b.y, a.z + b.z};
}
923

William Bundy's avatar
William Bundy committed
924 925 926 927
static inline Vec3i operator*(Vec3i a, integer s)
{
	return Vec3i{a.x * s, a.y * s, a.z * s};
}
928

William Bundy's avatar
William Bundy committed
929 930 931 932
static inline Vec3i operator*(integer s, Vec3i a)
{
	return Vec3i{a.x * s, a.y * s, a.z * s};
}
933

William Bundy's avatar
William Bundy committed
934 935 936 937
static inline Vec3i operator/(Vec3i a, integer s)
{
	return a * (1.0f / s);
}
938

William Bundy's avatar
William Bundy committed
939 940 941 942
static inline Vec3i operator*(Vec3i a, Vec3i b)
{
	return Vec3i{a.x * b.x, a.y * b.y, a.z * b.z};
}
943

William Bundy's avatar
William Bundy committed
944 945 946 947 948
static inline Vec3i& operator+=(Vec3i& a, Vec3i b)
{
	a = a + b;
	return a;
}
949

William Bundy's avatar
William Bundy committed
950 951 952 953 954
static inline Vec3i& operator-=(Vec3i& a, Vec3i b)
{
	a = a - b;
	return a;
}
955

William Bundy's avatar
William Bundy committed
956 957 958 959 960
static inline Vec3i& operator*=(Vec3i& a, integer b)
{
	a = a * b;
	return a;
}
961

William Bundy's avatar
William Bundy committed
962 963 964 965 966
static inline Vec3i& operator*=(Vec3i& a, Vec3i b)
{
	a = a * b;
	return a;
}
967

William Bundy's avatar
William Bundy committed
968 969 970 971 972
static inline Vec3i& operator/=(Vec3i& a, integer b)
{
	a = a / b;
	return a;
}
973 974 975



William Bundy's avatar
William Bundy committed
976 977 978 979
static inline Vec4i operator-(Vec4i a)
{
    return Vec4i{-a.x, -a.y, -a.z, -a.w};
}
980

William Bundy's avatar
William Bundy committed
981 982 983 984
static inline Vec4i operator+(Vec4i a, Vec4i b)
{
	return Vec4i{a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w};
}
985

William Bundy's avatar
William Bundy committed
986 987 988 989
static inline Vec4i operator-(Vec4i a, Vec4i b)
{
	return Vec4i{a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w};
}
990

William Bundy's avatar
William Bundy committed
991 992 993 994
static inline Vec4i operator*(Vec4i a, Vec4i b)
{
	return Vec4i{a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w};
}
995

William Bundy's avatar
William Bundy committed
996 997 998 999
static inline Vec4i operator*(Vec4i a, integer b)
{
	return Vec4i{a.x * b, a.y * b, a.z * b, a.w * b};
}
1000

William Bundy's avatar
William Bundy committed
1001 1002 1003 1004
static inline Vec4i operator*(integer b, Vec4i a) 
{
	return a * b;
}
1005

William Bundy's avatar
William Bundy committed
1006 1007 1008 1009
static inline Vec4i operator/(Vec4i a, integer b)
{
	return a * (1.0f/b);
}
1010

William Bundy's avatar
William Bundy committed
1011 1012 1013 1014 1015
static inline Vec4i operator+=(Vec4i& a, Vec4i b)
{
    a = a + b;
    return a;
}
1016

William Bundy's avatar
William Bundy committed
1017 1018 1019 1020 1021
static inline Vec4i operator-=(Vec4i& a, Vec4i b)
{
    a = a - b;
    return a;
}
1022

William Bundy's avatar
William Bundy committed
1023 1024 1025 1026 1027
static inline Vec4i operator*=(Vec4i& a, integer b)
{
	a = a * b;
	return a;
}
1028

William Bundy's avatar
William Bundy committed
1029 1030 1031 1032 1033
static inline Vec4i operator/=(Vec4i& a, integer b)
{
	a = a / b;
	return a;
}
1034

William Bundy's avatar
William Bundy committed
1035 1036 1037 1038 1039
static inline Vec4i operator*=(Vec4i& a, Vec4i b)
{
    a = a * b;
    return a;
}
1040

William Bundy's avatar
William Bundy committed
1041
#line 886 "c:\\users\\william\\stuff\\development\\rituals\\src\\rituals_math.cpp"
1042 1043 1044



William Bundy's avatar
William Bundy committed
1045 1046 1047 1048 1049 1050
static inline Vec2 v2_perpendicular(Vec2 v)
{
	return Vec2 {
		-v.y, v.x
	};
}
1051

William Bundy's avatar
William Bundy committed
1052 1053 1054 1055
static inline real v2_dot(Vec2 a, Vec2 b)
{
	return a.x * b.x + a.y * b.y;
}
1056

William Bundy's avatar
William Bundy committed
1057 1058 1059 1060
static inline real v2_len_sq(Vec2 a)
{
	return a.x * a.x + a.y * a.y;
}
1061

William Bundy's avatar
William Bundy committed
1062 1063 1064 1065
static inline real v2_len(Vec2 a)
{
    return sqrtf(v2_len_sq(a));
}
1066

William Bundy's avatar
William Bundy committed
1067 1068 1069 1070
static inline real v2_cross(Vec2 a, Vec2 b)
{
	return a.x * b.y - a.y * b.x;
}
1071

William Bundy's avatar
William Bundy committed
1072 1073 1074 1075 1076 1077
static inline Vec2 v2_from_angle(real normal)
{
	return Vec2 {
		cosf(normal), sinf(normal)
	};
}
1078

William Bundy's avatar
William Bundy committed
1079 1080 1081 1082
static inline real v2_to_angle(Vec2 v)
{
	return atan2f(v.y, v.x);
}
1083

William Bundy's avatar
William Bundy committed
1084 1085 1086 1087 1088
static inline Vec2 v2_normalize(Vec2 v)
{
	real mag = sqrt(v.x*v.x + v.y * v.y);
	return v2(v.x / mag, v.y / mag);
}
1089 1090


William Bundy's avatar
William Bundy committed
1091 1092 1093 1094
static inline real v3_dot(Vec3 a, Vec3 b)
{
	return a.x * b.x + a.y * b.y + a.z * b.z;
}
1095

William Bundy's avatar
William Bundy committed
1096 1097 1098 1099
static inline real v3_len_sq(Vec3 a)
{
	return a.x * a.x + a.y * a.y + a.z * a.z;
}
1100

William Bundy's avatar
William Bundy committed
1101 1102 1103 1104
static inline real v3_len(Vec3 a)
{
	return sqrtf(v3_len_sq(a));
}
1105 1106


William Bundy's avatar
William Bundy committed
1107 1108 1109 1110 1111 1112
static inline Vec3 v3_cross(Vec3 a, Vec3 b)
{
    Vec3 v;
    v.x = (a.y * b.z - b.y * a.z);
    v.y = (a.x * b.z - b.x * a.z);
	v.z = (a.x * b.y - a.y * b.x);
1113

William Bundy's avatar
William Bundy committed
1114