Thursday, September 29, 2011

Figure 31


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!


Figure 31
======================
Note: great program. The donut keeps on rotating around, up and down, left and right.
======================

/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If not, you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/
// Lighting.cpp : Defines the entry point for the console application.
//


#include

const int WIDTH=600, HEIGHT=600;
GLfloat pos[]={-2, 4, 5, 1}, //light position
amb[]={0.3, 0.3, 0.3, 1.0};//ambient intensity
GLfloat front_amb_diff[]={0.7, 0.5, 0.1, 1.0};//front side property
GLfloat back_amb_diff[]={0.4, 0.7, 0.1, 1.0};//back side property
GLfloat spe[]={0.25, 0.25, 0.25, 1.0};//property for front and back
GLfloat theta=0, dt=0.5, axes[3][3]={ {1,0,0}, {0,1,0}, {0,0,1}};
int axis=0; //0->x, 1->y, 2->z, 3->light around z

void display()//without rotating the light around z as in the book
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();//preservethe CTM that puts the object inview volume
if(axis<3) glRotated(theta, axes[axis][0], axes[axis][1], axes[axis][2]);
else{
glPushMatrix();
glRotated(theta, 0,0,1);
glLightfv(GL_LIGHT0, GL_POSITION, pos);//redifine the position of the light, pos is never changed, there is effect bec we changed the contents of the glRotated
glPopMatrix();
}
glutSolidTorus(0.4, 1.0, 48, 96); // 48 is the number os slices, 96 slices under the thorus, 1.0 central radius of the thorus, 0.4 radius of the tube that forms the thorus
glPopMatrix();
glutSwapBuffers();
}
void display2()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(theta, axes[axis][0], axes[axis][1], axes[axis][2]);
glutSolidTorus(0.4, 1.0, 48, 96);
glPopMatrix();
glutSwapBuffers();
}
void idle()
{
if(theta>=360) axis=(axis+1)%4;
theta=(theta<360)?theta+dt:dt;
glutPostRedisplay();

}
void idle2()
{
if(theta>=360) axis=(axis+1)%3;
theta=(theta<360)?theta+dt:dt;
glutPostRedisplay();
}
void main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH|GLUT_RGB);
glutInitWindowSize(WIDTH, HEIGHT);
glutInitWindowPosition(300,200);
glutCreateWindow("GLUT Objects by irap123.com");
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45,1.0,2,8);//or use glOrtho(-2, 2,-2, 2, 2, 8);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, front_amb_diff);//front side
glMaterialfv(GL_BACK, GL_AMBIENT_AND_DIFFUSE, back_amb_diff);//back side
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spe);//front and back
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 75);//front and back
glLightfv(GL_LIGHT0, GL_AMBIENT, amb);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);//for solide cobde
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(0,0,-5);
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glutDisplayFunc(display);
glutIdleFunc(idle);
glutMainLoop();
}

No comments:

Post a Comment