2020-03-16 19:46:54 +00:00
|
|
|
#include "particlesystem.h"
|
|
|
|
#include "initOpenGL.h"
|
2020-03-18 11:29:08 +00:00
|
|
|
#include "utils.h"
|
2020-03-16 19:46:54 +00:00
|
|
|
|
2020-03-20 15:33:43 +00:00
|
|
|
#define PARTICLE_AMOUNT 10000
|
2020-03-16 19:46:54 +00:00
|
|
|
|
|
|
|
void calcPos(particle *p, float dt);
|
|
|
|
void calcCol(particle *p);
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
/************* INIT *************/
|
|
|
|
// Init OpenGL and GLFW
|
|
|
|
initGLFW();
|
|
|
|
setErrorCallbackGL();
|
|
|
|
|
|
|
|
int width = WIDTH, height = HEIGHT;
|
|
|
|
GLFWwindow *window = createGLFWWindow(WIDTH, HEIGHT, "Informatikprojekt - OpenGL CPU");
|
|
|
|
|
|
|
|
setCurrentContextGL(window);
|
|
|
|
setFramebufferSizeCallbackGL(window);
|
|
|
|
|
|
|
|
// glad
|
|
|
|
initGlad();
|
|
|
|
|
|
|
|
/************* PARTICLE SYSTEM *************/
|
|
|
|
vector3f *epos1 = initVector3f(0, 0, 0);
|
|
|
|
emitter *e1 = initEmitter(epos1, PARTICLE_AMOUNT);
|
|
|
|
particle_system *ps = initParticleSystem(1);
|
|
|
|
(ps->emitters)[0] = e1;
|
|
|
|
initRandomParticles(e1);
|
|
|
|
|
|
|
|
/************* RENDER LOOP *************/
|
|
|
|
double time, tFrame, tLast = 0;
|
|
|
|
while (!glfwWindowShouldClose(window))
|
|
|
|
{
|
|
|
|
time = glfwGetTime();
|
|
|
|
tFrame = time - tLast;
|
|
|
|
tLast = time;
|
|
|
|
|
|
|
|
/*** UPDATE ***/
|
|
|
|
updateParticles((float) tFrame, ps, calcPos, calcCol);
|
|
|
|
|
|
|
|
/*** RENDER ***/
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
|
|
|
glfwGetFramebufferSize(window, &width, &height);
|
|
|
|
|
|
|
|
emitter *e;
|
|
|
|
particle *p;
|
|
|
|
vector3f *pos;
|
2020-04-01 20:17:35 +00:00
|
|
|
for (int y = 0; y < ps->eamount; y++)
|
2020-03-16 19:46:54 +00:00
|
|
|
{
|
2020-04-01 20:17:35 +00:00
|
|
|
e = (ps->emitters)[y];
|
|
|
|
for (int x = 0; x < e->pamount; x++)
|
2020-03-16 19:46:54 +00:00
|
|
|
{
|
2020-04-01 20:17:35 +00:00
|
|
|
p = (e->particles)[x];
|
2020-03-16 19:46:54 +00:00
|
|
|
pos = p->position;
|
|
|
|
|
|
|
|
glColor3f(p->color->x, p->color->y, p->color->z);
|
|
|
|
glBegin(GL_POINTS);
|
2021-03-03 16:19:21 +00:00
|
|
|
glVertex3f(pos->x, pos->y, pos->z);
|
2020-03-16 19:46:54 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwSwapBuffers(window);
|
|
|
|
glfwPollEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
//END
|
|
|
|
terminateGLFW(window);
|
|
|
|
freeParticleSystem(ps);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void calcPos(particle *p, float dt)
|
|
|
|
{
|
|
|
|
p->position->x += p->velocity->x * dt;
|
|
|
|
p->position->y += p->velocity->y * dt;
|
|
|
|
p->position->z += p->velocity->z * dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void calcCol(particle *p)
|
|
|
|
{
|
|
|
|
p->color->x -= 0.00001f;
|
|
|
|
p->color->y -= 0.00001f;
|
|
|
|
p->color->z -= 0.00001f;
|
2020-04-01 20:17:35 +00:00
|
|
|
}
|