1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
//
// C++ Implementation: BoatAnimation
//
// Description:
//
//
// Author: Thibaut GRIDEL <tgridel@free.fr>
//
// Copyright (c) 2008-2020 Thibaut GRIDEL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
#include <iostream>
#include "boatanimation.h"
#include "boats.h"
#include "angleanimation.h"
#include "headinganimation.h"
#include "splineanimation.h"
#include "trackmodel.h"
#include "boatmodel.h"
/**
Populates the animation items for position, Headings and other attributes.
This method parses the path of the \a track, does some stalling
analysis and determines specific position animation.
*/
BoatAnimation::BoatAnimation(TrackModel *track, BoatModel *boat, int index, QObject *parent)
: QParallelAnimationGroup(parent),
m_track(track),
m_boat(boat)
{
BoatModel *model = track->boats()[index];
BoatModel *endel = track->boats()[index+1];
QPainterPath curve = model->path();
QPointF point = curve.elementAt(0);
QPointF c1 = curve.elementAt(1);
QPointF c2 = curve.elementAt(2);
QPointF end = curve.elementAt(3);
bool stalled = ((point == c1) || (c2 == end));
// position
SplineAnimation *splineAnimation = new SplineAnimation(boat, "pos", model->path());
splineAnimation->setDuration(2000);
splineAnimation->setStartValue(point);
splineAnimation->setEndValue(end);
addAnimation(splineAnimation);
// text
PropertyAnimation *textAnimation = new PropertyAnimation(boat, "text");
textAnimation->setDuration(2000);
textAnimation->setStartValue(model->text());
textAnimation->setEndValue(model->text());
addAnimation(textAnimation);
// text position
PropertyAnimation *textPosAnimation = new PropertyAnimation(boat, "textPos");
textPosAnimation->setDuration(2000);
textPosAnimation->setStartValue(model->textPosition());
textPosAnimation->setEndValue(model->textPosition());
addAnimation(textPosAnimation);
// laylines
PropertyAnimation *laylinesAnimation = new PropertyAnimation(boat, "laylines");
laylinesAnimation->setDuration(2000);
laylinesAnimation->setStartValue(model->laylines());
laylinesAnimation->setEndValue(model->laylines());
addAnimation(laylinesAnimation);
// heading
QVariantAnimation *headingAnimation;
if (stalled) {
headingAnimation = new AngleAnimation(boat, "heading");
} else {
headingAnimation = new HeadingAnimation(boat, "heading", model->path());
}
headingAnimation->setDuration(2000);
headingAnimation->setStartValue(model->heading());
headingAnimation->setEndValue(endel->heading());
addAnimation(headingAnimation);
AngleAnimation *windAnimation = new AngleAnimation(boat, "wind");
windAnimation->setDuration(2000);
windAnimation->setStartValue(model->wind());
windAnimation->setEndValue(endel->wind());
addAnimation(windAnimation);
// sail angle
AngleAnimation *sailAngleAnimation = new AngleAnimation(boat, "trimSailAngle");
sailAngleAnimation->setDuration(2000);
sailAngleAnimation->setStartValue(model->trimmedSailAngle());
sailAngleAnimation->setEndValue(endel->trimmedSailAngle());
addAnimation(sailAngleAnimation);
// jib angle
AngleAnimation *jibAngleAnimation = new AngleAnimation(boat, "trimJibAngle");
jibAngleAnimation->setDuration(2000);
jibAngleAnimation->setStartValue(model->trimmedJibAngle());
jibAngleAnimation->setEndValue(endel->trimmedJibAngle());
addAnimation(jibAngleAnimation);
// spin
PropertyAnimation *spinAnimation = new PropertyAnimation(boat, "spin");
spinAnimation->setDuration(2000);
spinAnimation->setStartValue(model->spin());
spinAnimation->setEndValue(endel->spin());
addAnimation(spinAnimation);
// spin angle
AngleAnimation *spinAngleAnimation = new AngleAnimation(boat, "trimSpinAngle");
spinAngleAnimation->setDuration(2000);
spinAngleAnimation->setStartValue(model->trimmedSpinAngle());
spinAngleAnimation->setEndValue(endel->trimmedSpinAngle());
addAnimation(spinAngleAnimation);
// gen angle
AngleAnimation *genAngleAnimation = new AngleAnimation(boat, "trimGennAngle");
genAngleAnimation->setDuration(2000);
genAngleAnimation->setStartValue(model->trimmedGennAngle());
genAngleAnimation->setEndValue(endel->trimmedGennAngle());
addAnimation(genAngleAnimation);
// overlap
PropertyAnimation *overlapAnimation = new PropertyAnimation(boat, "overlap");
overlapAnimation->setDuration(2000);
overlapAnimation->setStartValue(QVariant(model->overlap()));
overlapAnimation->setEndValue(QVariant(model->overlap()));
addAnimation(overlapAnimation);
// flag
PropertyAnimation *flagAnimation = new PropertyAnimation(boat, "flag");
flagAnimation->setDuration(2000);
flagAnimation->setStartValue(model->flag());
flagAnimation->setEndValue(model->flag());
addAnimation(flagAnimation);
// acceleration
switch(model->acceleration()) {
case Boats::accelerating:
setEasingCurve(QEasingCurve::InSine);
break;
case Boats::decelerating:
setEasingCurve(QEasingCurve::OutSine);
break;
default:
break;
}
}
BoatAnimation::~BoatAnimation() {
}
void BoatAnimation::setEasingCurve(const QEasingCurve &easing) {
for (int i=0; i< animationCount(); ++i) {
QVariantAnimation *animation = dynamic_cast<QVariantAnimation*>(animationAt(i));
if(animation) {
animation->setEasingCurve(easing);
}
}
}
|