18 #include <QEasingCurve> 19 #include <QDomDocument> 25 return mKeyframes.isEmpty() ? 0 : mKeyframes.constLast().time;
30 if ( mKeyframes.isEmpty() )
33 if ( time < mKeyframes.constFirst().time )
35 return mKeyframes.first();
37 else if ( time >= mKeyframes.constLast().time )
39 return mKeyframes.last();
47 for (
int i = 0; i < mKeyframes.size() - 1; i++ )
49 const Keyframe &k0 = mKeyframes.at( i );
50 const Keyframe &k1 = mKeyframes.at( i + 1 );
51 if ( time >= k0.
time && time <= k1.
time )
54 float eIp = mEasingCurve.valueForProgress( ip );
55 float eIip = 1.0f - eIp;
66 float yaw0 = fmod( k0.
yaw, 360 ), yaw1 = fmod( k1.
yaw, 360 );
67 if ( std::abs( yaw0 - yaw1 ) > 180 )
75 kf.
yaw = yaw0 * eIip + yaw1 * eIp;
86 mEasingCurve = QEasingCurve( ( QEasingCurve::Type ) elem.attribute( QStringLiteral(
"interpolation" ), QStringLiteral(
"0" ) ).toInt() );
90 QDomElement elemKeyframes = elem.firstChildElement( QStringLiteral(
"keyframes" ) );
91 QDomElement elemKeyframe = elemKeyframes.firstChildElement( QStringLiteral(
"keyframe" ) );
92 while ( !elemKeyframe.isNull() )
95 kf.
time = elemKeyframe.attribute( QStringLiteral(
"time" ) ).toFloat();
96 kf.
point.
set( elemKeyframe.attribute( QStringLiteral(
"x" ) ).toDouble(),
97 elemKeyframe.attribute( QStringLiteral(
"y" ) ).toDouble(),
98 elemKeyframe.attribute( QStringLiteral(
"z" ) ).toDouble() );
99 kf.
dist = elemKeyframe.attribute( QStringLiteral(
"dist" ) ).toFloat();
100 kf.
pitch = elemKeyframe.attribute( QStringLiteral(
"pitch" ) ).toFloat();
101 kf.
yaw = elemKeyframe.attribute( QStringLiteral(
"yaw" ) ).toFloat();
102 mKeyframes.append( kf );
103 elemKeyframe = elemKeyframe.nextSiblingElement( QStringLiteral(
"keyframe" ) );
109 QDomElement elem = doc.createElement( QStringLiteral(
"animation3d" ) );
110 elem.setAttribute( QStringLiteral(
"interpolation" ), mEasingCurve.type() );
112 QDomElement elemKeyframes = doc.createElement( QStringLiteral(
"keyframes" ) );
114 for (
const Keyframe &keyframe : mKeyframes )
116 QDomElement elemKeyframe = doc.createElement( QStringLiteral(
"keyframe" ) );
117 elemKeyframe.setAttribute( QStringLiteral(
"time" ), keyframe.time );
118 elemKeyframe.setAttribute( QStringLiteral(
"x" ), keyframe.point.x() );
119 elemKeyframe.setAttribute( QStringLiteral(
"y" ), keyframe.point.y() );
120 elemKeyframe.setAttribute( QStringLiteral(
"z" ), keyframe.point.z() );
121 elemKeyframe.setAttribute( QStringLiteral(
"dist" ), keyframe.dist );
122 elemKeyframe.setAttribute( QStringLiteral(
"pitch" ), keyframe.pitch );
123 elemKeyframe.setAttribute( QStringLiteral(
"yaw" ), keyframe.yaw );
124 elemKeyframes.appendChild( elemKeyframe );
127 elem.appendChild( elemKeyframes );
Qgs3DAnimationSettings()
ctor
float time
Relative time of the keyframe in seconds.
double y() const
Returns Y coordinate.
void set(double x, double y, double z)
Sets vector coordinates.
double z() const
Returns Z coordinate.
Keyframe interpolate(float time) const
Interpolates camera position and rotation at the given point in time.
QgsVector3D point
Point towards which the camera is looking in 3D world coords.
float dist
Distance of the camera from the focal point.
float yaw
Horizontal rotation around the focal point in degrees.
void readXml(const QDomElement &elem)
Reads configuration from a DOM element previously written by writeXml()
QDomElement writeXml(QDomDocument &doc) const
Writes configuration to a DOM element, to be used later with readXml()
double x() const
Returns X coordinate.
float pitch
Tilt of the camera in degrees (0 = looking from the top, 90 = looking from the side, 180 = looking from the bottom)
float duration() const
Returns duration of the whole animation in seconds.