void ofxSosoRenderer::setupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip, float fov, float nearDist, float farDist) { if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); float eyeX = viewW / 2; float eyeY = viewH / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; float aspect = (float) viewW / viewH; if(nearDist == 0) nearDist = dist / 10.0f; if(farDist == 0) farDist = dist * 10.0f; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov, aspect, nearDist, farDist); //glMatrixMode(GL_MODELVIEW); //from ofGLRenderer //glLoadIdentity(); //from ofGLRenderer //gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0); //from ofGLRenderer gluLookAt(0, 0, dist, 0, 0, 0, 0, 1, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //note - theo checked this on iPhone and Desktop for both vFlip = false and true if(ofDoesHWOrientation()){ if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } }else{ if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation(); switch(orientation) { case OF_ORIENTATION_180: glRotatef(-180, 0, 0, 1); if(vFlip){ glScalef(1, -1, 1); glTranslatef(-width, 0, 0); }else{ glTranslatef(-width, -height, 0); } break; case OF_ORIENTATION_90_RIGHT: glRotatef(-90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); }else{ glScalef(-1, -1, 1); glTranslatef(0, -height, 0); } break; case OF_ORIENTATION_90_LEFT: glRotatef(90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); glTranslatef(-width, -height, 0); }else{ glScalef(-1, -1, 1); glTranslatef(-width, 0, 0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } break; } } }
// draw_characterを改変して使ってみる void draw_one_character(s_character *character) { GLfloat color_body[4]; GLfloat color_eye[4] = {0.6, 0.0, 0.0, 1.0}; double pos_base[3] = {-0.27, 0.0, 0.27}; double pos_x, pos_y, pos_z; e_color color; int i; //ここだけ変えた pos_x = character->x; pos_y = character->y; pos_z = character->z; color = character->color; // set color color_body[0] = color_val[color][0]; color_body[1] = color_val[color][1]; color_body[2] = color_val[color][2]; color_body[3] = 1.0; // start drawing an object glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, color_body); glMaterialfv(GL_FRONT, GL_DIFFUSE, color_body); glMaterialfv(GL_FRONT, GL_SPECULAR, color_body); glMaterialf(GL_FRONT, GL_SHININESS, 80.0); glTranslatef(pos_x, pos_y, pos_z); // 動いてる向きに回転させる if (character->speed < 0) { glRotatef(90.0f, 0.0f, 0.0f, 1.0f); } else { glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); } // body draw_rectangle(0.5, 0.8, 0.3, 0.0, -0.1, 0.0); // head draw_rectangle(0.3, 0.3, 0.3, 0.0, 0.3, 0.2); for (i = 0; i < 3; i++) { // right // baseleg draw_rectangle(0.4, 0.07, 0.07, -0.2, pos_base[i] - 0.1, 0.0); // endleg draw_rectangle(0.07, 0.07, 0.3, -0.4, pos_base[i] - 0.1, -0.15); // left // baseleg draw_rectangle(0.4, 0.07, 0.07, 0.2, pos_base[i] - 0.1, 0.0); // endleg draw_rectangle(0.07, 0.07, 0.3, 0.4, pos_base[i] - 0.1, -0.15); } glMaterialfv(GL_FRONT, GL_AMBIENT, color_eye); glMaterialfv(GL_FRONT, GL_DIFFUSE, color_eye); glMaterialfv(GL_FRONT, GL_SPECULAR, color_eye); glMaterialf(GL_FRONT, GL_SHININESS, 80.0); // eyes draw_rectangle(0.05, 0.05, 0.05, 0.07, 0.45, 0.25); draw_rectangle(0.05, 0.05, 0.05, -0.07, 0.45, 0.25); // finish drawing an object glPopMatrix(); }
// Primary GLUT callback loop function //***************************************************************************** void DisplayGL() { // update the simulation, unless paused double dProcessingTime = 0.0; if (!bPause) { // start timer FUNCTIME if it's update time if (iFrameCount >= iFrameTrigger) { shrDeltaT(FUNCTIME); } // Run the simlation computations shrLog("\n %d \n\n", ZZ); nbody->update(activeParams.m_timestep); nbody->getArray(BodySystem::BODYSYSTEM_POSITION); ZZ++; // Make graphics work with or without CL/GL interop if (bUsePBO) { renderer->setPBO((unsigned int)nbody->getCurrentReadBuffer(), nbody->getNumBodies()); } else { renderer->setPositions((float*)nbody->getCurrentReadBuffer(), nbody->getNumBodies()); } // get processing time from timer FUNCTIME, if it's update time if (iFrameCount >= iFrameTrigger) { dProcessingTime = shrDeltaT(FUNCTIME); } } // Redraw main graphics display, if enabled glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (displayEnabled) { // view transform glMatrixMode(GL_MODELVIEW); glLoadIdentity(); for (int c = 0; c < 3; ++c) { camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia; camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia; } glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]); glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0); glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0); renderer->setSpriteSize(activeParams.m_pointSize); renderer->display(displayMode); } // Display user interface if enabled if (bShowSliders) { glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color glEnable(GL_BLEND); paramlist->Render(0, 0); glDisable(GL_BLEND); } // Flip backbuffer to screen glutSwapBuffers(); // If frame count has triggerd, increment the frame counter, and do fps stuff if (iFrameCount++ > iFrameTrigger) { // If tour mode is enabled & interval has timed out, switch to next tour/demo mode /*dElapsedTime += shrDeltaT(DEMOTIME); if (bTour && (dElapsedTime > demoTime)) { dElapsedTime = 0.0; activeDemo = (activeDemo + 1) % numDemos; SelectDemo(activeDemo); }*/ // get the perf and fps stats iFramesPerSec = (int)((double)iFrameCount/ shrDeltaT(FPSTIME)); double dGigaInteractionsPerSecond = 0.0; double dGigaFlops = 0.0; ComputePerfStats(dGigaInteractionsPerSecond, dGigaFlops, dProcessingTime, 1); // If not paused, set the display window title, reset trigger and log info char cTitle[256]; if(!bPause) { #ifdef GPU_PROFILING #ifdef _WIN32 sprintf_s(cTitle, "OpenCL for GPU Nbody Demo (%d bodies): %i fps | %0.4f BIPS | %0.4f GFLOP/s", numBodies, iFramesPerSec, dGigaInteractionsPerSecond, dGigaFlops); #else sprintf(cTitle, "OpenCL for GPU Nbody Demo (%d bodies): %i fps | %0.4f BIPS | %0.4f GFLOP/s", numBodies, iFramesPerSec, dGigaInteractionsPerSecond, dGigaFlops); #endif #else #ifdef _WIN32 sprintf_s(cTitle, "OpenCL for GPU Nbody Demo (%d bodies)", numBodies, iFramesPerSec, dGigaInteractionsPerSecond); #else sprintf(cTitle, "OpenCL for GPU Nbody Demo (%d bodies)", numBodies, iFramesPerSec, dGigaInteractionsPerSecond); #endif #endif glutSetWindowTitle(cTitle); // Log fps and processing info to console and file shrLog("%s\n", cTitle); // if doing quick test, exit if ((bNoPrompt) && (!--iTestSets)) { // Cleanup up and quit shrQAFinish2(false, *pArgc, (const char **)pArgv, QA_PASSED); Cleanup(EXIT_SUCCESS); } // reset the frame counter and adjust trigger iFrameCount = 0; iFrameTrigger = (iFramesPerSec > 1) ? iFramesPerSec * 2 : 1; } } glutReportErrors(); }
void LowerLeg(char solid) { float k, l; #ifdef LIGHT SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess); #endif glColor3f(1.0, 1.0, 0.0); for (k = 0.0; k < 2.0; k++) { for (l = 0.0; l < 2.0; l++) { glPushMatrix(); glTranslatef(k, 0.0, l); #ifdef LIGHT SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess); #endif glColor3f(1.0, 1.0, 0.0); Box(1.0, 0.5, 1.0, solid); glTranslatef(0.0, -0.45, 0.0); #ifdef LIGHT SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2); #endif glColor3f(0.5, 0.5, 0.5); #ifdef SPHERE if (!solid) glutWireSphere(0.2, 16, 10); else glutSolidSphere(0.2, 16, 10); #endif if (leg) glRotatef((GLfloat) heel1, 1.0, 0.0, 0.0); else glRotatef((GLfloat) heel2, 1.0, 0.0, 0.0); /* glTranslatef(0.0, -0.2, 0.0); */ glTranslatef(0.0, -1.7, 0.0); #ifdef LIGHT SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess); #endif glColor3f(1.0, 1.0, 0.0); Box(0.25, 3.0, 0.25, solid); glTranslatef(0.0, -1.7, 0.0); #ifdef LIGHT SetMaterial(mat_specular2, mat_ambient2, mat_diffuse2, mat_shininess2); #endif glColor3f(0.5, 0.5, 0.5); #ifdef SPHERE if (!solid) glutWireSphere(0.2, 16, 10); else glutSolidSphere(0.2, 16, 10); #endif if (leg) glRotatef((GLfloat) - heel1, 1.0, 0.0, 0.0); else glRotatef((GLfloat) - heel2, 1.0, 0.0, 0.0); glTranslatef(0.0, -0.45, 0.0); #ifdef LIGHT SetMaterial(mat_specular, mat_ambient, mat_diffuse, mat_shininess); #endif glColor3f(1.0, 1.0, 0.0); Box(1.0, 0.5, 1.0, solid); if (!k && !l) { int j; glTranslatef(-0.4, -0.8, 0.5); if (leg) glRotatef((GLfloat) ankle1, 1.0, 0.0, 0.0); else glRotatef((GLfloat) ankle2, 1.0, 0.0, 0.0); glRotatef(90.0, 0.0, 1.0, 0.0); if (!solid) gluQuadricDrawStyle(qobj, GLU_LINE); gluCylinder(qobj, 0.8, 0.8, 1.8, 16, 10); for (j = 0; j < 2; j++) { if (!solid) gluQuadricDrawStyle(qobj, GLU_LINE); if (j) { glScalef(-1.0, 1.0, 1.0); glTranslatef(0.0, 0.0, 1.8); } gluDisk(qobj, 0.0, 0.8, 16, 10); if (j) glTranslatef(0.0, 0.0, -1.8); } glScalef(-1.0, 1.0, 1.0); glRotatef(-90.0, 0.0, 1.0, 0.0); glTranslatef(0.95, -0.8, 0.0); glCallList(SOLID_MECH_FOOT); } glPopMatrix(); } } }
void DisplayScene() { // kolor tła - zawartość bufora koloru glClearColor(1.0, 1.0, 1.0, 1.0); // czyszczenie bufora koloru i bufora głębokości glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // wybór macierzy modelowania glMatrixMode(GL_MODELVIEW); // macierz modelowania = macierz jednostkowa glLoadIdentity(); // przesunięcie układu współrzędnych obiektów do środka bryły odcinania glTranslatef(0.0, 0.0, -(near + far) / 2); // obroty obiektu glRotatef(rotatex, 1.0, 0.0, 0.0); glRotatef(rotatez, 0.0, 0.0, 1.0); // skalowanie obiektu - klawisze "+" i "-" glScalef(scale, scale, scale); // włączenie testu bufora głębokości glEnable(GL_DEPTH_TEST); // włączenie teksturowania dwuwymiarowego glEnable(GL_TEXTURE_2D); // filtr powiększający glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // filtr pomniejszający glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter); // dowiązanie wybranej tekstury glBindTexture(GL_TEXTURE_2D, texture); // ustawienie parametów środowiska tekstur glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); // utworzenie kwadryki GLUquadricObj *quadobj = gluNewQuadric(); // styl (wygląd) generowanej kwadryki gluQuadricDrawStyle(quadobj, GLU_FILL); // sposób generacji wektorów normalnych gluQuadricNormals(quadobj, GLU_SMOOTH); // nałożenie tekstury na kwadrykę gluQuadricTexture(quadobj, GL_TRUE); // narysowanie kuli gluSphere(quadobj, 1.0, 30, 30); // usunięcie kwadryki gluDeleteQuadric(quadobj); // wyłączenie teksturowania dwuwymiarowego glDisable(GL_TEXTURE_2D); // informacje o wybranych parametrach bieżącej tekstury char string[200]; GLfloat var; glColor3fv(Black); // wartość priorytetu tekstury glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, &var); sprintf_s(string, "GL_TEXTURE_PRIORITY = %f", var); DrawString(2, 2, string); // czy tekstura jest rezydentna glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_RESIDENT, &var); if (var == GL_FALSE) strcpy_s(string, "GL_TEXTURE_RESIDENT = GL_FALSE"); else strcpy_s(string, "GL_TEXTURE_RESIDENT = GL_TRUE"); DrawString(2, 16, string); // szerokość tekstury (poziom 0) glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &var); sprintf_s(string, "GL_TEXTURE_WIDTH = %f", var); DrawString(2, 30, string); // wysokość tekstury (poziom 0) glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &var); sprintf_s(string, "GL_TEXTURE_HEIGHT = %f", var); DrawString(2, 46, string); // skierowanie poleceñ do wykonania glFlush(); // zamiana buforów koloru glutSwapBuffers(); }
void XMLScene::parseGraph(Graph &graphScene){ if (graphElement == NULL){ printf("graph element not found\n"); exit(-1); } else { printf("processing graph\n"); temp = graphElement->Attribute("rootid"); string atualnode = graphElement->Attribute("rootid"); if(temp.empty()){ printf("graph attribute rootid not found\n"); exit(-1); } else { printf(">> graph rootid: %s\n", atualnode.c_str()); graphScene.rootNode = graphElement->Attribute("rootid"); } TiXmlElement *node = graphElement->FirstChildElement(); TiXmlElement *nodeElement; bool found = false; bool existsPrim; bool existsDesc; while(node){ bool displayList=false; nodeElement = NULL; temp = node->Attribute("id"); atualnode = node->Attribute("id"); if(temp.empty()){ printf("node attribute id not found\n"); exit(-1); } else { if(node->Attribute("displaylist")){ temp=node->Attribute("displaylist"); if(temp=="true") displayList=true; } existsPrim=false; existsDesc=false; printf(">> node id: %s\n",atualnode.c_str()); if ( graphScene.nodes.find(atualnode) == graphScene.nodes.end() ) { graphScene.nodes[atualnode] = Node(atualnode); graphScene.nodes[atualnode].displayList=displayList; } else{ printf(">> node %s already exists\n",atualnode.c_str()); exit(-1); } nodeElement = node->FirstChildElement("transforms"); if(nodeElement == NULL){ printf(" block transforms not found\n"); exit(-1); } else{ nodeElement = nodeElement->FirstChildElement(); glLoadIdentity(); while(nodeElement){ temp = (char *) nodeElement->Value(); if(strcmp(temp.c_str(),"transform") == 0){ printf(" transform\n"); temp = nodeElement->Attribute("type"); if(strcmp(temp.c_str(),"translate")==0) { printf(" >> type: translate\n"); temp = nodeElement->Attribute("to"); float x,y,z; if(temp.c_str() && sscanf(temp.c_str(),"%f %f %f",&x,&y,&z)==3) { printf(" >> to: %f %f %f\n", x,y,z); } else { printf(" error parsing to\n"); exit(-1); } glTranslatef(x,y,z); } else if(strcmp(temp.c_str(),"rotate")==0) { temp = nodeElement->Attribute("axis"); string axis; float angle,axisx = 0,axisy = 0, axisz = 0; if(!temp.empty()) { if(temp == "x" || temp == "y" || temp == "z"){ axis = temp; printf(" >> axis: %s\n", axis.c_str()); if(temp == "x"){ axisx = 1; } else if(temp == "y"){ axisy = 1; } else { axisz = 1; } } else{ printf(" error: wrong value of axis\n"); exit(-1); } } else { printf(" error parsing axis\n"); exit(-1); } temp = nodeElement->Attribute("angle"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&angle)==1) { printf(" >> angle: %f\n", angle); } else { printf(" error parsing angle\n"); exit(-1); } glRotatef(angle,axisx,axisy,axisz); } else if(strcmp(temp.c_str(),"scale")==0){ temp = nodeElement->Attribute("factor"); float x,y,z; if(temp.c_str() && sscanf(temp.c_str(),"%f %f %f",&x,&y,&z)==3) { printf(" >> factor: %f %f %f\n", x,y,z); } else { printf(" error parsing factor\n"); exit(-1); } glScalef(x,y,z); } else { printf(" error parsing type\n"); exit(-1); } } nodeElement = nodeElement->NextSiblingElement(); } float m[16]; glGetFloatv(GL_MODELVIEW_MATRIX, &m[0]); for(int i = 0; i<16; i++) graphScene.nodes[atualnode].matrix[i] = m[i]; } TiXmlElement * anim = node->FirstChildElement("animationref"); bool found = false; while(anim){ temp = anim->Attribute("id"); if(temp.empty()){ printf("Error parsing animationref id\n"); exit(-1); } for(size_t i = 0; i < graphScene.anims.size(); i++){ if(temp == graphScene.anims.at(i)->id){ found = true; graphScene.nodes[atualnode].anims.push_back(graphScene.anims.at(i)); break; } } if(!found){ printf("Animation %s doesn't exist\n", temp.c_str()); exit(-1); } found = false; anim = anim->NextSiblingElement("animationref"); } TiXmlElement *prim=node->FirstChildElement("primitives"); if(prim!=NULL) existsPrim=true; TiXmlElement *desc=node->FirstChildElement("descendants"); if(desc!=NULL) existsDesc=true; nodeElement = NULL; nodeElement = node->FirstChildElement("appearanceref"); if(nodeElement == NULL){ printf(" element appearanceref not found\n"); exit(-1); } else{ string id = nodeElement->Attribute("id"); if(id.empty()){ printf(" attribute id not found\n"); exit(-1); } if(id=="inherit") graphScene.nodes[atualnode].inherited=true; else{ graphScene.nodes[atualnode].inherited=false; graphScene.nodes[atualnode].appear = &graphScene.appearances[id]; } } /********************/ if(prim == NULL && !existsDesc){ printf(" blocks primitives and descendants not found\n"); exit(-1); } else if(prim !=NULL){ nodeElement = prim->FirstChildElement(); while(nodeElement){ temp = (char *) nodeElement->Value(); if(strcmp(temp.c_str(),"rectangle") == 0){ printf(" primitive rectangle\n"); float x1,x2,y1,y2; temp = nodeElement->Attribute("xy1"); if(temp.c_str() && sscanf(temp.c_str(),"%f %f",&x1, &y1)==2) { printf(" >> xy1: %f %f\n", x1, y1); } else { printf(" error parsing xy1\n"); exit(-1); } temp = nodeElement->Attribute("xy2"); if(temp.c_str() && sscanf(temp.c_str(),"%f %f",&x2, &y2)==2) { printf(" >> xy2: %f %f\n", x2, y2); } else { printf(" error parsing xy2\n"); exit(-1); } graphScene.nodes[atualnode].primitives.push_back(new Rectangle(x1,y1,x2,y2)); } else if(strcmp(temp.c_str(),"plane")==0){ printf(" primitive plane\n"); float parts; temp = nodeElement->Attribute("parts"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&parts)==1) { printf(" >> parts: %f\n",parts); } else{ printf(" error parsing parts\n"); exit(-1); } graphScene.nodes[atualnode].primitives.push_back(new Plane(parts)); } else if(strcmp(temp.c_str(),"board")==0){ printf(" Game Board\n"); graphScene.nodes[atualnode].primitives.push_back(new Board()); } else if(strcmp(temp.c_str(),"patch")==0){ printf(" primitive patch\n"); string compute; float partsU,partsV,order; temp=nodeElement->Attribute("compute"); if(!temp.empty()){ if(temp=="point" || temp=="line" || temp=="fill") compute=temp; else{ printf(" compute value error\n"); exit(-1); } } else{ printf(" error parsing compute\n"); } temp=nodeElement->Attribute("order"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&order)==1){ printf(" >> order: %f\n",order); if(order>3 || order<1){ printf(" order must be a value between 1 and 3\n"); exit(-1); } } else { printf(" error parsing order\n"); exit(-1); } temp = nodeElement->Attribute("partsU"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&partsU)==1){ printf(" >> partsU: %f\n",partsU); } else { printf(" error parsing partsU\n"); exit(-1); } temp = nodeElement->Attribute("partsV"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&partsV)==1){ printf(" >> partsV: %f\n",partsV); } else { printf(" error parsing partsV\n"); exit(-1); } TiXmlElement* ctrlpoints=nodeElement->FirstChildElement(); const int numCP = (order+1)*(order+1); int count=0; GLfloat* ctrl = new GLfloat[numCP*3]; while(ctrlpoints){ float x,y,z; temp=ctrlpoints->Attribute("x"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&x)==1){ printf(" >> x: %f\n",x); } else{ printf(" error parsing x\n"); exit(-1); } temp=ctrlpoints->Attribute("y"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&y)==1){ printf(" >> y: %f\n",y); } else{ printf(" error parsing y\n"); exit(-1); } temp=ctrlpoints->Attribute("z"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&z)==1){ printf(" >> z: %f\n",z); } else{ printf(" error parsing y\n"); exit(-1); } ctrl[count*3 + 0]=x; ctrl[count*3 + 1]=y; ctrl[count*3 + 2]=z; count++; ctrlpoints=ctrlpoints->NextSiblingElement(); } if(count!=numCP){ printf(" bad number of control points\n"); exit(-1); } GLfloat* ctPoints = new GLfloat[numCP * 3]; for(int i = 0; i < numCP; i++) { int tmp = (i%3); tmp *= ((order+1)*(order+1)); tmp += floor((float)i/3) *3; ctPoints[i*3 + 0] = ctrl[tmp + 0]; ctPoints[i*3 + 1] = ctrl[tmp + 1]; ctPoints[i*3 + 2] = ctrl[tmp + 2]; } if(cull==1) graphScene.nodes[atualnode].primitives.push_back(new Patch(order,partsU,partsV,compute,ctrl)); else graphScene.nodes[atualnode].primitives.push_back(new Patch(order,partsU,partsV,compute,ctPoints)); } else if(strcmp(temp.c_str(),"vehicle")==0){ graphScene.nodes[atualnode].primitives.push_back(new Vehicle()); } else if(strcmp(temp.c_str(),"flag")==0){ printf(" primitive vehicle\n"); string texture; temp=nodeElement->Attribute("texture"); if(temp.empty()){ printf("no texture file input\n"); exit(-1); } texture=temp; graphScene.nodes[atualnode].primitives.push_back(new Flag(texture)); } else if(strcmp(temp.c_str(),"triangle") == 0){ printf(" primitive triangle\n"); float x1,x2,x3,y1,y2,y3,z1,z2,z3; temp = nodeElement->Attribute("xyz1"); if(temp.c_str() && sscanf(temp.c_str(),"%f %f %f",&x1, &y1, &z1)==3) { printf(" >> xyz1: %f %f %f\n", x1, y1, z1); } else { printf(" error parsing xyz1\n"); exit(-1); } temp = nodeElement->Attribute("xyz2"); if(temp.c_str() && sscanf(temp.c_str(),"%f %f %f",&x2, &y2, &z2)==3) { printf(" >> xy2: %f %f %f\n", x2, y2, z2); } else { printf(" error parsing xyz2\n"); exit(-1); } temp = nodeElement->Attribute("xyz3"); if(temp.c_str() && sscanf(temp.c_str(),"%f %f %f",&x3, &y3, &z3)==3) { printf(" >> xyz3: %f %f %f\n", x3, y3, z3); } else { printf(" error parsing xyz3\n"); exit(-1); } graphScene.nodes[atualnode].primitives.push_back(new Triangle(x1,y1,z1,x2,y2,z2,x3,y3,z3)); } else if(strcmp(temp.c_str(),"torus") == 0){ printf(" primitive torus\n"); float innerradius,outerradius; int slices,loops; temp = nodeElement->Attribute("inner"); if(temp.c_str() && sscanf(temp.c_str(),"%f", &innerradius)==1) { printf(" >> inner: %f\n", innerradius); } else { printf(" error parsing inner\n"); exit(-1); } temp = nodeElement->Attribute("outer"); if(temp.c_str() && sscanf(temp.c_str(),"%f",&outerradius)==1) { printf(" >> outer: %f\n", outerradius); } else { printf(" error parsing outer\n"); exit(-1); } temp = nodeElement->Attribute("slices"); if(temp.c_str() && sscanf(temp.c_str(),"%d",&slices)==1) { printf(" >> slices: %d\n", slices); } else { printf(" error parsing slices\n"); exit(-1); } temp = nodeElement->Attribute("loops"); if(temp.c_str() && sscanf(temp.c_str(),"%d",&loops)==1) { printf(" >> loops: %d\n", loops); } else { printf(" error parsing loops\n"); exit(-1); } graphScene.nodes[atualnode].primitives.push_back(new Torus(innerradius,outerradius,slices,loops)); } else if(strcmp(temp.c_str(),"sphere") == 0){ printf(" primitive sphere\n"); float radius; int slices,stacks; temp = nodeElement->Attribute("radius"); if(temp.c_str() && sscanf(temp.c_str(),"%f", &radius)==1) { printf(" >> radius: %f\n", radius); } else { printf(" error parsing radius\n"); exit(-1); } temp = nodeElement->Attribute("slices"); if(temp.c_str() && sscanf(temp.c_str(),"%d",&slices)==1) { printf(" >> slices: %d\n", slices); } else { printf(" error parsing slices\n"); exit(-1); } temp = nodeElement->Attribute("stacks"); if(temp.c_str() && sscanf(temp.c_str(),"%d",&stacks)==1) { printf(" >> stacks: %d\n", stacks); } else { printf(" error parsing stacks\n"); exit(-1); } graphScene.nodes[atualnode].primitives.push_back(new Sphere(radius,slices,stacks)); } else if(strcmp(temp.c_str(),"cylinder") == 0){ printf(" primitive cylinder\n"); float base,top,height; int slices,stacks; temp = nodeElement->Attribute("base"); if(temp.c_str() && sscanf(temp.c_str(),"%f", &base)==1) { printf(" >> base: %f\n", base); } else { printf(" error parsing base\n"); exit(-1); } temp = nodeElement->Attribute("top"); if(temp.c_str() && sscanf(temp.c_str(),"%f", &top)==1) { printf(" >> top: %f\n", top); } else { printf(" error parsing top\n"); exit(-1); } temp = nodeElement->Attribute("height"); if(temp.c_str() && sscanf(temp.c_str(),"%f", &height)==1) { printf(" >> height: %f\n", height); } else { printf(" error parsing height\n"); exit(-1); } temp = nodeElement->Attribute("slices"); if(temp.c_str() && sscanf(temp.c_str(),"%d",&slices)==1) { printf(" >> outer: %d\n", slices); } else { printf(" error parsing slices\n"); exit(-1); } temp = nodeElement->Attribute("stacks"); if(temp.c_str() && sscanf(temp.c_str(),"%d",&stacks)==1) { printf(" >> outer: %d\n", stacks); } else { printf(" error parsing stacks\n"); exit(-1); } graphScene.nodes[atualnode].primitives.push_back(new Cylinder(base,top,height,slices,stacks)); } nodeElement = nodeElement->NextSiblingElement(); } } nodeElement = NULL; nodeElement = node->FirstChildElement("descendants"); string atualdescendant; if(nodeElement == NULL && !existsPrim){ printf(" blocks descendants and primitives not found\n"); exit(-1); } else if(nodeElement !=NULL){ nodeElement = nodeElement->FirstChildElement("noderef"); while(nodeElement){ temp = nodeElement->Attribute("id"); atualdescendant = nodeElement->Attribute("id"); if(temp.empty()){ printf(" error parsing noderef attribute id\n"); exit(-1); } else{ printf(" >> descendant %s\n",atualdescendant.c_str()); /*if ( graphScene.nodes.find(atualdescendant) == graphScene.nodes.end() ) { graphScene.nodes[atualdescendant] = Node(atualdescendant); } if ( graphScene.graphNodes.find(atualdescendant) == graphScene.graphNodes.end() ) { graphScene.graphNodes[atualdescendant] = GraphNode(atualdescendant); if(graphScene.nodes.find(atualdescendant) == graphScene.nodes.end()){ graphScene.nodes[atualdescendant] = Node(atualdescendant); } graphScene.graphNodes[atualdescendant].atualNode = &graphScene.nodes[atualdescendant]; } graphScene.graphNodes[atualnode].descendants[atualdescendant] = &graphScene.graphNodes[atualdescendant]; */ graphScene.nodes[atualnode].childs.push_back(atualdescendant); } nodeElement = nodeElement->NextSiblingElement(); } } } node = node->NextSiblingElement(); } } }
void TextObject::draw(bool outlined, float x, float y) { glEnable(0x84F5); //GL_TEXTURE_RECTANGLE_NV = GL_TEXTURE_RECTANGLE_ARB = 0x84F5 glBindTexture(m_texture->getType(), m_texture->getTextureId()); glPushMatrix(); glRotatef(0.0f, 0.0f, 0.0f, 1.0f); glScalef(1.0f, 1.0f, 1.0f); glColor4f(0.0f, 0.0f, 0.0f, pow(AMask, 2)); glPushMatrix(); glTranslatef(x - 1.0f, y, 0.0f); drawQuad(); glPopMatrix(); glPushMatrix(); glTranslatef(x - 1.0f, y - 1.0f, 0.0f); drawQuad(); glPopMatrix(); glPushMatrix(); glTranslatef(x, y - 1.0f, 0.0f); drawQuad(); glPopMatrix(); glPushMatrix(); glTranslatef(x + 1.0f, y - 1.0f, 0.0f); drawQuad(); glPopMatrix(); glPushMatrix(); glTranslatef(x + 1.0f, y, 0.0f); drawQuad(); glPopMatrix(); glPushMatrix(); glTranslatef(x + 1.0f, y + 1.0f, 0.0f); drawQuad(); glPopMatrix(); glPushMatrix(); glTranslatef(x, y + 1.0f, 0.0f); drawQuad(); glPopMatrix(); glPushMatrix(); glTranslatef(x - 1.0f, y + 1.0f, 0.0f); drawQuad(); glPopMatrix(); glColor4f(RMask, GMask, BMask, AMask); glPushMatrix(); glTranslatef(x, y, 0.0f); drawQuad(); glPopMatrix(); glPopMatrix(); glDisable(0x84F5); //GL_TEXTURE_RECTANGLE_NV = GL_TEXTURE_RECTANGLE_ARB = 0x84F5 }
void render() { glTranslatef(strafe_, pedestal_, -zoom_); glRotatef(rotation_, 0.0, 1.0, 0.0); glRotatef(pitch_, 1.0, 0.0, 0.0); }
void SampleGLView::gDraw(float rotation) { /* Clear the buffer, clear the matrix */ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); /* A step backward, then spin the cube */ glTranslatef(0, 0, -5); glRotatef(rotation, 0, 0, 1); glRotatef(rotation, 1, 0.6, 0); /* We tell we want to draw quads */ glBegin (GL_QUADS); /* Every four calls to glVertex, a quad is drawn */ glColor3f (0, 0, 0); glVertex3f (-1, -1, -1); glColor3f (0, 0, 1); glVertex3f (-1, -1, 1); glColor3f (0, 1, 1); glVertex3f (-1, 1, 1); glColor3f (0, 1, 0); glVertex3f (-1, 1, -1); glColor3f (1, 0, 0); glVertex3f ( 1, -1, -1); glColor3f (1, 0, 1); glVertex3f ( 1, -1, 1); glColor3f (1, 1, 1); glVertex3f ( 1, 1, 1); glColor3f (1, 1, 0); glVertex3f ( 1, 1, -1); glColor3f (0, 0, 0); glVertex3f (-1, -1, -1); glColor3f (0, 0, 1); glVertex3f (-1, -1, 1); glColor3f (1, 0, 1); glVertex3f ( 1, -1, 1); glColor3f (1, 0, 0); glVertex3f ( 1, -1, -1); glColor3f (0, 1, 0); glVertex3f (-1, 1, -1); glColor3f (0, 1, 1); glVertex3f (-1, 1, 1); glColor3f (1, 1, 1); glVertex3f ( 1, 1, 1); glColor3f (1, 1, 0); glVertex3f ( 1, 1, -1); glColor3f (0, 0, 0); glVertex3f (-1, -1, -1); glColor3f (0, 1, 0); glVertex3f (-1, 1, -1); glColor3f (1, 1, 0); glVertex3f ( 1, 1, -1); glColor3f (1, 0, 0); glVertex3f ( 1, -1, -1); glColor3f (0, 0, 1); glVertex3f (-1, -1, 1); glColor3f (0, 1, 1); glVertex3f (-1, 1, 1); glColor3f (1, 1, 1); glVertex3f ( 1, 1, 1); glColor3f (1, 0, 1); glVertex3f ( 1, -1, 1); /* No more quads */ glEnd (); /* End */ glFlush (); }
void draw_scene() { static float ang_self = 0.0; /*Define the angle of self-rotate */ static float angle = 0.0; glLightfv(GL_LIGHT4, GL_POSITION, lit4_position); glLightfv(GL_LIGHT4, GL_SPOT_DIRECTION, lit4_direction); glLightfv(GL_LIGHT5, GL_POSITION, lit5_position); glLightfv(GL_LIGHT5, GL_SPOT_DIRECTION, lit5_direction); glLightfv(GL_LIGHT1, GL_POSITION, lit1_position); /*fixed position---*/ glDisable(GL_TEXTURE_2D); draw_floor(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glTranslatef(0.0, 0.0, 0.0); glMatrixMode(GL_MODELVIEW); draw_slope(); draw_axes(); draw_object(); /*-------Draw the billboard ----*/ glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBindTexture(GL_TEXTURE_2D, textName[2]); glEnable(GL_TEXTURE_2D); draw_billboard(5.0*4.0, -3.0*4.0, 5.0, 8.0); draw_billboard(6.0*4.0, -5.0*4.0, 5.0, 8.0); draw_billboard(3.0*4.0, -6.0*4.0, 5.0, 8.0); draw_billboard(2.0*4.0, -7.0*4.0, 5.0, 8.0); draw_billboard(7.0*4.0, -2.0*4.0, 5.0, 8.0); glDisable(GL_TEXTURE_2D); /*-------Draw the car body which is a cube----*/ glTranslatef(position[0], position[1], position[2]); glRotatef(-up_ang, 1.0, 0.0, 0.0); glRotatef(self_ang, 0.0, 1.0, 0.0); glPushMatrix(); /* Save M1 coord. sys */ draw_cube(); glPopMatrix(); /* Get M1 back */ /*-------Draw the front wheels -----*/ glColor3f(1.0, 0.0, 0.0); glPushMatrix(); /* Save M1 coord. sys */ glTranslatef(-4.0, 0.0, 3.0); /* Go to left wheel position */ glutSolidTorus(0.5, /* inner radius */ 1.0, /* outer radius */ 24, /* divided into 18 segments */ 12); /* 12 rings */ glPopMatrix(); glPushMatrix(); /* Save M1 coord. sys */ glTranslatef(-4.0, 0.0, -3.0);/* Go to right wheel position */ glutSolidTorus(0.5, /* inner radius */ 1.0, /* outer radius */ 24, /* divided into 18 segments */ 12); /* 12 rings */ glPopMatrix(); /*------Draw back wheels ----*/ glColor3f(1.0, 0.4, 0.0); glPushMatrix(); /* Save M1 coord. sys */ glTranslatef(6.0, 0.0, 0.0); /* Go to left wheel position */ glutSolidTorus(0.5, /* inner radius */ 1.0, /* outer radius */ 24, /* divided into 18 segments */ 12); /* 12 rings */ glPopMatrix(); glColor3f(1.0, 0.4, 0.4); glPushMatrix(); /* Save M1 coord. sys */ glTranslatef(0.0, 1.5, 7.5); /* Go to left wheel position */ glRotatef(-90.0, 1.0, 0.0, 0.0); glutSolidTorus(0.5, /* inner radius */ 3.0, /* outer radius */ 24, /* divided into 18 segments */ 12); /* 12 rings */ glPopMatrix(); glColor3f(1.0, 0.4, 0.4); glPushMatrix(); /* Save M1 coord. sys */ glTranslatef(0.0, 1.5, -7.5); /* Go to left wheel position */ glRotatef(-90.0, 1.0, 0.0, 0.0); glutSolidTorus(0.5, /* inner radius */ 3.0, /* outer radius */ 24, /* divided into 18 segments */ 12); /* 12 rings */ glPopMatrix(); glColor3f(1.0, 1.0, 1.0); glPushMatrix(); glTranslatef(0.0, 1.5, 7.5); glRotatef(bld_ang, 0.0, 1.0, 0.0); draw_blade();/* draw the first blade */ glRotatef(120, 0.0, 1.0, 0.0); draw_blade();/* draw the first blade */ glRotatef(120, 0.0, 1.0, 0.0); draw_blade();/* draw the first blade */ glPopMatrix(); glColor3f(1.0, 1.0, 1.0); glPushMatrix(); glTranslatef(0.0, 1.5, -7.5); glRotatef(bld_ang, 0.0, 1.0, 0.0); draw_blade(); glRotatef(120, 0.0, 1.0, 0.0); draw_blade(); glRotatef(120, 0.0, 1.0, 0.0); draw_blade(); glPopMatrix(); }
void Robot::draw() const { // Retrieve the current (interpolated) pose of the robot. Pose pose = getPose(); // You can set the robot to be whatever color you like. // By default it is white. glPushMatrix(); glMatrixMode(GL_MODELVIEW); //BODY glColor4d(1, 1, 1, 1); glTranslatef(pose.x_, pose.y_,pose.z_); glRotatef(pose.angles_[BODY_ANGLE], 0, 0, 1); drawCuboid(BODY_X,BODY_LEN,BODY_Z); //HEAD glPushMatrix(); glTranslatef(0,BODY_LEN/2,0); glRotatef(pose.angles_[HEAD_ANGLE], 0, 0, 1); glTranslatef(0,.3,0); drawCuboid(.6,.6,.6); glPopMatrix(); // ARMS!! //Right glPushMatrix(); glTranslatef(0, BODY_LEN/2.0, BODY_Z/2.0 + UARM_WIDTH/2.0); //Move to shoulder joint from center of body drawArm(pose, RIGHT_SHOULDER, RIGHT_ELBOW); glPopMatrix(); //Left glPushMatrix(); glTranslatef(0, BODY_LEN/2.0, - (BODY_Z/2.0 + UARM_WIDTH/2.0)); //Move to shoulder joint from center of body drawArm(pose, LEFT_SHOULDER, LEFT_ELBOW); glPopMatrix(); //LEGS //RIGHT glPushMatrix(); glTranslatef(0, -1, .25); drawLeg(pose, RIGHT_HIP, RIGHT_KNEE, RIGHT_ANKLE); glPopMatrix(); //LEFT glPushMatrix(); glTranslatef(0, -1, -.25); drawLeg(pose, LEFT_HIP, LEFT_KNEE, LEFT_ANKLE); glPopMatrix(); //WINGS //RIGHT glPushMatrix(); glTranslatef(-BODY_X/2.0,BODY_LEN/2.0 -.2,BODY_Z/2.0 - .2); drawWing(pose, RIGHT_WING_MID_Y, RIGHT_WING_Y, RIGHT_WING_Z); glPopMatrix(); //LEFT glPushMatrix(); glTranslatef(-BODY_X/2.0,BODY_LEN/2.0 -.2, -BODY_Z/2.0 + .2); drawWing(pose, LEFT_WING_MID_Y, LEFT_WING_Y, LEFT_WING_Z); glPopMatrix(); //Body matrix glPopMatrix(); }
void draw(HyperspaceSaverSettings *inSettings){ if(inSettings->first){ if(inSettings->dUseTunnels){ // only tunnels use caustic textures glDisable(GL_FOG); // Caustic textures can only be created after rendering context has been created // because they have to be drawn and then read back from the framebuffer. #ifdef WIN32 if(doingPreview) // super fast for Windows previewer inSettings->theCausticTextures = new causticTextures(8, inSettings->numAnimTexFrames, 32, 32, 1.0f, 0.01f, 10.0f); else // normal #endif inSettings->theCausticTextures = new causticTextures(8, inSettings->numAnimTexFrames, 100, 256, 1.0f, 0.01f, 20.0f); glEnable(GL_FOG); } if(inSettings->dShaders){ #ifdef WIN32 if(doingPreview) // super fast for Windows previewer inSettings->theWNCM = new wavyNormalCubeMaps(inSettings->numAnimTexFrames, 32); else // normal #endif inSettings->theWNCM = new wavyNormalCubeMaps(inSettings->numAnimTexFrames, 128); } glViewport(inSettings->viewport[0], inSettings->viewport[1], inSettings->viewport[2], inSettings->viewport[3]); inSettings->first = 0; } // Variables for printing text static float computeTime = 0.0f; static float drawTime = 0.0f; //static rsTimer computeTimer, drawTimer; // start compute time timer //computeTimer.tick(); glMatrixMode(GL_MODELVIEW); // Camera movements static float camHeading[3] = {0.0f, 0.0f, 0.0f}; // current, target, and last static int changeCamHeading = 1; static float camHeadingChangeTime[2] = {20.0f, 0.0f}; // total, elapsed static float camRoll[3] = {0.0f, 0.0f, 0.0f}; // current, target, and last static int changeCamRoll = 1; static float camRollChangeTime[2] = {1.0f, 0.0f}; // total, elapsed camHeadingChangeTime[1] += inSettings->frameTime; if(camHeadingChangeTime[1] >= camHeadingChangeTime[0]){ // Choose new direction camHeadingChangeTime[0] = rsRandf(15.0f) + 5.0f; camHeadingChangeTime[1] = 0.0f; camHeading[2] = camHeading[1]; // last = target if(changeCamHeading){ // face forward most of the time if(rsRandi(6)) camHeading[1] = 0.0f; // face backward the rest of the time else if(rsRandi(2)) camHeading[1] = RS_PI; else camHeading[1] = -RS_PI; changeCamHeading = 0; } else changeCamHeading = 1; } float t = camHeadingChangeTime[1] / camHeadingChangeTime[0]; t = 0.5f * (1.0f - cosf(RS_PI * t)); camHeading[0] = camHeading[1] * t + camHeading[2] * (1.0f - t); camRollChangeTime[1] += inSettings->frameTime; if(camRollChangeTime[1] >= camRollChangeTime[0]){ // Choose new roll angle camRollChangeTime[0] = rsRandf(5.0f) + 10.0f; camRollChangeTime[1] = 0.0f; camRoll[2] = camRoll[1]; // last = target if(changeCamRoll){ camRoll[1] = rsRandf(RS_PIx2*2) - RS_PIx2; changeCamRoll = 0; } else changeCamRoll = 1; } t = camRollChangeTime[1] / camRollChangeTime[0]; t = 0.5f * (1.0f - cosf(RS_PI * t)); camRoll[0] = camRoll[1] * t + camRoll[2] * (1.0f - t); static float pathDir[3] = {0.0f, 0.0f, -1.0f}; inSettings->thePath->moveAlongPath(float(inSettings->dSpeed) * inSettings->frameTime * 0.04f); inSettings->thePath->update(inSettings->frameTime); inSettings->thePath->getPoint(inSettings->dDepth + 2, inSettings->thePath->step, inSettings->camPos); inSettings->thePath->getBaseDirection(inSettings->dDepth + 2, inSettings->thePath->step, pathDir); float pathAngle = atan2f(-pathDir[0], -pathDir[2]); glLoadIdentity(); glRotatef((pathAngle + camHeading[0]) * RS_RAD2DEG, 0, 1, 0); glRotatef(camRoll[0] * RS_RAD2DEG, 0, 0, 1); glGetFloatv(GL_MODELVIEW_MATRIX, inSettings->billboardMat); glLoadIdentity(); glRotatef(-camRoll[0] * RS_RAD2DEG, 0, 0, 1); glRotatef((-pathAngle - camHeading[0]) * RS_RAD2DEG, 0, 1, 0); glTranslatef(inSettings->camPos[0]*-1, inSettings->camPos[1]*-1, inSettings->camPos[2]*-1); glGetDoublev(GL_MODELVIEW_MATRIX, inSettings->modelMat); inSettings->unroll = camRoll[0] * RS_RAD2DEG; if(inSettings->dUseGoo){ // calculate diagonal fov float diagFov = 0.5f * float(inSettings->dFov) / RS_RAD2DEG; diagFov = tanf(diagFov); diagFov = sqrtf(diagFov * diagFov + (diagFov * inSettings->aspectRatio * diagFov * inSettings->aspectRatio)); diagFov = 2.0f * atanf(diagFov); inSettings->theGoo->update(inSettings->camPos[0], inSettings->camPos[2], pathAngle + camHeading[0], diagFov, inSettings); } // measure compute time //computeTime += computeTimer.tick(); // start draw time timer //drawTimer.tick(); // clear glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // draw stars glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_2D, NULL); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, NULL); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, inSettings->flaretex[0]); static float temppos[2]; for(int i=0; i<inSettings->dStars; i++){ temppos[0] = inSettings->stars[i]->pos[0] - inSettings->camPos[0]; temppos[1] = inSettings->stars[i]->pos[2] - inSettings->camPos[2]; if(temppos[0] > inSettings->depth){ inSettings->stars[i]->pos[0] -= inSettings->depth * 2.0f; inSettings->stars[i]->lastPos[0] -= inSettings->depth * 2.0f; } if(temppos[0] < inSettings->depth*-1){ inSettings->stars[i]->pos[0] += inSettings->depth * 2.0f; inSettings->stars[i]->lastPos[0] += inSettings->depth * 2.0f; } if(temppos[1] > inSettings->depth){ inSettings->stars[i]->pos[2] -= inSettings->depth * 2.0f; inSettings->stars[i]->lastPos[2] -= inSettings->depth * 2.0f; } if(temppos[1] < inSettings->depth*-1){ inSettings->stars[i]->pos[2] += inSettings->depth * 2.0f; inSettings->stars[i]->lastPos[2] += inSettings->depth * 2.0f; } inSettings->stars[i]->draw(inSettings->camPos, inSettings->unroll, inSettings->modelMat, inSettings->projMat, inSettings->viewport); } glDisable(GL_CULL_FACE); // pick animated texture frame static float textureTime = 0.0f; textureTime += inSettings->frameTime; // loop frames every 2 seconds const float texFrameTime(2.0f / float(inSettings->numAnimTexFrames)); while(textureTime > texFrameTime){ textureTime -= texFrameTime; inSettings->whichTexture ++; } while(inSettings->whichTexture >= inSettings->numAnimTexFrames) inSettings->whichTexture -= inSettings->numAnimTexFrames; // alpha component gets normalmap lerp value const float lerp = textureTime / texFrameTime; // draw goo if(inSettings->dUseGoo){ // calculate color static float goo_rgb_phase[3] = {-0.1f, -0.1f, -0.1f}; static float goo_rgb_speed[3] = {rsRandf(0.02f) + 0.02f, rsRandf(0.02f) + 0.02f, rsRandf(0.02f) + 0.02f}; float goo_rgb[4]; for(int i=0; i<3; i++){ goo_rgb_phase[i] += goo_rgb_speed[i] * inSettings->frameTime; if(goo_rgb_phase[i] >= RS_PIx2) goo_rgb_phase[i] -= RS_PIx2; goo_rgb[i] = sinf(goo_rgb_phase[i]); if(goo_rgb[i] < 0.0f) goo_rgb[i] = 0.0f; } // setup textures if(inSettings->dShaders){ goo_rgb[3] = lerp; glDisable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_CUBE_MAP_ARB); glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->nebulatex); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->theWNCM->texture[(inSettings->whichTexture + 1) % inSettings->numAnimTexFrames]); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, inSettings->theWNCM->texture[inSettings->whichTexture]); glUseProgramObjectARB(gooProgram); } else{ goo_rgb[3] = 1.0f; glBindTexture(GL_TEXTURE_2D, inSettings->nebulatex); glEnable(GL_TEXTURE_2D); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); } // draw it glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_BLEND); glColor4fv(goo_rgb); inSettings->theGoo->draw(); if(inSettings->dShaders){ glDisable(GL_TEXTURE_CUBE_MAP_ARB); glUseProgramObjectARB(0); } else{ glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } } // update starburst static float starBurstTime = 300.0f; // burst after 5 minutes starBurstTime -= inSettings->frameTime; if(starBurstTime <= 0.0f){ float pos[] = {inSettings->camPos[0] + (pathDir[0] * inSettings->depth * (0.5f + rsRandf(0.5f))), rsRandf(2.0f) - 1.0f, inSettings->camPos[2] + (pathDir[2] * inSettings->depth * (0.5f + rsRandf(0.5f)))}; inSettings->theStarBurst->restart(pos); // it won't actually restart unless it's ready to starBurstTime = rsRandf(240.0f) + 60.0f; // burst again within 1-5 minutes } if(inSettings->dShaders) inSettings->theStarBurst->draw(lerp, inSettings); else inSettings->theStarBurst->draw(inSettings); // draw tunnel if(inSettings->dUseTunnels){ inSettings->theTunnel->make(inSettings->frameTime, inSettings->dShaders); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); if(inSettings->dShaders){ glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, inSettings->theCausticTextures->caustictex[(inSettings->whichTexture + 1) % inSettings->numAnimTexFrames]); glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, inSettings->theCausticTextures->caustictex[inSettings->whichTexture]); glUseProgramObjectARB(tunnelProgram); inSettings->theTunnel->draw(lerp); glUseProgramObjectARB(0); } else{ glBindTexture(GL_TEXTURE_2D, inSettings->theCausticTextures->caustictex[inSettings->whichTexture]); inSettings->theTunnel->draw(); } glDisable(GL_CULL_FACE); } // draw sun with lens flare glDisable(GL_FOG); float flarepos[3] = {0.0f, 2.0f, 0.0f}; glBindTexture(GL_TEXTURE_2D, inSettings->flaretex[0]); inSettings->sunStar->draw(inSettings->camPos, inSettings->unroll, inSettings->modelMat, inSettings->projMat, inSettings->viewport); float diff[3] = {flarepos[0] - inSettings->camPos[0], flarepos[1] - inSettings->camPos[1], flarepos[2] - inSettings->camPos[2]}; float alpha = 0.5f - 0.005f * sqrtf(diff[0] * diff[0] + diff[1] * diff[1] + diff[2] * diff[2]); if(alpha > 0.0f) flare(flarepos, 1.0f, 1.0f, 1.0f, alpha, inSettings); glEnable(GL_FOG); // measure draw time //drawTime += drawTimer.tick(); // write text static float totalTime = 0.0f; totalTime += inSettings->frameTime; static std::vector<std::string> strvec; static int frames = 0; ++frames; if(frames == 60){ strvec.clear(); std::string str1 = " FPS = " + to_string(60.0f / totalTime); strvec.push_back(str1); std::string str2 = "compute time = " + to_string(computeTime / 60.0f); strvec.push_back(str2); std::string str3 = " draw time = " + to_string(drawTime / 60.0f); strvec.push_back(str3); totalTime = 0.0f; computeTime = 0.0f; drawTime = 0.0f; frames = 0; } if(inSettings->kStatistics){ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0f, 50.0f * inSettings->aspectRatio, 0.0f, 50.0f, -1.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(1.0f, 48.0f, 0.0f); glColor3f(1.0f, 0.6f, 0.0f); inSettings->textwriter->draw(strvec); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); } #ifdef WIN32 wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE); #endif #ifdef RS_XSCREENSAVER glXSwapBuffers(xdisplay, xwindow); #endif }
bool MapDraw::drawAnt(Creature* a, bool animate) { // top-right - white tm->nextTexture(1); // ant dead? if (a->getHP() <= 0) material( 15,10,10 ); else material(3,3,3); // exit early if not visible. if (! isVisible(a->getX(), a->getY())) return false; // find X/Y location by finding offset from center. // Then add the offset for smoothly moving between 2 squares. //TODO: Why do I need to add 1 to a->getX() ?!? float x = (positionX(a->getX()+1)*MODEL_SCALE) + (a->getOffsetX()*MODEL_SCALE_INCREMENT); float y = (positionY(a->getY())*MODEL_SCALE) + (a->getOffsetY()*MODEL_SCALE_INCREMENT); if (!animate) { StaticDraw::drawRect(x, y, MODEL_SCALE*0.2, MODEL_SCALE*.4, MODEL_SCALE*0.9, tm); return true; } // draw at x, y. // slightly off the background to get rid of overlaping. glPushMatrix(); // if X has no influence, facing right or left. // convert facing direction to measurement of 90 degrees ((-20:20) * 2.25). // (angle is -32768 to 32767) float xInfluence = ((a->getFacingX() * 2.25f)); // default facing up. float yInfluence = ((a->getFacingY() * 2.25f)); float rotation = 0; // this nonsense sets the ants rotation to face the direction its walking. // TODO: figure out how to convert this to glRotatef32i. // pointing top-left if (( a->getFacingX() <= 0 ) && (a->getFacingY() >= 0)) rotation = (-315) - (yInfluence+xInfluence); // pointing down-left else if (( a->getFacingX() <= 0 ) && (a->getFacingY() <= 0)) rotation = (-225) - (yInfluence-xInfluence); // pointing top-right else if (( a->getFacingX() > 0 ) && (a->getFacingY() >= 0)) rotation = (-45) + (yInfluence-xInfluence); // pointing down-right else if (( a->getFacingX() > 0 ) && (a->getFacingY() <= 0)) rotation = (-135) + (yInfluence+xInfluence); // translate to the center point. glTranslatef(x, y, 0.01); // rotate so the ant faces in the correct direction. glRotatef( rotation , 0, 0, 1); if (a->getType() == ANT_WORKER) drawWorker( a->getCarrying() ); else if (a->getType() == ANT_QUEEN) drawQueen( a->getCarrying() ); // queens don't carry anything, but whatev. glPopMatrix(1); return true; }
void RenderCamera() { glRotatef(view_rotx, 1.0, 0.0, 0.0); glRotatef(view_roty, 0.0, 1.0, 0.0); glRotatef(view_rotz, 0.0, 0.0, 1.0); }
/* draw method for ant */ static Bool draw_ant(antspotlightstruct *mp, const GLfloat *Material, int mono, int shadow, float ant_step, Bool (*sphere)(float), Bool (*cone)(float)) { float cos1 = cos(ant_step); float cos2 = cos(ant_step + 2 * Pi / 3); float cos3 = cos(ant_step + 4 * Pi / 3); float sin1 = sin(ant_step); float sin2 = sin(ant_step + 2 * Pi / 3); float sin3 = sin(ant_step + 4 * Pi / 3); /* Apparently this is a performance killer on many systems... glEnable(GL_POLYGON_SMOOTH); */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mp->mono ? MaterialGray5 : Material); glEnable(GL_CULL_FACE); glPushMatrix(); glScalef(1, 1.3, 1); if(!((*sphere)(0.18))) return False; glScalef(1, 1 / 1.3, 1); glTranslatef(0.00, 0.30, 0.00); if(!((*sphere)(0.2))) return False; glTranslatef(-0.05, 0.17, 0.05); glRotatef(-90, 1, 0, 0); glRotatef(-25, 0, 1, 0); if(!((*cone)(0.05))) return False; glTranslatef(0.00, 0.10, 0.00); if(!((*cone)(0.05))) return False; glRotatef(25, 0, 1, 0); glRotatef(90, 1, 0, 0); glScalef(1, 1.3, 1); glTranslatef(0.15, -0.65, 0.05); if(!((*sphere)(0.25))) return False; glScalef(1, 1 / 1.3, 1); glPopMatrix(); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); /* ANTENNAS */ glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_LINES); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, 0.40); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.30, 0.00); glColor3fv(MaterialGray); glVertex3f(0.40, 0.70, -0.40); glEnd(); if(!shadow) { glBegin(GL_POINTS); glColor3fv(mp->mono ? MaterialGray6 : MaterialGray5); glVertex3f(0.40, 0.70, 0.40); glVertex3f(0.40, 0.70, -0.40); glEnd(); } /* LEFT-FRONT ARM */ glBegin(GL_LINE_STRIP); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.05, 0.18); glVertex3f(0.35 + 0.05 * cos1, 0.15, 0.25); glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45); glEnd(); /* LEFT-CENTER ARM */ glBegin(GL_LINE_STRIP); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.00, 0.18); glVertex3f(0.35 + 0.05 * cos2, 0.00, 0.25); glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45); glEnd(); /* LEFT-BACK ARM */ glBegin(GL_LINE_STRIP); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, -0.05, 0.18); glVertex3f(0.35 + 0.05 * cos3, -0.15, 0.25); glColor3fv(MaterialGray); glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45); glEnd(); /* RIGHT-FRONT ARM */ glBegin(GL_LINE_STRIP); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.05, -0.18); glVertex3f(0.35 - 0.05 * sin1, 0.15, -0.25); glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45); glEnd(); /* RIGHT-CENTER ARM */ glBegin(GL_LINE_STRIP); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, 0.00, -0.18); glVertex3f(0.35 - 0.05 * sin2, 0.00, -0.25); glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45); glEnd(); /* RIGHT-BACK ARM */ glBegin(GL_LINE_STRIP); glColor3fv(mp->mono ? MaterialGray5 : Material); glVertex3f(0.00, -0.05, -0.18); glVertex3f(0.35 - 0.05 * sin3, -0.15, -0.25); glColor3fv(MaterialGray); glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45); glEnd(); if(!shadow) { glBegin(GL_POINTS); glColor3fv(MaterialGray5); glVertex3f(-0.20 + 0.05 * cos1, 0.25 + 0.1 * sin1, 0.45); glVertex3f(-0.20 + 0.05 * cos2, 0.00 + 0.1 * sin2, 0.45); glVertex3f(-0.20 + 0.05 * cos3, -0.25 + 0.1 * sin3, 0.45); glVertex3f(-0.20 - 0.05 * sin1, 0.25 + 0.1 * cos1, -0.45); glVertex3f(-0.20 - 0.05 * sin2, 0.00 + 0.1 * cos2, -0.45); glVertex3f(-0.20 - 0.05 * sin3, -0.25 + 0.1 * cos3, -0.45); glEnd(); } glEnable(GL_LIGHTING); return True; }
/** * draw() * * Draw to the screen. */ void draw() { //set background color to black glClearColor(0.0, 0.0, 0.0, 0.0); //clear info from last draw glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //switch to the drawing perspective glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //rotate and translate the scene to simulate camera movement glRotatef(camera_pitch, 1.0, 0.0, 0.0); glRotatef(camera_yaw, 0.0, 1.0, 0.0); glRotatef(camera_roll, 0.0, 0.0, 1.0); glTranslatef(camera_x, camera_y, camera_z); //initiate camera position and angle gluLookAt (0.0, 5.0, -35.0, //camera position 0.0, 5.0, 0.0, //look-at point 0.0, 1.0, 0.0); //up direction //draw light #1 and its light stand object if (draw_light1) { //turn on light #1 glEnable(GL_LIGHT0); //draw light #1 effect GLfloat diff_light[] = {light1_red, light1_green, light1_blue, 1.0}; GLfloat l_position[] = {light1_x, 1 + light1_height + 2*sinf(PI/18), light1_z, 1.0f}; glLightfv (GL_LIGHT0, GL_DIFFUSE, diff_light); glLightfv (GL_LIGHT0, GL_POSITION, l_position); //draw light #1 stand base and head glPushMatrix(); light_position(light1_x, light1_z); light_angle(light1_x, light1_z); glCallList(light_base_id); glPushMatrix(); glTranslatef(0.0, light1_height, 0.0); glCallList(light_head_id); glPopMatrix(); glPopMatrix(); //light #1 stand pole glPushMatrix(); light_position(light1_x, light1_z); glTranslatef(0.0f, light1_height + 2*sinf(PI/18), 0.0); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glColor3f(0.2, 0.2, 0.2); GLUquadricObj * light_stand; light_stand = gluNewQuadric(); gluQuadricDrawStyle(light_stand, GLU_FILL); gluCylinder(light_stand, 0.05f, 0.05f, light1_height, 8, 8); glEnd(); glPopMatrix(); } //draw light #2 and its light stand object if (draw_light2) { //turn on light #2 glEnable(GL_LIGHT1); //draw light #2 effect GLfloat diff_light[] = {light2_red, light2_green, light2_blue, 1.0}; GLfloat l_position[] = {light2_x, 1 + light2_height + 2*sinf(PI/18), light2_z, 1.0f}; glLightfv (GL_LIGHT1, GL_DIFFUSE, diff_light); glLightfv (GL_LIGHT1, GL_POSITION, l_position); //draw light #2 stand base and head glPushMatrix(); light_position(light2_x, light2_z); light_angle(light2_x, light2_z); glCallList(light_base_id); glPushMatrix(); glTranslatef(0.0, light2_height, 0.0); glCallList(light_head_id); glPopMatrix(); glPopMatrix(); //light #2 stand pole glPushMatrix(); light_position(light2_x, light2_z); glTranslatef(0.0f, light2_height + 2*sinf(PI/18), 0.0); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glColor3f(0.2, 0.2, 0.2); GLUquadricObj * light_stand; light_stand = gluNewQuadric(); gluQuadricDrawStyle(light_stand, GLU_FILL); gluCylinder(light_stand, 0.05f, 0.05f, light2_height, 8, 8); glEnd(); glPopMatrix(); } //draw light #3 and its light stand object if (draw_light3) { //turn on light #3 glEnable(GL_LIGHT2); //draw light #3 effect GLfloat diff_light[] = {light3_red, light3_green, light3_blue, 1.0}; GLfloat l_position[] = {light3_x, 6.0 + 2*sinf(PI/18), light3_z, 1.0f}; glLightfv (GL_LIGHT2, GL_DIFFUSE, diff_light); glLightfv (GL_LIGHT2, GL_POSITION, l_position); //draw light #3 stand base and head glPushMatrix(); light_position(light3_x, light3_z); light_angle(light3_x, light3_z); glCallList(light_base_id); glPushMatrix(); glTranslatef(0.0, light3_height, 0.0); glCallList(light_head_id); glPopMatrix(); glPopMatrix(); //light #3 stand pole glPushMatrix(); light_position(light3_x, light3_z); glTranslatef(0.0f, light3_height + 2*sinf(PI/18), 0.0); glRotatef(90.0f, 1.0f, 0.0f, 0.0f); glColor3f(0.2, 0.2, 0.2); GLUquadricObj * light_stand; light_stand = gluNewQuadric(); gluQuadricDrawStyle(light_stand, GLU_FILL); gluCylinder(light_stand, 0.05f, 0.05f, light3_height, 8, 8); glEnd(); glPopMatrix(); } //draw the grid lines if (draw_grid) { glBegin (GL_LINES); glColor3f(0.5f, 0.5f, 0.5f); for (int i = -10; i <= 10; ++i) { //floor glVertex3f(i, 0, -10); glVertex3f(i, 0, 10); glVertex3f(10, 0, i); glVertex3f(-10, 0, i); //back wall glVertex3f(i, 0, 10); glVertex3f(i, 10, 10); //left wall glVertex3f(10, 0, i); glVertex3f(10, 10, i); //right wall glVertex3f(-10, 0, i); glVertex3f(-10, 10, i); } for (int i = 0; i <= 10; ++i) { //back wall glVertex3f(10, i, 10); glVertex3f(-10, i, 10); //left wall glVertex3f(10, i, -10); glVertex3f(10, i, 10); //right wall glVertex3f(-10, i, -10); glVertex3f(-10, i, 10); } glEnd(); //GL_LINES for grid } //DRAW PERSON 1 (GREEN) if (draw_person1) { glPushMatrix(); //set the postition and orientation of person 1 glTranslatef(person1_x, 0.0f, person1_z); glRotatef(person1_xrot, 1.0f, 0.0f, 0.0f); glRotatef(person1_zrot, 0.0f, 0.0f, 1.0f); glRotatef(person1_yrot, 0.0f, 1.0f, 0.0f); glScalef(0.7f, 0.7f, 0.55f); //head for person 1 glPushMatrix(); glColor3f(1.0f, .9f, .6f); glCallList(head_list_id); //call the head display list glPopMatrix(); //body for person 1 glPushMatrix(); glColor3f(0.0f, 0.8f, 0.0f); glCallList(body_list_id); //call the body display list glPopMatrix(); glPopMatrix(); } //DRAW PERSON 2 (RED) if (draw_person2) { glPushMatrix(); //set the postition and orientation of person 2 glTranslatef(person2_x, 0.0f, person2_z); glRotatef(person2_xrot, 1.0f, 0.0f, 0.0f); glRotatef(person2_zrot, 0.0f, 0.0f, 1.0f); glRotatef(person2_yrot, 0.0f, 1.0f, 0.0f); glScalef(0.8f, 0.8f, 0.65f); //head for person 2 glPushMatrix(); glColor3f(0.9f, 0.7f, 0.6f); glCallList(head_list_id); glPopMatrix(); //body for person 2 glPushMatrix(); glColor3f(0.7f, 0.0f, 0.1f); glCallList(body_list_id); glPopMatrix(); glPopMatrix(); } //DRAW PERSON 3 (BLUE) if (draw_person3) { glPushMatrix(); //set the postition and orientation of person 3 glTranslatef(person3_x, 0.0f, person3_z); glRotatef(person3_xrot, 1.0f, 0.0f, 0.0f); glRotatef(person3_zrot, 0.0f, 0.0f, 1.0f); glRotatef(person3_yrot, 0.0f, 1.0f, 0.0f); glScalef(0.7f, 0.65f, 0.6f); //head for person 3 glPushMatrix(); glColor3f(0.9f, 0.9f, 0.8f); glCallList(head_list_id); glPopMatrix(); //body for person 3 glPushMatrix(); glColor3f(0.1f, 0.0f, 0.9f); glCallList(body_list_id); glPopMatrix(); glPopMatrix(); } //DRAW PERSON 4 (YELLOW) if (draw_person4) { glPushMatrix(); //set the postition and orientation of person 4 glTranslatef(person4_x, 0.0f, person4_z); glRotatef(person4_xrot, 1.0f, 0.0f, 0.0f); glRotatef(person4_zrot, 0.0f, 0.0f, 1.0f); glRotatef(person4_yrot, 0.0f, 1.0f, 0.0f); glScalef(0.75f, 0.85f, 0.65f); //head for person 4 glPushMatrix(); glColor3f(0.5f, 0.5f, 0.2f); glCallList(head_list_id); glPopMatrix(); //body for person 4 glPushMatrix(); glColor3f(0.9f, 0.9f, 0.0f); glCallList(body_list_id); glPopMatrix(); glPopMatrix(); } //swap the current window with the buffered window glutSwapBuffers(); }
/** * Draws all points of the objects in OpenGl with SDL in cartesian coordinates */ void drawObjects(struct system *System, struct tip *Tip, struct space *Space, struct graphene *Graphene, struct substrate *Substrate) { SDL_Event event; Uint8 running = 1; GLfloat angleH = 0.0f; GLfloat angleV = -90.0f; GLfloat rescaleX = WIDTH/System->size.x; GLfloat rescaleY = HEIGHT/System->size.z; while (running) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); glClearColor(0.0, 0.0, 0.0, 0.0); // Black background color glClear(GL_COLOR_BUFFER_BIT); // Black screen glColor4f(1.0, 1.0, 1.0, 0.0); // White color for Objects glOrtho(-WIDTH/2, WIDTH/2, HEIGHT/2, -HEIGHT/2, HEIGHT/2, -HEIGHT/2); glRotatef(angleV, 1.0f, 0.0f, 0.0f); // Show the x-z plane of the system glRotatef(angleH, 0.0f, 0.0f, 1.0f); // Rotate around Z glTranslatef(-0.0f, -0.0f, -120.0f); glPointSize(1.0f); glLineWidth(2.0f); glMatrixMode (GL_MODELVIEW); // Draw objects glBegin(GL_POINTS); for (Uint32 i = 0; i < Tip->numPoints; i++) { glColor3f (Tip->points[i].potential/System->potential, 0.5f, 0.0f); glVertex3f(Tip->points[i].x * rescaleX, Tip->points[i].y * rescaleY, Tip->points[i].z * rescaleY); } for (Uint32 i = 0; i < Space->numPoints; i++) { glColor3f (Space->points[i].potential/System->potential, 0.5f, 0.5f); glVertex3f(Space->points[i].x * rescaleX, Space->points[i].y * rescaleY, Space->points[i].z * rescaleY); } for (Uint32 i = 0; i < Graphene->numPoints; i++) { glColor3f (Graphene->points[i].potential/System->potential, 0.5f, 0.5f); glVertex3f(Graphene->points[i].x * rescaleX, Graphene->points[i].y * rescaleY, Graphene->points[i].z * rescaleY); } for (Uint32 i = 0; i < Substrate->numPoints; i++) { glColor3f (Substrate->points[i].potential/System->potential, 0.0f, 0.5f); glVertex3f(Substrate->points[i].x * rescaleX, Substrate->points[i].y * rescaleY, Substrate->points[i].z * rescaleY); } glColor3f (1.0f, 1.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); // Center of the System glEnd(); SDL_GL_SwapBuffers(); SDL_Delay(150); while (SDL_PollEvent (&event)) { if(event.type == SDL_QUIT) { running = 0; } else if (event.key.keysym.sym == SDLK_ESCAPE) { running = 0; } else if(event.button.button == SDL_BUTTON_LEFT && event.button.state == SDL_PRESSED) { angleH += 10.0f; } else if(event.button.button == SDL_BUTTON_RIGHT && event.button.state == SDL_PRESSED) { angleH -= 10.0f; } else if(event.button.button == SDL_BUTTON_WHEELUP && event.button.state == SDL_PRESSED) { angleV += 5.0f; } else if(event.button.button == SDL_BUTTON_WHEELDOWN && event.button.state == SDL_PRESSED) { angleV -= 5.0f; } } } }
/** * body() * * Creates a display list for the body of a person. */ void body() { GLfloat fan_angle; //angle for a triangle fan int sections = 40; //number of triangles in a triangle fan //generate a display list for a body body_list_id = glGenLists(1); //compile the new display list glNewList(body_list_id, GL_COMPILE); glPushMatrix(); glTranslatef(0.0f, 5.05f, 0.0f); glRotatef(90, 1.0, 0.0, 0.0); //create a torso with a cylinder glPushMatrix(); GLUquadricObj * torso; torso = gluNewQuadric(); gluQuadricDrawStyle(torso, GLU_FILL); gluCylinder(torso, 1.0f, 1.0f, 2.25f, 25, 25); glPopMatrix(); //triangle fan for top of body glPushMatrix(); glRotatef(180.0, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(cosf(fan_angle), sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); //triangle fan for bottom of torso glPushMatrix(); glTranslatef(0.0, 0.0, 2.25); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(cosf(fan_angle), sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); //arm 1 glPushMatrix(); glTranslatef(1.25f, 0.0f, 0.0f); GLUquadricObj * arm1; arm1 = gluNewQuadric(); gluQuadricDrawStyle(arm1, GLU_FILL); gluCylinder(arm1, 0.25f, 0.25f, 2.5f, 12, 12); glPopMatrix(); //triangle fan for top of arm 1 glPushMatrix(); glTranslatef(1.25, 0.0, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); sections = 12; for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); //triangle fan for bottom of arm 1 glPushMatrix(); glTranslatef(1.25, 0.0, 2.5); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); sections = 12; for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); //arm 2 glPushMatrix(); glTranslatef(-1.25f, 0.0f, 0.0f); GLUquadricObj * arm2; arm2 = gluNewQuadric(); gluQuadricDrawStyle(arm2, GLU_FILL); gluCylinder(arm2, 0.25f, 0.25f, 2.5f, 12, 12); glPopMatrix(); //triangle fan for top of arm 2 glPushMatrix(); glTranslatef(-1.25, 0.0, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); sections = 12; for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); //triangle fan for bottom of arm 2 glPushMatrix(); glTranslatef(-1.25, 0.0, 2.5); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); sections = 12; for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); //leg 1 glPushMatrix(); glTranslatef(0.5f, 0.0f, 2.25f); GLUquadricObj * leg1; leg1 = gluNewQuadric(); gluQuadricDrawStyle(leg1, GLU_FILL); gluCylinder(leg1, 0.5f, 0.2f, 2.8f, 12, 12); glPopMatrix(); //triangle fan for bottom of leg 1 glPushMatrix(); glTranslatef(0.5, 0.0, 5.05); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); sections = 12; for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(0.2*cosf(fan_angle), 0.2*sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); //leg 2 glPushMatrix(); glTranslatef(-0.5f, 0.0f, 2.25f); GLUquadricObj * leg2; leg2 = gluNewQuadric(); gluQuadricDrawStyle(leg2, GLU_FILL); gluCylinder(leg2, 0.5f, 0.2f, 2.8f, 12, 12); glPopMatrix(); //triangle fan for bottom of leg 2 glPushMatrix(); glTranslatef(-0.5, 0.0, 5.05); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 0.0f); sections = 12; for(int i = 0; i <= sections; ++i) { fan_angle = (GLfloat) i * 2 * PI / sections; glVertex3f(0.2*cosf(fan_angle), 0.2*sinf(fan_angle), 0.0f); } glEnd(); glPopMatrix(); glPopMatrix(); glEndList(); }
void StateBasedGame::preRender(GameContainer* container, Renderer* g) { #if defined( ARK2D_ANDROID ) glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glLoadIdentity(); /*g->setScissorTestEnabled(true); glScissor(container->getTranslateX(), container->getTranslateY(), float(container->getWidth()) * container->getScaleX(), float(container->getHeight()) * container->getScaleY()); */ /* g->setScissorTestEnabled(true); g->scissor( container->getTranslateX(), container->getTranslateY(), (int) float(container->getWidth()) * container->getScaleX(), (int) float(container->getHeight()) * container->getScaleY() ); */ /*g->setScissorTestEnabled(true); g->scissor( container->getTranslateX(), container->getTranslateY(), container->getWidth() * container->getScaleX(), container->getHeight() * container->getScaleY() );*/ g->pushMatrix(); g->translate(container->getTranslateX(), container->getTranslateY()); g->pushMatrix(); g->scale(container->getScale(), container->getScale()); #elif defined(ARK2D_IPHONE) if (container->getOrientation() == GameContainer::ORIENTATION_LANDSCAPE) { glPushMatrix(); glTranslatef(container->m_platformSpecific.m_glView.bounds.size.width, 0.0f, 0.0f ); glRotatef(90.0, 0.0, 0.0, 1.0); } g->pushMatrix(); g->translate(container->getTranslateX(), container->getTranslateY()); g->pushMatrix(); g->scale(container->getScale(), container->getScale()); #elif (defined(ARK2D_MACINTOSH) || defined(ARK2D_WINDOWS) || defined(ARK2D_FLASCC)) /*glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glLoadIdentity(); g->setScissorTestEnabled(true); g->scissor( container->getTranslateX(), container->getTranslateY(), container->getWidth() * container->getScaleX(), container->getHeight() * container->getScaleY() )*/ g->pushMatrix(); g->translate(container->getTranslateX(), container->getTranslateY()); g->pushMatrix(); g->scale(container->getScale(), container->getScale()); #else g->pushMatrix(); #endif }
void drawSphere (void) { /* This sphere is going to be rotated around the *current axis*. This is because the model was first rotated and then translated. */ glPushMatrix (); glRotatef (rotate, axis[0], axis[1], axis[2]); glTranslatef (-15.0, 10.0, 5.0); glColor3f (1.0, 0.0, 0.0); glutWireSphere (5.0, 6.0, 6.0); glPopMatrix (); /* This sphere is going to be rotated around the its own center. This is because the model was first translated and then rotated. */ glPushMatrix (); glTranslatef (5.0, 10.0, 0.0); glRotatef (rotate, axis[0], axis[1], axis[2]); glColor3f (0.0, 1.0, 0.0); glutWireSphere (2.0, 6.0, 6.0); glPopMatrix (); }
void DrawMech(void) { int i, j; glScalef(0.5, 0.5, 0.5); glPushMatrix(); glTranslatef(0.0, -0.75, 0.0); glRotatef((GLfloat) tilt, 1.0, 0.0, 0.0); glRotatef(90.0, 1.0, 0.0, 0.0); #ifdef HIP glCallList(SOLID_MECH_HIP); #endif glRotatef(-90.0, 1.0, 0.0, 0.0); glTranslatef(0.0, 0.75, 0.0); glPushMatrix(); glRotatef((GLfloat) pivot, 0.0, 1.0, 0.0); glPushMatrix(); #ifdef TORSO glCallList(SOLID_MECH_TORSO); #endif glPopMatrix(); glPushMatrix(); glTranslatef(0.5, 0.5, 0.0); #ifdef ROCKET_POD glCallList(SOLID_MECH_ROCKET); #endif glPopMatrix(); for (i = 0; i < 2; i++) { glPushMatrix(); if (i) glScalef(-1.0, 1.0, 1.0); glTranslatef(1.5, 0.0, 0.0); #ifdef SHOULDER glCallList(SOLID_MECH_SHOULDER); #endif glTranslatef(0.9, 0.0, 0.0); if (i) { glRotatef((GLfloat) lat1, 0.0, 0.0, 1.0); glRotatef((GLfloat) shoulder1, 1.0, 0.0, 0.0); glRotatef((GLfloat) shoulder3, 0.0, 1.0, 0.0); } else { glRotatef((GLfloat) lat2, 0.0, 0.0, 1.0); glRotatef((GLfloat) shoulder2, 1.0, 0.0, 0.0); glRotatef((GLfloat) shoulder4, 0.0, 1.0, 0.0); } glTranslatef(0.0, -1.4, 0.0); #ifdef UPPER_ARM glCallList(SOLID_MECH_UPPER_ARM); #endif glTranslatef(0.0, -2.9, 0.0); if (i) glRotatef((GLfloat) elbow1, 1.0, 0.0, 0.0); else glRotatef((GLfloat) elbow2, 1.0, 0.0, 0.0); glTranslatef(0.0, -0.9, -0.2); #ifdef LOWER_ARM glCallList(SOLID_MECH_FOREARM); glPushMatrix(); glTranslatef(0.0, 0.0, 2.0); glRotatef((GLfloat) fire, 0.0, 0.0, 1.0); glCallList(SOLID_MECH_VULCAN); glPopMatrix(); #endif glPopMatrix(); } glPopMatrix(); glPopMatrix(); for (j = 0; j < 2; j++) { glPushMatrix(); if (j) { glScalef(-0.5, 0.5, 0.5); leg = 1; } else { glScalef(0.5, 0.5, 0.5); leg = 0; } glTranslatef(2.0, -1.5, 0.0); if (j) { glRotatef((GLfloat) hip11, 1.0, 0.0, 0.0); glRotatef((GLfloat) hip12, 0.0, 0.0, 1.0); } else { glRotatef((GLfloat) hip21, 1.0, 0.0, 0.0); glRotatef((GLfloat) hip22, 0.0, 0.0, 1.0); } glTranslatef(0.0, 0.3, 0.0); #ifdef UPPER_LEG glPushMatrix(); glCallList(SOLID_MECH_UPPER_LEG); glPopMatrix(); #endif glTranslatef(0.0, -8.3, -0.4); if (j) glRotatef((GLfloat) - hip12, 0.0, 0.0, 1.0); else glRotatef((GLfloat) - hip22, 0.0, 0.0, 1.0); glTranslatef(-0.5, -0.85, -0.5); #ifdef LOWER_LEG LowerLeg(1); #endif glPopMatrix(); } }
// Funciones a definir desde Effect.h void FXritmo::perFrame(float time) { float t = time * 0.001f; float fftbass=miMusic.getFFTBass(); glClearColor(0.925,0,0.549,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); cam.toOGL(); cam.SetPos(0,0,-6); cam.SetLook(0,-1,-0.1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); float xt=2; // xtremo float z_depth=float(-0.0121); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glPointSize(10); glColor3f(1,1,1); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); float valy; int numV,j; Point p; static float pulso=0; int row=miMusic.getRow(); if((row==0) || (row==1) || (row==8) || (row==9) || (row==16) || (row==17) || (row==24) || (row==25)) { valy=4; } else { valy=0; } if(valy>0) { pulso=valy; } else { if(pulso>0) { pulso=pulso-pulso*pulso*0.05; } } numV=unaEsfera.getNumVertex(); for(j=0; j<numV; j++) { p.x = 2*sin(t*0.5 + j); p.y = fftbass*5 + 2*cos(t*0.5+j); p.z = 2*(sin(p.y)) + fftbass; p.w = unaEsfera.getVertex(j).w; unaEsfera.setVertex(j,p); } glTranslatef(0,0,pulso*0.6); glRotatef(t*10 ,1,1,1); unaEsfera.perFrame(t); glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScalef(3,3,3); glRotatef(t,1,0,0); unCubo.setPolyAlpha(0.3); unCubo.perFrame(t); glPopMatrix(); glDisable(GL_BLEND); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); for(int i=1; i<6; i++) { fxmotionblur->perFrame(t); } fxmotionblur->postprepareFrame(); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); xt=1.01;//10-0.05*_row; // xtremos miDemo->ponOrtopedico(4,4); float al=fmod(t,2),dp=0,dpy=-1; // desplazamiento glColor4f(1,1,1,pulso); glBindTexture(GL_TEXTURE_2D, this->layerTitle.texID); glBegin(GL_QUADS); glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0, 0); glVertex3f(-xt*2+dp,-xt+dpy,z_depth); glTexCoord2f(1,0); glVertex3f(xt*2+dp,-xt+dpy, z_depth); glTexCoord2f(1,1); glVertex3f(xt*2+dp,xt+dpy, z_depth); glTexCoord2f(0,1); glVertex3f(-xt*2+dp,xt+dpy,z_depth); glEnd(); glDisable(GL_TEXTURE_2D); miDemo->quitaOrtopedico(); }
void render() { int i; //Typical render pass glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //First render background and menu if it is enabled enable_2d(); glEnable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glVertexPointer(2, GL_FLOAT, 0, background_vertices); glTexCoordPointer(2, GL_FLOAT, 0, background_tex_coord); glBindTexture(GL_TEXTURE_2D, background); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); if (menu_active || menu_show_animation || menu_hide_animation) { glTranslatef(pos_x, pos_y, 0.0f); for (i = 0; i < 4; i++) { if (i == selected) { glVertexPointer(2, GL_FLOAT, 0, radio_btn_selected_vertices); glTexCoordPointer(2, GL_FLOAT, 0, radio_btn_selected_tex_coord); glBindTexture(GL_TEXTURE_2D, radio_btn_selected); } else { glVertexPointer(2, GL_FLOAT, 0, radio_btn_unselected_vertices); glTexCoordPointer(2, GL_FLOAT, 0, radio_btn_unselected_tex_coord); glBindTexture(GL_TEXTURE_2D, radio_btn_unselected); } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glTranslatef(0.0f, 60.0f, 0.0f); } bbutil_render_text(font, "Color Menu", 10.0f, 10.0f, 0.35f, 0.35f, 0.35f, 1.0f); bbutil_render_text(font, "Red", 70.0f, -40.0f, 0.35f, 0.35f, 0.35f, 1.0f); bbutil_render_text(font, "Green", 70.0f, -100.0f, 0.35f, 0.35f, 0.35f, 1.0f); bbutil_render_text(font, "Blue", 70.0f, -160.0f, 0.35f, 0.35f, 0.35f, 1.0f); bbutil_render_text(font, "Yellow", 70.0f, -220.0f, 0.35f, 0.35f, 0.35f, 1.0f); } glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable(GL_TEXTURE_2D); //Then render the cube enable_3d(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glTranslatef(cube_pos_x, cube_pos_y, cube_pos_z); glRotatef(30.0f, 1.0f, 0.0f, 0.0f); glRotatef(15.0f, 0.0f, 0.0f, 1.0f); glRotatef(angle, 0.0f, 1.0f, 0.0f); glColor4f(cube_color[0], cube_color[1], cube_color[2], cube_color[3]); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glVertexPointer(3, GL_FLOAT, 0, cube_vertices); glNormalPointer(GL_FLOAT, 0, cube_normals); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDrawArrays(GL_TRIANGLE_STRIP, 4, 4); glDrawArrays(GL_TRIANGLE_STRIP, 8, 4); glDrawArrays(GL_TRIANGLE_STRIP, 12, 4); glDrawArrays(GL_TRIANGLE_STRIP, 16, 4); glDrawArrays(GL_TRIANGLE_STRIP, 20, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glDisable(GL_COLOR_MATERIAL); glDisable(GL_DEPTH_TEST); //Use utility code to update the screen bbutil_swap(); }
void draw_troncos(GLint k,GLint level) { if(level ==0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,tex[1]); } else if(level ==1) { glEnable(GL_TEXTURE_2D); glColor4f(GRAY2); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // blending + textura glBindTexture(GL_TEXTURE_2D,tex[3]); } else { if(ascendente == 1) { if(lvl3_colors[k][3]<0.5) { lvl3_colors[k][3]+=0.0005; } else { lvl3_colors[k][3]+=0.001; } if(lvl3_colors[k][3]>1.0) { ascendente = 0; } } else { lvl3_colors[k][3]-=0.001; if(lvl3_colors[k][3]<0.0) { ascendente = 1; } } glEnable(GL_BLEND); glColor4f(lvl3_colors[k][0],lvl3_colors[k][1],lvl3_colors[k][2],lvl3_colors[k][3]); } glPushMatrix(); /*desenho do cilindro*/ glTranslatef(levels[level].troncoPos[k][0],levels[level].troncoPos[k][1],levels[level].troncoPos[k][2]); glRotatef (levels[level].troncoRot[k][0],levels[level].troncoRot[k][1],levels[level].troncoRot[k][2],levels[level].troncoRot[k][3]); GLUquadricObj* y = gluNewQuadric( ); gluQuadricDrawStyle(y, GLU_FILL); gluQuadricNormals(y, GLU_SMOOTH); gluQuadricTexture(y,GL_TRUE); gluCylinder(y,levels[level].troncoDim[k][0],levels[level].troncoDim[k][1],levels[level].troncoDim[k][2],32,32); /*desenho dos discos que tapam a extremidades do cilindro*/ gluDisk(y, 0.0, levels[level].diskRadius[k], 32, 32); glTranslatef(0,0,levels[level].troncoDim[k][2]); gluDisk(y, 0.0, levels[level].diskRadius[k], 32, 32); gluDeleteQuadric(y); glPopMatrix(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); }
void display() { sdkStartTimer(&timer); // update the simulation if (!bPause) { psystem->setIterations(iterations); psystem->setDamping(damping); psystem->setGravity(-gravity); psystem->setCollideSpring(collideSpring); psystem->setCollideDamping(collideDamping); psystem->setCollideShear(collideShear); psystem->setCollideAttraction(collideAttraction); psystem->update(timestep); if (renderer) { renderer->setVertexBuffer(psystem->getCurrentReadBuffer(), psystem->getNumParticles()); } } // render glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // view transform glMatrixMode(GL_MODELVIEW); glLoadIdentity(); for (int c = 0; c < 3; ++c) { camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia; camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia; } glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]); glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0); glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0); glGetFloatv(GL_MODELVIEW_MATRIX, modelView); // cube glColor3f(1.0, 1.0, 1.0); glutWireCube(2.0); // collider glPushMatrix(); float3 p = psystem->getColliderPos(); glTranslatef(p.x, p.y, p.z); glColor3f(1.0, 0.0, 0.0); glutSolidSphere(psystem->getColliderRadius(), 20, 10); glPopMatrix(); if (renderer && displayEnabled) { renderer->display(displayMode); } if (displaySliders) { glDisable(GL_DEPTH_TEST); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color glEnable(GL_BLEND); params->Render(0, 0); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } sdkStopTimer(&timer); glutSwapBuffers(); glutReportErrors(); computeFPS(); }
void reflection(){ glPushMatrix(); //glRotatef(-90,1,0,0); quad(2,1,1,0); glPopMatrix(); //REFLEXÃO //1. Activa o uso do stencil buffer glEnable(GL_STENCIL_TEST); //2. Nao escreve no color buffer - desativar glColorMask(GL_FALSE, GL_FALSE,GL_FALSE, GL_FALSE); //3. Torna inactivo o teste de profundidade glDisable(GL_DEPTH_TEST); //4. Coloca a 1 todos os pixels no stencil buffer que representam o chão. A combinaçao desenhaChao + StencilFunc + StencilOp e que me da a mascara. A area de desenho, que vai ser colocada 1, e dada pelo desenhaChao. glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); //5. Desenhar o quadrado drawEdges(); //6. Activa a escrita de cor glColorMask(1, 1, 1, 1); //7. Activa o teste de profundidade glEnable(GL_DEPTH_TEST); //8. O stencil test passa apenas quando o pixel tem o valor 1 no stencil buffer glStencilFunc(GL_EQUAL, 1, 1); //9. Stencil buffer read-only glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //10. Desenha o objecto com a reflexão onde stencil buffer é 1 //para z=0 e z=10 glPushMatrix(); glTranslatef(0, 0, -0.001); glRotatef(-90,1,0,0); glScalef(1,-1,1); quad(2,1,1,1); glPopMatrix(); glPushMatrix(); glTranslatef(0, 2, 10.001); glRotatef(90,1,0,0); glScalef(1,-1,1); quad(2,1,1,1); glPopMatrix(); //---------------------------- //para x=0 e x=10 glPushMatrix(); glTranslatef(-0.001, 0,0); glRotatef(90,0,0,1); glScalef(1,-1,1); quad(2,1,1,2); glPopMatrix(); glPushMatrix(); glTranslatef(10.001, 2,0); glRotatef(270,0,0,1); glScalef(1,-1,1); quad(2,1,1,2); glPopMatrix(); //11. Desactiva a utilização do stencil buffer glDisable(GL_STENCIL_TEST); // isto aplica a textura ao chao Blending glEnable(GL_BLEND); glColor4f(1, 1, 1, 0.3); drawEdges(); glDisable(GL_BLEND); }
int MD2MODEL_draw(CMD2MODEL *_object, double frame, int texture, float *pos, float *scale, float *rotate) { int i; int n, n2; double interp; GLfloat v_curr[3], v_next[3], v[3], norm[3]; GLfloat *n_curr, *n_next; const framemd2 *pframe1, *pframe2; const vertexmd2 *pvert1, *pvert2; bool enabled; int nvert = 0; int *pglcmds; glcmd *packet; if (texture < 0) return 0; n = (int)frame; interp = frame - n; if (n < 0 || n >= THIS->num_frames) return 0; n2 = n + 1; if (n2 >= THIS->num_frames) n2 = 0; enabled = glIsEnabled(GL_TEXTURE_2D); if (!enabled) glEnable(GL_TEXTURE_2D); glPushMatrix(); if (pos) glTranslatef(pos[0], pos[1], pos[2]); glRotatef(-90, 1, 0, 0); glRotatef(-90, 0, 0, 1); if (rotate && rotate[0] != 0) glRotatef(rotate[0], rotate[1], rotate[2], rotate[3]); glScalef(THIS->scale[0], THIS->scale[1], THIS->scale[2]); if (scale) glScalef(scale[0], scale[1], scale[2]); glBindTexture(GL_TEXTURE_2D, texture); #if 1 // pglcmds points at the start of the command list pglcmds = THIS->glcmds; pframe1 = &THIS->frames[n]; pframe2 = &THIS->frames[n2]; //fprintf(stderr, "\n******** %p: n = %d / %d | %p %p\n", _object, n, THIS->num_frames, pframe1->verts, pframe2->verts); // Draw the model while ((i = *(pglcmds++)) != 0) { //fprintf(stderr, "i = %d\n", i); if (i < 0) { glBegin(GL_TRIANGLE_FAN); i = -i; } else { glBegin(GL_TRIANGLE_STRIP); } // Draw each vertex of this group for (/* Nothing */ ; i > 0; --i, pglcmds += 3) { packet = (glcmd *)pglcmds; //fprintf(stderr, "%d (%d) ", i, packet->index); pvert1 = &pframe1->verts[packet->index]; pvert2 = &pframe2->verts[packet->index]; //if (!pvert1 || !pvert2) // continue; // Pass texture coordinates to OpenGL //glTexCoord2f (pGLcmd->s, 1.0f - pGLcmd->t); glTexCoord2f(packet->s, packet->t); // Compute interpolated normal vector n_curr = anorms_table[pvert1->normalIndex]; n_next = anorms_table[pvert2->normalIndex]; norm[0] = n_curr[0] + interp * (n_next[0] - n_curr[0]); norm[1] = n_curr[1] + interp * (n_next[1] - n_curr[1]); norm[2] = n_curr[2] + interp * (n_next[2] - n_curr[2]); // Normal vector glNormal3fv(norm); v_curr[0] = pframe1->scale[0] * pvert1->v[0] + pframe1->translate[0]; v_curr[1] = pframe1->scale[1] * pvert1->v[1] + pframe1->translate[1]; v_curr[2] = pframe1->scale[2] * pvert1->v[2] + pframe1->translate[2]; v_next[0] = pframe2->scale[0] * pvert2->v[0] + pframe2->translate[0]; v_next[1] = pframe2->scale[1] * pvert2->v[1] + pframe2->translate[1]; v_next[2] = pframe2->scale[2] * pvert2->v[2] + pframe2->translate[2]; v[0] = v_curr[0] + interp * (v_next[0] - v_curr[0]); v[1] = v_curr[1] + interp * (v_next[1] - v_curr[1]); v[2] = v_curr[2] + interp * (v_next[2] - v_curr[2]); glVertex3fv(v); nvert++; } //fprintf(stderr, "\n"); glEnd(); } #else { int j; GLfloat s, t; glBegin (GL_TRIANGLES); for (i = 0; i < THIS->num_tris; ++i) { for (j = 0; j < 3; ++j) { pframe1 = &THIS->frames[n]; pframe2 = &THIS->frames[n2]; pvert1 = &pframe1->verts[THIS->triangles[i].vertex[j]]; pvert2 = &pframe2->verts[THIS->triangles[i].vertex[j]]; s = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].s / THIS->skinwidth; t = (GLfloat)THIS->texcoords[THIS->triangles[i].st[j]].t / THIS->skinheight; glTexCoord2f (s, t); n_curr = anorms_table[pvert1->normalIndex]; n_next = anorms_table[pvert2->normalIndex]; norm[0] = n_curr[0] + interp * (n_next[0] - n_curr[0]); norm[1] = n_curr[1] + interp * (n_next[1] - n_curr[1]); norm[2] = n_curr[2] + interp * (n_next[2] - n_curr[2]); glNormal3fv (norm); v_curr[0] = pframe1->scale[0] * pvert1->v[0] + pframe1->translate[0]; v_curr[1] = pframe1->scale[1] * pvert1->v[1] + pframe1->translate[1]; v_curr[2] = pframe1->scale[2] * pvert1->v[2] + pframe1->translate[2]; v_next[0] = pframe2->scale[0] * pvert2->v[0] + pframe2->translate[0]; v_next[1] = pframe2->scale[1] * pvert2->v[1] + pframe2->translate[1]; v_next[2] = pframe2->scale[2] * pvert2->v[2] + pframe2->translate[2]; v[0] = v_curr[0] + interp * (v_next[0] - v_curr[0]); v[1] = v_curr[1] + interp * (v_next[1] - v_curr[1]); v[2] = v_curr[2] + interp * (v_next[2] - v_curr[2]); glVertex3fv (v); nvert++; } } glEnd(); } #endif //glScalef(1/THIS->scale[0], 1/THIS->scale[1], 1/THIS->scale[2]); glPopMatrix(); if (!enabled) glDisable(GL_TEXTURE_2D); return nvert; }
// `使用OpenGL來繪圖` void RenderFrameOpenGL(void) { // `清除畫面` glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); // `設定要用陣列的方式傳入頂點位置跟顏色` glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); // `計算出一個可以轉換到鏡頭座標系的矩陣` Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up); Matrix4x4 world_view_matrix; glMatrixMode(GL_MODELVIEW); // `載入鏡頭轉換矩陣` glLoadMatrixf( (float *) &view_matrix ); glPushMatrix(); // `把目前的矩陣存到stack里` // `太陽, 套入滑鼠的旋轉控制.` glRotatef(FastMath::RadianToDegree(g_fRotate_X), 1.0f, 0.0f, 0.0f); glRotatef(FastMath::RadianToDegree(g_fRotate_Y), 0.0f, 1.0f, 0.0f); glVertexPointer(3, GL_FLOAT, sizeof(Vertex_VC), g_pSunVertices); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex_VC), g_pSunVertices[0].m_RGBA); glDrawElements(GL_TRIANGLES, g_iNumSphereIndices, GL_UNSIGNED_SHORT, g_pSphereIndices); // `水星` glPushMatrix(); // `把目前的矩陣存到stack里` float mercury_rotate_y = 360.0f * (g_simulation_days / days_a_year_mercury); glRotatef(mercury_rotate_y, 0.0f, 1.0f, 0.0f); glTranslatef(mercury_to_sun_distance, 0.0f, 0.0f); glVertexPointer(3, GL_FLOAT, sizeof(Vertex_VC), g_pMoonVertices); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex_VC), g_pMoonVertices[0].m_RGBA); glDrawElements(GL_TRIANGLES, g_iNumSphereIndices, GL_UNSIGNED_SHORT, g_pSphereIndices); // `從stack里pop出一個矩陣, 并套用到目前所指定要操作的矩陣`GL_MODELVIEW glPopMatrix(); // `金星` glPushMatrix(); // `把目前的矩陣存到stack里` float venus_rotate_y = 360.0f * (g_simulation_days / days_a_year_venus); glRotatef(venus_rotate_y, 0.0f, 1.0f, 0.0f); glTranslatef(venus_to_sun_distance, 0.0f, 0.0f); glVertexPointer(3, GL_FLOAT, sizeof(Vertex_VC), g_pMoonVertices); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex_VC), g_pMoonVertices[0].m_RGBA); glDrawElements(GL_TRIANGLES, g_iNumSphereIndices, GL_UNSIGNED_SHORT, g_pSphereIndices); // `從stack里pop出一個矩陣, 并套用到目前所指定要操作的矩陣`GL_MODELVIEW glPopMatrix(); // `地球` glPushMatrix();// `把目前的矩陣存到stack里` float earth_rotate_y = 360.0f * (g_simulation_days / days_a_year); glRotatef(earth_rotate_y, 0.0f, 1.0f, 0.0f); glTranslatef(earth_to_sun_distance, 0.0f, 0.0f); glVertexPointer(3, GL_FLOAT, sizeof(Vertex_VC), g_pEarthVertices); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex_VC), g_pEarthVertices[0].m_RGBA); glDrawElements(GL_TRIANGLES, g_iNumSphereIndices, GL_UNSIGNED_SHORT, g_pSphereIndices); // `月球` float moon_rotate_y = 360.0f * (g_simulation_days / days_a_month); glRotatef(moon_rotate_y, 0.0f, 1.0f, 0.0f); glTranslatef(moon_to_earth_distance, 0.0f, 0.0f); glVertexPointer(3, GL_FLOAT, sizeof(Vertex_VC), g_pMoonVertices); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex_VC), g_pMoonVertices[0].m_RGBA); glDrawElements(GL_TRIANGLES, g_iNumSphereIndices, GL_UNSIGNED_SHORT, g_pSphereIndices); // `從stack里pop出一個矩陣, 并套用到目前所指定要操作的矩陣GL_MODELVIEW` glPopMatrix(); glPopMatrix(); // `把背景backbuffer的畫面呈現出來` GutSwapBuffersOpenGL(); }
void GLWidget::draw() { QPainter p(this); // used for text overlay // save the GL state set for QPainter p.beginNativePainting(); saveGLState(); // render the 'bubbles.svg' file into our pbuffer QPainter pbuffer_painter(pbuffer); svg_renderer->render(&pbuffer_painter); pbuffer_painter.end(); glFlush(); if (!hasDynamicTextureUpdate) pbuffer->updateDynamicTexture(dynamicTexture); makeCurrent(); // draw into the GL widget glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1, 1, -1, 1, 10, 100); glTranslatef(0.0f, 0.0f, -15.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glViewport(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio()); glBindTexture(GL_TEXTURE_2D, dynamicTexture); glEnable(GL_TEXTURE_2D); glEnable(GL_MULTISAMPLE); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // draw background glPushMatrix(); glScalef(1.7f, 1.7f, 1.7f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glCallList(tile_list); glPopMatrix(); const int w = logo.width(); const int h = logo.height(); glRotatef(rot_x, 1.0f, 0.0f, 0.0f); glRotatef(rot_y, 0.0f, 1.0f, 0.0f); glRotatef(rot_z, 0.0f, 0.0f, 1.0f); glScalef(scale/w, scale/w, scale/w); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); // draw the Qt icon glTranslatef(-w+1, -h+1, 0.0f); for (int y=h-1; y>=0; --y) { uint *p = (uint*) logo.scanLine(y); uint *end = p + w; int x = 0; while (p < end) { glColor4ub(qRed(*p), qGreen(*p), qBlue(*p), uchar(qAlpha(*p)*.9)); glTranslatef(0.0f, 0.0f, wave[y*w+x]); if (qAlpha(*p) > 128) glCallList(tile_list); glTranslatef(0.0f, 0.0f, -wave[y*w+x]); glTranslatef(2.0f, 0.0f, 0.0f); ++x; ++p; } glTranslatef(-w*2.0f, 2.0f, 0.0f); } // restore the GL state that QPainter expects restoreGLState(); p.endNativePainting(); // draw the overlayed text using QPainter p.setPen(QColor(197, 197, 197, 157)); p.setBrush(QColor(197, 197, 197, 127)); p.drawRect(QRect(0, 0, width(), 50)); p.setPen(Qt::black); p.setBrush(Qt::NoBrush); const QString str1(tr("A simple OpenGL pbuffer example.")); const QString str2(tr("Use the mouse wheel to zoom, press buttons and move mouse to rotate, double-click to flip.")); QFontMetrics fm(p.font()); p.drawText(width()/2 - fm.width(str1)/2, 20, str1); p.drawText(width()/2 - fm.width(str2)/2, 20 + fm.lineSpacing(), str2); }
static void draw_ico( void ) { GLuint list; list = glGenLists( 1 ); glNewList( list, GL_COMPILE ); TRIANGLE(1.5,seno,edgedivisions,(3*SQRT3+SQRT15)/12); glEndList(); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[0]); glCallList(list); glPushMatrix(); glRotatef(180,0,0,1); glRotatef(-icoangle,1,0,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[1]); glCallList(list); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[2]); glCallList(list); glPopMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,-SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[3]); glCallList(list); glPopMatrix(); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[4]); glCallList(list); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[5]); glCallList(list); glPopMatrix(); glRotatef(180,0,0,1); glRotatef(-icoangle,1,0,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[6]); glCallList(list); glPopMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,-SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[7]); glCallList(list); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,-SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[8]); glCallList(list); glPopMatrix(); glRotatef(180,0,0,1); glRotatef(-icoangle,1,0,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[9]); glCallList(list); glPopMatrix(); glRotatef(180,1,0,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[10]); glCallList(list); glPushMatrix(); glRotatef(180,0,0,1); glRotatef(-icoangle,1,0,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[11]); glCallList(list); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[12]); glCallList(list); glPopMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,-SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[13]); glCallList(list); glPopMatrix(); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[14]); glCallList(list); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[15]); glCallList(list); glPopMatrix(); glRotatef(180,0,0,1); glRotatef(-icoangle,1,0,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[16]); glCallList(list); glPopMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,-SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[17]); glCallList(list); glPushMatrix(); glRotatef(180,0,1,0); glRotatef(-180+icoangle,0.5,-SQRT3/2,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[18]); glCallList(list); glPopMatrix(); glRotatef(180,0,0,1); glRotatef(-icoangle,1,0,0); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialColor[19]); glCallList(list); glDeleteLists(list,1); }