ControlledForceFieldRenderable::ControlledForceFieldRenderable(ShaderProgramPtr program,ConstantForceFieldPtr forceField)
    : HierarchicalRenderable(program),
    m_force(forceField), m_pBuffer(0), m_cBuffer(0), m_nBuffer(0)
{
    glm::vec3 initial_direction(1,0,0);
    m_status = ControlledForceFieldStatus(initial_direction);

    //Create geometric data to display an arrow representing the movement of the particle
    const std::vector<ParticlePtr>& particles = m_force->getParticles();
    m_positions.clear();
    m_colors.clear();
    m_normals.clear();

    for (ParticlePtr p : particles) {
        m_positions.push_back(p->getPosition());
        m_positions.push_back(p->getPosition() + m_status.movement);
        m_colors.push_back(glm::vec4(1.0,0.0,0.0,1.0));
        m_colors.push_back(glm::vec4(1.0,0.0,0.0,1.0));
        m_normals.push_back(glm::vec3(1.0,0.0,0.0));
        m_normals.push_back(glm::vec3(1.0,0.0,0.0));
    }

    //Create buffers
    glGenBuffers(1, &m_pBuffer); //vertices
    glGenBuffers(1, &m_cBuffer); //colors
    glGenBuffers(1, &m_nBuffer); //normals

    //Activate buffer and send data to the graphics card
    glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_pBuffer));
    glcheck(glBufferData(GL_ARRAY_BUFFER, m_positions.size()*sizeof(glm::vec3), m_positions.data(), GL_STATIC_DRAW));
    glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_cBuffer));
    glcheck(glBufferData(GL_ARRAY_BUFFER, m_colors.size()*sizeof(glm::vec4), m_colors.data(), GL_STATIC_DRAW));
    glcheck(glBindBuffer(GL_ARRAY_BUFFER, m_nBuffer));
    glcheck(glBufferData(GL_ARRAY_BUFFER, m_normals.size()*sizeof(glm::vec3), m_normals.data(), GL_STATIC_DRAW));
}
Пример #2
0
 void dispersion()
 {
  to_begin=1;
 lcd_cursor(1,1);
  lcd_string("DISPE");
  velocity(VELOCITY_MAX,VELOCITY_MAX);
		forward();
		while(1)
		{
		follow();
		lcd_print(2,16,bot_dir,1);
			if(isPlus())
			{
					follow();
					while(isPlus());
					if(value == 0 && end == 0)		
					initial_direction(bot_id);	
					
					if(value == 0 && end == 1)
					{
						turnRight();
						change_dirn(bot_dir);
					}
				value++;
						
			}
			if(isEnd())
			{
				USART_Transmit('*');
				USART_Transmit(bot_id);
				switch(bot_id)
				{
				case 'A':	flag[0]++;break;
				case 'B':	flag[1]++;break;
				case 'C': 	flag[2]++;break;
				case 'D':	flag[3]++;break;
				}
				
				if(end==0)
				{
					turnBack();
					value = 0;
				
				}
				if(end==1)
				{  
					turnBack();
					value = 0;
				}
				if(end ==2)
				{
				length =value-1;
				lcd_print(1,7,length,1);
				turnBack();
				stop();
				break;
				}
				end++;
			  
			}
		}
}