yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #02943
[Branch ~yade-dev/yade/trunk] Rev 1939: Implement https://blueprints.launchpad.net/yade/+spec/sphere-gl-stripes (weird lighting things). ...
------------------------------------------------------------
revno: 1939
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-01-05 21:02:43 +0100
message:
Implement https://blueprints.launchpad.net/yade/+spec/sphere-gl-stripes (weird lighting things). Must be enabled via "Gl1_Sphere(stripes=True)" in python.
modified:
pkg/common/RenderingEngine/GLDrawSphereModel.cpp
pkg/common/RenderingEngine/Gl1_Sphere.cpp
pkg/common/RenderingEngine/Gl1_Sphere.hpp
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'pkg/common/RenderingEngine/GLDrawSphereModel.cpp'
--- pkg/common/RenderingEngine/GLDrawSphereModel.cpp 2009-12-11 14:51:17 +0000
+++ pkg/common/RenderingEngine/GLDrawSphereModel.cpp 2010-01-05 20:02:43 +0000
@@ -22,9 +22,9 @@
// glPopMatrix();
//}
+int GLDrawSphereModel::glWiredSphereList=-1;
+
int GLDrawSphereModel::glSphereList=-1;
-int GLDrawSphereModel::glWiredSphereList=-1;
-
vector<Vector3r> GLDrawSphereModel::vertices;
vector<Vector3r> GLDrawSphereModel::faces;
bool GLDrawSphereModel::first = true;
@@ -108,9 +108,6 @@
glMaterialv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Vector3f(gm->diffuseColor[0],gm->diffuseColor[1],gm->diffuseColor[2]));
glColor3v(gm->diffuseColor);
-// transparent spheres
-//glColor4(gm->diffuseColor[0],gm->diffuseColor[1],gm->diffuseColor[2],0.4);
-
if (gm->wire || wire)
{// circle facing the camera
glPushMatrix();
@@ -118,15 +115,6 @@
glScalef(radius,radius,radius);
glCallList(glWiredSphereList);
glPopMatrix();
-
-/////////////////////////// FIXME - display coordinates (stupid place!!)
-// glPushMatrix();
-// glRasterPos2i(0,0);
-// std::string str=std::string(" (") + boost::lexical_cast<std::string>((float)(ph->se3.position[0])) + "," + boost::lexical_cast<std::string>((float)(ph->se3.position[1])) + ")";
-// for(unsigned int i=0;i<str.length();i++)
-// glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, str[i]);
-// glPopMatrix();
-///////////////////////////
}
else
{
@@ -136,74 +124,6 @@
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-void GLDrawSphereModel::subdivideTriangle(Vector3r& v1,Vector3r& v2,Vector3r& v3, int depth)
-{
- Vector3r v12,v23,v31;
-
- if (depth==0)
- {
- Vector3r v = (v1+v2+v3)/3.0;
- Real angle = atan(v[2]/v[0])/v.Length();
-
- ////////////////////////////
- //
- // FIXME - another parameter to GLDraw* to allow to disable that stripe on the sphere
- //
- // BEGIN mark
- GLfloat matAmbient[4];
-
- if (angle>-Mathr::PI/6.0 && angle<=Mathr::PI/6.0)
- {
- matAmbient[0] = 0.2;
- matAmbient[1] = 0.2;
- matAmbient[2] = 0.2;
- matAmbient[3] = 0.0;
- }
- else
- {
- matAmbient[0] = 0.0;
- matAmbient[1] = 0.0;
- matAmbient[2] = 0.0;
- matAmbient[3] = 0.0;
- }
-
- glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,matAmbient);
- // END mark
- ////////////////////////////
-
-
- glBegin(GL_TRIANGLES);
- glNormal3v(v3);
- glVertex3v(v3);
- glNormal3v(v2);
- glVertex3v(v2);
- glNormal3v(v1);
- glVertex3v(v1);
- glEnd();
-
- return;
- }
- v12 = v1+v2;
- v23 = v2+v3;
- v31 = v3+v1;
- v12.Normalize();
- v23.Normalize();
- v31.Normalize();
- subdivideTriangle(v1,v12,v31,depth-1);
- subdivideTriangle(v2,v23,v12,depth-1);
- subdivideTriangle(v3,v31,v23,depth-1);
- subdivideTriangle(v12,v23,v31,depth-1);
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-void GLDrawSphereModel::drawSphere(int depth)
-{
- glShadeModel(GL_SMOOTH);
-
- for(int i=0;i<20;i++)
- subdivideTriangle(vertices[(unsigned int)faces[i][0]],vertices[(unsigned int)faces[i][1]],vertices[(unsigned int)faces[i][2]],depth);
-}
void GLDrawSphereModel::drawCircle(bool filled)
{
=== modified file 'pkg/common/RenderingEngine/Gl1_Sphere.cpp'
--- pkg/common/RenderingEngine/Gl1_Sphere.cpp 2009-12-13 20:30:13 +0000
+++ pkg/common/RenderingEngine/Gl1_Sphere.cpp 2010-01-05 20:02:43 +0000
@@ -11,20 +11,130 @@
#include<yade/lib-opengl/OpenGLWrapper.hpp>
bool Gl1_Sphere::wire=false;
+bool Gl1_Sphere::stripes=false;
bool Gl1_Sphere::glutNormalize=true;
int Gl1_Sphere::glutSlices=12;
int Gl1_Sphere::glutStacks=6;
+vector<Vector3r> Gl1_Sphere::vertices, Gl1_Sphere::faces;
+int Gl1_Sphere::glSphereList=-1;
+
void Gl1_Sphere::go(const shared_ptr<Shape>& cm, const shared_ptr<State>& ,bool wire2, const GLViewInfo&)
{
Real r=(static_cast<Sphere*>(cm.get()))->radius;
glMaterialv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, Vector3f(cm->diffuseColor[0],cm->diffuseColor[1],cm->diffuseColor[2]));
glColor3v(cm->diffuseColor);
if(glutNormalize) glPushAttrib(GL_NORMALIZE); // as per http://lists.apple.com/archives/Mac-opengl/2002/Jul/msg00085.html
- if (wire || wire2) glutWireSphere(r,glutSlices,glutStacks);
- else glutSolidSphere(r,glutSlices,glutStacks);
+ if (wire || wire2) glutWireSphere(r,glutSlices,glutStacks);
+ else {
+ if(stripes) { glScalef(r,r,r); drawSphere();}
+ else glutSolidSphere(r,glutSlices,glutStacks);
+ }
if(glutNormalize) glPopAttrib();
return;
}
YADE_PLUGIN((Gl1_Sphere));
YADE_REQUIRE_FEATURE(OPENGL)
+
+
+/***************************** WARNING *********************
+***** The following code was written by Olivier Galizzi ****
+************ and hasn't been properly reviewed *************/
+
+// https://blueprints.launchpad.net/yade/+spec/sphere-gl-stripes
+
+void Gl1_Sphere::drawSphere(){
+ int depth=1; // used to be function argument, but called only from 1 place, always with 1
+ if(vertices.size()==0) initGlLists();
+ glShadeModel(GL_SMOOTH);
+ //glScalef(radius,radius,radius);
+ glCallList(glSphereList);
+ // render the sphere now
+ for(int i=0;i<20;i++)
+ subdivideTriangle(vertices[(unsigned int)faces[i][0]],vertices[(unsigned int)faces[i][1]],vertices[(unsigned int)faces[i][2]],depth);
+
+}
+
+void Gl1_Sphere::subdivideTriangle(Vector3r& v1,Vector3r& v2,Vector3r& v3, int depth){
+ Vector3r v12,v23,v31;
+ if (depth==0){
+ Vector3r v = (v1+v2+v3)/3.0;
+ Real angle = atan(v[2]/v[0])/v.Length();
+ GLfloat matAmbient[4];
+ if (angle>-Mathr::PI/6.0 && angle<=Mathr::PI/6.0){
+ matAmbient[0] = 0.2;
+ matAmbient[1] = 0.2;
+ matAmbient[2] = 0.2;
+ matAmbient[3] = 0.0;
+ }else{
+ matAmbient[0] = 0.0;
+ matAmbient[1] = 0.0;
+ matAmbient[2] = 0.0;
+ matAmbient[3] = 0.0;
+ }
+ glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,matAmbient);
+ glBegin(GL_TRIANGLES);
+ glNormal3v(v3);
+ glVertex3v(v3);
+ glNormal3v(v2);
+ glVertex3v(v2);
+ glNormal3v(v1);
+ glVertex3v(v1);
+ glEnd();
+ return;
+ }
+ v12 = v1+v2;
+ v23 = v2+v3;
+ v31 = v3+v1;
+ v12.Normalize();
+ v23.Normalize();
+ v31.Normalize();
+ subdivideTriangle(v1,v12,v31,depth-1);
+ subdivideTriangle(v2,v23,v12,depth-1);
+ subdivideTriangle(v3,v31,v23,depth-1);
+ subdivideTriangle(v12,v23,v31,depth-1);
+}
+
+void Gl1_Sphere::initGlLists(void){
+ Real X = 0.525731112119133606;
+ Real Z = 0.850650808352039932;
+ vertices.push_back(Vector3r(-X,0,Z));
+ vertices.push_back(Vector3r(X,0,Z));
+ vertices.push_back(Vector3r(-X,0,-Z));
+ vertices.push_back(Vector3r(X,0,-Z));
+ vertices.push_back(Vector3r(0,Z,X));
+ vertices.push_back(Vector3r(0,Z,-X));
+ vertices.push_back(Vector3r(0,-Z,X));
+ vertices.push_back(Vector3r(0,-Z,-X));
+ vertices.push_back(Vector3r(Z,X,0));
+ vertices.push_back(Vector3r(-Z,X,0));
+ vertices.push_back(Vector3r(Z,-X,0));
+ vertices.push_back(Vector3r(-Z,-X,0));
+
+ faces.push_back(Vector3r(0,4,1));
+ faces.push_back(Vector3r(0,9,4));
+ faces.push_back(Vector3r(9,5,4));
+ faces.push_back(Vector3r(4,5,8));
+ faces.push_back(Vector3r(4,8,1));
+ faces.push_back(Vector3r(8,10,1));
+ faces.push_back(Vector3r(8,3,10));
+ faces.push_back(Vector3r(5,3,8));
+ faces.push_back(Vector3r(5,2,3));
+ faces.push_back(Vector3r(2,7,3));
+ faces.push_back(Vector3r(7,10,3));
+ faces.push_back(Vector3r(7,6,10));
+ faces.push_back(Vector3r(7,11,6));
+ faces.push_back(Vector3r(11,0,6));
+ faces.push_back(Vector3r(0,1,6));
+ faces.push_back(Vector3r(6,1,10));
+ faces.push_back(Vector3r(9,0,11));
+ faces.push_back(Vector3r(9,11,2));
+ faces.push_back(Vector3r(9,2,5));
+ faces.push_back(Vector3r(7,2,11));
+
+ glSphereList = glGenLists(1);
+ glNewList(glSphereList,GL_COMPILE);
+ glEnable(GL_LIGHTING);
+ drawSphere();
+ glEndList();
+}
=== modified file 'pkg/common/RenderingEngine/Gl1_Sphere.hpp'
--- pkg/common/RenderingEngine/Gl1_Sphere.hpp 2009-12-13 20:30:13 +0000
+++ pkg/common/RenderingEngine/Gl1_Sphere.hpp 2010-01-05 20:02:43 +0000
@@ -10,15 +10,21 @@
#include<yade/pkg-common/GLDrawFunctors.hpp>
-class Gl1_Sphere : public GlShapeFunctor
-{
+class Gl1_Sphere : public GlShapeFunctor{
private :
- static bool wire, glutNormalize;
+ static bool wire, stripes, glutNormalize;
static int glutSlices, glutStacks;
+
+ // for stripes
+ static vector<Vector3r> vertices, faces;
+ static int glSphereList;
+ void subdivideTriangle(Vector3r& v1,Vector3r& v2,Vector3r& v3, int depth);
+ void drawSphere(void);
+ void initGlLists(void);
public :
virtual void go(const shared_ptr<Shape>&, const shared_ptr<State>&,bool,const GLViewInfo&);
RENDERS(Sphere);
- REGISTER_ATTRIBUTES(Serializable,(wire)(glutNormalize)(glutSlices)(glutStacks));
+ REGISTER_ATTRIBUTES(Serializable,(wire)(glutNormalize)(glutSlices)(glutStacks)(stripes));
REGISTER_CLASS_AND_BASE(Gl1_Sphere,GlShapeFunctor);
};