Thursday, September 29, 2011

Figure 23


$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 23
===================
Note: Here, you just click and the line is formed. There is no need to drag and so on.
=================

/*
//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
*/
// EditingPolygons2.cpp : Defines the entry point for the console application.
//


#include
#include

int width=500, height=600, vert[100][2], n=0, type=GL_LINE_STRIP, v;
bool rubberbanding=false, antialiasing=false;

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
if(n==1 && (type==GL_LINE_STRIP || type==GL_LINE_LOOP)){
glBegin(GL_POINTS);
glVertex2iv(vert[0]);
glEnd();
}
glBegin(type);
for(int i=0; i glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{

}
int findVertex(int x, int y)
{
int dx, dy;
for(int i=0; i dx=vert[i][0]-x;
dy=vert[i][0]-y;
if(dx*dx+dy*dy<16) return i;
}
return -1;
}
void mouse(int button, int state, int x, int y)
{
switch(button)
{
case GLUT_LEFT_BUTTON:
if(state==GLUT_DOWN){//mouse down
v=n++;
vert[v][0]=x;
vert[v][1]=height-1-y;
rubberbanding=true;
glutPostRedisplay();
std::cout<<"In state == GLUT_DOWN \n";
}
else{ rubberbanding=false; std::cout<<"In the else ...\n";}//mouse released
break;
case GLUT_RIGHT_BUTTON:
if(state==GLUT_DOWN && (v=findVertex(x, height-1-y)!=-1)){
if(glutGetModifiers()==GLUT_ACTIVE_CTRL){
for(int i=v; i vert[i][0]=vert[i+1][0];
vert[i][1]=vert[i+1][1];
}
n--;
}else{//attach vertex to cursor
vert[v][0]=x;
vert[v][1]=height-1-y;
rubberbanding=true; //start rubber banding
}
glutPostRedisplay();
}
else rubberbanding=false; //end rubber banding
break;
}//end of switch
}
void motion(int x, int y)
{
if(rubberbanding){//if rubberbanding is on, then update
vert[v][0]=x;
vert[v][1]=height-1-y;
std::cout<<"In motion...\n";
glutPostRedisplay();
}
}
void main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowSize(width, height);
glutInitWindowPosition(50,100);
glutCreateWindow("Edit polygons : irap123.com");
glClearColor(0,0,0,0);
glColor3f(1,1,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,width, 0, height);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}

No comments:

Post a Comment