SlideShare a Scribd company logo
Introduction to Computer Graphics using OpenGL
Can someone tell me what shall I do to connect between the LineClipping, drawing the line, and
rectangle function? I wrote the code below for the above question:
#include
#define red makecol(255,0,0)
#define green makecol(0,255,0)
#include // use as needed for your system
#include
#include
#include
#include
#include "vector.h"
const int screenWidth = 800;
const int screenHeight = 600;
double xmax, xmin, ymax, ymin;
typedef int OutCode;
double xvmin, yvmin, xvmax, yvmax;
int clicks = 0;
Point positions[4];
bool flag = false;
const int INSIDE = 0; // 0000
const int LEFT = 1;
const int RIGHT = 2;
const int BOTTOM = 4; // 0100
const int TOP = 8;
OutCode ComputeOutCode(double x, double y)
{
OutCode code;
code = INSIDE;
if (x < xmin)
code |= LEFT;
else if (x > xmax)
code |= RIGHT;
if (y < ymin)
code |= BOTTOM;
else if (y > ymax)
code |= TOP;
return code;
}
void LineClipping(double x0, double y0, double x1, double y1)
{
OutCode outcode0 = ComputeOutCode(x0, y0);
OutCode outcode1 = ComputeOutCode(x1, y1);
bool accept = false; bool done = false;
while (done)
{
if (!(outcode0 | outcode1)) // Trivially accept and get out of loop
{
accept = true; done = true;
break;
}
else if (outcode0 & outcode1) // Trivially reject and get out of loop
{
done = true;
break;
}
else
{
// failed both tests, so calculate the line segment to clip
// from an outside point to an intersection with clip edge
double x, y;
// At least one endpoint is outside the clip rectangle; pick it.
OutCode outcodeOut = outcode0 ? outcode0 : outcode1;
// Now find the intersection point;
if (outcodeOut & TOP) { // point is above the clip rectangle
x = x0 + (x1 - x0) * (ymax - y0) / (y1 - y0);
y = ymax;
}
else if (outcodeOut & BOTTOM) { // point is below the clip rectangle
x = x0 + (x1 - x0) * (ymin - y0) / (y1 - y0);
y = ymin;
}
else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle
y = y0 + (y1 - y0) * (xmax - x0) / (x1 - x0);
x = xmax;
}
else if (outcodeOut & LEFT) { // point is to the left of clip rectangle
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);
}
}
}
if (accept)
{
// window to viewport mapping
/* double sx = (xvmax - xvmin) / (xmax - xmin);// scale parameter in x direction
double sy = (yvmax - yvmin) / (ymax - ymin);// scale parameter in y direction
double vx0 = xvmin + (x0 - xmin)*sx;
double vy0 = yvmin + (y0 - ymin)*sy;
double vx1 = xvmin + (x1 - xmin)*sx;
double vy1 = yvmin + (y1 - ymin)*sy;*/
//draw a red color viewport
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_LOOP);
glVertex2f(xmin, ymin);
glVertex2f(xmax, ymin);
glVertex2f(xmax, ymax);
glVertex2f(xmin, ymax);
glEnd();
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex2d(x0, y0);
glVertex2d(x1, y1);
glEnd();
}
}
//<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>>
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); // set white background color
glColor3f(0.4f, 0.7f, 0.2f); // set the drawing color
glPointSize(8.0); // a ‘dot’ is 4 by 4 pixels
}
void setWindow(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(left, right, bottom, top);
}
// Set the screen viewport using thisfunction
void setViewport(GLint left, GLint right, GLint bottom, GLint top)
{
glViewport(left, bottom, right - left, top - bottom);
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
setWindow(0, screenWidth, 0, screenHeight);
setViewport(0, screenWidth, 0, screenHeight);
xmax = double(positions[0].x);
xmin = double(positions[1].x);
ymax = double(positions[0].y);
ymin = double(positions[1].y);
if (clicks >1)
{
{
glBegin(GL_LINE_LOOP);
glVertex2i(positions[0].x, positions[0].y);
glVertex2i(positions[1].x, positions[0].y);
glVertex2i(positions[1].x, positions[1].y);
glVertex2i(positions[0].x, positions[1].y);
glEnd();
}
}
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
for (int i = 0; i < clicks; i++)
{
glVertex2i(positions[i].x, positions[i].y);
}
glEnd();
// draw a blue colored window
for (int i = 0; i < clicks; i++)
{
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POINTS);
glVertex2d(positions[i].x, positions[i].y);
}
glEnd();
glFlush(); // send all output to display
glutSwapBuffers();
}
void myKeyboard(unsigned char key, int x, int y)
{
if (key == 'i')
flag = true;
}
void myMouse(int button, int state, int x, int y)
{
if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
{
if (clicks == 4)
clicks = 0;
positions[clicks] = Point(x, screenHeight - y);
clicks++;
}
if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
clicks = 0;
glutPostRedisplay();
}
void main(int argc, char** argv)
{
glutInit(&argc, argv); // initialize the toolkit
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_MULTISAMPLE); // set
display mode
glutInitWindowSize(screenWidth, screenHeight); // set window size
glutInitWindowPosition(100, 100); // set window position on screen
glutCreateWindow("cohen sutherland clipping"); // open the screen window
glutDisplayFunc(myDisplay); // register redraw function
glutMouseFunc(myMouse);
//glutMotionFunc(myMouseMove);
//glutKeyboardFunc(myKeyboard);
myInit();
glutMainLoop(); // go into a perpetual loop
} Dynamic Line Clipping Input 2 points. Draw an axis aligned rectangle using the 2 points.
Input 2 more points Draw the line segment between the two points Using the Cohen-Sutherland
Clipping Algorithm find the clipped coordinates of the line segment with the rectangle. Draw the
clipped line segment in a different color. Allow the user to move the rectangle, and calculate new
clipping coordinate. Optional: Allow the user to also scale the rectangle using the mouse and
calculate new clipping coordinates.
Solution
I will suggest you to go through this code,because the code you have written is very big and the
thing with the programming is to write the small codes instead of big ones(which will create
confusion).
So here is the code:-
Ad

