Escalar
Rotar
// gifu.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <GL/glut.h> // Librería de OpenGL
#include <stdlib.h> //Libreria estandar de ANSI C
#include <stdio.h>
#include <iostream>
#include <gl\glut.h>
using namespace std;
GLfloat x=0.0,y=0.0,z=0.0,girarX=0.0,girarY=0.0,girarZ=0.0;
float vertice1[]={0,0,-3};
float vertice2[]={0,0,3};
float vertice3[]={6,0,-3};
float vertice4[]={3,6,3};
void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(0.2,0.3,0.9);// glClearColor (0.3, 0.0, 1, 0.0);
gluLookAt(0,5,20,0,0,0,0,1,0);
glTranslatef(x,y,z);
glRotatef(girarX,0,1,0);
glRotatef(girarY,1,0,0);
glRotatef(girarZ,0,0,1);
glBegin(GL_TRIANGLES);
glColor3f(0,0,1);
glVertex3fv(vertice1);
glVertex3fv(vertice3);
glVertex3fv(vertice2);
glColor3f(1,1,0);
glVertex3fv(vertice3);
glVertex3fv(vertice2);
glVertex3fv(vertice4);
glColor3f(1,0,0);
glVertex3fv(vertice2);
glVertex3fv(vertice1);
glVertex3fv(vertice4);
glColor3f(0,1,0);
glVertex3fv(vertice1);
glVertex3fv(vertice3);
glVertex3fv(vertice4);
glEnd();
glFlush();
glutSwapBuffers();
}
void Redimensionar(GLsizei ancho, GLsizei altura){
if(altura == 0)
{
altura = 1;
}
glViewport(0, 0, ancho, altura);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(ancho>altura)
{
gluPerspective(45.0f,ancho/altura,1,150.0f);
}
else
{
gluPerspective(45.0f,altura/ancho,1,150.0f);
}
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_CULL_FACE);
}
void teclado(unsigned char key,int inX, int inY)
{
if(key == 'm')
{
y=y+0.5f;
glutPostRedisplay();
}
if(key == 'n')
{
y=y-0.5f;
glutPostRedisplay();
}
if(key == 'h')
{
x=x+0.5f;
glutPostRedisplay();
}
if(key == 'j')
{
x=x-0.5f;
glutPostRedisplay();
}
if(key == 's')
{
z=z+0.5f;
glutPostRedisplay();
}
if(key == 'd')
{
z=z-0.5f;
glutPostRedisplay();
}
if(key == 'x')
{
girarX=girarX-10;
glutPostRedisplay();
}
if(key == 'y')
{
girarY=girarY-10;
glutPostRedisplay();
}
if(key == 'z')
{
girarZ=girarZ+10;
glutPostRedisplay();
}
}
void myinit()
{
// glClearColor (0.3, 0.0, 0, 0.5);
glClearColor (0.3, 0.9, 0, 0.9);
}
void IniciarGL(void)
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}
void main(void)
{
myinit();
glutInitWindowSize(800,600);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100,100);
glutCreateWindow("Figure");
glutDisplayFunc(display);
glutReshapeFunc(Redimensionar);
glutKeyboardFunc(teclado);
IniciarGL();
glutMainLoop();
glutDestroyWindow(glutGetWindow());
}
No hay comentarios:
Publicar un comentario