32#if defined(USE_SIMD_SSE)
34#elif defined(USE_SIMD_APPLE)
36#elif defined(USE_SIMD_NEON)
53#if defined(USE_SIMD_SSE)
54 m128 = _mm_setzero_ps();
55#elif defined(USE_SIMD_APPLE)
56 m128 = simd_make_float3(0.0f, 0.0f, 0.0f);
57#elif defined(USE_SIMD_NEON)
58 m128 = vdupq_n_f32(0.0f);
66#if defined(USE_SIMD_SSE)
67 m128 = _mm_set_ps(0.0f, s, s, s);
68#elif defined(USE_SIMD_APPLE)
69 m128 = simd_make_float3(s, s, s);
70#elif defined(USE_SIMD_NEON)
71 m128 = vsetq_lane_f32(0.0f, vdupq_n_f32(s), 3);
79#if defined(USE_SIMD_SSE)
80 m128 = _mm_set_ps(0.0f,
z,
y,
x);
81#elif defined(USE_SIMD_APPLE)
82 m128 = simd_make_float3(
x,
y,
z);
83#elif defined(USE_SIMD_NEON)
84 float temp[4] = {
x,
y,
z, 0.0f };
85 m128 = vld1q_f32(temp);
95#if defined(USE_SIMD_SSE)
96 explicit Vector3(
const __m128& data) : m128(data) {}
97#elif defined(USE_SIMD_NEON)
98 explicit Vector3(
const float32x4_t& data) : m128(data) {}
101#if defined(USE_SIMD_APPLE)
102 explicit Vector3(
const simd_float4& data) : m128(simd_make_float3(data)) {}
104 explicit Vector3(
const simd_float3& data) : m128(data) {}
108#if defined(USE_SIMD_SSE)
109 m128 = _mm_set_ps(0.0f, packed[2], packed[1], packed[0]);
110#elif defined(USE_SIMD_APPLE)
111 m128 = simd_make_float3(packed[0], packed[1], packed[2]);
112#elif defined(USE_SIMD_NEON)
113 float temp[4] = { packed[0], packed[1], packed[2], 0.0f };
114 m128 = vld1q_f32(temp);
122 [[nodiscard]]
float getX()
const {
123#if defined(USE_SIMD_SSE)
124 return _mm_cvtss_f32(m128);
125#elif defined(USE_SIMD_APPLE)
127#elif defined(USE_SIMD_NEON)
128 return vgetq_lane_f32(m128, 0);
134 [[nodiscard]]
float getY()
const {
135#if defined(USE_SIMD_SSE)
136 return _mm_cvtss_f32(_mm_shuffle_ps(m128, m128, _MM_SHUFFLE(1,1,1,1)));
137#elif defined(USE_SIMD_APPLE)
139#elif defined(USE_SIMD_NEON)
140 return vgetq_lane_f32(m128, 1);
146 [[nodiscard]]
float getZ()
const {
147#if defined(USE_SIMD_SSE)
148 return _mm_cvtss_f32(_mm_shuffle_ps(m128, m128, _MM_SHUFFLE(2,2,2,2)));
149#elif defined(USE_SIMD_APPLE)
151#elif defined(USE_SIMD_NEON)
152 return vgetq_lane_f32(m128, 2);
160#if defined(USE_SIMD_SSE)
161 return Vector3(_mm_add_ps(this->m128, other.m128));
162#elif defined(USE_SIMD_APPLE)
163 return Vector3(this->m128 + other.m128);
164#elif defined(USE_SIMD_NEON)
165 return Vector3(vaddq_f32(this->m128, other.m128));
167 return Vector3(this->
x + other.
x, this->y + other.
y, this->z + other.
z);
173#if defined(USE_SIMD_SSE)
174 m128 = _mm_add_ps(m128, rhs.m128);
175#elif defined(USE_SIMD_APPLE)
176 m128 = m128 + rhs.m128;
177#elif defined(USE_SIMD_NEON)
178 m128 = vaddq_f32(m128, rhs.m128);
189#if defined(USE_SIMD_SSE)
190 return Vector3(_mm_sub_ps(this->m128, other.m128));
191#elif defined(USE_SIMD_APPLE)
192 return Vector3(this->m128 - other.m128);
193#elif defined(USE_SIMD_NEON)
194 return Vector3(vsubq_f32(this->m128, other.m128));
196 return Vector3(this->
x - other.
x, this->y - other.
y, this->z - other.
z);
202#if defined(USE_SIMD_SSE)
203 m128 = _mm_sub_ps(m128, rhs.m128);
204#elif defined(USE_SIMD_APPLE)
205 m128 = m128 - rhs.m128;
206#elif defined(USE_SIMD_NEON)
207 m128 = vsubq_f32(m128, rhs.m128);
226#if defined(USE_SIMD_APPLE)
227 return simd_length(m128);
229 return std::sqrt(
dot(*
this));
235#if defined(USE_SIMD_APPLE)
236 return simd_length_squared(m128);
244#if defined(USE_SIMD_APPLE)
245 return simd_distance(m128, other.m128);
247 return (*
this - other).length();
255#if defined(USE_SIMD_APPLE)
256 std::cout <<
"Vector3(" << m128.x <<
", " << m128.y <<
", " << m128.z <<
")\n";
257#elif defined(USE_SIMD_SSE) || defined(USE_SIMD_NEON)
258 std::cout <<
"Vector3(" <<
getX() <<
", " <<
getY() <<
", " <<
getZ() <<
")\n";
260 std::cout <<
"Vector3(" <<
x <<
", " <<
y <<
", " <<
z <<
")\n";
311 return std::sqrt(
x *
x +
y *
y +
z *
z);
318#include "vector3.inl"
std::array< float, 3 > PackedVector3f
4x4 column-major transformation matrix with SIMD acceleration.
Vector3 cross(const Vector3 &other) const
Matrix4 toScalingMatrix() const
Vector3(const float x, const float y, const float z)
Vector3 & operator+=(const Vector3 &rhs)
Vector3 normalized() const
Matrix4 toTranslationMatrix() const
Vector3 operator+(const Vector3 &other) const
float distance(const Vector3 &other) const
Vector3 operator-() const
Vector3(const Vector4 &other)
Vector3 & operator-=(const Vector3 &rhs)
Vector3 transformNormal(const Matrix4 &mat) const
Vector3 operator-(const Vector3 &other) const
float dot(const Vector3 &other) const
Vector3 transform(const Matrix4 &mat) const
Vector3(const PackedVector3f &packed)
Vector3 operator*(const Vector3 &other) const
float lengthSquared() const
Vector3 operator*(float scalar) const
Vector3T(const T x, const T y, const T z)
Vector3T< T > operator-(const Vector3T &other) const
4D vector for homogeneous coordinates, color values, and SIMD operations.