6#ifndef MATERIALX_RENDER_TYPES_H
7#define MATERIALX_RENDER_TYPES_H
16MATERIALX_NAMESPACE_BEGIN
20class MX_RENDER_API Quaternion :
public VectorN<Vector4, float, 4>
23 using VectorN<
Vector4, float, 4>::VectorN;
24 Quaternion() =
default;
25 Quaternion(
float x,
float y,
float z,
float w) :
28 _arr = { x, y, z, w };
31 Quaternion
operator*(
const Quaternion& q)
const
34 _arr[0] * q._arr[3] + _arr[3] * q._arr[0] + _arr[1] * q._arr[2] - _arr[2] * q._arr[1],
35 _arr[1] * q._arr[3] + _arr[3] * q._arr[1] + _arr[2] * q._arr[0] - _arr[0] * q._arr[2],
36 _arr[2] * q._arr[3] + _arr[3] * q._arr[2] + _arr[0] * q._arr[1] - _arr[1] * q._arr[0],
37 _arr[3] * q._arr[3] - _arr[0] * q._arr[0] - _arr[1] * q._arr[1] - _arr[2] * q._arr[2]
43 float l = 1.f /
getMagnitude() * (_arr[3] < 0 ? -1.f : 1.f);
44 return { _arr[0] * l, _arr[1] * l, _arr[2] * l, _arr[3] * l };
47 static Quaternion createFromAxisAngle(
const Vector3& v,
float a)
49 float s = std::sin(a * 0.5f);
50 return Quaternion(v[0] * s, v[1] * s, v[2] * s, std::cos(a * 0.5f));
56 static const Quaternion IDENTITY;
61class MX_RENDER_API Vector3d :
public VectorN<Vector3d, double, 3>
64 using VectorN<Vector3d, double, 3>::VectorN;
66 Vector3d(
double x,
double y,
double z) : VectorN(
Uninit{})
74class MX_RENDER_API Vector4d :
public VectorN<Vector4d, double, 4>
77 using VectorN<Vector4d, double, 4>::VectorN;
79 Vector4d(
double x,
double y,
double z,
double w) : VectorN(
Uninit{})
81 _arr = { x, y, z, w };
87class MX_RENDER_API Color3d :
public VectorN<Color3d, double, 3>
90 using VectorN<Color3d, double, 3>::VectorN;
92 Color3d(
double r,
double g,
double b) : VectorN(
Uninit{})
101class MX_RENDER_API Half
104 explicit Half(
float value) : _data(toFloat16(value)) { }
105 operator float()
const {
return toFloat32(_data); }
107 bool operator==(Half rhs)
const {
return float(*
this) == float(rhs); }
108 bool operator!=(Half rhs)
const {
return float(*
this) != float(rhs); }
109 bool operator<(Half rhs)
const {
return float(*
this) < float(rhs); }
110 bool operator>(Half rhs)
const {
return float(*
this) > float(rhs); }
111 bool operator<=(Half rhs)
const {
return float(*
this) <= float(rhs); }
112 bool operator>=(Half rhs)
const {
return float(*
this) >= float(rhs); }
114 Half
operator+(Half rhs)
const {
return Half(
float(*
this) +
float(rhs)); }
115 Half
operator-(Half rhs)
const {
return Half(
float(*
this) -
float(rhs)); }
116 Half
operator*(Half rhs)
const {
return Half(
float(*
this) *
float(rhs)); }
117 Half
operator/(Half rhs)
const {
return Half(
float(*
this) /
float(rhs)); }
119 Half&
operator+=(Half rhs) {
return operator=(*
this + rhs); }
120 Half&
operator-=(Half rhs) {
return operator=(*
this - rhs); }
121 Half&
operator*=(Half rhs) {
return operator=(*
this * rhs); }
122 Half&
operator/=(Half rhs) {
return operator=(*
this / rhs); }
124 Half
operator-()
const {
return Half(-
float(*
this)); }
134 static constexpr int const shift = 13;
135 static constexpr int const shiftSign = 16;
137 static constexpr int32_t
const infN = 0x7F800000;
138 static constexpr int32_t
const maxN = 0x477FE000;
139 static constexpr int32_t
const minN = 0x38800000;
140 static constexpr int32_t
const signN = (int32_t) 0x80000000;
142 static constexpr int32_t
const infC = infN >> shift;
143 static constexpr int32_t
const nanN = (infC + 1) << shift;
144 static constexpr int32_t
const maxC = maxN >> shift;
145 static constexpr int32_t
const minC = minN >> shift;
146 static constexpr int32_t
const signC = (int32_t) 0x00008000;
148 static constexpr int32_t
const mulN = 0x52000000;
149 static constexpr int32_t
const mulC = 0x33800000;
151 static constexpr int32_t
const subC = 0x003FF;
152 static constexpr int32_t
const norC = 0x00400;
154 static constexpr int32_t
const maxD = infC - maxC - 1;
155 static constexpr int32_t
const minD = minC - subC - 1;
157 static constexpr int32_t
const maxF = 0x7FFFFFBF;
159 static uint16_t toFloat16(
float value)
163 uint32_t sign = (uint32_t) (v.si & signN);
167 int32_t subN = (int32_t) std::min(s.f * v.f, (
float) maxF);
168 v.si ^= (subN ^ v.si) & -(minN > v.si);
169 v.si ^= (infN ^ v.si) & -((infN > v.si) & (v.si > maxN));
170 v.si ^= (nanN ^ v.si) & -((nanN > v.si) & (v.si > infN));
172 v.si ^= ((v.si - maxD) ^ v.si) & -(v.si > maxC);
173 v.si ^= ((v.si - minD) ^ v.si) & -(v.si > subC);
174 return (uint16_t) (v.ui | sign);
177 static float toFloat32(uint16_t value)
181 int32_t sign = v.si & signC;
184 v.si ^= ((v.si + minD) ^ v.si) & -(v.si > subC);
185 v.si ^= ((v.si + maxD) ^ v.si) & -(v.si > maxC);
189 int32_t mask = (norC > v.si) ? -1 : 1;
191 v.si ^= (s.si ^ v.si) & mask;
200MATERIALX_NAMESPACE_END
Macros for declaring imported and exported symbols.
A 4x4 matrix of floating-point values.
Definition Types.h:656
A tag class for constructing vectors and matrices without initialization.
Definition Types.h:48
A vector of three floating-point values.
Definition Types.h:306
A vector of four floating-point values.
Definition Types.h:328
VectorN & operator+=(const V &rhs)
Component-wise addition of two vectors.
Definition Types.h:108
bool operator!=(const V &rhs) const
Return true if the given vector differs from this one.
Definition Types.h:76
V operator+(const V &rhs) const
Component-wise addition of two vectors.
Definition Types.h:99
V operator-() const
Unary negation of a vector.
Definition Types.h:201
V operator*(const V &rhs) const
Component-wise multiplication of two vectors.
Definition Types.h:133
V operator/(const V &rhs) const
Component-wise division of two vectors.
Definition Types.h:150
VectorN & operator*=(const V &rhs)
Component-wise multiplication of two vectors.
Definition Types.h:142
bool operator<(const V &rhs) const
Compare two vectors lexicographically.
Definition Types.h:79
bool operator==(const V &rhs) const
Return true if the given vector is identical to this one.
Definition Types.h:73
VectorN & operator-=(const V &rhs)
Component-wise subtraction of two vectors.
Definition Types.h:125
V getNormalized() const
Return a normalized vector.
Definition Types.h:223
S getMagnitude() const
Return the magnitude of the vector.
Definition Types.h:214
VectorN & operator/=(const V &rhs)
Component-wise division of two vectors.
Definition Types.h:159