ASL
Vec3_< T > Class Template Reference

Detailed Description

template<class T>
class asl::Vec3_< T >

A Vec3_ represents a vector in 3D space.

It is a template Vec3_<T> and has two predefined specializations Vec3 (float) and Vec3d (double)

This class allows operating with vectors as with primitive types via operators. It can be used together with class Matrix4 to transform vectors in space.

Vec3 a (10, 10, 0.1);
Vec3 b (-5, 1.5, 50);
Vec3 c = -a + 2.f * (b - a).normalized();
Vec3_ normalized() const
Returns a normalized version of this vector.
Definition: Vec3.h:64

There are operators for dot product (*), cross product (^) and multiplication by a scalar (*).

float angle = acos((a * b) / (a.length() * b.length()));
Vec3 trinormal = ((b - a) ^ (c - a)).normalized();
T angle(const Vec3_ &b) const
Returns the angle between this vector and b
Definition: Vec3.h:75

#include <Vec3.h>

Public Member Functions

Vec2_< T > xy () const
 Returns the x and y components as a Vec2.
 
Vec3_< T > zyx () const
 Returns this vector with components reversed (z,y,x)
 
Vec2_< T > h2c () const
 Returns the cartesian coordinates vector corresponding to this homogenous coordinates.
 
Vec3_ normalized () const
 Returns a normalized version of this vector.
 
length () const
 Returns the length of the vector.
 
length2 () const
 Returns the length of the vector squared.
 
operator! () const
 Returns the length of the vector.
 
angle (const Vec3_ &b) const
 Returns the angle between this vector and b
 
Vec3_ operator+ (const Vec3_ &b) const
 Returns this plus b
 
Vec3_ operator- (const Vec3_ &b) const
 Returns this minus b
 
Vec3_ operator^ (const Vec3_ &b) const
 Returns the cross product of this vector and b
 
operator* (const Vec3_ &b) const
 Returns the dot product of this vector and b
 
Vec3_ operator* (T r) const
 Returns this vector multiplied by scalar r
 
Vec3_ operator/ (T r) const
 Returns this vector divided by scalar r
 
Vec3_ operator% (const Vec3_ &b) const
 Returns a vector that is a component-wise product of this vector and b
 
bool operator== (const Vec3_ &b) const
 Checks if this vector is equal to b
 
bool operator!= (const Vec3_ &b) const
 Checks if this vector is not equal to b
 
void operator+= (const Vec3_ &b)
 Adds vector b to this vector.
 
void operator-= (const Vec3_ &b)
 Subtracts vector b from this vector.
 
void operator*= (T r)
 Multiplies this vector by scalar r
 
void operator/= (T r)
 Divides this vector by scalar r
 
void operator%= (const Vec3_ &b)
 Multiplies this vector by another, component-wise.
 
Vec3_ operator- () const
 Returns this vector negated.
 
bool isNull (T tol=(T) 0.000001) const
 Returns true if this vector's length is less than a given threshold (almost zero)
 
bool isParallelToVector (const Vec3_ &v2, T tol=(T) 0.000001)
 Returns true if this vector is nearly parallel to vector v2 with a given tolerance.
 

Public Attributes

x
 The x, y, z components.
 

Friends

Vec3_ operator* (T r, const Vec3_ &b)
 Returns this vector multiplied by scalar r
 

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