#include <vec.h>
Setting Vec values | |
Vec () | |
Default constructor. Default value is (0,0,0). | |
Vec (float X, float Y, float Z) | |
Standard constructor with the x, y and z values. | |
template<class C> | Vec (const C &c) |
Vec & | operator= (const Vec &v) |
Classical = operator. | |
void | setValue (float X, float Y, 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. Typical usage would be (see also the & operator):. | |
operator const float * () const | |
Conversion operator that returns the memory address of the vector. Same as address(). . | |
Calculus | |
Vec & | operator+= (const Vec &a) |
Adds a to the vector. | |
Vec & | operator-= (const Vec &a) |
Subtracts a to the vector. | |
Vec & | operator *= (float k) |
Multiply the vector by a scalar. | |
Vec & | operator/= (float k) |
Divides the vector by a scalar. If the library was compiled with the "debug" qt CONFIG flag, complains with a zero k 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, 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, float k) |
Returns the division of the vector with a scalar. If the library was compiled with the "debug" qt CONFIG flag, complains about zero k 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. | |
float | normalize () |
Normalizes the Vec. Its previous norm is returned. If the library was compiled with the "debug" qt CONFIG flag, displays warning for null norm vectors. | |
Vec | unit () const |
Returns a unitary (normalized) representation of the vector. The original Vec is not modified. | |
Vec projection | |
void | projectOnAxis (const Vec &dir) |
void | projectOnPlane (const Vec &n) |
XML representation | |
Vec (const QDomElement &e) | |
Constructs a Vec from a QDomElement representing an XML code of the form <anyTagName x=".." y=".." z=".." />. | |
QDomElement | domElement (const QString &name, QDomDocument &doc) const |
void | initFromDOMElement (const QDomElement &e) |
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. |
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;
A Vec can directly be used as an float*
argument to OpenGL functions using such a code:
Vec pos, normal; glNormal3fv(normal); glVertex3fv(pos);
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 your type implements a []
operator
that looks like this:
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 :
See also the Quaternion and the Frame documentations.qglviewer::Vec sc = sceneCenter(); myVector.setX(sc.x); // or sc[0] myVector.setY(sc.y); // or sc[1] myVector.setZ(sc.z); // or sc[2]
|
Universal explicit converter from any class to Vec. You can use your own vector class everywhere a
|
|
Creates an XML QDomElement that represents the Vec. Use initFromDOMElement() to restore the Vec state from the resulting domElement. When saved to a file (see Qt::QDomDocument documentation) it will create a line like:
See also Quaternion::domElement(), Camera::domElement(), KeyFrameInterpolator::domElement()... |
|
Restore the Vec state from a |
|
Projects on the axis whose direction is dir (and that passes through the origin).
|
|
Projects on the plane whose normal is n and that passes through the origin.
|