void Viewport::drawObjs(cairo_t* cr){ m_cairo = cr; auto element = m_world->getFirstObject(); while(element != nullptr){ drawObj(element->getInfo()); element = element->getProximo(); } drawObj(m_border); }
static PyObject* pyDrawObj(PyObject *self, PyObject *args) { int id; if(!PyArg_ParseTuple(args, "i", &id)) return NULL; drawObj(getObj(id)); Py_RETURN_NONE; }
void Panel::doRefresh(void) { unsigned short i; for(i=0;i<mNumOfObj;i++) { if(mObjArr[i]->isVisible()) drawObj(mObjArr[i]); } }
void Widget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // gluLookAt(radius*qCos(AngToRad*xRot), yRot, radius*qSin(AngToRad*xRot), 0, 0, 0, 0, 1, 0); if(isObjOn){ drawObj(); } else { drawTriangle(); } glFlush(); }
void drawFixeds() { int i; for (i = 0; i < FIXED_OBJECTS_NUMBER; i++) { glPushMatrix(); glTranslatef(fixeds[i].x, fixeds[i].translate, fixeds[i].y); glScalef(fixeds[i].scale, fixeds[i].scale, fixeds[i].scale); drawObj(*(fixeds_objs[i])); glPopMatrix(); } }
/* Drawing Functions */ void drawCoins(void) { int i; for (i = 0; i < DYNAMIC_OBJECTS_NUMBER; i++) { if (coins[i].visible) { glPushMatrix(); glTranslatef(coins[i].x, coins[i].translate, coins[i].y); drawObj(*obj); glPopMatrix(); } } }
bool nnView::draw(void) { bool res = false; int x, y; nnPoint map = {0}; if (parent) { IManager *manager = parent->getManager(); IViewGlue * glue = parent->getView(); if (glue != nullptr) { nnObjManager & mn = *dynamic_cast<nnObjManager*>(manager); nnPoint off = glue->getOffsetView(); nnPoint map = glue->getMap(); InnObj *obj; res = true; map += off; for (y = off.y; y < map.y; y++) { for (x = off.x; x < map.x; x++) { obj = manager->getObj(x, y); if (obj) { res &= drawObj(obj, x, y, glue); } else { res &= drawBkg(x, y, glue); } } } } if (res) { drawPower(glue); } } return res; }
void APP_OBJLoader::Draw() { Gizmos::clear(); Gizmos::addTransform(glm::mat4(1)); vec4 white(1); vec4 black(0, 0, 0, 1); // draws the home grid for (int i = 0; i < 21; ++i) { Gizmos::addLine(vec3(-10 + i, 0, 10), vec3(-10 + i, 0, -10), i == 10 ? white : black); Gizmos::addLine(vec3(10, 0, -10 + i), vec3(-10, 0, -10 + i), i == 10 ? white : black); } drawObj(); Gizmos::draw(GameCam->GetProjectionView()); }
void drawSceneObjects(void) { //glPushMatrix(); // red cube // glTranslatef(0.0f, 0.0f, 0.0f); // glColor4f(1.0, 0.0, 0.0, 1.0); // glutSolidCube(0.1); //glPopMatrix(); // //glPushMatrix(); // blue sphere // glTranslatef(0.0f, 0.0f, -2.0f); // glColor4f(0.0, 0.5, 1.0, 1.0); // glutSolidSphere(1, 30, 30); //glPopMatrix(); // //glPushMatrix(); // orange sphere // glTranslatef(3.0f, 0.0f, 0.0f); // glColor4f(1.0, 0.5, 0.0, 1.0); // glutSolidSphere(1, 15, 15); //glPopMatrix(); // //glPushMatrix(); // pink whosum // glTranslatef(-3.0f, 0.0f, -2.0f); // glColor4f(1.0, 0.5, 1.0, 1.0); // glutSolidTorus(0.1, 0.5, 15, 15); //glPopMatrix(); // //glPushMatrix(); // yellow whassum // glTranslatef(-3.0f, 0.0f, -20.0f); // glColor4f(1.0, 1.0, 0.0, 1.0); // glutSolidDodecahedron(); //glPopMatrix(); glBegin(GL_TRIANGLES); drawObj(); glEnd(); }
void pickFaces(int button, int state, int x, int y) { GLuint selectBuf[BUFSIZE]; GLint hits; GLint viewport[4]; if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) { return; } glGetIntegerv(GL_VIEWPORT, viewport); glSelectBuffer(BUFSIZE, selectBuf); (void) glRenderMode(GL_SELECT); glInitNames(); glPushName(0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); /* create 5x5 pixel picking region near cursor location */ gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 5.0, 5.0, viewport); glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5); // glOrtho(0.0f, windowWidth, windowHeight, 0.0f, 0.0f, 1.0f); drawObj(GL_SELECT); glMatrixMode (GL_PROJECTION); glPopMatrix(); glutSwapBuffers(); hits = glRenderMode(GL_RENDER); processHits(hits, selectBuf); glutPostRedisplay(); }
int main() { lightDir.x=0.5; lightDir.y=.7; lightDir.z=-0.5; kmVec3Normalize(&lightDir,&lightDir); // creates a window and GLES context // create a window and GLES context if (!glfwInit()) exit(EXIT_FAILURE); window = glfwCreateWindow(width, height, "I N V A D E R S ! ! !", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowSizeCallback(window,window_size_callback); glfwMakeContextCurrent(window); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); // The obj shapes and their textures are loaded cubeTex = loadPNG("resources/textures/dice.png"); loadObj(&cubeObj, "resources/models/cube.gbo", "resources/shaders/textured.vert", "resources/shaders/textured.frag"); shipTex = loadPNG("resources/textures/shipv2.png"); loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj); alienTex = loadPNG("resources/textures/alien.png"); loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj); shotTex = loadPNG("resources/textures/shot.png"); loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj); expTex = loadPNG("resources/textures/explosion.png"); playerPos.x = 0; playerPos.y = 0; playerPos.z = 0; kmMat4Identity(&view); pEye.x = 0; pEye.y = 2; pEye.z = 4; pCenter.x = 0; pCenter.y = 0; pCenter.z = -5; pUp.x = 0; pUp.y = 1; pUp.z = 0; kmMat4LookAt(&view, &pEye, &pCenter, &pUp); // projection matrix, as distance increases // the way the model is drawn is effected kmMat4Identity(&projection); kmMat4PerspectiveProjection(&projection, 45, (float)width/ height, 0.1, 1000); glViewport(0, 0, width,height); // these two matrices are pre combined for use with each model render kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); // initialises glprint's matrix shader and texture initGlPrint(width,height); font1=createFont("resources/textures/font.png",0,256,16,16,16); font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // only used by glprintf glEnable(GL_DEPTH_TEST); int num_frames = 0; bool quit = false; resetAliens(); for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { playerShots[n].alive = false; } initPointClouds("resources/shaders/particle.vert", "resources/shaders/particle.frag",(float)width/24.0); for (int n = 0; n < MAX_ALIENS; n++) { aliens[n].explosion=createPointCloud(40); resetExposion(aliens[n].explosion); // sets initials positions } glClearColor(0, .5, 1, 1); while (!quit) { // the main loop clock_gettime(0,&ts); // note the time BEFORE we start to render the current frame glfwPollEvents(); if (glfwGetKey(window,GLFW_KEY_ESCAPE)==GLFW_PRESS || glfwWindowShouldClose(window)) quit = true; float rad; // radians rotation based on frame counter glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); frame++; rad = frame * (0.0175f * 2); //kmMat4Identity(&model); kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z); playerCroll += (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral) / 2); // kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3); // kmMat4RotationYawPitchRoll(&rot,0,3.1416,-playerCroll*3); kmMat4Multiply(&model, &model, &rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shipTex); drawObj(&shipObj, &mvp, &mv, lightDir, viewDir); glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16, font2,"frame=%i", frame); kmVec3 tmp; playerFireCount--; if (glfwGetKey(window,GLFW_KEY_LEFT_CONTROL)==GLFW_PRESS && playerFireCount < 0) { struct playerShot_t *freeShot; freeShot = getFreeShot(); if (freeShot != 0) { playerFireCount = 15; freeShot->alive = true; kmVec3Assign(&freeShot->pos, &playerPos); } } for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { if (playerShots[n].alive) { playerShots[n].pos.z -= .08; if (playerShots[n].pos.z < -10) playerShots[n].alive = false; //kmMat4Identity(&model); kmMat4Translation(&model, playerShots[n].pos.x, playerShots[n].pos.y, playerShots[n].pos.z); //kmMat4RotationPitchYawRoll(&model, rad * 4, 0, // -rad * 4); kmMat4RotationYawPitchRoll(&rot,rad*4,0,-rad*4); kmMat4Multiply(&model,&model,&rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shotTex); drawObj(&shotObj, &mvp, &mv, lightDir, viewDir); } } playerRoll = 0; if (glfwGetKey(window,GLFW_KEY_LEFT)==GLFW_PRESS && playerPos.x > -10) { playerPos.x -= 0.1; playerRoll = .2; } if (glfwGetKey(window,GLFW_KEY_RIGHT)==GLFW_PRESS && playerPos.x < 10) { playerPos.x += 0.1; playerRoll = -.2; } pEye.x = playerPos.x * 1.25; pCenter.x = playerPos.x; pCenter.y = playerPos.y + 1; pCenter.z = playerPos.z; int deadAliens; deadAliens = 0; for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].alive == true) { //kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); //kmMat4RotationPitchYawRoll(&model, -.4, 0, 0); kmMat4RotationYawPitchRoll(&rot,.2,0,0); kmMat4Multiply(&model,&model,&rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, alienTex); drawObj(&alienObj, &mvp, &mv, lightDir, viewDir); kmVec3 d; for (int i = 0; i < MAX_PLAYER_SHOTS; i++) { kmVec3Subtract(&d, &aliens[n].pos, &playerShots[i].pos); if (kmVec3Length(&d) < .7 && playerShots[i].alive) { aliens[n].alive = false; playerShots[i].alive = false; aliens[n].exploding = true; resetExposion(aliens[n].explosion); } } } if (aliens[n].alive != true && aliens[n].exploding != true) { deadAliens++; } } if (deadAliens == MAX_ALIENS) { resetAliens(); } // draw explosions after ALL aliens for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].exploding==true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); glBindTexture(GL_TEXTURE_2D, expTex); drawPointCloud(aliens[n].explosion, &mvp); aliens[n].explosion->tick=aliens[n].explosion->tick+0.05; if (aliens[n].explosion->tick>1.25) { aliens[n].exploding=false; } else { // update the explosion for (int i=0; i<aliens[n].explosion->totalPoints; i++) { float t; t=aliens[n].explosion->tick; if (i>aliens[n].explosion->totalPoints/2) t=t/2.0; aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t; aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t; aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t; } } } } // move camera kmMat4LookAt(&view, &pEye, &pCenter, &pUp); kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); kmVec3Subtract(&viewDir,&pEye,&pCenter); kmVec3Normalize(&viewDir,&viewDir); // dump values glPrintf(100, 280, font1,"eye %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z); glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y, pCenter.z); glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20); glfwSwapBuffers(window); ts.tv_nsec+=20000000; // 1000000000 / 50 = 50hz less time to render the frame //thrd_sleep(&ts,NULL); // tinycthread usleep(20000); // while I work out why tinycthread that was working isnt.... :/ } glfwDestroyWindow(window); glfwTerminate(); return 0; }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); drawObj(GL_RENDER); glutSwapBuffers(); }
int main(int argc, char *argv[]) { chdir("/Users/tjgreen/Documents/OpenGL/Sol"); GLFWwindow *window = setupGLFW(); GLuint skyboxTexture = initCubemap(); //GLFWwindow* window2 = glfwCreateWindow(500, 500, "SolarSystem", NULL, NULL); //glfwMakeContextCurrent(window2); /*Cross platform compatibility stuff uncomment if not on mac GLenum err = glewInit(); if (GLEW_OK != err) { printf(stderr, "Error: %s\n", glewGetErrorString(err)); }*/ sunTexture = loadTexture("include/textures/Planets/sun2.jpg"); sunNormal = loadTexture("include/textures/Planets/sunNormal.png"); planetBuilder(); init(); createPerspectiveMatrix(); initializePlanetButtons(); glEnable(GL_CULL_FACE); glEnable(GL_MULTISAMPLE); glCullFace(GL_BACK); attachGUIShaders(); float fpsFrames= 0; float lastTime = 0; while(!glfwWindowShouldClose(window)) { GLfloat currentFrame = glfwGetTime(); deltaTime = currentFrame - lastFrame; lastFrame = currentFrame; fpsFrames++; if(currentFrame - lastTime >= 1.0) { //printf("%f\n", 1000/fpsFrames); fpsFrames = 0; lastTime += 1.0; } glfwPollEvents(); doMovement(); glfwPollEvents(); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, WIDTH, HEIGHT); drawSkybox(skyboxTexture); drawSun(); drawPlanet(); //glFrontFace(GL_CW); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); drawAtmosphere(); glDisable(GL_BLEND); //glFrontFace(GL_CCW); drawObj(); drawMoon(); //drawButton(button1); //drawPlanetButtons(); if(stopRotation == 0){ for(int i = 0; i < 11; i++) { orbitSpeedArray[i] += 0.1/planetInstanceArray[i].orbit; } for(int i = 0; i < 11; i++) { rotationSpeedArray[i] += 0.1/planetInstanceArray[i].day; } thetaY += 0.1; } glfwSwapBuffers(window); } glDeleteVertexArrays(1, &planetVAO); glDeleteBuffers(1, &planetVBO); glfwTerminate(); return 0; }
void display(void){ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); if (GetAsyncKeyState(VK_END)) { radius+=0.25; zoomFactor += 0.02; } if (GetAsyncKeyState(VK_HOME)) { if (radius > 2) radius-=0.25; zoomFactor -= 0.02; } // Zoom by changing view frustum /* glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0*zoomFactor,(float)width/(float)height,0.2,80.0); glMatrixMode(GL_MODELVIEW); */ if (currentAction == NAVIGATE) ; else updateCameraPos(); gluLookAt(lookFromx, lookFromy, lookFromz, lookAtx, lookAty, lookAtz, upx, upy, upz); glEnable(GL_TEXTURE_2D); // Draw Boundary Walls glTexImage2D( // initialize texture GL_TEXTURE_2D, // texture is 2-d 0, // resolution level 0 GL_RGB, // internal format boundaryWallPix[0].nCols, // image width boundaryWallPix[0].nRows, // image height 0, // no border GL_RGB, // my format GL_UNSIGNED_BYTE, // my type boundaryWallPix[0].pixel); // the pixels for (int i = 0; i < numBoundaryWalls; i++) { drawMesh(boundaryWalls[i]); } // Draw Inner Walls glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, innerWallPix[0].nCols, innerWallPix[0].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, innerWallPix[0].pixel); for (int i = 0; i < numInnerWalls; i++) { drawMesh(innerWalls[i]); } VECTOR3D temp = VECTOR3D(personBody->translation.x + 7.0, personBody->translation.y, personBody->translation.z); if (temp.GetQuaddLength() < 9){ doors[0]->angles.y = 90.0; doors[0]->translation.x = -10.0; doors[0]->translation.z = -1.5; doors[1]->angles.y = -90.0; doors[1]->translation.x = -4.0; doors[1]->translation.z = -1.5; } else { doors[0]->angles.y = 0.0; doors[0]->translation.x = -8.5; doors[0]->translation.z = 0.0; doors[1]->angles.y = 0.0; doors[1]->translation.x = -5.5; doors[1]->translation.z = 0.0; } temp = VECTOR3D(personBody->translation.x, personBody->translation.y, personBody->translation.z+8.0); if (temp.GetQuaddLength() < 9){ doors[2]->angles.y = 90.0; doors[2]->translation.x = 1.0; doors[2]->translation.z = -10.0; doors[3]->angles.y = -90.0; doors[3]->translation.x = 1.0; doors[3]->translation.z = -6.0; //cout << "Distance is < 4.0" << endl; } else { doors[2]->angles.y = 0.0; doors[2]->translation.x = 0.0; doors[2]->translation.z = -9.0; doors[3]->angles.y = 0.0; doors[3]->translation.x = 0.0; doors[3]->translation.z = -7.0; //cout << "Distance is greater than 1" << endl; } // Draw left doors glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, doorPix[0].nCols, doorPix[0].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, doorPix[0].pixel); drawMesh(doors[0]); drawMesh(doors[2]); // Draw right doors glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, doorPix[1].nCols, doorPix[1].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, doorPix[1].pixel); drawMesh(doors[1]); drawMesh(doors[3]); // Draw Floor glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, floorPix[0].nCols, floorPix[0].nRows, 0, GL_RGB, GL_UNSIGNED_BYTE, floorPix[0].pixel); terrainGrid->DrawGrid(gridSize); // Draw Person drawMesh(personBody, personHead); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); for (int i = 0; i < 12; i++){ drawObj(cobj[i]); } glDisable(GL_TEXTURE_2D); glutSwapBuffers(); }
int main() { lightDir.x=0.5; lightDir.y=.7; lightDir.z=-0.5; kmVec3Normalize(&lightDir,&lightDir); // creates a window and GLES context if (makeContext() != 0) exit(-1); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); // The obj shapes and their textures are loaded cubeTex = loadPNG("resources/textures/dice.png"); loadObj(&cubeObj, "resources/models/cube.gbo", "resources/shaders/textured.vert", "resources/shaders/textured.frag"); shipTex = loadPNG("resources/textures/shipv2.png"); loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj); alienTex = loadPNG("resources/textures/alien.png"); loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj); shotTex = loadPNG("resources/textures/shot.png"); loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj); expTex = loadPNG("resources/textures/explosion.png"); playerPos.x = 0; playerPos.y = 0; playerPos.z = 0; kmMat4Identity(&view); pEye.x = 0; pEye.y = 2; pEye.z = 4; pCenter.x = 0; pCenter.y = 0; pCenter.z = -5; pUp.x = 0; pUp.y = 1; pUp.z = 0; kmMat4LookAt(&view, &pEye, &pCenter, &pUp); // projection matrix, as distance increases // the way the model is drawn is effected kmMat4Identity(&projection); kmMat4PerspectiveProjection(&projection, 45, (float)getDisplayWidth() / getDisplayHeight(), 0.1, 100); glViewport(0, 0, getDisplayWidth(), getDisplayHeight()); // these two matrices are pre combined for use with each model render kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); // initialises glprint's matrix shader and texture initGlPrint(getDisplayWidth(), getDisplayHeight()); font1=createFont("resources/textures/font.png",0,256,16,16,16); font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // only used by glprintf glEnable(GL_DEPTH_TEST); struct timeval t, ta, t1, t2; // fps stuff gettimeofday(&t1, NULL); int num_frames = 0; bool quit = false; mouse = getMouse(); keys = getKeys(); resetAliens(); for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { playerShots[n].alive = false; } initPointClouds("resources/shaders/particle.vert", "resources/shaders/particle.frag",(float)getDisplayWidth()/24.0); for (int n = 0; n < MAX_ALIENS; n++) { aliens[n].explosion=createPointCloud(40); resetExposion(aliens[n].explosion); // sets initials positions } while (!quit) { // the main loop doEvents(); // update mouse and key arrays // mask of 4 is right mouse if (keys[KEY_ESC]) quit = true; glClearColor(0, .5, 1, 1); // render between two gettimeofday calls so // we can sleep long enough to roughly sync // to ~60fps but not on the pi! // TODO find something a tad more elegent long i; gettimeofday(&t, NULL); i = t.tv_sec * 1e6 + t.tv_usec; // render(); float rad; // radians rotation based on frame counter glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); frame++; rad = frame * (0.0175f * 2); kmMat4Identity(&model); kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z); playerCroll += (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral) / 2); kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3); // kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shipTex); drawObj(&shipObj, &mvp, &mv, lightDir, viewDir); glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16, font2,"frame=%i fps=%3.2f", frame, lfps); kmVec3 tmp; playerFireCount--; if (keys[KEY_LCTRL] && playerFireCount < 0) { struct playerShot_t *freeShot; freeShot = getFreeShot(); if (freeShot != 0) { playerFireCount = 15; freeShot->alive = true; kmVec3Assign(&freeShot->pos, &playerPos); } } for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { if (playerShots[n].alive) { playerShots[n].pos.z -= .08; if (playerShots[n].pos.z < -10) playerShots[n].alive = false; kmMat4Identity(&model); kmMat4Translation(&model, playerShots[n].pos.x, playerShots[n].pos.y, playerShots[n].pos.z); kmMat4RotationPitchYawRoll(&model, rad * 4, 0, -rad * 4); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shotTex); drawObj(&shotObj, &mvp, &mv, lightDir, viewDir); } } playerRoll = 0; if (keys[KEY_CURSL] && playerPos.x > -10) { playerPos.x -= 0.1; playerRoll = .2; } if (keys[KEY_CURSR] && playerPos.x < 10) { playerPos.x += 0.1; playerRoll = -.2; } pEye.x = playerPos.x * 1.25; pCenter.x = playerPos.x; pCenter.y = playerPos.y + 1; pCenter.z = playerPos.z; int deadAliens; deadAliens = 0; for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].alive == true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4RotationPitchYawRoll(&model, -.4, 0, 0); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, alienTex); drawObj(&alienObj, &mvp, &mv, lightDir, viewDir); kmVec3 d; for (int i = 0; i < MAX_PLAYER_SHOTS; i++) { kmVec3Subtract(&d, &aliens[n].pos, &playerShots[i].pos); if (kmVec3Length(&d) < .7 && playerShots[i].alive) { aliens[n].alive = false; playerShots[i].alive = false; aliens[n].exploding = true; resetExposion(aliens[n].explosion); } } } if (aliens[n].alive != true && aliens[n].exploding != true) { deadAliens++; } } if (deadAliens == MAX_ALIENS) { resetAliens(); } // draw explosions after ALL aliens for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].exploding==true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); glBindTexture(GL_TEXTURE_2D, expTex); drawPointCloud(aliens[n].explosion, &mvp); aliens[n].explosion->tick=aliens[n].explosion->tick+0.05; if (aliens[n].explosion->tick>1.25) { aliens[n].exploding=false; } else { // update the explosion for (int i=0; i<aliens[n].explosion->totalPoints; i++) { float t; t=aliens[n].explosion->tick; if (i>aliens[n].explosion->totalPoints/2) t=t/2.0; aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t; aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t; aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t; } } } } // move camera kmMat4LookAt(&view, &pEye, &pCenter, &pUp); kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); kmVec3Subtract(&viewDir,&pEye,&pCenter); kmVec3Normalize(&viewDir,&viewDir); // dump values glPrintf(100, 280, font1,"eye %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z); glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y, pCenter.z); glPrintf(100, 320, font1,"mouse %i,%i %i ", mouse[0], mouse[1], mouse[2]); glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20); swapBuffers(); gettimeofday(&ta, NULL); long j = (ta.tv_sec * 1e6 + ta.tv_usec); i = j - i; if (i < 0) i = 1000000; // pass through - slower that 60fps if (i < 16000) usleep(16000 - i); // every 10 frames average the time taken and store // fps value for later printing with glprintf if (++num_frames % 10 == 0) { gettimeofday(&t2, NULL); float dtf = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) * 1e-6; lfps = num_frames / dtf; num_frames = 0; t1 = t2; } } closeContext(); return 0; }