void ViewportUtil::setView() { // passage souris en normalisé : xn=1/wv*xs-xv, yn=1/yw*ys-yv Matrix4d mproj; Matrix4d mmodelview; Matrix4d localNormalized; double viewport[4]; // viewport : [0]=x_min,[1]=y_min, [2]=width, [3]=height double mat[16]; glGetDoublev(GL_VIEWPORT, viewport); glGetDoublev(GL_PROJECTION_MATRIX,mat); mproj.set(mat); glGetDoublev(GL_MODELVIEW_MATRIX, mat); eyeLocal.set(mat); mmodelview.set(mat); normalizedLocal.mul(mproj,mmodelview); localNormalized.invert(normalizedLocal); normalizedWindow.setRow(0,2.0/viewport[2],0,0,-1-viewport[0]); normalizedWindow.setRow(1,0,-2.0/viewport[3],0,1+viewport[1]); normalizedWindow.setRow(2,0,0,1,0); normalizedWindow.setRow(3,0,0,0,1); // normalizedWindow.print("normalizedWindow"); windowNormalized.invert(normalizedWindow); // windowNormalized.print("windowNormalized"); localWindow.mul(localNormalized,normalizedWindow); // localWindow.print("localWindow="); }
Pose getDirTransform(Pose transformation) { Matrix4d dirTransformation = transformation.asMatrix(); dirTransformation.invert(); dirTransformation.transpose(); Pose dirTransform(dirTransformation); return dirTransform; }
Point3d ViewportUtil::cameraLocal() { float mat[16]; glGetFloatv(GL_MODELVIEW_MATRIX,mat); Matrix4d m; m.set(mat); m.invert(); Point3d p(0,0,0); m.transform(&p); return p; }
void VRMolecule::setLocalOrigin(int ID) { if (atoms.count(ID) == 0) return; uint now = VRGlobals::CURRENT_FRAME + rand(); Matrix4d m = atoms[ID]->getTransformation(); m.invert(); Matrix4d im; MatrixLookAt( im, Vec3d(0,0,0), Vec3d(0,0,1), Vec3d(0,1,0) ); im.mult(m); atoms[ID]->propagateTransformation(im, now); }
void frustum::computeProfile() { profile.clear(); Matrix4d m = trans.asMatrix(); m.invert(); for (auto d : directions) { Vec3d p; m.mult(d,p); profile.addPoint( Vec2d(p[0], p[1]) ); } if (!profile.isCCW()) profile.reverseOrder(); }
void VRMolecule::substitute(int a, VRMoleculePtr m, int b) { if (atoms.count(a) == 0) return; if (m->atoms.count(b) == 0) return; Matrix4d am = atoms[a]->getTransformation(); Matrix4d bm = m->atoms[b]->getTransformation(); map<int, VRBond> bondsA = atoms[a]->getBonds(); map<int, VRBond> bondsB = m->atoms[b]->getBonds(); if (bondsA.count(0) == 0) return; if (bondsB.count(0) == 0) return; VRAtom* A = bondsA[0].atom2; VRAtom* B = bondsB[0].atom2; int Ai = A->getID(); int Bi = B->getID(); remAtom(a); m->remAtom(b); if (atoms.count(Ai) == 0) { cout << "AA\n"; return; } if (m->atoms.count(Bi) == 0) { cout << "BB\n"; return; } // copy atoms for (auto at : m->atoms) { int ID = getID(); at.second->setID(ID); atoms[ID] = at.second; } m->set(m->getDefinition()); // attach molecules A->append(B, 1, true); // transform new atoms uint now = VRGlobals::CURRENT_FRAME + rand(); A->recFlag = now; bm.invert(); Matrix4d Bm = B->getTransformation(); bm.mult(Bm); bm.setTranslate(Vec3d(0,0,0)); am.mult(bm); MatrixLookAt( bm, Vec3d(0,0,0), Vec3d(0,0,1), Vec3d(0,-1,0) ); bm.mult(am); bm[3] = am[3]; B->propagateTransformation(bm, now); updateGeo(); }
void Light::drawDebug(const GLWidget* widget, const RenderManager::DebugGizmosFilter& filter) const { if(filter.draw_lights) { widget->qglColor(Qt::yellow); glBegin(GL_LINE_LOOP); for(int i=0 ; i<360 ; i+=10) { float sin = fastSin(i)/10; float cos = fastCos(i)/10; glVertex3d(0,sin,cos); } glEnd(); glBegin(GL_LINE_LOOP); for(int i=0 ; i<360 ; i+=10) { float sin = fastSin(i)/10; float cos = fastCos(i)/10; glVertex3d(sin,0,cos); } glEnd(); glBegin(GL_LINE_LOOP); for(int i=0 ; i<360 ; i+=10) { float sin = fastSin(i)/10; float cos = fastCos(i)/10; glVertex3d(sin,cos,0); } glEnd(); if(m_type == SPOT || m_type == SUN) { glPushMatrix(); if(m_type == SUN) { glLoadIdentity(); #ifndef MERGEFORSUN Viewpoint* targetVp = RENDER_MANAGER.getRenderPassInfo()->lod_viewpoint; targetVp->applyTransform(0); #endif } Matrix4d mat; if(m_type == SUN) { computePSSM(mat, 0); } else { computeLightFrustum(mat); } mat.invert(); glMultMatrixd(mat.values); glBegin(GL_LINES); glVertex3d(-1,-1,-1); glVertex3d( 1,-1,-1); glVertex3d(-1,-1,-1); glVertex3d(-1, 1,-1); glVertex3d(-1,-1,-1); glVertex3d(-1,-1, 1); glVertex3d( 1,-1,-1); glVertex3d( 1, 1,-1); glVertex3d( 1,-1,-1); glVertex3d( 1,-1, 1); glVertex3d(-1, 1,-1); glVertex3d( 1, 1,-1); glVertex3d(-1, 1,-1); glVertex3d(-1, 1, 1); widget->qglColor(Qt::red); glVertex3d(-1,-1, 1); glVertex3d( 1,-1, 1); glVertex3d(-1,-1, 1); glVertex3d(-1, 1, 1); glVertex3d( 1, 1, 1); glVertex3d(-1, 1, 1); glVertex3d( 1, 1, 1); glVertex3d( 1,-1, 1); widget->qglColor(Qt::yellow); glVertex3d( 1, 1, 1); glVertex3d( 1, 1,-1); glEnd(); glPopMatrix(); } } }