SH4ZAM! 0.1.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz::vec3 Struct Reference

#include <shz_vector.hpp>

Inheritance diagram for shz::vec3:
Collaboration diagram for shz::vec3:

Public Member Functions

 vec3 ()=default
 
 vec3 (shz_vec3_t other) noexcept
 
 vec3 (float v) noexcept
 
 vec3 (float x, float y, float z) noexcept
 
 vec3 (shz::vec2 xy, float z) noexcept
 
 vec3 (float x, shz::vec2 yz) noexcept
 
 vec3 (sincos azimuth, sincos elevation) noexcept
 
vec2 xy () const noexcept
 
vec3 cross (vec3 other) const noexcept
 
float triple (vec3 b, vec3 c) const noexcept
 
vec3 perp () const noexcept
 
vec3 reject (vec3 onto) const noexcept
 
vec3 barycenter (vec3 a, vec3 b, vec3 c) const noexcept
 
 vecN ()=default
 
 vecN (CType other) noexcept
 
float dot (CppType other) const noexcept
 
vec2 dot (CppType v1, CppType v2) const noexcept
 
vec3 dot (CppType v1, CppType v2, CppType v3) const noexcept
 
- Public Member Functions inherited from shz::vecN< vec3, shz_vec3_t, 3 >
 vecN ()=default
 
 vecN (CType other) noexcept
 
to () const noexcept
 
CppTypederef (const auto *raw) noexcept
 
CppTypeoperator+= (CppType other) noexcept
 
CppTypeoperator-= (CppType other) noexcept
 
CppTypeoperator*= (CppType other) noexcept
 
CppTypeoperator*= (float other) noexcept
 
CppTypeoperator/= (CppType other) noexcept
 
CppTypeoperator/= (float other) noexcept
 
CppType swizzle () const noexcept
 
CppType abs () const noexcept
 
CppType neg () const noexcept
 
CppType inv () const noexcept
 
float max () const noexcept
 
float min () const noexcept
 
CppType clamp (float min, float max) const noexcept
 
CppType floor () const noexcept
 
CppType ceil () const noexcept
 
CppType round () const noexcept
 
CppType fract () const noexcept
 
CppType sign () const noexcept
 
CppType saturate () const noexcept
 
CppType minv (CppType other) const noexcept
 
CppType maxv (CppType other) const noexcept
 
float dot (CppType other) const noexcept
 
vec2 dot (CppType v1, CppType v2) const noexcept
 
vec3 dot (CppType v1, CppType v2, CppType v3) const noexcept
 
float magnitude () const noexcept
 
float magnitude_sqr () const noexcept
 
float magnitude_inv () const noexcept
 
CppType direction () const noexcept
 
void normalize () noexcept
 
CppType direction_safe () const noexcept
 
void normalize_safe () noexcept
 
float distance (const CppType &other) const noexcept
 
float distance_sqr (const CppType &other) const noexcept
 
CppType move (CppType target, float maxdist) const noexcept
 
CppType reflect (CppType normal) const noexcept
 
CppType refract (CppType normal, float eta) const noexcept
 
CppType project (CppType onto) const noexcept
 
CppType project_safe (CppType onto) const noexcept
 
float angle_between (CppType other) const noexcept
 
auto angles () const noexcept
 

Static Public Member Functions

static auto orthonormalize (vec3 in1, vec3 in2) noexcept
 
static void orthonormalize (vec3 in1, vec3 in2, vec3 *out1, vec3 *out2) noexcept
 
static vec3 cubic_hermite (vec3 v1, vec3 tangent1, vec3 v2, vec3 tangent2, float amount) noexcept
 
static vec3 from_angles (float azimuth_rads, float elevation_rads) noexcept
 
static vec3 from_angles_deg (float azimuth_deg, float elevation_deg) noexcept
 
- Static Public Member Functions inherited from shz::vecN< vec3, shz_vec3_t, 3 >
static CppType from (const auto &raw) noexcept
 
