void Render(double time)
	{
		// update the particle positions, ages and directions
		GLuint i = 0;
		float time_diff = (time - prev_time);
		float age_mult = 0.2f;
		while(i != positions.size())
		{
			float drag = 0.1f * (time_diff);
			if((ages[i] += time_diff * age_mult) < 1.0f)
			{
				directions[i] *= (1.0f - drag);
				positions[i] += directions[i]*time_diff;
			}
			else
			{
				ages[i] = 0.0f;
				directions[i] = NewDirection();
				positions[i] = Vec3f();
			}
			++i;
		}
		// if there are not enough particles yet
		if(i != particle_count)
		{
			float spawn_interval = 1.0f/(age_mult*particle_count);
			if(prev_spawn + spawn_interval < time)
			{
				directions.push_back(NewDirection());
				positions.push_back(Vec3f());
				ages.push_back(0.0f);
				prev_spawn = time;
			}
		}
		prev_time = time;

		assert(positions.size() == directions.size());
		assert(positions.size() == ages.size());

		// upload the particle positions
		pos_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, positions);
		// upload the particle ages
		age_buf.Bind(Buffer::Target::Array);
		Buffer::Data(Buffer::Target::Array, ages);

		gl.Clear().ColorBuffer().DepthBuffer();
		//
		// set the matrix for camera orbiting the origin
		camera_matrix.Set(
			CamMatrixf::Orbiting(
				Vec3f(),
				18.0f,
				FullCircles(time * 0.5),
				Degrees(45)
			)
		);

		gl.DrawArrays(PrimitiveType::Points, 0, positions.size());
	}
Exemple #2
0
void Player::CheckDirections()
{
	if (mDirection == FORWARD		&& mNode->Front!=NULL) 
	{
		if (!mNode->Front->GhostNode)
		{NewDirection(mNode->Front);}
	}
	else if (mDirection == BACKWARD	&& mNode->Back!=NULL)
	{
		if (!mNode->Back->GhostNode)
		{NewDirection(mNode->Back);}
	}
	else if (mDirection == LEFT		&& mNode->Left!=NULL)
	{
		if (!mNode->Left->GhostNode)
		{NewDirection(mNode->Left);}
	}
	else if (mDirection == RIGHT	&& mNode->Right!=NULL)
	{
		if (!mNode->Right->GhostNode)
		{NewDirection(mNode->Right);}
	}
	else mDirection = PAUSE;
}
	// Spawns a new particle if the time is right
	bool SpawnParticle(
		double time,
		Vec3f& position,
		Vec3f& direction,
		float& age
	)
	{
		float new_age = time - spawn_time - spawn_interval;
		if(new_age >= 0.0f)
		{
			spawn_time += spawn_interval;
			direction = NewDirection();
			Vec3f emitter_pos = path.Position(spawn_time/cycle_time);
			position = emitter_pos + direction;
			age = new_age;
			return true;
		}
		return false;
	}