Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
raymath.h
Go to the documentation of this file.
1
47#ifndef RAYMATH_H
48#define RAYMATH_H
49
50#if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_STATIC_INLINE)
51 #error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_STATIC_INLINE is contradictory"
52#endif
53
54// Function specifiers definition
55#if defined(RAYMATH_IMPLEMENTATION)
56 #if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
57 #define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll).
58 #elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
59 #define RMAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
60 #else
61 #define RMAPI extern inline // Provide external definition
62 #endif
63#elif defined(RAYMATH_STATIC_INLINE)
64 #define RMAPI static inline // Functions may be inlined, no external out-of-line definition
65#else
66 #if defined(__TINYC__)
67 #define RMAPI static inline // plain inline not supported by tinycc (See issue #435)
68 #else
69 #define RMAPI inline // Functions may be inlined or external definition used
70 #endif
71#endif
72
73//----------------------------------------------------------------------------------
74// Defines and Macros
75//----------------------------------------------------------------------------------
76#ifndef PI
77 #define PI 3.14159265358979323846f
78#endif
79
80#ifndef EPSILON
81 #define EPSILON 0.000001f
82#endif
83
84#ifndef DEG2RAD
85 #define DEG2RAD (PI/180.0f)
86#endif
87
88#ifndef RAD2DEG
89 #define RAD2DEG (180.0f/PI)
90#endif
91
92// Get float vector for Matrix
93#ifndef MatrixToFloat
94 #define MatrixToFloat(mat) (MatrixToFloatV(mat).v)
95#endif
96
97// Get float vector for Vector3
98#ifndef Vector3ToFloat
99 #define Vector3ToFloat(vec) (Vector3ToFloatV(vec).v)
100#endif
101
102//----------------------------------------------------------------------------------
103// Types and Structures Definition
104//----------------------------------------------------------------------------------
105#if !defined(RL_VECTOR2_TYPE)
106// Vector2 type
107typedef struct Vector2 {
108 float x;
109 float y;
111#define RL_VECTOR2_TYPE
112#endif
113
114#if !defined(RL_VECTOR3_TYPE)
115// Vector3 type
116typedef struct Vector3 {
117 float x;
118 float y;
119 float z;
121#define RL_VECTOR3_TYPE
122#endif
123
124#if !defined(RL_VECTOR4_TYPE)
125// Vector4 type
126typedef struct Vector4 {
127 float x;
128 float y;
129 float z;
130 float w;
132#define RL_VECTOR4_TYPE
133#endif
134
135#if !defined(RL_QUATERNION_TYPE)
136// Quaternion type
138#define RL_QUATERNION_TYPE
139#endif
140
141#if !defined(RL_MATRIX_TYPE)
142// Matrix type (OpenGL style 4x4 - right handed, column major)
143typedef struct Matrix {
144 float m0, m4, m8, m12; // Matrix first row (4 components)
145 float m1, m5, m9, m13; // Matrix second row (4 components)
146 float m2, m6, m10, m14; // Matrix third row (4 components)
147 float m3, m7, m11, m15; // Matrix fourth row (4 components)
149#define RL_MATRIX_TYPE
150#endif
151
152// NOTE: Helper types to be used instead of array return types for *ToFloat functions
153typedef struct float3 {
154 float v[3];
156
157typedef struct float16 {
158 float v[16];
160
161#include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), fminf(), fmaxf(), fabs()
162
163//----------------------------------------------------------------------------------
164// Module Functions Definition - Utils math
165//----------------------------------------------------------------------------------
166
167// Clamp float value
168RMAPI float Clamp(float value, float min, float max)
169{
170 float result = (value < min)? min : value;
171
172 if (result > max) result = max;
173
174 return result;
175}
176
177// Calculate linear interpolation between two floats
178RMAPI float Lerp(float start, float end, float amount)
179{
180 float result = start + amount*(end - start);
181
182 return result;
183}
184
185// Normalize input value within input range
186RMAPI float Normalize(float value, float start, float end)
187{
188 float result = (value - start)/(end - start);
189
190 return result;
191}
192
193// Remap input value within input range to output range
194RMAPI float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd)
195{
196 float result = (value - inputStart)/(inputEnd - inputStart)*(outputEnd - outputStart) + outputStart;
197
198 return result;
199}
200
201// Check whether two given floats are almost equal
202RMAPI int FloatEquals(float x, float y)
203{
204 int result = (fabsf(x - y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(x), fabsf(y))));
205
206 return result;
207}
208
209//----------------------------------------------------------------------------------
210// Module Functions Definition - Vector2 math
211//----------------------------------------------------------------------------------
212
213// Vector with components value 0.0f
215{
216 Vector2 result = { 0.0f, 0.0f };
217
218 return result;
219}
220
221// Vector with components value 1.0f
223{
224 Vector2 result = { 1.0f, 1.0f };
225
226 return result;
227}
228
229// Add two vectors (v1 + v2)
231{
232 Vector2 result = { v1.x + v2.x, v1.y + v2.y };
233
234 return result;
235}
236
237// Add vector and float value
239{
240 Vector2 result = { v.x + add, v.y + add };
241
242 return result;
243}
244
245// Subtract two vectors (v1 - v2)
247{
248 Vector2 result = { v1.x - v2.x, v1.y - v2.y };
249
250 return result;
251}
252
253// Subtract vector by float value
255{
256 Vector2 result = { v.x - sub, v.y - sub };
257
258 return result;
259}
260
261// Calculate vector length
263{
264 float result = sqrtf((v.x*v.x) + (v.y*v.y));
265
266 return result;
267}
268
269// Calculate vector square length
271{
272 float result = (v.x*v.x) + (v.y*v.y);
273
274 return result;
275}
276
277// Calculate two vectors dot product
279{
280 float result = (v1.x*v2.x + v1.y*v2.y);
281
282 return result;
283}
284
285// Calculate distance between two vectors
287{
288 float result = sqrtf((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
289
290 return result;
291}
292
293// Calculate square distance between two vectors
295{
296 float result = ((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
297
298 return result;
299}
300
301// Calculate angle from two vectors
303{
304 float result = atan2f(v2.y, v2.x) - atan2f(v1.y, v1.x);
305
306 return result;
307}
308
309// Scale vector (multiply by value)
311{
312 Vector2 result = { v.x*scale, v.y*scale };
313
314 return result;
315}
316
317// Multiply vector by vector
319{
320 Vector2 result = { v1.x*v2.x, v1.y*v2.y };
321
322 return result;
323}
324
325// Negate vector
327{
328 Vector2 result = { -v.x, -v.y };
329
330 return result;
331}
332
333// Divide vector by vector
335{
336 Vector2 result = { v1.x/v2.x, v1.y/v2.y };
337
338 return result;
339}
340
341// Normalize provided vector
343{
344 Vector2 result = { 0 };
345 float length = sqrtf((v.x*v.x) + (v.y*v.y));
346
347 if (length > 0)
348 {
349 float ilength = 1.0f/length;
350 result.x = v.x*ilength;
351 result.y = v.y*ilength;
352 }
353
354 return result;
355}
356
357// Transforms a Vector2 by a given Matrix
359{
360 Vector2 result = { 0 };
361
362 float x = v.x;
363 float y = v.y;
364 float z = 0;
365
366 result.x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12;
367 result.y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13;
368
369 return result;
370}
371
372// Calculate linear interpolation between two vectors
374{
375 Vector2 result = { 0 };
376
377 result.x = v1.x + amount*(v2.x - v1.x);
378 result.y = v1.y + amount*(v2.y - v1.y);
379
380 return result;
381}
382
383// Calculate reflected vector to normal
385{
386 Vector2 result = { 0 };
387
388 float dotProduct = (v.x*normal.x + v.y*normal.y); // Dot product
389
390 result.x = v.x - (2.0f*normal.x)*dotProduct;
391 result.y = v.y - (2.0f*normal.y)*dotProduct;
392
393 return result;
394}
395
396// Rotate vector by angle
398{
399 Vector2 result = { 0 };
400
401 float cosres = cosf(angle);
402 float sinres = sinf(angle);
403
404 result.x = v.x*cosres - v.y*sinres;
405 result.y = v.x*sinres + v.y*cosres;
406
407 return result;
408}
409
410// Move Vector towards target
411RMAPI Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance)
412{
413 Vector2 result = { 0 };
414
415 float dx = target.x - v.x;
416 float dy = target.y - v.y;
417 float value = (dx*dx) + (dy*dy);
418
419 if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) return target;
420
421 float dist = sqrtf(value);
422
423 result.x = v.x + dx/dist*maxDistance;
424 result.y = v.y + dy/dist*maxDistance;
425
426 return result;
427}
428
429// Invert the given vector
431{
432 Vector2 result = { 1.0f/v.x, 1.0f/v.y };
433
434 return result;
435}
436
437// Clamp the components of the vector between
438// min and max values specified by the given vectors
440{
441 Vector2 result = { 0 };
442
443 result.x = fminf(max.x, fmaxf(min.x, v.x));
444 result.y = fminf(max.y, fmaxf(min.y, v.y));
445
446 return result;
447}
448
449// Clamp the magnitude of the vector between two min and max values
450RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
451{
452 Vector2 result = { 0 };
453
454 float length = (v.x*v.x) + (v.y*v.y);
455 if (length > 0.0f)
456 {
457 length = sqrtf(length);
458
459 if (length < min)
460 {
461 float scale = min/length;
462 result.x = v.x*scale;
463 result.y = v.y*scale;
464 }
465 else if (length > max)
466 {
467 float scale = max/length;
468 result.x = v.x*scale;
469 result.y = v.y*scale;
470 }
471 }
472
473 return result;
474}
475
476// Check whether two given vectors are almost equal
478{
479 int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
480 ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y)))));
481
482 return result;
483}
484
485//----------------------------------------------------------------------------------
486// Module Functions Definition - Vector3 math
487//----------------------------------------------------------------------------------
488
489// Vector with components value 0.0f
491{
492 Vector3 result = { 0.0f, 0.0f, 0.0f };
493
494 return result;
495}
496
497// Vector with components value 1.0f
499{
500 Vector3 result = { 1.0f, 1.0f, 1.0f };
501
502 return result;
503}
504
505// Add two vectors
507{
508 Vector3 result = { v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
509
510 return result;
511}
512
513// Add vector and float value
515{
516 Vector3 result = { v.x + add, v.y + add, v.z + add };
517
518 return result;
519}
520
521// Subtract two vectors
523{
524 Vector3 result = { v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
525
526 return result;
527}
528
529// Subtract vector by float value
531{
532 Vector3 result = { v.x - sub, v.y - sub, v.z - sub };
533
534 return result;
535}
536
537// Multiply vector by scalar
539{
540 Vector3 result = { v.x*scalar, v.y*scalar, v.z*scalar };
541
542 return result;
543}
544
545// Multiply vector by vector
547{
548 Vector3 result = { v1.x*v2.x, v1.y*v2.y, v1.z*v2.z };
549
550 return result;
551}
552
553// Calculate two vectors cross product
555{
556 Vector3 result = { v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x };
557
558 return result;
559}
560
561// Calculate one vector perpendicular vector
563{
564 Vector3 result = { 0 };
565
566 float min = (float) fabs(v.x);
567 Vector3 cardinalAxis = {1.0f, 0.0f, 0.0f};
568
569 if (fabsf(v.y) < min)
570 {
571 min = (float) fabs(v.y);
572 Vector3 tmp = {0.0f, 1.0f, 0.0f};
573 cardinalAxis = tmp;
574 }
575
576 if (fabsf(v.z) < min)
577 {
578 Vector3 tmp = {0.0f, 0.0f, 1.0f};
579 cardinalAxis = tmp;
580 }
581
582 // Cross product between vectors
583 result.x = v.y*cardinalAxis.z - v.z*cardinalAxis.y;
584 result.y = v.z*cardinalAxis.x - v.x*cardinalAxis.z;
585 result.z = v.x*cardinalAxis.y - v.y*cardinalAxis.x;
586
587 return result;
588}
589
590// Calculate vector length
592{
593 float result = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
594
595 return result;
596}
597
598// Calculate vector square length
600{
601 float result = v.x*v.x + v.y*v.y + v.z*v.z;
602
603 return result;
604}
605
606// Calculate two vectors dot product
608{
609 float result = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
610
611 return result;
612}
613
614// Calculate distance between two vectors
616{
617 float result = 0.0f;
618
619 float dx = v2.x - v1.x;
620 float dy = v2.y - v1.y;
621 float dz = v2.z - v1.z;
622 result = sqrtf(dx*dx + dy*dy + dz*dz);
623
624 return result;
625}
626
627// Calculate square distance between two vectors
629{
630 float result = 0.0f;
631
632 float dx = v2.x - v1.x;
633 float dy = v2.y - v1.y;
634 float dz = v2.z - v1.z;
635 result = dx*dx + dy*dy + dz*dz;
636
637 return result;
638}
639
640// Calculate angle between two vectors
642{
643 float result = 0.0f;
644
645 Vector3 cross = { v1.y*v2.z - v1.z*v2.y, v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x };
646 float len = sqrtf(cross.x*cross.x + cross.y*cross.y + cross.z*cross.z);
647 float dot = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
648 result = atan2f(len, dot);
649
650 return result;
651}
652
653// Negate provided vector (invert direction)
655{
656 Vector3 result = { -v.x, -v.y, -v.z };
657
658 return result;
659}
660
661// Divide vector by vector
663{
664 Vector3 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z };
665
666 return result;
667}
668
669// Normalize provided vector
671{
672 Vector3 result = v;
673
674 float length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
675 if (length == 0.0f) length = 1.0f;
676 float ilength = 1.0f/length;
677
678 result.x *= ilength;
679 result.y *= ilength;
680 result.z *= ilength;
681
682 return result;
683}
684
685// Orthonormalize provided vectors
686// Makes vectors normalized and orthogonal to each other
687// Gram-Schmidt function implementation
689{
690 float length = 0.0f;
691 float ilength = 0.0f;
692
693 // Vector3Normalize(*v1);
694 Vector3 v = *v1;
695 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
696 if (length == 0.0f) length = 1.0f;
697 ilength = 1.0f/length;
698 v1->x *= ilength;
699 v1->y *= ilength;
700 v1->z *= ilength;
701
702 // Vector3CrossProduct(*v1, *v2)
703 Vector3 vn1 = { v1->y*v2->z - v1->z*v2->y, v1->z*v2->x - v1->x*v2->z, v1->x*v2->y - v1->y*v2->x };
704
705 // Vector3Normalize(vn1);
706 v = vn1;
707 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
708 if (length == 0.0f) length = 1.0f;
709 ilength = 1.0f/length;
710 vn1.x *= ilength;
711 vn1.y *= ilength;
712 vn1.z *= ilength;
713
714 // Vector3CrossProduct(vn1, *v1)
715 Vector3 vn2 = { vn1.y*v1->z - vn1.z*v1->y, vn1.z*v1->x - vn1.x*v1->z, vn1.x*v1->y - vn1.y*v1->x };
716
717 *v2 = vn2;
718}
719
720// Transforms a Vector3 by a given Matrix
722{
723 Vector3 result = { 0 };
724
725 float x = v.x;
726 float y = v.y;
727 float z = v.z;
728
729 result.x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12;
730 result.y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13;
731 result.z = mat.m2*x + mat.m6*y + mat.m10*z + mat.m14;
732
733 return result;
734}
735
736// Transform a vector by quaternion rotation
738{
739 Vector3 result = { 0 };
740
741 result.x = v.x*(q.x*q.x + q.w*q.w - q.y*q.y - q.z*q.z) + v.y*(2*q.x*q.y - 2*q.w*q.z) + v.z*(2*q.x*q.z + 2*q.w*q.y);
742 result.y = v.x*(2*q.w*q.z + 2*q.x*q.y) + v.y*(q.w*q.w - q.x*q.x + q.y*q.y - q.z*q.z) + v.z*(-2*q.w*q.x + 2*q.y*q.z);
743 result.z = v.x*(-2*q.w*q.y + 2*q.x*q.z) + v.y*(2*q.w*q.x + 2*q.y*q.z)+ v.z*(q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z);
744
745 return result;
746}
747
748// Calculate linear interpolation between two vectors
750{
751 Vector3 result = { 0 };
752
753 result.x = v1.x + amount*(v2.x - v1.x);
754 result.y = v1.y + amount*(v2.y - v1.y);
755 result.z = v1.z + amount*(v2.z - v1.z);
756
757 return result;
758}
759
760// Calculate reflected vector to normal
762{
763 Vector3 result = { 0 };
764
765 // I is the original vector
766 // N is the normal of the incident plane
767 // R = I - (2*N*(DotProduct[I, N]))
768
769 float dotProduct = (v.x*normal.x + v.y*normal.y + v.z*normal.z);
770
771 result.x = v.x - (2.0f*normal.x)*dotProduct;
772 result.y = v.y - (2.0f*normal.y)*dotProduct;
773 result.z = v.z - (2.0f*normal.z)*dotProduct;
774
775 return result;
776}
777
778// Get min value for each pair of components
780{
781 Vector3 result = { 0 };
782
783 result.x = fminf(v1.x, v2.x);
784 result.y = fminf(v1.y, v2.y);
785 result.z = fminf(v1.z, v2.z);
786
787 return result;
788}
789
790// Get max value for each pair of components
792{
793 Vector3 result = { 0 };
794
795 result.x = fmaxf(v1.x, v2.x);
796 result.y = fmaxf(v1.y, v2.y);
797 result.z = fmaxf(v1.z, v2.z);
798
799 return result;
800}
801
802// Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
803// NOTE: Assumes P is on the plane of the triangle
805{
806 Vector3 result = { 0 };
807
808 Vector3 v0 = { b.x - a.x, b.y - a.y, b.z - a.z }; // Vector3Subtract(b, a)
809 Vector3 v1 = { c.x - a.x, c.y - a.y, c.z - a.z }; // Vector3Subtract(c, a)
810 Vector3 v2 = { p.x - a.x, p.y - a.y, p.z - a.z }; // Vector3Subtract(p, a)
811 float d00 = (v0.x*v0.x + v0.y*v0.y + v0.z*v0.z); // Vector3DotProduct(v0, v0)
812 float d01 = (v0.x*v1.x + v0.y*v1.y + v0.z*v1.z); // Vector3DotProduct(v0, v1)
813 float d11 = (v1.x*v1.x + v1.y*v1.y + v1.z*v1.z); // Vector3DotProduct(v1, v1)
814 float d20 = (v2.x*v0.x + v2.y*v0.y + v2.z*v0.z); // Vector3DotProduct(v2, v0)
815 float d21 = (v2.x*v1.x + v2.y*v1.y + v2.z*v1.z); // Vector3DotProduct(v2, v1)
816
817 float denom = d00*d11 - d01*d01;
818
819 result.y = (d11*d20 - d01*d21)/denom;
820 result.z = (d00*d21 - d01*d20)/denom;
821 result.x = 1.0f - (result.z + result.y);
822
823 return result;
824}
825
826// Projects a Vector3 from screen space into object space
827// NOTE: We are avoiding calling other raymath functions despite available
829{
830 Vector3 result = { 0 };
831
832 // Calculate unproject matrix (multiply view patrix by projection matrix) and invert it
833 Matrix matViewProj = { // MatrixMultiply(view, projection);
834 view.m0*projection.m0 + view.m1*projection.m4 + view.m2*projection.m8 + view.m3*projection.m12,
835 view.m0*projection.m1 + view.m1*projection.m5 + view.m2*projection.m9 + view.m3*projection.m13,
836 view.m0*projection.m2 + view.m1*projection.m6 + view.m2*projection.m10 + view.m3*projection.m14,
837 view.m0*projection.m3 + view.m1*projection.m7 + view.m2*projection.m11 + view.m3*projection.m15,
838 view.m4*projection.m0 + view.m5*projection.m4 + view.m6*projection.m8 + view.m7*projection.m12,
839 view.m4*projection.m1 + view.m5*projection.m5 + view.m6*projection.m9 + view.m7*projection.m13,
840 view.m4*projection.m2 + view.m5*projection.m6 + view.m6*projection.m10 + view.m7*projection.m14,
841 view.m4*projection.m3 + view.m5*projection.m7 + view.m6*projection.m11 + view.m7*projection.m15,
842 view.m8*projection.m0 + view.m9*projection.m4 + view.m10*projection.m8 + view.m11*projection.m12,
843 view.m8*projection.m1 + view.m9*projection.m5 + view.m10*projection.m9 + view.m11*projection.m13,
844 view.m8*projection.m2 + view.m9*projection.m6 + view.m10*projection.m10 + view.m11*projection.m14,
845 view.m8*projection.m3 + view.m9*projection.m7 + view.m10*projection.m11 + view.m11*projection.m15,
846 view.m12*projection.m0 + view.m13*projection.m4 + view.m14*projection.m8 + view.m15*projection.m12,
847 view.m12*projection.m1 + view.m13*projection.m5 + view.m14*projection.m9 + view.m15*projection.m13,
848 view.m12*projection.m2 + view.m13*projection.m6 + view.m14*projection.m10 + view.m15*projection.m14,
849 view.m12*projection.m3 + view.m13*projection.m7 + view.m14*projection.m11 + view.m15*projection.m15 };
850
851 // Calculate inverted matrix -> MatrixInvert(matViewProj);
852 // Cache the matrix values (speed optimization)
853 float a00 = matViewProj.m0, a01 = matViewProj.m1, a02 = matViewProj.m2, a03 = matViewProj.m3;
854 float a10 = matViewProj.m4, a11 = matViewProj.m5, a12 = matViewProj.m6, a13 = matViewProj.m7;
855 float a20 = matViewProj.m8, a21 = matViewProj.m9, a22 = matViewProj.m10, a23 = matViewProj.m11;
856 float a30 = matViewProj.m12, a31 = matViewProj.m13, a32 = matViewProj.m14, a33 = matViewProj.m15;
857
858 float b00 = a00*a11 - a01*a10;
859 float b01 = a00*a12 - a02*a10;
860 float b02 = a00*a13 - a03*a10;
861 float b03 = a01*a12 - a02*a11;
862 float b04 = a01*a13 - a03*a11;
863 float b05 = a02*a13 - a03*a12;
864 float b06 = a20*a31 - a21*a30;
865 float b07 = a20*a32 - a22*a30;
866 float b08 = a20*a33 - a23*a30;
867 float b09 = a21*a32 - a22*a31;
868 float b10 = a21*a33 - a23*a31;
869 float b11 = a22*a33 - a23*a32;
870
871 // Calculate the invert determinant (inlined to avoid double-caching)
872 float invDet = 1.0f/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
873
874 Matrix matViewProjInv = {
875 (a11*b11 - a12*b10 + a13*b09)*invDet,
876 (-a01*b11 + a02*b10 - a03*b09)*invDet,
877 (a31*b05 - a32*b04 + a33*b03)*invDet,
878 (-a21*b05 + a22*b04 - a23*b03)*invDet,
879 (-a10*b11 + a12*b08 - a13*b07)*invDet,
880 (a00*b11 - a02*b08 + a03*b07)*invDet,
881 (-a30*b05 + a32*b02 - a33*b01)*invDet,
882 (a20*b05 - a22*b02 + a23*b01)*invDet,
883 (a10*b10 - a11*b08 + a13*b06)*invDet,
884 (-a00*b10 + a01*b08 - a03*b06)*invDet,
885 (a30*b04 - a31*b02 + a33*b00)*invDet,
886 (-a20*b04 + a21*b02 - a23*b00)*invDet,
887 (-a10*b09 + a11*b07 - a12*b06)*invDet,
888 (a00*b09 - a01*b07 + a02*b06)*invDet,
889 (-a30*b03 + a31*b01 - a32*b00)*invDet,
890 (a20*b03 - a21*b01 + a22*b00)*invDet };
891
892 // Create quaternion from source point
893 Quaternion quat = { source.x, source.y, source.z, 1.0f };
894
895 // Multiply quat point by unproject matrix
896 Quaternion qtransformed = { // QuaternionTransform(quat, matViewProjInv)
897 matViewProjInv.m0*quat.x + matViewProjInv.m4*quat.y + matViewProjInv.m8*quat.z + matViewProjInv.m12*quat.w,
898 matViewProjInv.m1*quat.x + matViewProjInv.m5*quat.y + matViewProjInv.m9*quat.z + matViewProjInv.m13*quat.w,
899 matViewProjInv.m2*quat.x + matViewProjInv.m6*quat.y + matViewProjInv.m10*quat.z + matViewProjInv.m14*quat.w,
900 matViewProjInv.m3*quat.x + matViewProjInv.m7*quat.y + matViewProjInv.m11*quat.z + matViewProjInv.m15*quat.w };
901
902 // Normalized world points in vectors
903 result.x = qtransformed.x/qtransformed.w;
904 result.y = qtransformed.y/qtransformed.w;
905 result.z = qtransformed.z/qtransformed.w;
906
907 return result;
908}
909
910// Get Vector3 as float array
912{
913 float3 buffer = { 0 };
914
915 buffer.v[0] = v.x;
916 buffer.v[1] = v.y;
917 buffer.v[2] = v.z;
918
919 return buffer;
920}
921
922// Invert the given vector
924{
925 Vector3 result = { 1.0f/v.x, 1.0f/v.y, 1.0f/v.z };
926
927 return result;
928}
929
930// Clamp the components of the vector between
931// min and max values specified by the given vectors
933{
934 Vector3 result = { 0 };
935
936 result.x = fminf(max.x, fmaxf(min.x, v.x));
937 result.y = fminf(max.y, fmaxf(min.y, v.y));
938 result.z = fminf(max.z, fmaxf(min.z, v.z));
939
940 return result;
941}
942
943// Clamp the magnitude of the vector between two values
944RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
945{
946 Vector3 result = { 0 };
947
948 float length = (v.x*v.x) + (v.y*v.y) + (v.z*v.z);
949 if (length > 0.0f)
950 {
951 length = sqrtf(length);
952
953 if (length < min)
954 {
955 float scale = min/length;
956 result.x = v.x*scale;
957 result.y = v.y*scale;
958 result.z = v.z*scale;
959 }
960 else if (length > max)
961 {
962 float scale = max/length;
963 result.x = v.x*scale;
964 result.y = v.y*scale;
965 result.z = v.z*scale;
966 }
967 }
968
969 return result;
970}
971
972// Check whether two given vectors are almost equal
974{
975 int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
976 ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
977 ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z)))));
978
979 return result;
980}
981
982// Compute the direction of a refracted ray where v specifies the
983// normalized direction of the incoming ray, n specifies the
984// normalized normal vector of the interface of two optical media,
985// and r specifies the ratio of the refractive index of the medium
986// from where the ray comes to the refractive index of the medium
987// on the other side of the surface
989{
990 Vector3 result = { 0 };
991
992 float dot = v.x*n.x + v.y*n.y + v.z*n.z;
993 float d = 1.0f - r*r*(1.0f - dot*dot);
994
995 if (d >= 0.0f)
996 {
997 d = sqrtf(d);
998 v.x = r*v.x - (r*dot + d)*n.x;
999 v.y = r*v.y - (r*dot + d)*n.y;
1000 v.z = r*v.z - (r*dot + d)*n.z;
1001
1002 result = v;
1003 }
1004
1005 return result;
1006}
1007
1008//----------------------------------------------------------------------------------
1009// Module Functions Definition - Matrix math
1010//----------------------------------------------------------------------------------
1011
1012// Compute matrix determinant
1014{
1015 float result = 0.0f;
1016
1017 // Cache the matrix values (speed optimization)
1018 float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
1019 float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
1020 float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
1021 float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
1022
1023 result = a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
1024 a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
1025 a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
1026 a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
1027 a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
1028 a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
1029
1030 return result;
1031}
1032
1033// Get the trace of the matrix (sum of the values along the diagonal)
1035{
1036 float result = (mat.m0 + mat.m5 + mat.m10 + mat.m15);
1037
1038 return result;
1039}
1040
1041// Transposes provided matrix
1043{
1044 Matrix result = { 0 };
1045
1046 result.m0 = mat.m0;
1047 result.m1 = mat.m4;
1048 result.m2 = mat.m8;
1049 result.m3 = mat.m12;
1050 result.m4 = mat.m1;
1051 result.m5 = mat.m5;
1052 result.m6 = mat.m9;
1053 result.m7 = mat.m13;
1054 result.m8 = mat.m2;
1055 result.m9 = mat.m6;
1056 result.m10 = mat.m10;
1057 result.m11 = mat.m14;
1058 result.m12 = mat.m3;
1059 result.m13 = mat.m7;
1060 result.m14 = mat.m11;
1061 result.m15 = mat.m15;
1062
1063 return result;
1064}
1065
1066// Invert provided matrix
1068{
1069 Matrix result = { 0 };
1070
1071 // Cache the matrix values (speed optimization)
1072 float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
1073 float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
1074 float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
1075 float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
1076
1077 float b00 = a00*a11 - a01*a10;
1078 float b01 = a00*a12 - a02*a10;
1079 float b02 = a00*a13 - a03*a10;
1080 float b03 = a01*a12 - a02*a11;
1081 float b04 = a01*a13 - a03*a11;
1082 float b05 = a02*a13 - a03*a12;
1083 float b06 = a20*a31 - a21*a30;
1084 float b07 = a20*a32 - a22*a30;
1085 float b08 = a20*a33 - a23*a30;
1086 float b09 = a21*a32 - a22*a31;
1087 float b10 = a21*a33 - a23*a31;
1088 float b11 = a22*a33 - a23*a32;
1089
1090 // Calculate the invert determinant (inlined to avoid double-caching)
1091 float invDet = 1.0f/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
1092
1093 result.m0 = (a11*b11 - a12*b10 + a13*b09)*invDet;
1094 result.m1 = (-a01*b11 + a02*b10 - a03*b09)*invDet;
1095 result.m2 = (a31*b05 - a32*b04 + a33*b03)*invDet;
1096 result.m3 = (-a21*b05 + a22*b04 - a23*b03)*invDet;
1097 result.m4 = (-a10*b11 + a12*b08 - a13*b07)*invDet;
1098 result.m5 = (a00*b11 - a02*b08 + a03*b07)*invDet;
1099 result.m6 = (-a30*b05 + a32*b02 - a33*b01)*invDet;
1100 result.m7 = (a20*b05 - a22*b02 + a23*b01)*invDet;
1101 result.m8 = (a10*b10 - a11*b08 + a13*b06)*invDet;
1102 result.m9 = (-a00*b10 + a01*b08 - a03*b06)*invDet;
1103 result.m10 = (a30*b04 - a31*b02 + a33*b00)*invDet;
1104 result.m11 = (-a20*b04 + a21*b02 - a23*b00)*invDet;
1105 result.m12 = (-a10*b09 + a11*b07 - a12*b06)*invDet;
1106 result.m13 = (a00*b09 - a01*b07 + a02*b06)*invDet;
1107 result.m14 = (-a30*b03 + a31*b01 - a32*b00)*invDet;
1108 result.m15 = (a20*b03 - a21*b01 + a22*b00)*invDet;
1109
1110 return result;
1111}
1112
1113// Get identity matrix
1115{
1116 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
1117 0.0f, 1.0f, 0.0f, 0.0f,
1118 0.0f, 0.0f, 1.0f, 0.0f,
1119 0.0f, 0.0f, 0.0f, 1.0f };
1120
1121 return result;
1122}
1123
1124// Add two matrices
1126{
1127 Matrix result = { 0 };
1128
1129 result.m0 = left.m0 + right.m0;
1130 result.m1 = left.m1 + right.m1;
1131 result.m2 = left.m2 + right.m2;
1132 result.m3 = left.m3 + right.m3;
1133 result.m4 = left.m4 + right.m4;
1134 result.m5 = left.m5 + right.m5;
1135 result.m6 = left.m6 + right.m6;
1136 result.m7 = left.m7 + right.m7;
1137 result.m8 = left.m8 + right.m8;
1138 result.m9 = left.m9 + right.m9;
1139 result.m10 = left.m10 + right.m10;
1140 result.m11 = left.m11 + right.m11;
1141 result.m12 = left.m12 + right.m12;
1142 result.m13 = left.m13 + right.m13;
1143 result.m14 = left.m14 + right.m14;
1144 result.m15 = left.m15 + right.m15;
1145
1146 return result;
1147}
1148
1149// Subtract two matrices (left - right)
1151{
1152 Matrix result = { 0 };
1153
1154 result.m0 = left.m0 - right.m0;
1155 result.m1 = left.m1 - right.m1;
1156 result.m2 = left.m2 - right.m2;
1157 result.m3 = left.m3 - right.m3;
1158 result.m4 = left.m4 - right.m4;
1159 result.m5 = left.m5 - right.m5;
1160 result.m6 = left.m6 - right.m6;
1161 result.m7 = left.m7 - right.m7;
1162 result.m8 = left.m8 - right.m8;
1163 result.m9 = left.m9 - right.m9;
1164 result.m10 = left.m10 - right.m10;
1165 result.m11 = left.m11 - right.m11;
1166 result.m12 = left.m12 - right.m12;
1167 result.m13 = left.m13 - right.m13;
1168 result.m14 = left.m14 - right.m14;
1169 result.m15 = left.m15 - right.m15;
1170
1171 return result;
1172}
1173
1174// Get two matrix multiplication
1175// NOTE: When multiplying matrices... the order matters!
1177{
1178 Matrix result = { 0 };
1179
1180 result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
1181 result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
1182 result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
1183 result.m3 = left.m0*right.m3 + left.m1*right.m7 + left.m2*right.m11 + left.m3*right.m15;
1184 result.m4 = left.m4*right.m0 + left.m5*right.m4 + left.m6*right.m8 + left.m7*right.m12;
1185 result.m5 = left.m4*right.m1 + left.m5*right.m5 + left.m6*right.m9 + left.m7*right.m13;
1186 result.m6 = left.m4*right.m2 + left.m5*right.m6 + left.m6*right.m10 + left.m7*right.m14;
1187 result.m7 = left.m4*right.m3 + left.m5*right.m7 + left.m6*right.m11 + left.m7*right.m15;
1188 result.m8 = left.m8*right.m0 + left.m9*right.m4 + left.m10*right.m8 + left.m11*right.m12;
1189 result.m9 = left.m8*right.m1 + left.m9*right.m5 + left.m10*right.m9 + left.m11*right.m13;
1190 result.m10 = left.m8*right.m2 + left.m9*right.m6 + left.m10*right.m10 + left.m11*right.m14;
1191 result.m11 = left.m8*right.m3 + left.m9*right.m7 + left.m10*right.m11 + left.m11*right.m15;
1192 result.m12 = left.m12*right.m0 + left.m13*right.m4 + left.m14*right.m8 + left.m15*right.m12;
1193 result.m13 = left.m12*right.m1 + left.m13*right.m5 + left.m14*right.m9 + left.m15*right.m13;
1194 result.m14 = left.m12*right.m2 + left.m13*right.m6 + left.m14*right.m10 + left.m15*right.m14;
1195 result.m15 = left.m12*right.m3 + left.m13*right.m7 + left.m14*right.m11 + left.m15*right.m15;
1196
1197 return result;
1198}
1199
1200// Get translation matrix
1201RMAPI Matrix MatrixTranslate(float x, float y, float z)
1202{
1203 Matrix result = { 1.0f, 0.0f, 0.0f, x,
1204 0.0f, 1.0f, 0.0f, y,
1205 0.0f, 0.0f, 1.0f, z,
1206 0.0f, 0.0f, 0.0f, 1.0f };
1207
1208 return result;
1209}
1210
1211// Create rotation matrix from axis and angle
1212// NOTE: Angle should be provided in radians
1214{
1215 Matrix result = { 0 };
1216
1217 float x = axis.x, y = axis.y, z = axis.z;
1218
1219 float lengthSquared = x*x + y*y + z*z;
1220
1221 if ((lengthSquared != 1.0f) && (lengthSquared != 0.0f))
1222 {
1223 float ilength = 1.0f/sqrtf(lengthSquared);
1224 x *= ilength;
1225 y *= ilength;
1226 z *= ilength;
1227 }
1228
1229 float sinres = sinf(angle);
1230 float cosres = cosf(angle);
1231 float t = 1.0f - cosres;
1232
1233 result.m0 = x*x*t + cosres;
1234 result.m1 = y*x*t + z*sinres;
1235 result.m2 = z*x*t - y*sinres;
1236 result.m3 = 0.0f;
1237
1238 result.m4 = x*y*t - z*sinres;
1239 result.m5 = y*y*t + cosres;
1240 result.m6 = z*y*t + x*sinres;
1241 result.m7 = 0.0f;
1242
1243 result.m8 = x*z*t + y*sinres;
1244 result.m9 = y*z*t - x*sinres;
1245 result.m10 = z*z*t + cosres;
1246 result.m11 = 0.0f;
1247
1248 result.m12 = 0.0f;
1249 result.m13 = 0.0f;
1250 result.m14 = 0.0f;
1251 result.m15 = 1.0f;
1252
1253 return result;
1254}
1255
1256// Get x-rotation matrix (angle in radians)
1258{
1259 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
1260 0.0f, 1.0f, 0.0f, 0.0f,
1261 0.0f, 0.0f, 1.0f, 0.0f,
1262 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
1263
1264 float cosres = cosf(angle);
1265 float sinres = sinf(angle);
1266
1267 result.m5 = cosres;
1268 result.m6 = -sinres;
1269 result.m9 = sinres;
1270 result.m10 = cosres;
1271
1272 return result;
1273}
1274
1275// Get y-rotation matrix (angle in radians)
1277{
1278 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
1279 0.0f, 1.0f, 0.0f, 0.0f,
1280 0.0f, 0.0f, 1.0f, 0.0f,
1281 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
1282
1283 float cosres = cosf(angle);
1284 float sinres = sinf(angle);
1285
1286 result.m0 = cosres;
1287 result.m2 = sinres;
1288 result.m8 = -sinres;
1289 result.m10 = cosres;
1290
1291 return result;
1292}
1293
1294// Get z-rotation matrix (angle in radians)
1296{
1297 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
1298 0.0f, 1.0f, 0.0f, 0.0f,
1299 0.0f, 0.0f, 1.0f, 0.0f,
1300 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
1301
1302 float cosres = cosf(angle);
1303 float sinres = sinf(angle);
1304
1305 result.m0 = cosres;
1306 result.m1 = -sinres;
1307 result.m4 = sinres;
1308 result.m5 = cosres;
1309
1310 return result;
1311}
1312
1313
1314// Get xyz-rotation matrix (angles in radians)
1316{
1317 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
1318 0.0f, 1.0f, 0.0f, 0.0f,
1319 0.0f, 0.0f, 1.0f, 0.0f,
1320 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
1321
1322 float cosz = cosf(-ang.z);
1323 float sinz = sinf(-ang.z);
1324 float cosy = cosf(-ang.y);
1325 float siny = sinf(-ang.y);
1326 float cosx = cosf(-ang.x);
1327 float sinx = sinf(-ang.x);
1328
1329 result.m0 = cosz*cosy;
1330 result.m4 = (cosz*siny*sinx) - (sinz*cosx);
1331 result.m8 = (cosz*siny*cosx) + (sinz*sinx);
1332
1333 result.m1 = sinz*cosy;
1334 result.m5 = (sinz*siny*sinx) + (cosz*cosx);
1335 result.m9 = (sinz*siny*cosx) - (cosz*sinx);
1336
1337 result.m2 = -siny;
1338 result.m6 = cosy*sinx;
1339 result.m10= cosy*cosx;
1340
1341 return result;
1342}
1343
1344// Get zyx-rotation matrix (angles in radians)
1346{
1347 Matrix result = { 0 };
1348
1349 float cz = cosf(ang.z);
1350 float sz = sinf(ang.z);
1351 float cy = cosf(ang.y);
1352 float sy = sinf(ang.y);
1353 float cx = cosf(ang.x);
1354 float sx = sinf(ang.x);
1355
1356 result.m0 = cz*cy;
1357 result.m1 = cz*sy*sx - cx*sz;
1358 result.m2 = sz*sx + cz*cx*sy;
1359 result.m3 = 0;
1360
1361 result.m4 = cy*sz;
1362 result.m5 = cz*cx + sz*sy*sx;
1363 result.m6 = cx*sz*sy - cz*sx;
1364 result.m7 = 0;
1365
1366 result.m8 = -sy;
1367 result.m9 = cy*sx;
1368 result.m10 = cy*cx;
1369 result.m11 = 0;
1370
1371 result.m12 = 0;
1372 result.m13 = 0;
1373 result.m14 = 0;
1374 result.m15 = 1;
1375
1376 return result;
1377}
1378
1379// Get scaling matrix
1380RMAPI Matrix MatrixScale(float x, float y, float z)
1381{
1382 Matrix result = { x, 0.0f, 0.0f, 0.0f,
1383 0.0f, y, 0.0f, 0.0f,
1384 0.0f, 0.0f, z, 0.0f,
1385 0.0f, 0.0f, 0.0f, 1.0f };
1386
1387 return result;
1388}
1389
1390// Get perspective projection matrix
1391RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far)
1392{
1393 Matrix result = { 0 };
1394
1395 float rl = (float)(right - left);
1396 float tb = (float)(top - bottom);
1397 float fn = (float)(far - near);
1398
1399 result.m0 = ((float)near*2.0f)/rl;
1400 result.m1 = 0.0f;
1401 result.m2 = 0.0f;
1402 result.m3 = 0.0f;
1403
1404 result.m4 = 0.0f;
1405 result.m5 = ((float)near*2.0f)/tb;
1406 result.m6 = 0.0f;
1407 result.m7 = 0.0f;
1408
1409 result.m8 = ((float)right + (float)left)/rl;
1410 result.m9 = ((float)top + (float)bottom)/tb;
1411 result.m10 = -((float)far + (float)near)/fn;
1412 result.m11 = -1.0f;
1413
1414 result.m12 = 0.0f;
1415 result.m13 = 0.0f;
1416 result.m14 = -((float)far*(float)near*2.0f)/fn;
1417 result.m15 = 0.0f;
1418
1419 return result;
1420}
1421
1422// Get perspective projection matrix
1423// NOTE: Angle should be provided in radians
1424RMAPI Matrix MatrixPerspective(double fovy, double aspect, double near, double far)
1425{
1426 Matrix result = { 0 };
1427
1428 double top = near*tan(fovy*0.5);
1429 double bottom = -top;
1430 double right = top*aspect;
1431 double left = -right;
1432
1433 // MatrixFrustum(-right, right, -top, top, near, far);
1434 float rl = (float)(right - left);
1435 float tb = (float)(top - bottom);
1436 float fn = (float)(far - near);
1437
1438 result.m0 = ((float)near*2.0f)/rl;
1439 result.m5 = ((float)near*2.0f)/tb;
1440 result.m8 = ((float)right + (float)left)/rl;
1441 result.m9 = ((float)top + (float)bottom)/tb;
1442 result.m10 = -((float)far + (float)near)/fn;
1443 result.m11 = -1.0f;
1444 result.m14 = -((float)far*(float)near*2.0f)/fn;
1445
1446 return result;
1447}
1448
1449// Get orthographic projection matrix
1450RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far)
1451{
1452 Matrix result = { 0 };
1453
1454 float rl = (float)(right - left);
1455 float tb = (float)(top - bottom);
1456 float fn = (float)(far - near);
1457
1458 result.m0 = 2.0f/rl;
1459 result.m1 = 0.0f;
1460 result.m2 = 0.0f;
1461 result.m3 = 0.0f;
1462 result.m4 = 0.0f;
1463 result.m5 = 2.0f/tb;
1464 result.m6 = 0.0f;
1465 result.m7 = 0.0f;
1466 result.m8 = 0.0f;
1467 result.m9 = 0.0f;
1468 result.m10 = -2.0f/fn;
1469 result.m11 = 0.0f;
1470 result.m12 = -((float)left + (float)right)/rl;
1471 result.m13 = -((float)top + (float)bottom)/tb;
1472 result.m14 = -((float)far + (float)near)/fn;
1473 result.m15 = 1.0f;
1474
1475 return result;
1476}
1477
1478// Get camera look-at matrix (view matrix)
1480{
1481 Matrix result = { 0 };
1482
1483 float length = 0.0f;
1484 float ilength = 0.0f;
1485
1486 // Vector3Subtract(eye, target)
1487 Vector3 vz = { eye.x - target.x, eye.y - target.y, eye.z - target.z };
1488
1489 // Vector3Normalize(vz)
1490 Vector3 v = vz;
1491 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
1492 if (length == 0.0f) length = 1.0f;
1493 ilength = 1.0f/length;
1494 vz.x *= ilength;
1495 vz.y *= ilength;
1496 vz.z *= ilength;
1497
1498 // Vector3CrossProduct(up, vz)
1499 Vector3 vx = { up.y*vz.z - up.z*vz.y, up.z*vz.x - up.x*vz.z, up.x*vz.y - up.y*vz.x };
1500
1501 // Vector3Normalize(x)
1502 v = vx;
1503 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
1504 if (length == 0.0f) length = 1.0f;
1505 ilength = 1.0f/length;
1506 vx.x *= ilength;
1507 vx.y *= ilength;
1508 vx.z *= ilength;
1509
1510 // Vector3CrossProduct(vz, vx)
1511 Vector3 vy = { vz.y*vx.z - vz.z*vx.y, vz.z*vx.x - vz.x*vx.z, vz.x*vx.y - vz.y*vx.x };
1512
1513 result.m0 = vx.x;
1514 result.m1 = vy.x;
1515 result.m2 = vz.x;
1516 result.m3 = 0.0f;
1517 result.m4 = vx.y;
1518 result.m5 = vy.y;
1519 result.m6 = vz.y;
1520 result.m7 = 0.0f;
1521 result.m8 = vx.z;
1522 result.m9 = vy.z;
1523 result.m10 = vz.z;
1524 result.m11 = 0.0f;
1525 result.m12 = -(vx.x*eye.x + vx.y*eye.y + vx.z*eye.z); // Vector3DotProduct(vx, eye)
1526 result.m13 = -(vy.x*eye.x + vy.y*eye.y + vy.z*eye.z); // Vector3DotProduct(vy, eye)
1527 result.m14 = -(vz.x*eye.x + vz.y*eye.y + vz.z*eye.z); // Vector3DotProduct(vz, eye)
1528 result.m15 = 1.0f;
1529
1530 return result;
1531}
1532
1533// Get float array of matrix data
1535{
1536 float16 result = { 0 };
1537
1538 result.v[0] = mat.m0;
1539 result.v[1] = mat.m1;
1540 result.v[2] = mat.m2;
1541 result.v[3] = mat.m3;
1542 result.v[4] = mat.m4;
1543 result.v[5] = mat.m5;
1544 result.v[6] = mat.m6;
1545 result.v[7] = mat.m7;
1546 result.v[8] = mat.m8;
1547 result.v[9] = mat.m9;
1548 result.v[10] = mat.m10;
1549 result.v[11] = mat.m11;
1550 result.v[12] = mat.m12;
1551 result.v[13] = mat.m13;
1552 result.v[14] = mat.m14;
1553 result.v[15] = mat.m15;
1554
1555 return result;
1556}
1557
1558//----------------------------------------------------------------------------------
1559// Module Functions Definition - Quaternion math
1560//----------------------------------------------------------------------------------
1561
1562// Add two quaternions
1564{
1565 Quaternion result = {q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w};
1566
1567 return result;
1568}
1569
1570// Add quaternion and float value
1572{
1573 Quaternion result = {q.x + add, q.y + add, q.z + add, q.w + add};
1574
1575 return result;
1576}
1577
1578// Subtract two quaternions
1580{
1581 Quaternion result = {q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w};
1582
1583 return result;
1584}
1585
1586// Subtract quaternion and float value
1588{
1589 Quaternion result = {q.x - sub, q.y - sub, q.z - sub, q.w - sub};
1590
1591 return result;
1592}
1593
1594// Get identity quaternion
1596{
1597 Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
1598
1599 return result;
1600}
1601
1602// Computes the length of a quaternion
1604{
1605 float result = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
1606
1607 return result;
1608}
1609
1610// Normalize provided quaternion
1612{
1613 Quaternion result = { 0 };
1614
1615 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
1616 if (length == 0.0f) length = 1.0f;
1617 float ilength = 1.0f/length;
1618
1619 result.x = q.x*ilength;
1620 result.y = q.y*ilength;
1621 result.z = q.z*ilength;
1622 result.w = q.w*ilength;
1623
1624 return result;
1625}
1626
1627// Invert provided quaternion
1629{
1630 Quaternion result = q;
1631
1632 float lengthSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;
1633
1634 if (lengthSq != 0.0f)
1635 {
1636 float invLength = 1.0f/lengthSq;
1637
1638 result.x *= -invLength;
1639 result.y *= -invLength;
1640 result.z *= -invLength;
1641 result.w *= invLength;
1642 }
1643
1644 return result;
1645}
1646
1647// Calculate two quaternion multiplication
1649{
1650 Quaternion result = { 0 };
1651
1652 float qax = q1.x, qay = q1.y, qaz = q1.z, qaw = q1.w;
1653 float qbx = q2.x, qby = q2.y, qbz = q2.z, qbw = q2.w;
1654
1655 result.x = qax*qbw + qaw*qbx + qay*qbz - qaz*qby;
1656 result.y = qay*qbw + qaw*qby + qaz*qbx - qax*qbz;
1657 result.z = qaz*qbw + qaw*qbz + qax*qby - qay*qbx;
1658 result.w = qaw*qbw - qax*qbx - qay*qby - qaz*qbz;
1659
1660 return result;
1661}
1662
1663// Scale quaternion by float value
1665{
1666 Quaternion result = { 0 };
1667
1668 result.x = q.x*mul;
1669 result.y = q.y*mul;
1670 result.z = q.z*mul;
1671 result.w = q.w*mul;
1672
1673 return result;
1674}
1675
1676// Divide two quaternions
1678{
1679 Quaternion result = { q1.x/q2.x, q1.y/q2.y, q1.z/q2.z, q1.w/q2.w };
1680
1681 return result;
1682}
1683
1684// Calculate linear interpolation between two quaternions
1686{
1687 Quaternion result = { 0 };
1688
1689 result.x = q1.x + amount*(q2.x - q1.x);
1690 result.y = q1.y + amount*(q2.y - q1.y);
1691 result.z = q1.z + amount*(q2.z - q1.z);
1692 result.w = q1.w + amount*(q2.w - q1.w);
1693
1694 return result;
1695}
1696
1697// Calculate slerp-optimized interpolation between two quaternions
1699{
1700 Quaternion result = { 0 };
1701
1702 // QuaternionLerp(q1, q2, amount)
1703 result.x = q1.x + amount*(q2.x - q1.x);
1704 result.y = q1.y + amount*(q2.y - q1.y);
1705 result.z = q1.z + amount*(q2.z - q1.z);
1706 result.w = q1.w + amount*(q2.w - q1.w);
1707
1708 // QuaternionNormalize(q);
1709 Quaternion q = result;
1710 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
1711 if (length == 0.0f) length = 1.0f;
1712 float ilength = 1.0f/length;
1713
1714 result.x = q.x*ilength;
1715 result.y = q.y*ilength;
1716 result.z = q.z*ilength;
1717 result.w = q.w*ilength;
1718
1719 return result;
1720}
1721
1722// Calculates spherical linear interpolation between two quaternions
1724{
1725 Quaternion result = { 0 };
1726
1727 float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w;
1728
1729 if (cosHalfTheta < 0)
1730 {
1731 q2.x = -q2.x; q2.y = -q2.y; q2.z = -q2.z; q2.w = -q2.w;
1732 cosHalfTheta = -cosHalfTheta;
1733 }
1734
1735 if (fabsf(cosHalfTheta) >= 1.0f) result = q1;
1736 else if (cosHalfTheta > 0.95f) result = QuaternionNlerp(q1, q2, amount);
1737 else
1738 {
1739 float halfTheta = acosf(cosHalfTheta);
1740 float sinHalfTheta = sqrtf(1.0f - cosHalfTheta*cosHalfTheta);
1741
1742 if (fabsf(sinHalfTheta) < 0.001f)
1743 {
1744 result.x = (q1.x*0.5f + q2.x*0.5f);
1745 result.y = (q1.y*0.5f + q2.y*0.5f);
1746 result.z = (q1.z*0.5f + q2.z*0.5f);
1747 result.w = (q1.w*0.5f + q2.w*0.5f);
1748 }
1749 else
1750 {
1751 float ratioA = sinf((1 - amount)*halfTheta)/sinHalfTheta;
1752 float ratioB = sinf(amount*halfTheta)/sinHalfTheta;
1753
1754 result.x = (q1.x*ratioA + q2.x*ratioB);
1755 result.y = (q1.y*ratioA + q2.y*ratioB);
1756 result.z = (q1.z*ratioA + q2.z*ratioB);
1757 result.w = (q1.w*ratioA + q2.w*ratioB);
1758 }
1759 }
1760
1761 return result;
1762}
1763
1764// Calculate quaternion based on the rotation from one vector to another
1766{
1767 Quaternion result = { 0 };
1768
1769 float cos2Theta = (from.x*to.x + from.y*to.y + from.z*to.z); // Vector3DotProduct(from, to)
1770 Vector3 cross = { from.y*to.z - from.z*to.y, from.z*to.x - from.x*to.z, from.x*to.y - from.y*to.x }; // Vector3CrossProduct(from, to)
1771
1772 result.x = cross.x;
1773 result.y = cross.y;
1774 result.z = cross.z;
1775 result.w = 1.0f + cos2Theta;
1776
1777 // QuaternionNormalize(q);
1778 // NOTE: Normalize to essentially nlerp the original and identity to 0.5
1779 Quaternion q = result;
1780 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
1781 if (length == 0.0f) length = 1.0f;
1782 float ilength = 1.0f/length;
1783
1784 result.x = q.x*ilength;
1785 result.y = q.y*ilength;
1786 result.z = q.z*ilength;
1787 result.w = q.w*ilength;
1788
1789 return result;
1790}
1791
1792// Get a quaternion for a given rotation matrix
1794{
1795 Quaternion result = { 0 };
1796
1797 if ((mat.m0 > mat.m5) && (mat.m0 > mat.m10))
1798 {
1799 float s = sqrtf(1.0f + mat.m0 - mat.m5 - mat.m10)*2;
1800
1801 result.x = 0.25f*s;
1802 result.y = (mat.m4 + mat.m1)/s;
1803 result.z = (mat.m2 + mat.m8)/s;
1804 result.w = (mat.m9 - mat.m6)/s;
1805 }
1806 else if (mat.m5 > mat.m10)
1807 {
1808 float s = sqrtf(1.0f + mat.m5 - mat.m0 - mat.m10)*2;
1809 result.x = (mat.m4 + mat.m1)/s;
1810 result.y = 0.25f*s;
1811 result.z = (mat.m9 + mat.m6)/s;
1812 result.w = (mat.m2 - mat.m8)/s;
1813 }
1814 else
1815 {
1816 float s = sqrtf(1.0f + mat.m10 - mat.m0 - mat.m5)*2;
1817 result.x = (mat.m2 + mat.m8)/s;
1818 result.y = (mat.m9 + mat.m6)/s;
1819 result.z = 0.25f*s;
1820 result.w = (mat.m4 - mat.m1)/s;
1821 }
1822
1823 return result;
1824}
1825
1826// Get a matrix for a given quaternion
1828{
1829 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
1830 0.0f, 1.0f, 0.0f, 0.0f,
1831 0.0f, 0.0f, 1.0f, 0.0f,
1832 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
1833
1834 float a2 = q.x*q.x;
1835 float b2 = q.y*q.y;
1836 float c2 = q.z*q.z;
1837 float ac = q.x*q.z;
1838 float ab = q.x*q.y;
1839 float bc = q.y*q.z;
1840 float ad = q.w*q.x;
1841 float bd = q.w*q.y;
1842 float cd = q.w*q.z;
1843
1844 result.m0 = 1 - 2*(b2 + c2);
1845 result.m1 = 2*(ab + cd);
1846 result.m2 = 2*(ac - bd);
1847
1848 result.m4 = 2*(ab - cd);
1849 result.m5 = 1 - 2*(a2 + c2);
1850 result.m6 = 2*(bc + ad);
1851
1852 result.m8 = 2*(ac + bd);
1853 result.m9 = 2*(bc - ad);
1854 result.m10 = 1 - 2*(a2 + b2);
1855
1856 return result;
1857}
1858
1859// Get rotation quaternion for an angle and axis
1860// NOTE: angle must be provided in radians
1862{
1863 Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
1864
1865 float axisLength = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);
1866
1867 if (axisLength != 0.0f)
1868 {
1869 angle *= 0.5f;
1870
1871 float length = 0.0f;
1872 float ilength = 0.0f;
1873
1874 // Vector3Normalize(axis)
1875 Vector3 v = axis;
1876 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
1877 if (length == 0.0f) length = 1.0f;
1878 ilength = 1.0f/length;
1879 axis.x *= ilength;
1880 axis.y *= ilength;
1881 axis.z *= ilength;
1882
1883 float sinres = sinf(angle);
1884 float cosres = cosf(angle);
1885
1886 result.x = axis.x*sinres;
1887 result.y = axis.y*sinres;
1888 result.z = axis.z*sinres;
1889 result.w = cosres;
1890
1891 // QuaternionNormalize(q);
1892 Quaternion q = result;
1893 length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
1894 if (length == 0.0f) length = 1.0f;
1895 ilength = 1.0f/length;
1896 result.x = q.x*ilength;
1897 result.y = q.y*ilength;
1898 result.z = q.z*ilength;
1899 result.w = q.w*ilength;
1900 }
1901
1902 return result;
1903}
1904
1905// Get the rotation angle and axis for a given quaternion
1906RMAPI void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle)
1907{
1908 if (fabsf(q.w) > 1.0f)
1909 {
1910 // QuaternionNormalize(q);
1911 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
1912 if (length == 0.0f) length = 1.0f;
1913 float ilength = 1.0f/length;
1914
1915 q.x = q.x*ilength;
1916 q.y = q.y*ilength;
1917 q.z = q.z*ilength;
1918 q.w = q.w*ilength;
1919 }
1920
1921 Vector3 resAxis = { 0.0f, 0.0f, 0.0f };
1922 float resAngle = 2.0f*acosf(q.w);
1923 float den = sqrtf(1.0f - q.w*q.w);
1924
1925 if (den > 0.0001f)
1926 {
1927 resAxis.x = q.x/den;
1928 resAxis.y = q.y/den;
1929 resAxis.z = q.z/den;
1930 }
1931 else
1932 {
1933 // This occurs when the angle is zero.
1934 // Not a problem: just set an arbitrary normalized axis.
1935 resAxis.x = 1.0f;
1936 }
1937
1938 *outAxis = resAxis;
1939 *outAngle = resAngle;
1940}
1941
1942// Get the quaternion equivalent to Euler angles
1943// NOTE: Rotation order is ZYX
1944RMAPI Quaternion QuaternionFromEuler(float pitch, float yaw, float roll)
1945{
1946 Quaternion result = { 0 };
1947
1948 float x0 = cosf(pitch*0.5f);
1949 float x1 = sinf(pitch*0.5f);
1950 float y0 = cosf(yaw*0.5f);
1951 float y1 = sinf(yaw*0.5f);
1952 float z0 = cosf(roll*0.5f);
1953 float z1 = sinf(roll*0.5f);
1954
1955 result.x = x1*y0*z0 - x0*y1*z1;
1956 result.y = x0*y1*z0 + x1*y0*z1;
1957 result.z = x0*y0*z1 - x1*y1*z0;
1958 result.w = x0*y0*z0 + x1*y1*z1;
1959
1960 return result;
1961}
1962
1963// Get the Euler angles equivalent to quaternion (roll, pitch, yaw)
1964// NOTE: Angles are returned in a Vector3 struct in radians
1966{
1967 Vector3 result = { 0 };
1968
1969 // Roll (x-axis rotation)
1970 float x0 = 2.0f*(q.w*q.x + q.y*q.z);
1971 float x1 = 1.0f - 2.0f*(q.x*q.x + q.y*q.y);
1972 result.x = atan2f(x0, x1);
1973
1974 // Pitch (y-axis rotation)
1975 float y0 = 2.0f*(q.w*q.y - q.z*q.x);
1976 y0 = y0 > 1.0f ? 1.0f : y0;
1977 y0 = y0 < -1.0f ? -1.0f : y0;
1978 result.y = asinf(y0);
1979
1980 // Yaw (z-axis rotation)
1981 float z0 = 2.0f*(q.w*q.z + q.x*q.y);
1982 float z1 = 1.0f - 2.0f*(q.y*q.y + q.z*q.z);
1983 result.z = atan2f(z0, z1);
1984
1985 return result;
1986}
1987
1988// Transform a quaternion given a transformation matrix
1990{
1991 Quaternion result = { 0 };
1992
1993 result.x = mat.m0*q.x + mat.m4*q.y + mat.m8*q.z + mat.m12*q.w;
1994 result.y = mat.m1*q.x + mat.m5*q.y + mat.m9*q.z + mat.m13*q.w;
1995 result.z = mat.m2*q.x + mat.m6*q.y + mat.m10*q.z + mat.m14*q.w;
1996 result.w = mat.m3*q.x + mat.m7*q.y + mat.m11*q.z + mat.m15*q.w;
1997
1998 return result;
1999}
2000
2001// Check whether two given quaternions are almost equal
2003{
2004 int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
2005 ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
2006 ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&
2007 ((fabsf(p.w - q.w)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.w), fabsf(q.w)))));
2008
2009 return result;
2010}
2011
2012#endif // RAYMATH_H
#define EPSILON
Definition: raymath.h:81
RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
Definition: raymath.h:450
RMAPI float Clamp(float value, float min, float max)
Definition: raymath.h:168
RMAPI Vector3 Vector3Normalize(Vector3 v)
Definition: raymath.h:670
RMAPI float QuaternionLength(Quaternion q)
Definition: raymath.h:1603
RMAPI Vector2 Vector2Transform(Vector2 v, Matrix mat)
Definition: raymath.h:358
RMAPI Vector2 Vector2Negate(Vector2 v)
Definition: raymath.h:326
RMAPI Vector3 Vector3Clamp(Vector3 v, Vector3 min, Vector3 max)
Definition: raymath.h:932
RMAPI Vector3 Vector3Transform(Vector3 v, Matrix mat)
Definition: raymath.h:721
#define RMAPI
raymath v1.5 - Math functions to work with Vector2, Vector3, Matrix and Quaternions
Definition: raymath.h:69
RMAPI Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q)
Definition: raymath.h:737
RMAPI Vector2 Vector2Zero(void)
Definition: raymath.h:214
RMAPI Matrix MatrixRotate(Vector3 axis, float angle)
Definition: raymath.h:1213
RMAPI Vector2 Vector2One(void)
Definition: raymath.h:222
RMAPI float Vector2LengthSqr(Vector2 v)
Definition: raymath.h:270
RMAPI Vector2 Vector2Multiply(Vector2 v1, Vector2 v2)
Definition: raymath.h:318
RMAPI Quaternion QuaternionNormalize(Quaternion q)
Definition: raymath.h:1611
RMAPI Quaternion QuaternionFromEuler(float pitch, float yaw, float roll)
Definition: raymath.h:1944
RMAPI Vector2 Vector2Invert(Vector2 v)
Definition: raymath.h:430
RMAPI Quaternion QuaternionIdentity(void)
Definition: raymath.h:1595
RMAPI Quaternion QuaternionInvert(Quaternion q)
Definition: raymath.h:1628
RMAPI Vector3 Vector3AddValue(Vector3 v, float add)
Definition: raymath.h:514
RMAPI Quaternion QuaternionFromMatrix(Matrix mat)
Definition: raymath.h:1793
RMAPI float Vector3Angle(Vector3 v1, Vector3 v2)
Definition: raymath.h:641
RMAPI Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount)
Definition: raymath.h:1698
RMAPI Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to)
Definition: raymath.h:1765
RMAPI Matrix QuaternionToMatrix(Quaternion q)
Definition: raymath.h:1827
RMAPI Vector3 Vector3Min(Vector3 v1, Vector3 v2)
Definition: raymath.h:779
RMAPI Vector2 Vector2Divide(Vector2 v1, Vector2 v2)
Definition: raymath.h:334
RMAPI Vector3 Vector3Perpendicular(Vector3 v)
Definition: raymath.h:562
RMAPI Vector2 Vector2AddValue(Vector2 v, float add)
Definition: raymath.h:238
RMAPI Quaternion QuaternionScale(Quaternion q, float mul)
Definition: raymath.h:1664
RMAPI int FloatEquals(float x, float y)
Definition: raymath.h:202
RMAPI float Vector3LengthSqr(const Vector3 v)
Definition: raymath.h:599
RMAPI float Vector3DotProduct(Vector3 v1, Vector3 v2)
Definition: raymath.h:607
RMAPI Matrix MatrixScale(float x, float y, float z)
Definition: raymath.h:1380
RMAPI Vector2 Vector2Rotate(Vector2 v, float angle)
Definition: raymath.h:397
RMAPI Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
Definition: raymath.h:804
RMAPI Vector3 Vector3Add(Vector3 v1, Vector3 v2)
Definition: raymath.h:506
RMAPI float Normalize(float value, float start, float end)
Definition: raymath.h:186
RMAPI Vector3 Vector3One(void)
Definition: raymath.h:498
RMAPI Vector2 Vector2Reflect(Vector2 v, Vector2 normal)
Definition: raymath.h:384
RMAPI Vector2 Vector2Add(Vector2 v1, Vector2 v2)
Definition: raymath.h:230
RMAPI Matrix MatrixIdentity(void)
Definition: raymath.h:1114
RMAPI Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance)
Definition: raymath.h:411
RMAPI Matrix MatrixRotateX(float angle)
Definition: raymath.h:1257
struct Vector2 Vector2
RMAPI Vector3 Vector3Zero(void)
Definition: raymath.h:490
RMAPI Vector3 Vector3Subtract(Vector3 v1, Vector3 v2)
Definition: raymath.h:522
RMAPI Vector2 Vector2Scale(Vector2 v, float scale)
Definition: raymath.h:310
Vector4 Quaternion
Definition: raymath.h:137
RMAPI Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2)
Definition: raymath.h:1579
RMAPI float Vector2DotProduct(Vector2 v1, Vector2 v2)
Definition: raymath.h:278
RMAPI float Vector3DistanceSqr(Vector3 v1, Vector3 v2)
Definition: raymath.h:628
RMAPI int Vector3Equals(Vector3 p, Vector3 q)
Definition: raymath.h:973
RMAPI Vector2 Vector2Normalize(Vector2 v)
Definition: raymath.h:342
RMAPI Quaternion QuaternionDivide(Quaternion q1, Quaternion q2)
Definition: raymath.h:1677
RMAPI Quaternion QuaternionAdd(Quaternion q1, Quaternion q2)
Definition: raymath.h:1563
RMAPI float Vector2Length(Vector2 v)
Definition: raymath.h:262
RMAPI Matrix MatrixTranslate(float x, float y, float z)
Definition: raymath.h:1201
RMAPI Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view)
Definition: raymath.h:828
RMAPI Vector3 Vector3Multiply(Vector3 v1, Vector3 v2)
Definition: raymath.h:546
RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
Definition: raymath.h:2002
RMAPI float16 MatrixToFloatV(Matrix mat)
Definition: raymath.h:1534
RMAPI Vector2 Vector2Clamp(Vector2 v, Vector2 min, Vector2 max)
Definition: raymath.h:439
RMAPI Vector3 Vector3Negate(Vector3 v)
Definition: raymath.h:654
struct Matrix Matrix
RMAPI Vector3 Vector3Divide(Vector3 v1, Vector3 v2)
Definition: raymath.h:662
RMAPI float Vector3Distance(Vector3 v1, Vector3 v2)
Definition: raymath.h:615
RMAPI float MatrixDeterminant(Matrix mat)
Definition: raymath.h:1013
RMAPI float3 Vector3ToFloatV(Vector3 v)
Definition: raymath.h:911
RMAPI Quaternion QuaternionTransform(Quaternion q, Matrix mat)
Definition: raymath.h:1989
RMAPI Matrix MatrixPerspective(double fovy, double aspect, double near, double far)
Definition: raymath.h:1424
RMAPI Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount)
Definition: raymath.h:749
RMAPI Matrix MatrixInvert(Matrix mat)
Definition: raymath.h:1067
RMAPI Matrix MatrixSubtract(Matrix left, Matrix right)
Definition: raymath.h:1150
RMAPI float Lerp(float start, float end, float amount)
Definition: raymath.h:178
RMAPI Vector3 Vector3SubtractValue(Vector3 v, float sub)
Definition: raymath.h:530
RMAPI Matrix MatrixRotateZYX(Vector3 ang)
Definition: raymath.h:1345
RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2)
Definition: raymath.h:294
RMAPI Vector2 Vector2SubtractValue(Vector2 v, float sub)
Definition: raymath.h:254
RMAPI Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
Definition: raymath.h:246
RMAPI Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
Definition: raymath.h:1723
RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
Definition: raymath.h:944
RMAPI Vector3 Vector3Refract(Vector3 v, Vector3 n, float r)
Definition: raymath.h:988
RMAPI Matrix MatrixRotateXYZ(Vector3 ang)
Definition: raymath.h:1315
RMAPI Vector3 Vector3Reflect(Vector3 v, Vector3 normal)
Definition: raymath.h:761
RMAPI Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
Definition: raymath.h:1861
RMAPI float Vector2Distance(Vector2 v1, Vector2 v2)
Definition: raymath.h:286
RMAPI void Vector3OrthoNormalize(Vector3 *v1, Vector3 *v2)
Definition: raymath.h:688
RMAPI Vector3 QuaternionToEuler(Quaternion q)
Definition: raymath.h:1965
RMAPI float MatrixTrace(Matrix mat)
Definition: raymath.h:1034
RMAPI float Vector3Length(const Vector3 v)
Definition: raymath.h:591
RMAPI Matrix MatrixAdd(Matrix left, Matrix right)
Definition: raymath.h:1125
RMAPI Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2)
Definition: raymath.h:554
RMAPI Quaternion QuaternionAddValue(Quaternion q, float add)
Definition: raymath.h:1571
RMAPI Matrix MatrixRotateY(float angle)
Definition: raymath.h:1276
RMAPI void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle)
Definition: raymath.h:1906
RMAPI Vector3 Vector3Max(Vector3 v1, Vector3 v2)
Definition: raymath.h:791
RMAPI Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2)
Definition: raymath.h:1648
RMAPI Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount)
Definition: raymath.h:1685
RMAPI Matrix MatrixRotateZ(float angle)
Definition: raymath.h:1295
RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top, double near, double far)
Definition: raymath.h:1391
RMAPI Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount)
Definition: raymath.h:373
RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, double near, double far)
Definition: raymath.h:1450
RMAPI Quaternion QuaternionSubtractValue(Quaternion q, float sub)
Definition: raymath.h:1587
RMAPI int Vector2Equals(Vector2 p, Vector2 q)
Definition: raymath.h:477
RMAPI float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd)
Definition: raymath.h:194
RMAPI Vector3 Vector3Invert(Vector3 v)
Definition: raymath.h:923
RMAPI Vector3 Vector3Scale(Vector3 v, float scalar)
Definition: raymath.h:538
RMAPI Matrix MatrixTranspose(Matrix mat)
Definition: raymath.h:1042
RMAPI Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up)
Definition: raymath.h:1479
RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
Definition: raymath.h:302
RMAPI Matrix MatrixMultiply(Matrix left, Matrix right)
Definition: raymath.h:1176
Definition: raylib.h:212
float m14
Definition: raylib.h:215
float m11
Definition: raylib.h:216
float m5
Definition: raylib.h:214
float m15
Definition: raylib.h:216
float m3
Definition: raylib.h:216
float m1
Definition: raylib.h:214
float m9
Definition: raylib.h:214
float m0
Definition: raylib.h:213
float m2
Definition: raylib.h:215
float m6
Definition: raylib.h:215
float m4
Definition: raylib.h:213
float m13
Definition: raylib.h:214
float m8
Definition: raylib.h:213
float m12
Definition: raylib.h:213
float m7
Definition: raylib.h:216
float m10
Definition: raylib.h:215
float x
Definition: physac.h:130
float y
Definition: physac.h:131
float x
Definition: raylib.h:195
float y
Definition: raylib.h:196
float z
Definition: raylib.h:197
float x
Definition: raylib.h:202
float y
Definition: raylib.h:203
float w
Definition: raylib.h:205
float z
Definition: raylib.h:204
float v[16]
Definition: raymath.h:158
float v[3]
Definition: raymath.h:154