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

#include <cugl.h>

Public Member Functions

 Point (GLfloat x=0, GLfloat y=0, GLfloat z=0, GLfloat w=1)
 
 Point (GLfloat coordinates[])
 
 Point (const Quaternion &q)
 
GLfloat & operator[] (int i)
 
const GLfloat & operator[] (int i) const
 
void normalize ()
 
Point unit () const
 
void draw () const
 
void light (GLenum lightNum) const
 
void translate () const
 
Point operator/ (GLfloat s) const
 
Point operator+= (const Vector &v)
 
Point operator-= (const Vector &v)
 

Private Attributes

GLfloat x
 
GLfloat y
 
GLfloat z
 
GLfloat w
 

Friends

class Line
 
class Vector
 
class Matrix
 
class Plane
 
Point operator+ (const Vector &v, const Point &p)
 
Point operator+ (const Point &p, const Vector &v)
 
Point operator* (const Point &p, GLfloat s)
 
Point operator* (GLfloat s, const Point &p)
 
Vector operator- (const Point &p, const Point &q)
 
Point meet (const Line &k, const Plane &p)
 
bool operator== (const Point &p, const Point &q)
 
bool operator!= (const Point &p, const Point &q)
 
std::ostream & operator<< (std::ostream &os, const Point &p)
 
GLfloat dist (const Point &p, const Plane &s)
 
GLfloat dist (const Plane &s, const Point &p)
 
double dist (const Point &p, const Point &q)
 

Detailed Description

An instance is a point represented by four homogeneous coordinates. A point is represented by (x,y,z,w) in which each component is a GLfloat. If w=0, the point is `at infinity'. Points at infinity may be used like other points, but a few operations do not work for them. CUGL functions do not issue an error message when this happens: they simply return a default result.

A Point is in normal form if w=1. A Point may be normalized if w!=0.

Definition at line 157 of file cugl.h.

Constructor & Destructor Documentation

cugl::Point::Point ( GLfloat  x = 0,
GLfloat  y = 0,
GLfloat  z = 0,
GLfloat  w = 1 
)

Construct a point with coordinates (x, y, z, w). Default parameter values: (0,0,0,1).

Referenced by operator/().

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

Construct a Point from coordinates.

Parameters
coordinatesis an array containing at least four coordinates.
Precondition
The array must have at least four components.

Definition at line 2590 of file cugl.h.

References w, x, y, and z.

cugl::Point::Point ( const Quaternion q)

Convert a Quaternion to a Point.

Note
This is a rather peculiar operation and should not normally be used. It is intended for experiments with non-linear transformations.
Parameters
qis a quaternion.

Member Function Documentation

void cugl::Point::draw ( ) const
inline

Draw the point using glVertex4f().

Definition at line 2619 of file cugl.h.

References w, x, y, and z.

Referenced by cugl::Vector::draw().

void cugl::Point::light ( GLenum  lightNum) const
inline

Use this point as a light position. If w = 0, the light is directional, otherwise it is positional.

Parameters
lightNumspecifies which light to use: GL_LIGHT0, GL_LIGHT1, ...

Definition at line 2626 of file cugl.h.

References w, x, y, and z.

void cugl::Point::normalize ( )

Normalize a point. A Point (x,y,z,w) is in normal form if w=1.

Note
Error ZERO_DIVISOR reported if w=0.
The value of this Point is changed by this function.
Point cugl::Point::operator+= ( const Vector v)
inline

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 (x-w*v.x, y-w*v.y, z-w*v.z, w).

Definition at line 2598 of file cugl.h.

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

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

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

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

Definition at line 2606 of file cugl.h.

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

Point cugl::Point::operator/ ( GLfloat  s) const
inline

Scale a Point. Scale the coordinates of a Point by dividing by the scalar s. This is implemented by multiplying the w component of the Point by s. If s=0, the result is a Point at infinity.

Returns
the Point at (x,y,z,s*w).

Definition at line 2614 of file cugl.h.

References Point(), w, x, y, and z.

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

Access coordinates of a point.

Parameters
iis the index of the coordinate: p[0] = x, p[1] = y, p[2] = z, p[3] = w.
Note
Error BAD_INDEX reported if i is not one of {0,1,2, 3}.
const GLfloat& cugl::Point::operator[] ( int  i) const

Access coordinates of a point. This form is used with const instances (p[i] cannot appear on the left of =).

Parameters
iis the index of the coordinate: p[0] = x, p[1] = y, p[2] = z, p[3] = w.
Note
Error BAD_INDEX reported if i is not one of {0,1,2, 3}.
void cugl::Point::translate ( ) const
inline

Translate to the point using glTranslatef().

Note
If the point is at infinity (w = 0), this function has no effect.

Definition at line 2636 of file cugl.h.

References w, x, y, and z.

Point cugl::Point::unit ( ) const

Return the normalized form of a Point. A Point (x,y,z,w) is in normal form if w=1.

Note
Error ZERO_DIVISOR reported if w=0.

Friends And Related Function Documentation

GLfloat dist ( const Point p,
const Plane s 
)
friend

Return the distance between a Point and a Plane. The result has the correct magnitude only if the Point and the Plane are both in normal form. In particular, the result is incorrect if the Point is at infinity. However, the sign of the result is correct in all cases, and so it is not necessary to provide normalized arguments if only the sign is important.

Definition at line 2673 of file cugl.h.

GLfloat dist ( const Plane s,
const Point p 
)
friend

Return the distance between a Point and a Plane. The result has the correct magnitude only if the Point and the Plane are both in normal form. In particular, the result is incorrect if the Point is at infinity. However, the sign of the result is correct in all cases, and so it is not necessary to provide normalized arguments if only the sign is important.

Definition at line 2678 of file cugl.h.

double dist ( const Point p,
const Point q 
)
friend

Return the disgtance bewteen two points.

Note
Does not check that the points are normalized.

Definition at line 354 of file cugl.h.

Point meet ( const Line k,
const Plane p 
)
friend

Find the point where this line meets the plane p. Sets error BAD_LINE if the line lies within the plane.

Returns
the Point at which Line k meets Plane p.
bool operator!= ( const Point p,
const Point q 
)
friend

Compare two points. 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 2668 of file cugl.h.

Point operator* ( const Point p,
GLfloat  s 
)
friend

Scale a point.

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

Definition at line 2653 of file cugl.h.

Point operator* ( GLfloat  s,
const Point p 
)
friend

Scale a point. Multiply each of the components of the Point by s. In homogeneous coordinates, this operation does not change the ``position'' of the Point. However, it may be used, for example, to normalize a Point.

Returns
The scaled Point.

Definition at line 2658 of file cugl.h.

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

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

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 Point p,
const Point q 
)
friend

Return the vector corresponding to the displacement between the two points. This is the vector (p.x/p.w - q.x/q.w, p.y/p.w - q.y/q.w, p.z/p.w - q.z/q.w). If p or q is a point at infinity, return the zero vector.

Returns
the Vector corresponding to the displacement between the two points.

Definition at line 2831 of file cugl.h.

std::ostream& operator<< ( std::ostream &  os,
const Point p 
)
friend

Write "(x,y,z,w)" to output stream. Inserts the coordinates of the point into the output stream os in the format "(x,y,z,w)". 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 point as a whole.

bool operator== ( const Point p,
const Point q 
)
friend

Compare two points. 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 2663 of file cugl.h.

Member Data Documentation

GLfloat cugl::Point::w
private
GLfloat cugl::Point::x
private
GLfloat cugl::Point::y
private
GLfloat cugl::Point::z
private

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