Setting the value | |
Vec () | |
Vec (float X, float Y, float Z) | |
template<class C> | |
Vec (const C &c) | |
Vec & | operator= (const Vec &v) |
void | setValue (float X, float Y, float Z) |
Accessing the value | |
float | operator[] (int i) const |
float & | operator[] (int i) |
operator const float * () const | |
Algebraic computations | |
Vec & | operator+= (const Vec &a) |
Vec & | operator-= (const Vec &a) |
Vec & | operator *= (float k) |
Vec & | operator/= (float k) |
Vec | operator+ (const Vec &a, const Vec &b) |
Vec | operator- (const Vec &a, const Vec &b) |
Vec | operator- (const Vec &a) |
Vec | operator * (const Vec &a, float k) |
Vec | operator * (float k, const Vec &a) |
Vec | operator/ (const Vec &a, float k) |
bool | operator!= (const Vec &a, const Vec &b) |
bool | operator== (const Vec &a, const Vec &b) |
float | operator * (const Vec &a, const Vec &b) |
Vec | cross (const Vec &a, const Vec &b) |
Vec | operator^ (const Vec &a, const Vec &b) |
Norm of the vector | |
float | squaredNorm () const |
float | norm () const |
float | normalize () |
Vec | unit () const |
Projection | |
void | projectOnAxis (const Vec &direction) |
void | projectOnPlane (const Vec &normal) |
XML representation | |
Vec (const QDomElement &element) | |
QDomElement | domElement (const QString &name, QDomDocument &document) const |
void | initFromDOMElement (const QDomElement &element) |
Output stream | |
std::ostream & | operator<< (std::ostream &o, const qglviewer::Vec &) |
Public Attributes | |
float | x |
float | y |
float | z |
Vec is used as a parameter and return type by many methods of the library. It provides classical algebraic computational methods and is compatible with OpenGL:
// Draws a point located at 3.0 OpenGL units in front of the camera Vec pos = camera()->position() + 3.0 * camera()->viewDirection(); glBegin(GL_POINTS); glVertex3fv(pos); glEnd();
This makes of Vec a good candidate for representing positions and vectors in your programs. Since it is part of the qglviewer
namespace, specify qglviewer::Vec
or use 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 vector type instead, as long as it implements this operator (see the Vec(const C& c) documentation).
See also the Quaternion and the Frame documentations.
|
Default constructor. Value is set to (0,0,0). |
|
Standard constructor with the x, y and z values. |
|
Universal explicit converter from any class to Vec. You can use your own vector class everywhere a
class MyVec { // ... float operator[](int i) const { returns x, y or z when i=0, 1 or 2; } } MyVec v(...); camera()->setPosition(v);
Note that standard vector types (stl, |
|
Constructs a Vec from a If one of these attributes is missing or is not a number, a warning is displayed and the associated value is set to 0.0. See also domElement() and initFromDOMElement(). |
|
Returns an XML
When output to a file, the resulting QDomElement will look like: <name x=".." y=".." z=".." />
Use initFromDOMElement() to restore the Vec state from the resulting Here is complete example that creates a QDomDocument and saves it into a file: Vec sunPos; QDomDocument document("myDocument"); QDomElement sunElement = document.createElement("Sun"); document.appendChild(sunElement); sunElement.setAttribute("brightness", sunBrightness()); sunElement.appendChild(sunPos.domElement("sunPosition", document)); // Other additions to the document hierarchy... // Save doc document QFile f("myFile.xml"); if (f.open(IO_WriteOnly)) { QTextStream out(&f); document.save(out, 2); f.close(); } See also Quaternion::domElement(), Frame::domElement(), Camera::domElement()... |
|
Restores the Vec state from a
The To restore the Vec state from an xml file, use: // Load DOM from file QDomDocument doc; QFile f("myFile.xml"); if (f.open(IO_ReadOnly)) { doc.setContent(&f); f.close(); } // Parse the DOM tree and initialize QDomElement main=doc.documentElement(); myVec.initFromDOMElement(main); See also the Vec(const QDomElement&) constructor. |
|
Returns the norm of the vector. |
|
Normalizes the Vec and returns its original norm.
Normalizing a null vector will result in |
|
Multiply the vector by a scalar |
|
Conversion operator returning the memory address of the vector. Very convenient to pass a Vec pointer as a parameter to OpenGL functions: Vec pos, normal; glNormal3fv(normal); glVertex3fv(pos); |
|
Adds |
|
Subtracts |
|
Divides the vector by a scalar
An absolute |
|
Output stream operator. Enables debugging code like: Vec pos(...); cout << "Position=" << pos << endl; |
|
Equal operator. |
|
Bracket operator returning an l-value. |
|
Bracket operator, with a constant return value. |
|
Projects the Vec on the axis of direction
|
|
Projects the Vec on the plane whose normal is
|
|
Set the current value. Better than using operator=() with a temporary Vec(x,y,z). |
|
Returns the squared norm of the Vec. |
|
Returns a unitary (normalized) representation of the vector. The original Vec is not modified. |
|
Cross product of the two Vec. Mind the order ! |
|
Dot product of the two Vec. |
|
Returns the product of the vector with a scalar. |
|
Returns the product of the vector with a scalar. |
|
Returns |
|
Returns the sum of the two vectors. |
|
Unary minus operator. |
|
Returns the difference of the two vectors. |
|
Returns the division of the vector with a scalar.
Too small |
|
Returns |
|
Cross product of the two vectors. Same as cross(). |
|
The internal data representation is public. One can use v.x, v.y, v.z. See also operator[](). |
|
The internal data representation is public. One can use v.x, v.y, v.z. See also operator[](). |
|
The internal data representation is public. One can use v.x, v.y, v.z. See also operator[](). |