4 * Copyright (C) 2006-2011 Simon Wunderlich <dotslash@packetmixer.de>
6 * This file is part of the s3d Widgets, a Widget Library for s3d.
7 * See http://s3d.berlios.de/ for more updates.
9 * s3d Widgets is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * s3d Widgets is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the s3d Widgets; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 /* the animation stack */
30 static s3dw_widget
*ani_s
[MAXANI
];
32 static int animation_on
= 0;
35 /* is item f already on stack? */
36 int s3dw_ani_stackpos(s3dw_widget
*f
)
39 for (i
= 0; i
< ani_n
; i
++)
41 return i
; /* already in list */
46 /* add an item on the animation stack */
47 void s3dw_ani_add(s3dw_widget
*f
)
50 s3dprintf(VLOW
, "[A]ni ADD (%10p), oid = %d, ani_n = %d, type is %s\n", (void*)f
, f
->oid
, ani_n
, s3dw_get_type_string(f
->type
));
51 if ((f
->oid
== 0) && (f
->type
!= S3DW_TCAM
)) {
52 s3dprintf(HIGH
, "s3dw_ani_add() assert failed: weird, moving cam but its not a cam object?");
55 if ((ani_n
< MAXANI
) && (animation_on
)) {
56 if (s3dw_ani_stackpos(f
) != -1)
57 return; /* already in list */
61 } else /* no place, finish now */
62 s3dw_ani_finish(f
, -1);
65 /* delete an item from the animation stack */
66 void s3dw_ani_del(int i
)
68 if ((i
>= 0) && (i
< ani_n
)) {
69 s3dprintf(VLOW
, "[A]ni DEL %d, ani_n = %d\n", i
, ani_n
);
71 ani_s
[i
] = ani_s
[ani_n
]; /* that should also work if i is the last one */
73 s3dprintf(MED
, "[F]ATAL: can't delete animation!\n");
77 /* apply the animation */
78 void s3dw_ani_doit(s3dw_widget
*f
)
80 if ((f
->oid
== 0) && (f
->type
!= S3DW_TCAM
)) {
81 s3dprintf(HIGH
, "s3dw_ani_doit() assert failed: weird, moving cam but its not a cam object?");
84 s3dprintf(HIGH
, "moving cam");
86 s3d_translate(f
->oid
, f
->ax
, f
->ay
, f
->az
);
87 s3d_rotate(f
->oid
, f
->arx
, f
->ary
, f
->arz
);
88 s3d_scale(f
->oid
, f
->as
);
92 /* finish an animation on the stack, stack index i */
93 void s3dw_ani_finish(s3dw_widget
*f
, int i
)
107 /* do one step of the animation */
108 void s3dw_ani_iterate(s3dw_widget
*f
)
110 f
->ax
= (f
->x
+ f
->ax
* ZOOMS
) / (ZOOMS
+ 1);
111 f
->ay
= (f
->y
+ f
->ay
* ZOOMS
) / (ZOOMS
+ 1);
112 f
->az
= (f
->z
+ f
->az
* ZOOMS
) / (ZOOMS
+ 1);
113 f
->arx
= (f
->rx
+ f
->arx
* ZOOMS
) / (ZOOMS
+ 1);
114 f
->ary
= (f
->ry
+ f
->ary
* ZOOMS
) / (ZOOMS
+ 1);
115 f
->arz
= (f
->rz
+ f
->arz
* ZOOMS
) / (ZOOMS
+ 1);
116 f
->as
= (f
->s
+ f
->as
* ZOOMS
) / (ZOOMS
+ 1);
120 /* checks if f is good enough */
121 int s3dw_ani_check(s3dw_widget
*f
)
123 float x
, y
, z
, rx
, ry
, rz
;
131 if (((fabs(f
->as
- f
->s
) / f
->s
) > 0.01) || (sqrt(x
*x
+ y
*y
+ z
*z
) > 0.01) || (sqrt(rx
*rx
+ ry
*ry
+ rz
*rz
) > 0.01))
136 /* need an arrangement ... */
137 void s3dw_ani_needarr(void)
141 while (ani_need_arr
) s3dw_arrange();
146 /** \brief doing the whole animation thing
148 * Just call this in your mainloop if you want some nice window sliding
149 * animations. it's somewhat bloating, but you don't want to miss it ;)
152 * #include <time.h> // nanosleep()
153 * static struct timespec t={0.33*1000*1000}; // 33 mili seconds
156 * // keep this in your mainloop. this will do smooth animations for you ...
158 * nanosleep(&t,NULL);
162 * s3d_mainloop(mainloop);
165 void s3dw_ani_mate(void)
169 animation_on
= 1; /* animation is activated */
170 if (ani_need_arr
) s3dw_arrange();
171 for (i
= 0; i
< ani_n
; i
++) {
174 if (s3dw_ani_check(f
)) {
175 s3dw_ani_finish(f
, i
);
176 i
--; /* a new widget is here now, take care in the next iteration */