CUGL
2.0
|
#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) |
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)).
|
inline |
Construct the zero vector: (0,0,0).
Definition at line 610 of file cugl.h.
Referenced by operator-().
|
inline |
|
inline |
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.
points | is an array of points. |
numPoints | is the number of points in the array. |
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.
|
inlineexplicit |
Construct a vector from a quaternion by ignoring the scalar component of the quaternion. Vector(q) constructs the vector returned by q.vector()
.
q | is 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.
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.
p | is the start point for the vector. |
Definition at line 2821 of file cugl.h.
References cugl::Point::draw().
|
inline |
|
inline |
|
inline |
void cugl::Vector::normalize | ( | ) |
Normalize this vector. See also Vector::unit(). Reports error ZERO_NORM if the vector is zero.
|
inline |
|
inline |
Vector cugl::Vector::operator/ | ( | GLfloat | scale | ) | const |
Return the vector (x/scale,y/scale,z/scale). Error ZERO_DIVISOR reported if scale
is zero.
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.
|
inline |
|
inline |
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.
Referenced by cugl::Quaternion::axis(), and cugl::Plane::normal().
Displace a Point with a Vector.
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.
|
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.
|
private |
X component of vector.
Definition at line 836 of file cugl.h.
Referenced by cugl::cross(), cugl::dot(), drawNormal(), norm(), cugl::operator*(), operator*=(), cugl::operator+(), cugl::Point::operator+=(), operator+=(), operator-(), cugl::operator-(), cugl::Point::operator-=(), operator-=(), cugl::operator==(), skew(), translate(), and Vector().
|
private |
Y component of vector.
Definition at line 839 of file cugl.h.
Referenced by cugl::cross(), cugl::dot(), drawNormal(), norm(), cugl::operator*(), operator*=(), cugl::operator+(), cugl::Point::operator+=(), operator+=(), operator-(), cugl::operator-(), cugl::Point::operator-=(), operator-=(), cugl::operator==(), skew(), translate(), and Vector().
|
private |
Z component of vector.
Definition at line 842 of file cugl.h.
Referenced by cugl::cross(), cugl::dot(), drawNormal(), norm(), cugl::operator*(), operator*=(), cugl::operator+(), cugl::Point::operator+=(), operator+=(), operator-(), cugl::operator-(), cugl::Point::operator-=(), operator-=(), cugl::operator==(), skew(), translate(), and Vector().