annotate third_party/raylib/include/raymath.h @ 63:fff1b048dda6

[Postdog] Fixed a problem where string did not wrap.
author June Park <parkjune1995@gmail.com>
date Tue, 23 Dec 2025 14:00:37 -0800
parents f33d9ff8b6e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 /**********************************************************************************************
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3 * raymath v2.0 - Math functions to work with Vector2, Vector3, Matrix and Quaternions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5 * CONVENTIONS:
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
6 * - Matrix structure is defined as row-major (memory layout) but parameters naming AND all
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
7 * math operations performed by the library consider the structure as it was column-major
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
8 * It is like transposed versions of the matrices are used for all the maths
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
9 * It benefits some functions making them cache-friendly and also avoids matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
10 * transpositions sometimes required by OpenGL
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
11 * Example: In memory order, row0 is [m0 m4 m8 m12] but in semantic math row0 is [m0 m1 m2 m3]
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
12 * - Functions are always self-contained, no function use another raymath function inside,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
13 * required code is directly re-implemented inside
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
14 * - Functions input parameters are always received by value (2 unavoidable exceptions)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
15 * - Functions use always a "result" variable for return (except C++ operators)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
16 * - Functions are always defined inline
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
17 * - Angles are always in radians (DEG2RAD/RAD2DEG macros provided for convenience)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
18 * - No compound literals used to make sure libray is compatible with C++
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
19 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
20 * CONFIGURATION:
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
21 * #define RAYMATH_IMPLEMENTATION
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22 * Generates the implementation of the library into the included file.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23 * If not defined, the library is in header only mode and can be included in other headers
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
24 * or source files without problems. But only ONE file should hold the implementation.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
25 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
26 * #define RAYMATH_STATIC_INLINE
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
27 * Define static inline functions code, so #include header suffices for use.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
28 * This may use up lots of memory.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
29 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
30 * #define RAYMATH_DISABLE_CPP_OPERATORS
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
31 * Disables C++ operator overloads for raymath types.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
32 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
33 * LICENSE: zlib/libpng
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
34 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
35 * Copyright (c) 2015-2024 Ramon Santamaria (@raysan5)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
36 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
37 * This software is provided "as-is", without any express or implied warranty. In no event
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
38 * will the authors be held liable for any damages arising from the use of this software.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
39 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
40 * Permission is granted to anyone to use this software for any purpose, including commercial
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
41 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
42 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
43 * 1. The origin of this software must not be misrepresented; you must not claim that you
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
44 * wrote the original software. If you use this software in a product, an acknowledgment
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
45 * in the product documentation would be appreciated but is not required.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
46 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
47 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
48 * as being the original software.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
49 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
50 * 3. This notice may not be removed or altered from any source distribution.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
51 *
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
52 **********************************************************************************************/
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
53
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
54 #ifndef RAYMATH_H
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
55 #define RAYMATH_H
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
56
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
57 #if defined(RAYMATH_IMPLEMENTATION) && defined(RAYMATH_STATIC_INLINE)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
58 #error "Specifying both RAYMATH_IMPLEMENTATION and RAYMATH_STATIC_INLINE is contradictory"
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
59 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
60
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
61 // Function specifiers definition
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
62 #if defined(RAYMATH_IMPLEMENTATION)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
63 #if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
64 #define RMAPI __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
65 #elif defined(BUILD_LIBTYPE_SHARED)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
66 #define RMAPI __attribute__((visibility("default"))) // We are building raylib as a Unix shared library (.so/.dylib)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
67 #elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
68 #define RMAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
69 #else
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
70 #define RMAPI extern inline // Provide external definition
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
71 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
72 #elif defined(RAYMATH_STATIC_INLINE)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
73 #define RMAPI static inline // Functions may be inlined, no external out-of-line definition
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
74 #else
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
75 #if defined(__TINYC__)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
76 #define RMAPI static inline // plain inline not supported by tinycc (See issue #435)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
77 #else
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
78 #define RMAPI inline // Functions may be inlined or external definition used
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
79 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
80 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
81
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
82
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
83 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
84 // Defines and Macros
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
85 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
86 #ifndef PI
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
87 #define PI 3.14159265358979323846f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
88 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
89
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
90 #ifndef EPSILON
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
91 #define EPSILON 0.000001f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
92 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
93
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
94 #ifndef DEG2RAD
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
95 #define DEG2RAD (PI/180.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
96 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
97
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
98 #ifndef RAD2DEG
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
99 #define RAD2DEG (180.0f/PI)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
100 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
101
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
102 // Get float vector for Matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
103 #ifndef MatrixToFloat
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
104 #define MatrixToFloat(mat) (MatrixToFloatV(mat).v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
105 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
106
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
107 // Get float vector for Vector3
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
108 #ifndef Vector3ToFloat
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
109 #define Vector3ToFloat(vec) (Vector3ToFloatV(vec).v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
110 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
111
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
112 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
113 // Types and Structures Definition
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
114 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
115 #if !defined(RL_VECTOR2_TYPE)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
116 // Vector2 type
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
117 typedef struct Vector2 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
118 float x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
119 float y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
120 } Vector2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
121 #define RL_VECTOR2_TYPE
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
122 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
123
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
124 #if !defined(RL_VECTOR3_TYPE)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
125 // Vector3 type
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
126 typedef struct Vector3 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
127 float x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
128 float y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
129 float z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
130 } Vector3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
131 #define RL_VECTOR3_TYPE
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
132 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
133
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
134 #if !defined(RL_VECTOR4_TYPE)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
135 // Vector4 type
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
136 typedef struct Vector4 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
137 float x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
138 float y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
139 float z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
140 float w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
141 } Vector4;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
142 #define RL_VECTOR4_TYPE
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
143 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
144
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
145 #if !defined(RL_QUATERNION_TYPE)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
146 // Quaternion type
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
147 typedef Vector4 Quaternion;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
148 #define RL_QUATERNION_TYPE
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
149 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
150
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
151 #if !defined(RL_MATRIX_TYPE)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
152 // Matrix type (OpenGL style 4x4 - right handed, column major)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
153 typedef struct Matrix {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
154 float m0, m4, m8, m12; // Matrix first row (4 components)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
155 float m1, m5, m9, m13; // Matrix second row (4 components)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
156 float m2, m6, m10, m14; // Matrix third row (4 components)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
157 float m3, m7, m11, m15; // Matrix fourth row (4 components)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
158 } Matrix;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
159 #define RL_MATRIX_TYPE
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
160 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
161
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
162 // NOTE: Helper types to be used instead of array return types for *ToFloat functions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
163 typedef struct float3 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
164 float v[3];
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
165 } float3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
166
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
167 typedef struct float16 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
168 float v[16];
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
169 } float16;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
170
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
171 #include <math.h> // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabsf()
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
172
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
173 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
174 // Module Functions Definition - Utils math
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
175 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
176
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
177 // Clamp float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
178 RMAPI float Clamp(float value, float min, float max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
179 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
180 float result = (value < min)? min : value;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
181
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
182 if (result > max) result = max;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
183
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
184 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
185 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
186
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
187 // Calculate linear interpolation between two floats
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
188 RMAPI float Lerp(float start, float end, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
189 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
190 float result = start + amount*(end - start);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
191
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
192 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
193 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
194
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
195 // Normalize input value within input range
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
196 RMAPI float Normalize(float value, float start, float end)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
197 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
198 float result = (value - start)/(end - start);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
199
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
200 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
201 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
202
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
203 // Remap input value within input range to output range
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
204 RMAPI float Remap(float value, float inputStart, float inputEnd, float outputStart, float outputEnd)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
205 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
206 float result = (value - inputStart)/(inputEnd - inputStart)*(outputEnd - outputStart) + outputStart;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
207
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
208 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
209 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
210
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
211 // Wrap input value from min to max
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
212 RMAPI float Wrap(float value, float min, float max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
213 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
214 float result = value - (max - min)*floorf((value - min)/(max - min));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
215
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
216 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
217 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
218
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
219 // Check whether two given floats are almost equal
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
220 RMAPI int FloatEquals(float x, float y)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
221 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
222 #if !defined(EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
223 #define EPSILON 0.000001f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
224 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
225
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
226 int result = (fabsf(x - y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(x), fabsf(y))));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
227
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
228 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
229 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
230
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
231 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
232 // Module Functions Definition - Vector2 math
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
233 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
234
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
235 // Vector with components value 0.0f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
236 RMAPI Vector2 Vector2Zero(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
237 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
238 Vector2 result = { 0.0f, 0.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
239
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
240 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
241 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
242
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
243 // Vector with components value 1.0f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
244 RMAPI Vector2 Vector2One(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
245 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
246 Vector2 result = { 1.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
247
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
248 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
249 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
250
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
251 // Add two vectors (v1 + v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
252 RMAPI Vector2 Vector2Add(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
253 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
254 Vector2 result = { v1.x + v2.x, v1.y + v2.y };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
255
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
256 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
257 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
258
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
259 // Add vector and float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
260 RMAPI Vector2 Vector2AddValue(Vector2 v, float add)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
261 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
262 Vector2 result = { v.x + add, v.y + add };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
263
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
264 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
265 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
266
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
267 // Subtract two vectors (v1 - v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
268 RMAPI Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
269 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
270 Vector2 result = { v1.x - v2.x, v1.y - v2.y };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
271
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
272 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
273 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
274
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
275 // Subtract vector by float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
276 RMAPI Vector2 Vector2SubtractValue(Vector2 v, float sub)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
277 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
278 Vector2 result = { v.x - sub, v.y - sub };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
279
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
280 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
281 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
282
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
283 // Calculate vector length
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
284 RMAPI float Vector2Length(Vector2 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
285 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
286 float result = sqrtf((v.x*v.x) + (v.y*v.y));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
287
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
288 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
289 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
290
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
291 // Calculate vector square length
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
292 RMAPI float Vector2LengthSqr(Vector2 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
293 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
294 float result = (v.x*v.x) + (v.y*v.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
295
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
296 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
297 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
298
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
299 // Calculate two vectors dot product
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
300 RMAPI float Vector2DotProduct(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
301 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
302 float result = (v1.x*v2.x + v1.y*v2.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
303
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
304 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
305 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
306
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
307 // Calculate distance between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
308 RMAPI float Vector2Distance(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
309 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
310 float result = sqrtf((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
311
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
312 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
313 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
314
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
315 // Calculate square distance between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
316 RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
317 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
318 float result = ((v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
319
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
320 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
321 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
322
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
323 // Calculate angle between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
324 // NOTE: Angle is calculated from origin point (0, 0)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
325 RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
326 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
327 float result = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
328
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
329 float dot = v1.x*v2.x + v1.y*v2.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
330 float det = v1.x*v2.y - v1.y*v2.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
331
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
332 result = atan2f(det, dot);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
333
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
334 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
335 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
336
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
337 // Calculate angle defined by a two vectors line
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
338 // NOTE: Parameters need to be normalized
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
339 // Current implementation should be aligned with glm::angle
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
340 RMAPI float Vector2LineAngle(Vector2 start, Vector2 end)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
341 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
342 float result = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
343
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
344 // TODO(10/9/2023): Currently angles move clockwise, determine if this is wanted behavior
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
345 result = -atan2f(end.y - start.y, end.x - start.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
346
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
347 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
348 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
349
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
350 // Scale vector (multiply by value)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
351 RMAPI Vector2 Vector2Scale(Vector2 v, float scale)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
352 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
353 Vector2 result = { v.x*scale, v.y*scale };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
354
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
355 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
356 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
357
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
358 // Multiply vector by vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
359 RMAPI Vector2 Vector2Multiply(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
360 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
361 Vector2 result = { v1.x*v2.x, v1.y*v2.y };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
362
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
363 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
364 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
365
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
366 // Negate vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
367 RMAPI Vector2 Vector2Negate(Vector2 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
368 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
369 Vector2 result = { -v.x, -v.y };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
370
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
371 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
372 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
373
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
374 // Divide vector by vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
375 RMAPI Vector2 Vector2Divide(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
376 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
377 Vector2 result = { v1.x/v2.x, v1.y/v2.y };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
378
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
379 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
380 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
381
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
382 // Normalize provided vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
383 RMAPI Vector2 Vector2Normalize(Vector2 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
384 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
385 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
386 float length = sqrtf((v.x*v.x) + (v.y*v.y));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
387
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
388 if (length > 0)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
389 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
390 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
391 result.x = v.x*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
392 result.y = v.y*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
393 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
394
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
395 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
396 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
397
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
398 // Transforms a Vector2 by a given Matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
399 RMAPI Vector2 Vector2Transform(Vector2 v, Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
400 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
401 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
402
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
403 float x = v.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
404 float y = v.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
405 float z = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
406
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
407 result.x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
408 result.y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
409
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
410 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
411 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
412
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
413 // Calculate linear interpolation between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
414 RMAPI Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
415 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
416 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
417
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
418 result.x = v1.x + amount*(v2.x - v1.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
419 result.y = v1.y + amount*(v2.y - v1.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
420
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
421 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
422 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
423
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
424 // Calculate reflected vector to normal
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
425 RMAPI Vector2 Vector2Reflect(Vector2 v, Vector2 normal)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
426 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
427 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
428
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
429 float dotProduct = (v.x*normal.x + v.y*normal.y); // Dot product
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
430
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
431 result.x = v.x - (2.0f*normal.x)*dotProduct;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
432 result.y = v.y - (2.0f*normal.y)*dotProduct;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
433
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
434 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
435 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
436
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
437 // Get min value for each pair of components
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
438 RMAPI Vector2 Vector2Min(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
439 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
440 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
441
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
442 result.x = fminf(v1.x, v2.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
443 result.y = fminf(v1.y, v2.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
444
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
445 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
446 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
447
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
448 // Get max value for each pair of components
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
449 RMAPI Vector2 Vector2Max(Vector2 v1, Vector2 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
450 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
451 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
452
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
453 result.x = fmaxf(v1.x, v2.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
454 result.y = fmaxf(v1.y, v2.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
455
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
456 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
457 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
458
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
459 // Rotate vector by angle
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
460 RMAPI Vector2 Vector2Rotate(Vector2 v, float angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
461 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
462 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
463
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
464 float cosres = cosf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
465 float sinres = sinf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
466
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
467 result.x = v.x*cosres - v.y*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
468 result.y = v.x*sinres + v.y*cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
469
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
470 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
471 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
472
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
473 // Move Vector towards target
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
474 RMAPI Vector2 Vector2MoveTowards(Vector2 v, Vector2 target, float maxDistance)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
475 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
476 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
477
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
478 float dx = target.x - v.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
479 float dy = target.y - v.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
480 float value = (dx*dx) + (dy*dy);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
481
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
482 if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) return target;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
483
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
484 float dist = sqrtf(value);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
485
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
486 result.x = v.x + dx/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
487 result.y = v.y + dy/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
488
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
489 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
490 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
491
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
492 // Invert the given vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
493 RMAPI Vector2 Vector2Invert(Vector2 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
494 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
495 Vector2 result = { 1.0f/v.x, 1.0f/v.y };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
496
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
497 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
498 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
499
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
500 // Clamp the components of the vector between
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
501 // min and max values specified by the given vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
502 RMAPI Vector2 Vector2Clamp(Vector2 v, Vector2 min, Vector2 max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
503 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
504 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
505
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
506 result.x = fminf(max.x, fmaxf(min.x, v.x));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
507 result.y = fminf(max.y, fmaxf(min.y, v.y));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
508
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
509 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
510 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
511
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
512 // Clamp the magnitude of the vector between two min and max values
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
513 RMAPI Vector2 Vector2ClampValue(Vector2 v, float min, float max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
514 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
515 Vector2 result = v;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
516
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
517 float length = (v.x*v.x) + (v.y*v.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
518 if (length > 0.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
519 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
520 length = sqrtf(length);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
521
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
522 float scale = 1; // By default, 1 as the neutral element.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
523 if (length < min)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
524 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
525 scale = min/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
526 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
527 else if (length > max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
528 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
529 scale = max/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
530 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
531
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
532 result.x = v.x*scale;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
533 result.y = v.y*scale;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
534 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
535
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
536 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
537 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
538
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
539 // Check whether two given vectors are almost equal
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
540 RMAPI int Vector2Equals(Vector2 p, Vector2 q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
541 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
542 #if !defined(EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
543 #define EPSILON 0.000001f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
544 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
545
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
546 int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
547 ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y)))));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
548
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
549 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
550 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
551
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
552 // Compute the direction of a refracted ray
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
553 // v: normalized direction of the incoming ray
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
554 // n: normalized normal vector of the interface of two optical media
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
555 // r: ratio of the refractive index of the medium from where the ray comes
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
556 // to the refractive index of the medium on the other side of the surface
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
557 RMAPI Vector2 Vector2Refract(Vector2 v, Vector2 n, float r)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
558 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
559 Vector2 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
560
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
561 float dot = v.x*n.x + v.y*n.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
562 float d = 1.0f - r*r*(1.0f - dot*dot);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
563
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
564 if (d >= 0.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
565 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
566 d = sqrtf(d);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
567 v.x = r*v.x - (r*dot + d)*n.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
568 v.y = r*v.y - (r*dot + d)*n.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
569
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
570 result = v;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
571 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
572
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
573 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
574 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
575
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
576
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
577 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
578 // Module Functions Definition - Vector3 math
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
579 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
580
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
581 // Vector with components value 0.0f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
582 RMAPI Vector3 Vector3Zero(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
583 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
584 Vector3 result = { 0.0f, 0.0f, 0.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
585
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
586 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
587 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
588
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
589 // Vector with components value 1.0f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
590 RMAPI Vector3 Vector3One(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
591 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
592 Vector3 result = { 1.0f, 1.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
593
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
594 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
595 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
596
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
597 // Add two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
598 RMAPI Vector3 Vector3Add(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
599 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
600 Vector3 result = { v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
601
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
602 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
603 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
604
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
605 // Add vector and float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
606 RMAPI Vector3 Vector3AddValue(Vector3 v, float add)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
607 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
608 Vector3 result = { v.x + add, v.y + add, v.z + add };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
609
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
610 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
611 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
612
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
613 // Subtract two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
614 RMAPI Vector3 Vector3Subtract(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
615 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
616 Vector3 result = { v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
617
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
618 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
619 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
620
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
621 // Subtract vector by float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
622 RMAPI Vector3 Vector3SubtractValue(Vector3 v, float sub)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
623 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
624 Vector3 result = { v.x - sub, v.y - sub, v.z - sub };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
625
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
626 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
627 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
628
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
629 // Multiply vector by scalar
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
630 RMAPI Vector3 Vector3Scale(Vector3 v, float scalar)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
631 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
632 Vector3 result = { v.x*scalar, v.y*scalar, v.z*scalar };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
633
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
634 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
635 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
636
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
637 // Multiply vector by vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
638 RMAPI Vector3 Vector3Multiply(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
639 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
640 Vector3 result = { v1.x*v2.x, v1.y*v2.y, v1.z*v2.z };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
641
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
642 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
643 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
644
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
645 // Calculate two vectors cross product
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
646 RMAPI Vector3 Vector3CrossProduct(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
647 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
648 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 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
649
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
650 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
651 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
652
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
653 // Calculate one vector perpendicular vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
654 RMAPI Vector3 Vector3Perpendicular(Vector3 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
655 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
656 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
657
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
658 float min = fabsf(v.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
659 Vector3 cardinalAxis = {1.0f, 0.0f, 0.0f};
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
660
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
661 if (fabsf(v.y) < min)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
662 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
663 min = fabsf(v.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
664 Vector3 tmp = {0.0f, 1.0f, 0.0f};
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
665 cardinalAxis = tmp;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
666 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
667
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
668 if (fabsf(v.z) < min)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
669 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
670 Vector3 tmp = {0.0f, 0.0f, 1.0f};
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
671 cardinalAxis = tmp;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
672 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
673
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
674 // Cross product between vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
675 result.x = v.y*cardinalAxis.z - v.z*cardinalAxis.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
676 result.y = v.z*cardinalAxis.x - v.x*cardinalAxis.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
677 result.z = v.x*cardinalAxis.y - v.y*cardinalAxis.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
678
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
679 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
680 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
681
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
682 // Calculate vector length
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
683 RMAPI float Vector3Length(const Vector3 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
684 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
685 float result = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
686
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
687 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
688 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
689
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
690 // Calculate vector square length
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
691 RMAPI float Vector3LengthSqr(const Vector3 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
692 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
693 float result = v.x*v.x + v.y*v.y + v.z*v.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
694
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
695 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
696 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
697
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
698 // Calculate two vectors dot product
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
699 RMAPI float Vector3DotProduct(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
700 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
701 float result = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
702
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
703 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
704 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
705
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
706 // Calculate distance between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
707 RMAPI float Vector3Distance(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
708 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
709 float result = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
710
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
711 float dx = v2.x - v1.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
712 float dy = v2.y - v1.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
713 float dz = v2.z - v1.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
714 result = sqrtf(dx*dx + dy*dy + dz*dz);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
715
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
716 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
717 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
718
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
719 // Calculate square distance between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
720 RMAPI float Vector3DistanceSqr(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
721 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
722 float result = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
723
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
724 float dx = v2.x - v1.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
725 float dy = v2.y - v1.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
726 float dz = v2.z - v1.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
727 result = dx*dx + dy*dy + dz*dz;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
728
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
729 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
730 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
731
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
732 // Calculate angle between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
733 RMAPI float Vector3Angle(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
734 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
735 float result = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
736
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
737 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 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
738 float len = sqrtf(cross.x*cross.x + cross.y*cross.y + cross.z*cross.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
739 float dot = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
740 result = atan2f(len, dot);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
741
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
742 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
743 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
744
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
745 // Negate provided vector (invert direction)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
746 RMAPI Vector3 Vector3Negate(Vector3 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
747 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
748 Vector3 result = { -v.x, -v.y, -v.z };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
749
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
750 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
751 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
752
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
753 // Divide vector by vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
754 RMAPI Vector3 Vector3Divide(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
755 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
756 Vector3 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
757
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
758 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
759 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
760
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
761 // Normalize provided vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
762 RMAPI Vector3 Vector3Normalize(Vector3 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
763 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
764 Vector3 result = v;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
765
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
766 float length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
767 if (length != 0.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
768 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
769 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
770
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
771 result.x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
772 result.y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
773 result.z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
774 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
775
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
776 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
777 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
778
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
779 //Calculate the projection of the vector v1 on to v2
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
780 RMAPI Vector3 Vector3Project(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
781 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
782 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
783
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
784 float v1dv2 = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
785 float v2dv2 = (v2.x*v2.x + v2.y*v2.y + v2.z*v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
786
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
787 float mag = v1dv2/v2dv2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
788
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
789 result.x = v2.x*mag;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
790 result.y = v2.y*mag;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
791 result.z = v2.z*mag;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
792
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
793 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
794 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
795
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
796 //Calculate the rejection of the vector v1 on to v2
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
797 RMAPI Vector3 Vector3Reject(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
798 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
799 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
800
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
801 float v1dv2 = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
802 float v2dv2 = (v2.x*v2.x + v2.y*v2.y + v2.z*v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
803
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
804 float mag = v1dv2/v2dv2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
805
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
806 result.x = v1.x - (v2.x*mag);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
807 result.y = v1.y - (v2.y*mag);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
808 result.z = v1.z - (v2.z*mag);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
809
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
810 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
811 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
812
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
813 // Orthonormalize provided vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
814 // Makes vectors normalized and orthogonal to each other
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
815 // Gram-Schmidt function implementation
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
816 RMAPI void Vector3OrthoNormalize(Vector3 *v1, Vector3 *v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
817 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
818 float length = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
819 float ilength = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
820
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
821 // Vector3Normalize(*v1);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
822 Vector3 v = *v1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
823 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
824 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
825 ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
826 v1->x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
827 v1->y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
828 v1->z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
829
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
830 // Vector3CrossProduct(*v1, *v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
831 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 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
832
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
833 // Vector3Normalize(vn1);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
834 v = vn1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
835 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
836 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
837 ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
838 vn1.x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
839 vn1.y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
840 vn1.z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
841
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
842 // Vector3CrossProduct(vn1, *v1)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
843 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 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
844
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
845 *v2 = vn2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
846 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
847
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
848 // Transforms a Vector3 by a given Matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
849 RMAPI Vector3 Vector3Transform(Vector3 v, Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
850 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
851 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
852
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
853 float x = v.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
854 float y = v.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
855 float z = v.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
856
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
857 result.x = mat.m0*x + mat.m4*y + mat.m8*z + mat.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
858 result.y = mat.m1*x + mat.m5*y + mat.m9*z + mat.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
859 result.z = mat.m2*x + mat.m6*y + mat.m10*z + mat.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
860
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
861 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
862 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
863
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
864 // Transform a vector by quaternion rotation
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
865 RMAPI Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
866 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
867 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
868
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
869 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);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
870 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);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
871 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);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
872
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
873 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
874 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
875
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
876 // Rotates a vector around an axis
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
877 RMAPI Vector3 Vector3RotateByAxisAngle(Vector3 v, Vector3 axis, float angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
878 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
879 // Using Euler-Rodrigues Formula
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
880 // Ref.: https://en.wikipedia.org/w/index.php?title=Euler%E2%80%93Rodrigues_formula
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
881
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
882 Vector3 result = v;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
883
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
884 // Vector3Normalize(axis);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
885 float length = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
886 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
887 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
888 axis.x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
889 axis.y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
890 axis.z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
891
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
892 angle /= 2.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
893 float a = sinf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
894 float b = axis.x*a;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
895 float c = axis.y*a;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
896 float d = axis.z*a;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
897 a = cosf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
898 Vector3 w = { b, c, d };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
899
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
900 // Vector3CrossProduct(w, v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
901 Vector3 wv = { w.y*v.z - w.z*v.y, w.z*v.x - w.x*v.z, w.x*v.y - w.y*v.x };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
902
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
903 // Vector3CrossProduct(w, wv)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
904 Vector3 wwv = { w.y*wv.z - w.z*wv.y, w.z*wv.x - w.x*wv.z, w.x*wv.y - w.y*wv.x };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
905
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
906 // Vector3Scale(wv, 2*a)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
907 a *= 2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
908 wv.x *= a;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
909 wv.y *= a;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
910 wv.z *= a;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
911
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
912 // Vector3Scale(wwv, 2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
913 wwv.x *= 2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
914 wwv.y *= 2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
915 wwv.z *= 2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
916
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
917 result.x += wv.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
918 result.y += wv.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
919 result.z += wv.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
920
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
921 result.x += wwv.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
922 result.y += wwv.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
923 result.z += wwv.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
924
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
925 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
926 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
927
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
928 // Move Vector towards target
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
929 RMAPI Vector3 Vector3MoveTowards(Vector3 v, Vector3 target, float maxDistance)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
930 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
931 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
932
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
933 float dx = target.x - v.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
934 float dy = target.y - v.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
935 float dz = target.z - v.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
936 float value = (dx*dx) + (dy*dy) + (dz*dz);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
937
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
938 if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) return target;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
939
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
940 float dist = sqrtf(value);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
941
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
942 result.x = v.x + dx/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
943 result.y = v.y + dy/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
944 result.z = v.z + dz/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
945
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
946 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
947 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
948
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
949 // Calculate linear interpolation between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
950 RMAPI Vector3 Vector3Lerp(Vector3 v1, Vector3 v2, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
951 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
952 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
953
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
954 result.x = v1.x + amount*(v2.x - v1.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
955 result.y = v1.y + amount*(v2.y - v1.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
956 result.z = v1.z + amount*(v2.z - v1.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
957
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
958 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
959 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
960
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
961 // Calculate cubic hermite interpolation between two vectors and their tangents
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
962 // as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
963 RMAPI Vector3 Vector3CubicHermite(Vector3 v1, Vector3 tangent1, Vector3 v2, Vector3 tangent2, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
964 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
965 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
966
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
967 float amountPow2 = amount*amount;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
968 float amountPow3 = amount*amount*amount;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
969
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
970 result.x = (2*amountPow3 - 3*amountPow2 + 1)*v1.x + (amountPow3 - 2*amountPow2 + amount)*tangent1.x + (-2*amountPow3 + 3*amountPow2)*v2.x + (amountPow3 - amountPow2)*tangent2.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
971 result.y = (2*amountPow3 - 3*amountPow2 + 1)*v1.y + (amountPow3 - 2*amountPow2 + amount)*tangent1.y + (-2*amountPow3 + 3*amountPow2)*v2.y + (amountPow3 - amountPow2)*tangent2.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
972 result.z = (2*amountPow3 - 3*amountPow2 + 1)*v1.z + (amountPow3 - 2*amountPow2 + amount)*tangent1.z + (-2*amountPow3 + 3*amountPow2)*v2.z + (amountPow3 - amountPow2)*tangent2.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
973
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
974 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
975 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
976
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
977 // Calculate reflected vector to normal
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
978 RMAPI Vector3 Vector3Reflect(Vector3 v, Vector3 normal)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
979 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
980 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
981
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
982 // I is the original vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
983 // N is the normal of the incident plane
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
984 // R = I - (2*N*(DotProduct[I, N]))
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
985
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
986 float dotProduct = (v.x*normal.x + v.y*normal.y + v.z*normal.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
987
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
988 result.x = v.x - (2.0f*normal.x)*dotProduct;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
989 result.y = v.y - (2.0f*normal.y)*dotProduct;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
990 result.z = v.z - (2.0f*normal.z)*dotProduct;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
991
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
992 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
993 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
994
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
995 // Get min value for each pair of components
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
996 RMAPI Vector3 Vector3Min(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
997 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
998 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
999
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1000 result.x = fminf(v1.x, v2.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1001 result.y = fminf(v1.y, v2.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1002 result.z = fminf(v1.z, v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1003
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1004 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1005 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1006
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1007 // Get max value for each pair of components
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1008 RMAPI Vector3 Vector3Max(Vector3 v1, Vector3 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1009 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1010 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1011
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1012 result.x = fmaxf(v1.x, v2.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1013 result.y = fmaxf(v1.y, v2.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1014 result.z = fmaxf(v1.z, v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1015
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1016 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1017 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1018
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1019 // Compute barycenter coordinates (u, v, w) for point p with respect to triangle (a, b, c)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1020 // NOTE: Assumes P is on the plane of the triangle
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1021 RMAPI Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1022 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1023 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1024
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1025 Vector3 v0 = { b.x - a.x, b.y - a.y, b.z - a.z }; // Vector3Subtract(b, a)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1026 Vector3 v1 = { c.x - a.x, c.y - a.y, c.z - a.z }; // Vector3Subtract(c, a)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1027 Vector3 v2 = { p.x - a.x, p.y - a.y, p.z - a.z }; // Vector3Subtract(p, a)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1028 float d00 = (v0.x*v0.x + v0.y*v0.y + v0.z*v0.z); // Vector3DotProduct(v0, v0)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1029 float d01 = (v0.x*v1.x + v0.y*v1.y + v0.z*v1.z); // Vector3DotProduct(v0, v1)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1030 float d11 = (v1.x*v1.x + v1.y*v1.y + v1.z*v1.z); // Vector3DotProduct(v1, v1)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1031 float d20 = (v2.x*v0.x + v2.y*v0.y + v2.z*v0.z); // Vector3DotProduct(v2, v0)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1032 float d21 = (v2.x*v1.x + v2.y*v1.y + v2.z*v1.z); // Vector3DotProduct(v2, v1)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1033
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1034 float denom = d00*d11 - d01*d01;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1035
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1036 result.y = (d11*d20 - d01*d21)/denom;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1037 result.z = (d00*d21 - d01*d20)/denom;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1038 result.x = 1.0f - (result.z + result.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1039
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1040 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1041 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1042
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1043 // Projects a Vector3 from screen space into object space
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1044 // NOTE: We are avoiding calling other raymath functions despite available
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1045 RMAPI Vector3 Vector3Unproject(Vector3 source, Matrix projection, Matrix view)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1046 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1047 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1048
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1049 // Calculate unprojected matrix (multiply view matrix by projection matrix) and invert it
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1050 Matrix matViewProj = { // MatrixMultiply(view, projection);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1051 view.m0*projection.m0 + view.m1*projection.m4 + view.m2*projection.m8 + view.m3*projection.m12,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1052 view.m0*projection.m1 + view.m1*projection.m5 + view.m2*projection.m9 + view.m3*projection.m13,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1053 view.m0*projection.m2 + view.m1*projection.m6 + view.m2*projection.m10 + view.m3*projection.m14,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1054 view.m0*projection.m3 + view.m1*projection.m7 + view.m2*projection.m11 + view.m3*projection.m15,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1055 view.m4*projection.m0 + view.m5*projection.m4 + view.m6*projection.m8 + view.m7*projection.m12,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1056 view.m4*projection.m1 + view.m5*projection.m5 + view.m6*projection.m9 + view.m7*projection.m13,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1057 view.m4*projection.m2 + view.m5*projection.m6 + view.m6*projection.m10 + view.m7*projection.m14,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1058 view.m4*projection.m3 + view.m5*projection.m7 + view.m6*projection.m11 + view.m7*projection.m15,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1059 view.m8*projection.m0 + view.m9*projection.m4 + view.m10*projection.m8 + view.m11*projection.m12,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1060 view.m8*projection.m1 + view.m9*projection.m5 + view.m10*projection.m9 + view.m11*projection.m13,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1061 view.m8*projection.m2 + view.m9*projection.m6 + view.m10*projection.m10 + view.m11*projection.m14,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1062 view.m8*projection.m3 + view.m9*projection.m7 + view.m10*projection.m11 + view.m11*projection.m15,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1063 view.m12*projection.m0 + view.m13*projection.m4 + view.m14*projection.m8 + view.m15*projection.m12,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1064 view.m12*projection.m1 + view.m13*projection.m5 + view.m14*projection.m9 + view.m15*projection.m13,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1065 view.m12*projection.m2 + view.m13*projection.m6 + view.m14*projection.m10 + view.m15*projection.m14,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1066 view.m12*projection.m3 + view.m13*projection.m7 + view.m14*projection.m11 + view.m15*projection.m15 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1067
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1068 // Calculate inverted matrix -> MatrixInvert(matViewProj);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1069 // Cache the matrix values (speed optimization)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1070 float a00 = matViewProj.m0, a01 = matViewProj.m1, a02 = matViewProj.m2, a03 = matViewProj.m3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1071 float a10 = matViewProj.m4, a11 = matViewProj.m5, a12 = matViewProj.m6, a13 = matViewProj.m7;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1072 float a20 = matViewProj.m8, a21 = matViewProj.m9, a22 = matViewProj.m10, a23 = matViewProj.m11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1073 float a30 = matViewProj.m12, a31 = matViewProj.m13, a32 = matViewProj.m14, a33 = matViewProj.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1074
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1075 float b00 = a00*a11 - a01*a10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1076 float b01 = a00*a12 - a02*a10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1077 float b02 = a00*a13 - a03*a10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1078 float b03 = a01*a12 - a02*a11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1079 float b04 = a01*a13 - a03*a11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1080 float b05 = a02*a13 - a03*a12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1081 float b06 = a20*a31 - a21*a30;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1082 float b07 = a20*a32 - a22*a30;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1083 float b08 = a20*a33 - a23*a30;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1084 float b09 = a21*a32 - a22*a31;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1085 float b10 = a21*a33 - a23*a31;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1086 float b11 = a22*a33 - a23*a32;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1087
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1088 // Calculate the invert determinant (inlined to avoid double-caching)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1089 float invDet = 1.0f/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1090
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1091 Matrix matViewProjInv = {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1092 (a11*b11 - a12*b10 + a13*b09)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1093 (-a01*b11 + a02*b10 - a03*b09)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1094 (a31*b05 - a32*b04 + a33*b03)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1095 (-a21*b05 + a22*b04 - a23*b03)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1096 (-a10*b11 + a12*b08 - a13*b07)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1097 (a00*b11 - a02*b08 + a03*b07)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1098 (-a30*b05 + a32*b02 - a33*b01)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1099 (a20*b05 - a22*b02 + a23*b01)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1100 (a10*b10 - a11*b08 + a13*b06)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1101 (-a00*b10 + a01*b08 - a03*b06)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1102 (a30*b04 - a31*b02 + a33*b00)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1103 (-a20*b04 + a21*b02 - a23*b00)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1104 (-a10*b09 + a11*b07 - a12*b06)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1105 (a00*b09 - a01*b07 + a02*b06)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1106 (-a30*b03 + a31*b01 - a32*b00)*invDet,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1107 (a20*b03 - a21*b01 + a22*b00)*invDet };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1108
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1109 // Create quaternion from source point
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1110 Quaternion quat = { source.x, source.y, source.z, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1111
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1112 // Multiply quat point by unprojecte matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1113 Quaternion qtransformed = { // QuaternionTransform(quat, matViewProjInv)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1114 matViewProjInv.m0*quat.x + matViewProjInv.m4*quat.y + matViewProjInv.m8*quat.z + matViewProjInv.m12*quat.w,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1115 matViewProjInv.m1*quat.x + matViewProjInv.m5*quat.y + matViewProjInv.m9*quat.z + matViewProjInv.m13*quat.w,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1116 matViewProjInv.m2*quat.x + matViewProjInv.m6*quat.y + matViewProjInv.m10*quat.z + matViewProjInv.m14*quat.w,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1117 matViewProjInv.m3*quat.x + matViewProjInv.m7*quat.y + matViewProjInv.m11*quat.z + matViewProjInv.m15*quat.w };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1118
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1119 // Normalized world points in vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1120 result.x = qtransformed.x/qtransformed.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1121 result.y = qtransformed.y/qtransformed.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1122 result.z = qtransformed.z/qtransformed.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1123
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1124 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1125 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1126
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1127 // Get Vector3 as float array
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1128 RMAPI float3 Vector3ToFloatV(Vector3 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1129 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1130 float3 buffer = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1131
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1132 buffer.v[0] = v.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1133 buffer.v[1] = v.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1134 buffer.v[2] = v.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1135
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1136 return buffer;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1137 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1138
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1139 // Invert the given vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1140 RMAPI Vector3 Vector3Invert(Vector3 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1141 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1142 Vector3 result = { 1.0f/v.x, 1.0f/v.y, 1.0f/v.z };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1143
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1144 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1145 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1146
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1147 // Clamp the components of the vector between
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1148 // min and max values specified by the given vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1149 RMAPI Vector3 Vector3Clamp(Vector3 v, Vector3 min, Vector3 max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1150 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1151 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1152
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1153 result.x = fminf(max.x, fmaxf(min.x, v.x));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1154 result.y = fminf(max.y, fmaxf(min.y, v.y));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1155 result.z = fminf(max.z, fmaxf(min.z, v.z));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1156
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1157 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1158 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1159
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1160 // Clamp the magnitude of the vector between two values
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1161 RMAPI Vector3 Vector3ClampValue(Vector3 v, float min, float max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1162 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1163 Vector3 result = v;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1164
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1165 float length = (v.x*v.x) + (v.y*v.y) + (v.z*v.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1166 if (length > 0.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1167 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1168 length = sqrtf(length);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1169
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1170 float scale = 1; // By default, 1 as the neutral element.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1171 if (length < min)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1172 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1173 scale = min/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1174 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1175 else if (length > max)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1176 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1177 scale = max/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1178 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1179
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1180 result.x = v.x*scale;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1181 result.y = v.y*scale;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1182 result.z = v.z*scale;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1183 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1184
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1185 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1186 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1187
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1188 // Check whether two given vectors are almost equal
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1189 RMAPI int Vector3Equals(Vector3 p, Vector3 q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1190 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1191 #if !defined(EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1192 #define EPSILON 0.000001f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1193 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1194
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1195 int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1196 ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1197 ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z)))));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1198
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1199 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1200 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1201
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1202 // Compute the direction of a refracted ray
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1203 // v: normalized direction of the incoming ray
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1204 // n: normalized normal vector of the interface of two optical media
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1205 // r: ratio of the refractive index of the medium from where the ray comes
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1206 // to the refractive index of the medium on the other side of the surface
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1207 RMAPI Vector3 Vector3Refract(Vector3 v, Vector3 n, float r)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1208 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1209 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1210
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1211 float dot = v.x*n.x + v.y*n.y + v.z*n.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1212 float d = 1.0f - r*r*(1.0f - dot*dot);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1213
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1214 if (d >= 0.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1215 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1216 d = sqrtf(d);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1217 v.x = r*v.x - (r*dot + d)*n.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1218 v.y = r*v.y - (r*dot + d)*n.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1219 v.z = r*v.z - (r*dot + d)*n.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1220
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1221 result = v;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1222 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1223
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1224 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1225 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1226
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1227
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1228 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1229 // Module Functions Definition - Vector4 math
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1230 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1231
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1232 RMAPI Vector4 Vector4Zero(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1233 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1234 Vector4 result = { 0.0f, 0.0f, 0.0f, 0.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1235 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1236 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1237
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1238 RMAPI Vector4 Vector4One(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1239 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1240 Vector4 result = { 1.0f, 1.0f, 1.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1241 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1242 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1243
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1244 RMAPI Vector4 Vector4Add(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1245 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1246 Vector4 result = {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1247 v1.x + v2.x,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1248 v1.y + v2.y,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1249 v1.z + v2.z,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1250 v1.w + v2.w
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1251 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1252 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1253 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1254
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1255 RMAPI Vector4 Vector4AddValue(Vector4 v, float add)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1256 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1257 Vector4 result = {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1258 v.x + add,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1259 v.y + add,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1260 v.z + add,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1261 v.w + add
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1262 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1263 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1264 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1265
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1266 RMAPI Vector4 Vector4Subtract(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1267 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1268 Vector4 result = {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1269 v1.x - v2.x,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1270 v1.y - v2.y,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1271 v1.z - v2.z,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1272 v1.w - v2.w
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1273 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1274 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1275 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1276
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1277 RMAPI Vector4 Vector4SubtractValue(Vector4 v, float add)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1278 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1279 Vector4 result = {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1280 v.x - add,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1281 v.y - add,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1282 v.z - add,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1283 v.w - add
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1284 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1285 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1286 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1287
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1288 RMAPI float Vector4Length(Vector4 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1289 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1290 float result = sqrtf((v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1291 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1292 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1293
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1294 RMAPI float Vector4LengthSqr(Vector4 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1295 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1296 float result = (v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1297 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1298 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1299
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1300 RMAPI float Vector4DotProduct(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1301 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1302 float result = (v1.x*v2.x + v1.y*v2.y + v1.z*v2.z + v1.w*v2.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1303 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1304 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1305
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1306 // Calculate distance between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1307 RMAPI float Vector4Distance(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1308 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1309 float result = sqrtf(
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1310 (v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y) +
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1311 (v1.z - v2.z)*(v1.z - v2.z) + (v1.w - v2.w)*(v1.w - v2.w));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1312 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1313 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1314
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1315 // Calculate square distance between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1316 RMAPI float Vector4DistanceSqr(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1317 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1318 float result =
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1319 (v1.x - v2.x)*(v1.x - v2.x) + (v1.y - v2.y)*(v1.y - v2.y) +
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1320 (v1.z - v2.z)*(v1.z - v2.z) + (v1.w - v2.w)*(v1.w - v2.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1321
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1322 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1323 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1324
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1325 RMAPI Vector4 Vector4Scale(Vector4 v, float scale)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1326 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1327 Vector4 result = { v.x*scale, v.y*scale, v.z*scale, v.w*scale };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1328 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1329 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1330
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1331 // Multiply vector by vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1332 RMAPI Vector4 Vector4Multiply(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1333 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1334 Vector4 result = { v1.x*v2.x, v1.y*v2.y, v1.z*v2.z, v1.w*v2.w };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1335 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1336 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1337
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1338 // Negate vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1339 RMAPI Vector4 Vector4Negate(Vector4 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1340 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1341 Vector4 result = { -v.x, -v.y, -v.z, -v.w };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1342 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1343 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1344
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1345 // Divide vector by vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1346 RMAPI Vector4 Vector4Divide(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1347 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1348 Vector4 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z, v1.w/v2.w };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1349 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1350 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1351
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1352 // Normalize provided vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1353 RMAPI Vector4 Vector4Normalize(Vector4 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1354 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1355 Vector4 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1356 float length = sqrtf((v.x*v.x) + (v.y*v.y) + (v.z*v.z) + (v.w*v.w));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1357
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1358 if (length > 0)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1359 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1360 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1361 result.x = v.x*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1362 result.y = v.y*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1363 result.z = v.z*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1364 result.w = v.w*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1365 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1366
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1367 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1368 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1369
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1370 // Get min value for each pair of components
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1371 RMAPI Vector4 Vector4Min(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1372 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1373 Vector4 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1374
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1375 result.x = fminf(v1.x, v2.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1376 result.y = fminf(v1.y, v2.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1377 result.z = fminf(v1.z, v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1378 result.w = fminf(v1.w, v2.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1379
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1380 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1381 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1382
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1383 // Get max value for each pair of components
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1384 RMAPI Vector4 Vector4Max(Vector4 v1, Vector4 v2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1385 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1386 Vector4 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1387
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1388 result.x = fmaxf(v1.x, v2.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1389 result.y = fmaxf(v1.y, v2.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1390 result.z = fmaxf(v1.z, v2.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1391 result.w = fmaxf(v1.w, v2.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1392
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1393 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1394 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1395
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1396 // Calculate linear interpolation between two vectors
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1397 RMAPI Vector4 Vector4Lerp(Vector4 v1, Vector4 v2, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1398 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1399 Vector4 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1400
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1401 result.x = v1.x + amount*(v2.x - v1.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1402 result.y = v1.y + amount*(v2.y - v1.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1403 result.z = v1.z + amount*(v2.z - v1.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1404 result.w = v1.w + amount*(v2.w - v1.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1405
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1406 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1407 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1408
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1409 // Move Vector towards target
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1410 RMAPI Vector4 Vector4MoveTowards(Vector4 v, Vector4 target, float maxDistance)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1411 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1412 Vector4 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1413
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1414 float dx = target.x - v.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1415 float dy = target.y - v.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1416 float dz = target.z - v.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1417 float dw = target.w - v.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1418 float value = (dx*dx) + (dy*dy) + (dz*dz) + (dw*dw);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1419
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1420 if ((value == 0) || ((maxDistance >= 0) && (value <= maxDistance*maxDistance))) return target;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1421
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1422 float dist = sqrtf(value);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1423
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1424 result.x = v.x + dx/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1425 result.y = v.y + dy/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1426 result.z = v.z + dz/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1427 result.w = v.w + dw/dist*maxDistance;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1428
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1429 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1430 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1431
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1432 // Invert the given vector
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1433 RMAPI Vector4 Vector4Invert(Vector4 v)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1434 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1435 Vector4 result = { 1.0f/v.x, 1.0f/v.y, 1.0f/v.z, 1.0f/v.w };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1436 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1437 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1438
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1439 // Check whether two given vectors are almost equal
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1440 RMAPI int Vector4Equals(Vector4 p, Vector4 q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1441 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1442 #if !defined(EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1443 #define EPSILON 0.000001f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1444 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1445
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1446 int result = ((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1447 ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1448 ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1449 ((fabsf(p.w - q.w)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.w), fabsf(q.w)))));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1450 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1451 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1452
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1453
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1454 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1455 // Module Functions Definition - Matrix math
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1456 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1457
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1458 // Compute matrix determinant
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1459 RMAPI float MatrixDeterminant(Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1460 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1461 float result = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1462
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1463 // Cache the matrix values (speed optimization)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1464 float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1465 float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1466 float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1467 float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1468
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1469 result = a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1470 a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1471 a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1472 a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1473 a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1474 a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1475
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1476 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1477 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1478
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1479 // Get the trace of the matrix (sum of the values along the diagonal)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1480 RMAPI float MatrixTrace(Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1481 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1482 float result = (mat.m0 + mat.m5 + mat.m10 + mat.m15);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1483
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1484 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1485 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1486
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1487 // Transposes provided matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1488 RMAPI Matrix MatrixTranspose(Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1489 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1490 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1491
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1492 result.m0 = mat.m0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1493 result.m1 = mat.m4;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1494 result.m2 = mat.m8;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1495 result.m3 = mat.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1496 result.m4 = mat.m1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1497 result.m5 = mat.m5;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1498 result.m6 = mat.m9;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1499 result.m7 = mat.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1500 result.m8 = mat.m2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1501 result.m9 = mat.m6;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1502 result.m10 = mat.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1503 result.m11 = mat.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1504 result.m12 = mat.m3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1505 result.m13 = mat.m7;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1506 result.m14 = mat.m11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1507 result.m15 = mat.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1508
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1509 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1510 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1511
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1512 // Invert provided matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1513 RMAPI Matrix MatrixInvert(Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1514 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1515 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1516
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1517 // Cache the matrix values (speed optimization)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1518 float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1519 float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1520 float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1521 float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1522
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1523 float b00 = a00*a11 - a01*a10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1524 float b01 = a00*a12 - a02*a10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1525 float b02 = a00*a13 - a03*a10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1526 float b03 = a01*a12 - a02*a11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1527 float b04 = a01*a13 - a03*a11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1528 float b05 = a02*a13 - a03*a12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1529 float b06 = a20*a31 - a21*a30;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1530 float b07 = a20*a32 - a22*a30;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1531 float b08 = a20*a33 - a23*a30;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1532 float b09 = a21*a32 - a22*a31;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1533 float b10 = a21*a33 - a23*a31;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1534 float b11 = a22*a33 - a23*a32;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1535
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1536 // Calculate the invert determinant (inlined to avoid double-caching)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1537 float invDet = 1.0f/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1538
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1539 result.m0 = (a11*b11 - a12*b10 + a13*b09)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1540 result.m1 = (-a01*b11 + a02*b10 - a03*b09)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1541 result.m2 = (a31*b05 - a32*b04 + a33*b03)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1542 result.m3 = (-a21*b05 + a22*b04 - a23*b03)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1543 result.m4 = (-a10*b11 + a12*b08 - a13*b07)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1544 result.m5 = (a00*b11 - a02*b08 + a03*b07)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1545 result.m6 = (-a30*b05 + a32*b02 - a33*b01)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1546 result.m7 = (a20*b05 - a22*b02 + a23*b01)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1547 result.m8 = (a10*b10 - a11*b08 + a13*b06)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1548 result.m9 = (-a00*b10 + a01*b08 - a03*b06)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1549 result.m10 = (a30*b04 - a31*b02 + a33*b00)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1550 result.m11 = (-a20*b04 + a21*b02 - a23*b00)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1551 result.m12 = (-a10*b09 + a11*b07 - a12*b06)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1552 result.m13 = (a00*b09 - a01*b07 + a02*b06)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1553 result.m14 = (-a30*b03 + a31*b01 - a32*b00)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1554 result.m15 = (a20*b03 - a21*b01 + a22*b00)*invDet;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1555
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1556 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1557 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1558
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1559 // Get identity matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1560 RMAPI Matrix MatrixIdentity(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1561 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1562 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1563 0.0f, 1.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1564 0.0f, 0.0f, 1.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1565 0.0f, 0.0f, 0.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1566
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1567 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1568 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1569
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1570 // Add two matrices
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1571 RMAPI Matrix MatrixAdd(Matrix left, Matrix right)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1572 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1573 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1574
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1575 result.m0 = left.m0 + right.m0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1576 result.m1 = left.m1 + right.m1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1577 result.m2 = left.m2 + right.m2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1578 result.m3 = left.m3 + right.m3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1579 result.m4 = left.m4 + right.m4;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1580 result.m5 = left.m5 + right.m5;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1581 result.m6 = left.m6 + right.m6;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1582 result.m7 = left.m7 + right.m7;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1583 result.m8 = left.m8 + right.m8;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1584 result.m9 = left.m9 + right.m9;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1585 result.m10 = left.m10 + right.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1586 result.m11 = left.m11 + right.m11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1587 result.m12 = left.m12 + right.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1588 result.m13 = left.m13 + right.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1589 result.m14 = left.m14 + right.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1590 result.m15 = left.m15 + right.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1591
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1592 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1593 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1594
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1595 // Subtract two matrices (left - right)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1596 RMAPI Matrix MatrixSubtract(Matrix left, Matrix right)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1597 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1598 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1599
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1600 result.m0 = left.m0 - right.m0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1601 result.m1 = left.m1 - right.m1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1602 result.m2 = left.m2 - right.m2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1603 result.m3 = left.m3 - right.m3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1604 result.m4 = left.m4 - right.m4;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1605 result.m5 = left.m5 - right.m5;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1606 result.m6 = left.m6 - right.m6;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1607 result.m7 = left.m7 - right.m7;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1608 result.m8 = left.m8 - right.m8;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1609 result.m9 = left.m9 - right.m9;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1610 result.m10 = left.m10 - right.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1611 result.m11 = left.m11 - right.m11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1612 result.m12 = left.m12 - right.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1613 result.m13 = left.m13 - right.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1614 result.m14 = left.m14 - right.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1615 result.m15 = left.m15 - right.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1616
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1617 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1618 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1619
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1620 // Get two matrix multiplication
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1621 // NOTE: When multiplying matrices... the order matters!
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1622 RMAPI Matrix MatrixMultiply(Matrix left, Matrix right)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1623 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1624 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1625
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1626 result.m0 = left.m0*right.m0 + left.m1*right.m4 + left.m2*right.m8 + left.m3*right.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1627 result.m1 = left.m0*right.m1 + left.m1*right.m5 + left.m2*right.m9 + left.m3*right.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1628 result.m2 = left.m0*right.m2 + left.m1*right.m6 + left.m2*right.m10 + left.m3*right.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1629 result.m3 = left.m0*right.m3 + left.m1*right.m7 + left.m2*right.m11 + left.m3*right.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1630 result.m4 = left.m4*right.m0 + left.m5*right.m4 + left.m6*right.m8 + left.m7*right.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1631 result.m5 = left.m4*right.m1 + left.m5*right.m5 + left.m6*right.m9 + left.m7*right.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1632 result.m6 = left.m4*right.m2 + left.m5*right.m6 + left.m6*right.m10 + left.m7*right.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1633 result.m7 = left.m4*right.m3 + left.m5*right.m7 + left.m6*right.m11 + left.m7*right.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1634 result.m8 = left.m8*right.m0 + left.m9*right.m4 + left.m10*right.m8 + left.m11*right.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1635 result.m9 = left.m8*right.m1 + left.m9*right.m5 + left.m10*right.m9 + left.m11*right.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1636 result.m10 = left.m8*right.m2 + left.m9*right.m6 + left.m10*right.m10 + left.m11*right.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1637 result.m11 = left.m8*right.m3 + left.m9*right.m7 + left.m10*right.m11 + left.m11*right.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1638 result.m12 = left.m12*right.m0 + left.m13*right.m4 + left.m14*right.m8 + left.m15*right.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1639 result.m13 = left.m12*right.m1 + left.m13*right.m5 + left.m14*right.m9 + left.m15*right.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1640 result.m14 = left.m12*right.m2 + left.m13*right.m6 + left.m14*right.m10 + left.m15*right.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1641 result.m15 = left.m12*right.m3 + left.m13*right.m7 + left.m14*right.m11 + left.m15*right.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1642
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1643 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1644 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1645
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1646 // Get translation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1647 RMAPI Matrix MatrixTranslate(float x, float y, float z)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1648 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1649 Matrix result = { 1.0f, 0.0f, 0.0f, x,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1650 0.0f, 1.0f, 0.0f, y,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1651 0.0f, 0.0f, 1.0f, z,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1652 0.0f, 0.0f, 0.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1653
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1654 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1655 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1656
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1657 // Create rotation matrix from axis and angle
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1658 // NOTE: Angle should be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1659 RMAPI Matrix MatrixRotate(Vector3 axis, float angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1660 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1661 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1662
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1663 float x = axis.x, y = axis.y, z = axis.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1664
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1665 float lengthSquared = x*x + y*y + z*z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1666
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1667 if ((lengthSquared != 1.0f) && (lengthSquared != 0.0f))
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1668 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1669 float ilength = 1.0f/sqrtf(lengthSquared);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1670 x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1671 y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1672 z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1673 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1674
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1675 float sinres = sinf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1676 float cosres = cosf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1677 float t = 1.0f - cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1678
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1679 result.m0 = x*x*t + cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1680 result.m1 = y*x*t + z*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1681 result.m2 = z*x*t - y*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1682 result.m3 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1683
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1684 result.m4 = x*y*t - z*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1685 result.m5 = y*y*t + cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1686 result.m6 = z*y*t + x*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1687 result.m7 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1688
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1689 result.m8 = x*z*t + y*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1690 result.m9 = y*z*t - x*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1691 result.m10 = z*z*t + cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1692 result.m11 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1693
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1694 result.m12 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1695 result.m13 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1696 result.m14 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1697 result.m15 = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1698
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1699 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1700 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1701
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1702 // Get x-rotation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1703 // NOTE: Angle must be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1704 RMAPI Matrix MatrixRotateX(float angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1705 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1706 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1707 0.0f, 1.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1708 0.0f, 0.0f, 1.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1709 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1710
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1711 float cosres = cosf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1712 float sinres = sinf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1713
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1714 result.m5 = cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1715 result.m6 = sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1716 result.m9 = -sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1717 result.m10 = cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1718
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1719 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1720 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1721
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1722 // Get y-rotation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1723 // NOTE: Angle must be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1724 RMAPI Matrix MatrixRotateY(float angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1725 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1726 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1727 0.0f, 1.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1728 0.0f, 0.0f, 1.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1729 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1730
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1731 float cosres = cosf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1732 float sinres = sinf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1733
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1734 result.m0 = cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1735 result.m2 = -sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1736 result.m8 = sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1737 result.m10 = cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1738
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1739 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1740 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1741
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1742 // Get z-rotation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1743 // NOTE: Angle must be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1744 RMAPI Matrix MatrixRotateZ(float angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1745 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1746 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1747 0.0f, 1.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1748 0.0f, 0.0f, 1.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1749 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1750
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1751 float cosres = cosf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1752 float sinres = sinf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1753
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1754 result.m0 = cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1755 result.m1 = sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1756 result.m4 = -sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1757 result.m5 = cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1758
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1759 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1760 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1761
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1762
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1763 // Get xyz-rotation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1764 // NOTE: Angle must be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1765 RMAPI Matrix MatrixRotateXYZ(Vector3 angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1766 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1767 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1768 0.0f, 1.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1769 0.0f, 0.0f, 1.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1770 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1771
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1772 float cosz = cosf(-angle.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1773 float sinz = sinf(-angle.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1774 float cosy = cosf(-angle.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1775 float siny = sinf(-angle.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1776 float cosx = cosf(-angle.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1777 float sinx = sinf(-angle.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1778
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1779 result.m0 = cosz*cosy;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1780 result.m1 = (cosz*siny*sinx) - (sinz*cosx);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1781 result.m2 = (cosz*siny*cosx) + (sinz*sinx);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1782
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1783 result.m4 = sinz*cosy;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1784 result.m5 = (sinz*siny*sinx) + (cosz*cosx);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1785 result.m6 = (sinz*siny*cosx) - (cosz*sinx);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1786
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1787 result.m8 = -siny;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1788 result.m9 = cosy*sinx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1789 result.m10= cosy*cosx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1790
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1791 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1792 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1793
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1794 // Get zyx-rotation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1795 // NOTE: Angle must be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1796 RMAPI Matrix MatrixRotateZYX(Vector3 angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1797 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1798 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1799
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1800 float cz = cosf(angle.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1801 float sz = sinf(angle.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1802 float cy = cosf(angle.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1803 float sy = sinf(angle.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1804 float cx = cosf(angle.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1805 float sx = sinf(angle.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1806
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1807 result.m0 = cz*cy;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1808 result.m4 = cz*sy*sx - cx*sz;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1809 result.m8 = sz*sx + cz*cx*sy;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1810 result.m12 = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1811
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1812 result.m1 = cy*sz;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1813 result.m5 = cz*cx + sz*sy*sx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1814 result.m9 = cx*sz*sy - cz*sx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1815 result.m13 = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1816
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1817 result.m2 = -sy;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1818 result.m6 = cy*sx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1819 result.m10 = cy*cx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1820 result.m14 = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1821
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1822 result.m3 = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1823 result.m7 = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1824 result.m11 = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1825 result.m15 = 1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1826
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1827 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1828 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1829
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1830 // Get scaling matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1831 RMAPI Matrix MatrixScale(float x, float y, float z)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1832 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1833 Matrix result = { x, 0.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1834 0.0f, y, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1835 0.0f, 0.0f, z, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1836 0.0f, 0.0f, 0.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1837
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1838 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1839 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1840
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1841 // Get perspective projection matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1842 RMAPI Matrix MatrixFrustum(double left, double right, double bottom, double top, double nearPlane, double farPlane)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1843 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1844 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1845
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1846 float rl = (float)(right - left);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1847 float tb = (float)(top - bottom);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1848 float fn = (float)(farPlane - nearPlane);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1849
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1850 result.m0 = ((float)nearPlane*2.0f)/rl;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1851 result.m1 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1852 result.m2 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1853 result.m3 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1854
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1855 result.m4 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1856 result.m5 = ((float)nearPlane*2.0f)/tb;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1857 result.m6 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1858 result.m7 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1859
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1860 result.m8 = ((float)right + (float)left)/rl;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1861 result.m9 = ((float)top + (float)bottom)/tb;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1862 result.m10 = -((float)farPlane + (float)nearPlane)/fn;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1863 result.m11 = -1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1864
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1865 result.m12 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1866 result.m13 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1867 result.m14 = -((float)farPlane*(float)nearPlane*2.0f)/fn;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1868 result.m15 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1869
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1870 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1871 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1872
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1873 // Get perspective projection matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1874 // NOTE: Fovy angle must be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1875 RMAPI Matrix MatrixPerspective(double fovY, double aspect, double nearPlane, double farPlane)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1876 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1877 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1878
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1879 double top = nearPlane*tan(fovY*0.5);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1880 double bottom = -top;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1881 double right = top*aspect;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1882 double left = -right;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1883
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1884 // MatrixFrustum(-right, right, -top, top, near, far);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1885 float rl = (float)(right - left);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1886 float tb = (float)(top - bottom);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1887 float fn = (float)(farPlane - nearPlane);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1888
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1889 result.m0 = ((float)nearPlane*2.0f)/rl;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1890 result.m5 = ((float)nearPlane*2.0f)/tb;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1891 result.m8 = ((float)right + (float)left)/rl;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1892 result.m9 = ((float)top + (float)bottom)/tb;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1893 result.m10 = -((float)farPlane + (float)nearPlane)/fn;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1894 result.m11 = -1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1895 result.m14 = -((float)farPlane*(float)nearPlane*2.0f)/fn;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1896
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1897 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1898 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1899
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1900 // Get orthographic projection matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1901 RMAPI Matrix MatrixOrtho(double left, double right, double bottom, double top, double nearPlane, double farPlane)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1902 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1903 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1904
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1905 float rl = (float)(right - left);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1906 float tb = (float)(top - bottom);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1907 float fn = (float)(farPlane - nearPlane);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1908
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1909 result.m0 = 2.0f/rl;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1910 result.m1 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1911 result.m2 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1912 result.m3 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1913 result.m4 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1914 result.m5 = 2.0f/tb;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1915 result.m6 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1916 result.m7 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1917 result.m8 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1918 result.m9 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1919 result.m10 = -2.0f/fn;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1920 result.m11 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1921 result.m12 = -((float)left + (float)right)/rl;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1922 result.m13 = -((float)top + (float)bottom)/tb;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1923 result.m14 = -((float)farPlane + (float)nearPlane)/fn;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1924 result.m15 = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1925
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1926 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1927 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1928
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1929 // Get camera look-at matrix (view matrix)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1930 RMAPI Matrix MatrixLookAt(Vector3 eye, Vector3 target, Vector3 up)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1931 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1932 Matrix result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1933
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1934 float length = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1935 float ilength = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1936
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1937 // Vector3Subtract(eye, target)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1938 Vector3 vz = { eye.x - target.x, eye.y - target.y, eye.z - target.z };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1939
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1940 // Vector3Normalize(vz)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1941 Vector3 v = vz;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1942 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1943 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1944 ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1945 vz.x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1946 vz.y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1947 vz.z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1948
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1949 // Vector3CrossProduct(up, vz)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1950 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 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1951
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1952 // Vector3Normalize(x)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1953 v = vx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1954 length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1955 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1956 ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1957 vx.x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1958 vx.y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1959 vx.z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1960
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1961 // Vector3CrossProduct(vz, vx)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1962 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 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1963
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1964 result.m0 = vx.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1965 result.m1 = vy.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1966 result.m2 = vz.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1967 result.m3 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1968 result.m4 = vx.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1969 result.m5 = vy.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1970 result.m6 = vz.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1971 result.m7 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1972 result.m8 = vx.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1973 result.m9 = vy.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1974 result.m10 = vz.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1975 result.m11 = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1976 result.m12 = -(vx.x*eye.x + vx.y*eye.y + vx.z*eye.z); // Vector3DotProduct(vx, eye)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1977 result.m13 = -(vy.x*eye.x + vy.y*eye.y + vy.z*eye.z); // Vector3DotProduct(vy, eye)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1978 result.m14 = -(vz.x*eye.x + vz.y*eye.y + vz.z*eye.z); // Vector3DotProduct(vz, eye)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1979 result.m15 = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1980
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1981 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1982 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1983
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1984 // Get float array of matrix data
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1985 RMAPI float16 MatrixToFloatV(Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1986 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1987 float16 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1988
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1989 result.v[0] = mat.m0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1990 result.v[1] = mat.m1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1991 result.v[2] = mat.m2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1992 result.v[3] = mat.m3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1993 result.v[4] = mat.m4;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1994 result.v[5] = mat.m5;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1995 result.v[6] = mat.m6;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1996 result.v[7] = mat.m7;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1997 result.v[8] = mat.m8;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1998 result.v[9] = mat.m9;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1999 result.v[10] = mat.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2000 result.v[11] = mat.m11;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2001 result.v[12] = mat.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2002 result.v[13] = mat.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2003 result.v[14] = mat.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2004 result.v[15] = mat.m15;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2005
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2006 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2007 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2008
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2009 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2010 // Module Functions Definition - Quaternion math
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2011 //----------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2012
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2013 // Add two quaternions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2014 RMAPI Quaternion QuaternionAdd(Quaternion q1, Quaternion q2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2015 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2016 Quaternion result = {q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w};
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2017
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2018 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2019 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2020
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2021 // Add quaternion and float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2022 RMAPI Quaternion QuaternionAddValue(Quaternion q, float add)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2023 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2024 Quaternion result = {q.x + add, q.y + add, q.z + add, q.w + add};
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2025
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2026 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2027 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2028
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2029 // Subtract two quaternions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2030 RMAPI Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2031 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2032 Quaternion result = {q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w};
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2033
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2034 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2035 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2036
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2037 // Subtract quaternion and float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2038 RMAPI Quaternion QuaternionSubtractValue(Quaternion q, float sub)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2039 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2040 Quaternion result = {q.x - sub, q.y - sub, q.z - sub, q.w - sub};
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2041
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2042 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2043 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2044
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2045 // Get identity quaternion
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2046 RMAPI Quaternion QuaternionIdentity(void)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2047 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2048 Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2049
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2050 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2051 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2052
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2053 // Computes the length of a quaternion
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2054 RMAPI float QuaternionLength(Quaternion q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2055 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2056 float result = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2057
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2058 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2059 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2060
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2061 // Normalize provided quaternion
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2062 RMAPI Quaternion QuaternionNormalize(Quaternion q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2063 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2064 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2065
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2066 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2067 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2068 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2069
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2070 result.x = q.x*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2071 result.y = q.y*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2072 result.z = q.z*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2073 result.w = q.w*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2074
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2075 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2076 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2077
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2078 // Invert provided quaternion
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2079 RMAPI Quaternion QuaternionInvert(Quaternion q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2080 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2081 Quaternion result = q;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2082
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2083 float lengthSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2084
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2085 if (lengthSq != 0.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2086 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2087 float invLength = 1.0f/lengthSq;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2088
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2089 result.x *= -invLength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2090 result.y *= -invLength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2091 result.z *= -invLength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2092 result.w *= invLength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2093 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2094
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2095 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2096 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2097
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2098 // Calculate two quaternion multiplication
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2099 RMAPI Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2100 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2101 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2102
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2103 float qax = q1.x, qay = q1.y, qaz = q1.z, qaw = q1.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2104 float qbx = q2.x, qby = q2.y, qbz = q2.z, qbw = q2.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2105
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2106 result.x = qax*qbw + qaw*qbx + qay*qbz - qaz*qby;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2107 result.y = qay*qbw + qaw*qby + qaz*qbx - qax*qbz;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2108 result.z = qaz*qbw + qaw*qbz + qax*qby - qay*qbx;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2109 result.w = qaw*qbw - qax*qbx - qay*qby - qaz*qbz;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2110
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2111 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2112 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2113
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2114 // Scale quaternion by float value
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2115 RMAPI Quaternion QuaternionScale(Quaternion q, float mul)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2116 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2117 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2118
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2119 result.x = q.x*mul;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2120 result.y = q.y*mul;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2121 result.z = q.z*mul;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2122 result.w = q.w*mul;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2123
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2124 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2125 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2126
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2127 // Divide two quaternions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2128 RMAPI Quaternion QuaternionDivide(Quaternion q1, Quaternion q2)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2129 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2130 Quaternion result = { q1.x/q2.x, q1.y/q2.y, q1.z/q2.z, q1.w/q2.w };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2131
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2132 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2133 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2134
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2135 // Calculate linear interpolation between two quaternions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2136 RMAPI Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2137 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2138 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2139
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2140 result.x = q1.x + amount*(q2.x - q1.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2141 result.y = q1.y + amount*(q2.y - q1.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2142 result.z = q1.z + amount*(q2.z - q1.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2143 result.w = q1.w + amount*(q2.w - q1.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2144
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2145 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2146 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2147
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2148 // Calculate slerp-optimized interpolation between two quaternions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2149 RMAPI Quaternion QuaternionNlerp(Quaternion q1, Quaternion q2, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2150 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2151 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2152
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2153 // QuaternionLerp(q1, q2, amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2154 result.x = q1.x + amount*(q2.x - q1.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2155 result.y = q1.y + amount*(q2.y - q1.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2156 result.z = q1.z + amount*(q2.z - q1.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2157 result.w = q1.w + amount*(q2.w - q1.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2158
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2159 // QuaternionNormalize(q);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2160 Quaternion q = result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2161 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2162 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2163 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2164
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2165 result.x = q.x*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2166 result.y = q.y*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2167 result.z = q.z*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2168 result.w = q.w*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2169
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2170 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2171 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2172
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2173 // Calculates spherical linear interpolation between two quaternions
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2174 RMAPI Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2175 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2176 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2177
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2178 #if !defined(EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2179 #define EPSILON 0.000001f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2180 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2181
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2182 float cosHalfTheta = q1.x*q2.x + q1.y*q2.y + q1.z*q2.z + q1.w*q2.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2183
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2184 if (cosHalfTheta < 0)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2185 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2186 q2.x = -q2.x; q2.y = -q2.y; q2.z = -q2.z; q2.w = -q2.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2187 cosHalfTheta = -cosHalfTheta;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2188 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2189
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2190 if (fabsf(cosHalfTheta) >= 1.0f) result = q1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2191 else if (cosHalfTheta > 0.95f) result = QuaternionNlerp(q1, q2, amount);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2192 else
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2193 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2194 float halfTheta = acosf(cosHalfTheta);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2195 float sinHalfTheta = sqrtf(1.0f - cosHalfTheta*cosHalfTheta);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2196
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2197 if (fabsf(sinHalfTheta) < EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2198 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2199 result.x = (q1.x*0.5f + q2.x*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2200 result.y = (q1.y*0.5f + q2.y*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2201 result.z = (q1.z*0.5f + q2.z*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2202 result.w = (q1.w*0.5f + q2.w*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2203 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2204 else
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2205 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2206 float ratioA = sinf((1 - amount)*halfTheta)/sinHalfTheta;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2207 float ratioB = sinf(amount*halfTheta)/sinHalfTheta;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2208
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2209 result.x = (q1.x*ratioA + q2.x*ratioB);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2210 result.y = (q1.y*ratioA + q2.y*ratioB);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2211 result.z = (q1.z*ratioA + q2.z*ratioB);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2212 result.w = (q1.w*ratioA + q2.w*ratioB);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2213 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2214 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2215
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2216 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2217 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2218
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2219 // Calculate quaternion cubic spline interpolation using Cubic Hermite Spline algorithm
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2220 // as described in the GLTF 2.0 specification: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#interpolation-cubic
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2221 RMAPI Quaternion QuaternionCubicHermiteSpline(Quaternion q1, Quaternion outTangent1, Quaternion q2, Quaternion inTangent2, float t)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2222 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2223 float t2 = t*t;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2224 float t3 = t2*t;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2225 float h00 = 2*t3 - 3*t2 + 1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2226 float h10 = t3 - 2*t2 + t;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2227 float h01 = -2*t3 + 3*t2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2228 float h11 = t3 - t2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2229
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2230 Quaternion p0 = QuaternionScale(q1, h00);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2231 Quaternion m0 = QuaternionScale(outTangent1, h10);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2232 Quaternion p1 = QuaternionScale(q2, h01);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2233 Quaternion m1 = QuaternionScale(inTangent2, h11);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2234
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2235 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2236
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2237 result = QuaternionAdd(p0, m0);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2238 result = QuaternionAdd(result, p1);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2239 result = QuaternionAdd(result, m1);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2240 result = QuaternionNormalize(result);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2241
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2242 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2243 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2244
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2245 // Calculate quaternion based on the rotation from one vector to another
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2246 RMAPI Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2247 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2248 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2249
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2250 float cos2Theta = (from.x*to.x + from.y*to.y + from.z*to.z); // Vector3DotProduct(from, to)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2251 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)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2252
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2253 result.x = cross.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2254 result.y = cross.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2255 result.z = cross.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2256 result.w = 1.0f + cos2Theta;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2257
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2258 // QuaternionNormalize(q);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2259 // NOTE: Normalize to essentially nlerp the original and identity to 0.5
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2260 Quaternion q = result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2261 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2262 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2263 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2264
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2265 result.x = q.x*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2266 result.y = q.y*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2267 result.z = q.z*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2268 result.w = q.w*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2269
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2270 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2271 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2272
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2273 // Get a quaternion for a given rotation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2274 RMAPI Quaternion QuaternionFromMatrix(Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2275 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2276 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2277
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2278 float fourWSquaredMinus1 = mat.m0 + mat.m5 + mat.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2279 float fourXSquaredMinus1 = mat.m0 - mat.m5 - mat.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2280 float fourYSquaredMinus1 = mat.m5 - mat.m0 - mat.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2281 float fourZSquaredMinus1 = mat.m10 - mat.m0 - mat.m5;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2282
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2283 int biggestIndex = 0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2284 float fourBiggestSquaredMinus1 = fourWSquaredMinus1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2285 if (fourXSquaredMinus1 > fourBiggestSquaredMinus1)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2286 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2287 fourBiggestSquaredMinus1 = fourXSquaredMinus1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2288 biggestIndex = 1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2289 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2290
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2291 if (fourYSquaredMinus1 > fourBiggestSquaredMinus1)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2292 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2293 fourBiggestSquaredMinus1 = fourYSquaredMinus1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2294 biggestIndex = 2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2295 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2296
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2297 if (fourZSquaredMinus1 > fourBiggestSquaredMinus1)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2298 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2299 fourBiggestSquaredMinus1 = fourZSquaredMinus1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2300 biggestIndex = 3;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2301 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2302
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2303 float biggestVal = sqrtf(fourBiggestSquaredMinus1 + 1.0f)*0.5f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2304 float mult = 0.25f/biggestVal;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2305
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2306 switch (biggestIndex)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2307 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2308 case 0:
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2309 result.w = biggestVal;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2310 result.x = (mat.m6 - mat.m9)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2311 result.y = (mat.m8 - mat.m2)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2312 result.z = (mat.m1 - mat.m4)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2313 break;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2314 case 1:
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2315 result.x = biggestVal;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2316 result.w = (mat.m6 - mat.m9)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2317 result.y = (mat.m1 + mat.m4)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2318 result.z = (mat.m8 + mat.m2)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2319 break;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2320 case 2:
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2321 result.y = biggestVal;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2322 result.w = (mat.m8 - mat.m2)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2323 result.x = (mat.m1 + mat.m4)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2324 result.z = (mat.m6 + mat.m9)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2325 break;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2326 case 3:
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2327 result.z = biggestVal;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2328 result.w = (mat.m1 - mat.m4)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2329 result.x = (mat.m8 + mat.m2)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2330 result.y = (mat.m6 + mat.m9)*mult;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2331 break;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2332 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2333
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2334 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2335 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2336
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2337 // Get a matrix for a given quaternion
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2338 RMAPI Matrix QuaternionToMatrix(Quaternion q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2339 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2340 Matrix result = { 1.0f, 0.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2341 0.0f, 1.0f, 0.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2342 0.0f, 0.0f, 1.0f, 0.0f,
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2343 0.0f, 0.0f, 0.0f, 1.0f }; // MatrixIdentity()
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2344
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2345 float a2 = q.x*q.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2346 float b2 = q.y*q.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2347 float c2 = q.z*q.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2348 float ac = q.x*q.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2349 float ab = q.x*q.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2350 float bc = q.y*q.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2351 float ad = q.w*q.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2352 float bd = q.w*q.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2353 float cd = q.w*q.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2354
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2355 result.m0 = 1 - 2*(b2 + c2);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2356 result.m1 = 2*(ab + cd);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2357 result.m2 = 2*(ac - bd);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2358
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2359 result.m4 = 2*(ab - cd);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2360 result.m5 = 1 - 2*(a2 + c2);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2361 result.m6 = 2*(bc + ad);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2362
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2363 result.m8 = 2*(ac + bd);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2364 result.m9 = 2*(bc - ad);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2365 result.m10 = 1 - 2*(a2 + b2);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2366
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2367 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2368 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2369
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2370 // Get rotation quaternion for an angle and axis
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2371 // NOTE: Angle must be provided in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2372 RMAPI Quaternion QuaternionFromAxisAngle(Vector3 axis, float angle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2373 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2374 Quaternion result = { 0.0f, 0.0f, 0.0f, 1.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2375
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2376 float axisLength = sqrtf(axis.x*axis.x + axis.y*axis.y + axis.z*axis.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2377
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2378 if (axisLength != 0.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2379 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2380 angle *= 0.5f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2381
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2382 float length = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2383 float ilength = 0.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2384
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2385 // Vector3Normalize(axis)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2386 length = axisLength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2387 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2388 ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2389 axis.x *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2390 axis.y *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2391 axis.z *= ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2392
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2393 float sinres = sinf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2394 float cosres = cosf(angle);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2395
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2396 result.x = axis.x*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2397 result.y = axis.y*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2398 result.z = axis.z*sinres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2399 result.w = cosres;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2400
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2401 // QuaternionNormalize(q);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2402 Quaternion q = result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2403 length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2404 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2405 ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2406 result.x = q.x*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2407 result.y = q.y*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2408 result.z = q.z*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2409 result.w = q.w*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2410 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2411
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2412 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2413 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2414
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2415 // Get the rotation angle and axis for a given quaternion
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2416 RMAPI void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2417 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2418 if (fabsf(q.w) > 1.0f)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2419 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2420 // QuaternionNormalize(q);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2421 float length = sqrtf(q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2422 if (length == 0.0f) length = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2423 float ilength = 1.0f/length;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2424
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2425 q.x = q.x*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2426 q.y = q.y*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2427 q.z = q.z*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2428 q.w = q.w*ilength;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2429 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2430
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2431 Vector3 resAxis = { 0.0f, 0.0f, 0.0f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2432 float resAngle = 2.0f*acosf(q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2433 float den = sqrtf(1.0f - q.w*q.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2434
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2435 if (den > EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2436 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2437 resAxis.x = q.x/den;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2438 resAxis.y = q.y/den;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2439 resAxis.z = q.z/den;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2440 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2441 else
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2442 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2443 // This occurs when the angle is zero.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2444 // Not a problem: just set an arbitrary normalized axis.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2445 resAxis.x = 1.0f;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2446 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2447
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2448 *outAxis = resAxis;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2449 *outAngle = resAngle;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2450 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2451
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2452 // Get the quaternion equivalent to Euler angles
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2453 // NOTE: Rotation order is ZYX
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2454 RMAPI Quaternion QuaternionFromEuler(float pitch, float yaw, float roll)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2455 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2456 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2457
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2458 float x0 = cosf(pitch*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2459 float x1 = sinf(pitch*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2460 float y0 = cosf(yaw*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2461 float y1 = sinf(yaw*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2462 float z0 = cosf(roll*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2463 float z1 = sinf(roll*0.5f);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2464
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2465 result.x = x1*y0*z0 - x0*y1*z1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2466 result.y = x0*y1*z0 + x1*y0*z1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2467 result.z = x0*y0*z1 - x1*y1*z0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2468 result.w = x0*y0*z0 + x1*y1*z1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2469
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2470 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2471 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2472
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2473 // Get the Euler angles equivalent to quaternion (roll, pitch, yaw)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2474 // NOTE: Angles are returned in a Vector3 struct in radians
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2475 RMAPI Vector3 QuaternionToEuler(Quaternion q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2476 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2477 Vector3 result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2478
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2479 // Roll (x-axis rotation)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2480 float x0 = 2.0f*(q.w*q.x + q.y*q.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2481 float x1 = 1.0f - 2.0f*(q.x*q.x + q.y*q.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2482 result.x = atan2f(x0, x1);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2483
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2484 // Pitch (y-axis rotation)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2485 float y0 = 2.0f*(q.w*q.y - q.z*q.x);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2486 y0 = y0 > 1.0f ? 1.0f : y0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2487 y0 = y0 < -1.0f ? -1.0f : y0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2488 result.y = asinf(y0);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2489
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2490 // Yaw (z-axis rotation)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2491 float z0 = 2.0f*(q.w*q.z + q.x*q.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2492 float z1 = 1.0f - 2.0f*(q.y*q.y + q.z*q.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2493 result.z = atan2f(z0, z1);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2494
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2495 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2496 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2497
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2498 // Transform a quaternion given a transformation matrix
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2499 RMAPI Quaternion QuaternionTransform(Quaternion q, Matrix mat)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2500 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2501 Quaternion result = { 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2502
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2503 result.x = mat.m0*q.x + mat.m4*q.y + mat.m8*q.z + mat.m12*q.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2504 result.y = mat.m1*q.x + mat.m5*q.y + mat.m9*q.z + mat.m13*q.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2505 result.z = mat.m2*q.x + mat.m6*q.y + mat.m10*q.z + mat.m14*q.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2506 result.w = mat.m3*q.x + mat.m7*q.y + mat.m11*q.z + mat.m15*q.w;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2507
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2508 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2509 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2510
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2511 // Check whether two given quaternions are almost equal
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2512 RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2513 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2514 #if !defined(EPSILON)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2515 #define EPSILON 0.000001f
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2516 #endif
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2517
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2518 int result = (((fabsf(p.x - q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2519 ((fabsf(p.y - q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2520 ((fabsf(p.z - q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2521 ((fabsf(p.w - q.w)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.w), fabsf(q.w)))))) ||
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2522 (((fabsf(p.x + q.x)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.x), fabsf(q.x))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2523 ((fabsf(p.y + q.y)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.y), fabsf(q.y))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2524 ((fabsf(p.z + q.z)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.z), fabsf(q.z))))) &&
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2525 ((fabsf(p.w + q.w)) <= (EPSILON*fmaxf(1.0f, fmaxf(fabsf(p.w), fabsf(q.w))))));
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2526
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2527 return result;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2528 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2529
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2530 // Decompose a transformation matrix into its rotational, translational and scaling components
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2531 RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2532 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2533 // Extract translation.
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2534 translation->x = mat.m12;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2535 translation->y = mat.m13;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2536 translation->z = mat.m14;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2537
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2538 // Extract upper-left for determinant computation
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2539 const float a = mat.m0;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2540 const float b = mat.m4;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2541 const float c = mat.m8;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2542 const float d = mat.m1;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2543 const float e = mat.m5;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2544 const float f = mat.m9;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2545 const float g = mat.m2;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2546 const float h = mat.m6;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2547 const float i = mat.m10;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2548 const float A = e*i - f*h;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2549 const float B = f*g - d*i;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2550 const float C = d*h - e*g;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2551
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2552 // Extract scale
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2553 const float det = a*A + b*B + c*C;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2554 Vector3 abc = { a, b, c };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2555 Vector3 def = { d, e, f };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2556 Vector3 ghi = { g, h, i };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2557
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2558 float scalex = Vector3Length(abc);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2559 float scaley = Vector3Length(def);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2560 float scalez = Vector3Length(ghi);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2561 Vector3 s = { scalex, scaley, scalez };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2562
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2563 if (det < 0) s = Vector3Negate(s);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2564
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2565 *scale = s;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2566
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2567 // Remove scale from the matrix if it is not close to zero
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2568 Matrix clone = mat;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2569 if (!FloatEquals(det, 0))
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2570 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2571 clone.m0 /= s.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2572 clone.m4 /= s.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2573 clone.m8 /= s.x;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2574 clone.m1 /= s.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2575 clone.m5 /= s.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2576 clone.m9 /= s.y;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2577 clone.m2 /= s.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2578 clone.m6 /= s.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2579 clone.m10 /= s.z;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2580
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2581 // Extract rotation
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2582 *rotation = QuaternionFromMatrix(clone);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2583 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2584 else
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2585 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2586 // Set to identity if close to zero
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2587 *rotation = QuaternionIdentity();
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2588 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2589 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2590
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2591 #if defined(__cplusplus) && !defined(RAYMATH_DISABLE_CPP_OPERATORS)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2592
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2593 // Optional C++ math operators
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2594 //-------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2595
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2596 // Vector2 operators
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2597 static constexpr Vector2 Vector2Zeros = { 0, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2598 static constexpr Vector2 Vector2Ones = { 1, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2599 static constexpr Vector2 Vector2UnitX = { 1, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2600 static constexpr Vector2 Vector2UnitY = { 0, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2601
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2602 inline Vector2 operator + (const Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2603 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2604 return Vector2Add(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2605 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2606
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2607 inline const Vector2& operator += (Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2608 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2609 lhs = Vector2Add(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2610 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2611 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2612
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2613 inline Vector2 operator - (const Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2614 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2615 return Vector2Subtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2616 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2617
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2618 inline const Vector2& operator -= (Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2619 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2620 lhs = Vector2Subtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2621 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2622 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2623
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2624 inline Vector2 operator * (const Vector2& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2625 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2626 return Vector2Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2627 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2628
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2629 inline const Vector2& operator *= (Vector2& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2630 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2631 lhs = Vector2Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2632 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2633 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2634
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2635 inline Vector2 operator * (const Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2636 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2637 return Vector2Multiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2638 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2639
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2640 inline const Vector2& operator *= (Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2641 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2642 lhs = Vector2Multiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2643 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2644 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2645
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2646 inline Vector2 operator * (const Vector2& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2647 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2648 return Vector2Transform(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2649 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2650
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2651 inline const Vector2& operator -= (Vector2& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2652 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2653 lhs = Vector2Transform(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2654 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2655 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2656
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2657 inline Vector2 operator / (const Vector2& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2658 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2659 return Vector2Scale(lhs, 1.0f / rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2660 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2661
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2662 inline const Vector2& operator /= (Vector2& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2663 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2664 lhs = Vector2Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2665 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2666 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2667
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2668 inline Vector2 operator / (const Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2669 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2670 return Vector2Divide(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2671 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2672
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2673 inline const Vector2& operator /= (Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2674 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2675 lhs = Vector2Divide(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2676 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2677 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2678
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2679 inline bool operator == (const Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2680 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2681 return FloatEquals(lhs.x, rhs.x) && FloatEquals(lhs.y, rhs.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2682 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2683
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2684 inline bool operator != (const Vector2& lhs, const Vector2& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2685 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2686 return !FloatEquals(lhs.x, rhs.x) || !FloatEquals(lhs.y, rhs.y);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2687 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2688
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2689 // Vector3 operators
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2690 static constexpr Vector3 Vector3Zeros = { 0, 0, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2691 static constexpr Vector3 Vector3Ones = { 1, 1, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2692 static constexpr Vector3 Vector3UnitX = { 1, 0, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2693 static constexpr Vector3 Vector3UnitY = { 0, 1, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2694 static constexpr Vector3 Vector3UnitZ = { 0, 0, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2695
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2696 inline Vector3 operator + (const Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2697 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2698 return Vector3Add(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2699 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2700
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2701 inline const Vector3& operator += (Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2702 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2703 lhs = Vector3Add(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2704 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2705 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2706
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2707 inline Vector3 operator - (const Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2708 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2709 return Vector3Subtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2710 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2711
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2712 inline const Vector3& operator -= (Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2713 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2714 lhs = Vector3Subtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2715 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2716 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2717
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2718 inline Vector3 operator * (const Vector3& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2719 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2720 return Vector3Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2721 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2722
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2723 inline const Vector3& operator *= (Vector3& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2724 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2725 lhs = Vector3Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2726 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2727 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2728
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2729 inline Vector3 operator * (const Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2730 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2731 return Vector3Multiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2732 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2733
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2734 inline const Vector3& operator *= (Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2735 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2736 lhs = Vector3Multiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2737 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2738 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2739
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2740 inline Vector3 operator * (const Vector3& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2741 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2742 return Vector3Transform(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2743 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2744
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2745 inline const Vector3& operator -= (Vector3& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2746 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2747 lhs = Vector3Transform(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2748 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2749 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2750
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2751 inline Vector3 operator / (const Vector3& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2752 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2753 return Vector3Scale(lhs, 1.0f / rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2754 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2755
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2756 inline const Vector3& operator /= (Vector3& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2757 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2758 lhs = Vector3Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2759 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2760 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2761
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2762 inline Vector3 operator / (const Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2763 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2764 return Vector3Divide(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2765 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2766
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2767 inline const Vector3& operator /= (Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2768 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2769 lhs = Vector3Divide(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2770 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2771 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2772
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2773 inline bool operator == (const Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2774 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2775 return FloatEquals(lhs.x, rhs.x) && FloatEquals(lhs.y, rhs.y) && FloatEquals(lhs.z, rhs.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2776 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2777
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2778 inline bool operator != (const Vector3& lhs, const Vector3& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2779 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2780 return !FloatEquals(lhs.x, rhs.x) || !FloatEquals(lhs.y, rhs.y) || !FloatEquals(lhs.z, rhs.z);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2781 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2782
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2783 // Vector4 operators
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2784 static constexpr Vector4 Vector4Zeros = { 0, 0, 0, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2785 static constexpr Vector4 Vector4Ones = { 1, 1, 1, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2786 static constexpr Vector4 Vector4UnitX = { 1, 0, 0, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2787 static constexpr Vector4 Vector4UnitY = { 0, 1, 0, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2788 static constexpr Vector4 Vector4UnitZ = { 0, 0, 1, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2789 static constexpr Vector4 Vector4UnitW = { 0, 0, 0, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2790
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2791 inline Vector4 operator + (const Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2792 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2793 return Vector4Add(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2794 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2795
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2796 inline const Vector4& operator += (Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2797 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2798 lhs = Vector4Add(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2799 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2800 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2801
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2802 inline Vector4 operator - (const Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2803 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2804 return Vector4Subtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2805 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2806
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2807 inline const Vector4& operator -= (Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2808 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2809 lhs = Vector4Subtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2810 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2811 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2812
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2813 inline Vector4 operator * (const Vector4& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2814 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2815 return Vector4Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2816 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2817
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2818 inline const Vector4& operator *= (Vector4& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2819 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2820 lhs = Vector4Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2821 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2822 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2823
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2824 inline Vector4 operator * (const Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2825 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2826 return Vector4Multiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2827 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2828
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2829 inline const Vector4& operator *= (Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2830 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2831 lhs = Vector4Multiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2832 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2833 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2834
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2835 inline Vector4 operator / (const Vector4& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2836 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2837 return Vector4Scale(lhs, 1.0f / rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2838 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2839
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2840 inline const Vector4& operator /= (Vector4& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2841 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2842 lhs = Vector4Scale(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2843 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2844 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2845
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2846 inline Vector4 operator / (const Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2847 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2848 return Vector4Divide(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2849 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2850
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2851 inline const Vector4& operator /= (Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2852 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2853 lhs = Vector4Divide(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2854 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2855 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2856
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2857 inline bool operator == (const Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2858 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2859 return FloatEquals(lhs.x, rhs.x) && FloatEquals(lhs.y, rhs.y) && FloatEquals(lhs.z, rhs.z) && FloatEquals(lhs.w, rhs.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2860 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2861
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2862 inline bool operator != (const Vector4& lhs, const Vector4& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2863 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2864 return !FloatEquals(lhs.x, rhs.x) || !FloatEquals(lhs.y, rhs.y) || !FloatEquals(lhs.z, rhs.z) || !FloatEquals(lhs.w, rhs.w);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2865 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2866
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2867 // Quaternion operators
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2868 static constexpr Quaternion QuaternionZeros = { 0, 0, 0, 0 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2869 static constexpr Quaternion QuaternionOnes = { 1, 1, 1, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2870 static constexpr Quaternion QuaternionUnitX = { 0, 0, 0, 1 };
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2871
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2872 inline Quaternion operator + (const Quaternion& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2873 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2874 return QuaternionAddValue(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2875 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2876
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2877 inline const Quaternion& operator += (Quaternion& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2878 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2879 lhs = QuaternionAddValue(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2880 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2881 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2882
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2883 inline Quaternion operator - (const Quaternion& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2884 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2885 return QuaternionSubtractValue(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2886 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2887
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2888 inline const Quaternion& operator -= (Quaternion& lhs, const float& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2889 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2890 lhs = QuaternionSubtractValue(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2891 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2892 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2893
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2894 inline Quaternion operator * (const Quaternion& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2895 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2896 return QuaternionTransform(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2897 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2898
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2899 inline const Quaternion& operator *= (Quaternion& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2900 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2901 lhs = QuaternionTransform(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2902 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2903 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2904
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2905 // Matrix operators
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2906 inline Matrix operator + (const Matrix& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2907 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2908 return MatrixAdd(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2909 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2910
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2911 inline const Matrix& operator += (Matrix& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2912 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2913 lhs = MatrixAdd(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2914 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2915 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2916
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2917 inline Matrix operator - (const Matrix& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2918 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2919 return MatrixSubtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2920 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2921
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2922 inline const Matrix& operator -= (Matrix& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2923 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2924 lhs = MatrixSubtract(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2925 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2926 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2927
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2928 inline Matrix operator * (const Matrix& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2929 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2930 return MatrixMultiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2931 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2932
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2933 inline const Matrix& operator *= (Matrix& lhs, const Matrix& rhs)
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2934 {
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2935 lhs = MatrixMultiply(lhs, rhs);
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2936 return lhs;
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2937 }
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2938 //-------------------------------------------------------------------------------
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2939 #endif // C++ operators
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2940
f33d9ff8b6e8 [Raylib] Added raylib linux to third party lib and added cross platform support.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2941 #endif // RAYMATH_H