Public Attributes |
union { |
struct { |
double x |
double y |
double z |
} | |
double v_ [3] |
}; | |
Setting the value |
| Vec () |
| Vec (double X, double Y, double Z) |
template<class C > |
| Vec (const C &c) |
Vec & | operator= (const Vec &v) |
void | setValue (double X, double Y, double Z) |
Accessing the value |
double | operator[] (int i) const |
double & | operator[] (int i) |
const double * | address () const |
| operator const double * () const |
| operator double * () |
| operator const float * () const |
Algebraic computations |
Vec & | operator+= (const Vec &a) |
Vec & | operator-= (const Vec &a) |
Vec & | operator*= (double k) |
Vec & | operator/= (double k) |
Vec | orthogonalVec () const |
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, double k) |
Vec | operator* (double k, const Vec &a) |
Vec | operator/ (const Vec &a, double k) |
bool | operator!= (const Vec &a, const Vec &b) |
bool | operator== (const Vec &a, const Vec &b) |
double | operator* (const Vec &a, const Vec &b) |
Vec | operator^ (const Vec &a, const Vec &b) |
Vec | cross (const Vec &a, const Vec &b) |
Norm of the vector |
double | sqNorm () const |
double | squaredNorm () const |
double | norm () const |
double | 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) |
The Vec class represents 3D positions and 3D vectors.
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:
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;
Interface with other vector classes
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.
Definition at line 69 of file vec.h.
QDomElement Vec::domElement |
( |
const QString & |
name, |
|
|
QDomDocument & |
document |
|
) |
| const |
Returns an XML QDomElement
that represents the Vec.
name
is the name of the QDomElement tag. doc
is the QDomDocument
factory used to create QDomElement.
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 QDomElement
. See also the Vec(const QDomElement&) constructor.
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));
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()...
Definition at line 128 of file vec.cpp.
Restores the Vec state from a QDomElement
created by domElement().
The QDomElement
should contain x
, y
and z
attributes. 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.
To restore the Vec state from an xml file, use:
QDomDocument doc;
QFile f("myFile.xml");
if (f.open(IO_ReadOnly))
{
doc.setContent(&f);
f.close();
}
QDomElement main=doc.documentElement();
myVec.initFromDOMElement(main);
See also the Vec(const QDomElement&) constructor.
Definition at line 158 of file vec.cpp.