CUGL 4.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
cugl::Spinor Class Reference

#include <CUSpinor.h>

Public Member Functions

 Spinor ()
 
 Spinor (float angle)
 
 Spinor (float real, float complex)
 
Spinoroperator= (float angle)
 
Spinorset (float angle)
 
Spinorset (float real, float complex)
 
Spinorset (const Spinor s)
 
Spinorscale (float t)
 
Spinoradd (const Spinor other)
 
Spinoradd (float angle)
 
Spinorsubtract (const Spinor other)
 
Spinorsubtract (float angle)
 
Spinormultiply (const Spinor other)
 
Spinoroperator*= (float t)
 
Spinoroperator*= (const Spinor other)
 
Spinoroperator+= (const Spinor other)
 
Spinoroperator+= (float angle)
 
Spinoroperator-= (const Spinor other)
 
Spinoroperator-= (float angle)
 
Spinor operator* (float t)
 
Spinor operator* (const Spinor other)
 
const Spinor operator+ (const Spinor other) const
 
Spinor operator+ (float angle)
 
Spinoroperator- (const Spinor other)
 
Spinor operator- (float angle)
 
float getAngle () const
 
bool isZero () const
 
bool isNearZero (float epsilon=CU_MATH_EPSILON) const
 
float length () const
 
float lengthSquared () const
 
Spinornormalize ()
 
Spinor getNormalization () const
 
Spinorinvert ()
 
Spinor getInverse ()
 
Spinorlerp (Spinor dst, float t)
 
Spinorslerp (Spinor dst, float t)
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 Spinor (const Vec2 &v)
 
Spinoroperator= (const Vec2 &v)
 
Spinoroperator+= (const Vec2 &right)
 
Spinoroperator-= (const Vec2 &right)
 
const Spinor operator+ (const Vec2 &right) const
 
const Spinor operator- (const Vec2 &right) const
 
 operator Vec2 () const
 

Public Attributes

float real
 
float complex
 

Detailed Description

This class represents a spinor, which is often useful for lighting.

Spinors represent an angle about the origin, but behave like a mobius strip when rotated. For information on how spinors work, see

 https://en.wikipedia.org/wiki/Spinor

For the most part, this class works like a complex number with additional methods representing the spinor characteristics.

Constructor & Destructor Documentation

◆ Spinor() [1/4]

cugl::Spinor::Spinor ( )
inline

Creates the 0 spinor

◆ Spinor() [2/4]

cugl::Spinor::Spinor ( float  angle)
inline

Creates a spinor for the given angle (in radians)

Parameters
angleThe spinor angle

◆ Spinor() [3/4]

cugl::Spinor::Spinor ( float  real,
float  complex 
)
inline

Creates a spinor with the given real and imaginary parts

Parameters
realThe real component
complexThe imaginary component

◆ Spinor() [4/4]

cugl::Spinor::Spinor ( const Vec2 v)
explicit

Creates a spinor from the given vector.

The x is converted to the real component and y to complex.

Parameters
vThe vector to convert

Member Function Documentation

◆ add() [1/2]

Spinor & cugl::Spinor::add ( const Spinor  other)
inline

Adds the given spinor to this one.

Parameters
otherThe spinor to add
Returns
A reference to this (modified) Spinor for chaining.

◆ add() [2/2]

Spinor & cugl::Spinor::add ( float  angle)

Adds the given angle to this spinor.

This is the same as adding a spinor of the given angle.

Parameters
angleThe angle to add
Returns
A reference to this (modified) Spinor for chaining.

◆ getAngle()

float cugl::Spinor::getAngle ( ) const

Returns the angle represented by this spinor

Returns
the angle represented by this spinor

◆ getInverse()

Spinor cugl::Spinor::getInverse ( )
inline

Returns the inverse of this spinor.

Returns
the inverse of this spinor.

◆ getNormalization()

Spinor cugl::Spinor::getNormalization ( ) const
inline

Returns a normalized copy of this spinor.

This method creates a copy of this spinor that is of unit length (i.e. the length of the spinor after calling this method will be 1.0f). If the spinor already has unit length or if the length of the spinor is zero, this method does nothing.

Note: this does not modify this spinor.

Returns
A normalized copy of this spinor.

◆ invert()

Spinor & cugl::Spinor::invert ( )

Sets this spinor to its inverse.

Returns
A reference to this (modified) Spinor for chaining.

◆ isNearZero()

