static double setCameraAndOrient(float ang,int w, int h, int isUpdated) { GLdouble wx,wy,wz; double cameraDist; double y_c; double distH; static double ang_0= M_PI/3.0; static double y_v0= 1.6; static double z_v0= .8; int iter= 0; if (!isUpdated) { orientMe(ang); return 0; } cameraDist= z_v0/cos(ang_0); y_c= y_v0-z_v0*tan(ang_0); y= (y_c+cameraDist*sin(angle))*h; z= -cameraDist*cos(angle)*h; x= w/2; orientMe(ang); readMatsProject(x,h,z_level,&wx,&wy,&wz); while ( fabs(wy-h)> 1 ) { // if (iter>2) // printf ("different wy= %g y= %g\n",wy,y); y+= (wy-h); orientMe(ang); readMatsProject(x,h,z_level,&wx,&wy,&wz); ++iter; } distH= calcProjDepths(w,h); return distH; }
void inputKey(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT : angle -= 0.05f; orientMe(angle);break; case GLUT_KEY_RIGHT : angle +=0.05f; orientMe(angle);break; case GLUT_KEY_UP : moveMeFlat(5);break; case GLUT_KEY_DOWN : moveMeFlat(-5);break; } }
int mainSnowMan(int argc, char **argv) { //GL: glutInit(&argc, argv); //GL: glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); //GL: glutInitWindowPosition(100,100); //GL: glutInitWindowSize(640,360); whSnowman = glutCreateWindow("SnowMen from Lighthouse 3D"); initScene(); glutKeyboardFunc(processNormalKeys); glutSpecialFunc(inputKey); glutDisplayFunc(renderScene); //GL: glutIdleFunc(renderScene); glutReshapeFunc(changeSize); glutIdleFunc(parentIdleFunction); //Hacking a Hitch; Orient Me REquired before a pan. orientMe(0.01f); glutMainLoop(); return(0); }
void renderScene(void) { //float color[] ={1.0,1.0,1.0,1.0}; // clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_LIGHTING); // set the camera glLoadIdentity(); if (deltaMove) moveMeFlat(deltaMove); if (deltaUp) Lookup(deltaUp); if (deltaAngle) { angle += deltaAngle; orientMe(angle); } //float cam[3] = {x,y,z}; gluLookAt(x, y, z, x + lx,y + ly,z + lz, 0.0f,1.0f,0.0f); lightsON(); drawbar(); glutPostRedisplay(); // End of frame glutSwapBuffers(); }
void rotateMe(float ang) { orientMe(ang); ly = -sin(ang); lx = -cos(ang); lz = 1; glLoadIdentity(); gluLookAt(x, y, z, x + lx,y + ly,z + lz, 0.0f,1.0f,0.0f); }
void renderSceneAll(void) { if (deltaMove) { moveMeFlat(deltaMove); } if (deltaAngle) { angle += deltaAngle; orientMe(angle); } // renderScene(); renderScenesw1(); renderScenesw2(); renderScenesw3(); }
void renderScene(void) { unsigned short i; if (deltaMove) moveMeFlat(deltaMove); if (deltaAngle) { angle += deltaAngle; orientMe(angle); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw ground glColor3f(0.9f, 0.9f, 0.9f); glBegin(GL_QUADS); glVertex3f(-100.0f, 0.0f, -100.0f); glVertex3f(-100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, 100.0f); glVertex3f( 100.0f, 0.0f, -100.0f); glEnd(); for (i = 0; i < numParticulas; i++){ // printf("%f - %f X %f - %f\n", lista[i]->x, lista[i]->z, x, z); // glPushMatrix(); glTranslatef(lista[i]->x, 0, lista[i]->z); // glCallList(snowman_display_list);; drawBall(); glTranslatef(-lista[i]->x, 0, -lista[i]->z); moveParticula(lista[i]); glPopMatrix(); } // Draw 36 SnowMen for(int i = 0; i < 36; i++){ //if (boneco[i].live){ glPushMatrix(); glTranslatef(boneco[i].x,0,boneco[i].z); glCallList(boneco[i].dl);; glTranslatef(-boneco[i].x,0,-boneco[i].z); glPopMatrix(); } glutSwapBuffers(); }
void renderScene(void) { mainPlane.manageHealth(); //GLfloat lightpos[] = {-x,-z,-y}; //glTranslatef(lightpos[0], lightpos[1], lightpos[2]); glColor3f(1, 1, 1); //glutSolidSphere(30, 20, 20); //glTranslatef(-lightpos[0], -lightpos[1], -lightpos[2]); //glLightfv(GL_LIGHT0, GL_POSITION, lightpos); if (deltaMove) moveMeFlat(deltaMove); if (deltaAngle) { angle += deltaAngle; orientMe(angle); //rotateMe(angle); } if (rotationAngleDelta) { rotationAngle+=rotationAngleDelta; rotationAngleDelta=0; rotateMe(rotationAngle); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw ground glPushMatrix(); //glLoadIdentity(); //glTranslatef(x, y, z); //glRotatef(rotationAngle+90, 0, 1, 0); explosives.drawExplosions(); //glTranslatef(-x, -y, -z); glPopMatrix(); float minX=200000,maxX=0,minY=20000,maxY=0; glBegin(GL_QUADS); for (int i = 20; i <tiles.size()-20; i++) { for (int j = 20; j <tiles.size()-20; j++) { if(tiles[i][j].xMax>maxX) maxX = tiles[i][j].xMax; if(tiles[i][j].yMax>maxY) maxY = tiles[i][j].yMax; if(tiles[i][j].x<minX) minX = tiles[i][j].x; if(tiles[i][j].y<minY) minY = tiles[i][j].y; if (tiles[i][j].z>-.7) { tiles[i][j].drawTile(); } } } drawWater(maxX*40,maxY*40,minX*40,minY*40); glEnd(); drawTrees(); drawBuildings(); advanceLevel(); drawPlane(); //drawSilos(); drawCarrierGroup(); calculateFPS(); glutSwapBuffers(); //std::cout<<"hello"; indexer++; if (loadBuildings) { loadBuildings = 0; cDetector.buildings = &buildings; } cDetector.detectCollisions(); //glLoadIdentity(); }
void drawPlane(){ //Draw Enemy planes for (int i = 0; i<enemyPlanes.size(); i++) { if (enemyPlanes[i].y>0) { enemyPlanes[i].movePlane(); enemyPlanes[i].drawPlane(); } //enemyPlanes[i].movePlane(); //enemyPlanes[i].drawPlane(); //enemyPlanes[i].adjustAttitudeFacingPlane(mainPlane); if (!enemyPlanes[i].dead) { enemyPlanes[i].huntEnemyPlane(); } enemyPlanes[i].drawBullets(); if (enemyPlanes[i].enemyPlane->dead||enemyPlanes[i].enemyPlane==NULL) { if((rand()%10)>7){ enemyPlanes[i].enemyPlane = &mainPlane; //mainPlane.dead= 0; } enemyPlanes[i].enemyPlane = &friendlyPlanes[(rand()%(friendlyPlanes.size()-1))]; } } //Draw Friendly Planes for (int i = 1; i<friendlyPlanes.size(); i++) { if (friendlyPlanes[i].y>0) { friendlyPlanes[i].movePlane(); friendlyPlanes[i].drawPlane(); }else{ friendlyPlanes.erase(friendlyPlanes.begin()+i); //continue; } //friendlyPlanes[i].adjustAttitudeFacingPlane(mainPlane); if (!friendlyPlanes[i].dead) { friendlyPlanes[i].huntEnemyPlane(); } friendlyPlanes[i].drawBullets(); if (friendlyPlanes[i].enemyPlane->dead||friendlyPlanes[i].enemyPlane==NULL) { if (enemyPlanes.size()<2) { advanceLevel(); }else{ friendlyPlanes[i].enemyPlane = &enemyPlanes[(rand()%(enemyPlanes.size()-1))]; } } } //Chase View y = mainPlane.y+2; double planeYawRad = mainPlane.planeYaw*3.14159262/180; z = mainPlane.z+30*sin(planeYawRad); x = mainPlane.x-30*cos(planeYawRad); orientMe(1.57-planeYawRad); moveMeFlat(0); //Move and draw plane mainPlane.convertDesiredToActual(); mainPlane.movePlane(); mainPlane.drawPlane(); //mainPlane.manageHealth(); mainPlane.drawUserBullets(&enemyPlanes); }
Player::Player() { bomb = nullptr; SDL_GetMouseState(&mouseLastX, &mouseLastY); mouseLeftPressed = false; mouseRightPressed = false; boolKeyboardAngle = false; boolMove = false; allowedToFly = false; boolOnTheGround = false; ySpeed = 0; cameraAngleX = glm::radians(135.f); cameraAngleY = glm::radians(25.f); playerAngleX = cameraAngleX; playerAngleY = cameraAngleY; orientMe(); camlx = playerlx; camlz = playerlz; camly = playerly; x = 0.5f; y = Game::Instance().getMap().getH(0, 0); z = 0.5f; deltaAngle = 0.0; deltaMove=0.0; shootAng = ANG_SHOOT_START; shootForce = SHOOT_FORCE_START; perna1Ang = 245.f; perna2Ang = 40.f; std::vector<glm::vec3> vertices; std::vector<glm::vec2> uvs; std::vector<glm::vec3> normals; float corDino[3] = {25/255.f, 80/255.f, 25/255.f}; loadOBJ("Geometry/Objects/dinobody.obj", vertices, uvs, normals); std::vector<GLfloat> vColor; for(int i=0; i < (int)vertices.size(); i++){ vColor.push_back(corDino[0]); vColor.push_back(corDino[1]); vColor.push_back(corDino[2]); } std::vector<GLfloat> vPos; for(int i=0; i < (int)vertices.size(); i++){ vPos.push_back(vertices[i].x); vPos.push_back(vertices[i].y); vPos.push_back(vertices[i].z); } std::vector<GLfloat> vNormals; for(int i=0; i < (int)normals.size(); i++){ vNormals.push_back(normals[i].x); vNormals.push_back(normals[i].y); vNormals.push_back(normals[i].z); } playerAvatar = new GlObject(Game::Instance().getNormalShader(), vertices.size(), &vPos[0], &vColor[0], normals.size(), &vNormals[0]); std::vector<glm::vec3> verticesLeg; std::vector<glm::vec2> uvsLeg; std::vector<glm::vec3> normalsLeg; loadOBJ("Geometry/Objects/dinoleg.obj", verticesLeg, uvsLeg, normalsLeg); std::vector<GLfloat> vColorLeg1; for(int i=0; i < (int)verticesLeg.size(); i++){ vColorLeg1.push_back(corDino[0]); vColorLeg1.push_back(corDino[1]); vColorLeg1.push_back(corDino[2]); } std::vector<GLfloat> vPosLeg1; for(int i=0; i < (int)verticesLeg.size(); i++){ vPosLeg1.push_back(verticesLeg[i].x); vPosLeg1.push_back(verticesLeg[i].y); vPosLeg1.push_back(verticesLeg[i].z); } std::vector<GLfloat> vNormalsLeg1; for(int i=0; i < (int)normalsLeg.size(); i++){ vNormalsLeg1.push_back(normalsLeg[i].x); vNormalsLeg1.push_back(normalsLeg[i].y); vNormalsLeg1.push_back(normalsLeg[i].z); } playerLeg1 = new GlObject(Game::Instance().getNormalShader(), verticesLeg.size(), &vPosLeg1[0], &vColorLeg1[0], normalsLeg.size(), &vNormalsLeg1[0]); std::vector<GLfloat> vPosLeg2(vPosLeg1); std::vector<GLfloat> vColorLeg2(vColorLeg1); std::vector<GLfloat> vNormalsLeg2(vNormalsLeg1); playerLeg2 = new GlObject(Game::Instance().getNormalShader(), verticesLeg.size(), &vPosLeg2[0], &vColorLeg2[0], normalsLeg.size(), &vNormalsLeg2[0]); updateAvatarAndCamera(); EventAggregator::Instance().getEvent<Tick>().subscribe( [&](Tick &e){ tick(); }); }
void Player::tick() { // botão direito orienta player pra nova direção da camera if(mouseRightPressed) { playerlx = camlx; playerlz = camlz; playerly = camly; playerAngleX = cameraAngleX; playerAngleY = cameraAngleY; } else // só orienta o player pelo teclado quando não controlando direção do player com o mouse { if (boolKeyboardAngle) { playerAngleX += deltaAngle; orientMe(); // só orienta a câmera pra direção do player quando não está sendo controlada pelo mouse if(!mouseLeftPressed) { cameraAngleX = playerAngleX; cameraAngleY = playerAngleY; camlx = playerlx; camly = playerly; camlz = playerlz; } } } // move player com teclas ou com os dois botões do mouse apertados if (boolMove || (mouseLeftPressed && mouseRightPressed)) { // se está movendo com botões do mouse, seta velocidade // de movimento e matém player virado pra direção da câmera if(mouseLeftPressed && mouseRightPressed) { deltaMove = MOVEMENT_SPEED; playerlx = camlx; playerlz = camlz; playerly = camly; playerAngleX = cameraAngleX; playerAngleY = cameraAngleY; } moveMeFlat(deltaMove); } // gravidade y += ySpeed; ySpeed -= GRAVITY; // checa se chegou no chão if(y <= Game::Instance().getMap().getH(x, z)) { y = Game::Instance().getMap().getH(x, z); ySpeed = 0; boolOnTheGround = true; } else boolOnTheGround = false; updateAvatarAndCamera(); }
void NormalKeys(unsigned char key, int x, int y){ if (key == 'p') { if (globalSelection > -1 && globalSelection < scene.size() - 1) { globalSelection++; } } if (key == 'o') { if (globalSelection > 0 && globalSelection < scene.size()) { globalSelection--; } } if (key == 'q'){ exit(0);} if (key == 'e'){ printf("posX: %d ,", x); printf("posY: %d ,", y);} if (key == 'w'){ glTranslatef(0.0f,0.0f,-10.0f); Starla *stary2 = new Starla(x - 100, (y*-1) +100); scene.push_back(stary2); printf("estrellitaaaaaa"); glutPostRedisplay(); glFlush(); printf(" tamanho del vector %d", scene.size()); } if (key == 'r'){ glTranslatef(0.0f,0.0f,-10.0f); glutPostRedisplay(); printf("alejandomeeeee\n");} if (key == 'a'){ Starla *stary2 = new Starla(0, 0); scene.push_back(stary2); glutPostRedisplay(); glFlush(); printf(" tamanho del vector %d", scene.size()); } if (key =='s') { Sphere *stary2 = new Sphere(0,0); scene.push_back(stary2); printf("esferaaaaaaa\n"); glutPostRedisplay(); glFlush(); } if (key =='d') { Cube *stary2 = new Cube(0, 0); scene.push_back(stary2); printf("Cubooooooo\n"); glutPostRedisplay(); glFlush(); } if (key =='f') { Cone *stary2 = new Cone(x, y); scene.push_back(stary2); printf("Conoooo\n"); glutPostRedisplay(); glFlush(); } if (key =='g') { Torus *stary2 = new Torus(0, 0); scene.push_back(stary2); printf("Torusss\n"); glutPostRedisplay(); glFlush(); } if (key =='t') { Cylinder *stary2 = new Cylinder(0, 0); scene.push_back(stary2); printf("Cilindroooooo\n"); glutPostRedisplay(); glFlush(); } if (key == 'z') { angle -= 0.1f;orientMe(angle); glutPostRedisplay(); } if (key=='v') { angle +=0.1f;orientMe(angle); glutPostRedisplay(); } if (key == 'x') { moveMeFlat(10); glutPostRedisplay(); } if (key == 'c') { moveMeFlat(-10); glutPostRedisplay(); } if (key == 'h') { scene[globalSelection]->transladarEjeX(1.0f) ; glutPostRedisplay(); } if (key == 'j') { scene[globalSelection]->transladarEjeY(1.0f) ; glutPostRedisplay(); } if (key == 'k') { scene[globalSelection]->transladarEjeZ(1.0f) ; glutPostRedisplay(); } if (key == 'y') { scene[globalSelection]->transladarEjeX(-1.0f) ; glutPostRedisplay(); } if (key == 'u') { scene[globalSelection]->transladarEjeY(-1.0f) ; glutPostRedisplay(); } if (key == 'i') { scene[globalSelection]->transladarEjeZ(-1.0f) ; glutPostRedisplay(); } if (key == 'n') { scene[globalSelection]->dibujarOrigen(); glutPostRedisplay(); } if (key == 'm') { ponerGrid(); glutPostRedisplay(); } }