static void ArchFaceVault(float xValue, float resize) { glPushMatrix(); int i, numSlices; glTranslatef(xValue, 0, 0); glScalef(resize, 1, 1); double angle; double angInc; numSlices = 20; angle = 0; angInc = 3.14159/(2 * numSlices); for (i = 0; i < numSlices; i++) { glNormal3f(0,0,1); glColor3f(1,0,0); glBegin(GL_POLYGON); glVertex3f(1,0,1); // corner glVertex3f( cos(angle) , sin(angle)-1, 1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, 1); glEnd(); glBegin(GL_POLYGON); glVertex3f(-1,0,1); // corner glVertex3f(- cos(angle) , sin(angle)-1, 1); glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, 1); glEnd(); //--- glNormal3f(0,0,-1); glBegin(GL_POLYGON); glVertex3f(1,0,-1); // corner glVertex3f( cos(angle) , sin(angle)-1, -1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glBegin(GL_POLYGON); glVertex3f(-1,0,-1); // corner glVertex3f(- cos(angle) , sin(angle)-1, -1); glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); // vault glNormal3f(-cos(angle+angInc/2),-sin(angle+angInc/2),0); glColor3f(0,0,1); glBegin(GL_POLYGON); glVertex3f( cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( cos(angle) , sin(angle)-1, -1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glBegin(GL_POLYGON); glVertex3f( cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( cos(angle+angInc) , sin(angle+angInc)-1, 1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glNormal3f(cos(angle+angInc/2),-sin(angle+angInc/2),0); glBegin(GL_POLYGON); glVertex3f( - cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( -cos(angle) , sin(angle)-1, -1); glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glBegin(GL_POLYGON); glVertex3f( - cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( -cos(angle+angInc) , sin(angle+angInc)-1, 1); glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); angle += angInc; } glPopMatrix(); }
void Channel::_drawHelp() { const FrameData& frameData = _getFrameData(); std::string message = frameData.getMessage(); if( !frameData.showHelp() && message.empty( )) return; applyBuffer(); applyViewport(); setupAssemblyState(); glDisable( GL_LIGHTING ); glDisable( GL_DEPTH_TEST ); glColor3f( 1.f, 1.f, 1.f ); if( frameData.showHelp( )) { const eq::util::BitmapFont* font = getWindow()->getSmallFont(); std::string help = EVolve::getHelp(); float y = 340.f; for( size_t pos = help.find( '\n' ); pos != std::string::npos; pos = help.find( '\n' )) { glRasterPos3f( 10.f, y, 0.99f ); font->draw( help.substr( 0, pos )); help = help.substr( pos + 1 ); y -= 16.f; } // last line glRasterPos3f( 10.f, y, 0.99f ); font->draw( help ); } if( !message.empty( )) { const eq::util::BitmapFont* font = getWindow()->getMediumFont(); const eq::Viewport& vp = getViewport(); const eq::PixelViewport& pvp = getPixelViewport(); const float width = pvp.w / vp.w; const float xOffset = vp.x * width; const float height = pvp.h / vp.h; const float yOffset = vp.y * height; const float yMiddle = 0.5f * height; float y = yMiddle - yOffset; for( size_t pos = message.find( '\n' ); pos != std::string::npos; pos = message.find( '\n' )) { glRasterPos3f( 10.f - xOffset, y, 0.99f ); font->draw( message.substr( 0, pos )); message = message.substr( pos + 1 ); y -= 22.f; } // last line glRasterPos3f( 10.f - xOffset, y, 0.99f ); font->draw( message ); } EQ_GL_CALL( resetAssemblyState( )); }
void init_site() { list = glGenLists(NLIST); glNewList(list, GL_COMPILE); for (int v = 0; v< (NUM_PANELS_FLOOR*4);) { bool text = (v < 4); // unbind the texture //glDisable(GL_TEXTURE_2D); //doesn't work if (v == 4) { // make the sides of the pool the fog color glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fogColor); glColor3f ( fogColor[0], fogColor[1], fogColor[2]) ; } else if (text) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texName[0]); } glBegin(GL_QUADS); if (text) glTexCoord2f(0.0, 0.0); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; if (text) glTexCoord2f(1.0, 0.0); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; if (text) glTexCoord2f(1.0, 1.0); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; if (text) glTexCoord2f(0.0, 1.0); glVertex3f(vertices[v].x, vertices[v].y, vertices[v].z); v++; glEnd(); if (text) glDisable(GL_TEXTURE_2D); } glEndList(); glNewList(list+1, GL_COMPILE); // material reacts to light const float orange_boards[] = { 0.5f, 0.25f, 0.0f }; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, orange_boards); glColor3f (orange_boards[0], orange_boards[1], orange_boards[2]) ; for (int i = 0; i< NUM_BOARDS; i++) { glTranslatef(b_positions[i].x, b_positions[i].y, b_positions[i].z); glRotatef(b_rotations[i], 0.0, 1.0, 0.0); for (int v = 0; v< NUM_PANELS_BOARDS; v++) { glBegin(GL_QUADS); glNormal3f(0.0,1.0,0.0); //glTexCoord2f(0.0, 0.0); glVertex3f(boards[v].x, boards[v].y, boards[v].z); v++; glNormal3f(0.0,1.0,0.0); //glTexCoord2f(1.0, 0.0); glVertex3f(boards[v].x, boards[v].y, boards[v].z); v++; glNormal3f(0.0,1.0,0.0); //glTexCoord2f(1.0, 1.0); glVertex3f(boards[v].x, boards[v].y, boards[v].z); v++; glNormal3f(0.0,1.0,0.0); //glTexCoord2f(0.0, 1.0); glVertex3f(boards[v].x, boards[v].y, boards[v].z); glEnd(); } // undo rotation/translation glRotatef(-b_rotations[i], 0.0, 1.0, 0.0); glTranslatef(-b_positions[i].x, -b_positions[i].y, -b_positions[i].z); } glEndList(); glNewList(list+2, GL_COMPILE); for (int i = 0; i< NUM_BOXES; i++) { glTranslatef(bx_positions[i].x, bx_positions[i].y, bx_positions[i].z); glRotatef(bx_rotations[i], 0.0, 1.0, 0.0); for (int v = 0; v< NUM_PANELS_BOXES; v++) { int k = 4*v; if (v == 0) { float mcolor[] = { 1.f, 1.f, 1.f, 1.f }; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor); glColor3f ( mcolor[0], mcolor[1], mcolor[2]) ; } else if (v == (NUM_PANELS_BOXES-1)) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texName[4 + i]); float mcolor[] = { 0.f, 0., 0.f, 1.f }; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mcolor); glColor3f (mcolor[0], mcolor[1], mcolor[2]); } glBegin(GL_QUADS); if (v == (NUM_PANELS_BOXES-1)) { glNormal3f(0.0f,1.0f,0.0f); glTexCoord2f(0.0, 1.0); } glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z); k++; if (v == (NUM_PANELS_BOXES-1)) { glNormal3f(0.0f,1.0f,0.0f); glTexCoord2f(1.0, 1.0); } glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z); k++; if (v == (NUM_PANELS_BOXES-1)) { glNormal3f(0.0f,1.0f,0.0f); glTexCoord2f(1.0, 0.0); } glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z); k++; if (v == (NUM_PANELS_BOXES-1)) { glNormal3f(0.0f,1.0f,0.0f); glTexCoord2f(0.0, 0.0); } glVertex3f(boxes[k].x, boxes[k].y, boxes[k].z); glEnd(); if (v == (NUM_PANELS_BOXES-1)) glDisable(GL_TEXTURE_2D); } // undo rotation/translation glRotatef(-bx_rotations[i], 0.0, 1.0, 0.0); glTranslatef(-bx_positions[i].x, -bx_positions[i].y, -bx_positions[i].z); } glEndList(); glNewList(list+3, GL_COMPILE); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texName[1]); int v = 0; glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z); v++; glTexCoord2f(4.0, 0.0); glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z); v++; glTexCoord2f(4.0, 4.0); glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z); v++; glTexCoord2f(0.0, 4.0); glVertex3f(ceiling[v].x, ceiling[v].y, ceiling[v].z); v++; glEnd(); glDisable(GL_TEXTURE_2D); glEndList(); /***********************************************************/ g1 = gluNewQuadric(); g2 = gluNewQuadric(); g3 = gluNewQuadric(); for (int i=0; i<WINDOW_CUTOUT_PARTS; i++) window_cutout[i] = gluNewQuadric(); for (int i=0; i<GOALPOST_PARTS * 2; i++) goalpost[i] = gluNewQuadric(); for (int i=0; i<NUM_BUOYS * 2; i++) { buoys[i] = gluNewQuadric(); gluQuadricDrawStyle(buoys[i], GLU_FILL); } for (int i=0; i<2 * EXIT_SIDES; i++) { EXIT[i] = gluNewQuadric(); gluQuadricDrawStyle(EXIT[i], GLU_FILL); } gluQuadricDrawStyle(g1, GLU_FILL); gluQuadricDrawStyle(g2, GLU_FILL); gluQuadricDrawStyle(g3, GLU_FILL); }
/////////////////////////////////////////////////////////////////// // Draw the unit axis. A small white sphere represents the origin // and the three axes are colored Red, Green, and Blue, which // corresponds to positive X, Y, and Z respectively. Each axis has // an arrow on the end, and normals are provided should the axes // be lit. These are all built using the quadric shapes. For best // results, put this in a display list. void gltDrawUnitAxes(void) { GLUquadricObj *pObj; // Temporary, used for quadrics // Measurements float fAxisRadius = 0.025f; float fAxisHeight = 1.0f; float fArrowRadius = 0.06f; float fArrowHeight = 0.1f; // Setup the quadric object pObj = gluNewQuadric(); gluQuadricDrawStyle(pObj, GLU_FILL); gluQuadricNormals(pObj, GLU_SMOOTH); gluQuadricOrientation(pObj, GLU_OUTSIDE); gluQuadricTexture(pObj, GLU_FALSE); /////////////////////////////////////////////////////// // Draw the blue Z axis first, with arrowed head glColor3f(0.0f, 0.0f, 1.0f); gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1); glPushMatrix(); glTranslatef(0.0f, 0.0f, 1.0f); gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1); glRotatef(180.0f, 1.0f, 0.0f, 0.0f); gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1); glPopMatrix(); /////////////////////////////////////////////////////// // Draw the Red X axis 2nd, with arrowed head glColor3f(1.0f, 0.0f, 0.0f); glPushMatrix(); glRotatef(90.0f, 0.0f, 1.0f, 0.0f); gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1); glPushMatrix(); glTranslatef(0.0f, 0.0f, 1.0f); gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1); glPopMatrix(); glPopMatrix(); /////////////////////////////////////////////////////// // Draw the Green Y axis 3rd, with arrowed head glColor3f(0.0f, 1.0f, 0.0f); glPushMatrix(); glRotatef(-90.0f, 1.0f, 0.0f, 0.0f); gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1); glPushMatrix(); glTranslatef(0.0f, 0.0f, 1.0f); gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1); glRotatef(180.0f, 1.0f, 0.0f, 0.0f); gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1); glPopMatrix(); glPopMatrix(); //////////////////////////////////////////////////////// // White Sphere at origin glColor3f(1.0f, 1.0f, 1.0f); gluSphere(pObj, 0.05f, 15, 15); // Delete the quadric gluDeleteQuadric(pObj); }
void boardDraw() { //This method takes care of drawing our shapes in our window glClear( GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); drawBorder(); for(int i = 1; i < 21; i++) { for(int j = 1; j < 11; j++) { switch(board[i][j]) { case 1: //if a square block glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glBegin(GL_POLYGON); glColor3f(1, 1, 0); //color of our block glVertex3f(.35 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top left corner glVertex3f(.75 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top right corner glVertex3f(.75 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom right corner glVertex3f(.35 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom left corner glEnd(); break; case 2: // if a line block glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glBegin(GL_POLYGON); glColor3f(0, 1, 1); glVertex3f(.35 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top left corner glVertex3f(.75 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top right corner glVertex3f(.75 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom right corner glVertex3f(.35 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom left corner glEnd(); break; case 3: glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glBegin(GL_POLYGON); glColor3f(1, 1, 0); glVertex3f(.35 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top left corner glVertex3f(.75 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top right corner glVertex3f(.75 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom right corner glVertex3f(.35 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom left corner glEnd(); break; case 4: glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glBegin(GL_POLYGON); glColor3f(1, 1, 0); glVertex3f(.35 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top left corner glVertex3f(.75 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top right corner glVertex3f(.75 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom right corner glVertex3f(.35 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom left corner glEnd(); break; case 5: glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glBegin(GL_POLYGON); glColor3f(1, 1, 0); glVertex3f(.35 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top left corner glVertex3f(.75 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top right corner glVertex3f(.75 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom right corner glVertex3f(.35 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom left corner glEnd(); break; case 6: glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glBegin(GL_POLYGON); glColor3f(1, 1, 0); glVertex3f(.35 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top left corner glVertex3f(.75 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top right corner glVertex3f(.75 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom right corner glVertex3f(.35 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom left corner glEnd(); break; case 7: glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, 10.0, 0.0, 10.0, -1.0, 1.0); glBegin(GL_POLYGON); glColor3f(1, 1, 0); glVertex3f(.35 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top left corner glVertex3f(.75 + .45 * (j-1), 9.67 - .47 * (i-1), 0.0); // top right corner glVertex3f(.75 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom right corner glVertex3f(.35 + .45 * (j-1), 9.27 - .47 * (i-1), 0.0); // bottom left corner glEnd(); break; } } } glutSwapBuffers(); }
void VectorView::plot_arrow(double x, double y, double xval, double yval, double max, double min, double gs) { if (mode == 1) glColor3f(0.0f,0.0f,0.0f); else glColor3f(0.5f,0.5f,0.5f); // magnitude double real_mag = sqrt(sqr(xval) + sqr(yval)); double mag = real_mag; if (real_mag > max) mag = max; double length = mag/max * gs * length_coef; double width = 0.1 * gs; if (mode == 1) width *= 1.2; double xnew = x + gs * xval * mag / (max * real_mag) * length_coef; double ynew = y - gs * yval * mag / (max * real_mag) * length_coef; if ((mag)/(max - min) < 1e-5) { glTranslated(x,y,0.0); glBegin(GL_QUADS); glVertex2d( width, width); glVertex2d( width, -width); glVertex2d(-width, -width); glVertex2d(-width, width); glEnd(); } else { glBegin(GL_LINES); glVertex2d(x,y); glVertex2d(xnew, ynew); glEnd(); glTranslated(x,y,0.0); glRotated(atan2(-yval,xval) * 180.0/M_PI, 0.0, 0.0, 1.0); glBegin(GL_TRIANGLES); glVertex2d(length + 3 * width, 0.0); glVertex2d(length - 2 * width, width); glVertex2d(length - 2 * width, -width); glEnd(); } glLoadIdentity(); if (mode == 1) { float color[3]; get_palette_color((mag - min)/(max - min), color); // 0.0 -- 1.0 glColor3f(color[0], color[1], color[2]); if (mag/(max - min) < 1e-5) { glBegin(GL_QUADS); glVertex2d( width, width); glVertex2d( width, -width); glVertex2d(-width, -width); glVertex2d(-width, width); glEnd(); } else { glBegin(GL_LINES); glVertex2d(x,y); glVertex2d(xnew, ynew); glEnd(); glTranslated(x - 1, y,0.0); glRotated(atan2(-yval,xval) * 180.0/M_PI, 0.0, 0.0, 1.0); glBegin(GL_TRIANGLES); glVertex2d(length + 3 * width, 0.0); glVertex2d(length - 2 * width, width); glVertex2d(length - 2 * width, -width); glEnd(); glLoadIdentity(); } } }
void drawHouse() { glColor3f(rand() / double(RAND_MAX), rand() / double(RAND_MAX), rand() / double(RAND_MAX)); glBegin(GL_QUADS); glVertex3f(2.0f, 2.0f, -2.0f); glVertex3f(-2.0f, 2.0f, -2.0f); glVertex3f(-2.0f, 2.0f, 2.0f); glVertex3f(2.0f, 2.0f, 2.0f); glVertex3f(2.0f, -2.0f, 2.0f); glVertex3f(-2.0f, -2.0f, 2.0f); glVertex3f(-2.0f, -2.0f, -2.0f); glVertex3f(2.0f, -2.0f, -2.0f); glVertex3f(2.0f, 2.0f, 2.0f); glVertex3f(-2.0f, 2.0f, 2.0f); glVertex3f(-2.0f, -2.0f, 2.0f); glVertex3f(2.0f, -2.0f, 2.0f); glVertex3f(2.0f, -2.0f, -2.0f); glVertex3f(-2.0f, -2.0f, -2.0f); glVertex3f(-2.0f, 2.0f, -2.0f); glVertex3f(2.0f, 2.0f, -2.0f); glVertex3f(-2.0f, 2.0f, 2.0f); glVertex3f(-2.0f, 2.0f, -2.0f); glVertex3f(-2.0f, -2.0f, -2.0f); glVertex3f(-2.0f, -2.0f, 2.0f); glVertex3f(2.0f, 2.0f, -2.0f); glVertex3f(2.0f, 2.0f, 2.0f); glVertex3f(2.0f, -2.0f, 2.0f); glVertex3f(2.0f, -2.0f, -2.0f); glEnd(); //крыша glColor3f(0.0f, 0.0f, 1.0f); glBegin(GL_TRIANGLES); glVertex3f(0.0f, 4.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 2.0f); glVertex3f(2.0f, 2.0f, 2.0f); glVertex3f(0.0f, 4.0f, 0.0f); glVertex3f(2.0f, 2.0f, 2.0f); glVertex3f(2.0f, 2.0f, -2.0f); glVertex3f(0.0f, 4.0f, 0.0f); glVertex3f(2.0f, 2.0f, -2.0f); glVertex3f(-2.0f, 2.0f, -2.0f); glVertex3f(0.0f, 4.0f, 0.0f); glVertex3f(-2.0f, 2.0f, -2.0f); glVertex3f(-2.0f, 2.0f, 2.0f); glEnd(); //дверь glBegin(GL_QUADS); glColor3f(0.54f, 0.27f, 0.08f); glVertex3f(-1.5f, 0.0f, 2.01f); glVertex3f(-1.5f, 1.5f, 2.01f); glVertex3f(-0.5f, 1.5f, 2.01f); glVertex3f(-0.5f, 0.0f, 2.01f); glEnd(); //окно glBegin(GL_QUADS); glColor3f(0.1f, 0.1f, 0.1f); glVertex3f(1.5f, 0.5f, 2.01f); glVertex3f(1.5f, 1.5f, 2.01f); glVertex3f(0.5f, 1.5f, 2.01f); glVertex3f(0.5f, 0.5f, 2.01f); glEnd(); glBegin(GL_QUADS); glColor3f(0.8f, 0.8f, 0.9f); glVertex3f(1.4f, 0.6f, 2.011f); glVertex3f(1.4f, 1.4f, 2.011f); glVertex3f(0.6f, 1.4f, 2.011f); glVertex3f(0.6f, 0.6f, 2.011f); glEnd(); //доски glColor3f(0.54f, 0.27f, 0.08f); glTranslatef(2.7f, 0.4f, -2.0f); glutSolidCylinder(0.4f, 4.0f, 32, 32); glTranslatef(0.6f, 0.0f, 0.0f); glutSolidCylinder(0.4f, 4.0f, 32, 32); //типо кошка glTranslatef(-6.0f, -0.0f, 2.0f); glColor3f(0.2f, 0.2f, 0.2f); glutSolidSphere(0.4f, 20, 20); glTranslatef(0.0f, 0.5f, 0.0f); glutSolidSphere(0.2f, 20, 20); //Гусеница мутант glColor3f(0.0f, 1.0f, 0.0f); glTranslatef(-1.0f, 2.0f, -6.0f); glutWireSphere(3.0f, 32, 32); glTranslatef(0.0f, 4.0f, 0.0f); glutWireSphere(3.0f, 32, 32); glTranslatef(4.0f, 0.0f, 0.0f); glutWireSphere(1.0f, 20, 20); glTranslatef(-8.0f, 0.0f, 0.0f); glutWireSphere(1.0f, 20, 20); glTranslatef(4.0f, 4.0f, 0.0f); glutWireSphere(2.0f, 32, 32); //мангал glColor3f(1.0f, 1.0f, 1.0f); glTranslatef(0.0f, 10.0f, 10.0f); glutSolidCube(2.0f); }
void CUnit::DrawStats() { if ((gu->myAllyTeam != allyteam) && !gu->spectatingFullView && unitDef->hideDamage) { return; } float3 interPos = pos + (speed * gu->timeOffset); interPos.y += model->height + 5.0f; glBegin(GL_QUADS); const float3& camUp = camera->up; const float3& camRight = camera->right; const float hpp = max(0.0f, health / maxHealth); const float end = (0.5f - hpp) * 10.0f; // black background for healthbar glColor3f(0.0f, 0.0f, 0.0f); glVertexf3(interPos + (camUp * 6.0f) - (camRight * end)); glVertexf3(interPos + (camUp * 6.0f) + (camRight * 5.0f)); glVertexf3(interPos + (camUp * 4.0f) + (camRight * 5.0f)); glVertexf3(interPos + (camUp * 4.0f) - (camRight * end)); if (stunned) { glColor3f(0.0f, 0.0f, 1.0f); } else { if (hpp > 0.5f) { glColor3f(1.0f - ((hpp - 0.5f) * 2.0f), 1.0f, 0.0f); } else { glColor3f(1.0f, hpp * 2.0f, 0.0f); } } // healthbar glVertexf3(interPos + (camUp * 6.0f) - (camRight * 5.0f)); glVertexf3(interPos + (camUp * 6.0f) - (camRight * end)); glVertexf3(interPos + (camUp * 4.0f) - (camRight * end)); glVertexf3(interPos + (camUp * 4.0f) - (camRight * 5.0f)); if ((gu->myTeam != team) && !gu->spectatingFullView) { glEnd(); return; } // experience bar glColor3f(1.0f, 1.0f, 1.0f); const float hEnd = (limExperience * 0.8f) * 10.0f; glVertexf3(interPos + (-camUp * 2.0f) + (camRight * 6.0f)); glVertexf3(interPos + (-camUp * 2.0f) + (camRight * 8.0f)); glVertexf3(interPos + (camUp * (hEnd - 2.0f)) + (camRight * 8.0f)); glVertexf3(interPos + (camUp * (hEnd - 2.0f)) + (camRight * 6.0f)); glEnd(); if (group) { glPushMatrix(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glTranslatef3(interPos - (camRight * 10.0f)); glScalef(10.0f, 10.0f, 10.0f); font->glWorldPrint("%d", group->id); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glPopMatrix(); } if (beingBuilt) { glColor3f(1.0f, 0.0f, 0.0f); const float end = (buildProgress * 0.8f) * 10.0f; glBegin(GL_QUADS); glVertexf3(interPos - (camUp * 2.0f) - (camRight * 6.0f)); glVertexf3(interPos - (camUp * 2.0f) - (camRight * 8.0f)); glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 8.0f)); glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 6.0f)); glEnd(); } else if (stockpileWeapon) { glColor3f(1.0f, 0.0f, 0.0f); const float end = (stockpileWeapon->buildPercent * 0.8f) * 10.0f; glBegin(GL_QUADS); glVertexf3(interPos - (camUp * 2.0f) - (camRight * 6.0f)); glVertexf3(interPos - (camUp * 2.0f) - (camRight * 8.0f)); glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 8.0f)); glVertexf3(interPos + (camUp * (end - 2.0f)) - (camRight * 6.0f)); glEnd(); } }
void DrawVolumeUsingCurrentDisplayMode(void) { if (use_arrays) { if (regenerate_arrays == 1) { printf("Filling vertex/normal arrays... "); fflush(stdout); ClearArrays(); switch (display_mode) { case 0: FillArrayWithPoints(); break; case 1: FillArrayWithCubes(); break; case 2: FillArrayWithIsosurface(); break; } printf("done, %d array vertices used (1 per point, 4 per quad, 3 per triangle)\n", num_vertices_in_array); regenerate_arrays = 0; } glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertices); if (display_mode > 0) { glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, normals); } } glColor3f(0.6, 0.0, 0.0); if (display_mode == 0) glDisable(GL_LIGHTING); else glEnable(GL_LIGHTING); if (display_mode == 0) { /* points */ glPointSize(8.0); if (use_arrays) glDrawArrays(GL_POINTS, 0, num_vertices_in_array); else DrawVolumeAsPoints(); } else if (display_mode == 1) { /* cubes */ if (use_arrays) glDrawArrays(GL_QUADS, 0, num_vertices_in_array); else { glEnable(GL_RESCALE_NORMAL); DrawVolumeAsCubes(); glDisable(GL_RESCALE_NORMAL); } } else if (display_mode == 2) { /* isosurface */ if (use_arrays) glDrawArrays(GL_TRIANGLES, 0, num_vertices_in_array); else DrawVolumeAsIsosurface(); } if (use_arrays) { glDisableClientState(GL_VERTEX_ARRAY); if (display_mode > 0) glDisableClientState(GL_NORMAL_ARRAY); } }
void cTilePicker::render() { tileListStartXY = spritePos2D; glm::vec2 tilePosXY = tileListStartXY; for (int row = 0; row < 2; row++) { for (int column = 0; column < 3; column++) { switch (tilePickingList[row][column]) { case 1: GLTextureID = tileTextureList[1]->getTexture(); break; case 2: GLTextureID = tileTextureList[2]->getTexture(); break; case 3: GLTextureID = tileTextureList[3]->getTexture(); break; case 4: GLTextureID = tileTextureList[4]->getTexture(); break; case 5: GLTextureID = tileTextureList[5]->getTexture(); break; case 6: GLTextureID = tileTextureList[6]->getTexture(); break; } setTextureDimensions(tileTextureList[0]->getTWidth(), tileTextureList[0]->getTHeight()); setSpriteCentre(); glPushMatrix(); glTranslatef(tilePosXY.x, tilePosXY.y, 0.0f); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, GLTextureID); // Binding of GLtexture name glBegin(GL_QUADS); glColor3f(255.0f, 255.0f, 255.0f); glTexCoord2f(spriteTexCoordData[0].x, spriteTexCoordData[0].y); glVertex2f(0, 0); glTexCoord2f(spriteTexCoordData[1].x, spriteTexCoordData[1].y); glVertex2f(textureWidth, 0); glTexCoord2f(spriteTexCoordData[2].x, spriteTexCoordData[2].y); glVertex2f(textureWidth, textureHeight); glTexCoord2f(spriteTexCoordData[3].x, spriteTexCoordData[3].y); glVertex2f(0, textureHeight); glEnd(); glDisable(GL_TEXTURE_2D); glPopMatrix(); tilePosXY.x += cSprite::textureWidth; } tilePosXY.x = tileListStartXY.x; tilePosXY.y += cSprite::textureHeight; } }
//Draw Pacman at (x,y) void drawPacMan(int x, int y, int radius){ glColor3f(1.0, 1.0, 0.0); drawCircle(x,y,radius,40,1.7,M_PI/6); }
void drawButton(Button *b) { int fontx; int fonty; if (b) { /* * We will indicate that the mouse cursor is over the button by changing its * colour. */ if (b->highlighted) glColor3f(0.7f, 0.7f, 0.8f); else glColor3f(0.6f, 0.6f, 0.6f); /* * draw background for the button. */ glBegin(GL_QUADS); glVertex2i(b->x, b->y); glVertex2i(b->x, b->y + b->h); glVertex2i(b->x + b->w, b->y + b->h); glVertex2i(b->x + b->w, b->y); glEnd(); /* * Draw an outline around the button with width 3 */ glLineWidth(3); /* * The colours for the outline are reversed when the button. */ if (b->state) glColor3f(0.4f, 0.4f, 0.4f); else glColor3f(0.8f, 0.8f, 0.8f); glBegin(GL_LINE_STRIP); glVertex2i(b->x + b->w, b->y); glVertex2i(b->x, b->y); glVertex2i(b->x, b->y + b->h); glEnd(); if (b->state) glColor3f(0.8f, 0.8f, 0.8f); else glColor3f(0.4f, 0.4f, 0.4f); glBegin(GL_LINE_STRIP); glVertex2i(b->x, b->y + b->h); glVertex2i(b->x + b->w, b->y + b->h); glVertex2i(b->x + b->w, b->y); glEnd(); glLineWidth(1); /* * Calculate the x and y coords for the text string in order to center it. */ fontx = b->x + (b->w - glutBitmapLength(GLUT_BITMAP_HELVETICA_10, (const unsigned char*)b->label)) / 2; fonty = b->y + (b->h + 10) / 2; /* * if the button is pressed, make it look as though the string has been pushed * down. It's just a visual thing to help with the overall look.... */ if (b->state) { fontx += 2; fonty += 2; } /* * If the cursor is currently over the button we offset the text string and draw a shadow */ if (b->highlighted) { glColor3f(0, 0, 0); font(GLUT_BITMAP_HELVETICA_10, b->label, fontx, fonty); fontx--; fonty--; } glColor3f(1, 1, 1); font(GLUT_BITMAP_HELVETICA_10, b->label, fontx, fonty); } }
void displayfunc() { unsigned int i; GLuint texid; clearbuffer(0,0,0); for (i=0; i<height; i++) memcpy(&image[i*components*imgwidth], &volume[(long long)frame*components*width*height+i*components*width],components*width); glGenTextures(1,&texid); glBindTexture(GL_TEXTURE_2D,texid); glPixelStorei(GL_UNPACK_ALIGNMENT,1); if (components==1) glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,imgwidth,imgheight,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,image); else if (components==3) glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,imgwidth,imgheight,0,GL_RGB,GL_UNSIGNED_BYTE,image); else if (components==4) glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,imgwidth,imgheight,0,GL_RGBA,GL_UNSIGNED_BYTE,image); else ERRORMSG(); glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); glDisable(GL_DITHER); glDisable(GL_CULL_FACE); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); glTranslatef(0.5f/imgwidth,0.5f/imgheight,0.0f); glScalef((float)(width-1)/imgwidth,(float)(height-1)/imgheight,0.0f); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f,winwidth-1,0.0f,winheight-1,-1.0f,1.0f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); if (width*winheight<winwidth*height) { glTranslatef((winwidth-width*winheight/height)/2.0f,0.0f,0.0f); glScalef(width*winheight/height,winheight,0.0f); } else { glTranslatef(0.0f,(winheight-height*winwidth/width)/2.0f,0.0f); glScalef(winwidth,height*winwidth/width,0.0f); } glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); glBegin(GL_TRIANGLE_FAN); glTexCoord2f(0.0f,1.0f); glVertex3f(0.0f,0.0f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(1.0f,0.0f,0.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(0.0f,1.0f,0.0f); glEnd(); glDisable(GL_TEXTURE_2D); glDeleteTextures(1,&texid); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); glEnable(GL_DITHER); glEnable(GL_CULL_FACE); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glutSwapBuffers(); waitfor(1.0/fps); if (!pausing) if (frame<depth-1) frame++; else frame=0; if (frame==depth-1) pausing=TRUE; }
void mitk::MeshMapper2D::Paint(mitk::BaseRenderer *renderer) { bool visible = true; GetDataNode()->GetVisibility(visible, renderer, "visible"); if (!visible) return; // @FIXME: Logik fuer update bool updateNeccesary = true; if (updateNeccesary) { // aus GenerateData mitk::Mesh::Pointer input = const_cast<mitk::Mesh *>(this->GetInput()); // Get the TimeGeometry of the input object const TimeGeometry *inputTimeGeometry = input->GetTimeGeometry(); if ((inputTimeGeometry == nullptr) || (inputTimeGeometry->CountTimeSteps() == 0)) { return; } // // get the world time // ScalarType time = renderer->GetTime(); // // convert the world time in time steps of the input object // int timeStep = 0; if (time > itk::NumericTraits<mitk::ScalarType>::NonpositiveMin()) timeStep = inputTimeGeometry->TimePointToTimeStep(time); if (inputTimeGeometry->IsValidTimeStep(timeStep) == false) { return; } mitk::Mesh::MeshType::Pointer itkMesh = input->GetMesh(timeStep); if (itkMesh.GetPointer() == nullptr) { return; } const PlaneGeometry *worldplanegeometry = (renderer->GetCurrentWorldPlaneGeometry()); // apply color and opacity read from the PropertyList ApplyColorAndOpacityProperties(renderer); vtkLinearTransform *transform = GetDataNode()->GetVtkTransform(); // List of the Points Mesh::DataType::PointsContainerConstIterator it, end; it = itkMesh->GetPoints()->Begin(); end = itkMesh->GetPoints()->End(); // iterator on the additional data of each point Mesh::PointDataIterator dataIt; //, dataEnd; dataIt = itkMesh->GetPointData()->Begin(); // for switching back to old color after using selected color float unselectedColor[4]; glGetFloatv(GL_CURRENT_COLOR, unselectedColor); while (it != end) { mitk::Point3D p, projected_p; float vtkp[3]; itk2vtk(it->Value(), vtkp); transform->TransformPoint(vtkp, vtkp); vtk2itk(vtkp, p); renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p); Vector3D diff = p - projected_p; if (diff.GetSquaredNorm() < 4.0) { Point2D pt2d, tmp; renderer->WorldToDisplay(p, pt2d); Vector2D horz, vert; horz[0] = 5; horz[1] = 0; vert[0] = 0; vert[1] = 5; // check if the point is to be marked as selected if (dataIt->Value().selected) { horz[0] = 8; vert[1] = 8; glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red switch (dataIt->Value().pointSpec) { case PTSTART: // a quad glBegin(GL_LINE_LOOP); tmp = pt2d - horz + vert; glVertex2dv(&tmp[0]); tmp = pt2d + horz + vert; glVertex2dv(&tmp[0]); tmp = pt2d + horz - vert; glVertex2dv(&tmp[0]); tmp = pt2d - horz - vert; glVertex2dv(&tmp[0]); glEnd(); break; case PTUNDEFINED: // a diamond around the point glBegin(GL_LINE_LOOP); tmp = pt2d - horz; glVertex2dv(&tmp[0]); tmp = pt2d + vert; glVertex2dv(&tmp[0]); tmp = pt2d + horz; glVertex2dv(&tmp[0]); tmp = pt2d - vert; glVertex2dv(&tmp[0]); glEnd(); break; default: break; } // switch // the actual point glBegin(GL_POINTS); tmp = pt2d; glVertex2dv(&tmp[0]); glEnd(); } else // if not selected { glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]); switch (dataIt->Value().pointSpec) { case PTSTART: // a quad glBegin(GL_LINE_LOOP); tmp = pt2d - horz + vert; glVertex2dv(&tmp[0]); tmp = pt2d + horz + vert; glVertex2dv(&tmp[0]); tmp = pt2d + horz - vert; glVertex2dv(&tmp[0]); tmp = pt2d - horz - vert; glVertex2dv(&tmp[0]); glEnd(); break; case PTUNDEFINED: // drawing crosses glBegin(GL_LINES); tmp = pt2d - horz; glVertex2dv(&tmp[0]); tmp = pt2d + horz; glVertex2dv(&tmp[0]); tmp = pt2d - vert; glVertex2dv(&tmp[0]); tmp = pt2d + vert; glVertex2dv(&tmp[0]); glEnd(); break; default: { break; } } // switch } // else } ++it; ++dataIt; } // now connect the lines inbetween mitk::Mesh::PointType thisPoint; thisPoint.Fill(0); Point2D *firstOfCell = nullptr; Point2D *lastPoint = nullptr; unsigned int lastPointId = 0; bool lineSelected = false; Point3D firstOfCell3D; Point3D lastPoint3D; bool first; mitk::Line<mitk::ScalarType> line; std::vector<mitk::Point3D> intersectionPoints; double t; // iterate through all cells and then iterate through all indexes of points in that cell Mesh::CellIterator cellIt, cellEnd; Mesh::CellDataIterator cellDataIt; //, cellDataEnd; Mesh::PointIdIterator cellIdIt, cellIdEnd; cellIt = itkMesh->GetCells()->Begin(); cellEnd = itkMesh->GetCells()->End(); cellDataIt = itkMesh->GetCellData()->Begin(); while (cellIt != cellEnd) { unsigned int numOfPointsInCell = cellIt->Value()->GetNumberOfPoints(); if (numOfPointsInCell > 1) { // iterate through all id's in the cell cellIdIt = cellIt->Value()->PointIdsBegin(); cellIdEnd = cellIt->Value()->PointIdsEnd(); firstOfCell3D = input->GetPoint(*cellIdIt, timeStep); intersectionPoints.clear(); intersectionPoints.reserve(numOfPointsInCell); first = true; while (cellIdIt != cellIdEnd) { lastPoint3D = thisPoint; thisPoint = input->GetPoint(*cellIdIt, timeStep); // search in data (vector<> selectedLines) if the index of the point is set. if so, then the line is selected. lineSelected = false; Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines; // a line between 1(lastPoint) and 2(pt2d) has the Id 1, so look for the Id of lastPoint // since we only start, if we have more than one point in the cell, lastPointId is initiated with 0 Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId); if (position != selectedLines.end()) { lineSelected = true; } mitk::Point3D p, projected_p; float vtkp[3]; itk2vtk(thisPoint, vtkp); transform->TransformPoint(vtkp, vtkp); vtk2itk(vtkp, p); renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p); Vector3D diff = p - projected_p; if (diff.GetSquaredNorm() < 4.0) { Point2D pt2d, tmp; renderer->WorldToDisplay(p, pt2d); if (lastPoint == nullptr) { // set the first point in the cell. This point in needed to close the polygon firstOfCell = new Point2D; *firstOfCell = pt2d; lastPoint = new Point2D; *lastPoint = pt2d; lastPointId = *cellIdIt; } else { if (lineSelected) { glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red // a line from lastPoint to thisPoint glBegin(GL_LINES); glVertex2dv(&(*lastPoint)[0]); glVertex2dv(&pt2d[0]); glEnd(); } else // if not selected { glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]); // drawing crosses glBegin(GL_LINES); glVertex2dv(&(*lastPoint)[0]); glVertex2dv(&pt2d[0]); glEnd(); } // to draw the line to the next in iteration step *lastPoint = pt2d; // and to search for the selection state of the line lastPointId = *cellIdIt; } // if..else } // if <4.0 // fill off-plane polygon part 1 if ((!first) && (worldplanegeometry != nullptr)) { line.SetPoints(lastPoint3D, thisPoint); if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1))) { intersectionPoints.push_back(line.GetPoint(t)); } } ++cellIdIt; first = false; } // while cellIdIter // closed polygon? if (cellDataIt->Value().closed) { // close the polygon if needed if (firstOfCell != nullptr) { lineSelected = false; Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines; Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId); if (position != selectedLines.end()) // found the index { glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red // a line from lastPoint to firstPoint glBegin(GL_LINES); glVertex2dv(&(*lastPoint)[0]); glVertex2dv(&(*firstOfCell)[0]); glEnd(); } else { glColor3f(unselectedColor[0], unselectedColor[1], unselectedColor[2]); glBegin(GL_LINES); glVertex2dv(&(*lastPoint)[0]); glVertex2dv(&(*firstOfCell)[0]); glEnd(); } } } // if closed // Axis-aligned bounding box(AABB) around the cell if selected and set in Property bool showBoundingBox; if (dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox")) == nullptr) showBoundingBox = false; else showBoundingBox = dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox"))->GetValue(); if (showBoundingBox) { if (cellDataIt->Value().selected) { mitk::Mesh::DataType::BoundingBoxPointer aABB = input->GetBoundingBoxFromCell(cellIt->Index()); if (aABB.IsNotNull()) { mitk::Mesh::PointType min, max; min = aABB->GetMinimum(); max = aABB->GetMaximum(); // project to the displayed geometry Point2D min2D, max2D; Point3D p, projected_p; float vtkp[3]; itk2vtk(min, vtkp); transform->TransformPoint(vtkp, vtkp); vtk2itk(vtkp, p); renderer->WorldToDisplay(p, min2D); itk2vtk(max, vtkp); transform->TransformPoint(vtkp, vtkp); vtk2itk(vtkp, p); renderer->GetCurrentWorldPlaneGeometry()->Project(p, projected_p); Vector3D diff = p - projected_p; if (diff.GetSquaredNorm() < 4.0) { renderer->WorldToDisplay(p, max2D); // draw the BoundingBox glColor3f(selectedColor[0], selectedColor[1], selectedColor[2]); // red // a line from lastPoint to firstPoint glBegin(GL_LINE_LOOP); glVertex2f(min2D[0], min2D[1]); glVertex2f(min2D[0], max2D[1]); glVertex2f(max2D[0], max2D[1]); glVertex2f(max2D[0], min2D[1]); glEnd(); } // draw bounding-box } // bounding-box exists } // cell selected } // show bounding-box // fill off-plane polygon part 2 if (worldplanegeometry != nullptr) { // consider line from last to first line.SetPoints(thisPoint, firstOfCell3D); if (worldplanegeometry->IntersectionPointParam(line, t) && ((t >= 0) && (t <= 1))) { intersectionPoints.push_back(line.GetPoint(t)); } std::sort(intersectionPoints.begin(), intersectionPoints.end(), point3DSmaller); std::vector<mitk::Point3D>::iterator it, end; end = intersectionPoints.end(); if ((intersectionPoints.size() % 2) != 0) { --end; // ensure even number of intersection-points } Point2D pt2d; for (it = intersectionPoints.begin(); it != end; ++it) { glBegin(GL_LINES); renderer->WorldToDisplay(*it, pt2d); glVertex2dv(pt2d.GetDataPointer()); ++it; renderer->WorldToDisplay(*it, pt2d); glVertex2dv(pt2d.GetDataPointer()); glEnd(); } if (it != intersectionPoints.end()) { glBegin(GL_LINES); renderer->WorldToDisplay(*it, pt2d); glVertex2dv(pt2d.GetDataPointer()); glVertex2dv(pt2d.GetDataPointer()); glEnd(); } } // fill off-plane polygon part 2 } // if numOfPointsInCell>1 delete firstOfCell; delete lastPoint; lastPoint = nullptr; firstOfCell = nullptr; lastPointId = 0; ++cellIt; ++cellDataIt; } } }
void DemoApplication::renderme() { myinit(); updateCamera(); if (m_dynamicsWorld) { if(m_enableshadows) { glClear(GL_STENCIL_BUFFER_BIT); glEnable(GL_CULL_FACE); renderscene(0); glDisable(GL_LIGHTING); glDepthMask(GL_FALSE); glDepthFunc(GL_LEQUAL); glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL); glFrontFace(GL_CCW); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); renderscene(1); glFrontFace(GL_CW); glStencilOp(GL_KEEP,GL_KEEP,GL_DECR); renderscene(1); glFrontFace(GL_CCW); glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_BACK,GL_FILL); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LIGHTING); glDepthMask(GL_TRUE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); glDepthFunc(GL_LEQUAL); glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL ); glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); glDisable(GL_LIGHTING); renderscene(2); glEnable(GL_LIGHTING); glDepthFunc(GL_LESS); glDisable(GL_STENCIL_TEST); glDisable(GL_CULL_FACE); } else { glDisable(GL_CULL_FACE); renderscene(0); } int xOffset = 10; int yStart = 20; int yIncr = 20; glDisable(GL_LIGHTING); glColor3f(0, 0, 0); if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0) { setOrthographicProjection(); showProfileInfo(xOffset,yStart,yIncr); #ifdef USE_QUICKPROF if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings) { static int counter = 0; counter++; std::map<std::string, hidden::ProfileBlock*>::iterator iter; for (iter = btProfiler::mProfileBlocks.begin(); iter != btProfiler::mProfileBlocks.end(); ++iter) { char blockTime[128]; sprintf(blockTime, "%s: %lf",&((*iter).first[0]),btProfiler::getBlockTime((*iter).first, btProfiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT)); glRasterPos3f(xOffset,yStart,0); GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),blockTime); yStart += yIncr; } } #endif //USE_QUICKPROF resetPerspectiveProjection(); } glEnable(GL_LIGHTING); } updateCamera(); }
void draw_messages (int x, int y, text_message *msgs, int msgs_size, Uint8 filter, int msg_start, int offset_start, int cursor, int width, int height, float text_zoom, select_info* select) { float displayed_font_x_size = DEFAULT_FONT_X_LEN * text_zoom; float displayed_font_y_size = DEFAULT_FONT_Y_LEN * text_zoom; float selection_red = 255 / 255.0f; float selection_green = 162 / 255.0f; float selection_blue = 0; unsigned char cur_char; int i; int imsg, ichar; int cur_x, cur_y; int cursor_x = x-1, cursor_y = y-1; unsigned char ch; int cur_line = 0; int cur_col = 0; unsigned char last_color_char = 0; int in_select = 0; imsg = msg_start; ichar = offset_start; if (msgs[imsg].data == NULL || msgs[imsg].deleted) return; if (width < displayed_font_x_size || height < displayed_font_y_size) // no point in trying return; #ifndef MAP_EDITOR2 if (filter != FILTER_ALL) { // skip all messages of the wrong channel while (1) { if (skip_message(&msgs[imsg], filter)) { ichar = 0; if (++imsg >= msgs_size) imsg = 0; if (msgs[imsg].data == NULL || imsg == msg_start || msgs[imsg].deleted) // nothing to draw return; } else { break; } } if (msgs[imsg].data == NULL || msgs[imsg].deleted) return; } #endif //! MAP_EDITOR2 ch = msgs[imsg].data[ichar]; if (!is_color (ch)) { // search backwards for the last color for (i = ichar-1; i >= 0; i--) { ch = msgs[imsg].data[i]; if (is_color (ch)) { find_font_char (ch); last_color_char = ch; break; } } if (i < 0) { // no color character found, try the message color if (msgs[imsg].r >= 0) glColor3f (msgs[imsg].r, msgs[imsg].g, msgs[imsg].b); } } glEnable (GL_ALPHA_TEST); // enable alpha filtering, so we have some alpha key glAlphaFunc (GL_GREATER, 0.1f); #ifdef NEW_TEXTURES bind_texture(font_text); #else /* NEW_TEXTURES */ get_and_set_texture_id(font_text); #endif /* NEW_TEXTURES */ i = 0; cur_x = x; cur_y = y; glBegin (GL_QUADS); while (1) { if (i == cursor) { cursor_x = cur_x; cursor_y = cur_y; if (cursor_x - x > width - displayed_font_x_size) { cursor_x = x; cursor_y = cur_y + displayed_font_y_size; } } cur_char = msgs[imsg].data[ichar]; // watch for special characters if (cur_char == '\0') { // end of message if (++imsg >= msgs_size) { imsg = 0; } #ifndef MAP_EDITOR2 if (filter != FILTER_ALL) { // skip all messages of the wrong channel while (skip_message (&msgs[imsg], filter)) { if (++imsg >= msgs_size) imsg = 0; if (msgs[imsg].data == NULL || imsg == msg_start) break; } } #endif if (msgs[imsg].data == NULL || imsg == msg_start || msgs[imsg].deleted) break; rewrap_message (&msgs[imsg], text_zoom, width, NULL); ichar = 0; last_color_char = 0; } if (select != NULL && select->lines && select->lines[cur_line].msg == -1) { select->lines[cur_line].msg = imsg; select->lines[cur_line].chr = ichar; } if (cur_char == '\n' || cur_char == '\r' || cur_char == '\0') { // newline cur_y += displayed_font_y_size; if (cur_y - y > height - displayed_font_y_size) break; cur_x = x; if (cur_char != '\0') ichar++; i++; cur_line++; cur_col = 0; continue; } if (pos_selected(imsg, ichar, select)) { if (!in_select) { glColor3f (selection_red, selection_green, selection_blue); in_select = 1; } } else { if (in_select) { if (last_color_char) find_font_char (last_color_char); else if (msgs[imsg].r < 0) find_font_char (to_color_char (c_grey1)); else glColor3f (msgs[imsg].r, msgs[imsg].g, msgs[imsg].b); in_select = 0; } } if (is_color (cur_char)) { last_color_char = cur_char; if (in_select) { // don't draw color characters in a selection i++; ichar++; continue; } } cur_x += draw_char_scaled (cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size); cur_col++; ichar++; i++; if (cur_x - x > width - displayed_font_x_size) { // ignore rest of this line, but keep track of // color characters while (1) { ch = msgs[imsg].data[ichar]; if (ch == '\0' || ch == '\n' || ch == '\r') break; if (is_color (ch)) last_color_char = ch; ichar++; i++; } } } if (cursor_x >= x && cursor_y >= y && cursor_y - y <= height - displayed_font_y_size) { draw_char_scaled ('_', cursor_x, cursor_y, displayed_font_x_size, displayed_font_y_size); } glEnd(); glDisable(GL_ALPHA_TEST); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }
void ClipObject::drawLines(QGLViewer *viewer, bool backToFront) { bool noimage = !m_imagePresent && !m_captionPresent; bool quad = noimage && m_active; glEnable(GL_BLEND); // glEnable(GL_LINE_SMOOTH); // glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); Vec voxelScaling = Global::voxelScaling(); Vec opt = VECPRODUCT(m_position, voxelScaling); opt = Matrix::xformVec(m_xform, opt); float r = m_size; float s1 = m_tscale1; float s2 = m_tscale2; Vec tang = m_tang; Vec xaxis = m_xaxis; Vec yaxis = m_yaxis; tang = Matrix::rotateVec(m_xform, tang); xaxis = Matrix::rotateVec(m_xform, xaxis); yaxis = Matrix::rotateVec(m_xform, yaxis); if (backToFront) { if (m_active) glLineWidth(3); else glLineWidth(1); glColor3f(m_color.x, m_color.y, m_color.z); if (m_thickness > 0 && m_showThickness) DRAWTHICKNESS() else DRAWCLIPWIDGET() } glLineWidth(1); if (!m_solidColor || m_active) { Vec c0, ca, cb, c1; c0 = opt + s1*xaxis; ca = opt - 0.2*s2*yaxis; c1 = opt - s1*xaxis; cb = opt + 0.2*s2*yaxis; glColor4f(m_opacity, 0.5*m_opacity, 0, m_opacity); if (quad && m_moveAxis >= MoveX0 && m_moveAxis <= MoveX1) glBegin(GL_QUADS); else glBegin(GL_LINE_STRIP); glVertex3fv(c0); glVertex3fv(ca); glVertex3fv(c1); glVertex3fv(cb); if (!(quad && m_moveAxis == MoveZ)) glVertex3fv(c0); glEnd(); c0 = opt + s2*yaxis; ca = opt - 0.2*s1*xaxis; c1 = opt - s2*yaxis; cb = opt + 0.2*s1*xaxis; glColor4f(0.5*m_opacity, m_opacity, 0, m_opacity); if (quad && m_moveAxis >= MoveY0 && m_moveAxis <= MoveY1) glBegin(GL_QUADS); else glBegin(GL_LINE_STRIP); glVertex3fv(c0); glVertex3fv(ca); glVertex3fv(c1); glVertex3fv(cb); if (!quad) glVertex3fv(c0); glEnd(); c0 = opt + r*tang; Vec cax = opt - 0.2*s1*xaxis; Vec cbx = opt + 0.2*s1*xaxis; Vec cay = opt - 0.2*s2*yaxis; Vec cby = opt + 0.2*s2*yaxis; glColor4f(0, 0.5*m_opacity, m_opacity, m_opacity); if (quad && m_moveAxis == MoveZ) glBegin(GL_TRIANGLES); else glBegin(GL_LINE_STRIP); glVertex3fv(c0); glVertex3fv(cax); glVertex3fv(cay); glVertex3fv(c0); glVertex3fv(cay); glVertex3fv(cbx); glVertex3fv(c0); glVertex3fv(cbx); glVertex3fv(cby); glVertex3fv(c0); glVertex3fv(cby); glVertex3fv(cax); if (!(quad && m_moveAxis == MoveZ)) glVertex3fv(c0); glEnd(); } // glDisable(GL_LINE_SMOOTH); if (!backToFront) { if (m_active) glLineWidth(3); else glLineWidth(1); glColor3f(m_color.x, m_color.y, m_color.z); if (m_thickness > 0 && m_showThickness) DRAWTHICKNESS() else DRAWCLIPWIDGET() } if (!m_solidColor || m_active) { glEnable(GL_POINT_SPRITE); glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, Global::spriteTexture()); glTexEnvf( GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE ); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); glEnable(GL_POINT_SMOOTH); if (m_active) { glColor3f(1,0,0); glPointSize(25); } else { glColor3f(m_color.x, m_color.y, m_color.z); glPointSize(20); } glBegin(GL_POINTS); glVertex3fv(opt); glEnd(); glPointSize(1); glDisable(GL_POINT_SPRITE); glActiveTexture(GL_TEXTURE0); glDisable(GL_TEXTURE_2D); glDisable(GL_POINT_SMOOTH); } glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); }
// DRAW //------------------------------------------------- void Object3D::Draw () { // daca nu este vizibil, nu-l desenam if(!Visible) return; glPushMatrix(); // translatie glTranslatef( translation.x , translation.y , translation.z ); // rotatie glRotatef( rotation.x , 1.0 , 0.0 , 0.0 ); glRotatef( rotation.y , 0.0 , 1.0 , 0.0 ); glRotatef( rotation.z , 0.0 , 0.0 , 1.0 ); // scalare glScalef( scale.x , scale.y , scale.z); // setari de material : // daca nu este selectat if( !selected ) { // culoare normala glColor3f(color.x,color.y,color.z); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,(Vector4D(color.x,color.y,color.z,1)).Array()); } else { // culoarea atunci cand obiectul este selectat glColor3f(SelectedColor.x, SelectedColor.y, SelectedColor.z); glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,(Vector4D(SelectedColor.x,SelectedColor.y,SelectedColor.z,1)).Array()); } // culoare speculara, default glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,(Vector4D(0.1,0.1,0.1,1)).Array()); //culoae emisiva if(emission==true) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Vector4D(Vector4D(color.x,color.y,color.z,1)).Array()); else glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Vector4D(0, 0, 0, 0).Array()); // daca este wireframe if( Wireframe ) switch( Type ) { // cub wireframe case Cube : glutWireCube(1.0); break; // sfera wireframe case Sphere : glutWireSphere(1.0, levelOfDetail, levelOfDetail); break; // ceainic wireframe case MyTeapot: glutWireTeapot(1); break; // lampa wireframe case MyLamp: glutWireCone(1.0,2.0,(int)levelOfDetail,(int)levelOfDetail); break; // inamic wireframe case MyEnemy: glutWireDodecahedron(); break; // extra inamic wireframe case ExtraEnemy: glutWireTetrahedron(); break; // orice alt obiect, specificat de programator case Custom : customDraw(); } // daca nu este wireframe else switch( Type ) { // cub solid case Cube : glutSolidCube(1.0); break; // sfera solida case Sphere : glutSolidSphere(1.0, levelOfDetail, levelOfDetail); break; // ceainic solid case MyTeapot: glutSolidTeapot(1); break; // lampa solida case MyLamp: glutSolidCone(1.0,2.0,(int)levelOfDetail,(int)levelOfDetail); break; // inamic solid case MyEnemy: glutSolidDodecahedron(); // extra inamic solid case ExtraEnemy: glutSolidTetrahedron(); break; // orice alt obiect, specificat de programator case Custom : customDraw(); } glPopMatrix(); }
void VectorView::on_display() { set_ortho_projection(); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_1D); glPolygonMode(GL_FRONT_AND_BACK, pmode ? GL_LINE : GL_FILL); // initial grid point and grid step double gt = gs; if (hexa) gt *= sqrt(3.0)/2.0; double max_length = 0.0; // transform all vertices vec.lock_data(); int i; int nv = vec.get_num_vertices(); double4* vert = vec.get_vertices(); double2* tvert = new double2[nv]; for (i = 0; i < nv; i++) { tvert[i][0] = transform_x(vert[i][0]); tvert[i][1] = transform_y(vert[i][1]); // find max length of vectors double length = sqr(vert[i][2]) + sqr(vert[i][3]); if (length > max_length) max_length = length; } max_length = sqrt(max_length); // value range double min = range_min, max = range_max; if (range_auto) { min = vec.get_min_value(); max = vec.get_max_value(); } double irange = 1.0 / (max - min); // special case: constant solution if (fabs(min - max) < 1e-8) { irange = 1.0; min -= 0.5; } // draw all triangles int3* xtris = vec.get_triangles(); if (mode != 1) glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, gl_pallete_tex_id); glBegin(GL_TRIANGLES); glColor3f(0.95f, 0.95f, 0.95f); for (i = 0; i < vec.get_num_triangles(); i++) { double mag = sqrt(sqr(vert[xtris[i][0]][2]) + sqr(vert[xtris[i][0]][3])); glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0); glVertex2d(tvert[xtris[i][0]][0], tvert[xtris[i][0]][1]); mag = sqrt(sqr(vert[xtris[i][1]][2]) + sqr(vert[xtris[i][1]][3])); glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0); glVertex2d(tvert[xtris[i][1]][0], tvert[xtris[i][1]][1]); mag = sqrt(sqr(vert[xtris[i][2]][2]) + sqr(vert[xtris[i][2]][3])); glTexCoord2d((mag -min) * irange * tex_scale + tex_shift, 0.0); glVertex2d(tvert[xtris[i][2]][0], tvert[xtris[i][2]][1]); } glEnd(); glDisable(GL_TEXTURE_1D); // draw all edges /*if (mode == 0) glColor3f(0.3, 0.3, 0.3); else*/ glColor3f(0.5, 0.5, 0.5); glBegin(GL_LINES); int3* edges = vec.get_edges(); for (i = 0; i < vec.get_num_edges(); i++) { if (lines || edges[i][2] != 0) { glVertex2d(tvert[edges[i][0]][0], tvert[edges[i][0]][1]); glVertex2d(tvert[edges[i][1]][0], tvert[edges[i][1]][1]); } } glEnd(); // draw dashed edges if (lines) { glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0xCCCC); glBegin(GL_LINES); int2* dashes = vec.get_dashes(); for (i = 0; i < vec.get_num_dashes(); i++) { glVertex2d(tvert[dashes[i][0]][0], tvert[dashes[i][0]][1]); glVertex2d(tvert[dashes[i][1]][0], tvert[dashes[i][1]][1]); } glEnd(); glDisable(GL_LINE_STIPPLE); } // draw arrows if (mode != 2) { for (i = 0; i < vec.get_num_triangles(); i++) { double miny = 1e100; int idx, k, l1, l2, r2, r1, s; double lry, x; double mr, ml, lx, rx, xval, yval; double wh = output_height + gt, ww = output_width + gs; if ((tvert[xtris[i][0]][0] < -gs) && (tvert[xtris[i][1]][0] < -gs) && (tvert[xtris[i][2]][0] < -gs)) continue; if ((tvert[xtris[i][0]][0] > ww) && (tvert[xtris[i][1]][0] > ww) && (tvert[xtris[i][2]][0] > ww)) continue; if ((tvert[xtris[i][0]][1] < -gt) && (tvert[xtris[i][1]][1] < -gt) && (tvert[xtris[i][2]][1] < -gt)) continue; if ((tvert[xtris[i][0]][1] > wh) && (tvert[xtris[i][1]][1] > wh) && (tvert[xtris[i][2]][1] > wh)) continue; // find vertex with min y-coordinate for (k = 0; k < 3; k++) if (tvert[xtris[i][k]][1] < miny) miny = tvert[xtris[i][idx = k]][1]; l1 = r1 = xtris[i][idx]; l2 = xtris[i][n_vert(idx)]; r2 = xtris[i][p_vert(idx)]; // plane of x and y values on triangle double a[2], b[2], c[2], d[2]; for (int n = 0; n < 2; n++) { a[n] = (tvert[l1][1] - tvert[l2][1])*(vert[r1][2 +n] - vert[r2][2+n]) - (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][1] - tvert[r2][1]); b[n] = (vert[l1][2+n] - vert[l2][2+n])*(tvert[r1][0] - tvert[r2][0]) - (tvert[l1][0] - tvert[l2][0])*(vert[r1][2+n] - vert[r2][2+n]); c[n] = (tvert[l1][0] - tvert[l2][0])*(tvert[r1][1] - tvert[r2][1]) - (tvert[l1][1] - tvert[l2][1])*(tvert[r1][0] - tvert[r2][0]); d[n] = -a[n] * tvert[l1][0] - b[n] * tvert[l1][1] - c[n] * vert[l1][2+n]; a[n] /= c[n]; b[n] /= c[n]; d[n] /= c[n]; } s = (int) ceil((tvert[l1][1] - gy)/gt); // first step lry = gy + s*gt; bool shift = hexa && (s & 1); // if there are two points with min y-coordinate, switch to the next segment if ((tvert[l1][1] == tvert[l2][1]) || (tvert[r1][1] == tvert[r2][1])) if (tvert[l1][1] == tvert[l2][1]) {l1 = l2; l2 = r2;} else if (tvert[r1][1] == tvert[r2][1]) {r1 = r2; r2 = l2;} // slope of the left and right segment ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]); mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]); // x-coordinates of the endpoints of the first line lx = tvert[l1][0] + ml * (lry - (tvert[l1][1])); rx = tvert[r1][0] + mr * (lry - (tvert[r1][1])); if (lry < -gt) { k = (int) floor(-lry/gt); lry += gt * k; lx += k * ml * gt; rx += k * mr * gt; } // while we are in triangle while (((lry < tvert[l2][1]) || (lry < tvert[r2][1])) && (lry < wh)) { // while we are in the segment while (((lry <= tvert[l2][1]) && (lry <= tvert[r2][1])) && (lry < wh)) { double gz = gx; if (shift) gz -= 0.5*gs; s = (int) ceil((lx - gz)/gs); x = gz + s*gs; if (hexa) shift = !shift; if (x < -gs) { k = (int) floor(-x/gs); x += gs * k; } // go along the line while ((x < rx) && (x < ww)) { // plot the arrow xval = -a[0]*x - b[0]*lry - d[0]; yval = -a[1]*x - b[1]*lry - d[1]; plot_arrow(x, lry, xval, yval, max, min, gs); x += gs; } // move to the next line lx += ml*gt; rx += mr*gt; lry += gt; } // change segment if (lry >= tvert[l2][1]) { l1 = l2; l2 = r2; ml = (tvert[l1][0] - tvert[l2][0])/(tvert[l1][1] - tvert[l2][1]); lx = tvert[l1][0] + ml * (lry - (tvert[l1][1])); } else { r1 = r2; r2 = l2; mr = (tvert[r1][0] - tvert[r2][0])/(tvert[r1][1] - tvert[r2][1]); rx = tvert[r1][0] + mr * (lry - (tvert[r1][1])); } } } } delete [] tvert; vec.unlock_data(); }
void FlowShower::draw() { update(); setOrthoView(); glClear(GL_COLOR_BUFFER_BIT); float invRatio = float(game->getResY()) / float(game->getResX()); float hs = 0.02f; //mouse horizontal size //float vs = hs * invRatio; //mouse vertical size float x = float(game->getMouseX()) / float(game->getResX()); float y = 1.0f - float(game->getMouseY()) / float(game->getResY()); float left = (1.0f - invRatio) / 2.0f; float right = 1.0f - left; float osx = (x - left) / (right - left); if (painting && (game->isLeftDown() || game->isMiddleDown() || game->isKeyDown('n') || game->isRightDown())) { flower.bindMat(); glDisable(GL_TEXTURE_2D); if (game->isLeftDown()) glColor3f(0.1, 0.0f, 0.0f); else if (game->isMiddleDown() || game->isKeyDown('m')) glColor3f(0.2, 0.0f, 0.0f); else if (game->isRightDown()) glColor3f(0.0, 0.0f, 0.0f); /*glBegin(GL_QUADS); osx -= 1.0f; oldMouseOSX -= 1.0f; for (int j = 0; j < 3; j++) { glVertex2f(osx - hs, y - hs); glVertex2f(osx + hs, y - hs); glVertex2f(osx + hs, y + hs); glVertex2f(osx - hs, y + hs); glVertex2f(osx + hs, y - hs); glVertex2f(osx - hs, y - hs); glVertex2f(oldMouseOSX - hs, oldMouseY - hs); glVertex2f(oldMouseOSX + hs, oldMouseY - hs); glVertex2f(osx + vs, y + hs); glVertex2f(osx + vs, y - hs); glVertex2f(oldMouseOSX + hs, oldMouseY - hs); glVertex2f(oldMouseOSX + hs, oldMouseY + hs); glVertex2f(osx - vs, y + hs); glVertex2f(osx + vs, y + hs); glVertex2f(oldMouseOSX + hs, oldMouseY + hs); glVertex2f(oldMouseOSX - hs, oldMouseY + hs); glVertex2f(osx - vs, y - hs); glVertex2f(osx - vs, y + hs); glVertex2f(oldMouseOSX - hs, oldMouseY + hs); glVertex2f(oldMouseOSX - hs, oldMouseY - hs); osx += 1.0f; oldMouseOSX += 1.0f; } glEnd();*/ drawMouseOffScreen(); osx -= 2.0f; oldMouseOSX -= 2.0f; Fbo::unbind(); } if (game->isKeyDown('g')) { flower.bindMat(); glColor3f(0.0f, 0.0f, 0.0f); glDisable(GL_BLEND); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); } if (!paused) flower.iterate(iterations, this); if (streamlining) { flower.bindVel(); float sx = float(game->getMouseX()) / float(game->getResY()); float sy = 1.0f - float(game->getMouseY()) / float(game->getResY()); float x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX; float y = (sy-0.5)/scale+ viewY; if(x>0) x=x-static_cast<int>(x); else x=x-static_cast<int>(x)+1.0f; if(y>0) y=y-static_cast<int>(y); else y=y-static_cast<int>(y)+1.0f; slx[0] = x; sly[0] = y; while (slx[0] < 0.0f) slx[0] += 1.0f; while (sly[0] < 0.0f) sly[0] += 1.0f; while (slx[0] >= 1.0f) slx[0] -= 1.0f; while (sly[0] >= 1.0f) sly[0] -= 1.0f; for (int i = 1; i < slpnum; i++) { float pixel[3], xv, yv; float px = slx[i - 1], py = sly[i - 1]; while (px < 0.0f) px += 1.0f; while (py < 0.0f) py += 1.0f; while (px >= 1.0f) px -= 1.0f; while (py >= 1.0f) py -= 1.0f; //glReadPixels(int(px*float(size)),int(py*float(size)),1,1,GL_RGB,GL_FLOAT,(void *)pixel); getSpeed(size, pixel, px, py); xv = pixel[0]; yv = pixel[1]; float v = sqrt(xv * xv + yv * yv); if (v == 0.0f) v = 1.0f; float dl = 0.005f/scale; getSpeed(size, pixel, px + dl * xv / v / 2.0f, py + dl * yv / v / 2.0f); xv = pixel[0]; yv = pixel[1]; v = sqrt(xv * xv + yv * yv); if (v == 0.0f) v = 1.0f; slx[i] = slx[i - 1] + dl * xv / v; sly[i] = sly[i - 1] + dl * yv / v; } Fbo::unbind(); } if (game->isRightDown() && !painting) { flower.bindInk(); Shader::disable(); glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glColor3f(inkRed*(1.0f-inkNew)+inkRedNew*inkNew,inkGreen*(1.0f-inkNew)+inkGreenNew*inkNew,inkBlue*(1.0f-inkNew)+inkBlueNew*inkNew); // glColor3f(1.0,1.0,1.0); drawMouseOffScreen(); Fbo::unbind(); } if (game->isKeyDown('t')) { if(!coordInk) { flower.bindInk(); Shader::disable(); glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2f(0.0f, 0.0f); glVertex2f(1.0f, 0.0f); glVertex2f(1.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); } else { TexGroup::getSingleton()->bind(flowerTex, 0); initFromFGMat.enable(); flower.bindInk(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); Shader::disable(); } } if (game->isKeyDown('r')) { flower.bindVel(); Shader::disable(); glActiveTextureARB(GL_TEXTURE2_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glDisable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glColor3f(0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glVertex2f(0.0f, 0.0f); glVertex2f(1.0f, 0.0f); glVertex2f(1.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); Fbo::unbind(); } displayResult(); float sx = float(game->getMouseX()) / float(game->getResY()); float sy = 1.0f - float(game->getMouseY()) / float(game->getResY()); x = (sx-0.5* float(game->getResX())/ float(game->getResY()))/scale+ viewX; y = (sy-0.5)/scale+ viewY; if(x>0) x=x-static_cast<int>(x); else x=x-static_cast<int>(x)+1.0f; if(y>0) y=y-static_cast<int>(y); else y=y-static_cast<int>(y)+1.0f; float s = 0.02/scale; oldx1=x - s; oldx2=x + s; oldy1=y - s; oldy2=y + s; }
void MeshGui::display(void) { glClearColor( .9f, .9f, .9f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum( -xy_aspect*.04, xy_aspect*.04, -.04, .04, .1, 15.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glMultMatrixf( lights_rotation ); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glLoadIdentity(); glTranslatef( 0.0, 0.0, -2.6f ); glTranslatef( obj_pos[0], obj_pos[1], -obj_pos[2] ); glMultMatrixf( view_rotate ); glScalef( scale, scale, scale ); switch (radiogroup_item_id) { case 2: // draw the smf model glPushMatrix(); glTranslatef( -.5, 0.0, 0.0 ); glMultMatrixf( mesh_rotate ); glColor3f(0.9f, 0.9f, 0.9f); smf_model.display(); //subd.display(); glPopMatrix(); break; // shade with mesh edges displayed case 3: // the mesh itself glPushMatrix(); glTranslatef( -.5, 0.0, 0.0 ); glMultMatrixf( mesh_rotate ); glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); glColor3f(0.9f, 0.9f, 0.9f); smf_model.display(); glPopMatrix(); // the edges glPushMatrix(); glTranslatef( -.5, 0.0, 0.0 ); glMultMatrixf( mesh_rotate ); glColorMaterial(GL_FRONT, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor3f(0.0f, 0.0f, 0.0f); smf_model.display(); glColor3f(0.9f, 0.9f, 0.9f); glDisable(GL_COLOR_MATERIAL); glPopMatrix(); break; case 1: default: // draw the smf model glPushMatrix(); glTranslatef( -.5, 0.0, 0.0 ); glMultMatrixf( mesh_rotate ); glColor3f(0.9f, 0.9f, 0.9f); smf_model.display(); //subd.display(); glPopMatrix(); break; } /*glPushMatrix(); glTranslatef( .5, 0.0, 0.0 ); glMultMatrixf( mesh_rotate ); glutSolidTorus( .15,.3,16,8 ); glPopMatrix();*/ // show text if (show_text) { // disable lighting while we render text glDisable( GL_LIGHTING ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0.0, 100.0, 0.0, 100.0 ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glColor3ub( 0, 0, 0 ); glRasterPos2i( 10, 10 ); // render the live character array 'text' for(int i=0; i<(int)strlen( string_list[curr_string] ); i++ ) { glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, string_list[curr_string][i] ); } } glEnable( GL_LIGHTING ); glutSwapBuffers(); }
void SetColor(int r, int g, int b) { glColor3f(r/255.0,g/255.0,b/255.0); }
void BranchStatuePart::update(Dma& dmaChain, float time, float deltaTime, SyncPoints::Part* syncPoints) { if (m_splitCounter > 1.0f) { for (uint i = 0; i < 4; ++i) m_branch[i].divide(); m_splitCounter = 0.0f; } Model::resetCollectedModelCount(); ZENIC_ASSERT(m_scene->rootNode()); m_scene->rootNode()->update(time); Model** models = Model::collectedModels(); uint modelCount = Model::collectedModelsCount(); //m_branch->setModel(static_cast<BranchModel*>(models[0])); #ifdef PS2_EMU glBegin(GL_LINE_STRIP); //glClearColorf(0.0f, 0.0f, 0.0f); glColor3f(0.0f, 1.0f, 0.0f); float fade = 1.0f; for (uint k = 0; k < modelCount; ++k) { const BranchModel* model = static_cast<const BranchModel*>(models[k]); const DataPtr<BranchModel::Vertex>& curves = model->curves(); BranchModel::Vertex* objects = curves.objects(); const Vector3& scale = model->scale(); for (uint i = 0; i < 14; ++i) { Vector3 pos(objects[i].x * scale.x, objects[i].y * scale.y, objects[i].z * scale.z); glVertex3f(pos.x, pos.y, pos.z); if (i & 1) glColor3f(0, 1, 0.0f); else glColor3f(1.0f, 0, 0.0f); } } glEnd(); #endif s32 start = Branch::beginRender(dmaChain); dmaChain.addSrcCntTag(0, VIF_UNPACK(vif::V4_32, 4, 10)); // Temporay identity matrix Matrix4 temp; temp = temp.identity(); float* matrix = temp.matrix(); for (uint i = 0; i < 16; i++) dmaChain.addFloat(*matrix++); dmaChain.endPacket(); dmaChain.addSrcCntTag(); dmaChain.add32(0); dmaChain.add32(0); dmaChain.add32(VIF_FLUSH()); //dmaChain.add32(0); dmaChain.addMscal(start); dmaChain.endPacket(); for (uint i = 0; i < 4; ++i) m_branch[i].render(dmaChain, deltaTime); m_splitCounter += deltaTime; }
void RenderWorld(void) { glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE ); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, pyramidTex); // 在纹理矩阵中移动纹理 glMatrixMode(GL_TEXTURE); glLoadIdentity(); // glTranslatef(0.0f, -tex_y, 0.0f); // glScalef(0.0f, tex_y, 0.0f); glMatrixMode(GL_MODELVIEW); #if 0 for (int i=0; i<1; i++) { glPushMatrix(); #if 0 glColor3f(0.0f, 1.0f, 1.0f); glBegin(GL_TRIANGLE_FAN); { glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.1f, 1.1f, 0.1f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.1f, 1.1f,-0.1f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.1f, 1.1f,-0.1f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f); } glEnd(); glScalef(-1.0, -1.0, -1.0); glColor3f(1.0f, 1.0f, 0.0f); glBegin(GL_TRIANGLE_FAN); { glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 0.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.1f, 1.1f, 0.1f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 0.1f, 1.1f,-0.1f); glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.1f, 1.1f,-0.1f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.1f, 1.1f, 0.1f); } glEnd(); #else glColor3f(0.0f, 1.0f, 1.0f); // DrawCone(1.1, 0.13, 4); glScalef(-1.0, -1.0, -1.0); glColor3f(1.0f, 1.0f, 0.0f); // DrawCone(1.1, 0.13, 4); #endif glPopMatrix(); } #else #if 0 //glDisable(GL_TEXTURE_2D); // glColor3f(0.0f, 1.0f, 1.0f); // ConeDraw(&sCone); // glScalef(-1.0, -1.0, -1.0); // // glColor3f(1.0f, 1.0f, 0.0f); // glColor3f(1.0f, 1.0f, 1.0f); ConeDraw(&sCone); #else // glDisable(GL_TEXTURE_2D); // glDisable(GL_BLEND); RenderRect(); #endif #endif // 重置纹理矩阵 glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); tex_y += 0.001f; }
static inline void DrawUnitColVol(const CUnit* u) { if (u->IsInVoid()) return; if (!(u->losStatus[gu->myAllyTeam] & LOS_INLOS) && !gu->spectatingFullView) return; if (!camera->InView(u->drawMidPos, u->GetDrawRadius())) return; const CollisionVolume* v = &u->collisionVolume; const bool vCustomType = (v->GetVolumeType() < CollisionVolume::COLVOL_TYPE_SPHERE); const bool vCustomDims = ((v->GetOffsets()).SqLength() >= 1.0f || math::fabs(v->GetBoundingRadius() - u->radius) >= 1.0f); GLUquadricObj* q = gluNewQuadric(); gluQuadricDrawStyle(q, GLU_FILL); glDisable(GL_DEPTH_TEST); for (const CWeapon* w: u->weapons) { glPushMatrix(); glTranslatef3(w->aimFromPos); glColor4f(1.0f, 1.0f, 0.0f, 0.4f); gluSphere(q, 1.0f, 5, 5); glPopMatrix(); glPushMatrix(); glTranslatef3(w->weaponMuzzlePos); if (w->HaveTarget()) { glColor4f(1.0f, 0.8f, 0.0f, 0.4f); } else { glColor4f(1.0f, 0.0f, 0.0f, 0.4f); } gluSphere(q, 1.0f, 5, 5); glPopMatrix(); if (w->HaveTarget()) { glPushMatrix(); glTranslatef3(w->GetCurrentTargetPos()); glColor4f(1.0f, 0.8f, 0.0f, 0.4f); gluSphere(q, 1.0f, 5, 5); glPopMatrix(); } } glColorf4(DEFAULT_VOLUME_COLOR); glEnable(GL_DEPTH_TEST); gluDeleteQuadric(q); glPushMatrix(); glMultMatrixf(u->GetTransformMatrix()); DrawObjectMidAndAimPos(u); if (v->DefaultToPieceTree()) { // draw only the piece volumes for less clutter // note: relMidPos transform is on the stack at this // point but all piece-positions are relative to pos // --> undo it glTranslatef3(-u->relMidPos * WORLD_TO_OBJECT_SPACE); DrawObjectDebugPieces(u); glTranslatef3(u->relMidPos * WORLD_TO_OBJECT_SPACE); } else { if (!v->IgnoreHits()) { // make it fade red under attack if (u->lastAttackFrame > 0 && ((gs->frameNum - u->lastAttackFrame) < 150)) { glColor3f((1.0f - ((gs->frameNum - u->lastAttackFrame) / 150.0f)), 0.0f, 0.0f); } // if drawing this, disable the DrawObjectMidAndAimPos call // DrawCollisionVolume((u->localModel).GetBoundingVolume()); DrawCollisionVolume(v); if (u->lastAttackFrame > 0 && ((gs->frameNum - u->lastAttackFrame) < 150)) { glColorf4(DEFAULT_VOLUME_COLOR); } } } if (u->shieldWeapon != nullptr) { const CPlasmaRepulser* shield = static_cast<const CPlasmaRepulser*>(u->shieldWeapon); glColor4f(0.0f, 0.0f, 0.6f, 0.35f); DrawCollisionVolume(&shield->collisionVolume); } if (vCustomType || vCustomDims) { // assume this is a custom volume glColor4f(0.5f, 0.5f, 0.5f, 0.35f); glScalef(u->radius, u->radius, u->radius); glWireSphere(&volumeDisplayListIDs[0], 20, 20); } glPopMatrix(); }
void LLPreviewTexture::draw() { updateDimensions(); LLPreview::draw(); if (!isMinimized()) { LLGLSUIDefault gls_ui; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); const LLRect& border = mClientRect; LLRect interior = mClientRect; interior.stretch( -PREVIEW_BORDER_WIDTH ); // ...border gl_rect_2d( border, LLColor4(0.f, 0.f, 0.f, 1.f)); gl_rect_2d_checkerboard( interior ); if ( mImage.notNull() ) { // Draw the texture glColor3f( 1.f, 1.f, 1.f ); gl_draw_scaled_image(interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), mImage); // Pump the texture priority F32 pixel_area = mLoadingFullImage ? (F32)MAX_IMAGE_AREA : (F32)(interior.getWidth() * interior.getHeight() ); mImage->addTextureStats( pixel_area ); if(pixel_area > 0.f) { //boost the previewed image priority to the highest to make it to get loaded first. mImage->setAdditionalDecodePriority(1.0f) ; } // Don't bother decoding more than we can display, unless // we're loading the full image. if (!mLoadingFullImage) { S32 int_width = interior.getWidth(); S32 int_height = interior.getHeight(); mImage->setKnownDrawSize(int_width, int_height); } else { // Don't use this feature mImage->setKnownDrawSize(0, 0); } if( mLoadingFullImage ) { // *TODO: Translate LLFontGL::getFontSansSerif()->renderUTF8(std::string("Receiving:"), 0, interior.mLeft + 4, interior.mBottom + 4, LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM, LLFontGL::DROP_SHADOW); F32 data_progress = mImage->mDownloadProgress; // Draw the progress bar. const S32 BAR_HEIGHT = 12; const S32 BAR_LEFT_PAD = 80; S32 left = interior.mLeft + 4 + BAR_LEFT_PAD; S32 bar_width = getRect().getWidth() - left - RESIZE_HANDLE_WIDTH - 2; S32 top = interior.mBottom + 4 + BAR_HEIGHT; S32 right = left + bar_width; S32 bottom = top - BAR_HEIGHT; LLColor4 background_color(0.f, 0.f, 0.f, 0.75f); LLColor4 decoded_color(0.f, 1.f, 0.f, 1.0f); LLColor4 downloaded_color(0.f, 0.5f, 0.f, 1.0f); gl_rect_2d(left, top, right, bottom, background_color); if (data_progress > 0.0f) { // Downloaded bytes right = left + llfloor(data_progress * (F32)bar_width); if (right > left) { gl_rect_2d(left, top, right, bottom, downloaded_color); } } } else if( !mSavedFileTimer.hasExpired() ) { // *TODO: Translate LLFontGL::getFontSansSerif()->renderUTF8(std::string("File Saved"), 0, interior.mLeft + 4, interior.mBottom + 4, LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM, LLFontGL::DROP_SHADOW); } } } }
//GLUT display callback void display( void ) { ClearScreen(); glColor3f(1.0,1.0,1.0); draw_figure(data); }
void BbqGeoRefdTerrainRenderer<HeightType, HeightDeltaType, TextureType >::render( BbqTerrNode *rootNode, const BbqRenderOptions &options ) { _oStatistics.nodeCount = 0; _oStatistics.triangleCount = 0; traversalStack_.push_back(rootNode); // activate the shader: // glUseProgramObjectARB( terrainShader_.getProgramHandle() ); // terrainShader_.activate(options.pDrawEnv); // fprintf(stderr, "Frame start\n"); while(!traversalStack_.empty()) { BbqTerrNode *node = traversalStack_.back(); assert(node); traversalStack_.pop_back(); #ifdef GV_CHECK // cull this node->. if( options.enableFrustumCulling && !isIntersecting( options.frustum, node->boundingBox ) ) { // not visible at all _oStatistics.culledNodeCount++; continue; } #endif const Real32 detailFactor = options.screenSpaceError; //todo: i need to use the distance to Pnt3f bboxCenter; Vec3f dist; node->boundingBox.getCenter(bboxCenter); /* fprintf(stderr, "%d %f %f %f\n", node->id, bboxCenter[0], bboxCenter[1], bboxCenter[2]); */ dist = options.viewerpos - bboxCenter; const float distance = osgMax(dist.length(), 0.001f); // const float distance = osgMax( // getMagnitude( options.frustum.getPosition() - // node->boundingBox.getCenter() ), 0.001f ); //// todo: instead of the size of the node, use the maximum error bound Vec3f bboxSize; node->boundingBox.getSize(bboxSize); // const float nodeSize = node->boundingBox.getSize().x; const float nodeSize = bboxSize.x(); // const float fovY = options.frustum.getFovY(); const float fovY = options.fovy; const float screenResolution = float( options.screenSize.y() ) / fovY; #if 0 //Unused const float nodeError = screenResolution * ( ( nodeSize / float( _oDatabaseInfo.heightTileSize ) ) / distance ); const float objectSpaceHeightError = float( node->maxHeightError ) / 32767.0f * _oDatabaseInfo.heightScale + _oDatabaseInfo.heightOffset; // 65535.0f * _oDatabaseInfo.heightScale + _oDatabaseInfo.heightOffset; const float screenSpaceHeightError = ( objectSpaceHeightError / distance ) * screenResolution; const float screenFactor = float( options.screenSize.y() ) / ( 2.0f * tanf( fovY / 2.0f ) ); const float screenSpaceHeightError2 = ( objectSpaceHeightError / distance ) * screenFactor; const float switchDistance2 = ( objectSpaceHeightError / detailFactor ) * screenFactor; #endif // todo: geomorphing geht noch nicht richtig... Vec3f disp = options.viewerpos - bboxCenter; // options.frustum.getPosition() - node->boundingBox.getCenter(); // Vec3f extent = node->boundingBox.getSize(); Vec3f extent; node->boundingBox.getSize(extent); disp[0] = osgMax( 0.0f, fabsf( disp.x() ) - extent.x() ); disp[1] = osgMax( 0.0f, fabsf( disp.y() ) - extent.y() ); disp[2] = osgMax( 0.0f, fabsf( disp.z() ) - extent.z() ); // disp.y = 0; // for debugging // float d = 0; // d = osgSqrt( dot( disp, disp ) ); // d = osgSqrt( disp.dot(disp) ); // float // const float tan_half_FOV = tanf(0.5f * horizontal_FOV_degrees // * (float) M_PI / 180.0f); // // const float K = screen_width_pixels / tan_half_FOV; // // distance_LODmax is the distance below which we need to be // // at the maximum LOD. It's used in compute_lod(), which is // // called by the chunks during update(). // m_distance_LODmax = ; // return fmax(1, d / (objectSpaceHeightError / detailFactor) * K); //} //float switchDistance2 = ( objectSpaceHeightError / detailFactor ) * //screenFactor; //float switchDistance = ( objectSpaceHeightError / detailFactor ) * //screenFactor; float switchDistance = ( nodeSize / float( _oDatabaseInfo.heightTileSize ) ) / detailFactor * screenResolution; float geomorphStartDistance = switchDistance + 145.0f; //const bool hasEnoughDetail = nodeError < detailFactor; /* fprintf(stderr, "%f | %f\n", distance, geomorphStartDistance); */ if( node->isLeafNode() || distance > geomorphStartDistance ) { // render the node: #ifndef GV_TEST Inherited::setGeoMorphingFactor( node ); #else _oTerrainShader.setUniform( "geoMorphFactor", options.geoMorphFactor ); #endif renderNodeVbo( node, options.showSkirts, options ); if( options.showBoundingBoxes ) { glColor3f( 0, 0, 1 ); this->renderBoundingBox( node->boundingBox, options ); } if( options.showSwitchDistance ) { // Pnt3f bboxCenter; node->boundingBox.getCenter(bboxCenter); glColor3f( 0, 1, 0 ); Inherited::renderSphere(bboxCenter , switchDistance, options ); } } else { // compute the geomorphing factor: //const float innerSwitchDistance = switchDistance - //switchDistance / 4.0f; node->geoMorphingFactor = clamp( 1.0f - ( switchDistance - distance ) / ( geomorphStartDistance - switchDistance ), 0.0f, 1.0f ); //node->geoMorphingFactor = 1.0f; // push the child nodes: // todo: push the nearest child last.. (to get a rough front to // back rendering order) static int order[ 4 ] = { 0, 1, 2, 3 }; //static float dist[ 4 ]; //if( options.sortChildren ) //{ // for( int i = 0; i < 4; ++i ) // { // dist[ i ] = getMagnitude( node->children[ i //]->boundingBox.getCenter() - options.frustum.getPosition() ); // for( int j = 0; j < i; ++j ) // { // if( dist[ i ] < // } // } //} traversalStack_.push_back( node->children[ order[ 0 ] ] ); traversalStack_.push_back( node->children[ order[ 1 ] ] ); traversalStack_.push_back( node->children[ order[ 2 ] ] ); traversalStack_.push_back( node->children[ order[ 3 ] ] ); } } glColor3f(1.f, 0.f, 0.f); glBegin(GL_QUADS); { glVertex3f(rootNode->boundingBox.getMin().x(), 0.f, rootNode->boundingBox.getMin().z()); glVertex3f(rootNode->boundingBox.getMax().x(), 0.f, rootNode->boundingBox.getMin().z()); glVertex3f(rootNode->boundingBox.getMax().x(), 0.f, rootNode->boundingBox.getMax().z()); glVertex3f(rootNode->boundingBox.getMin().x(), 0.f, rootNode->boundingBox.getMax().z()); } glEnd(); static bool dumpBox = false; if(dumpBox == false) { fprintf(stderr, "%f %f | %f %f\n", rootNode->boundingBox.getMin().x(), rootNode->boundingBox.getMin().z(), rootNode->boundingBox.getMax().x(), rootNode->boundingBox.getMax().z()); dumpBox = true; } // glUseProgramObjectARB( 0 ); // _oTerrainShader.deactivate(options.pDrawEnv); }
void do_buoys() { unsigned long long T = gettimeofday() / 1000000; // seconds for (unsigned i=0; i<NUM_BUOYS; i++) { #ifdef CYCLE_COLORS // small t is number of periods of time BUOY_COLOR_PERIOD[i] unsigned long long t = (unsigned long long) ((double)T / BUOY_COLOR_PERIOD[i]); if (i == 0) // cycle color on each period glColor3f ( 1.0f, 0.0f, 0.0f ); else{ if (t % 3 == (i-1) % 3) glColor3f ( 0.0f, 1.0f, 0.0f ); else if (t % 3 == i % 3) glColor3f ( 1.0f, 0.0f, 0.0f ); else glColor3f ( 1.0f, 1.0f, 0.0f ); } #else if (i == 0) // static colours glColor3f ( 0.0f, 1.0f, 0.0f ); else if (i == 1) glColor3f ( 1.0f, 0.0f, 0.0f ); else glColor3f ( 1.0f, 1.0f, 0.0f); #endif glTranslatef(buoys_v[i].x, buoys_v[i].y, buoys_v[i].z); glRotatef(90, 1.0, 0.0, 0.0); if (BUOY_CYLINDRICAL[i]) { glTranslatef(0, 0, -0.25); gluCylinder(buoys[2 * i], /*BASE_RADIUS*/ .05,//double size /*TOP_RADIUS*/ .05, /*HEIGHT*/ .25, /*SLICES*/ 30, /*STACKS*/ 5); } else { glScalef(1.0, 1.0, 1.4); gluSphere(buoys[2 * i], /* radius*/ .12,//double size /* slices*/ 40, /* stacks*/ 40); } // supports // RZ - remove for now glColor3f ( 0.0f, 0.0f, 0.0f ); //gluCylinder(buoys[2 * i + 1], // /*BASE_RADIUS*/ .01, // /*TOP_RADIUS*/ .01, // /*HEIGHT*/ buoys_v[i].y, // /*SLICES*/ 10, // /*STACKS*/ 10); glRotatef(-90, 1.0, 0.0, 0.0); glTranslatef(-buoys_v[i].x, -buoys_v[i].y, -buoys_v[i].z); } }
//core elements static void arch() { int i, numSlices; double angle; double angInc; glPushMatrix(); glTranslatef(0,0.5,0); glScalef(4,1,2); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(-1.5,-1 ,0); glScalef(1,4,2); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(1.5, -1,0); glScalef(1,4,2); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, blueWindows); glMaterialfv(GL_FRONT, GL_DIFFUSE, blueWindows); glTranslatef(0,-1.5,0); glScalef(2,3.25,0.125); glutSolidCube(1); glMaterialfv(GL_FRONT, GL_AMBIENT, brickMat); glMaterialfv(GL_FRONT, GL_DIFFUSE, brickMat); glPopMatrix(); glPushMatrix(); glTranslatef(0,-1.75,0); glScalef(3.0,0.25,0.25); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(0.5,-2,0); glScalef(0.25,4,0.25); glutSolidCube(1); glPopMatrix(); glPushMatrix(); glTranslatef(-0.5,-2,0); glScalef(0.25,4,0.25); glutSolidCube(1); glPopMatrix(); numSlices = 20; angle = 0; angInc = 3.14159/(2 * numSlices); for (i = 0; i < numSlices; i++) { glNormal3f(0,0,1); glBegin(GL_POLYGON); glVertex3f(1,0,1); // corner glVertex3f( cos(angle) , sin(angle)-1, 1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, 1); glEnd(); glBegin(GL_POLYGON); glVertex3f(-1,0,1); // corner glVertex3f(- cos(angle) , sin(angle)-1, 1); glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, 1); glEnd(); //--- glNormal3f(0,0,-1); glBegin(GL_POLYGON); glVertex3f(1,0,-1); // corner glVertex3f( cos(angle) , sin(angle)-1, -1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glBegin(GL_POLYGON); glVertex3f(-1,0,-1); // corner glVertex3f(- cos(angle) , sin(angle)-1, -1); glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); // vault glNormal3f(-cos(angle+angInc/2),-sin(angle+angInc/2),0); glColor3f(0,0,1); glBegin(GL_POLYGON); glVertex3f( cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( cos(angle) , sin(angle)-1, -1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glBegin(GL_POLYGON); glVertex3f( cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( cos(angle+angInc) , sin(angle+angInc)-1, 1); glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glNormal3f(cos(angle+angInc/2),-sin(angle+angInc/2),0); glBegin(GL_POLYGON); glVertex3f( - cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( -cos(angle) , sin(angle)-1, -1); glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); glBegin(GL_POLYGON); glVertex3f( - cos(angle) , sin(angle)-1 ,1); // corner glVertex3f( -cos(angle+angInc) , sin(angle+angInc)-1, 1); glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1); glEnd(); angle += angInc; } }