static CppType lerp (CppType start, CppType end, float t) noexcept
 
static CppType step (CppType vec, T edge) noexcept
 
static CppType smoothstep (CppType vec, T edge0, T edge1) noexcept
 
static CppType smoothstep_safe (CppType vec, T edge0, T edge1) noexcept
 

Additional Inherited Members

- Public Types inherited from shz::vecN< vec3, shz_vec3_t, 3 >
using CppType
 
using CType
 
- Data Fields inherited from shz_vec3_t
union { 
 
   float   e [3] 
 
   struct { 
 
      union { 
 
         struct { 
 
            float   x 
 
            float   y 
 
         }  
 
         shz_vec2_t   xy 
 
      }  
 
      float   z 
 
   }  
 
};  
 
- Static Public Attributes inherited from shz::vecN< vec3, shz_vec3_t, 3 >
static constexpr size_t Rows
 
static constexpr size_t Cols
 

Detailed Description

3D Vector type

C++ structure for representing a 3-dimensional vector.

See also
shz::vecN, shz_vec2_t, shz::vec2, shz::vec4

Definition at line 443 of file shz_vector.hpp.

Constructor & Destructor Documentation

◆ vec3() [1/7]

shz::vec3::vec3 ( )
default

Default constructor: does nothing.

◆ vec3() [2/7]

shz::vec3::vec3 ( shz_vec3_t other)
inlinenoexcept

C constructor: constructs a C++ vec3 from a C shz_vec3_t.

Definition at line 454 of file shz_vector.hpp.

454 :
455 vecN(other) {}
vecN()=default
Default constructor, does nothing.

◆ vec3() [3/7]

shz::vec3::vec3 ( float v)
inlinenoexcept

Single-value constructor: initializes all components to v.

Definition at line 458 of file shz_vector.hpp.

458 :
459 vecN(shz_vec3_fill(v)) {}
shz_vec3_t shz_vec3_fill(float v) SHZ_NOEXCEPT
Returns a 3D vector with the value of each compoonent equal to v.

◆ vec3() [4/7]

shz::vec3::vec3 ( float x,
float y,
float z )
inlinenoexcept

Value constructor: initializes each component to its given value.

Definition at line 462 of file shz_vector.hpp.

462 :
463 vecN(shz_vec3_init(x, y, z)) {}
shz_vec3_t shz_vec3_init(float x, float y, float z) SHZ_NOEXCEPT
Returns a 3D vector with the given x, y, and z coordinates.
float y
Y coordinate.
Definition shz_vector.h:64
float x
X coordinate.
Definition shz_vector.h:63
float z
Z coordinate.
Definition shz_vector.h:68

◆ vec3() [5/7]

shz::vec3::vec3 ( shz::vec2 xy,
float z )
inlinenoexcept

Constructs a vec3 from a shz::vec2 and a scalar value for its z component.

Definition at line 466 of file shz_vector.hpp.

466 :
467 vecN(shz_vec2_vec3(xy, z)) {}
shz_vec3_t shz_vec2_vec3(shz_vec2_t vec, float z) SHZ_NOEXCEPT
Extends a 2D vector to 3D, using z as the value of the Z component.

◆ vec3() [6/7]

shz::vec3::vec3 ( float x,
shz::vec2 yz )
inlinenoexcept

Constructs a vec3 from a scalar as its x component and a shz::vec2 as its Y and Z components.

Definition at line 470 of file shz_vector.hpp.

470 :
471 vecN(shz_vec3_init(x, yz.x, yz.y)) {}
float x
X coordinate.
Definition shz_vector.h:42
float y
Y coordinate.
Definition shz_vector.h:43

◆ vec3() [7/7]

shz::vec3::vec3 ( sincos azimuth,
sincos elevation )
inlinenoexcept

Returns a 3D vector which forms the given angles with the +X axis.

Definition at line 474 of file shz_vector.hpp.

