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

#include <CUIVec3.h>

Public Member Functions

 IVec3 ()
 
 IVec3 (int x, int y, int z)
 
 IVec3 (const int *array)
 
 IVec3 (const IVec3 &p1, const IVec3 &p2)
 
IVec3operator= (const int *array)
 
IVec3set (int x, int y, int z)
 
IVec3set (const int *array)
 
IVec3set (const IVec3 &v)
 
IVec3set (const IVec3 &p1, const IVec3 &p2)
 
IVec3setZero ()
 
IVec3clamp (const IVec3 &min, const IVec3 &max)
 
IVec3 getClamp (const IVec3 &min, const IVec3 &max) const
 
IVec3add (const IVec3 &v)
 
IVec3add (int x, int y, int z)
 
IVec3subtract (const IVec3 &v)
 
IVec3subtract (int x, int y, int z)
 
IVec3scale (int s)
 
IVec3scale (int sx, int sy, int sz)
 
IVec3scale (const IVec3 &v)
 
IVec3negate ()
 
IVec3 getNegation () const
 
IVec3map (std::function< int(int)> func)
 
IVec3 getMap (std::function< int(int)> func) const
 
IVec3operator+= (const IVec3 &v)
 
IVec3operator-= (const IVec3 &v)
 
IVec3operator*= (int s)
 
IVec3operator*= (const IVec3 &v)
 
const IVec3 operator+ (const IVec3 &v) const
 
const IVec3 operator- (const IVec3 &v) const
 
const IVec3 operator- () const
 
const IVec3 operator* (int s) const
 
const IVec3 operator* (const IVec3 &v) const
 
bool operator< (const IVec3 &v) const
 
bool operator<= (const IVec3 &v) const
 
bool operator> (const IVec3 &v) const
 
bool operator>= (const IVec3 &v) const
 
bool operator== (const IVec3 &v) const
 
bool operator!= (const IVec3 &v) const
 
bool under (const IVec3 &v) const
 
bool over (const IVec3 &v) const
 
bool equals (const IVec3 &v) const
 
bool isZero () const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 
 operator Vec3 () const
 
 IVec3 (const Vec3 &v)
 
IVec3operator= (const Vec3 &v)
 
IVec3operator+= (const Vec3 &v)
 
IVec3operator-= (const Vec3 &v)
 
IVec3operator*= (const Vec3 &v)
 
const IVec3 operator+ (const Vec3 &v)
 
const IVec3 operator- (const Vec3 &v)
 
const IVec3 operator* (const Vec3 &v)
 
 operator IVec2 () const
 
 IVec3 (const IVec2 &v)
 
 IVec3 (const IVec2 &v, int z)
 
IVec3operator= (const IVec2 &v)
 
 operator IVec4 () const
 
 IVec3 (const IVec4 &v)
 
IVec3operator= (const IVec4 &v)
 

Static Public Member Functions

static IVec3clamp (const IVec3 &v, const IVec3 &min, const IVec3 &max, IVec3 *dst)
 
static IVec3add (const IVec3 &v1, const IVec3 &v2, IVec3 *dst)
 
static IVec3subtract (const IVec3 &v1, const IVec3 &v2, IVec3 *dst)
 
static IVec3scale (const IVec3 &v, int s, IVec3 *dst)
 
static IVec3scale (const IVec3 &v1, const IVec3 &v2, IVec3 *dst)
 
static IVec3negate (const IVec3 &v, IVec3 *dst)
 

Public Attributes

int x
 
int y
 
int z
 

Static Public Attributes

static const IVec3 ZERO
 
static const IVec3 ONE
 

Detailed Description

This class defines a 3-element integer vector.

This class is in standard layout with fields of uniform type. This means that it is safe to reinterpret_cast objects to int arrays.

Constructor & Destructor Documentation

◆ IVec3() [1/8]

cugl::IVec3::IVec3 ( )
inline

Constructs a new vector initialized to all zeros.

◆ IVec3() [2/8]

