1. Experiment no. – 3.2
Student Name: Krishna Kumar UID: 19BCS2605
Branch: CSE - 11 Section/Group : ‘C’
Semester: 5th
Date of Performance: 09 Nov 2021
Subject Name: Computer Graphics Lab Subject Code: CSP - 305
1. Aim/Overview of the practical: To display the result of window to viewport transformation.
2. Task to be done: To display the result of window to viewport transformation.
3. Algorithm :
Step1: Start
Step2: Taking the window port and view port co-ordinate form the user
Step3: and also taking two point of line form user
Step4: then calculating scalling factor by using formula
sx = (float)(x_vmax - x_vmin) / (x_wmax - x_wmin);
sy = (float)(y_vmax - y_vmin) / (y_wmax - y_wmin);
Step5: then calculating view point of line by using formula
x1_v = x_vmin + (float)((x1_w - x_wmin) * sx);
y1_v = y_vmin + (float)((y1_w - y_wmin) * sy);
x2_v = x_vmin + (float)((x2_w - x_wmin) * sx);
y2_v = y_vmin + (float)((y2_w - y_wmin) * sy);
Step6: then displaying the result of window port to view port transformation.
Step6: End
2. 4. Programming Code: for to display the result of window to viewport transformation
#include <iostream>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
using namespace std;
void WindowtoViewport(int x1_w, int y1_w,int x2_w, int y2_w, int x_wmax,
int y_wmax, int x_wmin, int y_wmin,
int x_vmax, int y_vmax, int x_vmin,
int y_vmin)
{
int x1_v, y1_v ,x2_v, y2_v;
float sx, sy;
sx = (float)(x_vmax - x_vmin) / (x_wmax - x_wmin);
sy = (float)(y_vmax - y_vmin) / (y_wmax - y_wmin);
x1_v = x_vmin + (float)((x1_w - x_wmin) * sx);
y1_v = y_vmin + (float)((y1_w - y_wmin) * sy);
x2_v = x_vmin + (float)((x2_w - x_wmin) * sx);
y2_v = y_vmin + (float)((y2_w - y_wmin) * sy);
cout<<endl;
cout<< "The point on viewport: ("<<x1_v <<","<< y1_v<<" "<<" to "<<"
"<<x2_v <<","<< y2_v<<")" ;
setcolor(YELLOW);
line(x1_v,y1_v,x2_v,y2_v);
}
int main()
{
int gd=DETECT, gm; int i;
initgraph (&gd,&gm,"c:tcbgi");
int x_wmax , y_wmax , x_wmin , y_wmin ;
3. cout<<" Enter the window port x_wmax and y_wmax : ";
cin >>x_wmax>>y_wmax;
cout<<" Enter the window port x_wmin and y_wmin : ";
cin>>x_wmin>>y_wmin;
setcolor(WHITE);
outtextxy(x_wmin,y_wmin-20,"Window Port");
rectangle( x_wmin, y_wmin,x_wmax, y_wmax);
int x_vmax , y_vmax , x_vmin , y_vmin ;
cout<<" Enter the view port x_vmax and y_vmax : ";
cin >>x_vmax>>y_vmax;
cout<<" Enter the view port x_vmin and y_vmin : ";
cin>>x_vmin>>y_vmin;
setcolor(GREEN);
outtextxy(x_vmin,y_vmin-20,"View Port");
rectangle( x_vmin,y_vmin,x_vmax, y_vmax);
int x1_w , y1_w ,x2_w , y2_w ;
cout<<"Enter the first point x1_w and y1_w of line : ";
cin>>x1_w>>y1_w;
cout<<"Enter the second point x2_w and y2_w of line : ";
cin>>x2_w>>y2_w;
setcolor(RED);
line(x1_w, y1_w,x2_w, y2_w );
WindowtoViewport(x1_w, y1_w,x2_w, y2_w ,x_wmax, y_wmax, x_wmin,
y_wmin, x_vmax, y_vmax,x_vmin,y_vmin);
getch();
closegraph();
}
4. 5. Output: for to display the result of window to viewport transformation
6. Learning outcomes (What I have learnt):
1. I have gathered detail knowledge about how to display the result of window to viewport
transformation
2. I have learn how to draw the result of window to viewport transformation.
3. I get to know about proper logic & algorithm in computation of the result of window
to viewport transformation
7. Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1.
2.
3.