Commit bd3a3ba1 authored by Thibault Soucarre's avatar Thibault Soucarre

arrows head are now correctly affected by settings

parent 813ce278
......@@ -269,54 +269,56 @@ void Render_alternate::paintGL(){
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1.0));
mvp = _projection * _modelview;
//draw the lines
std::map<EntityValue*, std::pair<Vbo *, Vbo*> >::iterator it_link = _arrows.begin();
while(it_link != _arrows.end()){
Shader*s = _arrows_shaders[it_link->first];
std::map<EntityValue*, std::pair<Vbo *, Vbo*> >::iterator it_arrow = _arrows.begin();
while(it_arrow != _arrows.end()){
Shader*s = _arrows_shaders[it_arrow->first];
glUseProgram(s->getProgramID());
it_link->second.first->lock();
it_arrow->second.first->lock();
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
if(it_link->first == NULL || it_link->first->get_visible())
glDrawArrays(GL_LINES, 0, it_link->second.first->getNbVertex());
it_link->second.first->unlock();
if(Info::Render::_arrows_shape == 1){
std::cout << "head of the arrow " << it_link->second.second->getNbVertex() << " " << it_link->second.first->getNbVertex() << std::endl;
it_link->second.second->lock();
if(it_arrow->first == NULL || it_arrow->first->get_visible())
glDrawArrays(GL_LINES, 0, it_arrow->second.first->getNbVertex());
it_arrow->second.first->unlock();
if(Info::Render::_arrows_shape == 1){ //head = points
std::cout << "head of the arrow " << it_arrow->second.second->getNbVertex() << " " << it_arrow->second.first->getNbVertex() << std::endl;
it_arrow->second.second->lock();
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_POINT_SMOOTH);
glPointSize(5);
if(it_link->first == NULL || it_link->first->get_visible())
glDrawArrays(GL_POINTS, 0, it_link->second.second->getNbVertex());
it_link->second.second->unlock();
if(it_arrow->first == NULL || it_arrow->first->get_visible())
glDrawArrays(GL_POINTS, 0, it_arrow->second.second->getNbVertex());
it_arrow->second.second->unlock();
}
it_link++;
it_arrow++;
}
//draw the head of the arrow according to the parameter arrows_shape
int n = _links.size()/4;
switch(Info::Render::_arrows_shape){
case 0: //triangles
_arrows3.lock();
_modelview = glm::scale(_modelview, glm::vec3(1/_x_state_scale, 1/_y_state_scale, 1));
tmp2 = _modelview;
for(int i=0; i<n ; i++) {
_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*_links[4*i+2], _y_state_scale*_links[4*i+3], 0));
_modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_TRIANGLES, 0, _arrows3.getNbVertex());
_modelview = tmp2;
if(Info::Render::_arrows_shape == 0){ //triangles
std::map<EntityValue*, std::vector<Element_pos> >::iterator it_link = _links.begin();
_modelview = glm::scale(_modelview, glm::vec3(1/_x_state_scale, 1/_y_state_scale, 1));
tmp2 = _modelview;
_arrows3.lock();
while(it_link != _links.end()){
Shader *s = _arrows_shaders[it_link->first];
glUseProgram(s->getProgramID());
std::vector<Element_pos> v = it_link->second;
int n = v.size()/3;
std::cout << "on est là " << n << std::endl;
if(it_link->first != NULL && !it_link->first->get_visible()){
it_link++;
continue;
}
for(int i=0 ; i<n ; i++){
_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale * v[3*i], _y_state_scale * v[3*i+1], 0));
_modelview = glm::rotate(_modelview, v[3*i+2], glm::vec3(0, 0, 1));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
glDrawArrays(GL_TRIANGLES, 0, _arrows3.getNbVertex());
_modelview = tmp2;
}
it_link++;
}
_arrows3.unlock();
}
_arrows3.unlock();
break;
case 1: //points
//_arrows2.lock();
//glDrawArrays(GL_POINTS, 0, _arrows2.getNbVertex());
//_arrows2.unlock();
break;
default: //no head
break;
}
_modelview = tmp;
_modelview = tmp;
}
/*drawing events*/
......@@ -841,6 +843,9 @@ void Render_alternate::start_draw_arrows(){
std::pair<Vbo*, Vbo*> p2(v1, v2);
std::pair<EntityValue*, std::pair<Vbo*, Vbo*> > p3(value, p2);
_arrows.insert(p3);
std::vector<Element_pos> v;
std::pair<EntityValue*, std::vector<Element_pos> > p4(value, v);
_links.insert(p4);
}
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
......@@ -861,10 +866,14 @@ void Render_alternate::start_draw_arrows(){
_current->add(x1, y1);
_current = _arrows[value].second;
_current->add(x1, y1);
_links.push_back(alpha);
_links.push_back(l);
_links.push_back(x1);
_links.push_back(y1);
std::vector<Element_pos> *v = &_links[value];
v->push_back(x1);
v->push_back(y1);
v->push_back(alpha);
//_links.push_back(alpha);
//_links.push_back(l);
//_links.push_back(x1);
//_links.push_back(y1);
}
void Render_alternate::end_draw_arrows(){
......
......@@ -106,7 +106,7 @@ private:
Element_col _r;
Element_col _g;
Element_col _b;
std::vector<Element_pos> _links;
//std::vector<Element_pos> _links;
//std::vector<Element_pos> _events;
std::vector<Container_text_> _texts;
std::map<long int, Variable_text_> _variable_texts;
......@@ -132,6 +132,7 @@ private:
//first element of the pair contains the line of the arrow, second contains the position of the head
std::map<EntityValue*, std::pair<Vbo*, Vbo*> > _arrows;
std::map<EntityValue*, Shader*> _arrows_shaders;
std::map<EntityValue*, std::vector<Element_pos> > _links;
/*!
* \brief Offset of the vertical helper line
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment