SH4ZAM! 0.7.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 (const shz_vec3_t &other) noexcept
 
 vec3 (float v) noexcept
 
 vec3 (float x, float y, float z) noexcept
 
 vec3 (const shz::vec2 &xy, float z) noexcept
 
 vec3 (float x, const shz::vec2 &yz) noexcept
 
 vec3 (const sincos &azimuth, const sincos &elevation) noexcept
 
vec2 xy () const noexcept
 
vec3 cross (const vec3 &other) const noexcept
 
float triple (const vec3 &b, const vec3 &c) const noexcept
 
vec3 perp () const noexcept
 
vec3 reject (const vec3 &onto) const noexcept
 
vec3 barycenter (const vec3 &a, const vec3 &b, const vec3 &c) const noexcept
 
 vecN () noexcept=default
 
 vecN (const vecN &other) noexcept=default
 
 vecN (const CType &other) noexcept
 
 vecN (const volatile CType &other) noexcept
 
float dot (const CppType &other) const noexcept
 
vec2 dot (const CppType &v1, const CppType &v2) const noexcept
 
vec3 dot (const CppType &v1, const CppType &v2, const CppType &v3) const noexcept
 
- Public Member Functions inherited from shz::vecN< vec3, shz_vec3_t, 3 >
 vecN () noexcept=default
 
 vecN (const vecN &other) noexcept=default
 
 vecN (const CType &other) noexcept
 
 vecN (const volatile CType &other) noexcept
 
to () const noexcept
 
CppTypederef (const auto *raw) noexcept
 
CppTypeoperator+= (const CppType &other) noexcept
 
CppTypeoperator-= (const CppType &other) noexcept
 
CppTypeoperator*= (const CppType &other) noexcept
 
CppTypeoperator*= (float other) noexcept
 
CppTypeoperator/= (const 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 (const CppType &other) const noexcept
 
CppType maxv (const CppType &other) const noexcept
 
float dot (const CppType &other) const noexcept
 
vec2 dot (const CppType &v1, const CppType &v2) const noexcept
 
vec3 dot (const CppType &v1, const CppType &v2, const CppType &v3) const noexcept
 
float magnitude () const noexcept
 
float magnitude_sqr () const noexcept
 
float magnitude_inv () const noexcept
 
CppType direction () const noexcept
 
CppType direction_safe () const noexcept
 
void normalize () noexcept
 
void normalize_safe () noexcept
 
CppType normalized () const noexcept
 
CppType normalized_safe () const noexcept
 
float distance (const CppType &other) const noexcept
 
float distance_sqr (const CppType &other) const noexcept
 
CppType move (const CppType &target, float maxdist) const noexcept
 
CppType reflect (const CppType &normal) const noexcept
 
CppType refract (const CppType &normal, float eta) const noexcept
 
CppType project (const CppType &onto) const noexcept
 
CppType project_safe (const CppType &onto) const noexcept
 
float angle_between (const CppType &other) const noexcept
 
auto angles () const noexcept
 

Static Public Member Functions

static auto orthonormalize (const vec3 &in1, const vec3 &in2) noexcept
 
static void orthonormalize (const vec3 &in1, const vec3 &in2, vec3 *out1, vec3 *out2) noexcept
 
static vec3 cubic_hermite (const vec3 &v1, const vec3 &tangent1, const vec3 &v2, const 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 (const CppType &start, const CppType &end, float t) noexcept
 
static CppType step (const CppType &vec, T &&edge) noexcept
 
static CppType smoothstep (const CppType &vec, T &&edge0, T &&edge1) noexcept
 
static CppType smoothstep_safe (const 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 465 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 ( const shz_vec3_t & other)
inlinenoexcept

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

Definition at line 479 of file shz_vector.hpp.

479 :
480 vecN(other) {}
vecN() noexcept=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 483 of file shz_vector.hpp.

483 :
484 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 487 of file shz_vector.hpp.

487 :
488 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 ( const shz::vec2 & xy,
float z )
inlinenoexcept

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

Definition at line 491 of file shz_vector.hpp.

491 :
492 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,
const 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 495 of file shz_vector.hpp.

495 :
496 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 ( const sincos & azimuth,
const sincos & elevation )
inlinenoexcept

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

Definition at line 499 of file shz_vector.hpp.

499 :
500 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 ( const vec3 & in1,
const vec3 & in2 )
inlinestaticnoexcept

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

Definition at line 503 of file shz_vector.hpp.

503 {
504 vec3 out1, out2;
505 shz_vec3_orthonormalize(in1, in2, &out1, &out2);
506 return std::make_pair(out1, out2);
507 }
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 ( const vec3 & in1,
const 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 510 of file shz_vector.hpp.

510 {
511 shz_vec3_orthonormalize(in1, in2, out1, out2);
512 }

◆ cubic_hermite()

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

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

Definition at line 515 of file shz_vector.hpp.

515 {
516 return shz_vec3_cubic_hermite(v1, tangent1, v2, tangent2, amount);
517 }
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 520 of file shz_vector.hpp.

520 {
521 return shz_vec3_t::xy;
522 }
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 525 of file shz_vector.hpp.

525 {
526 return shz_vec3_from_angles(azimuth_rads, elevation_rads);
527 }
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 530 of file shz_vector.hpp.

530 {
531 return shz_vec3_from_angles_deg(azimuth_deg, elevation_deg);
532 }
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 ( const vec3 & other) const
inlinenoexcept

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

Definition at line 535 of file shz_vector.hpp.

535 {
536 return shz_vec3_cross(*this, other);
537 }
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 ( const vec3 & b,
const vec3 & c ) const
inlinenoexcept

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

Definition at line 540 of file shz_vector.hpp.

540 {
541 return shz_vec3_triple(*this, b, c);
542 }
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 545 of file shz_vector.hpp.

545 {
546 return shz_vec3_perp(*this);
547 }
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 ( const vec3 & onto) const
inlinenoexcept

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

Definition at line 550 of file shz_vector.hpp.

550 {
551 return shz_vec3_reject(*this, onto);
552 }
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 ( const vec3 & a,
const vec3 & b,
const 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 555 of file shz_vector.hpp.

555 {
556 return shz_vec3_barycenter(*this, a, b, c);
557 }
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/4]

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

Default constructor, does nothing.

◆ vecN() [2/4]

shz::vecN< CRTP, C, R >::vecN ( const vecN & other)
defaultnoexcept

Default copy constructor.

◆ vecN() [3/4]

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

Converting constructor from existing C instance.

Definition at line 57 of file shz_vector.hpp.

57 :
58 CType(other) {}

◆ vecN() [4/4]

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

Converting constructor from existing volatile C instance.

Definition at line 61 of file shz_vector.hpp.

61 :
62 CType(const_cast<const CType&>(other)) {}

◆ dot() [1/3]

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

Returns the dot product of the given vector and another.

Definition at line 255 of file shz_vector.hpp.

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

◆ dot() [2/3]

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

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

Definition at line 260 of file shz_vector.hpp.

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

◆ dot() [3/3]

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

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

Definition at line 263 of file shz_vector.hpp.

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

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