//-----------------------------------------------------------------------
 ParticleSystem* ParticleSystemManager::createSystemImpl(const String& name,
     size_t quota, const String& resourceGroup)
 {
     ParticleSystem* sys = OGRE_NEW ParticleSystem(name, resourceGroup);
     sys->setParticleQuota(quota);
     return sys;
 }
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
    
    ofVec2f mouse(x,y);
    
    
    ps.push_back(ParticleSystem(mouse));

}
 //-----------------------------------------------------------------------
 ParticleSystem* ParticleSystemManager::createSystemImpl(IdType id,
                                             ObjectMemoryManager *objectMemoryManager,
                                             size_t quota, const String& resourceGroup)
 {
     ParticleSystem* sys = OGRE_NEW ParticleSystem( id, objectMemoryManager, resourceGroup );
     sys->setParticleQuota(quota);
     return sys;
 }
void ParticleManager::add(std::string name, sf::Texture* texture, sf::Vector2u frameSize, unsigned int maxParticles)
{
    if(has(name))
        return;

    systems.push_back(std::pair<std::string, ParticleSystem>(name, ParticleSystem(texture, frameSize, maxParticles)));

}
void ParticleManager::add(std::string name, sf::Color color, float variance, sf::Vector2u size, unsigned int maxParticles)
{
    if(has(name))
        return;

    systems.push_back(std::pair<std::string, ParticleSystem>(name, ParticleSystem(color, variance, size, maxParticles)));

}
Exemple #6
0
int main (int argc, char *argv[]) {

	srand(time(NULL));
	initGraphics(argc, argv);
	glEnable(GL_POINT_SMOOTH);

	Particle::startLifeSpan = 50;
	Particle::startColour = emitColours[0];
	currentColour = Particle::startColour;
	Particle::initialVelocity = 20.0;
	Particle::terminalVelocity = 50;
	Particle::airResistance = 1.0;
	Particle::renderMode = PARTICLERENDERMODE_POINT;
	Particle::bounce = 0.5;
	ParticleEmitter::emitSpread = 1.0;
	ParticleSystem::perEmit = 4;

	Texture::load("grass.png", "grass");
	Texture::load("sky.png", "sky");
	Texture::load("shine.png", "shine");

	glPointSize(10.0f);

	std::cout << glGetString(GL_RENDERER);

	createMoutains(&mountainY);

	createTrees();

	initFlyBys();

	// Create water sprinkler
	particleSystem = ParticleSystem();
	particleSystem.setEmitTicks(emitFrequency);
	makeSprinkler();

	camera = Vector3(
		cameraDistance * cos(cameraAngle * (M_PI / 180)), 
		cameraElevation , 
		cameraDistance * sin(cameraAngle * (M_PI/ 180))
	);

	gravitationalForce[0] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0, Vector3(100.0, -100, -400.0));
	gravitationalForce[1] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, -300.0));
	gravitationalForce[2] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, -200.0));
	gravitationalForce[3] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, -100.0));
	gravitationalForce[4] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, 0.0));
	gravitationalForce[5] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, 100.0));
	gravitationalForce[6] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, 200.0));
	gravitationalForce[7] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, 300.0));
	gravitationalForce[8] = GravitationalForce(GRAVITATIONALFORCETYPE_NONE, 10.0,  Vector3(100.0, -100, 400.0));

	glutMainLoop();

}
//--------------------------------------------------------------
void testApp::setup(){
    
    ofSetVerticalSync(true);
	ofEnableSmoothing();
    ofBackground(255);
    
    ofVec2f origin(ofGetWidth()/2, 50);
 
    
    ps.push_back(ParticleSystem(origin));
}
ParticleSystem* ParticleManager::InitParticleSystem(GLint shader, int numParticles)
{
	unsigned int index = _pSystems.size();
	_pSystems.push_back(ParticleSystem());

	ParticleSystem* system = &_pSystems[index];

	system->transform = Transform();
	system->transform.position = glm::vec3();
	system->transform.rotation = glm::quat();
	system->transform.scale = glm::vec3(1.0f, 1.0f, 1.0f);
	system->transform.linearVelocity = glm::vec3();
	system->transform.angularVelocity = glm::quat();
	system->transform.rotationOrigin = glm::vec3();
	system->transform.translate = glm::mat4();
	system->transform.model = glm::mat4();
	system->transform.parent = nullptr;

	system->shader = shader;

	system->timeSinceLastEmission = 0.0f;
	system->lifetime = 0.0f;
	system->arc = 0;
	system->numParticles = numParticles;
	system->texture = 0;
	system->nextAvailableParticle = 0;
	
	system->particles = new Particle[numParticles];
	for (int i = 0; i < numParticles; ++i)
	{
		system->particles[i].position_age = glm::vec4(0.0f, 0.0f, 0.0f, -1.0f);
		system->particles[i].velocity = glm::vec3();
	}

	system->particleBuffer = new GLubyte[sizeof(Particle) * numParticles];
	memcpy(system->particleBuffer, system->particles, sizeof(Particle) * numParticles);

	glGenVertexArrays(1, &system->vao);
	glBindVertexArray(system->vao);

	glGenBuffers(1, &system->vbo);
	glBindBuffer(GL_ARRAY_BUFFER, system->vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(Particle) * numParticles, system->particleBuffer, GL_DYNAMIC_DRAW);
	
	GLuint pos_ageAttrib = glGetAttribLocation(shader, "position_age");
	glEnableVertexAttribArray(pos_ageAttrib);
	glVertexAttribPointer(pos_ageAttrib, 4, GL_FLOAT, GL_FALSE, sizeof(Particle), 0);

	GLuint colorAttrib = glGetAttribLocation(shader, "color");
	glEnableVertexAttribArray(colorAttrib);
	glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, sizeof(Particle), (void*)(sizeof(GLfloat) * 4));
	
	return system;
}
//--------------------------------------------------------------
void testApp::setup(){
    
    ofSetVerticalSync(true);
	ofEnableSmoothing();
    ofBackground(255);
    
    ofVec2f origin(ofGetWidth()/2, 50);
  //ps.resize(1);
    
    
  //  for(int i = 0; i < ps.size(); i++){
  //  ps[i].setup(origin);}
    
    ps.push_back(ParticleSystem(origin));
}
Exemple #10
0
void mouse(int btn, int state, int x, int y)
{
	Vector3 tmp;
	switch (btn)
	{
    		case GLUT_LEFT_BUTTON:
		if(state == GLUT_DOWN)
		{
			tmp.x = x;
			tmp.y = 800-y;
			psystems.push_back(ParticleSystem(tmp));	
		}
		break;
	}
}
ParticleSystem::ParticleSystem(float r, int n, float t, float s, float sp, float gr, vec3 d, float p)
    : m_rate(r),
      m_nbMax(n),
      m_maxTimeAlive(t),
      m_started(false),
      m_spread(s),
      m_speed(sp),
      m_gravity(gr),
      m_down(d),
      gl_positions(NULL),
      gl_velocities(NULL),
      gl_ages(NULL),
      m_pointSize(p)
{
    ParticleSystem();
}
Exemple #12
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofSetLogLevel(OF_LOG_VERBOSE);
    ofSetVerticalSync(true);
    ofSetFrameRate(60);
    ofSetWindowTitle("Atiko7 Kinect Particles");
    ofDisableArbTex();
    spriteImg.load("sprite.png");
    
    mesh.setMode(OF_PRIMITIVE_POINTS);
    
    gui.setup();
    gui.add(guiLife1.setup("Life1", 18, 0, 50));
    gui.add(guiSize1.setup("Size1", 7, 1, 30));