cugl::IVec3::IVec3 ( int  x,
int  y,
int  z 
)
inline

Constructs a new vector initialized to the specified values.

Parameters
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.

◆ IVec3() [3/8]

cugl::IVec3::IVec3 ( const int *  array)
inline

Constructs a new vector from the values in the specified array.

Parameters
arrayAn array containing the elements of the vector in the order x, y, z.

◆ IVec3() [4/8]

cugl::IVec3::IVec3 ( const IVec3 p1,
const IVec3 p2 
)
inline

Constructs a vector that describes the direction between the specified points.

Parameters
p1The first point.
p2The second point.

◆ IVec3() [5/8]

cugl::IVec3::IVec3 ( const Vec3 v)
explicit

Creates a vector from the given floating point vector.

The float values are truncated.

Parameters
vThe vector to convert

◆ IVec3() [6/8]

cugl::IVec3::IVec3 ( const IVec2 v)
explicit

Creates a 3d vector from the given 2d one.

The z-value is set to 0.

Parameters
vThe vector to convert

◆ IVec3() [7/8]

cugl::IVec3::IVec3 ( const IVec2 v,
int  z 
)

Creates a 3d vector from the given 2d one.

The z-coordinate is given the appropriate value

Parameters
vThe vector to convert
zThe z-coordinate

◆ IVec3() [8/8]

cugl::IVec3::IVec3 ( const IVec4 v)
explicit

Creates a 3d vector from the given homogenous one.

The w-coordinate is dropped.

Parameters
vThe vector to convert

Member Function Documentation

◆ add() [1/3]

IVec3 & cugl::IVec3::add ( const IVec3 v)
inline

Adds the given vector to this one in place.

Parameters
vThe vector to add
Returns
A reference to this (modified) Vec3 for chaining.

◆ add() [2/3]

static IVec3 * cugl::IVec3::add ( const IVec3 v1,
const IVec3 v2,
IVec3 dst 
)
static

Adds the specified vectors and stores the result in dst.

Parameters
v1The first vector.
v2The second vector.
dstA vector to store the result in
Returns
A reference to dst for chaining

◆ add() [3/3]

IVec3 & cugl::IVec3::add ( int  x,
int  y,
int  z 
)
inline

Adds the given values to this vector.

Parameters
xThe x coordinate to add.
yThe y coordinate to add.
zThe z coordinate to add.
Returns
A reference to this (modified) Vec3 for chaining.

◆ clamp() [1/2]

IVec3 & cugl::IVec3::clamp ( const IVec3 min,
const IVec3 max 
)

Clamps this vector within the given range.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A reference to this (modified) Vec3 for chaining.

◆ clamp() [2/2]

static IVec3 * cugl::IVec3::clamp ( const IVec3 v,
const IVec3 min,
const IVec3 max,
IVec3 dst 
)
static

Clamps the specified vector within the given range and returns it in dst.

Parameters
vThe vector to clamp.
minThe minimum value.
maxThe maximum value.
dstA vector to store the result in.
Returns
A reference to dst for chaining

◆ equals()

bool cugl::IVec3::equals ( const IVec3 v) const
inline

Returns true if this vector is equal to the given vector.

Parameters
vThe vector to compare against.
Returns
True if this vector is equal to the given vector.

◆ getClamp()

IVec3 cugl::IVec3::getClamp ( const IVec3 min,
const IVec3 max 
) const
inline

Returns a copy of this vector clamped within the given range.

Note: this does not modify this vector.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
A copy of this vector clamped within the given range.

◆ getMap()

IVec3 cugl::IVec3::getMap ( std::function< int(int)>  func) const
inline

Returns a copy of this vector with func applied to each component.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h.

Parameters
funcThe function to map on the coordinates.
Returns
A copy of this vector with func applied to each component.

◆ getNegation()

IVec3 cugl::IVec3::getNegation ( ) const
inline

Returns a negated copy of this vector.

Note: This method does not modify the vector

Returns
a negated copy of this vector.

◆ isZero()

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

