# HG changeset patch # User John Tsiombikas # Date 1439965040 -10800 # Node ID 57c6f7b701268008ba08bbfca599cca3018b6495 # Parent a4ffd9e6984cc5d6b95fb84b33df2f62a78a991b renamed to textpsys diff -r a4ffd9e6984c -r 57c6f7b70126 Makefile --- a/Makefile Wed Aug 19 09:13:48 2015 +0300 +++ b/Makefile Wed Aug 19 09:17:20 2015 +0300 @@ -1,7 +1,7 @@ src = $(wildcard src/*.cc) obj = $(src:.cc=.o) dep = $(obj:.o=.d) -bin = textbomb +bin = textpsys CXXFLAGS = -std=c++11 -pedantic -Wall -g diff -r a4ffd9e6984c -r 57c6f7b70126 src/effect.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/effect.cc Wed Aug 19 09:17:20 2015 +0300 @@ -0,0 +1,117 @@ +#include +#include +#include "opengl.h" +#include "effect.h" +#include "psys.h" + +#include "hello1.h" +#include "hello2.h" +#include "pimg.h" + +static PSysParam ppmain; +static PSysParam ppexpl, ppflame; + +static ParticleSystem psys; +static Image *pimg; +static Image *simg[2]; + +bool fx_init() +{ + ppmain.spawn_rate = 20000; + ppmain.size = 0.06; + ppmain.spawn_range = 0.01; + ppmain.life = 0.4; + ppmain.gravity = Vector3(0, 0.01, 0); + + ppmain.pcolor_start = Vector3(0.717, 0.494, 0.951) * 0.6; + ppmain.pcolor_end = Vector3(0.9, 0.135, 0.005) * 0.6; + ppmain.pcolor_mid = lerp(ppmain.pcolor_start, ppmain.pcolor_mid, 0.5); + + ppmain.palpha_start = 1.0; + ppmain.palpha_mid = 0.5; + ppmain.palpha_end = 0.0; + + ppmain.pscale_start = 1.0; + ppmain.pscale_mid = 1.0; + ppmain.pscale_end = 7.0; + + pimg = new Image; + pimg->pixels = (unsigned char*)img_particle.pixel_data; + pimg->width = img_particle.width; + pimg->height = img_particle.height; + + ppmain.pimg = pimg; + + simg[0] = new Image; + simg[0]->pixels = (unsigned char*)img_hello1.pixel_data; + simg[0]->width = img_hello1.width; + simg[0]->height = img_hello1.height; + + simg[1] = new Image; + simg[1]->pixels = (unsigned char*)img_hello2.pixel_data; + simg[1]->width = img_hello2.width; + simg[1]->height = img_hello2.height; + + ppmain.spawn_map = simg[0]; + ppmain.spawn_map_speed = 0.8; + psys.pp = ppmain; + + // explosion parameters + ppexpl = ppmain; + ppexpl.pcolor_start = ppmain.pcolor_mid; + ppexpl.pcolor_mid = lerp(ppexpl.pcolor_start, ppexpl.pcolor_end, 0.5); + + ppexpl.palpha_start = 1.0; + ppexpl.palpha_mid = 0.5; + ppexpl.palpha_end = 0.05; + + ppexpl.pscale_start = 1.0; + ppexpl.pscale_mid = 3.0; + ppexpl.pscale_end = 5.0; + ppexpl.gravity = Vector3(0, -6, 0); + + // flame parameters + ppflame = ppexpl; + ppflame.pcolor_start = Vector3(1.0, 0.8, 0.2) * 0.5; + ppflame.pcolor_mid = Vector3(1.0, 0.3, 0.2) * 0.5; + ppflame.pcolor_end = Vector3(0.1, 0.1, 0.1); + //ppflame.pcolor_mid = lerp(ppflame.pcolor_start, ppflame.pcolor_end, 0.6); + + ppflame.life = 0.5; + ppflame.life_range = 0.25; + ppflame.size = 0.07; + ppflame.size_range = 0.03; + ppflame.spawn_rate = 18000; + ppflame.gravity = Vector3(0, 2, 0); + + ppflame.palpha_start *= 0.7; + ppflame.palpha_mid *= 0.7; + ppflame.palpha_end *= 0.7; + + return true; +} + +void fx_cleanup() +{ + delete pimg; + delete simg[0]; + delete simg[1]; +} + +void fx_draw(unsigned long msec) +{ + static unsigned long prev_msec; + float dt = (msec - prev_msec) / 1000.0; + prev_msec = msec; + + psys.update(dt); + psys.draw(); +} + +void fx_dbg() +{ + psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5); + psys.pp = ppflame; + //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5); + //psys.pp = ppexpl; +} diff -r a4ffd9e6984c -r 57c6f7b70126 src/effect.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/effect.h Wed Aug 19 09:17:20 2015 +0300 @@ -0,0 +1,10 @@ +#ifndef TBOMB_H_ +#define TBOMB_H_ + +bool fx_init(); +void fx_cleanup(); + +void fx_draw(unsigned long msec); +void fx_dbg(); + +#endif // TBOMB_H_ diff -r a4ffd9e6984c -r 57c6f7b70126 src/main.cc --- a/src/main.cc Wed Aug 19 09:13:48 2015 +0300 +++ b/src/main.cc Wed Aug 19 09:17:20 2015 +0300 @@ -6,7 +6,7 @@ #else #include #endif -#include "tbomb.h" +#include "effect.h" void display(); void idle(); @@ -38,10 +38,10 @@ glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); - if(!tbomb_init()) { + if(!fx_init()) { return 1; } - atexit(tbomb_cleanup); + atexit(fx_cleanup); start_time = glutGet(GLUT_ELAPSED_TIME); glutMainLoop(); @@ -54,7 +54,7 @@ glClear(GL_COLOR_BUFFER_BIT); - tbomb_draw(msec); + fx_draw(msec); glutSwapBuffers(); assert(glGetError() == GL_NO_ERROR); @@ -93,7 +93,7 @@ break; case ' ': - tbomb_dbg(); + fx_dbg(); break; } } diff -r a4ffd9e6984c -r 57c6f7b70126 src/tbomb.cc --- a/src/tbomb.cc Wed Aug 19 09:13:48 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -#include -#include -#include "opengl.h" -#include "tbomb.h" -#include "psys.h" - -#include "hello1.h" -#include "hello2.h" -#include "pimg.h" - -static PSysParam ppmain; -static PSysParam ppexpl, ppflame; - -static ParticleSystem psys; -static Image *pimg; -static Image *simg[2]; - -bool tbomb_init() -{ - ppmain.spawn_rate = 20000; - ppmain.size = 0.06; - ppmain.spawn_range = 0.01; - ppmain.life = 0.4; - ppmain.gravity = Vector3(0, 0.01, 0); - - ppmain.pcolor_start = Vector3(0.717, 0.494, 0.951) * 0.6; - ppmain.pcolor_end = Vector3(0.9, 0.135, 0.005) * 0.6; - ppmain.pcolor_mid = lerp(ppmain.pcolor_start, ppmain.pcolor_mid, 0.5); - - ppmain.palpha_start = 1.0; - ppmain.palpha_mid = 0.5; - ppmain.palpha_end = 0.0; - - ppmain.pscale_start = 1.0; - ppmain.pscale_mid = 1.0; - ppmain.pscale_end = 7.0; - - pimg = new Image; - pimg->pixels = (unsigned char*)img_particle.pixel_data; - pimg->width = img_particle.width; - pimg->height = img_particle.height; - - ppmain.pimg = pimg; - - simg[0] = new Image; - simg[0]->pixels = (unsigned char*)img_hello1.pixel_data; - simg[0]->width = img_hello1.width; - simg[0]->height = img_hello1.height; - - simg[1] = new Image; - simg[1]->pixels = (unsigned char*)img_hello2.pixel_data; - simg[1]->width = img_hello2.width; - simg[1]->height = img_hello2.height; - - ppmain.spawn_map = simg[0]; - ppmain.spawn_map_speed = 0.8; - psys.pp = ppmain; - - // explosion parameters - ppexpl = ppmain; - ppexpl.pcolor_start = ppmain.pcolor_mid; - ppexpl.pcolor_mid = lerp(ppexpl.pcolor_start, ppexpl.pcolor_end, 0.5); - - ppexpl.palpha_start = 1.0; - ppexpl.palpha_mid = 0.5; - ppexpl.palpha_end = 0.05; - - ppexpl.pscale_start = 1.0; - ppexpl.pscale_mid = 3.0; - ppexpl.pscale_end = 5.0; - ppexpl.gravity = Vector3(0, -6, 0); - - // flame parameters - ppflame = ppexpl; - ppflame.pcolor_start = Vector3(1.0, 0.8, 0.2) * 0.5; - ppflame.pcolor_mid = Vector3(1.0, 0.3, 0.2) * 0.5; - ppflame.pcolor_end = Vector3(0.1, 0.1, 0.1); - //ppflame.pcolor_mid = lerp(ppflame.pcolor_start, ppflame.pcolor_end, 0.6); - - ppflame.life = 0.5; - ppflame.life_range = 0.25; - ppflame.size = 0.07; - ppflame.size_range = 0.03; - ppflame.spawn_rate = 18000; - ppflame.gravity = Vector3(0, 2, 0); - - ppflame.palpha_start *= 0.7; - ppflame.palpha_mid *= 0.7; - ppflame.palpha_end *= 0.7; - - return true; -} - -void tbomb_cleanup() -{ - delete pimg; - delete simg[0]; - delete simg[1]; -} - -void tbomb_draw(unsigned long msec) -{ - static unsigned long prev_msec; - float dt = (msec - prev_msec) / 1000.0; - prev_msec = msec; - - psys.update(dt); - psys.draw(); -} - -void tbomb_dbg() -{ - psys.explode(Vector3(0, 0, 0), 2.5, ppflame.life, 1.5); - psys.pp = ppflame; - //psys.explode(Vector3(0, -0.2, 0), 3.0, 1.5); - //psys.pp = ppexpl; -} diff -r a4ffd9e6984c -r 57c6f7b70126 src/tbomb.h --- a/src/tbomb.h Wed Aug 19 09:13:48 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -#ifndef TBOMB_H_ -#define TBOMB_H_ - -bool tbomb_init(); -void tbomb_cleanup(); - -void tbomb_draw(unsigned long msec); -void tbomb_dbg(); - -#endif // TBOMB_H_