-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[all] Use drawtool everywhere #704
Changes from all commits
4aacbfb
12de07b
c014d3e
a6d6fe4
4b0a72e
998a44e
153e41a
a938a92
7ce2120
294becc
91e54a7
84607bb
d425fa1
8e2ae17
7e7f55b
09abc82
fcf55ab
b030405
5b7966c
ae0c2a6
7067e4b
d2fd7d9
c6b2fef
2686575
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,13 @@ void DrawToolGL::drawTriangles(const std::vector<Vector3> &points, const Vec<4,f | |
resetMaterial(colour); | ||
} | ||
|
||
void DrawToolGL::drawTriangles(const std::vector<Vector3> &points, const std::vector< Vec4f > &colour) | ||
{ | ||
std::vector<Vector3> normal; | ||
normal.clear(); | ||
this->drawTriangles(points,normal,colour); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
void DrawToolGL::drawTriangles(const std::vector<Vector3> &points, const Vector3& normal, const Vec<4,float>& colour) | ||
|
@@ -859,6 +866,35 @@ void DrawToolGL::drawQuads(const std::vector<Vector3> &points, const Vec4f& colo | |
resetMaterial(colour); | ||
} | ||
|
||
void DrawToolGL::drawQuads(const std::vector<Vector3> &points, const std::vector<Vec4f>& colours) | ||
{ | ||
glBegin(GL_QUADS); | ||
{ | ||
for (unsigned int i=0; i<points.size()/4; ++i) | ||
{ | ||
const Vector3& a = points[ 4*i+0 ]; | ||
const Vector3& b = points[ 4*i+1 ]; | ||
const Vector3& c = points[ 4*i+2 ]; | ||
const Vector3& d = points[ 4*i+3 ]; | ||
|
||
const Vec4f& col_a = colours[ 4*i+0 ]; | ||
const Vec4f& col_b = colours[ 4*i+1 ]; | ||
const Vec4f& col_c = colours[ 4*i+2 ]; | ||
const Vec4f& col_d = colours[ 4*i+3 ]; | ||
|
||
Vec4f average_colour; | ||
for(int i=0; i<4; i++) | ||
{ | ||
average_colour[i] = (col_a[i]+col_b[i]+col_c[i]+col_d[i])*0.25; | ||
} | ||
|
||
Vector3 n = cross((b-a),(c-a)); | ||
n.normalize(); | ||
internalDrawQuad(a,b,c,d,n,average_colour); | ||
} | ||
} glEnd(); | ||
} | ||
|
||
void DrawToolGL::drawTetrahedron(const Vector3 &p0, const Vector3 &p1, const Vector3 &p2, const Vector3 &p3, const Vec4f &colour) | ||
{ | ||
setMaterial(colour); | ||
|
@@ -1027,8 +1063,9 @@ void DrawToolGL::drawEllipsoid(const Vector3 &p, const Vector3 &radii) | |
|
||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
void DrawToolGL::drawBoundingBox( const Vector3 &min, const Vector3 &max ) | ||
void DrawToolGL::drawBoundingBox( const Vector3 &min, const Vector3 &max, float size) | ||
{ | ||
glLineWidth(size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will break code that have set the drawLine before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually no since @fredroy set a default value for "size" to one, for functions calling it without specifying the value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The normal convention is to save the attributes before changing them and restoring them to their old value when you are done. In your case you restore it to 1.0 regardless of its initial value this means that calling the function has a side effect on all future opengl drawing operation. It is way better to have side effect free functions so that the one that call them does not have to care about what the function is doing. |
||
glBegin( GL_LINES ); | ||
|
||
// 0-1 | ||
|
@@ -1069,6 +1106,7 @@ void DrawToolGL::drawBoundingBox( const Vector3 &min, const Vector3 &max ) | |
glVertex3f( (float)min[0], (float)max[1], (float)max[2] ); | ||
|
||
glEnd(); | ||
glLineWidth(1.0); | ||
} | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
@@ -1267,7 +1305,7 @@ void DrawToolGL::draw3DText(const Vector3 &p, float scale, const Vec4f &color, c | |
sofa::helper::gl::GlText::draw(text, p, (double)scale); | ||
} | ||
|
||
void DrawToolGL::draw3DText_Indices(const helper::vector<Vector3> &positions, float scale, const Vec4f &color) | ||
void DrawToolGL::draw3DText_Indices(const std::vector<Vector3> &positions, float scale, const Vec4f &color) | ||
{ | ||
glColor4f(color[0], color[1], color[2], color[3]); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2401,7 +2401,7 @@ void TriangleSetGeometryAlgorithms<DataTypes>::draw(const core::visual::VisualPa | |
|
||
const sofa::helper::vector<Triangle> &triangleArray = this->m_topology->getTriangles(); | ||
|
||
helper::vector<defaulttype::Vector3> positions; | ||
std::vector<defaulttype::Vector3> positions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we use helper::vector as much as possible ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could but @fredroy told me that he wanted to make it as independent from SOFA as possible (in this optic, we should also remove the defaulttype calls). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fear so much inconsistancies :) |
||
for (unsigned int i =0; i<triangleArray.size(); i++) | ||
{ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,7 @@ class SOFA_MISC_COLLISION_API TetrahedronModel : public core::CollisionModel | |
protected: | ||
|
||
TetrahedronModel(); | ||
void addTetraToDraw(const Tetrahedron& t, std::vector<sofa::defaulttype::Vector3>& tetraVertices, std::vector<sofa::defaulttype::Vector3>& normalVertices); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't the other parameters const ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, by looking into this function, its purpose is actually to build a vector and set new values in it |
||
public: | ||
virtual void init() override; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that if the normal is empty it does nothing ?
Maybe add some comment to explain the logic the declaration of drawTriangles()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, actually if you look closer, this function creates a vector of normals and then calls another function (l. 277) that computes normals if the vector has a null size