34 AI_DEVICE
constexpr AtVector(
float x,
float y,
float z) : x(x), y(y), z(z) { }
51 AI_DEVICE
constexpr AtVector operator+(
float f)
const
58 AI_DEVICE
AtVector& operator+=(
float f)
81 AI_DEVICE
constexpr AtVector operator-(
float f)
const
88 AI_DEVICE
AtVector& operator-=(
float f)
96 AI_DEVICE
constexpr AtVector operator-()
const
116 AI_DEVICE
constexpr AtVector operator*(
float f)
const
123 AI_DEVICE
AtVector operator*=(
float f)
146 AI_DEVICE
AtVector operator/(
float f)
const
153 AI_DEVICE
AtVector operator/=(
float f)
161 AI_DEVICE
constexpr bool operator==(
const AtVector& p)
const
163 return (x == p.x && y == p.y && z == p.z);
166 AI_DEVICE
constexpr bool operator!=(
const AtVector& p)
const
168 return !(*
this == p);
171 AI_DEVICE
AtVector& operator=(
float f)
179 AI_DEVICE
float& operator[](
unsigned int i)
184 AI_DEVICE
constexpr const float& operator[](
unsigned int i)
const
259 AI_DEVICE
constexpr AtVector2(
float x,
float y) : x(x), y(y) { }
276 AI_DEVICE
constexpr AtVector2 operator+(
float f)
const
302 AI_DEVICE
constexpr AtVector2 operator-(
float f)
const
315 AI_DEVICE
constexpr AtVector2 operator-()
const
333 AI_DEVICE
constexpr AtVector2 operator*(
float f)
const
359 AI_DEVICE
AtVector2 operator/(
float f)
const
372 AI_DEVICE
constexpr bool operator==(
const AtVector2& p)
const
374 return (x == p.x && y == p.y);
377 AI_DEVICE
constexpr bool operator!=(
const AtVector2& p)
const
379 return !(*
this == p);
389 AI_DEVICE
float& operator[](
unsigned int i)
394 AI_DEVICE
constexpr const float& operator[](
unsigned int i)
const
469 AI_DEVICE
constexpr AtHPoint(
float x,
float y,
float z,
float w) : x(x), y(y), z(z), w(w) { }
470 AI_DEVICE
constexpr AtHPoint(
const AtVector& v,
float w) : x(v.x), y(v.y), z(v.z), w(w) { }
488 AI_DEVICE
constexpr AtHPoint operator*(
float k)
const
496 AI_DEVICE
constexpr AtHPoint operator-()
const
520 AI_DEVICE
constexpr explicit AtVectorDv(
AtVector val) : val(val), dx(0, 0, 0), dy(0, 0, 0) { }
522 AI_DEVICE
constexpr AtVectorDv operator-()
const
547 return v1.x * v2.x + v1.y * v2.y;
555 return sqrtf(v1.x * v1.x + v1.y * v1.y);
563 return sqrtf(
AiSqr(p1.x-p2.x) +
AiSqr(p1.y - p2.y));
589 return AtVector2( std::abs(a.x), std::abs(a.y) );
597 return AiMax(a.x, a.y);
605 return AiMin(a.x, a.y);
620 return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z);
628 return a.x*b.x + a.y*b.y + a.z*b.z;
660 return AtVector(a.y * b.z - a.z * b.y,
661 a.z * b.x - a.x * b.z,
662 a.x * b.y - a.y * b.x);
671 return len == 0 ? a : a / len;
718 return AtVector( std::abs(a.x), std::abs(a.y), std::abs(a.z) );
726 return AiMax(a.x, a.y, a.z);
734 return AiMin(a.x, a.y, a.z);
742 float c = 1 - (a + b);
743 return c*p0 + a*p1 + b*p2;
756 return std::abs(a.x) < epsilon && std::abs(a.y) < epsilon && std::abs(a.z) < epsilon;
764 a = u * a.x + v * a.y + w * a.z;
770AI_DEVICE
inline void AiBerpUV(
float a,
float b,
float u0,
float v0,
float u1,
float v1,
float u2,
float v2,
float* u,
float* v)
772 float c = 1.0f - (a + b);
773 *u = c * u0 + a * u1 + b * u2;
774 *v = c * v0 + a * v1 + b * v2;
868#ifdef AI_CPU_COMPILER
869static constexpr const AtVector AI_P3_ZERO( 0.0f, 0.0f, 0.0f);
870static constexpr const AtVector AI_V3_ZERO( 0.0f, 0.0f, 0.0f);
871static constexpr const AtVector AI_V3_HALF( 0.5f, 0.5f, 0.5f);
872static constexpr const AtVector AI_V3_ONE ( 1.0f, 1.0f, 1.0f);
873static constexpr const AtVector AI_V3_X ( 1.0f, 0.0f, 0.0f);
874static constexpr const AtVector AI_V3_Y ( 0.0f, 1.0f, 0.0f);
875static constexpr const AtVector AI_V3_Z ( 0.0f, 0.0f, 1.0f);
876static constexpr const AtVector AI_V3_NEGX(-1.0f, 0.0f, 0.0f);
877static constexpr const AtVector AI_V3_NEGY( 0.0f, -1.0f, 0.0f);
878static constexpr const AtVector AI_V3_NEGZ( 0.0f, 0.0f, -1.0f);
879static constexpr const AtVector2 AI_P2_ZERO( 0.0f, 0.0f);
880static constexpr const AtVector2 AI_P2_ONE ( 1.0f, 1.0f);
882static __device__
const AtVector AI_P3_ZERO( 0.0f, 0.0f, 0.0f);
883static __device__
const AtVector AI_V3_ZERO( 0.0f, 0.0f, 0.0f);
884static __device__
const AtVector AI_V3_HALF( 0.5f, 0.5f, 0.5f);
885static __device__
const AtVector AI_V3_ONE ( 1.0f, 1.0f, 1.0f);
886static __device__
const AtVector AI_V3_X ( 1.0f, 0.0f, 0.0f);
887static __device__
const AtVector AI_V3_Y ( 0.0f, 1.0f, 0.0f);
888static __device__
const AtVector AI_V3_Z ( 0.0f, 0.0f, 1.0f);
889static __device__
const AtVector AI_V3_NEGX(-1.0f, 0.0f, 0.0f);
890static __device__
const AtVector AI_V3_NEGY( 0.0f, -1.0f, 0.0f);
891static __device__
const AtVector AI_V3_NEGZ( 0.0f, 0.0f, -1.0f);
892static __device__
const AtVector2 AI_P2_ZERO( 0.0f, 0.0f);
893static __device__
const AtVector2 AI_P2_ONE ( 1.0f, 1.0f);
DLL export prefix for API functions (necessary for multi-platform development)
Various useful constants.
#define AI_EPSILON
System epsilon value
Definition: ai_constants.h:41
AI_DEVICE constexpr T1 AiLerp(T2 t, T1 a, T1 b)
Linear interpolation between 'a' and 'b' using 't' (0<=t<=1)
Definition: ai_math.h:119
AI_DEVICE constexpr T AiClamp(T v, T lo, T hi)
Clamp the input to the specified range.
Definition: ai_math.h:101
AI_DEVICE constexpr T AiMin(T a, T b)
Minimum of 'a' and 'b'.
Definition: ai_math.h:30
AI_DEVICE constexpr T AiSqr(T a)
Square of 'a'.
Definition: ai_math.h:92
AI_DEVICE constexpr T AiMax(T a, T b)
Maximum of 'a' and 'b'.
Definition: ai_math.h:43
AI_DEVICE constexpr AtVector AiV3Min(const AtVector &a, const AtVector &b)
Minimum of two vectors, component-wise.
Definition: ai_vector.h:696
AI_DEVICE constexpr float AiV3Dot(const AtVector &a, const AtVector &b)
Dot product: <a, b>
Definition: ai_vector.h:626
AI_DEVICE constexpr float AiV3DistPlane(const AtVector &x, const AtVector &p, const AtVector &n)
Signed distance between point x and a plane defined by point p and normalized vector n.
Definition: ai_vector.h:650
AI_DEVICE AtVector2 ABS(const AtVector2 &a)
Absolute value of each component.
Definition: ai_vector.h:587
AI_DEVICE constexpr float AiV3Dist2(const AtVector &a, const AtVector &b)
Squared distance between two points: ||a-b||^2.
Definition: ai_vector.h:642
AI_DEVICE AtHPoint AiV4CreatePoint(const AtVector &v)
Create a 4D point: pout = (v.x, v.y, v.z, 1)
Definition: ai_vector.h:786
AI_DEVICE float AiMaxElement(const AtVector2 &a)
Element-wise max.
Definition: ai_vector.h:595
AI_DEVICE constexpr AtVector AiV3Max(const AtVector &a, const AtVector &b)
Maximum of two vectors, component-wise.
Definition: ai_vector.h:706
AI_DEVICE constexpr float AiV2Dot(const AtVector2 &v1, const AtVector2 &v2)
Dot product: <v1, v2>
Definition: ai_vector.h:545
AI_DEVICE float AiV2Length(const AtVector2 &v1)
Vector Length: ||v1||.
Definition: ai_vector.h:553
AI_DEVICE AtVector AiBerpXYZ(float a, float b, const AtVector &p0, const AtVector &p1, const AtVector &p2)
Barycentric interpolation of a point inside a triangle.
Definition: ai_vector.h:740
AI_DEVICE AtVector project() const
Project a homogeneous vector back into 3d: vout = vin.w != 0 ? vin * (1 / vin.w) : (0,...
Definition: ai_vector.h:504
AI_DEVICE constexpr AtVector AiV3Clamp(const AtVector &in, float lo, float hi)
Clamp each vector coordinate to the range [lo,hi].
Definition: ai_vector.h:686
constexpr AtVector2 AiV2Lerp(float t, const AtVector2 &lo, const AtVector2 &hi)
2D vector linear interpolation (t=0 -> result=lo, t=1 -> result=hi)
Definition: ai_vector.h:570
float AiV2Dist(const AtVector2 &p1, const AtVector2 &p2)
Distance between two points: ||p1-p2||.
Definition: ai_vector.h:561
void AiV4Project(AtVector &vout, const AtHPoint &vin)
Project a homogeneous vector back into 3d: vout = vin.w != 0 ? vin * (1 / vin.w) : (0,...
Definition: ai_vector.h:847
AI_API AI_DEVICE AI_PURE bool AiV3IsFinite(const AtVector &a)
Check whether a vector has all valid components (not NaN and not infinite)
Definition: ai_vector.cpp:10
void AiV4Scale(AtHPoint &vout, const AtHPoint &vin, float k)
Scale a vector by a constant: vout = vin * k.
Definition: ai_vector.h:831
void AiV4Add(AtHPoint &vout, const AtHPoint &v1, const AtHPoint &v2)
Add two vectors: vout = v1 + v2.
Definition: ai_vector.h:815
constexpr AtVector2 AiV2Clamp(const AtVector2 &in, float lo, float hi)
Clamp each vector coordinate to the range [lo,hi].
Definition: ai_vector.h:578
AI_DEVICE AtHPoint AiV4CreateVector(const AtVector &v)
Create a 4D vector: vout = (v.x, v.y, v.z, 0)
Definition: ai_vector.h:794
AI_DEVICE float AiV3Length(const AtVector &a)
Vector Length: ||a||.
Definition: ai_vector.h:618
void AiV4Sub(AtHPoint &vout, const AtHPoint &v1, const AtHPoint &v2)
Substract two vectors: vout = v1 - v2.
Definition: ai_vector.h:823
void AiV4Neg(AtHPoint &vout, const AtHPoint &vin)
Negate a vector: vout = -vin.
Definition: ai_vector.h:839
AI_DEVICE void AiV3RotateToFrame(AtVector &a, const AtVector &u, const AtVector &v, const AtVector &w)
Rotate vector a so that it aligns with frame {u,v,w}.
Definition: ai_vector.h:762
AI_DEVICE AtVector AiV3Normalize(const AtVector &a)
Normalize a vector: a / ||a||.
Definition: ai_vector.h:668
AI_API AI_DEVICE void AiV3BuildLocalFramePolar(AtVector &u, AtVector &v, const AtVector &N)
Build an orthonormal basis aligned with vector N (polar method).
Definition: ai_vector.cpp:43
AI_DEVICE constexpr AtVector AiV3Cross(const AtVector &a, const AtVector &b)
Cross product: a x b.
Definition: ai_vector.h:658
AI_DEVICE void AiBerpUV(float a, float b, float u0, float v0, float u1, float v1, float u2, float v2, float *u, float *v)
Barycentric interpolation of UV coordinates inside a 3D triangle.
Definition: ai_vector.h:770
float AiMinElement(const AtVector2 &a)
Element-wise min.
Definition: ai_vector.h:603
AI_DEVICE float AiV3Dist(const AtVector &a, const AtVector &b)
Distance between two points: ||a-b||.
Definition: ai_vector.h:634
AI_DEVICE bool AiV3IsSmall(const AtVector &a, float epsilon=AI_EPSILON)
Check for a zero vector, within a small tolerance: ||a|| < epsilon.
Definition: ai_vector.h:754
AI_DEVICE constexpr AtVector AiV3Lerp(float t, const AtVector &lo, const AtVector &hi)
3D vector linear interpolation (t=0 -> result=lo, t=1 -> result=hi)
Definition: ai_vector.h:678
AI_API AI_DEVICE void AiV3BuildLocalFrame(AtVector &u, AtVector &v, const AtVector &N)
Build an orthonormal basis aligned with vector N (Frisvad's method).
Definition: ai_vector.cpp:26
Definition: ai_comparison.h:17
Homogeneous point.
Definition: ai_vector.h:465
2D point
Definition: ai_vector.h:255
Vector with differentials.
Definition: ai_vector.h:515
3D point (single precision)
Definition: ai_vector.h:30