474 :
475 vecN(shz_vec3_from_sincos(azimuth, elevation)) {}
shz_vec3_t shz_vec3_from_sincos(shz_sincos_t azimuth, shz_sincos_t elevation) SHZ_NOEXCEPT
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis.

Member Function Documentation

◆ orthonormalize() [1/2]

static auto shz::vec3::orthonormalize ( vec3 in1,
vec3 in2 )
inlinestaticnoexcept

Returns 2 3D vectors which are normalized and orthogonal to the two input vectors as a std::pair<>.

Definition at line 478 of file shz_vector.hpp.

478 {
479 vec3 out1, out2;
480 shz_vec3_orthonormalize(in1, in2, &out1, &out2);
481 return std::make_pair(out1, out2);
482 }
void shz_vec3_orthonormalize(shz_vec3_t in1, shz_vec3_t in2, shz_vec3_t *out1, shz_vec3_t *out2) SHZ_NOEXCEPT
Returns 2 3D vectors which are normalized and orthogonal to the two input vectors.
vec3()=default
Default constructor: does nothing.

◆ orthonormalize() [2/2]

static void shz::vec3::orthonormalize ( vec3 in1,
vec3 in2,
vec3 * out1,
vec3 * out2 )
inlinestaticnoexcept

Returns 2 3D vectors which are normalized and orthogonal to the two input vectors via output pointers.

Definition at line 485 of file shz_vector.hpp.

485 {
486 shz_vec3_orthonormalize(in1, in2, out1, out2);
487 }

◆ cubic_hermite()

static vec3 shz::vec3::cubic_hermite ( vec3 v1,
vec3 tangent1,
vec3 v2,
vec3 tangent2,
float amount )
inlinestaticnoexcept

Calculates the cubic hermite interpolation between two vectors and their tangents.

Definition at line 490 of file shz_vector.hpp.

490 {
491 return shz_vec3_cubic_hermite(v1, tangent1, v2, tangent2, amount);
492 }
shz_vec3_t shz_vec3_cubic_hermite(shz_vec3_t vec, shz_vec3_t tangent1, shz_vec3_t vec2, shz_vec3_t tangent2, float amounht) SHZ_NOEXCEPT
Calculates the cubic hermite interpolation between two vectors and their tangents.

◆ xy()

vec2 shz::vec3::xy ( ) const
inlinenoexcept

Definition at line 495 of file shz_vector.hpp.

495 {
496 return shz_vec3_t::xy;
497 }
shz_vec2_t xy
Inner 2D vector containing <X, Y> coords.
Definition shz_vector.h:66

◆ from_angles()

static vec3 shz::vec3::from_angles ( float azimuth_rads,
float elevation_rads )
inlinestaticnoexcept

Returns a 3D vector which forms the given angles with the +X axis, in radians.

Definition at line 500 of file shz_vector.hpp.

500 {
501 return shz_vec3_from_angles(azimuth_rads, elevation_rads);
502 }
shz_vec3_t shz_vec3_from_angles(float azimuth, float elevation) SHZ_NOEXCEPT
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in ...

◆ from_angles_deg()

static vec3 shz::vec3::from_angles_deg ( float azimuth_deg,
float elevation_deg )
inlinestaticnoexcept

Returns a 3D vector which forms the given angles with the +X axis, in degrees.

Definition at line 505 of file shz_vector.hpp.

505 {
506 return shz_vec3_from_angles_deg(azimuth_deg, elevation_deg);
507 }
shz_vec3_t shz_vec3_from_angles_deg(float azimuth, float elevation) SHZ_NOEXCEPT
Returns the 3D unit vector representing the given rotation angles relative to the positive X axis in ...

◆ cross()

vec3 shz::vec3::cross ( vec3 other) const
inlinenoexcept

Returns a 3D vector which forms the given angles with the +X axis.

Definition at line 510 of file shz_vector.hpp.

