-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPropertyAnimators.cpp
128 lines (98 loc) · 2.71 KB
/
PropertyAnimators.cpp
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
// PropertyAnimators.cpp
//
// Property animator classes
#include <windows.h>
#include "Alchemy.h"
#include "DirectXUtil.h"
#include <math.h>
#include <stdio.h>
#include "Reanimator.h"
// CLinearFade ----------------------------------------------------------------
void CLinearFade::SetParams (int iDuration, int iFadeIn, int iFadeOut, DWORD dwMaxOpacity)
// SetParams
//
// Sets parameters
{
ASSERT(iFadeIn >= 0);
ASSERT(iFadeOut >= 0);
ASSERT(iDuration >= 0 || iFadeOut == 0);
ASSERT(iDuration < 0 || (iFadeOut + iFadeIn) <= iDuration);
m_iDuration = iDuration;
m_iFadeIn = iFadeIn;
m_iFadeOut = iFadeOut;
m_dwMaxOpacity = dwMaxOpacity;
}
void CLinearFade::SetProperty (int iFrame, CAniProperty &Property)
// SetProperty
//
// Sets the property
{
DWORD dwOpacity;
if (iFrame < m_iFadeIn)
dwOpacity = m_dwMaxOpacity * iFrame / m_iFadeIn;
else if (m_iDuration >= 0)
{
if (iFrame + m_iFadeOut > m_iDuration)
dwOpacity = m_dwMaxOpacity * (m_iDuration - iFrame) / m_iFadeOut;
else if (iFrame > m_iDuration)
dwOpacity = 0;
else
dwOpacity = m_dwMaxOpacity;
}
else
dwOpacity = m_dwMaxOpacity;
Property.Set(CAniProperty::typeOpacity, dwOpacity);
}
// CLinearMetric ---------------------------------------------------------------
void CLinearMetric::SetParams (Metric rStart, Metric rEnd, Metric rIncrement)
// SetParams
//
// Sets parameters
{
ASSERT((rStart <= rEnd && rIncrement >= 0.0) || (rStart >= rEnd && rIncrement <= 0.0));
m_rStart = rStart;
m_rEnd = rEnd;
m_rIncrement = rIncrement;
if (rIncrement == 0.0)
m_iDuration = 0;
else
m_iDuration = (int)((m_rEnd - m_rStart) / m_rIncrement);
}
void CLinearMetric::SetProperty (int iFrame, CAniProperty &Property)
// SetProperty
//
// Set parameters
{
if (iFrame >= m_iDuration - 1)
Property.Set(CAniProperty::typeMetric, m_rEnd);
else
Property.Set(CAniProperty::typeMetric, (Metric)(m_rStart + (iFrame * m_rIncrement)));
}
// CLinearRotation ------------------------------------------------------------
void CLinearRotation::SetParams (Metric rStartAngle, Metric rRate, int iAnimateTime, int iDuration)
// SetParams
//
// Sets parameters
{
if (rStartAngle < 0.0)
return;
m_rStartAngle = rStartAngle;
m_rRate = rRate;
m_iAnimateTime = iAnimateTime;
m_iDuration = iDuration;
}
void CLinearRotation::SetProperty (int iFrame, CAniProperty &Property)
// SetProperty
//
// Set parameters
{
Metric rAngle;
if (m_iAnimateTime > 0 && iFrame >= m_iAnimateTime - 1)
rAngle = (m_rStartAngle + m_iAnimateTime * m_rRate);
else
rAngle = (m_rStartAngle + iFrame * m_rRate);
if (rAngle > 0.0)
Property.Set(CAniProperty::typeInteger, (int)rAngle % 360);
else
Property.Set(CAniProperty::typeInteger, 360 - ((int)-rAngle % 360));
}