36 : frame_(NULL), period_(40), interpolationTime_(0.0), interpolationSpeed_(1.0), interpolationStarted_(false),
37 closedPath_(false), loopInterpolation_(false), pathIsValid_(false), valuesAreValid_(true), currentFrameValid_(false)
41 for (
int i=0; i<4; ++i)
50 for (
int i=0; i<4; ++i)
183 qWarning(
"Error in KeyFrameInterpolator::addKeyFrame: time is not monotone");
206 qWarning(
"Error in KeyFrameInterpolator::addKeyFrame: time is not monotone");
260 glDisable(GL_LIGHTING);
262 const qreal halfHeight = scale * 0.07;
263 const qreal halfWidth = halfHeight * 1.3;
264 const qreal dist = halfHeight / tan(qreal(
M_PI)/8.0);
266 const qreal arrowHeight = 1.5 * halfHeight;
267 const qreal baseHeight = 1.2 * halfHeight;
268 const qreal arrowHalfWidth = 0.5 * halfWidth;
269 const qreal baseHalfWidth = 0.3 * halfWidth;
272 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
273 glBegin(GL_LINE_STRIP);
274 glVertex3d(-halfWidth, halfHeight,-dist);
275 glVertex3d(-halfWidth,-halfHeight,-dist);
276 glVertex3d( 0.0, 0.0, 0.0);
277 glVertex3d( halfWidth,-halfHeight,-dist);
278 glVertex3d(-halfWidth,-halfHeight,-dist);
280 glBegin(GL_LINE_STRIP);
281 glVertex3d( halfWidth,-halfHeight,-dist);
282 glVertex3d( halfWidth, halfHeight,-dist);
283 glVertex3d( 0.0, 0.0, 0.0);
284 glVertex3d(-halfWidth, halfHeight,-dist);
285 glVertex3d( halfWidth, halfHeight,-dist);
289 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
292 glVertex3d(-baseHalfWidth, halfHeight,-dist);
293 glVertex3d( baseHalfWidth, halfHeight,-dist);
294 glVertex3d( baseHalfWidth, baseHeight,-dist);
295 glVertex3d(-baseHalfWidth, baseHeight,-dist);
299 glBegin(GL_TRIANGLES);
300 glVertex3d( 0.0, arrowHeight,-dist);
301 glVertex3d(-arrowHalfWidth, baseHeight, -dist);
302 glVertex3d( arrowHalfWidth, baseHeight, -dist);
339 const int nbSteps = 30;
366 Vec v1 = 3.0 * diff - 2.0 * kf_[1]->
tgP() - kf_[2]->
tgP();
367 Vec v2 = -2.0 * diff + kf_[1]->
tgP() + kf_[2]->
tgP();
370 for (
int step=0; step<nbSteps; ++step)
372 qreal alpha = step /
static_cast<qreal
>(nbSteps);
373 fr.
setPosition(kf_[1]->position() + alpha * (kf_[1]->tgP() + alpha * (v1+alpha*v2)));
386 path_.push_back(
Frame(kf_[1]->position(), kf_[1]->orientation()));
393 glDisable(GL_LIGHTING);
398 glBegin(GL_LINE_STRIP);
406 if (nbFrames > nbSteps)
410 if ((count++) >= goal)
412 goal += nbSteps /
static_cast<qreal
>(nbFrames);
414 glMultMatrixd(fr.
matrix());
619 QDomElement de = document.createElement(name);
624 QDomElement kfNode = fr.
domElement(
"KeyFrame", document);
625 kfNode.setAttribute(
"index", QString::number(count));
626 kfNode.setAttribute(
"time", QString::number(kf->
time()));
627 de.appendChild(kfNode);
630 de.setAttribute(
"nbKF", QString::number(
keyFrame_.count()));
651 QDomElement child=element.firstChild().toElement();
652 while (!child.isNull())
654 if (child.tagName() ==
"KeyFrame")
662 child = child.nextSibling().toElement();
void startInterpolation(int period=-1)
int interpolationPeriod() const
void resetInterpolation()
virtual ~KeyFrameInterpolator()
void setFrame(Frame *const frame)
qreal keyFrameTime(int index) const
qreal interpolationTime() const
void addKeyFrame(const Frame &frame)
KeyFrame(const Frame &fr, qreal t)
QMutableListIterator< KeyFrame * > * currentFrame_[4]
void setClosedPath(bool closed=true)
bool interpolationStarted_
static Quaternion squad(const Quaternion &a, const Quaternion &tgA, const Quaternion &tgB, const Quaternion &b, qreal t)
void computeTangent(const KeyFrame *const prev, const KeyFrame *const next)
virtual QDomElement domElement(const QString &name, QDomDocument &document) const
virtual void interpolateAtTime(qreal time)
virtual void drawPath(int mask=1, int nbFrames=6, qreal scale=1.0)
static Quaternion squadTangent(const Quaternion &before, const Quaternion ¢er, const Quaternion &after)
const Frame * frame() const
static void drawAxis(qreal length=1.0)
virtual void invalidateValues()
The Vec class represents 3D positions and 3D vectors.
const GLdouble * matrix() const
static qreal dot(const Quaternion &a, const Quaternion &b)
KeyFrameInterpolator(Frame *fr=NULL)
void flipOrientationIfNeeded(const Quaternion &prev)
static void setBoolAttribute(QDomElement &element, const QString &attribute, bool value)
static qreal qrealFromDom(const QDomElement &e, const QString &attribute, qreal defValue)
const Frame *const frame_
void setLoopInterpolation(bool loop=true)
bool loopInterpolation() const
Quaternion orientation() const
The Quaternion class represents 3D rotations and orientations.
void updateValuesFromPointer()
Quaternion orientation() const
void setInterpolationTime(qreal time)
void setPosition(const Vec &position)
void setInterpolationSpeed(qreal speed)
static bool boolFromDom(const QDomElement &e, const QString &attribute, bool defValue)
virtual void initFromDOMElement(const QDomElement &element)
The Frame class represents a coordinate system, defined by a position and an orientation.
QList< KeyFrame * > keyFrame_
Frame keyFrame(int index) const
static int intFromDom(const QDomElement &e, const QString &attribute, int defValue)
void setOrientation(const Quaternion &orientation)
virtual QDomElement domElement(const QString &name, QDomDocument &document) const
void updateCurrentKeyFrameForTime(qreal time)
void setPositionAndOrientationWithConstraint(Vec &position, Quaternion &orientation)
qreal interpolationSpeed() const
void updateModifiedFrameValues()
void setInterpolationPeriod(int period)
static void drawCamera(qreal scale)
virtual void initFromDOMElement(const QDomElement &element)