More Related Content

Similar to Introduction to Computer Graphics using OpenGLCan someone tell me .pdf (20)

c++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdfc++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdf
apexjaipur
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
arcotstarsports
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5
Vanishree Arun
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
Farhan Ab Rahman
 
Creating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfCreating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdf
ShaiAlmog1
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 
Cara membuat tulisan mengikuti kursor di blog
Cara membuat tulisan mengikuti kursor di blogCara membuat tulisan mengikuti kursor di blog
Cara membuat tulisan mengikuti kursor di blog
Akhmad Akbar
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Uma mohan
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
anyacarpets
 
Graphics point clipping c program
Graphics point clipping c programGraphics point clipping c program
Graphics point clipping c program
Dr.M.Karthika parthasarathy
 
Halide tutorial 2019
Halide tutorial 2019Halide tutorial 2019
Halide tutorial 2019
Champ Yen
 
Include
IncludeInclude
Include
Munkherdene Batsaikhan
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
Abdullah Al Shiam
 
how can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdfhow can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdf
mail931892
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
Bijoy679
 
Review questions and answers
Review questions and answersReview questions and answers
Review questions and answers
IIUM
 
animation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdfanimation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdf
ambritgames
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
monikagupta18jan
 
tetris
tetristetris
tetris
Cameron White
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
anwarsadath111
 
c++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdfc++ code#include iostream#include string#include stdlib.h.pdf
c++ code#include iostream#include string#include stdlib.h.pdf
apexjaipur
 
need help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdfneed help with code I wrote. This code is a maze gui, and i need hel.pdf
need help with code I wrote. This code is a maze gui, and i need hel.pdf
arcotstarsports
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5
Vanishree Arun
 
Creating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfCreating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdf
ShaiAlmog1
 
Cg my own programs
Cg my own programsCg my own programs
Cg my own programs
Amit Kapoor
 
Cara membuat tulisan mengikuti kursor di blog
Cara membuat tulisan mengikuti kursor di blogCara membuat tulisan mengikuti kursor di blog
Cara membuat tulisan mengikuti kursor di blog
Akhmad Akbar
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Uma mohan
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
anyacarpets
 
Halide tutorial 2019
Halide tutorial 2019Halide tutorial 2019
Halide tutorial 2019
Champ Yen
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
Abdullah Al Shiam
 
how can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdfhow can i build this as problem 2 of my code #include iostream.pdf
how can i build this as problem 2 of my code #include iostream.pdf
mail931892
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
Bijoy679
 
Review questions and answers
Review questions and answersReview questions and answers
Review questions and answers
IIUM
 
animation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdfanimation.#include windows.h#include GLglut.h#inclu.pdf
animation.#include windows.h#include GLglut.h#inclu.pdf
ambritgames
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
anwarsadath111
 

More from fathimafancyjeweller (20)

Write a Python program that extracts 1000 unique links from Twitter .pdf
Write a Python program that extracts 1000 unique links from Twitter .pdfWrite a Python program that extracts 1000 unique links from Twitter .pdf
Write a Python program that extracts 1000 unique links from Twitter .pdf
fathimafancyjeweller
 
Which of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdfWhich of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdf
fathimafancyjeweller
 
Why must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdfWhy must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdf
fathimafancyjeweller
 
What are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdfWhat are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdf
fathimafancyjeweller
 
Which of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdfWhich of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdf
fathimafancyjeweller
 
What measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdfWhat measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdf
fathimafancyjeweller
 
What types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdfWhat types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdf
fathimafancyjeweller
 
Using the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdfUsing the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdf
fathimafancyjeweller
 
True or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdfTrue or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdf
fathimafancyjeweller
 
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdfThomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
fathimafancyjeweller
 
The government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdfThe government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdf
fathimafancyjeweller
 
The financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdfThe financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdf
fathimafancyjeweller
 
Should the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdfShould the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdf
fathimafancyjeweller
 
Research and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdfResearch and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdf
fathimafancyjeweller
 
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdfQuestion 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
fathimafancyjeweller
 
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdfQuestion 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdf
fathimafancyjeweller
 
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdfProve that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdf
fathimafancyjeweller
 
Choose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdfChoose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdf
fathimafancyjeweller
 
An intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdfAn intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdf
fathimafancyjeweller
 
a trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdfa trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdf
fathimafancyjeweller
 
Write a Python program that extracts 1000 unique links from Twitter .pdf
Write a Python program that extracts 1000 unique links from Twitter .pdfWrite a Python program that extracts 1000 unique links from Twitter .pdf
Write a Python program that extracts 1000 unique links from Twitter .pdf
fathimafancyjeweller
 
Which of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdfWhich of the following statements about financial intermediaries is .pdf
Which of the following statements about financial intermediaries is .pdf
fathimafancyjeweller
 
Why must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdfWhy must each network router interface belong to a different network.pdf
Why must each network router interface belong to a different network.pdf
fathimafancyjeweller
 
What are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdfWhat are the similarities and differences between the seppuku of the.pdf
What are the similarities and differences between the seppuku of the.pdf
fathimafancyjeweller
 
Which of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdfWhich of the following are considered withdrawals from an economy.pdf
Which of the following are considered withdrawals from an economy.pdf
fathimafancyjeweller
 
What measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdfWhat measures have the EU (or member nations) taken to mitigate the .pdf
What measures have the EU (or member nations) taken to mitigate the .pdf
fathimafancyjeweller
 
What types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdfWhat types of powers are given to the states by the Constitution.pdf
What types of powers are given to the states by the Constitution.pdf
fathimafancyjeweller
 
Using the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdfUsing the balanced equations given below, determine the overall mola.pdf
Using the balanced equations given below, determine the overall mola.pdf
fathimafancyjeweller
 
True or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdfTrue or false Income statement profit and loss statement shows com.pdf
True or false Income statement profit and loss statement shows com.pdf
fathimafancyjeweller
 
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdfThomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
Thomas Rinks and Joseph Shields developed Psycho Chihuahua, a carica.pdf
fathimafancyjeweller
 
The government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdfThe government uses part of payroll taxes to pay for Social Security..pdf
The government uses part of payroll taxes to pay for Social Security..pdf
fathimafancyjeweller
 
The financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdfThe financial statements are prepared from the unadjusted trial balan.pdf
The financial statements are prepared from the unadjusted trial balan.pdf
fathimafancyjeweller
 
Should the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdfShould the US conform to international standardsSolutionYes, .pdf
Should the US conform to international standardsSolutionYes, .pdf
fathimafancyjeweller
 
Research and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdfResearch and describe a tool that can be used to test for web server.pdf
Research and describe a tool that can be used to test for web server.pdf
fathimafancyjeweller
 
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdfQuestion 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
Question 11 of 24 In E. coli, three structural Deand enzymes A. D, an.pdf
fathimafancyjeweller
 
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdfQuestion 1. Dscribe the change you observed when you added 1 mL of 0.pdf
Question 1. Dscribe the change you observed when you added 1 mL of 0.pdf
fathimafancyjeweller
 
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdfProve that a group of order 255 is a cyclic.SolutionLet G be a .pdf
Prove that a group of order 255 is a cyclic.SolutionLet G be a .pdf
fathimafancyjeweller
 
Choose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdfChoose one field such as academia, health, consulting, business, man.pdf
Choose one field such as academia, health, consulting, business, man.pdf
fathimafancyjeweller
 
An intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdfAn intercalating agent 1. Inserts between base pairs of the two str.pdf
An intercalating agent 1. Inserts between base pairs of the two str.pdf
fathimafancyjeweller
 
a trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdfa trait is considered discrete when 1-The traits are intermediat.pdf
a trait is considered discrete when 1-The traits are intermediat.pdf
fathimafancyjeweller
 
Ad

Recently uploaded (20)

ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Ad

