Escaleras.c



// DIBUJO DE LA ESCALERA ...
#include <GL/glut.h>
#include <unistd.h>

void Lado( );

void PintaEjes()
{
	glBegin(GL_LINES);
		glColor3f(1,0,0); glVertex3f(-5, 0, 0); glVertex3f(5, 0, 0);	// X
		glColor3f(0,1,0); glVertex3f(0, -5, 0); glVertex3f(0, 5, 0);	// Y
		glColor3f(0,0,1); glVertex3f(0, 0, -5); glVertex3f(0, 0, 5);	// Z
	glEnd();
	glPushMatrix();
	glColor3f(1,0,0); glTranslatef(5.0f, 0.0f, 0.0f); glutWireSphere(0.20, 20, 20);
	glPopMatrix(); glPushMatrix();
	glColor3f(0,1,0); glTranslatef(0.0f, 5.0f, 0.0f); glutWireSphere(0.20, 20, 20);
	glPopMatrix(); glPushMatrix();
	glColor3f(0,0,1); glTranslatef(0.0f, 0.0f, 5.0f); glutWireSphere(0.20, 20, 20);
	glPopMatrix();
}

void Gradua  ( )
{
	int k=0, x1,y1,x2,y2;

	glColor3f(1,0,0); glPushMatrix();
	for(k=1; k<10; k++)
	{
		glTranslatef(0.5, 0, 0);
		glBegin(GL_LINES); glVertex3f(0, 0.2, 0); glVertex3f(0, -0.2, 0); glEnd();
	}
	glPopMatrix();
	glPushMatrix();
	glColor3f(0,1,0);
	for(k=1; k<10; k++)
	{
		glTranslatef(0, 0.5, 0);
		glBegin(GL_LINES); glVertex3f(0.2, 0, 0); glVertex3f(-0.2, 0, 0); glEnd();
	}
	glPopMatrix();
	glPushMatrix();
	glColor3f(0,1, 0);
	for(k=1; k<10; k++)
	{
		glTranslatef(0, 0, 0.5);
		glBegin(GL_LINES); glVertex3f(0.2, 0, 0); glVertex3f(-0.2, 0, 0); glEnd();
	}
	glPopMatrix();
}

void Escalera( )
{
	int k=0, Escalones = 5;

	glPushMatrix( );
	for (k=0; k<Escalones; k++)
	{
		Lado( );
		glTranslatef( 0, 0, 1); glPushMatrix( ); glRotatef(90, 0, 1, 0 ); Lado( ); glPopMatrix( );
		glTranslatef( 1, 0, 0); Lado( ); 
	}
	glPopMatrix( );
}

void Lado ( )
{
	glColor3f(0,1,1);
	glBegin(GL_QUADS);
		glVertex3f(0, 1, 0); glVertex3f(0, -1, 0); glVertex3f(0, -1, 1); glVertex3f(0, 1, 1);
	glEnd();
}

Inicializa()
{
	glClearColor(0.0,0.0,0.0,0.0); glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-8.0,8.0, -8.0,8.0, -7.0,7.0);
	glMatrixMode(GL_MODELVIEW);
	gluLookAt(-1,-1,1,  2,2,-1,  0,0,1);			// (yo_x, yo_y, yo_z,      obj_x, obj_y, obj_z,      cab_x, cab_y, cabz)
	//gluLookAt(1,1,-1,  0,0,-1,  0,1,0);
}

void Dibuja(void)
{	
	glClear(GL_COLOR_BUFFER_BIT);
	PintaEjes( ); Gradua( );
	Escalera( );
	glFlush();
}

int main(int argc, char ** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
	glutInitWindowPosition(700,100);
	glutInitWindowSize(650,650);
	glutCreateWindow("USO DE LA CAMARA ... ");
	Inicializa();
	glutDisplayFunc(Dibuja);
	glutMainLoop();
}