NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include<windows.h>
#include<stdio.h>
#include<GL/glut.h>
#define outcode int
double xmin=50,ymin=50,xmax=100,ymax=100;
double xvmin=200,yvmin=200,xvmax=300,yvmax=300;
const int RIGHT = 8;
const int LEFT = 2;
const int TOP = 4;
const int BOTTOM=1;

outcode ComputeOutCode(double x,double y);

void CohenSutherlandLineClipAndDraw(double x0,double y0,double x1,double y1)
{
outcode outcode0,outcode1,outcodeOut;
bool accept = false,done = false;
outcode0 = ComputeOutCode(x0,y0);
outcode1 = ComputeOutCode(x1,y1);

do
{
if(!(outcode0|outcode1))
{
accept = true;
done = true;
}
else if(outcode0 & outcode1)
done = true;
else
{
double x,y;
outcodeOut = outcode0? outcode0: outcode1;

if(outcodeOut & TOP)
{
x = x0 + (x1-x0) * (ymax - y0)/(y1-y0);
y = ymax;
}
else if(outcodeOut & BOTTOM)
{
x = x0 + (x1-x0) * (ymin - y0)/(y1-y0);
y = ymin;
}
else if(outcodeOut & RIGHT)
{
y = y0 + (y1-y0) * (xmax - x0)/(x1-x0);
x = xmax;
}
else
{
y = y0 + (y1-y0) * (xmin-x0)/(x1-x0);
x = xmin;
}

if(outcodeOut == outcode0)
{
x0 = x;
y0 = y;
outcode0 = ComputeOutCode(x0,y0);
}
else
{
x1 = x;
y1 = y;
outcode1 = ComputeOutCode(x1,y1);
}
}
}while(!done);

if(accept)
{
double sx = (xvmax - xvmin)/(xmax-xmin);
double sy = (yvmax - yvmin)/(ymax-ymin);
double vx0 = xvmin + (x0-xmin)*sx;
double vy0 = yvmin + (y0-ymin)*sy;
double vx1 = xvmin + (x1-xmin)*sx;
double vy1 = yvmin + (y1-ymin)*sy;
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(xvmin,yvmin);
glVertex2f(xvmax,yvmin);
glVertex2f(xvmax,yvmax);
glVertex2f(xvmin,yvmax);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINES);
glVertex2d(vx0,vy0);
glVertex2d(vx1,vy1);
glEnd();
}
}

outcode ComputeOutCode(double x,double y)
{
outcode code = 0;
if(y>ymax)
code |= TOP;
else if(y<ymin)
code |= BOTTOM;
if(x>xmax)
code |= RIGHT;
else if(x<xmin)
code |= LEFT;
return code;
}

void display()
{
double x0=120,y0=10,x1=40,y1=130;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_LINES);
glVertex2d(x0,y0);
glVertex2d(x1,y1);
glVertex2d(60,20);
glVertex2d(80,120);
glEnd();
glColor3f(0.0,0.0,1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(xmin,ymin);
glVertex2f(xmax,ymin);
glVertex2f(xmax,ymax);
glVertex2f(xmin,ymax);
glEnd();
CohenSutherlandLineClipAndDraw(x0,y0,x1,y1);
CohenSutherlandLineClipAndDraw(60,20,80,120);
glFlush();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("Cohen Sutherland Line Clipping Algorithm");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.