Introduction to Computer Graphics using OpenGLCan someone tell me .pdf

  • 1. Introduction to Computer Graphics using OpenGL Can someone tell me what shall I do to connect between the LineClipping, drawing the line, and rectangle function? I wrote the code below for the above question: #include #define red makecol(255,0,0) #define green makecol(0,255,0) #include // use as needed for your system #include #include #include #include #include "vector.h" const int screenWidth = 800; const int screenHeight = 600; double xmax, xmin, ymax, ymin; typedef int OutCode; double xvmin, yvmin, xvmax, yvmax; int clicks = 0; Point positions[4]; bool flag = false; const int INSIDE = 0; // 0000 const int LEFT = 1; const int RIGHT = 2; const int BOTTOM = 4; // 0100 const int TOP = 8; OutCode ComputeOutCode(double x, double y) { OutCode code; code = INSIDE; if (x < xmin) code |= LEFT; else if (x > xmax) code |= RIGHT;
  • 2. if (y < ymin) code |= BOTTOM; else if (y > ymax) code |= TOP; return code; } void LineClipping(double x0, double y0, double x1, double y1) { OutCode outcode0 = ComputeOutCode(x0, y0); OutCode outcode1 = ComputeOutCode(x1, y1); bool accept = false; bool done = false; while (done) { if (!(outcode0 | outcode1)) // Trivially accept and get out of loop { accept = true; done = true; break; } else if (outcode0 & outcode1) // Trivially reject and get out of loop { done = true; break; } else { // failed both tests, so calculate the line segment to clip // from an outside point to an intersection with clip edge double x, y; // At least one endpoint is outside the clip rectangle; pick it. OutCode outcodeOut = outcode0 ? outcode0 : outcode1; // Now find the intersection point; if (outcodeOut & TOP) { // point is above the clip rectangle x = x0 + (x1 - x0) * (ymax - y0) / (y1 - y0); y = ymax; } else if (outcodeOut & BOTTOM) { // point is below the clip rectangle
  • 3. x = x0 + (x1 - x0) * (ymin - y0) / (y1 - y0); y = ymin; } else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle y = y0 + (y1 - y0) * (xmax - x0) / (x1 - x0); x = xmax; } else if (outcodeOut & LEFT) { // point is to the left of clip rectangle 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); } } } if (accept) { // window to viewport mapping /* double sx = (xvmax - xvmin) / (xmax - xmin);// scale parameter in x direction double sy = (yvmax - yvmin) / (ymax - ymin);// scale parameter in y direction double vx0 = xvmin + (x0 - xmin)*sx; double vy0 = yvmin + (y0 - ymin)*sy; double vx1 = xvmin + (x1 - xmin)*sx; double vy1 = yvmin + (y1 - ymin)*sy;*/ //draw a red color viewport glColor3f(1.0, 0.0, 0.0);
  • 4. glBegin(GL_LINE_LOOP); glVertex2f(xmin, ymin); glVertex2f(xmax, ymin); glVertex2f(xmax, ymax); glVertex2f(xmin, ymax); glEnd(); glColor3f(0.0, 0.0, 1.0); glBegin(GL_LINES); glVertex2d(x0, y0); glVertex2d(x1, y1); glEnd(); } } //<<<<<<<<<<<<<<<<<<<<<<< myInit >>>>>>>>>>>>>>>>>>>> void myInit(void) { glClearColor(1.0, 1.0, 1.0, 0.0); // set white background color glColor3f(0.4f, 0.7f, 0.2f); // set the drawing color glPointSize(8.0); // a ‘dot’ is 4 by 4 pixels } void setWindow(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(left, right, bottom, top); } // Set the screen viewport using thisfunction void setViewport(GLint left, GLint right, GLint bottom, GLint top) { glViewport(left, bottom, right - left, top - bottom); } //<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>> void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); // clear the screen
  • 5. setWindow(0, screenWidth, 0, screenHeight); setViewport(0, screenWidth, 0, screenHeight); xmax = double(positions[0].x); xmin = double(positions[1].x); ymax = double(positions[0].y); ymin = double(positions[1].y); if (clicks >1) { { glBegin(GL_LINE_LOOP); glVertex2i(positions[0].x, positions[0].y); glVertex2i(positions[1].x, positions[0].y); glVertex2i(positions[1].x, positions[1].y); glVertex2i(positions[0].x, positions[1].y); glEnd(); } } glColor3f(0.0, 1.0, 0.0); glBegin(GL_LINES); for (int i = 0; i < clicks; i++) { glVertex2i(positions[i].x, positions[i].y); } glEnd(); // draw a blue colored window for (int i = 0; i < clicks; i++) { glColor3f(0.0, 0.0, 1.0); glBegin(GL_POINTS); glVertex2d(positions[i].x, positions[i].y);
  • 6. } glEnd(); glFlush(); // send all output to display glutSwapBuffers(); } void myKeyboard(unsigned char key, int x, int y) { if (key == 'i') flag = true; } void myMouse(int button, int state, int x, int y) { if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { if (clicks == 4) clicks = 0; positions[clicks] = Point(x, screenHeight - y); clicks++; } if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) clicks = 0; glutPostRedisplay(); } void main(int argc, char** argv) { glutInit(&argc, argv); // initialize the toolkit glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_MULTISAMPLE); // set display mode glutInitWindowSize(screenWidth, screenHeight); // set window size glutInitWindowPosition(100, 100); // set window position on screen glutCreateWindow("cohen sutherland clipping"); // open the screen window glutDisplayFunc(myDisplay); // register redraw function glutMouseFunc(myMouse); //glutMotionFunc(myMouseMove); //glutKeyboardFunc(myKeyboard); myInit();
  • 7. glutMainLoop(); // go into a perpetual loop } Dynamic Line Clipping Input 2 points. Draw an axis aligned rectangle using the 2 points. Input 2 more points Draw the line segment between the two points Using the Cohen-Sutherland Clipping Algorithm find the clipped coordinates of the line segment with the rectangle. Draw the clipped line segment in a different color. Allow the user to move the rectangle, and calculate new clipping coordinate. Optional: Allow the user to also scale the rectangle using the mouse and calculate new clipping coordinates. Solution I will suggest you to go through this code,because the code you have written is very big and the thing with the programming is to write the small codes instead of big ones(which will create confusion). So here is the code:-
  翻译: