Skip to content
Snippets Groups Projects
Commit a483fb6d authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

Fixed 3D cylinder/arrow drawing code when dir vector is // to z-axis
parent 006bb363
No related branches found
No related tags found
No related merge requests found
// $Id: Entity.cpp,v 1.33 2004-04-13 18:47:32 geuzaine Exp $ // $Id: Entity.cpp,v 1.34 2004-04-13 19:27:09 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -56,7 +56,7 @@ void Draw_Sphere(double size, double x, double y, double z, int light) ...@@ -56,7 +56,7 @@ void Draw_Sphere(double size, double x, double y, double z, int light)
glEndList(); glEndList();
} }
glPushMatrix(); glPushMatrix();
glTranslatef(x, y, z); glTranslated(x, y, z);
glScalef(s, s, s); glScalef(s, s, s);
glCallList(listnum); glCallList(listnum);
glPopMatrix(); glPopMatrix();
...@@ -86,11 +86,16 @@ void Draw_Cylinder(double width, double *x, double *y, double *z, int light) ...@@ -86,11 +86,16 @@ void Draw_Cylinder(double width, double *x, double *y, double *z, int light)
double vdir[3] = {dx/length, dy/length, dz/length}; double vdir[3] = {dx/length, dy/length, dz/length};
double axis[3], cosphi, phi; double axis[3], cosphi, phi;
prodve(zdir, vdir, axis); prodve(zdir, vdir, axis);
norme(axis);
prosca(zdir, vdir, &cosphi); prosca(zdir, vdir, &cosphi);
if(!norme(axis)){
axis[0] = 0.;
axis[1] = 1.;
axis[2] = 0.;
}
phi = 180. * myacos(cosphi) / M_PI; phi = 180. * myacos(cosphi) / M_PI;
glTranslatef(x[0], y[0], z[0]);
glRotatef(phi, axis[0], axis[1], axis[2]); glTranslated(x[0], y[0], z[0]);
glRotated(phi, axis[0], axis[1], axis[2]);
gluCylinder(qua, radius, radius, length, CTX.quadric_subdivisions, 1); gluCylinder(qua, radius, radius, length, CTX.quadric_subdivisions, 1);
glPopMatrix(); glPopMatrix();
...@@ -349,18 +354,22 @@ void Draw_3DArrow(double relHeadRadius, double relStemLength, double relStemRadi ...@@ -349,18 +354,22 @@ void Draw_3DArrow(double relHeadRadius, double relStemLength, double relStemRadi
double vdir[3] = {dx/length, dy/length, dz/length}; double vdir[3] = {dx/length, dy/length, dz/length};
double axis[3], cosphi, phi; double axis[3], cosphi, phi;
prodve(zdir, vdir, axis); prodve(zdir, vdir, axis);
norme(axis);
prosca(zdir, vdir, &cosphi); prosca(zdir, vdir, &cosphi);
if(!norme(axis)){
axis[0] = 0.;
axis[1] = 1.;
axis[2] = 0.;
}
phi = 180. * myacos(cosphi) / M_PI; phi = 180. * myacos(cosphi) / M_PI;
glTranslatef(x, y, z); glTranslated(x, y, z);
glRotatef(phi, axis[0], axis[1], axis[2]); glRotated(phi, axis[0], axis[1], axis[2]);
if(head_l && head_r){ if(head_l && head_r){
glTranslatef(0., 0., stem_l); glTranslated(0., 0., stem_l);
gluCylinder(qua, head_r, 0., head_l, subdiv, 1); gluCylinder(qua, head_r, 0., head_l, subdiv, 1);
gluDisk(qua, stem_r, head_r, subdiv, 1); gluDisk(qua, stem_r, head_r, subdiv, 1);
glTranslatef(0., 0., -stem_l); glTranslated(0., 0., -stem_l);
} }
if(stem_l && stem_r){ if(stem_l && stem_r){
......
// $Id: Numeric.cpp,v 1.12 2004-04-13 18:47:32 geuzaine Exp $ // $Id: Numeric.cpp,v 1.13 2004-04-13 19:27:09 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -106,16 +106,16 @@ void prosca(double a[3], double b[3], double *c) ...@@ -106,16 +106,16 @@ void prosca(double a[3], double b[3], double *c)
*c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; *c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
} }
void norme(double a[3]) double norme(double a[3])
{ {
double mod; double mod = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
mod = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); if(mod != 0.0){
if(mod == 0.0)
return;
a[0] /= mod; a[0] /= mod;
a[1] /= mod; a[1] /= mod;
a[2] /= mod; a[2] /= mod;
} }
return mod;
}
int sys2x2(double mat[2][2], double b[2], double res[2]) int sys2x2(double mat[2][2], double b[2], double res[2])
{ {
......
...@@ -61,7 +61,7 @@ double myasin(double a); ...@@ -61,7 +61,7 @@ double myasin(double a);
double myacos(double a); double myacos(double a);
void prodve(double a[3], double b[3], double c[3]); void prodve(double a[3], double b[3], double c[3]);
void prosca(double a[3], double b[3], double *c); void prosca(double a[3], double b[3], double *c);
void norme(double a[3]); double norme(double a[3]);
int sys2x2(double mat[2][2], double b[2], double res[2]); int sys2x2(double mat[2][2], double b[2], double res[2]);
int sys3x3(double mat[3][3], double b[3], double res[3], double *det); int sys3x3(double mat[3][3], double b[3], double res[3], double *det);
int sys3x3_with_tol(double mat[3][3], double b[3], double res[3], double *det); int sys3x3_with_tol(double mat[3][3], double b[3], double res[3], double *det);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment