void DecorateBackgroundPlugin::decorateDoc(QAction *a, MeshDocument &m, RichParameterSet * parset,GLArea *gla, QPainter *, GLLogStream &) { static QString lastname("unitialized"); switch(ID(a)) { case DP_SHOW_CUBEMAPPED_ENV : { if(!cm.IsValid() || (lastname != cubemapFileName ) ) { qDebug( "Current CubeMapPath Dir: %s ",qPrintable(cubemapFileName)); glewInit(); bool ret = cm.Load(qPrintable(cubemapFileName)); lastname=cubemapFileName; if(! ret ) return; //QMessageBox::warning(gla,"Cubemapped background decoration","Warning unable to load cube map images: " + cubemapFileName ); cm.radius=10; } if(!cm.IsValid()) return; Matrix44f tr; glGetv(GL_MODELVIEW_MATRIX,tr); // Remove the translation from the current matrix by simply padding the last column of the matrix tr.SetColumn(3,Point4f(0,0,0,1.0)); //Remove the scaling from the the current matrix by adding an inverse scaling matrix float scale = 1.0/pow(tr.Determinant(),1.0f/3.0f); Matrix44f Scale; Scale.SetDiagonal(scale); tr=tr*Scale; glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); cm.DrawEnvCube(tr); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } break; case DP_SHOW_GRID : { emit this->askViewerShot("me"); Box3f bb=m.bbox(); float scaleBB = parset->getFloat(BoxRatioParam()); float majorTick = parset->getFloat(GridMajorParam()); float minorTick = parset->getFloat(GridMinorParam()); bool gridSnap = parset->getBool(GridSnapParam()); bool backFlag = parset->getBool(GridBackParam()); bool shadowFlag = parset->getBool(ShowShadowParam()); Color4b backColor = parset->getColor4b(GridColorBackParam()); Color4b frontColor = parset->getColor4b(GridColorFrontParam()); bb.Offset((bb.max-bb.min)*(scaleBB-1.0)); DrawGriddedCube(*m.mm(),bb,majorTick,minorTick,gridSnap,backFlag,shadowFlag,backColor,frontColor,gla); } break; } }
void ShadowMapping::renderingFromLightSetup(MeshDocument& md, GLArea* gla){ Box3m bb = md.bbox(); Point3m center = bb.Center(); Scalarm diag = bb.Diag(); GLfloat lP[4]; glGetLightfv(GL_LIGHT0, GL_POSITION, lP); vcg::Point3f light = -vcg::Point3f(lP[0],lP[1],lP[2]); vcg::Matrix44f tm = gla->trackball.Matrix(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(-(diag/2), diag/2, -(diag/2), diag/2, -(diag/2), diag/2); glMatrixMode(GL_MODELVIEW); glPushMatrix(); vcg::Point3f u, v; //mi seleziona automaticamente un upvector che mi eviti casi degeneri...nel caso vada bene 010 sceglie quello vcg::GetUV(light, u, v, vcg::Point3f(0,-1,0)); glLoadIdentity(); gluLookAt(0, 0, 0, light[0], light[1], light[2], v[0], v[1], v[2]); //get the rotation matrix from the trackball vcg::Matrix44f rotation; vcg::Similarityf track = gla->trackball.track; track.rot.ToMatrix(rotation); glMultMatrixf(rotation.transpose().V()); //traslate the model in the center glTranslatef(-center[0],-center[1],-center[2]); }