#include "stdafx.h"
#include <glut.h>
#include <math.h>
#define PI 3.1415926
void Dibuja();
void Inicializa();
void Listas();
void InitCamara();
void Especial(int,int,int);
void Raton(int,int,int,int);
void Mueve(int,int);
float ambiental[4]={.19225,.19225,.19225,1},
difusa[4]={.50754,.50754,.50754,1},
especular[4]={.508273,.508273,.508273,1},
posicion[4]={-45,25,-48,1};
unsigned int pino=1, muñecos=2, montaña=3;
float pcx,pcy,pcz,ocx,ocy,ocz,upx,upy;
float teta,phi,inc,eta;
int ok,xini,yini,okd;
void main()
{
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutInitWindowPosition(100,100);
glutCreateWindow("Camara");
glutDisplayFunc(Dibuja);
glutSpecialFunc(Especial);
glutMotionFunc(Mueve);
glutMouseFunc(Raton);
Inicializa();
glutMainLoop();
}
void Inicializa()
{
glClearColor(0,0,0,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80,1.333,.1,80);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glLightfv(GL_LIGHT1,GL_AMBIENT,ambiental);
glLightfv(GL_LIGHT1,GL_DIFFUSE,difusa);
glLightfv(GL_LIGHT1,GL_POSITION,posicion);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH);
ambiental[0]=ambiental[1]=ambiental[2]=0;
glFogfv(GL_FOG_COLOR,ambiental);
glFogf(GL_FOG_MODE,GL_EXP);
glFogf(GL_FOG_DENSITY,0.04);
glEnable(GL_FOG);
Listas();
InitCamara();
}
void Dibuja()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(pcx,pcy,pcz,ocx,ocy,ocz,upx,upy,0);
glPushMatrix();
//PISO------------------------------
glDisable(GL_LIGHTING);
glColor3f(.7,.7,.7);
glBegin(GL_QUADS);
glVertex3f(-30,-10,10);
glVertex3f(-30,-1,-25);
glVertex3f(30,-1,-25);
glVertex3f(30,-10,10);
glEnd();
glEnable(GL_LIGHTING);
//PINOS----------------------------
glTranslated(-5,-1,0);
glCallList(pino);
glPopMatrix();
glPushMatrix();
glTranslated(7,-.2,-2);
glCallList(pino);
glPopMatrix();
glPushMatrix();
glTranslated(8,-.2,-10);
glCallList(pino);
glPopMatrix();
glPushMatrix();
glTranslated(5,-.2,-6);
glCallList(pino);
//MUÑECOS-------------------
glPopMatrix();
glPushMatrix();
glTranslated(4,-1,0);
glCallList(muñecos);
glPopMatrix();
glPushMatrix();
glTranslated(-4,-1,-5);
glCallList(muñecos);
glPopMatrix();
glPushMatrix();
glTranslated(0,-1,3);
glCallList(muñecos);
glPopMatrix();
glPushMatrix();
glTranslated(8,1.4,-15);
glRotated(45,0,1,0);
glCallList(muñecos);
glPopMatrix();
glPushMatrix();
glTranslated(-10,1.2,-15);
glRotated(45,0,1,0);
glCallList(muñecos);
//MONTAÑAS---------------------
glPopMatrix();
glPushMatrix();
glCallList(montaña);
glPopMatrix();
glPushMatrix();
glTranslated(9,0,0);
glCallList(montaña);
glPopMatrix();
glPushMatrix();
glTranslated(20,0,0);
glCallList(montaña);
glPopMatrix();
glPushMatrix();
glTranslated(30,0,0);
glCallList(montaña);
glPopMatrix();
glPushMatrix();
glTranslated(-13,0,0);
glCallList(montaña);
glPopMatrix();
glPushMatrix();
glTranslated(-20,0,0);
glCallList(montaña);
glPopMatrix();
glPushMatrix();
glTranslated(-30,0,0);
glCallList(montaña);
//LUNA------------------------------------------------
glPopMatrix();
ambiental[0]=0, ambiental[1]=0, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,5);
glTranslated(-45,25,-48);//x,z,y
glutSolidSphere(9,99,99);
glutSwapBuffers();
}
void Listas()
{
GLUquadricObj *p;
p=gluNewQuadric();
//MONTAÑAS--------------------------------------------------------
glNewList(montaña,GL_COMPILE);
ambiental[0]=.6, ambiental[1]=.2, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,10);
glTranslated(0,8,-35);
glRotated(90,1,0,0);
gluCylinder(p,3,9,10,9,4);
ambiental[0]=1, ambiental[1]=1, ambiental[2]=1;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,10);
glTranslated(0,0,-5);//xzy
gluCylinder(p,.1,3,5,9,9);
glEndList();
//PINOS-------------------------------------------------
glNewList(pino,GL_COMPILE);
gluQuadricDrawStyle(p,GLU_FILL);
gluQuadricOrientation(p,GLU_OUTSIDE);
//tronco
ambiental[0]=.6, ambiental[1]=.2, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(0,0,-5);
glRotated(90,1,0,0);
gluCylinder(p,.2,.2,1,99,99);
//copas
ambiental[0]=0, ambiental[1]=.9, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glRotated(180,1,0,0);
gluCylinder(p,1,0,2,99,99);
glTranslated(0,0,.5);
gluCylinder(p,.9,0,2,99,99);
glTranslated(0,0,.5);
gluCylinder(p,.8,0,2,99,99);
glEndList();
//MUÑECOS-----------------------------------------------
glNewList(muñecos,GL_COMPILE);
//cuerpo
ambiental[0]=.9, ambiental[1]=.9, ambiental[2]=.9;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(0,-2,-6);
glutSolidSphere(.8,99,99);
glTranslated(0,-1,0);
glutSolidSphere(1,99,99);
glTranslated(0,2.1,0);
glutSolidSphere(.5,99,99);
//ojos
ambiental[0]=0, ambiental[1]=0, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(-.2,.2,.45);
glutSolidSphere(.1,99,99);
glTranslated(.4,0,0);
glutSolidSphere(.1,99,99);
//botones
glTranslated(-.2,-.8,.2);
glutSolidSphere(.1,99,99);
glTranslated(0,-.2,.2);
glutSolidSphere(.1,99,99);
glTranslated(0,-.2,.1);
glutSolidSphere(.1,99,99);
//sonrisa
glTranslated(-.09,.8,-.5);
glutSolidSphere(.05,99,99);
glTranslated(.1,0,0);
glutSolidSphere(.05,99,99);
glTranslated(.1,0,0);
glutSolidSphere(.05,99,99);
glTranslated(.1,.05,0);
glutSolidSphere(.05,99,99);
//nariz
ambiental[0]=.8, ambiental[1]=.3, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(-.2,.2,-.1);
glutSolidCone(.1,1,99,99);
//sombrero
ambiental[0]=0, ambiental[1]=0, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(0,.3,-.4);
glRotated(90,1,0,0);
glutSolidTorus(.1,.5,99,99);
glTranslated(0,0,-.6);
gluCylinder(p,.5,.5,.6,90,90);
glEndList();
gluDeleteQuadric(p);
}
void InitCamara()
{
inc=0.8;
teta=180;
phi=0;
eta=90;
pcx=0;
pcy=0;
pcz=0;
ocx=cos(phi*PI/180)*sin(teta*PI/180)+pcx;
ocy=sin(phi*PI/180)+pcy;
ocz=cos(phi*PI/180)*cos(teta*PI/180)+pcz;
upx=cos(eta*PI/180);
upy=sin(eta*PI/180);
}
void Especial (int tecla,int x, int y)
{
if(tecla==GLUT_KEY_UP)
{
pcx+=inc*sin(teta*PI/180);
ocx+=inc*sin(teta*PI/180);
pcz+=inc*cos(teta*PI/180);
ocz+=inc*cos(teta*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_DOWN)
{
pcx-=inc*sin(teta*PI/180);
ocx-=inc*sin(teta*PI/180);
pcz-=inc*cos(teta*PI/180);
ocz-=inc*cos(teta*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_RIGHT)
{
pcx+=inc*sin((teta-90)*PI/180);
ocx+=inc*sin((teta-90)*PI/180);
pcz+=inc*cos((teta-90)*PI/180);
ocz+=inc*cos((teta-90)*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_LEFT)
{
pcx-=inc*sin((teta-90)*PI/180);
ocx-=inc*sin((teta-90)*PI/180);
pcz-=inc*cos((teta-90)*PI/180);
ocz-=inc*cos((teta-90)*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_PAGE_UP)
{
pcy+=inc;
ocy+=inc;
glutPostRedisplay();
}
if(tecla==GLUT_KEY_PAGE_DOWN)
{
pcy-=inc;
ocy-=inc;
glutPostRedisplay();
}
}
void Raton(int boton, int edo, int x, int y)
{
if(boton==GLUT_LEFT_BUTTON)
{
ok=1;
okd=0;
xini=x;
yini=y;
}
if(boton==GLUT_RIGHT_BUTTON)
{
ok=0;
okd=1;
xini=x;
}
if(boton==GLUT_MIDDLE_BUTTON)
{
ok=0;
okd=0;
}
}
void Mueve(int x, int y)
{
int dx,dy;
if(ok)
{
dx=x-xini;
dy=y-yini;
xini=x;
yini=y;
teta-=dx*0.3;
if(teta>360)
teta-=360;
if(teta<0)
teta+=360;
phi-=dy*0.3;
if(phi>89)
phi=89;
if(phi<-89)
phi=-89;
ocx=cos(phi*PI/180)*sin(teta*PI/180)+pcx;
ocy=sin(phi*PI/180)+pcy;
ocz=cos(phi*PI/180)*cos(teta*PI/180)+pcz;
glutPostRedisplay();
}
if(okd)
{
dx=x-xini;
xini=x;
eta+=dx*0.3;
if(eta>360)
eta-=360;
if(eta<0)
eta+=360;
upx=cos(eta*PI/180);
upy=sin(eta*PI/180);
glutPostRedisplay();
}
}
P.O.O, Estructura de Datos, Tópicos Selectos de Programación, Fundamentos de Programación, Teoría de la Computación, Matemáticas para Computadoras, Fundamentos de Desarrollo de Sistemas, Programación Web, Graficación.
jueves, 8 de noviembre de 2012
miércoles, 7 de noviembre de 2012
API REST con ASP.NET
Aquí la liga del turorial!
http://www.codeproject.com/Articles/426769/Creating-a-REST-service-using-ASP-NET-Web-API
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
Desarrollaremos la aplicación cliente con:
http://appinventor.mit.edu/
API's e información:
http://www.programmableweb.com/
http://www.codeproject.com/Articles/426769/Creating-a-REST-service-using-ASP-NET-Web-API
Después de haber probado el tutorial anterior, llegué a la conclusión de que algunas funciones o métodos no estaban actualizados por lo que buscando en la página de descarga de librería encontré este tutorial que les va a servir. Además tiene más ejemplos.
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
Desarrollaremos la aplicación cliente con:
http://appinventor.mit.edu/
API's e información:
http://www.programmableweb.com/
miércoles, 31 de octubre de 2012
Luces en polígonos no predefinidos.
#include "stdafx.h"
#include<GL\glut.h>
#include<math.h>
void Inicializacion(void);
void Dibuja(void);
int _tmain(int argc, _TCHAR* argv[])
{
glutInitDisplayMode(GLUT_RGB|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(600,600);
glutInitWindowPosition(200,200);
glutCreateWindow("Cubo en OpenGL");
Inicializacion();
glutDisplayFunc(Dibuja);
glutMainLoop();
return 0;
}
void Inicializacion(void){
glMatrixMode(GL_PROJECTION); //coordenadas objeto en 3D
glLoadIdentity(); //Matriz identidad
gluPerspective(70,1,0.1,100);
glMatrixMode(GL_MODELVIEW);
/*glTranslated(0,0,-10);
glRotated(-253,0,1,0);
*/glClearColor(1,1,1,0);
glShadeModel(GL_SMOOTH);
glEnable(GL_CULL_FACE); //
glCullFace(GL_BACK); //glCullFace determina qué polígonos deben de descartarse, en este caso los traceros.
glFrontFace(GL_CW); //EL polígono está en el sentido de las manesillas del reloj
}
void Dibuja(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
GLfloat ambientlight[4] = {0.5f ,0.5f ,0.5f ,1.0f};
float glfLightPosition[4] = {0.0, 2, 7.0, 1.0};
float glfLightDiffuse[4] = {0.7, 0.7, 0.7, 1.0};
float glfLightSpecular[4] = {0.7, 0.7, 0.7, 1.0};
//glLightfv(GL_LIGHT0,GL_AMBIENT,ambientlight);
glLightfv(GL_LIGHT0, GL_POSITION, glfLightPosition); // Se definen las
glLightfv(GL_LIGHT0, GL_DIFFUSE, glfLightDiffuse); //carácterísticas de la
glLightfv(GL_LIGHT0, GL_SPECULAR, glfLightSpecular);// luces
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
//--------------------------------------------------
glPushMatrix();
float ambiental[4]={1,0,0,1};
float especular[4]={0.5,0,0.5,1};
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 30);
glTranslated(0,0,-10);
glRotated(45,10,10,0);
glBegin(GL_QUADS);
//cara 1
glColor3f(0,0,1);
glNormal3d(-8,0,-8);
glVertex3d(-2,-2,2);
//glNormal3d(0,8,-8);
glVertex3d(-2,2,2);
//glNormal3d(8,0,-8);
glVertex3d(2,2,2);
//glNormal3d(0,-8,-8);
glVertex3d(2,-2,2);
//cara2
glColor3f(1,0,1);
glNormal3d(0,0,8);
glVertex3d(2,2,-2);
glNormal3d(-8,0,0);
glVertex3d(-2,2,-2);
glVertex3d(-2,-2,-2);
glVertex3d(2,-2,-2);
//cara3
glColor3f(1,0,0);
glNormal3d(8,-8,8);
glVertex3d(-2,2,2);
//glNormal3d(8,-8,0);
glVertex3d(-2,-2,2);
//glNormal3d(8,8,-8);
glVertex3d(-2,-2,-2);
glVertex3d(-2,2,-2);
//cara 4
glColor3f(0,1,0);
glVertex3d(2,-2,2);
glVertex3d(2,2,2);
glVertex3d(2,2,-2);
glVertex3d(2,-2,-2);
//cara 5
glColor3f(1,1,0);
glVertex3d(-2,2,2);
glVertex3d(-2,2,-2);
glVertex3d(2,2,-2);
glVertex3d(2,2,2);
//cara 6
glColor3f(0,1,1);
glVertex3d(-2,-2,2);
glVertex3d(2,-2,2);
glVertex3d(2,-2,-2);
glVertex3d(-2,-2,-2);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
lunes, 29 de octubre de 2012
Exposición de día de Muertos.
Para todos los alumnos(as) que deseen participar, el día 1 de noviembre, en la entrada del edificio E se llevará acabo una exposición de día de muertos para lo cual se les solicita la realización de unas calaveritas literarias, alguna calavera de papel, papel picado, etc.
Pueden entregar el material con la Lic. Dora Ortíz.
De antemano gracias y espero que participen. Saludos.
@rezzaca
Suscribirse a:
Entradas (Atom)
