SH4ZAM! 0.9.1
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
 
Rotations

Routines for rotating a given vector.

Warning
These should only be used for one-off rotations, as it's much faster to apply the same rotation against a batch of multiple vectors by going through the XMTRX API.
vec3 rotate_x (float angle) const noexcept
 
vec3 rotate_y (float angle) const noexcept
 
vec3 rotate_z (float angle) 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
 
T to () const noexcept
 
CppType & deref (const auto *raw) noexcept
 
CppType & operator+= (const CppType &other) noexcept
 
CppType & operator-= (const CppType &other) noexcept
 
CppType & operator*= (const CppType &other) noexcept
 
CppType & operator*= (float other) noexcept
 
CppType & operator/= (const CppType &other) noexcept
 
CppType & operator/= (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
 
CppType inv_sqrtf () const noexcept
 
CppType sqrtf () 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 475 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 489 of file shz_vector.hpp.

489 :
490 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 493 of file shz_vector.hpp.

493 :
494 vecN(shz_vec3_fill(v)) {}
shz_vec3_t shz_vec3_fill(float v) 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 497 of file shz_vector.hpp.

497 :
498 vecN(shz_vec3_init(x, y, z)) {}
shz_vec3_t shz_vec3_init(float x, float y, float z) 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 501 of file shz_vector.hpp.

501 :
502 vecN(shz_vec2_vec3(xy, z)) {}
shz_vec3_t shz_vec2_vec3(shz_vec2_t vec, float z) 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 505 of file shz_vector.hpp.

505 :
506 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 509 of file shz_vector.hpp.

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

Member Function Documentation

◆ rotate_x()

vec3 shz::vec3::rotate_x ( float angle) const
inlinenoexcept

Rotates a 3D vector about the X axis by the given number of radians.

See also
shz::xmtrx::apply_rotation_x()

Definition at line 525 of file shz_vector.hpp.

525 {
526 return shz_vec3_rotate_x(*this, angle);
527 }
shz_vec3_t shz_vec3_rotate_x(shz_vec3_t vec, float radians) noexcept
Rotates the given 3D vector about the X axis by the given angle in radians.

◆ rotate_y()

vec3 shz::vec3::rotate_y ( float angle) const
inlinenoexcept

Rotates a 3D vector about the Y axis by the given number of radians.

See also
shz::xmtrx::apply_rotation_y()

Definition at line 533 of file shz_vector.hpp.

533 {
534 return shz_vec3_rotate_y(*this, angle);
535 }
shz_vec3_t shz_vec3_rotate_y(shz_vec3_t vec, float radians) noexcept
Rotates the given 3D vector about the Y axis by the given angle in radians.

◆ rotate_z()

vec3 shz::vec3::rotate_z ( float angle) const
inlinenoexcept

Rotates a 3D vector about the Z axis by the given number of radians.

See also
shz::xmtrx::apply_rotation_z()

Definition at line 541 of file shz_vector.hpp.

541 {
542 return shz_vec3_rotate_z(*this, angle);
543 }
shz_vec3_t shz_vec3_rotate_z(shz_vec3_t vec, float radians) noexcept
Rotates the given 3D vector about the Z axis by the given angle in radians.

◆ 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 547 of file shz_vector.hpp.

547 {
548 vec3 out1, out2;
549 shz_vec3_orthonormalize(in1, in2, &out1, &out2);
550 return std::make_pair(out1, out2);
551 }
void shz_vec3_orthonormalize(shz_vec3_t in1, shz_vec3_t in2, shz_vec3_t *out1, shz_vec3_t *out2) 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 554 of file shz_vector.hpp.

554 {
555 shz_vec3_orthonormalize(in1, in2, out1, out2);
556 }

◆ 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 559 of file shz_vector.hpp.

559 {
560 return shz_vec3_cubic_hermite(v1, tangent1, v2, tangent2, amount);
561 }
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) noexcept
Calculates the cubic hermite interpolation between two vectors and their tangents.

◆ xy()

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

Definition at line 564 of file shz_vector.hpp.

564 {
565 return shz_vec3_t::xy;
566 }
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 569 of file shz_vector.hpp.

569 {
570 return shz_vec3_from_angles(azimuth_rads, elevation_rads);
571 }
shz_vec3_t shz_vec3_from_angles(float azimuth, float elevation) 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 574 of file shz_vector.hpp.

574 {
575 return shz_vec3_from_angles_deg(azimuth_deg, elevation_deg);
576 }
shz_vec3_t shz_vec3_from_angles_deg(float azimuth, float elevation) 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 579 of file shz_vector.hpp.

579 {
580 return shz_vec3_cross(*this, other);
581 }
shz_vec3_t shz_vec3_cross(shz_vec3_t vec1, shz_vec3_t vec2) 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 584 of file shz_vector.hpp.

584 {
585 return shz_vec3_triple(*this, b, c);
586 }
float shz_vec3_triple(shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) 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 589 of file shz_vector.hpp.

589 {
590 return shz_vec3_perp(*this);
591 }
shz_vec3_t shz_vec3_perp(shz_vec3_t vec) 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 594 of file shz_vector.hpp.

594 {
595 return shz_vec3_reject(*this, onto);
596 }
shz_vec3_t shz_vec3_reject(shz_vec3_t vec, shz_vec3_t onto) 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 599 of file shz_vector.hpp.

599 {
600 return shz_vec3_barycenter(*this, a, b, c);
601 }
shz_vec3_t shz_vec3_barycenter(shz_vec3_t p, shz_vec3_t a, shz_vec3_t b, shz_vec3_t c) 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 265 of file shz_vector.hpp.

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

◆ 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 270 of file shz_vector.hpp.

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

◆ 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 273 of file shz_vector.hpp.

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

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