Main Page | Class Hierarchy | Compound List | All functions | Search

Vec Class Reference

A 3D point and vector class. More...

List of all members.

Setting Vec values

 Vec ()
 Default constructor. Default value is (0,0,0).

 Vec (const float X, const float Y, const float Z)
 Standard constructor with the x,y and z values.

template<class C>  Vec (const C &c)
 Universal explicit converter from any class to Vec.

Vecoperator= (const Vec &v)
 Classical = operator.

void setValue (const float X, const float Y, const float Z)
 Set the current value. Faster than using operator equal with a temporary Vec(x,y,z).


Access values

float operator[] (int i) const
 Bracket operator, with a constant return value.

float & operator[] (int i)
 Bracket operator, returns an l-value.

const float * address () const
 The memory address of the vector. Useful as an argument for glVertex3fv, glNormal3fv...

 operator const float * () const
 Dereferencing operator that returns the memory address of the vector. Same as address().


Calculus

Vecoperator+= (const Vec &a)
 Adds a to the vector.

Vecoperator-= (const Vec &a)
 Subtracts a to the vector.

Vecoperator *= (float k)
 Multiply the vector by a scalar.

Vecoperator/= (float k)
 Divides the vector by a scalar. If the library was compiled with the "debug" qt CONFIG flag, tests for null value.

Vec operator+ (const Vec &a, const Vec &b)
 Returns the sum of the two vectors.

Vec operator- (const Vec &a, const Vec &b)
 Returns the difference of the two vectors.

Vec operator- (const Vec &a)
 Unary minus operator.

Vec operator * (const Vec &a, const float k)
 Returns the product of the vector with a scalar.

Vec operator * (float k, const Vec &a)
 Returns the product of the vector with a scalar.

Vec operator/ (const Vec &a, const float k)
 Returns the division of the vector with a scalar. If the library was compiled with the "debug" qt CONFIG flag, tests for null value.

bool operator!= (const Vec &a, const Vec &b)
 Comparison based on the squared norm of the difference vector, see operator==.

bool operator== (const Vec &a, const Vec &b)
 Comparison based on the squared norm of the difference vector, epsilon=1E-10.

float operator * (const Vec &a, const Vec &b)
 Dot product.

Vec cross (const Vec &a, const Vec &b)
 Cross product of the two vectors. Mind the order !

Vec operator^ (const Vec &a, const Vec &b)
 Cross product of the two vectors. See also cross().


Norm of the vector

float sqNorm () const
 Returns the squared norm of the Vec.

float norm () const
 Returns the norm of the vector.

Vecnormalize ()
 Normalizes the Vec and returns the norm value. If the library was compiled with the "debug" qt CONFIG flag, tests for null value.


Vec projection

void projectOnAxis (const Vec &dir)
 Projects on the axis whose direction is dir (and that passes through the origin).

void projectOnPlane (const Vec &n)
 Projects on the plane whose normal is n and that passes through the origin.


XML representation.

These methods are used by higher level class (Camera, KeyFrameInterpolator...) to save and restore the state of the Vec they hold.

QDomElement domElement (const QString &name, QDomDocument &doc) const
void initFromDOMElement (const QDomElement &de)

Public Attributes

float x
 The internal data representation is public. One can use v.x, v.y, v.z.

float y
 The internal data representation is public. One can use v.x, v.y, v.z.

float z
 The internal data representation is public. One can use v.x, v.y, v.z.


Detailed Description

A 3D point and vector class.

Vec is a QGLViewer internal class, used to represent 3D positions and 3D vectors. It is part of the qglviewer namespace. You can use it in your programs by specifying qglviewer::Vec, or by using the qglviewer namespace :

 using namespace qglviewer; 

Vec implements a universal explicit converter, based on the [] operator. Everywhere a const Vec& argument is expected, you can use your own 3D point type instead, as long as it implements the [] operator :

    float operator[] (const int i) const { respectively return x, y or z for i=0, 1 or 2 };

The following code is hence valid :

    // class myVector implements the [] operator
    myVector mv;
    fr.setPosition( qglviewer::Vec(mv) );
    // or if you use namespace qglviewer
    fr.setPosition( Vec(mv) );

When Vec is used as a return value, a classical float[3] version of the function is always available.

You can also convert a Vec result to your own class, using code such as :

    qglviewer::Vec sc = sceneCenter();
    myVector.x() = sc.x;    // or sc[0]
    myVector.y() = sc.y;    // or sc[1]
    myVector.z() = sc.z;    // or sc[2]
See also the Quaternion and the Frame documentation.


Constructor & Destructor Documentation

Vec  )  [inline, explicit]
 