Returns true this vector contains all zeros.

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

◆ map()

IVec3 & cugl::IVec3::map ( std::function< int(int)>  func)
inline

Maps the given function to the vector coordinates in place.

This method supports any function that has the signature float func(float); This includes many of the functions in math.h.

Parameters
funcThe function to map on the coordinates.
Returns
A reference to this (modified) Vec3 for chaining.

◆ negate() [1/2]

IVec3 & cugl::IVec3::negate ( )
inline

Negates this vector.

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

◆ negate() [2/2]

static IVec3 * cugl::IVec3::negate ( const IVec3 v,
IVec3 dst 
)
static

Negates the specified vector and stores the result in dst.

Parameters
vThe vector to negate.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ operator IVec2()

cugl::IVec3::operator IVec2 ( ) const

Casts from IVec3 to IVec2.

The z-value is dropped.

◆ operator IVec4()

cugl::IVec3::operator IVec4 ( ) const

Casts from IVec3 to IVec3.

The w-coordinate is set to 0.

◆ operator std::string()

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

Cast from IVec3 to a string.

◆ operator Vec3()

cugl::IVec3::operator Vec3 ( ) const

Cast from IVec3 to a Vec3.

◆ operator!=()

bool cugl::IVec3::operator!= ( const IVec3 v) const
inline

Returns true if this vector is not equal to the given vector.

Parameters
vThe vector to compare against.
Returns
True if this vector is not equal to the given vector.

◆ operator*() [1/3]

const IVec3 cugl::IVec3::operator* ( const IVec3 v) const
inline

Returns the scalar product of this vector with the given vector.

This method is provided to support non-uniform scaling. Note: this does not modify this vector.

Parameters
vThe vector to scale by.
Returns
The scalar product of this vector with the given vector.

◆ operator*() [2/3]

const IVec3 cugl::IVec3::operator* ( const Vec3 v)

Returns the scalar product of this vector with the given vector.

The float values of v are truncated.

Note: this does not modify this vector.

Parameters
vThe vector to scale by.
Returns
The scalar product of this vector with the given vector.

◆ operator*() [3/3]

const IVec3 cugl::IVec3::operator* ( int  s) const
inline

Returns the scalar product of this vector with the given value.

Note: this does not modify this vector.

Parameters
sThe value to scale by.
Returns
The scalar product of this vector with the given value.

◆ operator*=() [1/3]

IVec3 & cugl::IVec3::operator*= ( const IVec3 v)
inline

Scales this vector nonuniformly by the given vector.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) IVec3 for chaining.

◆ operator*=() [2/3]

IVec3 & cugl::IVec3::operator*= ( const Vec3 v)

Scales this vector nonuniformly by the given vector.

The float values of v are truncated.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) Vec2 for chaining.

◆ operator*=() [3/3]

IVec3 & cugl::IVec3::operator*= ( int  s)
inline

Scales this vector in place by the given factor.

Parameters
sThe value to scale by
Returns
A reference to this (modified) IVec3 for chaining.

◆ operator+() [1/2]

const IVec3 cugl::IVec3::operator+ ( const IVec3 v) const
inline

Returns the sum of this vector with the given vector.

Note: this does not modify this vector.

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

◆ operator+() [2/2]

const IVec3 cugl::IVec3::operator+ ( const Vec3 v)

Returns the sum of this vector with the given vector.

The float values of v are truncated.

Note: this does not modify this vector.

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

◆ operator+=() [1/2]

IVec3 & cugl::IVec3::operator+= ( const IVec3 v)
inline

Adds the given vector to this one in place.

Parameters
vThe vector to add
Returns
A reference to this (modified) IVec3 for chaining.

◆ operator+=() [2/2]

IVec3 & cugl::IVec3::operator+= ( const Vec3 v)

Adds the given vector to this one in place.

The float values of v are truncated.

Parameters
vThe vector to add
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator-() [1/3]

const IVec3 cugl::IVec3::operator- ( ) const
inline

