Siwy
Gaduła
Dołączył: 02 Gru 2007
Posty: 93
Przeczytał: 0 tematów
|
Wysłany: Nie 10:52, 14 Cze 2009 Temat postu: grupa c - dajcie co macie |
|
|
#pragma warning(disable : 4244)
#pragma warning(disable : 4305)
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
//
#include <GL/glaux.h>
#include <GL/gl.h>
#include <GL/glu.h>
#define MODE_NUM 3
#define M_PI 3.14
GLfloat angle = 0.0f, speed = 0.4f, two_side = 0.0f;
GLfloat odl_perspk = 100.0, odl_perspp=15.0;
GLboolean zmiana_persp = GL_TRUE;
GLboolean swiatlo1=GL_TRUE, swiatlo2=GL_TRUE;
GLint cieniowanie=GL_SMOOTH;
GLint my_w, my_h;
GLboolean wl_kamere=GL_FALSE;
GLenum mode [MODE_NUM] = {
GL_FILL,
GL_LINE,
GL_POINT };
int mode_num = 0;
GLfloat front_shininess[] = {0.0};
GLfloat front_specular[] = {0.8f, 1.0f, 0.1f, 1.0f};
GLfloat front_diffuse[] = {0.8f, 1.0f, 0.1f, 1.0f};
GLfloat back_diffuse[] = {0.2, 0.5, 0.9, 1.0f};
GLfloat torus_ambient_and_diffuse[] = { 0.0, 0.8, 0.0, 0.5f };
GLfloat torus_emission[] = { 0.3, 0.2, 0.1, 0.5F };
GLfloat bulb_ambient_and_diffuse[] = { 0.4, 0.4, 0.1, 0.5f };
GLfloat bulb_emission[] = { 0.8f, 0.7f, 0.1f, 1.0f };
GLfloat p1_emission[] = { 0.2f, 0.2f, 0.6f, 0.65f };
GLfloat p2_emission[] = { 0.8f, 0.2f, 0.1f, 0.5f };
GLfloat p3_emission[] = { 0.1f, 0.9f, 0.5f, 0.5f };
GLfloat p4_emission[] = { 0.4f, 0.2f, 0.8f, 0.7f };
GLfloat light_position[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat light1_pos[] = { 0.0f, 0.0f, 1.0f, 1.0f };
void my_init(void){
GLfloat color_amb[]={0.2f,0.3f,0.2f,1.0f};
wl_kamere=GL_TRUE;
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.0, 0.0, 0.0, 0.0);
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,two_side);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glPolygonMode(GL_BACK,GL_FILL);
glPolygonMode(GL_FRONT,GL_FILL);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_BACK); glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glEnable(GL_LINE_SMOOTH);
}
void CALLBACK key_t(void) {
two_side=1-two_side;
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,two_side);
printf("\n\rTwo side=%f",two_side);
}
void CALLBACK key_b(void) {
wl_kamere^=GL_TRUE;
if (wl_kamere)
{ /*glMatrixMode(GL_PROJECTION);*/
glPopMatrix();
glPushMatrix();
gluLookAt(30,50,-20,0,0,-50,0,1,0);
/*glMatrixMode(GL_MODELVIEW);*/
}
else {
/*glMatrixMode(GL_PROJECTION);*/
glPopMatrix();
glPushMatrix();
gluLookAt(0,0,2,0,0,-50,0,1,0);
/*glMatrixMode(GL_MODELVIEW);*/
}
printf("\n\rWlacz kamere: %s",(wl_kamere ? "TAK":"NIE"));
}
void CALLBACK key_m(void) {
mode_num--;
if (mode_num < 0)
mode_num = 0;
else
{
glPolygonMode(GL_FRONT, mode[mode_num]);
}
}
void CALLBACK key_n(void)
{
mode_num++;
if (mode_num >= MODE_NUM)
mode_num = MODE_NUM - 1;
else
glPolygonMode(GL_FRONT, mode[mode_num]);
}
void CALLBACK my_display4(void){
GLfloat a,b,kat,ya,yb,xa,xb;
a=6.0;
b=1.0;
kat=89.0f;
xa=a*sin(kat*M_PI/180.0f);
ya=a*cos(kat*M_PI/180.0f);
xb=b*sin(kat*M_PI/180.0f);
yb=b*cos(kat*M_PI/180.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0, 0.0, -100.0);
glPushMatrix();
glTranslatef(10.0, -20.0, 10.0);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_SPECULAR, front_specular);
glLightfv(GL_LIGHT0, GL_DIFFUSE, front_diffuse);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, bulb_ambient_and_diffuse);
glMaterialfv(GL_FRONT, GL_EMISSION, bulb_emission);
glPopMatrix();
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
glColor3f(1.0f,0.0f,0.0f); // y
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,20.0f,0.0f);
glColor3f(1.0f,0.1f,0.0f); // x
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(20.0f,0.0f,0.0f);
glColor3f(1.0f,0.0f,0.0f); // z
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(00.0f,0.0f,30.0f);
glColor3f(0.0f,1.0f,0.0f); // I
glVertex3f(7.0f,0.0f,0.0f);
glVertex3f(7.0f,10.0f,0.0f);
glColor3f(0.0f,1.0f,0.0f); // II
glVertex3f(4.0f,0.0f,0.0f);
glVertex3f(4.0f,0.0f,30.0f);
glEnd();
glPushMatrix(); // 1
glColor3f(1,0,1);
glRotatef(angle,0,2,0);
glTranslatef(7,8,0);
auxSolidSphere(1);
glPopMatrix();
glPushMatrix(); // 2
glColor3f(0,1,1);
glRotatef(angle,1,0,0);
glTranslatef(7,4,0);
auxSolidSphere(1);
glPopMatrix();
glPushMatrix(); // 3
glColor3f(0,0,1);
glRotatef(angle*0,0,0,0);
glTranslatef(0,7,7);
auxSolidSphere(1);
glPopMatrix();
glPushMatrix(); // 4
glColor3f(1,1,1);
glRotatef(angle*0,0,0,0);
glTranslatef(0,7,16);
auxSolidSphere(1);
glPopMatrix();
glEnable(GL_LIGHTING);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
glPopMatrix();
glEnable(GL_CULL_FACE);
glFlush();
auxSwapBuffers();
}
void CALLBACK bulb_movement(void){
angle += speed;
my_display4();
}
void CALLBACK increase_speed(AUX_EVENTREC *event){
if(speed < 25.6) speed *= 2;
printf("Aktualna predkosc wynosi %.5f \r", speed);
}
void CALLBACK decrease_speed(AUX_EVENTREC *event){
if(speed > 0.00626) speed /= 2;
printf("Aktualna predkosc wynosi %.5f \r", speed);
}
GLfloat rad2deg(GLfloat rad) {
return (rad*180/M_PI);
}
GLfloat deg2rad(GLfloat kat) {
return (kat*M_PI/180);
}
void CALLBACK my_reshape(GLsizei w, GLsizei h){
my_w=w; my_h=h;
if(!h) return;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w < h)
if (zmiana_persp) {
glFrustum(-5.0f, 5.0f, -5.0f*h/w, 5.0f*h/w, odl_perspp, odl_perspk);
printf("Funkcja glFrustum!\r");
}
else {
gluPerspective(60, (GLdouble)h/w, odl_perspp, odl_perspk);
gluPerspective(2*rad2deg(atan2(5.0f*h/w,odl_perspp)), (GLdouble)h/w, odl_perspp, odl_perspk);
printf("Funkcja gluPerspective\r");
}
else
if (zmiana_persp) {
glFrustum(-5.0f*w/h, 5.0f*w/h, -5.0f, 5.0f, odl_perspp, odl_perspk);
printf("Funkcja glFrustum!\r");
}
else {
gluPerspective(2*rad2deg(atan2(5.0f*w/h,odl_perspp)), (GLdouble)w/h, odl_perspp, odl_perspk);
printf("Funkcja gluPerspective\r");
}
glPushMatrix();
if (wl_kamere) gluLookAt(30,10,-20,0,0,-80,0,1,0);
else gluLookAt(0,0,0,0,0,-80,0,1,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CALLBACK zmiana_perspektywy(void){
zmiana_persp ^= GL_TRUE;
my_reshape(my_w,my_h);
}
void CALLBACK key_a(void){
swiatlo1 ^= GL_TRUE;
if (swiatlo1) glEnable(GL_LIGHT0); else glDisable(GL_LIGHT0);
my_reshape(my_w,my_h);
}
void CALLBACK key_s(void){
swiatlo2 ^= GL_TRUE;
if (swiatlo2) glEnable(GL_LIGHT1); else glDisable(GL_LIGHT1);
my_reshape(my_w,my_h);
}
void CALLBACK inc_kon(void){
if(odl_perspk < 200) odl_perspk += 2;
my_reshape(my_w,my_h);
printf("Aktualna odlegl konca perspektywy wynosi %.5f \r", odl_perspk);
}
void CALLBACK dec_kon(void){
if (odl_perspk > 51) odl_perspk -= 2;
my_reshape(my_w,my_h);
printf("Aktualna odlegl konca perspektywy wynosi %.5f \r", odl_perspk);
}
void CALLBACK inc_pocz(void){
if(odl_perspp < 50) odl_perspp += 2;
my_reshape(my_w,my_h);
printf("Aktualna odlegl początku perspektywy wynosi %.5f \r", odl_perspp);
}
void CALLBACK dec_pocz(void){
if (odl_perspp > 1) odl_perspp -= 2;
my_reshape(my_w,my_h);
printf("Aktualna odlegl początku perspektywy wynosi %.5f \r", odl_perspp);
}
void main(void){
auxInitDisplayMode (AUX_DOUBLE | AUX_RGBA | AUX_DEPTH);
auxInitPosition (50, 100, 700, 400);
auxInitWindow ("Lighted Torus with blending");
my_init ();
auxReshapeFunc (my_reshape);
auxIdleFunc (bulb_movement);
auxKeyFunc(AUX_LEFT,inc_pocz);
auxKeyFunc(AUX_UP,inc_kon);
auxKeyFunc(AUX_RIGHT,dec_pocz);
auxKeyFunc(AUX_DOWN,dec_kon);
auxKeyFunc(AUX_z,zmiana_perspektywy);
auxKeyFunc(AUX_b, key_b); // kamera
auxKeyFunc(AUX_m, key_m); // polygon mode front +
auxKeyFunc(AUX_n, key_n); // polygon mode front -
auxKeyFunc(AUX_t, key_t); // two side lightmodel
auxKeyFunc(AUX_a, key_a); // swiatlo 0
auxKeyFunc(AUX_s, key_s); // swiatlo 1
auxMouseFunc (AUX_RIGHTBUTTON, AUX_MOUSEDOWN, increase_speed);
auxMouseFunc (AUX_LEFTBUTTON, AUX_MOUSEDOWN, decrease_speed);
auxMainLoop (my_display4);
}
|
|