29 #if QT_VERSION < 0x040000 31 # define peekNext current 41 : frame_(NULL), period_(40), interpolationTime_(0.0), interpolationSpeed_(1.0), interpolationStarted_(false),
42 closedPath_(false), loopInterpolation_(false), pathIsValid_(false), valuesAreValid_(true), currentFrameValid_(false)
46 #if QT_VERSION < 0x040000 49 for (
int i=0; i<4; ++i)
50 #
if QT_VERSION >= 0x040000
62 for (
int i=0; i<4; ++i)
195 qWarning(
"Error in KeyFrameInterpolator::addKeyFrame: time is not monotone");
218 qWarning(
"Error in KeyFrameInterpolator::addKeyFrame: time is not monotone");
263 #if QT_VERSION >= 0x040000 274 glDisable(GL_LIGHTING);
276 const float halfHeight = scale * 0.07;
277 const float halfWidth = halfHeight * 1.3;
278 const float dist = halfHeight / tan(
M_PI/8.0);
280 const float arrowHeight = 1.5f * halfHeight;
281 const float baseHeight = 1.2f * halfHeight;
282 const float arrowHalfWidth = 0.5f * halfWidth;
283 const float baseHalfWidth = 0.3f * halfWidth;
286 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
287 glBegin(GL_LINE_STRIP);
288 glVertex3f(-halfWidth, halfHeight,-dist);
289 glVertex3f(-halfWidth,-halfHeight,-dist);
290 glVertex3f( 0.0f, 0.0f, 0.0f);
291 glVertex3f( halfWidth,-halfHeight,-dist);
292 glVertex3f(-halfWidth,-halfHeight,-dist);
294 glBegin(GL_LINE_STRIP);
295 glVertex3f( halfWidth,-halfHeight,-dist);
296 glVertex3f( halfWidth, halfHeight,-dist);
297 glVertex3f( 0.0f, 0.0f, 0.0f);
298 glVertex3f(-halfWidth, halfHeight,-dist);
299 glVertex3f( halfWidth, halfHeight,-dist);
303 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
306 glVertex3f(-baseHalfWidth, halfHeight,-dist);
307 glVertex3f( baseHalfWidth, halfHeight,-dist);
308 glVertex3f( baseHalfWidth, baseHeight,-dist);
309 glVertex3f(-baseHalfWidth, baseHeight,-dist);
313 glBegin(GL_TRIANGLES);
314 glVertex3f( 0.0f, arrowHeight,-dist);
315 glVertex3f(-arrowHalfWidth, baseHeight, -dist);
316 glVertex3f( arrowHalfWidth, baseHeight, -dist);
353 const int nbSteps = 30;
357 #if QT_VERSION < 0x040000 375 #if QT_VERSION >= 0x040000 388 Vec v1 = 3.0 * diff - 2.0 * kf_[1]->
tgP() - kf_[2]->
tgP();
389 Vec v2 = -2.0 * diff + kf_[1]->
tgP() + kf_[2]->
tgP();
392 for (
int step=0; step<nbSteps; ++step)
394 float alpha = step /
static_cast<float>(nbSteps);
395 fr.
setPosition(kf_[1]->position() + alpha * (kf_[1]->tgP() + alpha * (v1+alpha*v2)));
404 #if QT_VERSION >= 0x040000 412 path_.push_back(
Frame(kf_[1]->position(), kf_[1]->orientation()));
419 glDisable(GL_LIGHTING);
424 glBegin(GL_LINE_STRIP);
425 #if QT_VERSION >= 0x040000 429 # if QT_VERSION < 0x030000 430 for (
int i=0; i <
path_.size(); ++i)
431 glVertex3fv((
path_.at(i)).position());
433 for (QValueVector<Frame>::const_iterator pnt=
path_.begin(), end=
path_.end(); pnt!=end; ++pnt)
434 glVertex3fv((*pnt).position());
442 if (nbFrames > nbSteps)
445 #if QT_VERSION >= 0x040000 448 # if QT_VERSION < 0x030000 449 for (
int i=0; i <
path_.size(); ++i)
451 for (QValueVector<Frame>::const_iterator pnt=
path_.begin(), end=
path_.end(); pnt!=end; ++pnt)
454 if ((count++) >= goal)
456 goal += nbSteps /
static_cast<float>(nbFrames);
458 #if QT_VERSION >= 0x040000 459 glMultMatrixd(fr.
matrix());
461 # if QT_VERSION < 0x030000 462 glMultMatrixd((
path_.at(i)).matrix());
464 glMultMatrixd((*pnt).matrix());
479 #if QT_VERSION >= 0x040000 495 #if QT_VERSION >= 0x040000 500 #if QT_VERSION >= 0x040000 575 #if QT_VERSION >= 0x040000 584 #if QT_VERSION >= 0x040000 590 #if QT_VERSION >= 0x040000 603 #if QT_VERSION >= 0x040000 609 #if QT_VERSION >= 0x040000 619 #if QT_VERSION >= 0x040000 628 #if QT_VERSION >= 0x040000 637 #if QT_VERSION >= 0x040000 717 QDomElement de = document.createElement(name);
719 #if QT_VERSION >= 0x040000 726 QDomElement kfNode = fr.
domElement(
"KeyFrame", document);
727 kfNode.setAttribute(
"index", QString::number(count));
728 kfNode.setAttribute(
"time", QString::number(kf->
time()));
729 de.appendChild(kfNode);
732 de.setAttribute(
"nbKF", QString::number(
keyFrame_.count()));
736 de.setAttribute(
"closedPath", (
closedPath()?
"true":
"false"));
751 #if QT_VERSION >= 0x040000 755 QDomElement child=element.firstChild().toElement();
756 while (!child.isNull())
758 if (child.tagName() ==
"KeyFrame")
766 child = child.nextSibling().toElement();
void startInterpolation(int period=-1)
float interpolationTime() const
int interpolationPeriod() const
void resetInterpolation()
virtual ~KeyFrameInterpolator()
void setFrame(Frame *const frame)
void addKeyFrame(const Frame &frame)
void updateCurrentKeyFrameForTime(float time)
static Quaternion squad(const Quaternion &a, const Quaternion &tgA, const Quaternion &tgB, const Quaternion &b, float t)
void setClosedPath(bool closed=true)
bool interpolationStarted_
void computeTangent(const KeyFrame *const prev, const KeyFrame *const next)
virtual QDomElement domElement(const QString &name, QDomDocument &document) const
static void drawCamera(float scale)
static Quaternion squadTangent(const Quaternion &before, const Quaternion ¢er, const Quaternion &after)
const Frame * frame() const
static double dot(const Quaternion &a, const Quaternion &b)
virtual void invalidateValues()
The Vec class represents 3D positions and 3D vectors.
const GLdouble * matrix() const
void setInterpolationTime(float time)
virtual void drawPath(int mask=1, int nbFrames=6, float scale=1.0f)
KeyFrameInterpolator(Frame *fr=NULL)
void flipOrientationIfNeeded(const Quaternion &prev)
virtual void interpolateAtTime(float time)
const Frame *const frame_
void setLoopInterpolation(bool loop=true)
bool loopInterpolation() const
KeyFrame(const Frame &fr, float t)
Quaternion orientation() const
static void drawAxis(float length=1.0f)
The Quaternion class represents 3D rotations and orientations.
void updateValuesFromPointer()
Quaternion orientation() const
void setPosition(const Vec &position)
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.
float keyFrameTime(int index) const
Frame keyFrame(int index) const
static int intFromDom(const QDomElement &e, const QString &attribute, int defValue)
void setInterpolationSpeed(float speed)
QPtrListIterator< KeyFrame > * currentFrame_[4]
void setOrientation(const Quaternion &orientation)
virtual QDomElement domElement(const QString &name, QDomDocument &document) const
float interpolationSpeed() const
QPtrList< KeyFrame > keyFrame_
void setPositionAndOrientationWithConstraint(Vec &position, Quaternion &orientation)
static float floatFromDom(const QDomElement &e, const QString &attribute, float defValue)
void updateModifiedFrameValues()
void setInterpolationPeriod(int period)
virtual void initFromDOMElement(const QDomElement &element)