Returns the negation of this vector.

Note: this does not modify this vector.

Returns
The negation of this vector.

◆ operator-() [2/3]

const IVec3 cugl::IVec3::operator- ( const IVec3 v) const
inline

Returns the difference of this vector with the given vector.

Note: this does not modify this vector.

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

◆ operator-() [3/3]

const IVec3 cugl::IVec3::operator- ( const Vec3 v)

Returns the difference of this vector with the given vector.

The float values of v are truncated.

Note: this does not modify this vector.

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

◆ operator-=() [1/2]

IVec3 & cugl::IVec3::operator-= ( const IVec3 v)
inline

Subtracts the given vector from this one in place.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) IVec3 for chaining.

◆ operator-=() [2/2]

IVec3 & cugl::IVec3::operator-= ( const Vec3 v)

Subtracts the given vector from this one in place.

The float values of v are truncated.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) IVec2 for chaining.

◆ operator<()

bool cugl::IVec3::operator< ( const IVec3 v) const
inline

Returns true if this vector is less than the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().

Parameters
vThe vector to compare against.
Returns
True if this vector is less than the given vector.

◆ operator<=()

bool cugl::IVec3::operator<= ( const IVec3 v) const
inline

Returns true if this vector is less than or equal the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are less than those of v, use the method under().

Parameters
vThe vector to compare against.
Returns
True if this vector is less than or equal the given vector.

◆ operator=() [1/4]

IVec3 & cugl::IVec3::operator= ( const int *  array)
inline

Sets the elements of this vector from the values in the specified array.

Parameters
arrayAn array containing the elements of the vector in the order x, y, z.
Returns
A reference to this (modified) IVec3 for chaining.

◆ operator=() [2/4]

IVec3 & cugl::IVec3::operator= ( const IVec2 v)

Sets the coordinates of this vector to those of the given 2d vector.

The z-value is set to 0.

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

◆ operator=() [3/4]

IVec3 & cugl::IVec3::operator= ( const IVec4 v)

Sets the coordinates of this vector to those of the given homogenous vector.

The w-coordinate is dropped.

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

◆ operator=() [4/4]

IVec3 & cugl::IVec3::operator= ( const Vec3 v)

Sets this vector to be the given floating point vector.

The float values are truncated.

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

◆ operator==()

bool cugl::IVec3::operator== ( const IVec3 v) const
inline

Returns true if this vector is equal to the given vector.

Parameters
vThe vector to compare against.
Returns
True if this vector is equal to the given vector.

◆ operator>()

bool cugl::IVec3::operator> ( const IVec3 v) const
inline

Returns true if this vector is greater than the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().

Parameters
vThe vector to compare against.
Returns
True if this vector is greater than the given vector.

◆ operator>=()

bool cugl::IVec3::operator>= ( const IVec3 v) const
inline

Returns true if this vector is greater than or equal the given vector.

This comparison uses the lexicographical order. To test if all components in this vector are greater than those of v, use the method over().

Parameters
vThe vector to compare against.
Returns
True if this vector is greater than or equal the given vector.

◆ over()

bool cugl::IVec3::over ( const IVec3 v) const
inline

Returns true if this vector dominates the given vector.

Domination means that all components of this vector are greater than or equal to the components of the given vector.

Parameters
vThe vector to compare against.
Returns
True if this vector is dominated by the given vector.

◆ scale() [1/5]

IVec3 & cugl::IVec3::scale ( const IVec3 v)
inline

Scales this vector nonuniformly by the given vector.

Parameters
vThe vector to scale by
Returns
A reference to this (modified) Vec3 for chaining.

◆ scale() [2/5]

static IVec3 * cugl::IVec3::scale ( const IVec3 v,
int  s,
IVec3 dst 
)
static

Scales the specified vector and stores the result in dst.

The scale is uniform by the constant s.

Parameters
vThe vector to scale.
sThe uniform scaling factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ scale() [3/5]

