minor changes

This commit is contained in:
Nico Pietroni 2004-08-26 13:18:32 +00:00
parent a7d6742fda
commit a81551f3a1
1 changed files with 45 additions and 36 deletions

View File

@ -47,14 +47,15 @@ public:
template <DrawMode dm,NormalMode nm,ColorMode cm > template <DrawMode dm,NormalMode nm,ColorMode cm >
void Draw(){ void Draw(){
switch (dm){ switch (dm){
case DMNone: break; case DMNone: break;
case DMSmallTetra: _DrawSmallTetra<cm>();break; case DMSmallTetra:_DrawSmallTetra<cm>();break;
case DMFlat:_DrawSurface<dm,nm,cm>();break; case DMFlat:_DrawSurface<dm,nm,cm>();break;
case DMWire:_DrawSurface<dm,nm,cm>();break; case DMWire:_DrawSurface<dm,nm,cm>();break;
case DMHidden:_DrawSurface<dm,nm,cm>();break; case DMHidden:_DrawSurface<dm,nm,cm>();break;
case DMFlatWire:_DrawFlatWire<nm,cm>(); break; case DMFlatWire:_DrawFlatWire<nm,cm>(); break;
case DMTransparent:break; case DMTransparent:break;
} }
} }
@ -64,22 +65,25 @@ template <ColorMode cm >
void _DrawSmallTetra(){ void _DrawSmallTetra(){
Point3x p[4],br; Point3x p[4],br;
CONT_TETRA::iterator it; CONT_TETRA::iterator it;
glPushAttrib(0xffffffff); glPushAttrib(0xffffffff);
glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE); glEnable(GL_LIGHT0);
glPolygonMode(GL_FRONT,GL_FILL); glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
glPolygonMode(GL_FRONT,GL_FILL);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
for( it = tetra.begin(); it != tetra.end(); ++it) for( it = tetra.begin(); it != tetra.end(); ++it)
if(!(*it).IsD()){ if(!(*it).IsD()){
_DrawSmallTetra<cm>(*it); _DrawSmallTetra<cm>(*it);
} }
glEnd(); glEnd();
glPopAttrib(); glPopAttrib();
} }
template <NormalMode nm,ColorMode cm > template <NormalMode nm,ColorMode cm >
void _DrawFlatWire(){ void _DrawFlatWire(){
glPushAttrib(0xffff); glPushAttrib(0xffff);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH); glEnable(GL_DEPTH);
glDepthRange(0.001,1.0); glDepthRange(0.001,1.0);
Draw<DMFlat,nm,cm>(); Draw<DMFlat,nm,cm>();
@ -95,24 +99,23 @@ template <DrawMode dm,NormalMode nm,ColorMode cm >
void _DrawSurface(){ void _DrawSurface(){
CONT_TETRA::iterator it; CONT_TETRA::iterator it;
glPushAttrib(0xffffffff); glPushAttrib(0xffff);
glEnable(GL_COLOR_MATERIAL);
if((dm == DMWire)||(dm ==DMHidden)) if((dm == DMWire)||(dm ==DMHidden))
{ {
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_NORMALIZE); glDisable(GL_NORMALIZE);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
} }
else else
{ {
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE); glEnable(GL_NORMALIZE);
glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_FRONT,GL_FILL);
} }
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
for( it = tetra.begin(); it != tetra.end(); ++it) for( it = tetra.begin(); it != tetra.end(); ++it)
_DrawTetra<dm,nm,cm>((*it)); _DrawTetra<dm,nm,cm>((*it));
glEnd(); glEnd();
glPopAttrib(); glPopAttrib();
} }
@ -121,7 +124,7 @@ template <DrawMode dm,NormalMode nm,ColorMode cm >
void _DrawTetra(TetraType &t) void _DrawTetra(TetraType &t)
{ {
if(!(t.IsD())) if(!(t.IsD()))
{ {
if ((dm!=DMWire)&&(dm!=DMHidden)) if ((dm!=DMWire)&&(dm!=DMHidden))
_ChooseColorTetra<cm>(t); _ChooseColorTetra<cm>(t);
for(int i = 0; i < 4; ++i){ for(int i = 0; i < 4; ++i){
@ -130,12 +133,13 @@ void _DrawTetra(TetraType &t)
else else
{ {
if (t.IsBorderF(i)) if (t.IsBorderF(i))
//if (t.IsS())
{ {
if(nm==NMSmooth) if(nm==NMSmooth)
_DrawFaceSmooth<cm>(t,i); _DrawFaceSmooth<cm>(t,i);
else else
if(nm==NMFlat) if(nm==NMFlat)
_DrawFace<cm>(t,i); _DrawFace<cm>(t,i);
} }
} }
} }
@ -146,7 +150,12 @@ template <ColorMode cm >
void _ChooseColorTetra(TetraType &t) void _ChooseColorTetra(TetraType &t)
{ {
if (cm==CMNone) if (cm==CMNone)
glColor3d(0.8,0.8,0.8); {
if (t.IsS())
glColor3d(1,0,0);
else
glColor3d(0.8f,0.8f,0.8f);
}
else else
if(cm == CMPerTetraF) if(cm == CMPerTetraF)
{ {
@ -154,7 +163,7 @@ void _ChooseColorTetra(TetraType &t)
c = color_tetra(t); c = color_tetra(t);
GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3]; GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3];
glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic); glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic);
} }
} }
template <ColorMode cm > template <ColorMode cm >
@ -168,7 +177,7 @@ void _ChooseColorVertex(VertexType &v)
c = color_vertex(v); c = color_vertex(v);
GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3]; GLint ic[4]; ic[0] = c[0];ic[1] = c[1];ic[2] = c[2];ic[3] = c[3];
glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic); glMaterialiv(GL_FRONT,GL_DIFFUSE ,ic);
} }
else else
if(cm == CMPerVertex) if(cm == CMPerVertex)
glColor3f(v.C()[0],v.C()[1],v.C()[2]); glColor3f(v.C()[0],v.C()[1],v.C()[2]);
@ -188,7 +197,7 @@ void _DrawFaceSmooth(TetraType &t,int face)
_ChooseColorVertex<cm>(*v1); _ChooseColorVertex<cm>(*v1);
glNormal(v1->N()); glNormal(v1->N());
glVertex(v1->P()); glVertex(v1->P());
_ChooseColorVertex<cm>(*v2); _ChooseColorVertex<cm>(*v2);
glNormal(v2->N()); glNormal(v2->N());
glVertex(v2->P()); glVertex(v2->P());
} }
@ -218,22 +227,22 @@ void _DrawSmallTetra(TetraType &t)
T.P3(0)=t.V(3)->cP(); T.P3(0)=t.V(3)->cP();
Point3x p[4], br; Point3x p[4], br;
br=T.ComputeBarycenter(); br=T.ComputeBarycenter();
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
p[i] = t.V(i)->P()* shrink_factor + br *(1- shrink_factor); p[i] = t.V(i)->P()* shrink_factor + br *(1- shrink_factor);
_ChooseColorTetra<cm>(t); _ChooseColorTetra<cm>(t);
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
{ {
glNormal(t.N(i)); glNormal(t.N(i));
VertexType *v0=t.V(Tetra::VofF(i,0)); VertexType *v0=t.V(Tetra::VofF(i,0));
VertexType *v1=t.V(Tetra::VofF(i,1)); VertexType *v1=t.V(Tetra::VofF(i,1));
VertexType *v2=t.V(Tetra::VofF(i,2)); VertexType *v2=t.V(Tetra::VofF(i,2));
_ChooseColorVertex<cm>(*v0); _ChooseColorVertex<cm>(*v0);
glVertex(p[Tetra::VofF(i,0)]); glVertex(p[Tetra::VofF(i,0)]);
_ChooseColorVertex<cm>(*v1); _ChooseColorVertex<cm>(*v1);
glVertex(p[Tetra::VofF(i,1)]); glVertex(p[Tetra::VofF(i,1)]);
_ChooseColorVertex<cm>(*v2); _ChooseColorVertex<cm>(*v2);
glVertex(p[Tetra::VofF(i,2)]); glVertex(p[Tetra::VofF(i,2)]);
} }
} }