19inline float Dot(
const Vec2& _lhs,
const Vec2& _rhs) {
return _lhs.
x * _rhs.
x + _lhs.
y * _rhs.
y; }
33inline float Dot(
const Vec3& _lhs,
const Vec3& _rhs) {
return _lhs.
x * _rhs.
x + _lhs.
y * _rhs.
y + _lhs.
z * _rhs.
z; }
41 _a.
y * _b.
z - _b.
y * _a.
z,
42 _a.
z * _b.
x - _b.
z * _a.
x,
43 _a.
x * _b.
y - _b.
x * _a.
y
55inline float Dot(
const Vec4& _lhs,
const Vec4& _rhs) {
return _lhs.
x * _rhs.
x + _lhs.
y * _rhs.
y + _lhs.
z * _rhs.
z + _lhs.
w * _rhs.
w; }
65 ret(0, 0) = _lhs(0, 0) * _rhs(0, 0) + _lhs(0, 1) * _rhs(1, 0) + _lhs(0, 2) * _rhs(2, 0);
66 ret(0, 1) = _lhs(0, 0) * _rhs(0, 1) + _lhs(0, 1) * _rhs(1, 1) + _lhs(0, 2) * _rhs(2, 1);
67 ret(0, 2) = _lhs(0, 0) * _rhs(0, 2) + _lhs(0, 1) * _rhs(1, 2) + _lhs(0, 2) * _rhs(2, 2);
68 ret(1, 0) = _lhs(1, 0) * _rhs(0, 0) + _lhs(1, 1) * _rhs(1, 0) + _lhs(1, 2) * _rhs(2, 0);
69 ret(1, 1) = _lhs(1, 0) * _rhs(0, 1) + _lhs(1, 1) * _rhs(1, 1) + _lhs(1, 2) * _rhs(2, 1);
70 ret(1, 2) = _lhs(1, 0) * _rhs(0, 2) + _lhs(1, 1) * _rhs(1, 2) + _lhs(1, 2) * _rhs(2, 2);
71 ret(2, 0) = _lhs(2, 0) * _rhs(0, 0) + _lhs(2, 1) * _rhs(1, 0) + _lhs(2, 2) * _rhs(2, 0);
72 ret(2, 1) = _lhs(2, 0) * _rhs(0, 1) + _lhs(2, 1) * _rhs(1, 1) + _lhs(2, 2) * _rhs(2, 1);
73 ret(2, 2) = _lhs(2, 0) * _rhs(0, 2) + _lhs(2, 1) * _rhs(1, 2) + _lhs(2, 2) * _rhs(2, 2);
80 _m(0, 0) * _v.
x + _m(0, 1) * _v.
y + _m(0, 2) * _v.
z,
81 _m(1, 0) * _v.
x + _m(1, 1) * _v.
y + _m(1, 2) * _v.
z,
82 _m(2, 0) * _v.
x + _m(2, 1) * _v.
y + _m(2, 2) * _v.
z
88 _m(0, 0) * _v.
x + _m(0, 1) * _v.
y + _m(0, 2) * _v.
z,
89 _m(1, 0) * _v.
x + _m(1, 1) * _v.
y + _m(1, 2) * _v.
z,
90 _m(2, 0) * _v.
x + _m(2, 1) * _v.
y + _m(2, 2) * _v.
z,
97Mat3
Rotation(
const Vec3& _axis,
float _rads);
98Mat3
Scale(
const Vec3& _s);
104 ret(0, 0) = _lhs(0, 0) * _rhs(0, 0) + _lhs(0, 1) * _rhs(1, 0) + _lhs(0, 2) * _rhs(2, 0) + _lhs(0, 3) * _rhs(3, 0);
105 ret(0, 1) = _lhs(0, 0) * _rhs(0, 1) + _lhs(0, 1) * _rhs(1, 1) + _lhs(0, 2) * _rhs(2, 1) + _lhs(0, 3) * _rhs(3, 1);
106 ret(0, 2) = _lhs(0, 0) * _rhs(0, 2) + _lhs(0, 1) * _rhs(1, 2) + _lhs(0, 2) * _rhs(2, 2) + _lhs(0, 3) * _rhs(3, 2);
107 ret(0, 3) = _lhs(0, 0) * _rhs(0, 3) + _lhs(0, 1) * _rhs(1, 3) + _lhs(0, 2) * _rhs(2, 3) + _lhs(0, 3) * _rhs(3, 3);
108 ret(1, 0) = _lhs(1, 0) * _rhs(0, 0) + _lhs(1, 1) * _rhs(1, 0) + _lhs(1, 2) * _rhs(2, 0) + _lhs(1, 3) * _rhs(3, 0);
109 ret(1, 1) = _lhs(1, 0) * _rhs(0, 1) + _lhs(1, 1) * _rhs(1, 1) + _lhs(1, 2) * _rhs(2, 1) + _lhs(1, 3) * _rhs(3, 1);
110 ret(1, 2) = _lhs(1, 0) * _rhs(0, 2) + _lhs(1, 1) * _rhs(1, 2) + _lhs(1, 2) * _rhs(2, 2) + _lhs(1, 3) * _rhs(3, 2);
111 ret(1, 3) = _lhs(1, 0) * _rhs(0, 3) + _lhs(1, 1) * _rhs(1, 3) + _lhs(1, 2) * _rhs(2, 3) + _lhs(1, 3) * _rhs(3, 3);
112 ret(2, 0) = _lhs(2, 0) * _rhs(0, 0) + _lhs(2, 1) * _rhs(1, 0) + _lhs(2, 2) * _rhs(2, 0) + _lhs(2, 3) * _rhs(3, 0);
113 ret(2, 1) = _lhs(2, 0) * _rhs(0, 1) + _lhs(2, 1) * _rhs(1, 1) + _lhs(2, 2) * _rhs(2, 1) + _lhs(2, 3) * _rhs(3, 1);
114 ret(2, 2) = _lhs(2, 0) * _rhs(0, 2) + _lhs(2, 1) * _rhs(1, 2) + _lhs(2, 2) * _rhs(2, 2) + _lhs(2, 3) * _rhs(3, 2);
115 ret(2, 3) = _lhs(2, 0) * _rhs(0, 3) + _lhs(2, 1) * _rhs(1, 3) + _lhs(2, 2) * _rhs(2, 3) + _lhs(2, 3) * _rhs(3, 3);
116 ret(3, 0) = _lhs(3, 0) * _rhs(0, 0) + _lhs(3, 1) * _rhs(1, 0) + _lhs(3, 2) * _rhs(2, 0) + _lhs(3, 3) * _rhs(3, 0);
117 ret(3, 1) = _lhs(3, 0) * _rhs(0, 1) + _lhs(3, 1) * _rhs(1, 1) + _lhs(3, 2) * _rhs(2, 1) + _lhs(3, 3) * _rhs(3, 1);
118 ret(3, 2) = _lhs(3, 0) * _rhs(0, 2) + _lhs(3, 1) * _rhs(1, 2) + _lhs(3, 2) * _rhs(2, 2) + _lhs(3, 3) * _rhs(3, 2);
119 ret(3, 3) = _lhs(3, 0) * _rhs(0, 3) + _lhs(3, 1) * _rhs(1, 3) + _lhs(3, 2) * _rhs(2, 3) + _lhs(3, 3) * _rhs(3, 3);
126 _m(0, 0) * _pos.
x + _m(0, 1) * _pos.
y + _m(0, 2) * _pos.
z + _m(0, 3),
127 _m(1, 0) * _pos.
x + _m(1, 1) * _pos.
y + _m(1, 2) * _pos.
z + _m(1, 3),
128 _m(2, 0) * _pos.
x + _m(2, 1) * _pos.
y + _m(2, 2) * _pos.
z + _m(2, 3)
134 _m(0, 0) * _v.
x + _m(0, 1) * _v.
y + _m(0, 2) * _v.
z + _m(0, 3) * _v.
w,
135 _m(1, 0) * _v.
x + _m(1, 1) * _v.
y + _m(1, 2) * _v.
z + _m(1, 3) * _v.
w,
136 _m(2, 0) * _v.
x + _m(2, 1) * _v.
y + _m(2, 2) * _v.
z + _m(2, 3) * _v.
w,
137 _m(3, 0) * _v.
x + _m(3, 1) * _v.
y + _m(3, 2) * _v.
z + _m(3, 3) * _v.
w
143Mat4
AlignZ(
const Vec3& _axis,
const Vec3& _up = Vec3(0.0f, 1.0f, 0.0f));
144Mat4
LookAt(
const Vec3& _from,
const Vec3& _to,
const Vec3& _up = Vec3(0.0f, 1.0f, 0.0f));
184 Plane(
const Vec3& _normal,
float _offset);
199bool Intersects(
const Ray& _ray,
const Plane& _plane );
200bool Intersect (
const Ray& _ray,
const Plane& _plane,
float& t0_ );
201bool Intersects(
const Ray& _ray,
const Sphere& _sphere );
202bool Intersect (
const Ray& _ray,
const Sphere& _sphere,
float& t0_,
float& t1_);
203bool Intersects(
const Ray& _ray,
const Capsule& _capsule );
204bool Intersect (
const Ray& _ray,
const Capsule& _capsule,
float& t0_,
float& t1_);
207void Nearest(
const Line& _line0,
const Line& _line1,
float& t0_,
float& t1_);
209void Nearest(
const Ray& _ray,
const Line& _line,
float& tr_,
float& tl_);
211Vec3
Nearest(
const Ray& _ray,
const LineSegment& _segment,
float& tr_);
213float Distance2(
const Ray& _ray,
const LineSegment& _segment);
215inline float Distance(
const Vec4& _plane,
const Vec3& _point){
return _plane.
x * _point.
x + _plane.
y * _point.
y + _plane.
z * _point.
z - _plane.
w; }
217constexpr float Pi = 3.14159265359f;
221inline float Radians(
float _degrees) {
return _degrees * (
Pi / 180.0f); }
222inline float Degrees(
float _radians) {
return _radians * (180.0f /
Pi); }
262 return _a < _b ? _b : _a;
277 return _a < _b ? _a : _b;
301inline T
Clamp(T _a, T _min, T _max) {
return Max(
Min(_a, _max), _min); }
304inline float Remap(
float _x,
float _start,
float _end) {
return Clamp(_x * (1.0f / (_end - _start)) + (-_start / (_end - _start)), 0.0f, 1.0f); }
T _Max(const T &_a, const T &_b, ScalarT)
Definition im3d_math.h:260
bool _AllLess(const T &_a, const T &_b, ScalarT)
Definition im3d_math.h:242
T _Min(const T &_a, const T &_b, ScalarT)
Definition im3d_math.h:275
float Dot(const Vec2 &_lhs, const Vec2 &_rhs)
Definition im3d_math.h:19
Vec2 operator+(const Vec2 &_lhs, const Vec2 &_rhs)
Definition im3d_math.h:12
Mat4 Inverse(const Mat4 &_m)
Definition im3d.cpp:3006
Vec2 Normalize(const Vec2 &_v)
Definition im3d_math.h:23
bool AllLess(const T &_a, const T &_b)
Definition im3d_math.h:294
T Max(T _a, T _b)
Definition im3d_math.h:297
bool Intersect(const Ray &_ray, const Plane &_plane, float &t0_)
Definition im3d.cpp:3128
Mat4 AlignZ(const Vec3 &_axis, const Vec3 &_up=Vec3(0.0f, 1.0f, 0.0f))
Definition im3d.cpp:3052
float Degrees(float _radians)
Definition im3d_math.h:222
constexpr float HalfPi
Definition im3d_math.h:219
Vec3 ToEulerXYZ(const Mat3 &_m)
Definition im3d.cpp:2833
Vec2 Abs(const Vec2 &_v)
Definition im3d_math.h:22
float Distance2(const Ray &_ray, const LineSegment &_segment)
Definition im3d.cpp:3264
float Remap(float _x, float _start, float _end)
Definition im3d_math.h:304
bool Intersects(const Ray &_ray, const Plane &_plane)
Definition im3d.cpp:3123
Mat3 FromEulerXYZ(Vec3 &_xyz)
Definition im3d.cpp:2860
T Clamp(T _a, T _min, T _max)
Definition im3d_math.h:301
float Radians(float _degrees)
Definition im3d_math.h:221
T Min(T _a, T _b)
Definition im3d_math.h:299
Vec2 operator-(const Vec2 &_lhs, const Vec2 &_rhs)
Definition im3d_math.h:13
constexpr float Pi
Definition im3d_math.h:217
float Distance(const Vec4 &_plane, const Vec3 &_point)
Definition im3d_math.h:215
float Length(const Vec2 &_v)
Definition im3d_math.h:20
Mat3 Transpose(const Mat3 &_m)
Definition im3d.cpp:2874
Vec2 operator/(const Vec2 &_lhs, const Vec2 &_rhs)
Definition im3d_math.h:15
constexpr float TwoPi
Definition im3d_math.h:218
Mat3 Rotation(const Vec3 &_axis, float _rads)
Definition im3d.cpp:2882
Mat4 Translation(const Vec3 &_t)
Definition im3d.cpp:3043
Vec3 Cross(const Vec3 &_a, const Vec3 &_b)
Definition im3d_math.h:38
float Length2(const Vec2 &_v)
Definition im3d_math.h:21
void Nearest(const Line &_line0, const Line &_line1, float &t0_, float &t1_)
Definition im3d.cpp:3179
Mat4 LookAt(const Vec3 &_from, const Vec3 &_to, const Vec3 &_up=Vec3(0.0f, 1.0f, 0.0f))
Definition im3d.cpp:3078
Vec2 operator*(const Vec2 &_lhs, const Vec2 &_rhs)
Definition im3d_math.h:14
IM3D_API void Scale(float _x, float _y, float _z)
Definition im3d.cpp:137
Definition im3d_math.h:188
Vec3 m_start
Definition im3d_math.h:189
float m_radius
Definition im3d_math.h:191
Vec3 m_end
Definition im3d_math.h:190
Capsule()
Definition im3d_math.h:193
Definition im3d_math.h:147
Vec3 m_origin
Definition im3d_math.h:148
Line()
Definition im3d_math.h:151
Vec3 m_direction
Definition im3d_math.h:149
Definition im3d_math.h:163
Vec3 m_end
Definition im3d_math.h:165
Vec3 m_start
Definition im3d_math.h:164
LineSegment()
Definition im3d_math.h:167
Definition im3d_math.h:179
float m_offset
Definition im3d_math.h:181
Vec3 m_normal
Definition im3d_math.h:180
Plane()
Definition im3d_math.h:183
Definition im3d_math.h:155
Vec3 m_origin
Definition im3d_math.h:156
Vec3 m_direction
Definition im3d_math.h:157
Ray()
Definition im3d_math.h:159
Definition im3d_math.h:171
Sphere()
Definition im3d_math.h:175
Vec3 m_origin
Definition im3d_math.h:172
float m_radius
Definition im3d_math.h:173
float y
Definition im3d.h:205
float x
Definition im3d.h:205
float y
Definition im3d.h:221
float x
Definition im3d.h:221
float z
Definition im3d.h:221
float z
Definition im3d.h:239
float y
Definition im3d.h:239
float x
Definition im3d.h:239
float w
Definition im3d.h:239
Definition im3d_math.h:229
Definition im3d_math.h:227
Definition im3d_math.h:228
Definition im3d_math.h:231
Definition im3d_math.h:226
Definition im3d_math.h:233
T::Type Type
Definition im3d_math.h:233
@ kSize
Definition im3d_math.h:233
Definition im3d_math.h:230