bool cugl::Spinor::isNearZero ( float  epsilon = CU_MATH_EPSILON) const
inline

Returns true if this spinor is with tolerance of the origin.

Parameters
epsilonThe comparison tolerance
Returns
true if this spinor is with tolerance of the origin.

◆ isZero()

bool cugl::Spinor::isZero ( ) const
inline

Returns true this spinor contains all zeros.

Returns
true if this spinor contains all zeros, false otherwise.

◆ length()

float cugl::Spinor::length ( ) const
inline

Returns the length of this spinor.

Returns
The length of the spinor.

{

See also
lengthSquared}

◆ lengthSquared()

float cugl::Spinor::lengthSquared ( ) const
inline

Returns the squared spinor of this vector.

This method is faster than spinor because it does not need to compute a square root. Hence it is best to us this method when it is not necessary to get the exact length of a spinor (e.g. when simply comparing the length to a threshold value).

Returns
The squared length of the spinor.

{

See also
length}

◆ lerp()

Spinor & cugl::Spinor::lerp ( Spinor  dst,
float  t 
)

Linearly interpolates this spinor with the given end result

Parameters
dstThe target spinor
tThe interpolation factor
Returns
A reference to this (modified) Spinor for chaining

◆ multiply()

Spinor & cugl::Spinor::multiply ( const Spinor  other)

Multiplies this spinor by the given one.

Parameters
otherThe spinor to multiply
Returns
A reference to this (modified) Spinor for chaining.

◆ normalize()

Spinor & cugl::Spinor::normalize ( )

Normalizes this spinor.

This method normalizes the spinor so that it is of unit length (i.e. the length of the spinor after calling this method will be 1.0f). If the spinor already has unit length or if the length of the spinor is zero, this method does nothing.

Returns
This spinor, after the normalization occurs.

◆ operator std::string()

cugl::Spinor::operator std::string ( ) const
inline

Cast from Spinor to a string.

◆ operator Vec2()

cugl::Spinor::operator Vec2 ( ) const

Casts from Spinor to Vec2.

◆ operator*() [1/2]

Spinor cugl::Spinor::operator* ( const Spinor  other)
inline

Returns the product this spinor by the given one.

Note: this does not modify this spinor.

Parameters
otherThe spinor to multiply
Returns
The product this spinor by the given one.

◆ operator*() [2/2]

Spinor cugl::Spinor::operator* ( float  t)
inline

Returns the scale this spinor by the given factor

Note: this does not modify this spinor.

Parameters
tThe scaling factor
Returns
The scale this spinor by the given factor

◆ operator*=() [1/2]

Spinor & cugl::Spinor::operator*= ( const Spinor  other)
inline

Multiplies this spinor by the given one.

Parameters
otherThe spinor to multiply
Returns
A reference to this (modified) Spinor for chaining.

◆ operator*=() [2/2]

Spinor & cugl::Spinor::operator*= ( float  t)
inline

Scales this spinor by the given factor

Parameters
tThe scaling factor
Returns
A reference to this (modified) Spinor for chaining.

◆ operator+() [1/3]

const Spinor cugl::Spinor::operator+ ( const Spinor  other) const
inline

Returns the sum of this spinor with the given spinor.

Note: this does not modify this spinor.

Parameters
otherThe spinor to add.
Returns
The sum of this spinor with the given spinor.

◆ operator+() [2/3]

const Spinor cugl::Spinor::operator+ ( const Vec2 right) const

Returns the sum of this spinor with the given vector.

Note: this does not modify this spinor.

Parameters
rightThe vector to add.
Returns
The sum of this spinor with the given vector.

◆ operator+() [3/3]

Spinor cugl::Spinor::operator+ ( float  angle)
inline

Returns the sum of this spinor with the given angle.

This is the same as adding a spinor of the given angle. Note: this does not modify this spinor.

Parameters
angleThe angle to add
Returns
The sum of this spinor with the given angle.

◆ operator+=() [1/3]

Spinor & cugl::Spinor::operator+= ( const Spinor  other)
inline

Adds the given spinor to this one.

Parameters
otherThe spinor to add
Returns
A reference to this (modified) Spinor for chaining.

◆ operator+=() [2/3]

Spinor & cugl::Spinor::operator+= ( const Vec2 right)

Adds the given vector from this spinor in place.

Parameters
rightThe vector to add
Returns
A reference to this (modified) Spinor for chaining.

◆ operator+=() [3/3]

