CUGL  2.0
Public Member Functions | Private Attributes | Friends | List of all members
cugl::Vector Class Reference

#include <cugl.h>

Public Member Functions

 Vector ()
 
 Vector (GLfloat x, GLfloat y, GLfloat z)
 
 Vector (GLfloat coordinates[])
 
 Vector (Point points[], int numPoints)
 
 Vector (const Point &p, const Point &q)
 
 Vector (const Quaternion &q)
 
Vector operator+= (const Vector &v)
 
Vector operator-= (const Vector &v)
 
Vector operator- () const
 
Vector operator*= (GLfloat scale)
 
Vector operator/ (GLfloat scale) const
 
Vector operator/= (GLfloat scale)
 
void normalize ()
 
Vector unit () const
 
GLfloat norm () const
 
GLfloat length () const
 
void translate () const
 
void drawNormal () const
 
Matrix skew ()
 
void draw (const Point &p=Point()) const
 
GLfloat & operator[] (int i)
 
const GLfloat & operator[] (int i) const
 

Private Attributes

GLfloat x
 
GLfloat y
 
GLfloat z
 

Friends

class Point
 
class Matrix
 
class Quaternion
 
Vector cross (const Vector &u, const Vector &v)
 
Vector operator* (const Vector &u, const Vector &v)
 
GLfloat dot (const Vector &u, const Vector &v)
 
Vector operator* (const Vector &v, GLfloat s)
 
Vector operator* (GLfloat s, const Vector &v)
 
Vector operator+ (const Vector &u, const Vector &v)
 
Vector operator- (const Vector &u, const Vector &v)
 
Point operator+ (const Vector &v, const Point &p)
 
Point operator+ (const Point &p, const Vector &v)
 
bool operator== (const Vector &x, const Vector &y)
 
bool operator!= (const Vector &x, const Vector &y)
 
std::ostream & operator<< (std::ostream &os, const Vector &v)
 

Detailed Description

An instance is a vector with 3 real components. A vector v is a 3-vector represented by three orthogonal components vx, vy, and vz. The norm of the vector v is vx*vx+vy*vy+vz*vz. The length of v is sqrt(norm(v)).

Definition at line 600 of file cugl.h.

Constructor & Destructor Documentation

cugl::Vector::Vector ( )
inline

Construct the zero vector: (0,0,0).

Definition at line 610 of file cugl.h.

Referenced by operator-().

cugl::Vector::Vector ( GLfloat  x,
GLfloat  y,
GLfloat  z 
)
inline

Construct the vector (x,y,z).

Definition at line 616 of file cugl.h.

cugl::Vector::Vector ( GLfloat  coordinates[])
inline

Construct a vector from the array coordinates.

Precondition
The array must have at least three components.

Definition at line 2731 of file cugl.h.

References x, y, and z.

cugl::Vector::Vector ( Point  points[],
int  numPoints 
)

Construct a vector normal to the polygon defined by the given points using Martin Newell's algorithm. The normal vector will be exact if the points lie in a plane, otherwise it will be a sort of average value. As with OpenGL, the vector will point in the direction from which the points are enumerated in a counter-clockwise direction.

Unlike other functions, this function does not use homogeneous coordinates. The points are assumed to have (x,y,z) coordinates; the w component is ignored.

Parameters
pointsis an array of points.
numPointsis the number of points in the array.
Returns
the vector normal to the plane defined by points.
Note
The vector is not a unit vector because it will probably be averaged with other vectors.
cugl::Vector::Vector ( const Point p,
const Point q 
)
inline

Construct a vector from two points. Vector(p, q) is equivalent to p - q.

Definition at line 2738 of file cugl.h.

References cugl::Point::w, cugl::Point::x, x, cugl::Point::y, y, cugl::Point::z, and z.

cugl::Vector::Vector ( const Quaternion q)
inlineexplicit

Construct a vector from a quaternion by ignoring the scalar component of the quaternion. Vector(q) constructs the vector returned by q.vector().

Parameters
qis the Quaternion whose vector component is to be used.

Definition at line 2754 of file cugl.h.

References cugl::Quaternion::v, x, y, and z.

Member Function Documentation

void cugl::Vector::draw ( const Point p = Point()) const
inline

Draw this vector as a line in the graphics window. The line joins P and P+V, where P is the point provided, or the origin if no point is given.

Parameters
pis the start point for the vector.

Definition at line 2821 of file cugl.h.

References cugl::Point::draw().

void cugl::Vector::drawNormal ( ) const
inline

Use this vector as a normal vector when drawing a surface. This is implemented by passing the vector to glNormal().

Definition at line 2816 of file cugl.h.

References x, y, and z.

GLfloat cugl::Vector::length ( ) const
inline

Return the length of this vector. The length of a vector is the square root of its norm.

Returns
the length of this vector.

Definition at line 2797 of file cugl.h.

References norm().

GLfloat cugl::Vector::norm ( ) const
inline

Return the norm of this vector. The norm of a vector is the sum of its squared components and is also the square of the length.

Returns
the norm of this vector.

Definition at line 2792 of file cugl.h.

References x, y, and z.

Referenced by length(), and cugl::Quaternion::norm().

void cugl::Vector::normalize ( )

Normalize this vector. See also Vector::unit(). Reports error ZERO_NORM if the vector is zero.