Default constructor. Default value is (0,0,0).

Vec const float  X,
const float  Y,
const float  Z
[inline, explicit]
 

Standard constructor with the x,y and z values.

Vec const C &  c  )  [inline, explicit]
 

Universal explicit converter from any class to Vec.

      // Declared in class MyVec
      float operator[](int i) const { return (x, y or z); }

      // Then you can use
      MyVec v(...);
      camera()->setPosition( qglviewer::Vec(v) );


Member Function Documentation

const float* address  )  const [inline]
 

The memory address of the vector. Useful as an argument for glVertex3fv, glNormal3fv...

QDomElement domElement const QString &  name,
QDomDocument &  doc
const
 

Creates an XML QDomElement that represents the Vec. name is the name of the QDomElement tag. You need to provide the QDomDocument doc that will hold the resulting element. Typical usage would be:

 QDomDocument doc("myDocument");
 Vec sunPos;
 // ...
 anyNode.addElement(sunPos.domElement("sunPosition", doc));
 // ...
Use initFromDOMElement() to restore the Vec state from the resulting domElement.

See also Quaternion::domElement(), Camera::domElement(), KeyFrameInterpolator::domElement()...

void initFromDOMElement const QDomElement &  de  ) 
 

Restore the Vec state from a QDomElement created by domElement(). The QDomElement must contain the x, y and z attributes, otherwise these fields are set to 0.0.

float norm  )  const [inline]
 

Returns the norm of the vector.

Vec& normalize  )  [inline]
 

Normalizes the Vec and returns the norm value. If the library was compiled with the "debug" qt CONFIG flag, tests for null value.

Vec& operator *= float  k  )  [inline]
 

Multiply the vector by a scalar.

operator const float *  )  const [inline]
 

Dereferencing operator that returns the memory address of the vector. Same as address().

Vec& operator+= const Vec a  )  [inline]
 

Adds a to the vector.

Vec& operator-= const Vec a  )  [inline]
 

Subtracts a to the vector.

Vec& operator/= float  k  )  [inline]
 

Divides the vector by a scalar. If the library was compiled with the "debug" qt CONFIG flag, tests for null value.

Vec& operator= const Vec v  )  [inline]
 

Classical = operator.

float& operator[] int  i  )  [inline]
 

Bracket operator, returns an l-value.

float operator[] int  i  )  const [inline]
 

Bracket operator, with a constant return value.

void projectOnAxis const Vec dir  ) 
 

Projects on the axis whose direction is dir (and that passes through the origin).

Attention:
The axis direction vector must be normalized. This is checked if the library was compiled with the "debug" qt CONFIG flag.

void projectOnPlane const Vec n  ) 
 

Projects on the plane whose normal is n and that passes through the origin.

Attention:
The plane normal vector must be normalized. This is checked in the debug library release.

void setValue const float  X,
const float  Y,
const float  Z
[inline]
 

Set the current value. Faster than using operator equal with a temporary Vec(x,y,z).

float sqNorm  )  const [inline]
 

Returns the squared norm of the Vec.


Friends And Related Function Documentation

Vec cross const Vec a,
const Vec b
[friend]
 

Cross product of the two vectors. Mind the order !

float operator * const Vec a,
const Vec b
[friend]
 

Dot product.

Vec operator * float  k,
const Vec a
[friend]
 

Returns the product of the vector with a scalar.

Vec operator * const Vec a,
const float  k
[friend]
 

Returns the product of the vector with a scalar.

bool operator!= const Vec a,
const Vec b
[friend]
 

Comparison based on the squared norm of the difference vector, see operator==.

Vec operator+ const Vec a,
const Vec b
[friend]
 

Returns the sum of the two vectors.

Vec operator- const Vec a  )  [friend]
 

Unary minus operator.

Vec operator- const Vec a,
const Vec b
[friend]
 

Returns the difference of the two vectors.

Vec operator/ const Vec a,
const float  k
[friend]
 

Returns the division of the vector with a scalar. If the library was compiled with the "debug" qt CONFIG flag, tests for null value.

bool operator== const Vec a,
const Vec b
[friend]
 

Comparison based on the squared norm of the difference vector, epsilon=1E-10.

Vec operator^ const Vec a,
const Vec b
[friend]
 

Cross product of the two vectors. See also cross().


Member Data Documentation

float x
 

The internal data representation is public. One can use v.x, v.y, v.z.

float y
 

The internal data representation is public. One can use v.x, v.y, v.z.

float z
 

The internal data representation is public. One can use v.x, v.y, v.z.


Generated on Wed Feb 11 17:22:08 2004 for libQGLViewer by doxygen 1.3.3