-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzglTranslateAnimation.cpp
executable file
·184 lines (152 loc) · 3.02 KB
/
zglTranslateAnimation.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
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
179
180
181
182
/*
* Copyright (C) 2010 ZiiLABS Pte Ltd
* All Rights Reserved.
*
* This software and its associated documentation may contain some
* proprietary, confidential and trade secret information of
* ZiiLABS Pte Ltd and except as provided by written agreement with
* ZiiLABS Pte Ltd
*
* a) no part may be disclosed, distributed, reproduced, transmitted,
* transcribed, stored in a retrieval system, adapted or translated
* in any form or by any means electronic, mechanical, magnetic,
* optical, chemical, manual or otherwise,
*
* and
*
* b) the recipient is not entitled to discover through reverse
* engineering or reverse compiling or other such techniques or
* processes the trade secrets contained therein or in the
* documentation.
*/
#include <stdlib.h>
#include "zglWidget.h"
#include "zglTranslateAnimation.h"
zglTranslateAnimation::zglTranslateAnimation()
{
m_FromX = 0.0f;
m_ToX = 0.0f;
m_FromY = 0.0f;
m_ToY = 0.0f;
m_FromZ = 0.0f;
m_ToZ = 0.0f;
m_flag = TRANSLATE_XYZ;
}
void zglTranslateAnimation::init(float fromX, float toX, float fromY,
float toY, float fromZ, float toZ)
{
m_FromX = fromX;
m_ToX = toX;
m_FromY = fromY;
m_ToY = toY;
m_FromZ = fromZ;
m_ToZ = toZ;
}
void zglTranslateAnimation::setTranslateFlag(int flag)
{
m_flag = flag & TRANSLATE_XYZ;
}
bool zglTranslateAnimation::update(long time)
{
if (m_widget == NULL)
{
m_state = ANIM_STATE_NONE;
return false;
}
long dur = time - m_start_time - m_delay_time;
if(dur < 0)
{
return true;//Return true to make the engine continue.
}
float t = dur / float(m_dur_time);
if (dur >= m_dur_time)
{
moveTo(1.0f, true);
#if 0 //TODO
if (m_type == ANIM_TYPE_ABSOLUTE)
{
moveTo(1.0f, true);
}
else
{
move(1.0f, true);
}
#endif
m_state = ANIM_STATE_NONE;
}
else
{
float it = getValue(t);
moveTo(it, false);
#if 0 //TODO
if (m_type == ANIM_TYPE_ABSOLUTE)
{
moveTo(it, false);
}
else
{
move(it, false);
}
#endif
}
return true;
}
void zglTranslateAnimation::moveTo(float it, bool lastFrame)
{
float mx = m_widget->getX();
float my = m_widget->getY();
float mz = m_widget->getZ();
if (lastFrame)
{
if (m_flag & TRANSLATE_X)
{
mx = m_ToX;
}
if (m_flag & TRANSLATE_Y)
{
my = m_ToY;
}
if (m_flag & TRANSLATE_Z)
{
mz = m_ToZ;
}
}
else
{
if (m_flag & TRANSLATE_X)
{
mx = it * (m_ToX - m_FromX) + m_FromX;
}
if (m_flag & TRANSLATE_Y)
{
my = it * (m_ToY - m_FromY) + m_FromY;
}
if (m_flag & TRANSLATE_Z)
{
mz = it * (m_ToZ - m_FromZ) + m_FromZ;
}
}
m_widget->locate(mx, my, mz);
//m_widget->moveTo(mx, my, mz);
}
void zglTranslateAnimation::move(float it, bool lastFrame)
{
//float mx = m_widget->getX();
//float my = m_widget->getY();
//float mz = m_widget->getZ();
//TODO
/*
if(m_flag | TRANSLATE_X)
{
mx = it * (m_ToX - m_FromX) + m_FromX;
}
if(m_flag | TRANSLATE_Y)
{
my = it * (m_ToY - m_FromY) + m_FromY;
}
if(m_flag | TRANSLATE_Z)
{
mz = it * (m_ToZ - m_FromZ) + m_FromZ;
}
*/
}