Note
The value of this vector is changed by this operation.
Vector cugl::Vector::operator*= ( GLfloat  scale)
inline

Multiply each component of the vector by scale.

Definition at line 2784 of file cugl.h.

References x, y, and z.

Vector cugl::Vector::operator+= ( const Vector v)
inline

Add vector v to this vector.

Definition at line 2763 of file cugl.h.

References x, y, and z.

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

Return Vector (-x,-y,-z).

Definition at line 2779 of file cugl.h.

References Vector(), x, y, and z.

Vector cugl::Vector::operator-= ( const Vector v)
inline

Subtract vector v from this vector.

Definition at line 2771 of file cugl.h.

References x, y, and z.

Vector cugl::Vector::operator/ ( GLfloat  scale) const

Return the vector (x/scale,y/scale,z/scale). Error ZERO_DIVISOR reported if scale is zero.

Returns
the Vector (x/scale,y/scale,z/scale).
Vector cugl::Vector::operator/= ( GLfloat  scale)

Divide each component of this vector by scale and return the new value. Error ZERO_DIVISOR reported if scale is zero.

GLfloat& cugl::Vector::operator[] ( int  i)

Get or set a reference to a component of this vector. v[0] is the x component; v[1] is the y component; v[2] is the z component. Error BAD_INDEX reported if i is not one of 0, 1, 2.

const GLfloat& cugl::Vector::operator[] ( int  i) const

Get a reference to a component of this vector. This form is used for const instances (v[i] cannot appear on the left of =). v[0] is the x component; v[1] is the y component; v[2] is the z component. Error BAD_INDEX reported if i is not one of 0, 1, 2.

Matrix cugl::Vector::skew ( )
inline

Construct the skew-symmetric matrix corresponding to this vector.

Definition at line 2807 of file cugl.h.

References x, y, and z.

void cugl::Vector::translate ( ) const
inline

Use this vector to translate an object. This is implemented by passing the vector to glTranslate().

Definition at line 2802 of file cugl.h.

References x, y, and z.

Vector cugl::Vector::unit ( ) const

Return a unit vector with the same direction as this vector. See also Vector::normalize(). Reports error ZERO_NORM if the vector is zero.

Note
The value of this vector is not changed by this operation.

Referenced by cugl::Quaternion::axis(), and cugl::Plane::normal().

Friends And Related Function Documentation

Vector cross ( const Vector u,
const Vector v 
)
friend

Return cross product of vectors u and v.

Definition at line 2859 of file cugl.h.

GLfloat dot ( const Vector u,
const Vector v 
)
friend

Return dot product of vectors u and v.

Definition at line 2875 of file cugl.h.

bool operator!= ( const Vector x,
const Vector y 
)
friend

Compare two vectors. This function returns false only if corresponding components are exactly equal. Values that are theoretically equal but computed in different ways are likely to be unequal according to this function.

Definition at line 2885 of file cugl.h.

Vector operator* ( const Vector u,
const Vector v 
)
friend

Return cross product of vectors u and v.

Definition at line 2867 of file cugl.h.

Vector operator* ( const Vector v,
GLfloat  s 
)
friend

Return Vector s*v.

Definition at line 2849 of file cugl.h.

Vector operator* ( GLfloat  s,
const Vector v 
)
friend

Return Vector s*v.

Definition at line 2854 of file cugl.h.

Vector operator+ ( const Vector u,
const Vector v 
)
friend

Return Vector u+v.

Definition at line 2839 of file cugl.h.

Point operator+ ( const Vector v,
const Point p 
)
friend

Displace a Point with a Vector.

Returns
Point at (p.x+p.w*v.x, p.y+p.w*v.y, p.z+p.w*v.z, p.w).

Displace a Point with a Vector. The components of the Vector are added to the corresponding components of the Point. If the Point is not in normal form, the Vector is implicitly scaled.

Returns
Point at (p.x+p.w*v.x, p.y+p.w*v.y, p.z+p.w*v.z, p.w).

Definition at line 2648 of file cugl.h.

Point operator+ ( const Point p,
const Vector v 
)
friend

Return Point p displaced by vector v.

Displace a Point with a Vector. The components of the Vector are added to the corresponding components of the Point. If the Point is not in normal form, the Vector is implicitly scaled.

Returns
Point at (p.x+p.w*v.x, p.y+p.w*v.y, p.z+p.w*v.z, p.w).

Definition at line 2643 of file cugl.h.

Vector operator- ( const Vector u,
const Vector v 
)
friend

Return Vector u-v.

Definition at line 2844 of file cugl.h.

std::ostream& operator<< ( std::ostream &  os,
const Vector v 
)
friend

Write vector to output stream as (x,y,z). Inserts the components of the vector into the output stream os in the format (x,y,z). The current settings of the stream formatting parameters are used. If a width is specified with setw(), it is applied to each coordinate, not to the vector as a whole.

bool operator== ( const Vector x,
const Vector y 
)
friend

Compare two vectors. This function returns true only if corresponding components are exactly equal. Values that are theoretically equal but computed in different ways are likely to be unequal according to this function.

Definition at line 2880 of file cugl.h.

Member Data Documentation

GLfloat cugl::Vector::x
private
GLfloat cugl::Vector::y
private
GLfloat cugl::Vector::z
private

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