cuadrics - WordPress.com

Transcripción

cuadrics - WordPress.com
Quadrics
Un ejemplo de comos e utiliza
Realizar practica de modelado de la parte de primer nivel, y la practica 2 “luces y materiales”
de nivel dos.
Se muestra una modificacion del programa base.cpp, dejamos inicializacion,Luces, materiales,
una funcion de ejes de referencia y el cubo Solamente, se dejo la funcion cilindro que quedo
para modificar los quadrics, lo demas se quito.
Para crear un cilindro con quadrics cree un objeto que le llame “mi objeto” y por lotanto se
cambio en las partes donde se inicializa, se crear, se utuliza y se borra nuestro objeto de
interes. Luego notamos que nuestro cilindro del ejemplo tenia por error un valor negativo, se
le quito el signo y listo.
Se recomienda al alumno realizar lo mismo con base.cpp y cambiarle de nombre (para no
perder el original) e irlo modificando como lo hicimos, su programa debera quedar parecido a
este programa completo modificado al final de este pdf. Tambien cambia a otras opciones de
Quadrics.
Programa completo
#include <openglut.h>
//declaracion de variables
GLUquadricObj *miobjeto;
GLfloat light_Ambient [4] = { 0.4, 0.4, 0.4, 1.0};
GLfloat light_Diffuse [4] = { 0.7, 0.7, 0.7, 1.0};
GLfloat light_Position [4] = {20.0, 15.0, 10.0, 1.0};
GLfloat
GLfloat
GLfloat
GLfloat
GLfloat
GLfloat
material
RedMaterial
GreenMaterial
BlueMaterial
WhiteMaterial
BlackMaterial
[4]
[4]
[4]
[4]
[4]
[4]
=
=
=
=
=
=
{1.0,
{1.0,
{0.0,
{0.0,
{1.0,
{0.0,
0.2,
0.0,
1.0,
0.0,
1.0,
0.0,
0.2,
0.0,
0.0,
1.0,
1.0,
0.0,
1.0
1.0
1.0
1.0
1.0
0.0
};
};
};
};
};
};
void inicializacion()
{
glutInitWindowSize(800,600);
glutInitWindowPosition(100,100);
glutCreateWindow("utilizando Quadrics con OpenGL");
}
void luces(void)
{
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ambient );
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Diffuse );
glLightfv(GL_LIGHT0, GL_POSITION, light_Position );
}
void materiales()
{
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material );
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glShadeModel (GL_FLAT);
}
void EjesReferencia()
{
glBegin (GL_LINES);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, RedMaterial );
glVertex3f ( 0.0, 0.0, 0.0);
glVertex3f (20.0, 0.0, 0.0);//eje x
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, GreenMaterial
);
glVertex3f ( 0.0, 0.0, 0.0);
glVertex3f ( 0.0,20.0, 0.0);//eje y
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, WhiteMaterial );
glVertex3f ( 0.0, 0.0, 0.0);
glVertex3f ( 0.0, 0.0,20.0);//eje z: profundidad
glEnd();
}
void cuboreferencia()
{
//cotas a 5 unidades. Z es Negativa
glBegin (GL_LINE_STRIP);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, BlackMaterial );
glVertex3f (5.0, 5.0, 0.0);//plano superior
glVertex3f ( 0, 5.0, 0.0);
glVertex3f (0, 5.0, 5.0);
glVertex3f ( 5.0, 5.0, 5.0);
glVertex3f (5.0, 5.0, 0.0);//plano fin1
glVertex3f ( 5.0, 0.0, 0.0);
glVertex3f ( 5.0, 0.0, 5.0);
glVertex3f (0.0, 0.0, 5.0);//plano inferior
glVertex3f (0, 5.0, 5.0);
glVertex3f ( 5.0, 5.0, 5.0);
glVertex3f ( 5.0, 0.0, 5.0);
glEnd();
}
void cilindro()
{
miobjeto = gluNewQuadric();
gluQuadricDrawStyle( miobjeto,GLU_FILL);
gluQuadricNormals( miobjeto, GLU_SMOOTH);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//glRotatef(-90,1.0,0.0,0.0);
gluCylinder( miobjeto, 2, 2, 3, 5, 5);
glPopMatrix();
gluDeleteQuadric(miobjeto);
}
void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
luces();
EjesReferencia();
cuboreferencia();
materiales();
cilindro();
glFlush();
}
void camara()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5,5,-5,5,-10,10); //esta es proyeccion plana
//gluPerspective(35,800/600,0,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,0, 15,15,15, 0,1,0);
}
int main(void)
{
inicializacion();
glutDisplayFunc(RenderScene);
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
camara();
glutMainLoop();
return 0;
}
Salida

Documentos relacionados