static IVec3 * cugl::IVec3::scale ( const IVec3 v1,
const IVec3 v2,
IVec3 dst 
)
static

Scales the specified vector and stores the result in dst.

The scale is nonuniform by the attributes in v2.

Parameters
v1The vector to scale.
v2The nonuniform scaling factor.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ scale() [4/5]

IVec3 & cugl::IVec3::scale ( int  s)
inline

Scales this vector in place by the given factor.

Parameters
sThe scalar to multiply by
Returns
A reference to this (modified) Vec3 for chaining.

◆ scale() [5/5]

IVec3 & cugl::IVec3::scale ( int  sx,
int  sy,
int  sz 
)
inline

Scales this vector nonuniformly by the given factors.

Parameters
sxThe scalar to multiply the x-axis
syThe scalar to multiply the y-axis
szThe scalar to multiply the z-axis
Returns
A reference to this (modified) Vec3 for chaining.

◆ set() [1/4]

IVec3 & cugl::IVec3::set ( const int *  array)
inline

Sets the elements of this vector from the values in the specified array.

Parameters
arrayAn array containing the elements of the vector in the order x, y, z.
Returns
A reference to this (modified) IVec3 for chaining.

◆ set() [2/4]

IVec3 & cugl::IVec3::set ( const IVec3 p1,
const IVec3 p2 
)
inline

Sets this vector to the directional vector between the specified points.

Parameters
p1The initial point of the vector.
p2The terminal point of the vector.
Returns
A reference to this (modified) Vec3 for chaining.

◆ set() [3/4]

IVec3 & cugl::IVec3::set ( const IVec3 v)
inline

Sets the elements of this vector to those in the specified vector.

Parameters
vThe vector to copy.
Returns
A reference to this (modified) Vec3 for chaining.

◆ set() [4/4]

IVec3 & cugl::IVec3::set ( int  x,
int  y,
int  z 
)
inline

Sets the elements of this vector to the specified values.

Parameters
xThe new x coordinate.
yThe new y coordinate.
zThe new z coordinate.
Returns
A reference to this (modified) IVec3 for chaining.

◆ setZero()

IVec3 & cugl::IVec3::setZero ( )
inline

Sets the elements of this vector to zero.

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

◆ subtract() [1/3]

IVec3 & cugl::IVec3::subtract ( const IVec3 v)
inline

Subtracts the given vector from this one in place.

Parameters
vThe vector to subtract
Returns
A reference to this (modified) Vec3 for chaining.

◆ subtract() [2/3]

static IVec3 * cugl::IVec3::subtract ( const IVec3 v1,
const IVec3 v2,
IVec3 dst 
)
static

Subtracts the specified vectors and stores the result in dst.

The resulting vector is computed as (v1 - v2).

Parameters
v1The first vector.
v2The second vector.
dstThe destination vector.
Returns
A reference to dst for chaining

◆ subtract() [3/3]

IVec3 & cugl::IVec3::subtract ( int  x,
int  y,
int  z 
)
inline

Subtracts the given values from this vector.

Parameters
xThe x coordinate to subtract.
yThe y coordinate to subtract.
zThe z coordinate to subtract.
Returns
A reference to this (modified) Vec3 for chaining.

◆ toString()

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

Returns a string representation of this vector for debuggging 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 debuggging purposes.

◆ under()

bool cugl::IVec3::under ( const IVec3 v) const
inline

Returns true if this vector is dominated by the given vector.

Domination means that all components of the given vector are greater than or equal to the components of this one.

Parameters
vThe vector to compare against.
Returns
True if this vector is dominated by the given vector.

Member Data Documentation

◆ ONE

const IVec3 cugl::IVec3::ONE
static

The ones vector IVec3(1,1,1)

◆ x

int cugl::IVec3::x

The x-coordinate.

◆ y

int cugl::IVec3::y

The y-coordinate.

◆ z

int cugl::IVec3::z

The z-coordinate.

◆ ZERO

const IVec3 cugl::IVec3::ZERO
static

The zero vector IVec3(0,0,0)


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