void VortexSheetMesh::calcCirculation() { for (size_t tri = 0; tri < mTris.size(); tri++) { VortexSheetInfo& v = mVorticity.data[tri]; Vec3 e0 = getEdge(tri,0), e1 = getEdge(tri,1), e2 = getEdge(tri,2); Real area = getFaceArea(tri); if (area < 1e-10 || normSquare(v.vorticity) < 1e-10) { v.circulation = 0; continue; } float cx, cy, cz; SolveOverconstraint34(e0.x, e0.y, e0.z, e1.x, e1.y, e1.z, e2.x, e2.y, e2.z, v.vorticity.x, v.vorticity.y, v.vorticity.z, cx, cy, cz); v.circulation = Vec3(cx, cy, cz) * area; } }
void Renderer::setLighting(){ // recompute emissive light colors for highlighted bodies Real now=TimingInfo::getNow(/*even if timing is disabled*/true)*1e-9; highlightEmission0[0]=highlightEmission0[1]=highlightEmission0[2]=.8*normSquare(now,1); highlightEmission1[0]=highlightEmission1[1]=highlightEmission0[2]=.5*normSaw(now,2); glClearColor(bgColor[0],bgColor[1],bgColor[2],1.0); // set light sources glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,1); // important: do lighting calculations on both sides of polygons const GLfloat pos[4] = {(GLfloat)lightPos[0],(GLfloat)lightPos[1],(GLfloat)lightPos[2],(GLfloat)1.0}; const GLfloat ambientColor[4]={0.5,0.5,0.5,1.0}; const GLfloat specularColor[4]={1,1,1,1.}; const GLfloat diffuseLight[4] = { (GLfloat)lightColor[0], (GLfloat)lightColor[1], (GLfloat)lightColor[2], 1.0f }; glLightfv(GL_LIGHT0, GL_POSITION,pos); glLightfv(GL_LIGHT0, GL_SPECULAR, specularColor); glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); if (light1) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0); const GLfloat pos2[4] = {(GLfloat)light2Pos[0],(GLfloat)light2Pos[1],(GLfloat)light2Pos[2],1.0}; const GLfloat ambientColor2[4]={0.0,0.0,0.0,1.0}; const GLfloat specularColor2[4]={.8,.8,.8,1.}; const GLfloat diffuseLight2[4] = { (GLfloat)light2Color[0], (GLfloat)light2Color[1], (GLfloat)light2Color[2], 1.0f }; glLightfv(GL_LIGHT1, GL_POSITION,pos2); glLightfv(GL_LIGHT1, GL_SPECULAR, specularColor2); glLightfv(GL_LIGHT1, GL_AMBIENT, ambientColor2); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight2); if (light2) glEnable(GL_LIGHT1); else glDisable(GL_LIGHT1); glEnable(GL_LIGHTING); // show both sides of triangles glDisable(GL_CULL_FACE); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1); // http://www.sjbaker.org/steve/omniv/opengl_lighting.html glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); //Shared material settings resetSpecularEmission(); // not sctrictly lighting related glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); //glEnable(GL_POLYGON_SMOOTH); glShadeModel(GL_SMOOTH); #ifdef __MINGW64__ // see http://www.opengl.org/discussion_boards/showthread.php/133406-GL_RESCALE_NORMAL-in-VC // why is glext.h not in mingw: // * http://sourceforge.net/projects/mingw-w64/forums/forum/723797/topic/3572810 glEnable(GL_NORMALIZE); #else glEnable(GL_RESCALE_NORMAL); #endif // important for rendering text, to avoid repetivie glDisable(GL_TEXTURE_2D) ... glEnable(GL_TEXTURE_2D) // glBindTexture(GL_TEXTURE_2D,0); };
void OpenGLRenderer::render(const shared_ptr<Scene>& _scene,Body::id_t selection){ gilLock lockgil; if(!initDone) init(); assert(initDone); selId = selection; scene=_scene; // assign scene inside functors boundDispatcher.updateScenePtr(); geomDispatcher.updateScenePtr(); physDispatcher.updateScenePtr(); shapeDispatcher.updateScenePtr(); // stateDispatcher.updateScenePtr(); // just to make sure, since it is not initialized by default if(!scene->bound) scene->bound=shared_ptr<Aabb>(new Aabb); // recompute emissive light colors for highlighted bodies Real now=TimingInfo::getNow(/*even if timing is disabled*/true)*1e-9; highlightEmission0[0]=highlightEmission0[1]=highlightEmission0[2]=.8*normSquare(now,1); highlightEmission1[0]=highlightEmission1[1]=highlightEmission0[2]=.5*normSaw(now,2); // clipping assert(clipPlaneNormals.size()==(size_t)numClipPlanes); for(size_t i=0;i<(size_t)numClipPlanes; i++){ // someone could have modified those from python and truncate the vectors; fill those here in that case if(i==clipPlaneSe3.size()) clipPlaneSe3.push_back(Se3r(Vector3r::Zero(),Quaternionr::Identity())); if(i==clipPlaneActive.size()) clipPlaneActive.push_back(false); if(i==clipPlaneNormals.size()) clipPlaneNormals.push_back(Vector3r::UnitX()); // end filling stuff modified from python if(clipPlaneActive[i]) clipPlaneNormals[i]=clipPlaneSe3[i].orientation*Vector3r(0,0,1); /* glBegin(GL_LINES);glVertex3v(clipPlaneSe3[i].position);glVertex3v(clipPlaneSe3[i].position+clipPlaneNormals[i]);glEnd(); */ } // set displayed Se3 of body (scaling) and isDisplayed (clipping) setBodiesDispInfo(); glClearColor(bgColor[0],bgColor[1],bgColor[2],1.0); // set light sources glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,1); // important: do lighting calculations on both sides of polygons const GLfloat pos[4] = {(float) light1Pos[0], (float) light1Pos[1], (float) light1Pos[2],1.0}; const GLfloat ambientColor[4]={0.2,0.2,0.2,1.0}; const GLfloat specularColor[4]={1,1,1,1.f}; const GLfloat diffuseLight[4] = { (float) light1Color[0], (float) light1Color[1], (float) light1Color[2], 1.0f }; glLightfv(GL_LIGHT0, GL_POSITION,pos); glLightfv(GL_LIGHT0, GL_SPECULAR, specularColor); glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); if (light1) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0); const GLfloat pos2[4] = {(float) light2Pos[0], (float) light2Pos[1], (float) light2Pos[2],1.0}; const GLfloat ambientColor2[4]={0.0,0.0,0.0,1.0}; const GLfloat specularColor2[4]={1,1,0.6,1.f}; const GLfloat diffuseLight2[4] = { (float) light2Color[0], (float) light2Color[1], (float) light2Color[2], 1.0f }; glLightfv(GL_LIGHT1, GL_POSITION,pos2); glLightfv(GL_LIGHT1, GL_SPECULAR, specularColor2); glLightfv(GL_LIGHT1, GL_AMBIENT, ambientColor2); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight2); if (light2) glEnable(GL_LIGHT1); else glDisable(GL_LIGHT1); glEnable(GL_LIGHTING); glEnable(GL_CULL_FACE); // http://www.sjbaker.org/steve/omniv/opengl_lighting.html glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); glEnable(GL_COLOR_MATERIAL); //Shared material settings resetSpecularEmission(); drawPeriodicCell(); if (dof || id) renderDOF_ID(); if (bound) renderBound(); if (shape) renderShape(); if (intrAllWire) renderAllInteractionsWire(); if (intrGeom) renderIGeom(); if (intrPhys) renderIPhys(); FOREACH(const shared_ptr<GlExtraDrawer> d, extraDrawers){ if(d->dead) continue; glPushMatrix(); d->scene=scene.get(); d->render(); glPopMatrix(); } }
double CoinPackedVectorBase::twoNorm() const { return sqrt(normSquare()); }
float Quaternion::norm() const { return sqrt(normSquare()); }
float Vector::norm() const { return sqrt(normSquare()); }