|
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) |
|
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:
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.
template<class C >
qglviewer::Vec::Vec |
( |
const C & |
c | ) |
|
|
inlineexplicit |
Universal explicit converter from any class to Vec. You can use your own vector class everywhere a const
Vec&
parameter is required, as long as it implements the operator
[ ]:
class MyVec
{
double 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, double
[3], ...) implement this operator and can hence be used in place of Vec. See also operator const double*() .
Definition at line 115 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:
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.
void Vec::initFromDOMElement |
( |
const QDomElement & |
element | ) |
|
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.