Commit 1c8ed651 authored by Thibault Soucarre's avatar Thibault Soucarre

change way to render arrows

parent 669a5001
......@@ -234,10 +234,13 @@ void Render_alternate::paintGL(){
//necessary for each link
_modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , _z_arrow));
_modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1.0));
//_modelview = tmp2;
//mvp = _projection * _modelview;
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//save current modelview
tmp2 = _modelview;
_arrows.lock();
for(int i=0; i<n ; i++){
for(int i=0; i<n ; i++) {
//change matrix to draw the current arrow
_modelview = glm::translate(_modelview, glm::vec3(_links[4*i+2], _links[4*i+3], 0));
_modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
......@@ -247,15 +250,44 @@ void Render_alternate::paintGL(){
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
glDrawArrays(GL_LINES, 0,6);
//_arrows.unlock();
//restore matrix with changes needed for all links
glDrawArrays(GL_LINES, 0, 2);
_modelview = tmp2;
}
_arrows.unlock();
//restore basic matrix
_modelview = tmp;
}
_arrows2.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, 3);
_modelview = tmp2;
}
_arrows2.unlock();
//_arrows.unlock();
//restore matrix with changes needed for all links
//}
//_arrows.unlock();
//_modelview = tmp2;
//_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*(_default_entity_x_translate - _x_state_translate), _y_state_scale*(_ruler_y + _ruler_height - _y_state_translate), _z_arrow));
//mvp = _projection * _modelview;
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
/*_modelview = tmp2;
for (int i=0; i<n;i++){
_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*_links[3*i+1], _y_state_scale*_links[3*i+2], 0));
_modelview = glm::rotate(_modelview, (float) _links[3*i], glm::vec3(0,0,1));
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
_arrows2.lock();
glDrawArrays(GL_TRIANGLES, 0, _arrows2.getNbVertex());
_arrows2.unlock();
//restore basic matrix
_modelview = tmp2;*/
}
//}
/*drawing events*/
if(false == Info::Render::_no_events){
n = _events.size()/3;
......@@ -268,7 +300,6 @@ void Render_alternate::paintGL(){
//change matrix to draw the current event
_modelview = glm::translate(_modelview, glm::vec3(_events[3*i], _events[3*i+1], _z_event));
_modelview = glm::scale(_modelview, glm::vec3(1/_x_state_scale, Info::Screen::width/(_y_state_scale*Info::Screen::height), 1.0));
//_circles.lock();
mvp = _projection * _modelview;
glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
//glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
......@@ -786,7 +817,7 @@ void Render_alternate::draw_arrow(const Element_pos start_time, const Element_po
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
Element_pos x0, x1, y0, y1, l, alpha, cos, sin;
Element_pos x0, x1, y0, y1, l, alpha, cosa, sina;
x0 = start_time + offset_x;
x1 = end_time + offset_x;
y0 = start_height + offset_y;
......@@ -794,27 +825,52 @@ void Render_alternate::draw_arrow(const Element_pos start_time, const Element_po
//size of the arrow
l = sqrt(pow(x1-x0,2)+pow(y1-y0,2));
//calculate angle beetween arrow and horizontal axe
cos = (x1-x0)/l;
sin = (y1-y0)/l;
alpha = acos(cos);
if(sin<0) alpha*= -1;
cosa = (x1-x0)/l;
sina = (y1-y0)/l;
alpha = acos(cosa);
if(sina<0) alpha*= -1;
/*glm::mat4 m(1.0);
m = glm::translate(m, glm::vec3(x0, y0, 0));
m = glm::rotate(m, alpha, glm::vec3(0,0,1));
m = glm::scale(m, glm::vec3(l, l, 1));
glm::vec4 v1(0,0,0,1); //origin
glm::vec4 v2(1,0,0,1);
glm::vec4 v3(cos(PI/8), -sin(PI/8)/10, 0, 1);
glm::vec4 v4(cos(PI/8), sin(PI/8)/10, 0, 1);
v1 = m * v1;
v2 = m * v2;
v3 = m * v3;
v4 = m * v4;
_arrows.add(v2.x, v2.y, 1, 1, 1);
_arrows.add(v1.x, v1.y, 1, 1, 1);
//_arrows.add(v2.x, v2.y, 1, 1, 1);
_arrows2.add(v3.x, v3.y, 1, 1, 1);
_arrows2.add(v2.x, v2.y, 1, 1, 1);
_arrows2.add(v4.x, v4.y, 1, 1, 1);
_arrows.add(x0, y0, 0, 1, 1);
_arrows.add(x1, y1, 0, 1, 1);*/
_links.push_back(alpha);
_links.push_back(l);
_links.push_back(x0);
_links.push_back(y0);
_links.push_back(x1);
_links.push_back(y1);
//_arrows.add(x0, y0, 1, 1, 1);
//_arrows.add(x1, y1, 1, 1, 1);
}
void Render_alternate::end_draw_arrows(){
//coordinates that we use for all arrows, we will change the angle and scale of using the modelview matrix
_arrows.add(1,0,1,1,1);
_arrows2.add(0,0,1,1,1);
_arrows2.add(-1.2, -0.4, 1, 1, 1);
_arrows2.add(-1.2, 0.4, 1, 1, 1);
_arrows.add(0,0,1,1,1);
_arrows.add(1,0,1,1,1);
_arrows.add(-1,0,1,1,1);
//_arrows.add(0,0,1,1,1);
_arrows.add(cos(PI/8), -sin(PI/8), 1, 1, 1);
_arrows.add(1,0,1,1,1);
//_arrows.add(cos(PI/8), -sin(PI/8), 1, 1, 1);
//_arrows.add(1,0,1,1,1);
//_arrows.add(0,0,1,1,1);
_arrows.add(cos(PI/8), sin(PI/8), 1, 1, 1);
//_arrows.add(cos(PI/8), sin(PI/8), 1, 1, 1);
_arrows.config();
_arrows2.config();
_draw_arrow = false;
cout << "end_draw_arrows " << _links.size() << endl;
}
......
......@@ -105,6 +105,7 @@ private:
//Vbo _states;
Vbo _circles;
Vbo _arrows;
Vbo _arrows2;
Vbo _counters;
Vbo _ruler;
Vbo *_current;
......
......@@ -109,8 +109,6 @@ int Vbo::add(Element_pos x, Element_pos y, char b){
_vertex.push_back(x);
_vertex.push_back(y);
_shaded.push_back(b);
//_vertex.push_back(3);
//_vertex.push_back(3);
_nbVertex++;
}
......
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