void GLView::paintGL() { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gluLookAt(-viewportX, -distance, -viewportZ, -viewportX, 0.0, -viewportZ, 0.0, 0.0, 1.0); glRotated(rotateX, 1.0, 0.0, 0.0); glRotated(rotateY, 0.0, 1.0, 0.0); glRotated(rotateZ, 0.0, 0.0, 1.0); if(showAxes) { glLineWidth(1); glColor3d(0.5, 0.5, 0.5); glBegin(GL_LINES); double c=fmax(distance/2,rulerLength); glVertex3d(-c, 0, 0); glVertex3d(+c, 0, 0); glVertex3d(0, -c, 0); glVertex3d(0, +c, 0); glVertex3d(0, 0, -c); glVertex3d(0, 0, +c); glEnd(); } if(showBase) { glLineWidth(1); glColor3d(0.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); glVertex3i(baseX, baseY, 0); glVertex3i(baseX+notchX, baseY, 0); glVertex3i(baseX+notchX, baseY+notchLength, 0); glVertex3i(baseX+notchX+notchWidth, baseY+notchLength, 0); glVertex3i(baseX+notchX+notchWidth, baseY, 0); glVertex3i(baseX+baseWidth, baseY, 0); glVertex3i(baseX+baseWidth, baseY+baseLength, 0); glVertex3i(baseX, baseY+baseLength, 0); glEnd(); } if(showPrintArea) { glLineWidth(1); glColor3d(0.0, 1.0, 0.0); glBegin(GL_LINE_LOOP); glVertex3i(printX, printY, 0); glVertex3i(printWidth-printX,printY, 0); glVertex3i(printWidth-printX,printLength-printY, 0); glVertex3i(printX, printLength-printY, 0); glEnd(); } if(showRulers) { glLineWidth(1); glColor3d(0.2, 0.2, 0.2); glBegin(GL_LINES); int k=distance<200?1:10; //Only show milimeters when close up for(int i=-rulerLength; i<rulerLength; i+=k) { int j=i%10?2:5; glVertex3i(i, 0, 0); glVertex3i(i, j, 0); } for(int i=-rulerLength; i<rulerLength; i+=k) { int j=i%10?2:5; glVertex3i(0, i, 0); glVertex3i(j, i, 0); } for(int i=-rulerLength; i<rulerLength; i+=k) { int j=i%10?2:5; glVertex3i(0, 0, i); glVertex3i(j, 0, i); } glEnd(); } if(render) render->draw(skeleton,showEdges); }
// 另一种对于view系列指令支持的方法是 // 预处理的时候直接读出最终的origin, scale, rot // 这样就可以实现在anim == off时,需要两遍绘图了 void sandbox::play() { set_defaults(); int played_count = 0; bool should_stop = false; for (std::vector<instruction>::const_iterator it = v.begin(); it != v.end(); ++it) { if (should_stop) { break; } const instruction& the_inst = *it; // std::cout << the_inst; switch (the_inst.name) { case inst::BGCOLOR: if (played_count != 0) { std::cout << "BACKGROUND必须在绘图指令之前使用,此处被省略" << std::endl; } else { glClearColor(the_inst.x1, the_inst.x2, the_inst.x3, 0.5); glClear(GL_COLOR_BUFFER_BIT); } break; case inst::ORIGIN: origin_x = the_inst.x1; origin_y = the_inst.x2; break; case inst::ROT: rot_angle = the_inst.x1; break; case inst::SCALE: scale_x = the_inst.x1; scale_y = the_inst.x2; break; case inst::BEGINDRAW: glBegin(GL_POINTS); in_loop = true; init_gradual(the_inst.i1); break; case inst::ENDDRAW: glEnd(); in_loop = false; end_gradual(); break; case inst::COLOR: glColor3d(the_inst.x1, the_inst.x2, the_inst.x3); break; case inst::WIDTH: width = the_inst.i1; break; case inst::DRAW: double x, y; convert(the_inst.x1, the_inst.x2, x, y); for (int i = -width / 2; i < (width + 1) / 2; i++) { for (int j = -width / 2; j < (width + 1) / 2; j++) { glVertex2d(x + i, y + j); } } if (anim) { played_count++; if (played_count == total_draw_instructions) { anim = false; finished = true; should_stop = true; } if (played_flame + speed == played_count) { played_flame = played_count; should_stop = true; } } process_gradual(); break; case inst::VIEW_ORIGIN: view_target_origin_x = the_inst.x1; view_target_origin_y = the_inst.x2; in_gradual_origin = true; break; case inst::VIEW_ROTATE: view_target_rot_angle = the_inst.x1; in_gradual_rot = true; break; case inst::VIEW_SCALE: view_target_scale_x = the_inst.x1; view_target_scale_y = the_inst.x2; in_gradual_scale = true; break; default: break; } }; if (in_loop) { glEnd(); in_loop = false; end_gradual(); } apply_global_parameters(); if (!anim) { finished = true; if (!static_replayed) { static_replayed = true; this->play(); } } }
//***************************************************************************************************************************** void dessine_box() { float t = 1.0f; // Configuration des états OpenGL glDisable(GL_DEPTH_TEST); //Désactivation de l'ecriture dans le z-buffer glDepthMask(GL_FALSE); glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); glColor3d(1.0, 1.0, 1.0); // Réglage de la position de la box calcul_pos_cam(); glPushMatrix(); glTranslated(cx, cy, cz); // Rendu de la geometrie //gauche glBindTexture(GL_TEXTURE_2D, textureBox[0]); glBegin(GL_QUADS); // X Negatif glTexCoord2f(0.0, 0.0); glVertex3f(-t, -t, -t); glTexCoord2f(1.0, 0.0); glVertex3f(-t, t, -t); glTexCoord2f(1.0, 1.0); glVertex3f(-t, t, t); glTexCoord2f(0.0, 1.0); glVertex3f(-t, -t, t); glEnd(); //droite glBindTexture(GL_TEXTURE_2D, textureBox[1]); glBegin(GL_QUADS); // X Positif glTexCoord2f(0.0, 0.0); glVertex3f(t, t, -t); glTexCoord2f(1.0, 0.0); glVertex3f(t, -t, -t); glTexCoord2f(1.0, 1.0); glVertex3f(t, -t, t); glTexCoord2f(0.0, 1.0); glVertex3f(t, t, t); glEnd(); //fond glBindTexture(GL_TEXTURE_2D, textureBox[2]); glBegin(GL_QUADS); // Y Negatif glTexCoord2f(0.0, 0.0); glVertex3f(t, -t, -t); glTexCoord2f(1.0, 0.0); glVertex3f(-t, -t, -t); glTexCoord2f(1.0, 1.0); glVertex3f(-t, -t, t); glTexCoord2f(0.0, 1.0); glVertex3f(t, -t, t); glEnd(); //avant glBindTexture(GL_TEXTURE_2D, textureBox[3]); glBegin(GL_QUADS); // Y Positif glTexCoord2f(0.0, 0.0); glVertex3f(-t, t, -t); glTexCoord2f(1.0, 0.0); glVertex3f(t, t, -t); glTexCoord2f(1.0, 1.0); glVertex3f(t, t, t); glTexCoord2f(0.0, 1.0); glVertex3f(-t, t, t); glEnd(); //sol glBindTexture(GL_TEXTURE_2D, textureBox[4]); glBegin(GL_QUADS); // Z Negatif glTexCoord2f(0.0, 0.0); glVertex3f(-t, -t, -t); glTexCoord2f(1.0, 0.0); glVertex3f(t, -t, -t); glTexCoord2f(1.0, 1.0); glVertex3f(t, t, -t); glTexCoord2f(0.0, 1.0); glVertex3f(-t, t, -t); glEnd(); //haut glBindTexture(GL_TEXTURE_2D, textureBox[5]); glBegin(GL_QUADS); // Z Positif glTexCoord2f(0.0, 0.0); glVertex3f(t, t, t); glTexCoord2f(1.0, 0.0); glVertex3f(t, -t, t); glTexCoord2f(1.0, 1.0); glVertex3f(-t, -t, t); glTexCoord2f(0.0, 1.0); glVertex3f(-t, t, t); glEnd(); // Réinitialisation des états OpenGL glPopMatrix(); // Réactivation de l'écriture dans le z-buffer glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glEnable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); }
void display () { if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); // Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); enter3D(); gluLookAt(camera.x, camera.y, camera.z, cameraLookAt.x, cameraLookAt.y, cameraLookAt.z, cameraUp.x, cameraUp.y, cameraUp.z); glPushMatrix(); glScaled(1.0, -1.0, 1.0); if (showSky) { drawSky(); } // Draw coordinate axis // glCallList(axisList); for (int i = 0; i < 9; i ++) { gravitationalForce[i].draw(); } if (showGround) { drawGround(); } if (showPipe) { glPushMatrix(); drawSprinkler(emitterSpacing * emitterCount, sprinkerHeight, 100, 5.0, 40.0); glPopMatrix(); } if (showMountains) { drawMoutains(3000, 0, 0); drawMoutains(4000, 180, -200); drawMoutains(5600, 45, -500); } if (showTrees) { drawTrees(); } if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) { Texture::set("shine"); glBlendFunc(GL_SRC_ALPHA, GL_ONE); } particleSystem.draw(); if (renderMode == PARTICLERENDERMODE_TEXTURESPRITE) { Texture::done(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /*glPushMatrix(); glColor3f(1.0, 1.0, 1.0); glTranslatef(0.0, -100.0, 0.0); glScalef(100.0, -100.0, 100.0); drawModel(); glPopMatrix();*/ if (wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } glDisable(GL_DEPTH_TEST); enter2D(); glColor4d(0.0, 0.0, 0.0, 1.0); sprintf(fpsText, "FPS:%4.2f", fps); drawText(GLUT_BITMAP_HELVETICA_18, windowWidth - 100, 20, fpsText); if (showHUD) { drawText(GLUT_BITMAP_HELVETICA_18, 10, 20, "Water sprinkler"); sprintf(cameraText, "%4.2f %4.2f %4.2f", camera.x, camera.y, camera.z); drawText(GLUT_BITMAP_HELVETICA_12, 10, 60, cameraText); sprintf(particleText, "Particles: %llu", particleSystem.getParticleCount()); drawText(GLUT_BITMAP_HELVETICA_12, 10, 100, particleText); if (menu) { // Current option glColor4d(0.2, 0.2, 0.2, 0.8); glRectd(10, windowHeight - 40, 120, windowHeight - 10); glColor4d(1.0, 1.0, 1.0, 1.0); drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, options[currentOption]); // Current option value glColor4d(0.4, 0.4, 0.4, 0.8); glRectd(120, windowHeight - 40, 240, windowHeight - 10); glColor4d(1.0, 1.0, 1.0, 1.0); switch (currentOption) { case 0: sprintf(optionValue, "%4.2f", Particle::initialVelocity); break; case 1: sprintf(optionValue, "%d", initialColour); break; case 2: sprintf(optionValue, "%d", gravityIntensity); break; case 3: sprintf(optionValue, "%d", Particle::startLifeSpan); break; case 4: sprintf(optionValue, "%s", renderModes[renderMode]); break; case 5: sprintf(optionValue, "%d", emitterCount); break; case 6: sprintf(optionValue, "%d", emitterSpacing); break; case 7: sprintf(optionValue, "%s", cameras[currentCamera]); break; case 8: sprintf(optionValue, "%4.2f", Particle::airResistance); break; case 9: sprintf(optionValue, "%s", cycleColours ? "On" : "Off"); break; case 10: sprintf(optionValue, "%d", emitFrequency); break; case 11: sprintf(optionValue, "%4.2f", ParticleEmitter::emitSpread); break; case 12: sprintf(optionValue, "%d", ParticleSystem::perEmit); break; case 13: sprintf(optionValue, "%s", ParticleEmitter::show ? "Yes" : "No"); break; case 14: sprintf(optionValue, "%s", wireframe ? "Yes" : "No"); break; case 15: sprintf(optionValue, "%s", showMountains ? "On" : "Off"); break; case 16: sprintf(optionValue, "%s", showTrees ? "On" : "Off"); break; case 17: sprintf(optionValue, "%s", showSky ? "On" : "Off"); break; case 18: sprintf(optionValue, "%s", showGround ? "On" : "Off"); break; case 19: sprintf(optionValue, "%s", demos[demo]->name.c_str()); break; case 20: sprintf(optionValue, "%1.1f", Particle::bounce); break; case 21: sprintf(optionValue, "%s", skyTexture ? "On" : "Off"); break; case 22: sprintf(optionValue, "%s", grassTexture ? "On" : "Off"); break; case 23: sprintf(optionValue, "%s", showPipe ? "On" : "Off"); break; case 24: sprintf(optionValue, "%s", ParticleEmitter::randomness ? "On" : "Off"); break; case 25: sprintf(optionValue, "%s", Tree::drawLeaves ? "On" : "Off"); break; default: sprintf(optionValue, "%s", ""); break; } drawText(GLUT_BITMAP_HELVETICA_12, 130, windowHeight - 20, optionValue); } else { glColor4d(1.0, 1.0, 1.0, 1.0); drawText(GLUT_BITMAP_HELVETICA_12, 20, windowHeight - 20, "Press m to toggle menu"); } for (int i = 1; i < 10; i++) { if (selectedGravitationalForce == i - 1) { glColor4d(1.0, 0.4, 0.4, 0.8); } else { glColor4d(0.4, 0.4, 1.0, 0.2); } glRectd(200 + ((i - 1) * 50), 10, 230 + ((i - 1) * 50), 40); glColor4d(0.0, 0.0, 0.0, 1.0); sprintf(n, "%d", i); drawText(GLUT_BITMAP_HELVETICA_18, 210 + ((i - 1) * 50), 30, n); } } if (currentCamera == 3) { glBegin(GL_LINES); glColor3d(0.8, 0.8, 0.8); glVertex2d((windowWidth / 2) - 30, windowHeight / 2); glVertex2d((windowWidth / 2) + 30, windowHeight / 2); glVertex2d(windowWidth / 2, (windowHeight / 2) - 30); glVertex2d(windowWidth / 2, (windowHeight / 2) + 30); glEnd(); } glPopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
/* * Prints out the menu */ void printMenu() { if (optionTargeted == 0) { glBindTexture(GL_TEXTURE_2D, texture[optionTargeted]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-17.0f, -11.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 10.0f, -11.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0f, 11.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-17.0f, 11.0f, 1.0f); // Top Left Of The Texture and Quad glEnd(); t = GLUT_BITMAP_TIMES_ROMAN_24; glColor3d(1, 0, 0); printGl("~> Play <~", 11.6, 5); } else { t = GLUT_BITMAP_HELVETICA_18; glColor3d(7, 7, 7); printGl("Play", 12.4, 5); } if (optionTargeted == 1) { glBindTexture(GL_TEXTURE_2D, texture[optionTargeted]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-17.0f, -11.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 08.0f, -11.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 08.0f, 11.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-17.0f, 11.0f, 1.0f); // Top Left Of The Texture and Quad glEnd(); t = GLUT_BITMAP_TIMES_ROMAN_24; glColor3d(1, 0, 0); printGl("~> Options <~", 11.2, 3); } else { t = GLUT_BITMAP_HELVETICA_18; glColor3d(7, 7, 7); printGl("Options", 12, 3); } if (optionTargeted == 2) { glBindTexture(GL_TEXTURE_2D, texture[optionTargeted]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-17.0f, -11.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 07.1f, -11.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 07.1f, 11.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-17.0f, 11.0f, 1.0f); // Top Left Of The Texture and Quad glEnd(); t = GLUT_BITMAP_TIMES_ROMAN_24; glColor3d(1, 0, 0); printGl("~> High scores <~", 10.8, 1); } else { t = GLUT_BITMAP_HELVETICA_18; glColor3d(7, 7, 7); printGl("High scores", 11.6, 1); } if (optionTargeted == 3) { glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-17.0f, -11.0f, 1.0f); // Bottom Left Of The Texture and Quad glTexCoord2f(1.0f, 0.0f); glVertex3f( 10.0f, -11.0f, 1.0f); // Bottom Right Of The Texture and Quad glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0f, 11.0f, 1.0f); // Top Right Of The Texture and Quad glTexCoord2f(0.0f, 1.0f); glVertex3f(-17.0f, 11.0f, 1.0f); // Top Left Of The Texture and Quad glEnd(); t = GLUT_BITMAP_TIMES_ROMAN_24; glColor3d(1, 0, 0); printGl("~> Exit <~", 11.6, -1); } else { t = GLUT_BITMAP_HELVETICA_18; glColor3d(7, 7, 7); printGl("Exit", 12.4, -1); } }
void DSStatusBar::show() { // 更改投影方式为 2D 平行投影 glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); glOrtho(0, status_bar_width, 0, window_height, 0.01, 1000); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport( window_width - status_bar_width, 0, status_bar_width, window_height ); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); gluLookAt(0.0, 0.0, 200.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glColor3d(1.0, 1.0, 1.0); renderBackground(); //fillRectange2D(0, 0, status_bar_width, window_height); // 这里画小地图,战场,人物等状态信息 glColor3f(0,1,1); // 让我们在这里写一下眼睛位置 std::wostringstream os; /*os << "(" << std::fixed << std::setprecision(2) << eye[0] << ", " << eye[1] << ", " << eye[2] << ")"; glPushMatrix(); { glLoadIdentity(); dstext_small.print(8.0, 8.0, os.str()); dstext_small.print(40.0, 30.0, L"Eye position"); } glPopMatrix();*/ //让我们写一下被选中人物的信息 glPushMatrix(); { //std::stringstream o; os.str(L""); os << frame.actors.selectInfo(); glLoadIdentity(); dstext_small.print(12.0, 400.0, os.str()); } glPopMatrix(); //提示消息 glPushMatrix(); { //std::stringstream o; os.str(L""); //os << L"帮助\nF1 拉近镜头\nF2 推远镜头\nup,down,left,right\n视角旋转\nw,a,s,d 视线平移\n鼠标点击 选择人物\n鼠标右键 取消选择"; //os << L"帮助:\nF1 拉近镜头\nF2 推远镜头\n↑ ↓ → ← 视角旋转\nW S A D 视线平移\n"; /*if (frame.actors.paused) { os << L"F4 切换为自动"; } else { os << L"F4 切换为手动"; }*/ glLoadIdentity(); dstext_small.print(15.0f, (GLfloat)window_height - 120, os.str()); } glPopMatrix(); /*os.str(L""); os << frame.actors.list["mage"].winx << L", " << frame.actors.list["mage"].winy << L", " << frame.actors.list["mage"].winz; glPushMatrix(); { glLoadIdentity(); dstext_small.print(5, 400, os.str().c_str()); } glPopMatrix();*/ glPushMatrix(); { //glColor3f(0,0,1); os.str(L""); os << L"FPS: " << frame.getFPS(); glLoadIdentity(); glScalef(0.5, 0.5, 0.5); dstext.print(15.0f, (GLfloat)window_height - 80, os.str()); } glPopMatrix(); glPushMatrix(); { os.str(L""); os << L"回合 " << frame.actors.getCurrentRound(); if (frame.actors.round_finished) { os << L"\nF3 进入下一回合"; } if (frame.actors.script_playing != 0) { os << L"\n" << frame.actors.script_playing << L" 个动作正在播放"; } if (frame.actors.all_finished) { os << L"\n已结束"; } glLoadIdentity(); dstext_small.print(15.0f, 220, os.str()); } glPopMatrix(); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); // 回到透视投影 glMatrixMode(GL_PROJECTION); } glPopMatrix(); glMatrixMode(GL_MODELVIEW); }
void Model::draw(unsigned int animation, double timeIn) { if (scene->mNumAnimations <= animation) return; aiAnimation* currentAnimation = scene->mAnimations[animation]; //Step 1: Interpolate position, rotation, scale in the all channels and add to transformation for (unsigned int i = 0; i < currentAnimation->mNumChannels; i++) { aiNodeAnim* currentChannel = currentAnimation->mChannels[i]; aiVector3D currentPosition = interpolatePosition(currentChannel, timeIn); aiQuaternion currentRotation = interpolateRotation(currentChannel, timeIn); aiVector3D currentScale = interpolateScale(currentChannel, timeIn); aiMatrix4x4& transformation = aiMatrix4x4(currentScale, currentRotation, currentPosition); aiNode* currentNode = scene->mRootNode->FindNode(currentChannel->mNodeName); currentNode->mTransformation = transformation; } for (unsigned int k = 0; k < scene->mNumMeshes; k++) { //Step 2: Bone transformation, change transformation of the bone according to animation aiMesh* currentMesh = scene->mMeshes[k]; std::vector<aiMatrix4x4> boneTransformations = std::vector<aiMatrix4x4>(currentMesh->mNumBones); for (unsigned int i = 0; i < currentMesh->mNumBones; i++) { aiBone* currentBone = currentMesh->mBones[i]; aiNode* currentNode = scene->mRootNode->FindNode(currentBone->mName); boneTransformations[i] = parentMultiplication(currentNode); boneTransformations[i] *= currentMesh->mBones[i]->mOffsetMatrix; } //Step 3: Skinning std::vector<aiVector3D> resultPosition(currentMesh->mNumVertices); for (size_t k = 0; k < currentMesh->mNumBones; k++) { const aiBone* currentBone = currentMesh->mBones[k]; const aiMatrix4x4& positionMatrix = boneTransformations[k]; for (size_t j = 0; j < currentBone->mNumWeights; j++) { const aiVertexWeight& weight = currentBone->mWeights[j]; size_t vertexId = weight.mVertexId; const aiVector3D& srcPosition = currentMesh->mVertices[vertexId]; resultPosition[vertexId] += weight.mWeight * (positionMatrix * srcPosition); } } //Step 4: Draw the final model // For every face size_t cv = 0, ctc = 0; glColor3d(1.0, 1.0, 1.0); // Set the face color to white for (int cf = 0; cf < currentMesh->mNumFaces; cf++) { const aiFace& face = currentMesh->mFaces[cf]; // For all vertices in face (Final drawing) if (wireframe) glBegin(GL_LINE_LOOP); else glBegin(GL_TRIANGLES); for (int cfi = 0; cfi < 3; cfi++) { double x = resultPosition[face.mIndices[cfi]].x; double y = resultPosition[face.mIndices[cfi]].y; double z = resultPosition[face.mIndices[cfi]].z; glVertex3d(x, y, z); } glEnd(); } } }
void EntGhost::draw() { // display logic goes here // draw the object at 0,0,0 // x,y are the gameboard, z is 0 for the level // remember Z is up now //Draw ghosts GLUquadric *myQuad = TextureHandler::getInstance()->getQuadric(); double red = color.x; double green = color.y; double blue = color.z; double alpha = 0.8; // color me glColor4d(red,green,blue,alpha); // texture me if (TextureHandler::getInstance()->getTexture()) { TextureHandler::getInstance()->use("ghost"); glColor4d(red * 0.5 + 0.5, green * 0.5 + 0.5, blue * 0.5 + 0.5,alpha); // looks better for texturing } if (scattering) { TextureHandler::getInstance()->use("pellet"); glColor4d(0.3, 0.3, 1.0, 0.9); // looks better for texturing } if (!homebound) { glPushMatrix(); // middle glTranslatef (0,0, -9); gluCylinder(myQuad, 6, 6, 9, 16, 16); glTranslatef (0,0, 9); // top glRotatef (90, 1, 0, 0.0); gluSphere(myQuad, 6, 16, 16); glRotatef (90,1, 0,0); glTranslatef (0,0, 9); gluDisk(myQuad, 0, 6, 16, 16); // bottom for (int angle = 0; angle < 360; angle += 40) { glPushMatrix(); glRotatef (angle + roto, 0,0,1); // animate the bottom (: glTranslatef (4.5,0,0); gluCylinder(myQuad, 1.5, 0, 3, 16, 16); glPopMatrix(); } glPopMatrix(); // shadow glPushMatrix(); TextureHandler::getInstance()->use("none"); glColor4d(0,0,0,0.5); glTranslated(0,0,-14); gluDisk(myQuad, 0, 6, 16, 16); glPopMatrix(); } TextureHandler::getInstance()->use("none"); // eyes glPushMatrix(); glColor3f(1,1,1); glTranslated(4,4,1); gluSphere(myQuad, 2, 8, 8); glColor3f(0,0,0); glTranslated(0,2,0); gluSphere(myQuad, 1, 8, 8); glPopMatrix(); glPushMatrix(); glColor3f(1,1,1); glTranslated(-4,4,1); gluSphere(myQuad, 2, 8, 8); glColor3f(0,0,0); glTranslated(0,2,0); gluSphere(myQuad, 1, 8, 8); glPopMatrix(); // shadow // here is the best example to show how shadows are handled // everywhere else they ar assuming the model is a sphere which in most cases is correct glPushMatrix(); TextureHandler::getInstance()->use("none"); // use a white texture glColor4d(0,0,0,0.5); // set it to show black with half opacity glTranslated(0,0,-14); // move it to our ground plane which we are using -14 for this glScaled(1,1,0); // flatten Z (orthographic projection to the ground plane) // draw again (same as above code minus color above) glPushMatrix(); glTranslated(4,4,1); gluSphere(myQuad, 2, 8, 8); glTranslated(0,2,0); gluSphere(myQuad, 1, 8, 8); glPopMatrix(); glPushMatrix(); glTranslated(-4,4,1); gluSphere(myQuad, 2, 8, 8); glTranslated(0,2,0); gluSphere(myQuad, 1, 8, 8); glPopMatrix(); glPopMatrix(); glColor3d(0.4,1,0); vect s( 0.25 ); // scale vect d( 0, 0, 8 ); // translation // put our number on top of the ghost quad( vect(-4,5) * s + d , vect(4,7) * s + d ); quad( vect(-4,-1) * s + d , vect(4,1) * s + d ); quad( vect(-4,-7) * s + d , vect(4,-5) * s + d ); quad( vect(-6,1) * s + d , vect(-4,5) * s + d ); quad( vect(-6,-5) * s + d , vect(-4,-1) * s + d ); quad( vect(4,-5) * s + d , vect(6,-1) * s + d ); }
void GUILane::drawLane2LaneConnections() const { for (std::vector<MSLink*>::const_iterator i = myLinks.begin(); i != myLinks.end(); ++i) { LinkState state = (*i)->getState(); const MSLane* connected = (*i)->getLane(); if (connected == 0) { continue; } switch (state) { case LINKSTATE_TL_GREEN_MAJOR: case LINKSTATE_TL_GREEN_MINOR: glColor3d(0, 1, 0); break; case LINKSTATE_TL_RED: glColor3d(1, 0, 0); break; case LINKSTATE_TL_YELLOW_MAJOR: case LINKSTATE_TL_YELLOW_MINOR: glColor3d(1, 1, 0); break; case LINKSTATE_TL_OFF_BLINKING: glColor3d(1, 1, 0); break; case LINKSTATE_TL_OFF_NOSIGNAL: glColor3d(0, 1, 1); break; case LINKSTATE_MAJOR: glColor3d(1, 1, 1); break; case LINKSTATE_MINOR: glColor3d(.2, .2, .2); break; case LINKSTATE_STOP: glColor3d(.4, .2, .2); break; case LINKSTATE_EQUAL: glColor3d(.5, .5, .5); break; case LINKSTATE_ALLWAY_STOP: glColor3d(.2, .2, .4); break; case LINKSTATE_DEADEND: glColor3d(0, 0, 0); break; } glBegin(GL_LINES); const Position& p1 = getShape()[-1]; const Position& p2 = connected->getShape()[0]; glVertex2f(p1.x(), p1.y()); glVertex2f(p2.x(), p2.y()); glEnd(); GLHelper::drawTriangleAtEnd(Line(p1, p2), (SUMOReal) .4, (SUMOReal) .2); } }
void OGL3DBase::InitLighting() { nextLight = 0; PC_Lighting& currLights = plot3Dbase.plotLighting; if (!currLights.useLighting) { // no lighting glDisable(GL_LIGHTING); glDisable(GL_NORMALIZE); glDisable(GL_LIGHT0); return; } SC_ColorSpec penColor = plot3Dbase.defaultPenSet->GetColor(currLights.ambientPen); // set basic ambient GLfloat ambientLight[4]; ambientLight[0] = (GLfloat) (penColor.RH * currLights.ambientIntensity); ambientLight[1] = (GLfloat) (penColor.GS * currLights.ambientIntensity); ambientLight[2] = (GLfloat) (penColor.BV * currLights.ambientIntensity); ambientLight[3] = (GLfloat) currLights.ambientLightAlpha; glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); if (!currLights.useDefaultLight) { glDisable(GL_LIGHT0); return; } // set up default light penColor = plot3Dbase.defaultPenSet->GetColor(currLights.defaultDiffuseLightPen); GLfloat diffuseLight[4]; diffuseLight[0] = (GLfloat) (penColor.RH * currLights.defaultDiffuseLightIntensity); diffuseLight[1] = (GLfloat) (penColor.GS * currLights.defaultDiffuseLightIntensity); diffuseLight[2] = (GLfloat) (penColor.BV * currLights.defaultDiffuseLightIntensity); diffuseLight[3] = (GLfloat) currLights.defaultDiffuseLightAlpha; glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); penColor = plot3Dbase.defaultPenSet->GetColor(currLights.defaultSpecularLightPen); GLfloat specularLight[4]; specularLight[0] = (GLfloat) (penColor.RH * currLights.defaultSpecularLightIntensity); specularLight[1] = (GLfloat) (penColor.GS * currLights.defaultSpecularLightIntensity); specularLight[2] = (GLfloat) (penColor.BV * currLights.defaultSpecularLightIntensity); specularLight[3] = (GLfloat) currLights.defaultSpecularLightAlpha; glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); double elev, azimuth; if (currLights.defaultLightIsFixed) { elev = currLights.fixedElevation; azimuth = currLights.fixedAzimuth; } else { elev = currView.elevation + currLights.relativeElevation; azimuth = currView.azimuth + currLights.relativeAzimuth; } elev = Radians(elev); azimuth = Radians(azimuth - 180.0); GLfloat defaultPosition[4]; defaultPosition[0] = (GLfloat) (sin(azimuth) * cos(elev)); defaultPosition[1] = (GLfloat) (cos(azimuth) * cos(elev)); defaultPosition[2] = (GLfloat) sin(elev); defaultPosition[3] = (GLfloat) currLights.defaultLightW; glLightfv(GL_LIGHT0, GL_POSITION, defaultPosition); if (currLights.showDefaultLight) { double defX = defaultPosition[0]; double defY = defaultPosition[1]; double defZ = defaultPosition[2]; if (currLights.defaultLightW > 0.01) { defX /= currLights.defaultLightW; defY /= currLights.defaultLightW; defZ /= currLights.defaultLightW; } static const double dl = 0.025; glColor3d(1.0, 0.0, 0.0); glLineWidth(3); glBegin(GL_LINES); glVertex4d(0.0, 0.0, 0.0, 1.0); glVertex4d(GLdouble(defX ), GLdouble(defY), GLdouble(defZ), currLights.defaultLightW); glEnd(); glColor3d(0.0, 0.0, 0.0); glBegin(GL_LINE_LOOP); glVertex3d(defX - dl, defY- dl, defZ- dl); glVertex3d(defX - dl, defY+ dl, defZ- dl); glVertex3d(defX + dl, defY+ dl, defZ- dl); glVertex3d(defX + dl, defY- dl, defZ- dl); glEnd(); glBegin(GL_LINE_LOOP); glVertex3d(defX - dl, defY- dl, defZ+ dl); glVertex3d(defX - dl, defY+ dl, defZ+ dl); glVertex3d(defX + dl, defY+ dl, defZ+ dl); glVertex3d(defX + dl, defY- dl, defZ+ dl); glEnd(); glBegin(GL_LINES); glVertex3d(defX - dl, defY- dl, defZ- dl); glVertex3d(defX - dl, defY- dl, defZ+ dl); glVertex3d(defX - dl, defY+ dl, defZ- dl); glVertex3d(defX - dl, defY+ dl, defZ+ dl); glVertex3d(defX + dl, defY- dl, defZ- dl); glVertex3d(defX + dl, defY- dl, defZ+ dl); glVertex3d(defX + dl, defY+ dl, defZ- dl); glVertex3d(defX + dl, defY+ dl, defZ+ dl); glEnd(); } glEnable(GL_LIGHT0); GLfloat mat_specular[] = {0.2F, 0.2F, 0.2F, 1.0F}; GLfloat mat_shininess[] = {50.0F}; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); nextLight++; }
void GUISUMOAbstractView::displayLegend() { // compute the scale bar length size_t length = 1; const std::string text("10000000000"); size_t noDigits = 1; size_t pixelSize = 0; while (true) { pixelSize = (size_t) m2p((SUMOReal) length); if (pixelSize > 20) { break; } length *= 10; noDigits++; if (noDigits > text.length()) { return; } } SUMOReal lineWidth = 1.0; glLineWidth((SUMOReal) lineWidth); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // draw the scale bar glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); SUMOReal len = (SUMOReal) pixelSize / (SUMOReal)(getWidth() - 1) * (SUMOReal) 2.0; glColor3d(0, 0, 0); double o = double(15) / double(getHeight()); double o2 = o + o; double oo = double(5) / double(getHeight()); glBegin(GL_LINES); // vertical glVertex2d(-.98, -1. + o); glVertex2d(-.98 + len, -1. + o); // tick at begin glVertex2d(-.98, -1. + o); glVertex2d(-.98, -1. + o2); // tick at end glVertex2d(-.98 + len, -1. + o); glVertex2d(-.98 + len, -1. + o2); glEnd(); SUMOReal w = SUMOReal(35) / SUMOReal(getWidth()); SUMOReal h = SUMOReal(35) / SUMOReal(getHeight()); pfSetPosition(SUMOReal(-0.99), SUMOReal(1. - o2 - oo)); pfSetScaleXY(w, h); glRotated(180, 1, 0, 0); pfDrawString("0m"); glRotated(-180, 1, 0, 0); pfSetPosition(SUMOReal(-.99 + len), SUMOReal(1. - o2 - oo)); glRotated(180, 1, 0, 0); pfDrawString((text.substr(0, noDigits) + "m").c_str()); glRotated(-180, 1, 0, 0); // restore matrices glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); }
void Ant::onDisplay() { glPushMatrix(); glScalef(scale, scale, 1); /** * Translate/Rotate the whole ant */ glTranslatef( 0, 0, -100 ); glRotatef( horizontal_spin, 0.0, 1.0, 0.3 ); glRotatef( vertical_spin, 1.0, 0.0, 0.3 ); // helps show the bounds of the ant if ( show_bounding_box ) { glutWireCube( 20.0 ); } glColor3d( 1.0, 0.0, 0.0 ); /** * The thorax is our local center for the ant, * therefore we do not call a postTranslate, as all * other object positions derive from the thorax */ thorax->onDisplay(); /** * Construct the rest of the ant */ abdomen->onDisplay(); abdomen->onPostDisplay(); glColor3d( 0.0, 0.2, 0.2 ); glTranslatef( 0, 0, 5.5 ); glRotatef( joint_angle_neck, 0, 1.0, 0.0 ); neck->onDisplay(); head->onDisplay(); head->onPostDisplay(); neck->onPostDisplay(); glRotatef( -joint_angle_neck, 0, 1.0, 0.0 ); front_left_leg->setBaseAngle( joint_angle_legs_base ); front_right_leg->setBaseAngle( joint_angle_legs_base ); middle_left_leg->setBaseAngle( joint_angle_legs_base ); middle_right_leg->setBaseAngle( joint_angle_legs_base ); rear_left_leg->setBaseAngle( joint_angle_legs_base ); rear_right_leg->setBaseAngle( joint_angle_legs_base ); front_left_leg->setTipAngle( joint_angle_legs_tip ); front_right_leg->setTipAngle( joint_angle_legs_tip ); middle_left_leg->setTipAngle( joint_angle_legs_tip ); middle_right_leg->setTipAngle( joint_angle_legs_tip ); rear_left_leg->setTipAngle( joint_angle_legs_tip ); rear_right_leg->setTipAngle( joint_angle_legs_tip ); glColor3d( 0.5, 0.5, 0.0 ); front_left_leg->onDisplay(); glRotatef( 180, 0, 1.0, 0.0 ); front_right_leg->onDisplay(); glTranslatef( 0, 0, 2.5 ); middle_right_leg->onDisplay(); glRotatef( 180, 0, 1.0, 0.0 ); middle_left_leg->onDisplay(); glTranslatef( 0, 0, -2.5 ); rear_left_leg->onDisplay(); glRotatef( 180, 0, 1.0, 0.0 ); rear_right_leg->onDisplay(); glScalef(-scale, -scale, 1); glPopMatrix(); }
void Bullet::display() { GLfloat x = position.x; GLfloat y = position.y; GLfloat z = position.z; glPushMatrix(); glColor3d(color.r, color.g, color.b); glBegin(GL_LINES); glVertex3f(x - width / 2, y - height / 2, z - depth); glVertex3f(x - width / 2, y + height / 2, z - depth); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y + height / 2, z - depth); glVertex3f(x + width / 2, y - height / 2, z - depth); glEnd(); glBegin(GL_LINES); glVertex3f(x - width / 2, y - height / 2, z - depth); glVertex3f(x - width / 2, y - height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x - width / 2, y + height / 2, z - depth); glVertex3f(x - width / 2, y + height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y + height / 2, z - depth); glVertex3f(x + width / 2, y + height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y - height / 2, z - depth); glVertex3f(x + width / 2, y - height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x - width / 2, y - height / 2, z); glVertex3f(x - width / 2, y + height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y + height / 2, z); glVertex3f(x + width / 2, y - height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y + height / 2, z); glVertex3f(x - width / 2, y + height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y - height / 2, z); glVertex3f(x - width / 2, y - height / 2, z); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y + height / 2, z - depth); glVertex3f(x - width / 2, y + height / 2, z - depth); glEnd(); glBegin(GL_LINES); glVertex3f(x + width / 2, y - height / 2, z - depth); glVertex3f(x - width / 2, y - height / 2, z - depth); glEnd(); glPopMatrix(); }
//----- paintGL ---------------------------------------------- void QGLWidgetTest::paintGL() { GInt32 i, j, k, w, ofs; GPoint<GDouble, 2> a, b, c; GPoint2 p1, p2; GPoint<GDouble, 3> col1(1.0f, 0.74f, 0.2f); GPoint<GDouble, 3> col2(0.4f, 0.1f, 0.6f); GPoint<GDouble, 3> col; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setLightAndTransform(); glDisable(GL_LINE_SMOOTH); glLineWidth(1.0f); if (gFillDraw) { k = gTriangles.size() / 3; glBegin(GL_TRIANGLES); for (i = 0; i < k; i++) { a = gTriangles[i * 3]; b = gTriangles[i * 3 + 1]; c = gTriangles[i * 3 + 2]; col = GMath::Lerp(GMath::Clamp(a[G_Y], (GDouble)0, (GDouble)1), col1, col2); glColor3d(col[0], col[1], col[2]); glVertex3d(a[G_X], a[G_Y], 1.0f); col = GMath::Lerp(GMath::Clamp(b[G_Y], (GDouble)0, (GDouble)1), col1, col2); glColor3d(col[0], col[1], col[2]); glVertex3d(b[G_X], b[G_Y], 1.0f); col = GMath::Lerp(GMath::Clamp(c[G_Y], (GDouble)0, (GDouble)1), col1, col2); glColor3d(col[0], col[1], col[2]); glVertex3d(c[G_X], c[G_Y], 1.0f); } glEnd(); if (!gWireFrame) return; glLineWidth(1.0f); glBegin(GL_LINES); glColor3f(1.0f, 1.0f, 1.0f); for (i = 0; i < k; i++) { a = gTriangles[i * 3]; b = gTriangles[i * 3 + 1]; c = gTriangles[i * 3 + 2]; glVertex3d(a[G_X], a[G_Y], 1.0f); glVertex3d(b[G_X], b[G_Y], 1.0f); glVertex3d(a[G_X], a[G_Y], 1.0f); glVertex3d(c[G_X], c[G_Y], 1.0f); glVertex3d(b[G_X], b[G_Y], 1.0f); glVertex3d(c[G_X], c[G_Y], 1.0f); } glEnd(); } else { glBegin(GL_LINES); glColor3f(1.0f, 1.0f, 1.0f); j = gIndex.size(); ofs = 0; for (i = 0; i < j; i++) { k = gIndex[i]; for (w = 0; w < k - 1; w++) { p1 = gVertices[ofs + w]; p2 = gVertices[ofs + w + 1]; glVertex3f(p1[G_X], p1[G_Y], 1.0f); glVertex3f(p2[G_X], p2[G_Y], 1.0f); } p1 = gVertices[ofs + k - 1]; p2 = gVertices[ofs]; glVertex3f(p1[G_X], p1[G_Y], 1.0f); glVertex3f(p2[G_X], p2[G_Y], 1.0f); ofs += k; } glEnd(); } glFlush(); }
void Bar::draw(Qwt3D::Triple const& pos) { Qwt3D::GLStateBewarer sb(GL_LINE_SMOOTH, true); sb.turnOn(); //an option to add further labels // if ((pos.x == mShowColumn) || (pos.y == mShowRow)) // { // Label3D lb; // lb.draw(pos, diag_, diag_ * 2); //} // set the zero level GLdouble minz = 0; //plot->hull().minVertex.z; Qwt3D::RGBA mTo = (*plot->dataColor())(pos); Qwt3D::RGBA mFrom = (*plot->dataColor())(pos.x, pos.y, minz); glBegin(GL_QUADS); if (((int)(100*pos.x) == (int)(100*mShowColumn)) || ((int)(100*pos.y) == (int)(100*mShowRow))) glColor3d(0.71, 0.835, 1); //(1, 0, 0); else glColor4d(mTo.r, mTo.g, mTo.b, mTo.a); //glColor4d(mFrom.r, mFrom.g, mFrom.b, mFrom.a); glVertex3d(pos.x - diag_, pos.y - diag_, minz); glVertex3d(pos.x + diag_, pos.y - diag_, minz); glVertex3d(pos.x + diag_, pos.y + diag_, minz); glVertex3d(pos.x - diag_, pos.y + diag_, minz); if (((int)(100*pos.x) == (int)(100*mShowColumn)) || ((int)(100*pos.y) == (int)(100*mShowRow))) glColor3d(0.71, 0.835, 1); //(1, 0, 0); else glColor4d(mTo.r, mTo.g, mTo.b, mTo.a); glVertex3d(pos.x - diag_, pos.y - diag_, pos.z); glVertex3d(pos.x + diag_, pos.y - diag_, pos.z); glVertex3d(pos.x + diag_, pos.y + diag_, pos.z); glVertex3d(pos.x - diag_, pos.y + diag_, pos.z); glColor4d(mFrom.r, mFrom.g, mFrom.b, mFrom.a); glVertex3d(pos.x - diag_, pos.y - diag_, minz); glVertex3d(pos.x + diag_, pos.y - diag_, minz); glColor4d(mTo.r, mTo.g, mTo.b, mTo.a); glVertex3d(pos.x + diag_, pos.y - diag_, pos.z); glVertex3d(pos.x - diag_, pos.y - diag_, pos.z); glColor4d(mFrom.r, mFrom.g, mFrom.b, mFrom.a); glVertex3d(pos.x - diag_, pos.y + diag_, minz); glVertex3d(pos.x + diag_, pos.y + diag_, minz); glColor4d(mTo.r, mTo.g, mTo.b, mTo.a); glVertex3d(pos.x + diag_, pos.y + diag_, pos.z); glVertex3d(pos.x - diag_, pos.y + diag_, pos.z); glColor4d(mFrom.r, mFrom.g, mFrom.b, mFrom.a); glVertex3d(pos.x - diag_, pos.y - diag_, minz); glVertex3d(pos.x - diag_, pos.y + diag_, minz); glColor4d(mTo.r, mTo.g, mTo.b, mTo.a); glVertex3d(pos.x - diag_, pos.y + diag_, pos.z); glVertex3d(pos.x - diag_, pos.y - diag_, pos.z); glColor4d(mFrom.r, mFrom.g, mFrom.b, mFrom.a); glVertex3d(pos.x + diag_, pos.y - diag_, minz); glVertex3d(pos.x + diag_, pos.y + diag_, minz); glColor4d(mTo.r, mTo.g, mTo.b, mTo.a); glVertex3d(pos.x + diag_, pos.y + diag_, pos.z); glVertex3d(pos.x + diag_, pos.y - diag_, pos.z); glEnd(); glColor3d(0, 0, 0); glBegin(GL_LINES); glVertex3d(pos.x - diag_, pos.y - diag_, minz); glVertex3d(pos.x + diag_, pos.y - diag_, minz); glVertex3d(pos.x - diag_, pos.y - diag_, pos.z); glVertex3d(pos.x + diag_, pos.y - diag_, pos.z); glVertex3d(pos.x - diag_, pos.y + diag_, pos.z); glVertex3d(pos.x + diag_, pos.y + diag_, pos.z); glVertex3d(pos.x - diag_, pos.y + diag_, minz); glVertex3d(pos.x + diag_, pos.y + diag_, minz); glVertex3d(pos.x - diag_, pos.y - diag_, minz); glVertex3d(pos.x - diag_, pos.y + diag_, minz); glVertex3d(pos.x + diag_, pos.y - diag_, minz); glVertex3d(pos.x + diag_, pos.y + diag_, minz); glVertex3d(pos.x + diag_, pos.y - diag_, pos.z); glVertex3d(pos.x + diag_, pos.y + diag_, pos.z); glVertex3d(pos.x - diag_, pos.y - diag_, pos.z); glVertex3d(pos.x - diag_, pos.y + diag_, pos.z); glVertex3d(pos.x - diag_, pos.y - diag_, minz); glVertex3d(pos.x - diag_, pos.y - diag_, pos.z); glVertex3d(pos.x + diag_, pos.y - diag_, minz); glVertex3d(pos.x + diag_, pos.y - diag_, pos.z); glVertex3d(pos.x + diag_, pos.y + diag_, minz); glVertex3d(pos.x + diag_, pos.y + diag_, pos.z); glVertex3d(pos.x - diag_, pos.y + diag_, minz); glVertex3d(pos.x - diag_, pos.y + diag_, pos.z); glEnd(); }
void GUILane::drawGL(const GUIVisualizationSettings& s) const { glPushMatrix(); const bool isInternal = myEdge->getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL; bool mustDrawMarkings = false; const bool drawDetails = s.scale * s.laneWidthExaggeration > 5; if (isInternal) { // draw internal lanes on top of junctions glTranslated(0, 0, GLO_JUNCTION + 0.1); } else { glTranslated(0, 0, getType()); } // set lane color if (!MSGlobals::gUseMesoSim) { setColor(s); glPushName(getGlID()); // do not register for clicks in MESOSIM } // draw lane // check whether it is not too small if (s.scale * s.laneWidthExaggeration < 1.) { GLHelper::drawLine(myShape); if (!MSGlobals::gUseMesoSim) { glPopName(); } glPopMatrix(); } else { if (isRailway(myPermissions)) { // draw as railway const SUMOReal halfRailWidth = 0.725 * s.laneWidthExaggeration; GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, halfRailWidth); glColor3d(1, 1, 1); glTranslated(0, 0, .1); GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, halfRailWidth - 0.2); drawCrossties(s, s.laneWidthExaggeration); } else { const SUMOReal laneWidth = isInternal ? myQuarterLaneWidth : myHalfLaneWidth; mustDrawMarkings = !isInternal; GLHelper::drawBoxLines(myShape, myShapeRotations, myShapeLengths, laneWidth * s.laneWidthExaggeration); } if (!MSGlobals::gUseMesoSim) { glPopName(); } glPopMatrix(); // draw ROWs (not for inner lanes) if (!isInternal && drawDetails) { glPushMatrix(); glTranslated(0, 0, GLO_JUNCTION); // must draw on top of junction shape GUINet* net = (GUINet*) MSNet::getInstance(); glTranslated(0, 0, .2); drawLinkRules(*net); if (s.showLinkDecals && !isRailway(myPermissions)) { drawArrows(); } if (s.showLane2Lane) { // this should be independent to the geometry: // draw from end of first to the begin of second drawLane2LaneConnections(); } glTranslated(0, 0, .1); if (s.drawLinkJunctionIndex) { drawLinkNo(); } if (s.drawLinkTLIndex) { drawTLSLinkNo(*net); } glPopMatrix(); } } if (mustDrawMarkings && drawDetails) { // needs matrix reset drawMarkings(s, s.laneWidthExaggeration); } // draw vehicles if (s.scale > s.minVehicleSize) { // retrieve vehicles from lane; disallow simulation const MSLane::VehCont& vehicles = getVehiclesSecure(); for (MSLane::VehCont::const_iterator v = vehicles.begin(); v != vehicles.end(); ++v) { if ((*v)->getLane() == this) { static_cast<const GUIVehicle* const>(*v)->drawGL(s); } // else: this is the shadow during a continuous lane change } // draw parking vehicles const std::set<const MSVehicle*> parking = MSVehicleTransfer::getInstance()->getParkingVehicles(this); for (std::set<const MSVehicle*>::const_iterator v = parking.begin(); v != parking.end(); ++v) { static_cast<const GUIVehicle* const>(*v)->drawGL(s); } // allow lane simulation releaseVehicles(); } }
void PerlinFace::render() { glPushMatrix(); update(); // Jump to head position, orientation and scale glm::quat orientation = _owningHead->getOrientation(); glm::vec3 axis = glm::axis(orientation); glTranslatef(_owningHead->getPosition().x, _owningHead->getPosition().y, _owningHead->getPosition().z); glScalef(_owningHead->getScale(), _owningHead->getScale(), _owningHead->getScale()); glRotatef(glm::angle(orientation), axis.x, axis.y, axis.z); glPushMatrix(); { // This block use the coordinates system of perlin's face points. // Correct head scale and offset from hard coded points coordinates. glScalef(2.0f * BODY_BALL_RADIUS_HEAD_BASE / (_vertices[HAIR_2].y - _vertices[JAW_BOTTOM].y), 2.0f * BODY_BALL_RADIUS_HEAD_BASE / (_vertices[HAIR_2].y - _vertices[JAW_BOTTOM].y), 2.0f * BODY_BALL_RADIUS_HEAD_BASE / (_vertices[HAIR_2].y - _vertices[JAW_BOTTOM].y)); glTranslatef(0, -60.0f, 20.0f); /**/ glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, _vboID); glVertexPointer(FLOAT_PER_VERTEX, GL_FLOAT, 0, 0); glEnableClientState(GL_NORMAL_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, _nboID); glNormalPointer(GL_FLOAT, 0, 0); glEnableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, _cboID); glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0); glDrawArrays(GL_TRIANGLES, 0, VERTEX_PER_TRIANGLE * _trianglesCount); // Draw eyes glColor3d(0, 0, 0); glBegin(GL_LINE_LOOP); glVertex3d(_vertices[EYE_LEFT].x, _vertices[EYE_LEFT].y, _vertices[EYE_LEFT].z); glVertex3d(_vertices[EYE_MID_TOP].x, _vertices[EYE_MID_TOP].y, _vertices[EYE_MID_TOP].z); glVertex3d(_vertices[EYE_RIGHT].x, _vertices[EYE_RIGHT].y, _vertices[EYE_RIGHT].z); glVertex3d(_vertices[EYE_MID_BOTTOM].x, _vertices[EYE_MID_BOTTOM].y, _vertices[EYE_MID_BOTTOM].z); glEnd(); glBegin(GL_LINE_LOOP); glVertex3d(_vertices[NUM_VERTICES + EYE_LEFT].x, _vertices[NUM_VERTICES + EYE_LEFT].y, _vertices[NUM_VERTICES + EYE_LEFT].z); glVertex3d(_vertices[NUM_VERTICES + EYE_MID_TOP].x, _vertices[NUM_VERTICES + EYE_MID_TOP].y, _vertices[NUM_VERTICES + EYE_MID_TOP].z); glVertex3d(_vertices[NUM_VERTICES + EYE_RIGHT].x, _vertices[NUM_VERTICES + EYE_RIGHT].y, _vertices[NUM_VERTICES + EYE_RIGHT].z); glVertex3d(_vertices[NUM_VERTICES + EYE_MID_BOTTOM].x, _vertices[NUM_VERTICES + EYE_MID_BOTTOM].y, _vertices[NUM_VERTICES + EYE_MID_BOTTOM].z); glEnd(); } glPopMatrix(); const float EYEBALL_RADIUS = 0.008f; const float EYEBALL_COLOR[4] = { 0.9f, 0.9f, 0.8f, 1.0f }; const float IRIS_RADIUS = 0.0035; const float IRIS_PROTRUSION = 0.0065f; // render white ball of left eyeball glm::vec3 eyePos = glm::vec3(0.024f, 0.0f, -0.032f); Head::_irisProgram.bind(); _owningHead->_dilatedIrisTexture = Head::_irisTexture->getDilatedTexture(_owningHead->_pupilDilation); glBindTexture(GL_TEXTURE_2D, _owningHead->_dilatedIrisTexture->getID()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glEnable(GL_TEXTURE_2D); orientation = _owningHead->getOrientation(); glm::vec3 front = orientation * IDENTITY_FRONT; // render left iris glm::quat leftIrisRotation; glPushMatrix(); { glTranslatef(eyePos.x, eyePos.y, eyePos.z); //translate to eyeball position //rotate the eyeball to aim towards the lookat position glm::vec3 targetLookatVector = _owningHead->_lookAtPosition - eyePos; leftIrisRotation = rotationBetween(front, targetLookatVector) * orientation; glm::vec3 rotationAxis = glm::axis(leftIrisRotation); glRotatef(glm::angle(leftIrisRotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glTranslatef(0.0f, 0.0f, IRIS_PROTRUSION); glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris // this ugliness is simply to invert the model transform and get the eye position in model space Head::_irisProgram.setUniform(Head::_eyePositionLocation, (glm::inverse(leftIrisRotation) * (Application::getInstance()->getCamera()->getPosition() - eyePos) + glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f), 1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS)); glutSolidSphere(0.5f, 15, 15); } glPopMatrix(); eyePos.x = - eyePos.x; // render right iris glm::quat rightIrisRotation; glPushMatrix(); { glTranslatef(eyePos.x, eyePos.y, eyePos.z); //translate to eyeball position //rotate the eyeball to aim towards the lookat position glm::vec3 targetLookatVector = _owningHead->_lookAtPosition - eyePos; rightIrisRotation = rotationBetween(front, targetLookatVector) * orientation; glm::vec3 rotationAxis = glm::axis(rightIrisRotation); glRotatef(glm::angle(rightIrisRotation), rotationAxis.x, rotationAxis.y, rotationAxis.z); glTranslatef(0.0f, 0.0f, IRIS_PROTRUSION); glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris // this ugliness is simply to invert the model transform and get the eye position in model space Head::_irisProgram.setUniform(Head::_eyePositionLocation, (glm::inverse(rightIrisRotation) * (Application::getInstance()->getCamera()->getPosition() - eyePos) + glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f), 1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS)); glutSolidSphere(0.5f, 15, 15); } glPopMatrix(); Head::_irisProgram.release(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); glPushMatrix(); glColor4fv(EYEBALL_COLOR); glTranslatef(eyePos.x, eyePos.y, eyePos.z); glutSolidSphere(EYEBALL_RADIUS, 30, 30); glPopMatrix(); //render white ball of right eyeball glPushMatrix(); glColor4fv(EYEBALL_COLOR); glTranslatef(-eyePos.x, eyePos.y, eyePos.z); glutSolidSphere(EYEBALL_RADIUS, 30, 30); glPopMatrix(); glPopMatrix(); }
void tree_Node_::draw_tree() { glPushMatrix(); draw(); glPushName(structID); double top = f_line() - 1.0 ; double bottom = l_line(); double midpoint = 0.5 * (top + bottom); if ( subNodes.size() > 1 ) { // glBegin(GL_LINE_STRIP); // glVertex2d( 0, top ); // glVertex2d(-1, top ); // glVertex2d(-0.8, midpoint ); // glVertex2d( 0, bottom ); // glEnd(); glBegin(GL_QUADS); glVertex2d(-1.0, top ); glVertex2d( 0.0, top ); glVertex2d( 0.0, bottom ); glVertex2d(-1.0, bottom ); glEnd(); glPushName ( boxID ); glPushMatrix(); glTranslated(-1, top , 0 ); glScaled ( 0.3, 0.3, 1 ); glBegin(GL_QUADS); glColor3d ( 1.0 , 0.0 , 0.0 ); if ( open ) glColor3d ( 0.0 , 1.0, 0.0 ); glVertex2d ( 1.0 , 1.0 ); glVertex2d ( -1.0 , 1.0 ); glVertex2d ( -1.0 , -1.0 ); glVertex2d ( 1.0 , -1.0 ); glEnd(); glPopMatrix(); glPopName(); glTranslated ( 1.0, 0.0, 0.0 ); } else if ( open && subNodes.size() == 1 ) { if ( subNodes[0]->firstline != firstline || subNodes[0]->lastline != lastline ) { //glBegin(GL_LINE_STRIP); //glVertex2d( 0, top ); //glVertex2d(-1, top); //glVertex2d( 0, bottom ); //glEnd(); glBegin(GL_QUADS); glVertex2d(-1.0, top ); glVertex2d( 0.0, subNodes[0]->f_line() - 1.0 ); glVertex2d( 0.0, subNodes[0]->l_line()); glVertex2d(-1.0, bottom ); glEnd(); glTranslated ( 1.0, 0.0, 0.0 ); } } if ( open ) { for ( int i = 0 ; i < (int)subNodes.size(); i++ ) { switch ( i % 3 ) { case 0 : glColor4d ( 1,0,0,0.2 ); break; case 1 : glColor4d ( 0,1,0,0.2 ); break; case 2 : glColor4d ( 0,0,1,0.2 ); break; } if ( subNodes[i] ) { // glBegin(GL_LINES); // glVertex2d(-1.0, top); // glVertex2d(0.0, subNodes[i]->f_line() - 1.0); // glEnd(); subNodes[i]->draw_tree(); } } } glPopName(); glPopMatrix(); }
//////////////////////////////////////////////////////////// /// Entry point of application //////////////////////////////////////////////////////////// int main() { // Create the main window sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML OpenGL"); // Create a clock for measuring time elapsed sf::Clock Clock; //prepare OpenGL surface for HSR glClearDepth(1.f); glClearColor(0.3f, 0.3f, 0.3f, 0.f); //background colour glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); //// Setup a perspective projection & Camera position glMatrixMode(GL_PROJECTION); glLoadIdentity(); //set up a 3D Perspective View volume //gluPerspective(90.f, 1.f, 1.f, 300.0f);//fov, aspect, zNear, zFar //set up a orthographic projection same size as window //this mease the vertex coordinates are in pixel space glOrtho(0,800,0,600,0,1); // use pixel coordinates // Start game loop while (App.isOpen()) { // Process events sf::Event Event; while (App.pollEvent(Event)) { // Close window : exit if (Event.type == sf::Event::Closed) App.close(); // Escape key : exit if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape)) App.close(); } //Prepare for drawing // Clear color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Apply some transformations glMatrixMode(GL_MODELVIEW); glLoadIdentity(); double angle=Clock.getElapsedTime().asMilliseconds(); glTranslated(+400,+300,0); //shift to original position glRotated(angle/10, 0, 0, 1); // rotate glTranslated(-400,-300,0);// shift centre to origin glBegin(GL_TRIANGLES);//draw a Triangle glColor3d(0,1,1);//cyan glVertex2d(100,100); glColor3d(1,1,0);//yellow glVertex2d(550,50); glColor3d(1,0,1);//magenta glVertex2d(700,500); glEnd(); // Finally, display rendered frame on screen App.display(); } return EXIT_SUCCESS; }
void Q3DGraph::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if(keyspressed & KEYDOWN) graus[0]+=3.f; if(keyspressed & KEYUP) graus[0]-=3.f; if(keyspressed & KEYAVPAG) graus[1]+=3.f; if(keyspressed & KEYREPAG) graus[1]-=3.f; if(keyspressed & KEYLEFT) graus[2]+=3.f; if(keyspressed & KEYRIGHT) graus[2]-=3.f; if(keyspressed & KEYW) z/=1.1f; if(keyspressed & KEYS) z= z!=0. ? z*1.1f : .1f; if(keyspressed & KEYQ) { zoom/=2.0f; crea(); } if(keyspressed & KEYE) { zoom*=2.0f; crea(); } graus[0] = graus[0]>=360.f ? graus[0]-360.f : graus[0]; graus[1] = graus[1]>=360.f ? graus[1]-360.f : graus[1]; graus[2] = graus[2]>=360.f ? graus[2]-360.f : graus[2]; glTranslatef(0.0f, 0.0f, z); glRotatef(graus[0], 1.0, 0.0, 0.0); glRotatef(graus[1], 0.0, 1.0, 0.0); glRotatef(graus[2], 0.0, 0.0, 2.0); double mida=default_size*zoom, step=default_step*zoom; dibuixa_eixos(); int i,j; if(method == G_POINTS || method == G_LINES) { if(method == G_POINTS){ glBegin(GL_POINTS); } else if(method == G_LINES){ glBegin(GL_LINES); } for(i=0; tefunc && i<(2*mida/step)-1; i++) { for(j=0; tefunc && j<2*mida/step-1; j++) { if(method == G_POINTS){ glColor3d( i*step/mida, j*step/mida, punts[i][j]/5); glVertex3d( i*step-mida, j*step - mida, punts[i][j]); } else { if(method == G_LINES) glColor3d( i*step/mida, j*step/mida, punts[i][j]/5); else glColor3d( 0.0,0.0,0.0); glVertex3d( i*step-mida, j*step - mida, punts[i][j]); glVertex3d( (i?i-1:i)*step-mida, j*step - mida, punts[i?i-1:i][j]); glVertex3d( i*step-mida, j*step - mida, punts[i][j]); glVertex3d( i*step-mida, (j?j-1:j)*step - mida, punts[i][j?j-1:j]); } } } glEnd(); } else if(method == G_SOLID){ if(trans){ glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA,GL_ONE); }else{ glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } double trans=0.8; glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); for(i=0; tefunc && i<(2*mida/step)-2; i++) { for(j=0; tefunc && j<2*mida/step-2; j++) { if(abs(punts[i][j]-punts[i][j+1])>700000. || abs(punts[i][j]-punts[i+1][j])>700000.){ // qDebug("assimptota %f %f", punts[i][j], punts[i][j+1]); } else { if(punts[i][j]>300.) qDebug("%f %f %f %f", punts[i][j], punts[i+1][j], punts[i][j+1], punts[i+1][j+1]); glTexCoord2f(0.0f, 1.0f); glColor4d( i*step/mida/2, (j+1)*step/mida/2, punts[i][j+1]/5, trans); glVertex3d( i*step-mida, (j+1)*step - mida, punts[i][j+1]); glTexCoord2f(0.0f, 0.0f); glColor4d( i*step/mida/2, j*step/mida/2, punts[i][j]/5, trans); glVertex3d( i*step-mida, j*step - mida, punts[i][j]); glTexCoord2f(1.0f, 0.0f); glColor4d((i+1)*step/mida/2, j*step/mida/2, punts[i+1][j]/5, trans); glVertex3d( (i+1)*step-mida, j*step - mida, punts[i+1][j]); glTexCoord2f(1.0f, 1.0f); glColor4d((i+1)*step/mida/2, (j+1)*step/mida/2, punts[i+1][j+1]/5,trans); glVertex3d( (i+1)*step-mida, (j+1)*step - mida, punts[i+1][j+1]); } } } glEnd(); glDisable(GL_TEXTURE_2D); } glFlush(); }
void render(particle &ptc){ //if (!Frustum::aabbInFrustum(ptc.hb)) return ptcsrendered++; float size = (float)BLOCKTEXTURE_UNITSIZE / BLOCKTEXTURE_SIZE * ptc.psize; float col = world::getbrightness(RoundInt(ptc.xpos), RoundInt(ptc.ypos), RoundInt(ptc.zpos)) / (float)world::BRIGHTNESSMAX; float col1 = col * 0.5f; float col2 = col * 0.7f; float tcx = ptc.tcX; float tcy = ptc.tcY; float psize = ptc.psize; double xpos = ptc.xpos - player::xpos; double ypos = ptc.ypos - player::ypos - player::height - player::heightExt; double zpos = ptc.zpos - player::zpos; glColor3d(col1, col1, col1); glTexCoord2d(tcx + size * 0.0, tcy + size * 0.0); glVertex3d(xpos - psize, ypos - psize, zpos + psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 0.0); glVertex3d(xpos + psize, ypos - psize, zpos + psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 1.0); glVertex3d(xpos + psize, ypos + psize, zpos + psize); glTexCoord2d(tcx + size * 0.0, tcy + size * 1.0); glVertex3d(xpos - psize, ypos + psize, zpos + psize); glColor3d(col1, col1, col1); glTexCoord2d(tcx + size * 0.0, tcy + size * 0.0); glVertex3d(xpos - psize, ypos + psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 0.0); glVertex3d(xpos + psize, ypos + psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 1.0); glVertex3d(xpos + psize, ypos - psize, zpos - psize); glTexCoord2d(tcx + size * 0.0, tcy + size * 1.0); glVertex3d(xpos - psize, ypos - psize, zpos - psize); glColor3d(col, col, col); glTexCoord2d(tcx + size * 0.0, tcy + size * 0.0); glVertex3d(xpos + psize, ypos + psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 0.0); glVertex3d(xpos - psize, ypos + psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 1.0); glVertex3d(xpos - psize, ypos + psize, zpos + psize); glTexCoord2d(tcx + size * 0.0, tcy + size * 1.0); glVertex3d(xpos + psize, ypos + psize, zpos + psize); glColor3d(col, col, col); glTexCoord2d(tcx + size * 0.0, tcy + size * 0.0); glVertex3d(xpos - psize, ypos - psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 0.0); glVertex3d(xpos + psize, ypos - psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 1.0); glVertex3d(xpos + psize, ypos - psize, zpos + psize); glTexCoord2d(tcx + size * 0.0, tcy + size * 1.0); glVertex3d(xpos - psize, ypos - psize, zpos + psize); glColor3d(col2, col2, col2); glTexCoord2d(tcx + size * 0.0, tcy + size * 0.0); glVertex3d(xpos + psize, ypos + psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 0.0); glVertex3d(xpos + psize, ypos + psize, zpos + psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 1.0); glVertex3d(xpos + psize, ypos - psize, zpos + psize); glTexCoord2d(tcx + size * 0.0, tcy + size * 1.0); glVertex3d(xpos + psize, ypos - psize, zpos - psize); glColor3d(col2, col2, col2); glTexCoord2d(tcx + size * 0.0, tcy + size * 0.0); glVertex3d(xpos - psize, ypos - psize, zpos - psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 0.0); glVertex3d(xpos - psize, ypos - psize, zpos + psize); glTexCoord2d(tcx + size * 1.0, tcy + size * 1.0); glVertex3d(xpos - psize, ypos + psize, zpos + psize); glTexCoord2d(tcx + size * 0.0, tcy + size * 1.0); glVertex3d(xpos - psize, ypos + psize, zpos - psize); }
//applies the filter to a GL texture. // //saves opengl states, and binds this filter's output buffer (render to texture) //sets up ortho projection for drawing just the texture using teh filters shaders //parameters are set as uniforms for the shaders GLuint GPUImageFilter::apply(GLuint inputTexture, GLuint inputTexture2){ glPushAttrib(GL_VIEWPORT_BIT); glPushAttrib(GL_ENABLE_BIT); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMatrixMode(GL_PROJECTION); glPushMatrix(); //render to the fbo using the shader glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, output_buffer); glClearColor(0.0,1.0,0.0,1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0,0,res_x, res_y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1.0, -1, 1.0, -1, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, inputTexture); this->shader->enable(); //set the parameters for the filters for(std::map<std::string, FilterParameter*>::const_iterator it = parameters.begin(); it != parameters.end(); ++it){ const char* test = it->first.c_str(); float test2 = it->second->value; this->shader->setUniform1f(it->first.c_str(), it->second->value); } if (inputTexture2 !=0){ this->shader->setUniform1i("tex2", 1); } //use geometry shader threads to process image blocks if(useGeometryShader){ //send n number of threads int numThreads = (int) parameters["threads"]->value; glBegin(GL_POINTS); //glVertex2d(3,3); int i=0; for(i=0; i<numThreads; i++){ float x = (float)((i/numThreads ) / (float)numThreads -0.5f) * 2.0f; float y = (float)((i%numThreads ) / (float)numThreads -0.5f)* 2.0f; glVertex2d(x,y); } glEnd(); }else{ //draw full screen quad with input texture aplied glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, inputTexture); glActiveTexture(GL_TEXTURE1); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, inputTexture2); this->shader->enable(); glBegin(GL_QUADS); glColor3d(1.0, 0.0, 0.0); glTexCoord2f(0, 0); glVertex3f(-1, -1, 0); glTexCoord2f(1, 0); glVertex3f(1, -1, 0); glTexCoord2f(1, 1); glVertex3f(1, 1, 0); glTexCoord2f(0, 1); glVertex3f(-1, 1, 0); glEnd(); } this->shader->disable(); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); glPopAttrib(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //should maybe have a stack glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,0); return output_texture; };
/* * Render buttons for video control. */ int RenderMenu(MODEL *model, D_PARAM *disp){ /* Movie Menu */ glBegin(GL_LINE_LOOP); glVertex3d(0.0, 0.0, 0.0); glVertex3d(0.0, 80.0, 0.0); glVertex3d(200.0, 80.0, 0.0); glVertex3d(200.0, 0.0, 0.0); glEnd(); glBegin(GL_LINES); glVertex3d(0.0, 60.0, 0.0); glVertex3d(200.0, 60.0, 0.0); glVertex3d(0.0, 20.0, 0.0); glVertex3d(200.0, 20.0, 0.0); glVertex3d(70, 60, 0); glVertex3d(70, 20, 0); glVertex3d(130, 60, 0); glVertex3d(130, 20, 0); glVertex3d(20, 20, 0); glVertex3d(20, 0, 0); glVertex3d(180, 20, 0); glVertex3d(180, 0, 0); glEnd(); /* Character */ glBegin(GL_TRIANGLES); glVertex3d(155, 50, 0); glVertex3d(155, 30, 0); glVertex3d(175, 40, 0); glVertex3d(45, 50, 0); glVertex3d(45, 30, 0); glVertex3d(25, 40, 0); glVertex3d(15, 5, 0); glVertex3d(15, 15, 0); glVertex3d(5, 10, 0); glVertex3d(185, 5, 0); glVertex3d(185, 15, 0); glVertex3d(195, 10, 0); glEnd(); glBegin(GL_QUADS); glVertex3d(90, 50, 0); glVertex3d(90, 30, 0); glVertex3d(110, 30, 0); glVertex3d(110, 50, 0); glColor3d(0.3, 0.3, 0.3); glVertex3d(20, 0, -0.1); glVertex3d(20, 20, -0.1); glVertex3d(180, 20, -0.1); glVertex3d(180, 0, -0.1); glColor3d(1.0, 1.0, 1.0); glEnd(); glPushMatrix(); glTranslated((150 * (double)disp->curstep / (double)(model->CVS_step_num + model->Sp_step_num)) + 20, 0.0, 0.0); glBegin(GL_QUADS); glVertex3d(0, 20, 0); glVertex3d(0, 0, 0); glVertex3d(10, 0, 0); glVertex3d(10, 20, 0); glEnd(); glPopMatrix(); glRasterPos3d(77, 65, 0); glprint("bitmap", "MOVIE"); glColor3d(1.0, 1.0, 1.0); return 0; }
void display(void) { if (initialized == false) { myInit(); initialized = true; } #pragma mark blendMask 1/2: 1. Enable GL_DEPTH_TEST, 2. TRUE DEPTHMASK 3. DISABLE blend //glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LESS); // The Type Of Depth Test To Do glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); // Turn ON Writing To The Depth-Buffer glDisable(GL_BLEND); //------------------------------------------------------------material vriables //define the material of the object float no_mat[] = { 0.0, 0.0, 0.0, 1.0 }; float mat_white[] = { 1.0, 1.0, 1.0, 1.0 }; float mat_gray1[] = { 0.3, 0.3, 0.3, 1.0 }; float mat_gray2[] = { 0.5, 0.5, 0.5, 1.0 }; float mat_red[] = { 1.0, 0.2, 0.1, 1.0 }; float mat_orange[] = { 0.7, 0.5, 0.1, 1.0 }; float mat_yellow[] = { 0.8, 0.8, 0.1, 1.0 }; float mat_green[] = { 0.0, 1.0, 0.0, 1.0 }; float mat_blue[] = { 0.1, 0.1, 0.8, 1.0 }; float mat_purple[] = { 0.8, .1, 0.8, 1.0 }; float no_shininess[] = { 0.0 }; float low_shininess[] = { 5.0 }; float high_shininess[] = { 100.0 }; float mat_bright[] = {1.0, 0.7, 0.1, 1.0}; float no_mat_a[] = { 0.0, 0.0, 0.0, 0.5 }; float mat_white_a[] = { 1.0, 1.0, 1.0, 0.5 }; float mat_gray1_a[] = { 0.3, 0.3, 0.3, 0.5 }; float mat_gray2_a[] = { 0.5, 0.5, 0.5, 0.5 }; float mat_red_a[] = { 1.0, 0.2, 0.1, 0.5 }; float mat_orange_a[] = { 0.7, 0.5, 0.1, 0.5 }; float mat_yellow_a[] = { 0.8, 0.8, 0.1, 0.5 }; float mat_green_a[] = { 0.0, 1.0, 0.0, 0.5 }; float mat_blue_a[] = { 0.1, 0.1, 0.8, 0.5 }; float mat_purple_a[] = { 0.8, .1, 0.8, 0.5 }; float mat_more_a[] = { 0.8, .1, 0.8, 0.2 }; float mat_less_a[] = { 0.8, .1, 0.8, 0.8 }; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* glBegin( GL_QUADS ); glTexCoord2f(0, 0); glVertex3f(-.5, -.5, 0); glTexCoord2f(1, 0); glVertex3f(.5, -.5, 0); glTexCoord2f(1, 1); glVertex3f(.5, .5, 0); glTexCoord2f(0, 1); glVertex3f(-.5, .5, 0); glEnd(); */ #pragma mark - //------------------------------------------------------------Spot for Obj (white Torus) glTranslatef(0.0, 0.0, -10.0); //set origin of shape (5 units into the distance) glRotatef(rotX1, 0.0, 1.0, 0.0); // whole world rotation glPushMatrix(); glTranslatef(-0.5, 1.1, 2.0); //glRotatef(rotX1, 1.0, 0.0, 0.0); glTranslatef((sin(rotX1*0.1))*0.4, 0.0, 0.0); glRotatef(90., 1.0, 1.0, 0.0); glLightfv(GL_LIGHT3, GL_POSITION, pos); //spot light3 (Sun) glMaterialfv(GL_FRONT, GL_AMBIENT, mat_gray1); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_white); glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_white_a); glMaterialfv(GL_FRONT, GL_EMISSION, mat_gray2); glutSolidTorus(0.03, 0.1, 32, 32); glPopMatrix(); //------------------------------------------------------------Red Sphere glPushMatrix(); glTranslatef(2.3, 0.0, -2.0 + sin(rotX1*0.2)); glLightfv(GL_LIGHT2, GL_POSITION, pos); //spot light2 glRotatef(-rotX1, 1.0, 0.0, 0.0); // glutSolidTorus(0.3, 0.8, 32, 32); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_red); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glutSolidSphere(0.45, 10, 10); //glutSolidCube(.5); glPopMatrix(); glPushMatrix(); //glTranslatef(2.0, 0.0, -2.0); glTranslatef(2.3, 0.0, -2.0 + sin(rotX1*0.2)); glRotatef(-rotX1, .0, .0, 1.0); glTranslatef(.0, 1.0, .0); glRotatef(-rotX1, .0, 1.0, .0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_purple); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glutSolidCube(.2); glPopMatrix(); //------------------------------------------------------------Sun glPushMatrix(); // glTranslatef(-3.0, -3, -2.0); // glRotatef(rotX1, 1.0, 0.0, 0.0); glTranslatef(.0, 1, -2.0); glRotatef(rotX1, .0, 0.0, 1.0); glTranslatef(2.0, .1, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, pos); // sun light glMaterialfv(GL_FRONT, GL_AMBIENT, mat_red); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red); glMaterialfv(GL_FRONT, GL_EMISSION, mat_bright); glutSolidSphere(0.15, 10, 10); // Sun glPopMatrix(); //end matrix //printNormal(1.0, 0.0, 0.0, 0.0, 1.0, 0.0); //------------------------------------------------------------Land glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_green); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_blue); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_less_a); glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, no_mat); #pragma mark - #pragma mark texture //------------------------------------------------------------Tex Binding glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, tex ); float numz = 14.0; float numx = 8.0; for (int z = -numz; z <= numz; z ++){ glBegin(GL_QUAD_STRIP); for (int x = -numx; x <= numx; x ++){ vec3 p0; vec3 p1; vec3 p2; p0.x = x; p0.y = -2; p0.z = z; p1.x = x; p1.y = -2; p1.z = z + 1; p2.x = x + 1; p2.y = -2; p2.z = z; vec3 norm = calulateNormal(p0, p1, p2); glNormal3d(norm.x, norm.y, norm.z); float u, v; u = ((x) + numx) / (numx * 2.); v = ((z+1.) + numz) / (numz * 2.); glTexCoord2f(u, v); glVertex3d(x, sin(z+1) * (sin(3.3*x))-2, z+1); u = ((x) + numx) / (numx * 2.); v = ((z) + numz) / (numz * 2.); glTexCoord2f(u, v); glVertex3d(x, sin(z) * (sin(3.3*x))-2, z); } glEnd(); } glBindTexture( GL_TEXTURE_2D, 0 ); glDisable( GL_TEXTURE_2D ); //------------------------------------------------------------Tex UnBinding #pragma mark blendMask 2/2: 1. Enable blend, 2. Enable BlendFunc 3. False depth mask 4. material alpha value glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Blending Function For Translucency Based On Source Alpha Value ( NEW ) glDepthMask( GL_FALSE ); // Turn Off Writing To The Depth-Buffer //------------------------------------------------------------Obj glEnable( GL_TEXTURE_2D ); glBindTexture( GL_TEXTURE_2D, tex ); glPushMatrix(); glTranslatef(0.0, -0.5, 2.0); glRotatef(rotX1, 0.0, 1.0, 0.0); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_white); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_white); glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_more_a); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); displayFaces(); glPopMatrix(); glBindTexture( GL_TEXTURE_2D, 0 ); glDisable( GL_TEXTURE_2D ); //------------------------------------------------------------Blue Sphere glPushMatrix(); glTranslatef(-2.3, cos(rotX1*0.2), -2.0); glLightfv(GL_LIGHT1, GL_POSITION, pos); //spot light1 glRotatef(rotX1, 1.0, 0.0, 0.0); //glutSolidSphere(0.8, 10, 10); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_blue); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_orange); glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_green_a); glMaterialfv(GL_FRONT, GL_EMISSION, mat_blue); glutSolidSphere(0.45, 10, 10); //glutSolidCube(.5); glRotatef(rotX1, 1.0, 0.0, 0.0); glTranslatef(.0, 1.0, .0); //glutWireCube(.1); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_orange); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_green); glMaterialfv(GL_FRONT, GL_SHININESS, low_shininess); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_blue); glMaterialfv(GL_FRONT, GL_EMISSION, no_mat); glutSolidCube(.1); glPopMatrix(); rotX1 += 0.05; #pragma mark Morph gl Drawing 3/4 //------------------------------------------------------------Morphing Obj GLfloat tx,ty,tz; // Temp X, Y & Z Variables vec3 q; // Holds Returned Calculated Values For One VertexglBegin(GL_POINTS); // Begin Drawing Points printf("key %i morph %i, verts %i\n", key, morph, morph1.verts); //glPointSize(2.0); glLineWidth(2.0); glTranslatef(0., 2., 0); glBegin(GL_LINE_STRIP); // Begin Drawing Points for(int i=0;i<morph1.verts;i++) // Loop Through All The Verts Of morph1 (All Objects Have { // The Same Amount Of Verts For Simplicity, Could Use maxver Also) if(morph) { q=calculate(i); } else { q.x=q.y=q.z=0; // If morph Is True Calculate Movement Otherwise Movement=0 } helper.points[i].x-=q.x; // Subtract q.x Units From helper.points[i].x (Move On X Axis) helper.points[i].y-=q.y; // Subtract q.y Units From helper.points[i].y (Move On Y Axis) helper.points[i].z-=q.z; // Subtract q.z Units From helper.points[i].z (Move On Z Axis) tx=helper.points[i].x; // Make Temp X Variable Equal To Helper's X Variable ty=helper.points[i].y; // Make Temp Y Variable Equal To Helper's Y Variable tz=helper.points[i].z; // Make Temp Z Variable Equal To Helper's Z VariableglColor3f(0,1,1); // Set Color To A Bright Shade Of Off Blue glVertex3f(tx,ty,tz); // Draw A Point At The Current Temp Values (Vertex) glColor3d(1.0,0.5,1.0); // Darken Color A Bit tx-=2*q.x; ty-=2*q.y; ty-=2*q.y; // Calculate Two Positions Ahead glVertex3f(tx,ty,tz); // Draw A Second Point At The Newly Calculate Position glColor3f(0.,0.,1.); // Set Color To A Very Dark Blue tx-=2*q.x; ty-=2*q.y; ty-=2*q.y; // Calculate Two More Positions Ahead glVertex3f(tx,ty,tz); // Draw A Third Point At The Second New Position if (i == 100) printf("%f %f %f\n", tx, ty, tz); } // This Creates A Ghostly Tail As Points Move glEnd(); // Done Drawing Points if(morph && step<=steps)step++; else { morph=0; sour=dest; step=0;} glutSwapBuffers(); }
static int BoundsBehindViewerRun() { float mat[16]; IceTImage image; IceTInt rank; icetGetIntegerv(ICET_RANK, &rank); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); icetGLDrawCallback(draw); icetStrategy(ICET_STRATEGY_REDUCE); icetBoundingBoxd(-1.0, 1.0, -1.0, 1.0, -0.0, 0.0); icetSetColorFormat(ICET_IMAGE_COLOR_RGBA_UBYTE); icetSetDepthFormat(ICET_IMAGE_DEPTH_FLOAT); /* We're just going to use one tile. */ icetResetTiles(); icetAddTile(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); /* Set up the transformation such that the quad in draw should cover the entire screen, but part of it extends behind the viewpoint. Furthermore, a naive division by w will show all points to the right of the screen (which, of course, is wrong). */ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(0.0, 0.0, -1.5); glRotated(10.0, 0.0, 1.0, 0.0); glScaled(10.0, 10.0, 10.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 2.0); printstat("Modelview matrix:\n"); glGetFloatv(GL_MODELVIEW_MATRIX, mat); PrintMatrix(mat); printstat("Projection matrix:\n"); glGetFloatv(GL_PROJECTION_MATRIX, mat); PrintMatrix(mat); /* Other normal OpenGL setup. */ glEnable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glColor3d(1.0, 1.0, 1.0); /* All the processes have the same data. Go ahead and tell IceT. */ icetDataReplicationGroupColor(0); image = icetGLDrawFrame(); /* Test the resulting image to make sure the polygon was drawn over it. */ if (rank == 0) { IceTUInt *cb = icetImageGetColorui(image); if (cb[0] != 0xFFFFFFFF) { printstat("First pixel in color buffer wrong: 0x%x\n", cb[0]); return TEST_FAILED; } } return TEST_PASSED; }
void displayPoly(Solid *s) { /*Get Edges */ Vec<Edge *> *es=s->sedges; Vec<Face *> *fs=s->sfaces; if (!centered) { /*center of the polyhedron*/ Vec<double> *c=s->center(); /*center coordinates of the polyhedron*/ centerX=(*c)[0]; centerY=(*c)[1]; centerZ=(*c)[2]; centered=true; }//if we do not have a center //draw solid model if (drawSolid) { /*Let us add a light*/ glEnable(GL_LIGHTING); //offset of polygons so the wires are easier to see glEnable( GL_POLYGON_OFFSET_FILL ); glPolygonOffset( 2.0, 2.0 ); //default color. gray glColor3f(0.5,0.5,0.5); //loop through each face for (unsigned int i=0;i<fs->size();i++) { /*Now we get the face*/ Face *f=(*fs)[i]; /*Now we have the loops*/ Vec< Loop *> *ls=f->floops; //compute face normal { Loop * loop=(*ls)[0]; Vertex *v1=loop->ledg->start; Vertex *v2=loop->ledg->nxthe->start; Vertex *v3=loop->ledg->nxthe->nxthe->start; double p1[3]={v1->getX(),v1->getY(),v1->getZ()}, p2[3]={v2->getX(),v2->getY(),v2->getZ()}, p3[3]={v3->getX(),v3->getY(),v3->getZ()}; double vec1[3]={p2[0]-p1[0],p2[1]-p1[1],p2[2]-p1[2]}; double vec2[3]={p3[0]-p1[0],p3[1]-p1[1],p3[2]-p1[2]}; double * n=crossProduct(vec2,vec1); double d=n[0]*n[0]+n[1]*n[1]+n[2]*n[2]; if(d>0) { d=sqrt(d); glNormal3d(n[0]/d,n[1]/d,n[2]/d); //cout<<"n="<<n[0]/d<<","<<n[1]/d<<","<<n[2]/d<<endl; } delete [] n; } //draw face for (unsigned int j=0;j<ls->size();j++) { /*Leading HalfEdge*/ HalfEdge *lhe=(*ls)[j]->ledg; HalfEdge *the=lhe->prvhe; /*Start vertex*/ Vertex *v=lhe->start; //draw polygon glBegin(GL_POLYGON); glVertex3f(v->getX(),v->getY(),v->getZ()); while(the!=lhe){ v=the->start; glVertex3f(v->getX(),v->getY(),v->getZ()); the=the->prvhe; }//while glEnd(); }//for j }//for i //set things back glDisable( GL_POLYGON_OFFSET_FILL ); glDisable(GL_LIGHTING); }//end draw solid //Wire Solids if (drawWire) { glColor3d(0,0,1); glBegin(GL_LINES); for (unsigned int i=0;i<es->size();i++){ Edge *e=(*es)[i]; Vertex *v1=e->he1->start; Vertex *v2=e->he2->start; glVertex3f(v1->getX(),v1->getY(),v1->getZ()); glVertex3f(v2->getX(),v2->getY(),v2->getZ()); } glEnd(); }//wire }//displaypoly
void ROWdrawAction_drawLinkRules(const GUINet &net, const GUILaneWrapper &lane, bool showToolTips) { unsigned int noLinks = lane.getLinkNumber(); const Position2DVector &g = lane.getShape(); const Position2D &end = g.getEnd(); const Position2D &f = g[-2]; const Position2D &s = end; SUMOReal rot = (SUMOReal) atan2((s.x()-f.x()), (f.y()-s.y()))*(SUMOReal) 180.0/(SUMOReal) PI; if (noLinks==0) { if (showToolTips) { glPushName(lane.getGlID()); } // draw a grey bar if no links are on the street glColor3d(0.5, 0.5, 0.5); glPushMatrix(); glTranslated(end.x(), end.y(), 0); glRotated(rot, 0, 0, 1); glBegin(GL_QUADS); glVertex2d(-SUMO_const_halfLaneWidth, 0.0); glVertex2d(-SUMO_const_halfLaneWidth, 0.5); glVertex2d(SUMO_const_halfLaneWidth, 0.5); glVertex2d(SUMO_const_halfLaneWidth, 0.0); glEnd(); glPopMatrix(); if (showToolTips) { glPopName(); } return; } // draw all links SUMOReal w = SUMO_const_laneWidth / (SUMOReal) noLinks; SUMOReal x1 = 0; glPushMatrix(); glTranslated(end.x(), end.y(), 0); glRotated(rot, 0, 0, 1); for (unsigned int i=0; i<noLinks; ++i) { SUMOReal x2 = x1 + w; MSLink::LinkState state = lane.getLane().getLinkCont()[i]->getState(); if (showToolTips) { switch (state) { case MSLink::LINKSTATE_TL_GREEN_MAJOR: case MSLink::LINKSTATE_TL_GREEN_MINOR: case MSLink::LINKSTATE_TL_RED: case MSLink::LINKSTATE_TL_YELLOW_MAJOR: case MSLink::LINKSTATE_TL_YELLOW_MINOR: case MSLink::LINKSTATE_TL_OFF_BLINKING: glPushName(net.getLinkTLID(lane.getLane().getLinkCont()[i])); break; case MSLink::LINKSTATE_MAJOR: case MSLink::LINKSTATE_MINOR: case MSLink::LINKSTATE_EQUAL: case MSLink::LINKSTATE_TL_OFF_NOSIGNAL: default: glPushName(lane.getGlID()); break; } } switch (state) { case MSLink::LINKSTATE_TL_GREEN_MAJOR: case MSLink::LINKSTATE_TL_GREEN_MINOR: glColor3d(0, 1, 0); break; case MSLink::LINKSTATE_TL_RED: glColor3d(1, 0, 0); break; case MSLink::LINKSTATE_TL_YELLOW_MAJOR: case MSLink::LINKSTATE_TL_YELLOW_MINOR: glColor3d(1, 1, 0); break; case MSLink::LINKSTATE_TL_OFF_BLINKING: glColor3d(1, 1, 0); break; case MSLink::LINKSTATE_TL_OFF_NOSIGNAL: glColor3d(0, 1, 1); break; case MSLink::LINKSTATE_MAJOR: glColor3d(1, 1, 1); break; case MSLink::LINKSTATE_MINOR: glColor3d(.2, .2, .2); break; case MSLink::LINKSTATE_EQUAL: glColor3d(.5, .5, .5); break; case MSLink::LINKSTATE_DEADEND: glColor3d(0, 0, 0); break; } glBegin(GL_QUADS); glVertex2d(x1-SUMO_const_halfLaneWidth, 0.0); glVertex2d(x1-SUMO_const_halfLaneWidth, 0.5); glVertex2d(x2-SUMO_const_halfLaneWidth, 0.5); glVertex2d(x2-SUMO_const_halfLaneWidth,0.0); glEnd(); if (showToolTips) { glPopName(); } x1 = x2; x2 += w; } glPopMatrix(); }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); // 三角形要素or四角形要素の描画 glLineWidth(1.0f); if(data.form <=2 ) glBegin(GL_TRIANGLES); else glBegin(GL_QUADS); glColor3d(0.7,0.7,0.7); for(int i=0;i<data.elem.size();i++){ Element e = data.elem[i]; for(int j=0;j<data.vertexNum;j++) glVertex2d(e.p[j]->z,e.p[j]->r); } glEnd(); // 境界の描画 if(data.isDispBoundary){ glLineWidth(3.0f); glBegin(GL_LINES); glColor3d(1.0,0.0,0.0); for(int i=0;i<data.edge.size();i++){ Edge *e = data.edge[i]; if(typeid(*e) == typeid(Str)){ glVertex2d( e->p[0]->z, e->p[0]->r ); glVertex2d( e->p[1]->z, e->p[1]->r ); }else{ Cir *c = dynamic_cast<Cir*>(e); double dt = c->rad/9; for(double rad1 = 0;fabs(rad1) < fabs(c->rad) ; rad1+=dt){ double z1,r1,z2,r2; double rad2 = rad1 + dt; z1 = c->center.z + c->r*cos(c->baseRad-rad1); r1 = c->center.r + c->r*sin(c->baseRad-rad1); z2 = c->center.z + c->r*cos(c->baseRad-rad2); r2 = c->center.r + c->r*sin(c->baseRad-rad2); glVertex2d(z1,r1); glVertex2d(z2,r2); } } } glEnd(); } // 要素間の境界線の描画 glLineWidth(1.0f); glBegin(GL_LINES); glColor3d(0.4,0.4,0.4); for(int i=0;i<data.elem.size();i++){ Element e = data.elem[i]; for(int j=0;j<data.vertexNum;j++){ glVertex2d( e.p[j]->z , e.p[j]->r ); glVertex2d( e.p[(j+1)% data.vertexNum]->z , e.p[(j+1)% data.vertexNum]->r ); } } glEnd(); // ノード番号の出力 if(data.isDispNodenum){ glColor3d(0,0,0); for(int i=0;i<data.node.size();i++){ int num = data.node[i].id; //if(data.node[i].id > data.firstNodenum ) num += 3; drawNum(num,data.node[i].z,data.node[i].r); } } glFlush(); }
void MyWindow::draw() { int i; if (!valid()) { //Init viewport and projection initGL(); double w = this->w(), h = this->h(); glViewport(0, 0, (int)w, (int)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); double left = -.1; double bottom = -.1; double right = 1.1; double top = 1.1; if(w > 1 && h > 1) { if(w > h) { right = -0.1 + 1.2 * w / h; } if(h > w) { bottom = 1.1 - 1.2 * h / w; } } double scale = 1. / 1000.; left = -w * scale; right = w * scale; bottom = -h * scale; top = h * scale; glFrustum(left, right, bottom, top, 5., 30.); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //Transform------ Vector3 trans = transform.getTrans(); glTranslated(trans[0], trans[1], -10 + trans[2]); double scale = transform.getScale(); glScaled(scale, scale, scale); Quaternion<> r = transform.getRot(); double ang = r.getAngle(); if(fabs(ang) > 1e-6) { Vector3 ax = r.getAxis(); glRotated(ang * 180. / M_PI, ax[0], ax[1], ax[2]); } //Draw---------- if(floor) drawFloor(); vector<const Mesh *> ms(meshes.size()); for(i = 0; i < (int)meshes.size(); ++i) { ms[i] = &(meshes[i]->getMesh()); } //shadows if(floor) { Vector3 lightRay = transform.getRot().inverse() * Vector3(1, 2, 2); if(lightRay[1] == 0) lightRay[1] = 1e-5; lightRay = -lightRay / lightRay[1]; glDisable(GL_LIGHTING); glColor3f(0.1f, 0.1f, 0.1f); glPushMatrix(); float matr[16] = {1,0,0,0, (float)lightRay[0],0,(float)lightRay[2],0, 0,0,1,0, 0,0.01f,0,1}; glMultMatrixf(matr); glDepthMask(0); for(i = 0; i < (int)ms.size(); ++i) drawMesh(*(ms[i]), flatShading); glDepthMask(1); glEnable(GL_LIGHTING); glPopMatrix(); } static GLfloat colr[4] = {1.f, .9f, .75f, 1.0f }; static GLfloat colrb[4] = {1.f, .9f, .75f, 1.0f }; glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colr); glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, colrb); //draw meshes for(i = 0; i < (int)meshes.size(); ++i) { drawMesh(*(ms[i]), flatShading); } //draw lines glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); for(i = 0; i < (int)lines.size(); ++i) { glColor3d(lines[i].color[0], lines[i].color[1], lines[i].color[2]); glLineWidth((float)lines[i].thickness); glBegin(GL_LINES); glVertex3d(lines[i].p1[0], lines[i].p1[1], lines[i].p1[2]); glVertex3d(lines[i].p2[0], lines[i].p2[1], lines[i].p2[2]); glEnd(); } if(skeleton) { glLineWidth(5); for(i = 0; i < (int)meshes.size(); ++i) { vector<Vector3> v = meshes[i]->getSkel(); if(v.size() == 0) continue; glColor3d(.5, 0, 0); const vector<int> &prev = human.fPrev(); glBegin(GL_LINES); for(int j = 1; j < (int)prev.size(); ++j) { int k = prev[j]; glVertex3d(v[j][0], v[j][1], v[j][2]); glVertex3d(v[k][0], v[k][1], v[k][2]); } glEnd(); } } }
void KnotsViewer::draw_knots() { if(surfacedata==NULL||parameter2==NULL) return; else if(parameter2->getq()==0)//弹出窗口输入参数时没有输入完毕。 return; glColor3d(0.0, 0.0, 0.5); glLineWidth(0.5); int p=parameter2->getp(); int q=parameter2->getq(); int m=parameter2->getm(); int n=parameter2->getn(); int unum=parameter2->getnum_u(); int vnum=parameter2->getnum_v(); if (uknot.size()!=m+2-p||vknot.size()!=n+2-q) return; /*for (int j=q;j<n+1;j++) for (int i=p;i<m+1;i++) { glBegin(GL_LINE_LOOP); glVertex2d(uknot[i-p],vknot[j-q]); glVertex2d(uknot[i-p+1],vknot[j-q]); glVertex2d(uknot[i-p+1],vknot[j-q+1]); glVertex2d(uknot[i-p],vknot[j-q+1]); glEnd(); }*/ //绘制节点线 //先画u线 for (int i=0; i<unum; i++) { glBegin(GL_LINES); glVertex2d(uknot[i],0); glVertex2d(uknot[i],1); glEnd(); } //再画v线 for (int i=0; i<vnum; i++) { glBegin(GL_LINES); glVertex2d(0,vknot[i]); glVertex2d(1,vknot[i]); glEnd(); } //再绘制一遍新增加的线,使用红色 glColor3d(1.0, 0.0, 0.0); //先画u线 int n_u=surfacedata->uknots_new.size(); int n_v=surfacedata->vknots_new.size(); for (int i=0; i<n_u; i++) { glBegin(GL_LINES); glVertex2d(surfacedata->uknots_new[i].knot,0); glVertex2d(surfacedata->uknots_new[i].knot,1); glEnd(); } //再画v线 for (int i=0; i<n_v; i++) { glBegin(GL_LINES); glVertex2d(0,surfacedata->vknots_new[i].knot); glVertex2d(1,surfacedata->vknots_new[i].knot); glEnd(); } }