//    gui.add(guiLife2.setup("Life2", 18, 0, 50));
//    gui.add(guiSize2.setup("Size2", 7, 1, 30));
    
    for(int i=0; i<maxPS; i++){
        ps.push_back(ParticleSystem(1, lifeDec1));
    }
    indices.assign(maxPS, 0);
    
    int a = 0;
    for (int i = 0; i < indices.size(); i++) {
        a +=steps+ ofRandom(0, 10);
        indices[i]=a;
        mesh.addColor(gColor);
        mesh.addVertex(ofVec3f(ps[i].particles[0].pos.x, ps[i].particles[0].pos.y, 0));
    }

    if (useKinect){
        niContext.setup();
        niDepthGenerator.setup( &niContext );
        niImageGenerator.setup( &niContext );
        niUserGenerator.setup( &niContext );
        niUserGenerator.setUseMaskPixels(true);
        niUserGenerator.setUseCloudPoints(true);
        niContext.setMirror(true);
        niContext.registerViewport();
    }
    userpixels.allocate(640, 480, 1);
    myImage.allocate(640, 480, OF_IMAGE_GRAYSCALE);
    myImage2.allocate(640, 480, OF_IMAGE_COLOR);

}
    //-----------------------------------------------------------------------
    ParticleSystem* ParticleSystemManager::createTemplate(const String& name, 
        const String& resourceGroup)
    {
        OGRE_LOCK_AUTO_MUTEX;
        // check name
        if (mSystemTemplates.find(name) != mSystemTemplates.end())
        {
#if OGRE_PLATFORM == OGRE_PLATFORM_WINRT
            LogManager::getSingleton().logMessage("ParticleSystem template with name '" + name + "' already exists.");
            return NULL;
#else
            OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, 
                "ParticleSystem template with name '" + name + "' already exists.", 
                "ParticleSystemManager::createTemplate");
#endif
        }

        ParticleSystem* tpl = OGRE_NEW ParticleSystem(name, resourceGroup);
        addTemplate(name, tpl);
        return tpl;

    }
	SmokeExample(void)
	 : emitters()
	 , projection_matrix(prog, "ProjectionMatrix")
	 , camera_matrix(prog, "CameraMatrix")
	{
		emitters.push_back(
			ParticleSystem(
				ListOf<Vec3f>
					(Vec3f(-20.0f, -10.0f,  10.0f))
					(Vec3f( 20.0f,   0.0f, -20.0f))
					(Vec3f( 20.0f,  10.0f,  20.0f))
					(Vec3f(-20.0f,   0.0f, -10.0f))
				.As<std::vector<Vec3f>>(), 5.0, 200.0
			)
		);
		emitters.push_back(
			ParticleSystem(
				ListOf<Vec3f>
					(Vec3f( 30.0f,   0.0f,   0.0f))
					(Vec3f(-30.0f,   0.0f,   0.0f))
					(Vec3f(-20.0f,  20.0f,   0.0f))
					(Vec3f( 20.0f, -10.0f,   0.0f))
				.As<std::vector<Vec3f>>(), 3.0, 200.0
			)
		);
		emitters.push_back(
			ParticleSystem(
				ListOf<Vec3f>
					(Vec3f(  5.0f,  20.0f,  20.0f))
					(Vec3f( -5.0f,  20.0f, -20.0f))
					(Vec3f(  5.0f, -20.0f, -20.0f))
					(Vec3f( -5.0f, -20.0f,  20.0f))
				.As<std::vector<Vec3f>>(), 20.0, 100.0
			)
		);
		// Set the vertex shader source
		vs.Source(
			"#version 330\n"
			"uniform mat4 CameraMatrix;"
			"in vec4 Position;"
			"in float Age;"
			"out float vertAge;"
			"void main(void)"
			"{"
			"	gl_Position = CameraMatrix * Position;"
			"	vertAge = Age;"
			"}"
		);
		// compile it
		vs.Compile();

		// Set the geometry shader source
		gs.Source(
			"#version 330\n"
			"layout(points) in;"
			"layout(triangle_strip, max_vertices = 4) out;"
			"uniform mat4 ProjectionMatrix;"
			"in float vertAge[];"
			"out float geomAge;"
			"void main(void)"
			"{"
			"	if(vertAge[0] > 1.0) return;"
			"	float s = 0.5;"
			"	float yo[2] = float[2](-1.0, 1.0);"
			"	float xo[2] = float[2](-1.0, 1.0);"
			"	for(int j=0;j!=2;++j)"
			"	for(int i=0;i!=2;++i)"
			"	{"
			"		float xoffs = xo[i]*(1.0+vertAge[0])*s;"
			"		float yoffs = yo[j]*(1.0+vertAge[0])*s;"
			"		gl_Position = ProjectionMatrix * vec4("
			"			gl_in[0].gl_Position.x-xoffs,"
			"			gl_in[0].gl_Position.y-yoffs,"
			"			gl_in[0].gl_Position.z,"
			"			1.0"
			"		);"
			"		geomAge = vertAge[0];"
			"		EmitVertex();"
			"	}"
			"	EndPrimitive();"
			"}"
		);
		// compile it
		gs.Compile();

		// set the fragment shader source
		fs.Source(
			"#version 330\n"
			"in float geomAge;"
			"out vec4 fragColor;"
			"void main(void)"
			"{"
			"	vec3 Color1 = vec3(1.0, 0.5, 0.5);"
			"	vec3 Color2 = vec3(0.3, 0.1, 0.1);"
			"	fragColor = vec4("
			"		mix(Color1, Color2, geomAge),"
			"		1.0 - geomAge"
			"	);"
			"}"
		);
		// compile it
		fs.Compile();

		// attach the shaders to the program
		prog.AttachShader(vs);
		prog.AttachShader(gs);
		prog.AttachShader(fs);
		// link and use it
		prog.Link();
		prog.Use();

		// bind the VAO for the particles
		particles.Bind();

		// bind the VBO for the particle positions
		pos_buf.Bind(Buffer::Target::Array);
		{
			Buffer::Data(Buffer::Target::Array, positions, BufferUsage::DynamicDraw);
			VertexAttribArray attr(prog, "Position");
			attr.Setup(3, DataType::Float);
			attr.Enable();
		}

		// bind the VBO for the particle ages
		age_buf.Bind(Buffer::Target::Array);
		{
			Buffer::Data(Buffer::Target::Array, ages, BufferUsage::DynamicDraw);
			VertexAttribArray attr(prog, "Age");
			attr.Setup(1, DataType::Float);
			attr.Enable();
		}
		//
		gl.ClearColor(0.9f, 0.9f, 0.9f, 0.0f);
		gl.ClearDepth(1.0f);
		gl.Enable(Capability::DepthTest);
		gl.Enable(Capability::Blend);
		gl.BlendFunc(BlendFn::SrcAlpha, BlendFn::OneMinusSrcAlpha);
	}