510 {
511 return shz_vec3_cross(*this, other);
512 }
shz_vec3_t shz_vec3_cross(shz_vec3_t vec1, shz_vec3_t vec2) SHZ_NOEXCEPT
Returns the vector produced by taking the cross-product of the two given 3D vectors.

◆ triple()

float shz::vec3::triple ( vec3 b,
vec3 c ) const
inlinenoexcept

Returns the 3D vector "triple product" between the given vector and vectors a and b.

Definition at line 515 of file shz_vector.hpp.

515 {
516 return shz_vec3_triple(*this, b, c);
517 }
float shz_vec3_triple(shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) SHZ_NOEXCEPT
Returns the 3D vector "triple product" between vector's a, b, and c.

◆ perp()

vec3 shz::vec3::perp ( ) const
inlinenoexcept

Returns a 3D vector which is perpendicular to this vector.

Definition at line 520 of file shz_vector.hpp.

520 {
521 return shz_vec3_perp(*this);
522 }
shz_vec3_t shz_vec3_perp(shz_vec3_t vec) SHZ_NOEXCEPT
Returns a vector which is perpendicular to the given vector.

◆ reject()

vec3 shz::vec3::reject ( vec3 onto) const
inlinenoexcept

Returns the 3D reject vector of the given vector and another.

Definition at line 525 of file shz_vector.hpp.

525 {
526 return shz_vec3_reject(*this, onto);
527 }
shz_vec3_t shz_vec3_reject(shz_vec3_t vec, shz_vec3_t onto) SHZ_NOEXCEPT
Returns the rejection of the given vector, vec, onto another vector, onto.

◆ barycenter()

vec3 shz::vec3::barycenter ( vec3 a,
vec3 b,
vec3 c ) const
inlinenoexcept

Computes the barycentric coordinates <u, v, w> for the given 3D vector, within the plane of the triangle formed by the given vertices, a, b, and c.

Definition at line 530 of file shz_vector.hpp.

530 {
531 return shz_vec3_barycenter(*this, a, b, c);
532 }
shz_vec3_t shz_vec3_barycenter(shz_vec3_t p, shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) SHZ_NOEXCEPT
Computes barycentric coordinates <u, v, w> for point p, within the plane of the triangle with vertice...

◆ vecN() [1/2]

shz::vecN< CRTP, C, R >::vecN ( )
default

Default constructor, does nothing.

◆ vecN() [2/2]

shz::vecN< CRTP, C, R >::vecN ( CType other)
inlinenoexcept

Converting constructor from existing C instance.

Definition at line 54 of file shz_vector.hpp.

54 :
55 CType(other) {}

◆ dot() [1/3]

float shz::vecN< CRTP, C, R >::dot ( CppType other) const
inlinenoexcept

Returns the dot product of the given vector and another.

Definition at line 246 of file shz_vector.hpp.

246 {
247 return shz_vec_dot(*static_cast<const CppType*>(this), other);
248 }
#define shz_vec_dot(vec1, vec2)
C type-generic vector dot product.
Definition shz_vector.h:778

◆ dot() [2/3]

vec2 shz::vecN< CRTP, C, R >::dot ( CppType v1,
CppType v2 ) const
noexcept

Returns the dot product of the given vector against two others.

Definition at line 251 of file shz_vector.hpp.

610 {
611 return shz_vec_dot2(*static_cast<const CRTP*>(this), v1, v2);
612}
#define shz_vec_dot2(l, r1, r2)
C type-generic vector chained double dot product.
Definition shz_vector.h:785

◆ dot() [3/3]

vec3 shz::vecN< CRTP, C, R >::dot ( CppType v1,
CppType v2,
CppType v3 ) const
noexcept

Returns the dot product of the given vector against three others.

Definition at line 254 of file shz_vector.hpp.

615 {
616 return shz_vec_dot3(*static_cast<const CRTP*>(this), v1, v2, v3);
617}
#define shz_vec_dot3(l, r1, r2, r3)
C type-generic vector chained triple dot product.
Definition shz_vector.h:792

The documentation for this struct was generated from the following file: