3 static void make_skycube(Scene *scene);
4 static void make_title(Scene *scene);
5 static void make_vol(Scene *scene);
6 static void render_vol(unsigned long time);
7 static void render_presents(float t);
10 static ParticleSystem *ps[PSYS_COUNT];
11 static ParticleSysParams *psys_params[PSYS_COUNT];
12 static bool psys_removed = false;
14 static const float inner_sz = 30.0;
15 static const float outer_sz = 70.0;
16 static const int sph_count = 50;
17 static Object *inner_sph, *vol_sph[sph_count];
19 static Texture *presents, *summer_hack;
25 PipesPart::PipesPart() : ScenePart("pipes", new Scene) {
27 TargetCamera *cam = new TargetCamera(Vector3(0, 20, -150));
29 TargetCamera *cam = new TargetCamera(Vector3(0, 10, -150));
31 cam->set_fov(DEG_TO_RAD(50));
32 scene->add_camera(cam);
34 PointLight *lt = new PointLight(Vector3(10, 100, -100));
37 scene->set_ambient_light(0.1);
47 presents = get_texture("data/img/presents.png");
48 summer_hack = get_texture("data/img/title.png");
50 MotionController cam_x, cam_y, cam_z;
52 cam_x = MotionController(CTRL_COS, TIME_FREE);
53 cam_x.set_sin_func(0.5, 40);
54 cam_x.set_control_axis(CTRL_X);
56 cam_z = MotionController(CTRL_SIN, TIME_FREE);
57 cam_z.set_sin_func(1.5, 100);
58 cam_z.set_control_axis(CTRL_Z);
60 cam_y = MotionController(CTRL_SIN, TIME_FREE);
61 cam_y.set_sin_func(0.35, 20);
62 cam_y.set_control_axis(CTRL_Y);
65 cam->add_controller(cam_x, CTRL_TRANSLATION);
66 //cam->add_controller(cam_z, CTRL_TRANSLATION);
67 cam->add_controller(cam_y, CTRL_TRANSLATION);
70 scene->set_background(0.5);
72 // make sure the volume and title textures are resident from the beginning
73 dsys::overlay(get_texture("data/img/cracks.jpg"), Vector2(0, 0), Vector2(0.1, 0.1), 0.0);
74 dsys::overlay(get_texture("data/img/volcano.jpg"), Vector2(0, 0), Vector2(0.1, 0.1), 0.0);
75 dsys::overlay(get_texture("data/img/title.png"), Vector2(0, 0), Vector2(0.1, 0.1), 0.0);
76 dsys::overlay(get_texture("data/img/presents.png"), Vector2(0, 0), Vector2(0.1, 0.1), 0.0);
78 //scene->render_sequence(0, 15000, 25);
82 PipesPart::~PipesPart() {
84 for(int i=0; i<PSYS_COUNT; i++) {
90 static const float pexpl_time = half_pi * 8.0;
91 static const float pexpl_full_time = pexpl_time + half_pi * 3.4;
92 static const float pstop_time = pexpl_time + half_pi * 6.0;
94 void PipesPart::draw_part() {
95 float t = (float)time / 1000.0f;
97 ScenePart::draw_part();
106 static unsigned long prev_drop;
107 bool drop = (time - prev_drop > 33.3333) ? true : false;
109 //Fuzzy val(0.0, 1.75 * (1.0 - sin(fmod(p, half_pi) + half_pi)));
110 Fuzzy val(0.0, 1.75 * sin(fmod(p, half_pi)));
111 for(int i=0; i<PSYS_COUNT; i++) {
112 psys_params[i]->shoot_dir = FuzzyVec3(val, val, val);
114 if(t > pexpl_full_time && drop) {
115 psys_params[i]->birth_rate.num *= 0.8;
121 for(int i=0; i<PSYS_COUNT; i++) {
122 float val = p > 0.5 ? 0.5 : p;
123 float range = val * 2.0;
124 psys_params[i]->spawn_offset_curve_area = Fuzzy(val, range);
131 //for(int i=0; i<PSYS_COUNT; i++) {
132 // scene->remove_particle_sys(ps[i]);
142 static void make_skycube(Scene *scene) {
143 const float size = 1000;
147 face[0] = new ObjPlane(Vector3(0, -1, 0), Vector2(size, size), 0);
148 face[0]->translate(Vector3(0, size / 2, 0));
149 tex[0] = get_texture("data/img/nebula_py.jpg");
151 face[1] = new ObjPlane(Vector3(0, 1, 0), Vector2(size, size), 0);
152 face[1]->translate(Vector3(0, -size / 2, 0));
153 tex[1] = get_texture("data/img/nebula_ny.jpg");
155 face[2] = new ObjPlane(Vector3(0, 0, -1), Vector2(size, size), 0);
156 face[2]->translate(Vector3(0, 0, size / 2));
157 tex[2] = get_texture("data/img/nebula_pz.jpg");
159 face[3] = new ObjPlane(Vector3(0, 0, 1), Vector2(size, size), 0);
160 face[3]->translate(Vector3(0, 0, -size / 2));
161 tex[3] = get_texture("data/img/nebula_nz.jpg");
163 face[4] = new ObjPlane(Vector3(-1, 0, 0), Vector2(size, size), 0);
164 face[4]->translate(Vector3(size / 2, 0, 0));
165 tex[4] = get_texture("data/img/nebula_px.jpg");
167 face[5] = new ObjPlane(Vector3(1, 0, 0), Vector2(size, size), 0);
168 face[5]->translate(Vector3(-size / 2, 0, 0));
169 tex[5] = get_texture("data/img/nebula_nx.jpg");
171 for(int i=0; i<6; i++) {
172 face[i]->apply_xform();
173 face[i]->set_rotation(Vector3(0, quarter_pi, 0));
175 Material *mat = face[i]->get_material_ptr();
176 mat->emissive_color = 1.0;
177 mat->set_texture(tex[i], TEXTYPE_DIFFUSE);
178 face[i]->set_texture_addressing(TEXADDR_CLAMP);
179 scene->add_object(face[i]);
184 void make_title(Scene *scene) {
186 for(int i=0; i<PSYS_COUNT; i++) {
187 char curve_fname[64];
188 sprintf(curve_fname, "data/curve%02d", i);
190 Curve *curve = load_curve(curve_fname);
191 curve->set_arc_parametrization(true);
192 ps[i] = new ParticleSystem("data/thelab.psys");
193 psys_params[i] = ps[i]->get_params();
194 psys_params[i]->spawn_offset_curve = curve;
196 psys_params[i]->birth_rate.num /= 1.5;
199 psys_params[i]->birth_rate.num /= 6.0;
202 psys_params[i]->birth_rate.num *= 1.3;
204 //scene->add_particle_sys(ps[i]);
208 static float vol_alpha[sph_count];
210 static void make_vol(Scene *scene) {
213 MotionController rot1(CTRL_LIN, TIME_FREE);
214 MotionController rot2(CTRL_SIN, TIME_FREE);
216 rot1.set_control_axis(CTRL_XY);
217 rot1.set_slope(1.08);
218 rot2.set_control_axis(CTRL_YZ);
219 rot2.set_slope(1.439999);
220 rot2.set_sin_func(1.5, 1.5);
222 inner_sph = new ObjSphere(inner_sz, 4);
223 mat = inner_sph->get_material_ptr();
224 mat->set_texture(get_texture("data/img/volcano.jpg"), TEXTYPE_DIFFUSE);
225 inner_sph->add_controller(rot1, CTRL_ROTATION);
226 inner_sph->add_controller(rot2, CTRL_ROTATION);
227 //scene->add_object(obj);
229 for(int i=0; i<sph_count; i++) {
230 float t = (float)i / (float)sph_count;
231 vol_sph[i] = new ObjSphere(inner_sz + (outer_sz - inner_sz) * t, 3);
232 mat = vol_sph[i]->get_material_ptr();
233 mat->set_texture(get_texture("data/img/cracks.jpg"), TEXTYPE_DIFFUSE);
234 mat->alpha = vol_alpha[i] = 1.0 - t;
235 mat->emissive_color = 1.0;
236 vol_sph[i]->set_handle_blending(false);
237 vol_sph[i]->set_blending_mode(BLEND_SRC_ALPHA, BLEND_ONE);
238 vol_sph[i]->set_blending(true);
239 vol_sph[i]->add_controller(rot1, CTRL_ROTATION);
240 vol_sph[i]->add_controller(rot2, CTRL_ROTATION);
241 vol_sph[i]->set_zwrite(false);
242 //scene->add_object(obj);
246 static void render_vol(unsigned long time) {
247 static const float leave_time = 34.0;
249 float t = (float)time / 1000.0;
250 if(t < pexpl_full_time) return;
252 float sp = (t - pexpl_full_time) / (pstop_time - pexpl_full_time);
253 if(t > pstop_time) sp = 1.0;
256 inner_sph->get_material_ptr()->alpha = sp;
257 for(int i=0; i<sph_count + 1; i++) {
258 Object *obj = i < sph_count ? vol_sph[i] : inner_sph;
260 obj->set_scaling(Vector3(sp, sp, sp));
261 if(i < sph_count) obj->get_material_ptr()->alpha = vol_alpha[i] * sp;
264 float lt = t - leave_time;
265 obj->set_position(Vector3(0, pow(lt * 5.0, 2.0), 0));
270 set_front_face(ORDER_CCW);
271 set_zbuffering(false);
272 for(int i=0; i<sph_count; i++) {
273 vol_sph[i]->render(time);
275 set_zbuffering(true);
276 set_front_face(ORDER_CW);
278 inner_sph->render(time);
280 set_zbuffering(false);
281 for(int i=0; i<sph_count; i++) {
282 vol_sph[i]->render(time);
284 set_zbuffering(true);
287 static void render_presents(float t) {
288 static const float pres_start = pexpl_full_time - 0.5;
289 static const Vector2 pres_sz(0.35, 0.12);
290 static const Vector2 hack_sz(0.55, 0.12);
294 if(t < 0.0 || t > pres_start + 5.0) return;
296 float x = pow((t * 0.2) - 1.0, 3.0);
297 Vector2 pres_pos(-x + 0.5, 0.3);
298 Vector2 hack_pos(x + 0.5, 0.7);
299 dsys::overlay(presents, pres_pos - pres_sz / 2.0, pres_pos + pres_sz / 2.0, 1.0);
300 dsys::overlay(summer_hack, hack_pos - hack_sz / 2.0, hack_pos + hack_sz / 2.0, 1.0);