TEST(ParticleGenerator, UpdateIntensity){
    ParticleGenerator generator = ParticleGenerator();

    generator.intensity = 2;
    generator.update();
    EXPECT_EQ(generator.particles.size(), 2);
}
void ParticleRenderer::setup(int maxParticles){
	
//	meshBuilder.setDepthOnly();
//	meshBuilder.setSimplification(4);
//	meshBuilder.cacheValidVertices = true;
	
	perlinForce = new ForcePerlin();
	spinForce = new ForceSpin();
	gravityForce = new ForceGravity();
	
	for(int i = 0; i < 10000; i++){
		ParticleGenerator g;
		g.addForce(perlinForce);
		g.addForce(spinForce);
		g.addForce(gravityForce);
		g.primaryColor = &primaryColor;
		g.secondaryColor = &secondaryColor;
		emitters.push_back(g);
	}
	
	for(int i = 0; i < maxParticles; i++){
		mesh.addVertex(ofVec3f(0,0,0));
		mesh.addColor(ofFloatColor(1.0,1.0,1.0,1.0));
		mesh.addTexCoord(ofVec2f(0.0,0.0));
	}
	
	maxAllowedParticles = maxParticles;
}
OGLViewer::OGLViewer(QWidget *parent)
	: QOpenGLWidget(parent), tcount(0)
	, fps(30), timestep(1.0 / fps), isSim(false)
{
	// Set surface format for current widget
	QSurfaceFormat format;
	format.setDepthBufferSize(32);
	format.setStencilBufferSize(8);
	format.setVersion(4, 5);
	format.setProfile(QSurfaceFormat::CoreProfile);
	this->setFormat(format);

	// Link timer trigger
	process_time.start();
	QTimer *timer = new QTimer(this);
	/*timer->setSingleShot(false);*/
	connect(timer, SIGNAL(timeout()), this, SLOT(update()));
	timer->start(0);

	// Read obj file
#ifdef _DEBUG
	box_mesh = new Mesh("../../scene/obj/cube_huge.obj");
	poly_mesh = new Mesh("../../scene/obj/bunny_simple.obj");
	poly_bound = new Mesh("../../scene/obj/bunny_bound.obj");
#else
	box_mesh = new Mesh("cube_large.obj");
	poly_mesh = new Mesh("bunny_simple.obj");
	poly_bound = new Mesh("bunny_bound.obj");
#endif // _DEBUG
	poly_bound->refine(triangleList);
	mytree = new KdTreeAccel(triangleList);

	texW = sparkTex.getWidth();
	texH = sparkTex.getHeight();
	sparkTex.getPixelsRGBA(tex_pixels);

	// Initialize particle generators
	//Point3D newpos(0.0, 0.0, 0.0), vel(0.3, 1.0, 1.0), vel_var(0.3, 0.3, 0.3);
	ParticleGenerator* pg = new ParticleGenerator(
		3500, 1000, 20, timestep, 3, 0.6,
		2.0, 1.2,
		Point3D(0.0, 5.0, 0.0),
		Vector3D(0, -10, 0), Vector3D(1, 0, 0),
		ParticleGenerator::CONCENTRIC_DISK, 0.5);
	Vector3D* gravity = new Vector3D(0.0, -9.8, 0.0);
	Vector3D* wind = new Vector3D(0, 0.0, 0.0);
	pg->addForce(gravity);
	pg->addForce(wind);
	pgs.push_back(pg);
	pg->exportVBO(ptc_size, ptc_verts, ptc_vels, ptc_life, ptc_alive, true);
	pg->addCollision(mytree);
	

	resetCamera();

	// Initialize transform matrix
	matrix.setIdentity();// setRotation(20, 0, 0);
	matrix.exportVBO(model_mat);
}
TEST(ParticleGenerator, NewParticlePosition) {
    ParticleGenerator generator = ParticleGenerator();

    generator.intensity = 1;
    Particle* p = generator.generate();

    EXPECT_EQ(p->position[0], generator.position[0]);
    delete p;
}
TEST(ParticleGenerator, NewParticleVelocity) {
    ParticleGenerator generator = ParticleGenerator();
    generator.direction = glm::vec3(1,0,0);

    generator.intensity = 1;
    Particle* p = generator.generate();

    EXPECT_EQ(p->velocity[0], generator.direction[0]);
    delete p;
}