Spinor & cugl::Spinor::operator+= ( float  angle)
inline

Adds the given angle to this spinor.

This is the same as adding a spinor of the given angle.

Parameters
angleThe angle to add
Returns
A reference to this (modified) Spinor for chaining.

◆ operator-() [1/3]

Spinor & cugl::Spinor::operator- ( const Spinor  other)
inline

Returns the result of subtracting the given spinor from this one.

Note: this does not modify this spinor.

Parameters
otherThe spinor to subtract
Returns
The result of subtracting the given spinor from this one.

◆ operator-() [2/3]

const Spinor cugl::Spinor::operator- ( const Vec2 right) const

Returns the difference of this spinor with the given vector.

Note: this does not modify this spinor.

Parameters
rightThe vector to subtract.
Returns
The difference of this spinor with the given vector.

◆ operator-() [3/3]

Spinor cugl::Spinor::operator- ( float  angle)
inline

Returns the result of subtracting the given angle from this spinor.

This is the same as subtracting a spinor of the given angle.

Parameters
angleThe angle to subtract
Returns
The result of subtracting the given angle from this spinor.

◆ operator-=() [1/3]

Spinor & cugl::Spinor::operator-= ( const Spinor  other)
inline

Subtracts the given spinor from this one.

Parameters
otherThe spinor to subtract
Returns
A reference to this (modified) Spinor for chaining.

◆ operator-=() [2/3]

Spinor & cugl::Spinor::operator-= ( const Vec2 right)

Subtracts the given vector from this spinor in place.

Parameters
rightThe vector to subtract
Returns
A reference to this (modified) Spinor for chaining.

◆ operator-=() [3/3]

Spinor & cugl::Spinor::operator-= ( float  angle)
inline

Subtracts the given angle from this spinor.

This is the same as subtracting a spinor of the given angle.

Parameters
angleThe angle to subtract
Returns
A reference to this (modified) Spinor for chaining.

◆ operator=() [1/2]

Spinor & cugl::Spinor::operator= ( const Vec2 v)

Sets the values of this spinor to those of the given vector.

The x is converted to the real component and y to complex.

Parameters
vThe vector to convert
Returns
A reference to this (modified) Spinor for chaining.

◆ operator=() [2/2]

Spinor & cugl::Spinor::operator= ( float  angle)
inline

Sets the spinor to have the given angle (in radians)

Parameters
angleThe spinor angle
Returns
a reference to this spinor for chaining

◆ scale()

Spinor & cugl::Spinor::scale ( float  t)
inline

Scales this spinor by the given factor

Parameters
tThe scaling factor
Returns
A reference to this (modified) Spinor for chaining.

◆ set() [1/3]

Spinor & cugl::Spinor::set ( const Spinor  s)
inline

Sets the spinor to be a copy of the given one

Parameters
sThe spinor to copy.
Returns
A reference to this (modified) Spinor for chaining.

◆ set() [2/3]

Spinor & cugl::Spinor::set ( float  angle)

Sets the spinor to have the given angle (in radians)

Parameters
angleThe spinor angle
Returns
A reference to this (modified) Spinor for chaining

◆ set() [3/3]

Spinor & cugl::Spinor::set ( float  real,
float  complex 
)
inline

Sets the elements of this vector to the specified values.

Parameters
realThe real component
complexThe imaginary component
Returns
A reference to this (modified) Spinor for chaining

◆ slerp()

Spinor & cugl::Spinor::slerp ( Spinor  dst,
float  t 
)

Spherically interpolates this spinor with the given end result

Parameters
dstThe target spinor
tThe interpolation factor
Returns
A reference to this (modified) Spinor for chaining

◆ subtract() [1/2]

Spinor & cugl::Spinor::subtract ( const Spinor  other)
inline

Subtracts the given spinor from this one.

Parameters
otherThe spinor to subtract
Returns
A reference to this (modified) Spinor for chaining.

◆ subtract() [2/2]

Spinor & cugl::Spinor::subtract ( float  angle)

Subtracts the given angle from this spinor.

This is the same as subtracting a spinor of the given angle.

Parameters
angleThe angle to subtract
Returns
A reference to this (modified) Spinor for chaining.

◆ toString()

std::string cugl::Spinor::toString ( bool  verbose = false) const

Returns a string representation of this spinor for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this vector for debugging purposes.

Member Data Documentation

◆ complex

float cugl::Spinor::complex

The imaginary component

◆ real

float cugl::Spinor::real

The real component


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