Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //final project Miguel y Emmanuel
- #include <windows.h>
- #include <GL/gl.h>
- #include <glut.h>
- #include <math.h>
- #include "Camera.h"
- #include "Vector3.h"
- #include <iostream>
- #include <assert.h>
- #include <fstream>
- #include <string.h>
- #include <stdio.h>
- #include <time.h>
- #include "textures.h"
- #include "terrain.h"
- #include <gl/GLU.h>
- using namespace std;
- /*********************************/
- /* NAVIGATION VARIABLES */
- /*********************************/
- /* 0.- Terrain texture
- * 1.- Military Texture for Tents
- */
- static GLuint textures[3];
- /*********************************/
- /* NAVIGATION VARIABLES */
- /*********************************/
- Camera *camera;
- float mouse_x, mouse_y;
- bool mouse_updated = false;
- /*********************************/
- /* TERRAIN VARIABLES */
- /*********************************/
- RGBpixmap myTexs[3];
- void init(void)
- {
- // Set clear (background) color
- glClearColor(0.62, 0.90, 0.98, 0.0);
- // Set light properties...
- GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
- GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
- // Finish setting up the two lights (position, and component values (specular and diffuse))
- glLightfv(GL_LIGHT0, GL_POSITION, light_position);
- glLightfv(GL_LIGHT0, GL_AMBIENT, white_light);
- //glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
- // Define material properties
- GLfloat mat_specular[] = { 0.8, 0.9, 1.0, 1.0 };
- GLfloat mat_shininess[] = { 30.0 };
- GLfloat mat_surface[] = { 0.7, 0.7, 0.7, 1.0 };
- // Set material properties, as defined above
- glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
- glMaterialfv(GL_FRONT, GL_AMBIENT, mat_surface);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_surface);
- // Set shading model to use
- glShadeModel (GL_SMOOTH);
- // Enable lighting
- glEnable(GL_LIGHTING);
- // Activate (enable) lights
- glEnable(GL_LIGHT0);
- // Enable depth testing (for hidden surface removal)
- glEnable(GL_DEPTH_TEST);
- // Enable texture
- glEnable(GL_TEXTURE_2D);
- glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
- // Initialize textures
- glGenTextures(2, textures);
- // Initialize terrain texture
- myTexs[0].SetTexColor(1.0, 1.0, 1.0);
- myTexs[0].readBMPFile("escaleras2.bmp");
- myTexs[0].SetTexture(textures[0]);
- // Initializse military texture
- myTexs[1].SetTexColor(1.0, 1.0, 1.0);
- myTexs[1].readBMPFile("escaleras1.bmp");
- myTexs[1].SetTexture(textures[1]);
- // Initialize textures
- //glGenTextures(2, textures);
- // Initialize terrain texture
- myTexs[2].SetTexColor(1.0, 1.0, 1.0);
- myTexs[2].readBMPFile("grass.bmp");
- myTexs[2].SetTexture(textures[2]);
- // Initialize the camera for navigation
- camera = new Camera();
- camera->set( 5, 5, 5, 0, 5, 5, 0, 1, 0 );
- }
- void escalera(float peldanos){
- float ancho=10.0;
- float alto=1.0;
- float profundo=2.0;
- float peldanos=4;
- for(int k=0;k<peldanos;k++){
- cout<<"---------------k vale --------------"<<k<<"\n";
- //parte frontal del peldaño
- //con la textura 0 de escalera
- glBindTexture(GL_TEXTURE_2D, textures[0]);
- //inicia dibujando el primer peldaño
- cout<<"**************imprime parte frontal del peldaño**********"<<"\n";
- glBegin(GL_QUADS);
- glTexCoord2f(0.0, 0.0);
- glVertex3f(0.0, alto*k, profundo*(-k));
- cout<<"+++++++++++++++++ vertex 1 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<0.0<<" y: "<<alto*k<<" z: "<<profundo*(-k)<<"\n";
- glTexCoord2f(1.0, 0.0);
- glVertex3f(ancho, alto*k, profundo*(-k));
- cout<<"+++++++++++++++++ vertex 2 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<ancho<<" y: "<<alto*k<<" z: "<<profundo*(-k)<<"\n";
- glTexCoord2f(1.0, 1.0);
- glVertex3f(ancho, alto*(k+1), profundo*(-k));
- cout<<"+++++++++++++++++ vertex 3 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<ancho<<" y: "<<alto*(k+1)<<" z: "<<profundo*(-k)<<"\n";
- glTexCoord2f(0.0, 1.0);
- glVertex3f(0.0, alto*(k+1),profundo*(-k));
- cout<<"+++++++++++++++++ vertex 4 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<0.0<<" y: "<<alto*(k+1)<<" z: "<<profundo*(-k)<<"\n";
- glEnd();
- //parte superior del peldaño
- //con la textura 1 de escalera
- glBindTexture(GL_TEXTURE_2D, textures[1]);
- //inicia dibujando el primer peldaño
- cout<<"**************imprime parte superior del peldaño**********"<<"\n";
- glBegin(GL_QUADS);
- glTexCoord2f(0.0, 0.0);
- glVertex3f(0.0, alto*(k+1), profundo*(-k));
- cout<<"+++++++++++++++++ vertex 1 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<0.0<<" y: "<<alto*(k+1)<<" z: "<<profundo*(-k)<<"\n";
- glTexCoord2f(1.0, 0.0);
- glVertex3f(ancho, alto*(k+1), profundo*(-k));
- cout<<"+++++++++++++++++ vertex 2 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<ancho<<" y: "<<alto*(k+1)<<" z: "<<profundo*(-k)<<"\n";
- glTexCoord2f(1.0, 1.0);
- glVertex3f(ancho, alto*(k+1), profundo*(k+1)*(-1));
- cout<<"+++++++++++++++++ vertex 3 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<ancho<<" y: "<<alto*(k+1)<<" z: "<<profundo*(k+1)*(-1)<<"\n";
- glTexCoord2f(0.0, 1.0);
- glVertex3f(0.0, alto*(k+1), profundo*(k+1)*(-1));
- cout<<"+++++++++++++++++ vertex 4 ++++++++++++++++++++++"<<"\n";
- cout<<"x: "<<0.0<<" y: "<<alto*(k+1)<<" z: "<<profundo*(k+1)*(-1)<<"\n";
- glEnd();
- }
- }
- void display(void)
- {
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
- glPushMatrix();
- // Draw terrain
- glBindTexture(GL_TEXTURE_2D, textures[2]);
- drawTerrain();
- glPopMatrix();
- ///dibuja escaleras
- glPushMatrix();
- escalera(5.0);
- glPopMatrix();
- glFlush();
- glutSwapBuffers();
- }
- void mouse_motion( int x, int y ) {
- float dx, dy;
- if( ! mouse_updated) {
- mouse_x = x;
- mouse_y = y;
- mouse_updated = true;
- } else {
- dx = x - mouse_x;
- dy = y - mouse_y;
- mouse_x = x;
- mouse_y = y;
- //camera->pitch( dy / 30.0 );
- camera->yaw( dx );
- }
- }
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key) {
- case 0x1B:
- case 'q':
- case 'Q': exit(0); break;
- default: break;
- }
- }
- void specialKeyboard(int key, int x, int y) {
- switch(key) {
- case GLUT_KEY_UP : camera->slide( 0.0, 0.0, -2.0 ); break;
- case GLUT_KEY_DOWN : camera->slide( 0.0, 0.0, 2.0 ); break;
- case GLUT_KEY_LEFT : camera->slide( -2.0, 0.0, 0.0 ); break;
- case GLUT_KEY_RIGHT : camera->slide( 2.0, 0.0, 0.0 ); break;
- }
- }
- int main (int argc, char** argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowSize(1024, 800);
- glutInitWindowPosition(100, 100);
- glutCreateWindow("Final Project");
- init();
- glutKeyboardFunc(keyboard);
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutSpecialFunc(specialKeyboard);
- glutPassiveMotionFunc(mouse_motion);
- glutMainLoop();
- return 0;
- }
Add Comment
Please, Sign In to add comment