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 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 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 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 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 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 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 committed
190 191 192



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

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

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

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

William Bundy committed
226
union Vec3i
227
{
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 committed
252
static inline Vec3 v3(real x, real y, real z)
253
{
William Bundy committed
254 255 256
	return Vec3{
		x, y, z
	};
257 258
}

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

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

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

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

William Bundy committed
287 288 289


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

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

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

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

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 committed
314
static inline Vec4 v4(Vec4i vi)
315
{
William Bundy committed
316 317
    return v4(vi.x, vi.y, vi.z, vi.w);
}
318

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

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

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

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

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

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

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





359

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










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

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

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

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

William Bundy committed
390 391

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

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

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



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 committed
413
static inline Vec3 v3_sub(Vec3 a, Vec3 b)
414
{
William Bundy committed
415
	return Vec3{a.x - b.x, a.y - b.y, a.z - b.z};
416 417
}

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

static inline Vec3 v3_add_scaled(Vec3 a, Vec3 b, real scale)
424
{
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 committed
428
static inline Vec3 v3_mul(Vec3 a, real s)
429
{
William Bundy committed
430
	return Vec3{a.x * s, a.y * s, a.z * s};
431
}
William Bundy committed
432 433

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

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


William Bundy committed
444 445

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

William Bundy committed
450
static inline Vec4 v4_add(Vec4 a, Vec4 b)
451
{
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 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 committed
460
static inline Vec4 v4_sub(Vec4 a, Vec4 b)
461
{
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 committed
464 465

static inline Vec4 v4_compenent_mul(Vec4 a, Vec4 b)
466
{
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 committed
470
static inline Vec4 v4_mul(Vec4 a, real b)
471
{
William Bundy committed
472
	return Vec4{a.x * b, a.y * b, a.z * b, a.w * b};
473 474
}

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



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

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

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

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

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

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

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 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 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 committed
534
static inline Vec3i v3i_negate(Vec3i a)
535
{
William Bundy committed
536 537
	return Vec3i{-a.x, -a.y, -a.z};
}
538

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

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

William Bundy committed
549
static inline Vec3i v3i_add_scaled(Vec3i a, Vec3i b, real scale)
550
{
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 committed
554
static inline Vec3i v3i_addi_scaled(Vec3i a, Vec3i b, integer scale)
555
{
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 committed
559
static inline Vec3i v3i_mul(Vec3i a, real s)
560
{
William Bundy committed
561
	return Vec3i{(integer)(a.x * s), (integer)(a.y * s), (integer)(a.z * s)};
562 563
}

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

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

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


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


William Bundy committed
586 587

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

William Bundy committed
592
static inline Vec4i v4i_add(Vec4i a, Vec4i b)
593
{
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 committed
597
static inline Vec4i v4i_add_scaled(Vec4i a, Vec4i b, real scale)
598
{
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 committed
602
static inline Vec4i v4i_addi_scaled(Vec4i a, Vec4i b, integer scale)
603
{
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 committed
607
static inline Vec4i v4i_sub(Vec4i a, Vec4i b)
608
{
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 committed
612
static inline Vec4i v4i_compenent_mul(Vec4i a, Vec4i b)
613
{
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 committed
617
static inline Vec4i v4i_mul(Vec4i a, real b)
618
{
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 committed
621
static inline Vec4i v4i_muli(Vec4i a, integer b)
622
{
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 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 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 committed
641 642 643 644
static inline Vec2 operator-(Vec2 a)
{
	return Vec2{-a.x, -a.y};
}
645

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 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 committed
656 657 658 659
static inline Vec2 operator*(Vec2 a, real s)
{
	return Vec2{a.x * s, a.y * s};
}
660

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 committed
666 667 668 669
static inline Vec2 operator/(Vec2 a, real s)
{
	return a * (1.0f / s);
}
670

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 committed
676 677 678 679 680
static inline Vec2& operator+=(Vec2& a, Vec2 b)
{
	a = a + b;
	return a;
}
681

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

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

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

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 committed
708 709 710 711
static inline Vec3 operator-(Vec3 a)
{
	return Vec3{-a.x, -a.y, -a.z};
}
712

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 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 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 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 committed
733 734 735 736
static inline Vec3 operator/(Vec3 a, real s)
{
	return a * (1.0f / s);
}
737

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 committed
743 744 745 746 747
static inline Vec3& operator+=(Vec3& a, Vec3 b)
{
	a = a + b;
	return a;
}
748

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

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

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

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 committed
776 777 778 779
static inline Vec4 operator-(Vec4 a)
{
    return Vec4{-a.x, -a.y, -a.z, -a.w};
}
780

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 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 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 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 committed
809 810 811 812 813
static inline Vec4 operator+=(Vec4& a, Vec4 b)
{
    a = a + b;
    return a;
}
814

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

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

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 committed
834 835 836 837 838
static inline Vec4 operator*=(Vec4& a, Vec4 b)
{
    a = a * b;
    return a;
}
839 840 841



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

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 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 committed
857 858 859 860
static inline Vec2i operator*(Vec2i a, integer s)
{
	return Vec2i{a.x * s, a.y * s};
}
861

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 committed
867 868 869 870
static inline Vec2i operator/(Vec2i a, integer s)
{
	return a * (1.0f / s);
}
871

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 committed
877 878 879 880 881
static inline Vec2i& operator+=(Vec2i& a, Vec2i b)
{
	a = a + b;
	return a;
}
882

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

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

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

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 committed
909 910 911 912
static inline Vec3i operator-(Vec3i a)
{
	return Vec3i{-a.x, -a.y, -a.z};
}
913

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 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 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 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 committed
934 935 936 937
static inline Vec3i operator/(Vec3i a, integer s)
{
	return a * (1.0f / s);
}
938

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 committed
944 945 946 947 948
static inline Vec3i& operator+=(Vec3i& a, Vec3i b)
{
	a = a + b;
	return a;
}
949

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

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

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

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 committed
976 977 978 979
static inline Vec4i operator-(Vec4i a)
{
    return Vec4i{-a.x, -a.y, -a.z, -a.w};
}
980

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 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 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 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 committed
1001 1002 1003 1004
static inline Vec4i operator*(integer b, Vec4i a) 
{
	return a * b;
}
1005

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

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

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

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

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

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

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



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 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 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 committed
1062 1063 1064 1065
static inline real v2_len(Vec2 a)
{
    return sqrtf(v2_len_sq(a));
}
1066

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 committed
1072 1073 1074 1075 1076 1077
static inline Vec2 v2_from_angle(real normal)
{
	return Vec2 {
		cosf(normal), sinf(normal)
	};
}
1078

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

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 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 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 committed
1101 1102 1103 1104
static inline real v3_len(Vec3 a)
{
	return sqrtf(v3_len_sq(a));
}
1105 1106


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 committed
1114 1115
    return v;
}
1116

William Bundy committed
1117 1118 1119 1120 1121
static inline Vec3 v3_normalize(Vec3 v)
{
	real mag = v3_len(v);
	return v3(v.x / mag, v.y / mag, v.z / mag);
}
1122

William Bundy committed
1123 1124 1125 1126
static inline real v4_dot(Vec4 a, Vec4 b)
{
	return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
}
1127

William Bundy committed
1128 1129 1130 1131
static inline real v4_len_sq(Vec4 a)
{
	return a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w;
}
1132

William Bundy committed
1133 1134 1135 1136
static inline real v4_len(Vec4 a)
{
	return sqrtf(v4_len_sq(a));
}
1137

William Bundy committed
1138 1139 1140 1141 1142
static inline Vec4 v4_normalize(Vec4 v)
{
	real mag = v4_len(v);
	return v4(v.x / mag, v.y / mag, v.z / mag, v.w / mag);
}
1143

William Bundy committed
1144 1145
static inline Vec4 hex_to_v4(uint32 rgba)
{
1146

William Bundy committed
1147 1148 1149 1150
	uint8 r = (uint8)((rgba >> (24)) & 0xFF);
	uint8 g = (uint8)((rgba >> (16)) & 0xFF);
	uint8 b = (uint8)((rgba >> (8)) & 0xFF);
	uint8 a = (uint8)((rgba >> (0)) & 0xFF);
1151

William Bundy committed
1152
	Vec4 color;
1153

William Bundy committed
1154 1155 1156 1157
	color.x = ((real)(r)/255.0f);
	color.y = ((real)(g)/255.0f);
	color.z = ((real)(b)/255.0f);
	color.w = ((real)(a)/255.0f);
1158

William Bundy committed
1159 1160
	return color;
}
1161 1162 1163 1164 1165





William Bundy committed
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
union Rect2
{
	struct {
		real x, y, w, h;
	};
	struct {
		Vec2 position, size;
	};
	real e[4];
};
1176

William Bundy committed
1177 1178 1179 1180 1181 1182 1183
struct Rect2_Clip_Info
{
	Vec2 rp1;
	Vec2 rp2;
	Vec2 diff1;
	Vec2 diff2;
};
1184

William Bundy committed
1185 1186 1187 1188
struct Rect2i
{
	integer x, y, w, h;
};
1189

William Bundy committed
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
union AABB
{
	struct {
		Vec2 center;
		union {
			struct {
				real hw, hh;
			};
			struct {
				Vec2 hext;
			};
		};
	};
	real e[4];
};
#line 1050 "c:\\users\\william\\stuff\\development\\rituals\\src\\rituals_math.cpp"
1206 1207 1208 1209 1210 1211 1212







William Bundy committed
1213
static inline bool operator==(Rect2 a, Rect2 b)
1214
{
William Bundy committed
1215
	return (a.x == b.x) && (a.y == b.y) && (a.w == b.w) && (a.h == b.h);
1216 1217
}

William Bundy committed
1218
static inline AABB aabb(Vec2 c, real hw, real hh)
1219
{
William Bundy committed
1220 1221 1222
	return AABB{
		c, hw, hh
	};
1223 1224
}

William Bundy committed
1225
static inline AABB aabb(real x, real y, real hw, real hh)
1226
{
William Bundy committed
1227 1228 1229
	return AABB{
		v2(x, y), hw, hh
	};
1230 1231
}

William Bundy committed
1232
static inline Rect2 rect2(real x, real y, real w, real h)
1233
{
William Bundy committed
1234 1235 1236
	return Rect2{
		x, y, w, h
	};
1237 1238
}

William Bundy committed
1239
static inline Rect2 rect2(Vec2 topleft, Vec2 size)
1240
{
William Bundy committed
1241 1242 1243
	return Rect2{
		topleft.x, topleft.y, size.x, size.y
	};
1244 1245
}

William Bundy committed
1246
static inline Rect2i rect2i(integer x, integer y, integer w, integer h)
1247
{
William Bundy committed
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424