0% found this document useful (0 votes)
39 views

USCSP504 Game Programming: Practical No-1

The document contains the code for 4 programs that perform different 2D transformations on geometric shapes in graphics mode in C programming language. Program 1 performs 2D translation of a triangle by translating its x and y coordinates. Program 2 performs 2D scaling of a triangle by multiplying its coordinates by a scale factor. Program 3 performs 2D rotation of a line by calculating the rotated coordinates of its endpoints. Program 4 performs 2D reflection of a triangle by reflecting it across the x-axis or y-axis.

Uploaded by

Apeksha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

USCSP504 Game Programming: Practical No-1

The document contains the code for 4 programs that perform different 2D transformations on geometric shapes in graphics mode in C programming language. Program 1 performs 2D translation of a triangle by translating its x and y coordinates. Program 2 performs 2D scaling of a triangle by multiplying its coordinates by a scale factor. Program 3 performs 2D rotation of a line by calculating the rotated coordinates of its endpoints. Program 4 performs 2D reflection of a triangle by reflecting it across the x-axis or y-axis.

Uploaded by

Apeksha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Name:- Apeksha Umakant Ojha

PRN No:- 2019420758

USCSP504
GAME PROGRAMMING

PRACTICAL NO-1

AIM:- Perform 2D translation of a triangle.

PROGRAM:-

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{ int
x1,x2,x3,y1,y2,y3,xt,yt;
int gd=DETECT, gm=DETECT;
initgraph(&gd,&gm, "C:\\TURBOC3\\BGI");
printf("Enter the values of vertex v1:");
scanf("%d %d",&x1,&y1); printf("Enter
the values of vertex v2:"); scanf("%d
%d",&x2,&y2); printf("Enter the values
of vertex v3:");
scanf("%d %d",&x3,&y3); line(x1,y1,x2,y2);
line(x2,y2,x3,y3); line(x1,y1,x3,y3); printf("Enter the
values for translating x co-ordinate:");
scanf("%d",&xt); printf("Enter the values for
translating y co-ordinate:"); scanf("%d",&yt)
line(x1+xt,y1+yt,x2+xt,y2+yt);
line(x2+xt,y2+yt,x3+xt,y3+yt);
line(x1+xt,y1+yt,x3+xt,y3+yt); getch();
closegraph();
}
OUTPUT:-

PRACTICAL NO-2

AIM:- Perform 2D scaling of a triangle.

PROGRAM:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int x1,x2,x3,y1,y2,y3,t;
int gd=DETECT, gm=DETECT;
initgraph(&gd,&gm, "C:\\TURBOC3\\BGI");
printf("Enter the values of vertex v1:"); scanf("%d
%d",&x1,&y1); printf("Enter the values of vertex
v2:"); scanf("%d %d",&x2,&y2); printf("Enter the
values of vertex v3:"); scanf("%d %d",&x3,&y3);
line(x1,y1,x2,y2); line(x2,y2,x3,y3);
line(x1,y1,x3,y3); printf("Enter the multiple for
scaling co-ordinates:");
scanf("%d",&t); line(x1*t,y1*t,x2*t,y2*t);
line(x2*t,y2*t,x3*t,y3*t); line(x1*t,y1*t,x3*t,y3*t);
getch();
closegraph();
}

OUTPUT:-
PRACTICAL N.O - 3

AIM:- Perform 2D Rotation of a line.

PROGRAM:-

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
int gd=DETECT,gm; int x1,y1,x2,y2;
float b1,b2; float t,deg;
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("enter the coordinate of line \n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
setcolor(6); line(x1,y1,x2,y2); getch();
printf("enter the angle of rotation:");
scanf("%f",&deg);
t=(22*deg)/(180*7);
b1=abs((x2*cos(t))-(y2*sin(t)));
b2=abs((x2*sin(t))+(y2*cos(t)));
line(x1,y1,b1,b2);
getch();
closegraph();
}
OUTPUT:-
PRACTICAL N.O - 4

AIM:- Write a program to perform for 2D reflection.

PROGRAM:-

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,x3,y3,ref;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\bgi"); printf("\n
enter the coordinates of triangle:\n");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1);
line(320,0,320,460); line(0,230,640,230); printf("\n enter 1 for rotating
about x axis & 2 for rotating about y axis:\n"); scanf("%d",&ref);
if(ref==1)
{
if(y1>230) { x1=x1;
x2=x2; x3=x3;
y1=y1-230; y2=y2-
230; y3=y3-230;
}
else {
x1=x1;
x2=x2;
x3=x3;
y1=y1+230;
y2=y2+230;
y3=y3+230;
}
}
if(ref==2)
{
if(x1>320)
{ x1=x1;
x2=x2;
x3=x3;
x1=x1-320;
x2=x2-320;
x3=x3-320;
}
else {
y1=y1;
y2=y2;
y3=y3;
x1=x1+320;
x2=x2+320;
x3=x3+320;
}
}
printf("\n triangle after reflection");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1); getch();
closegraph();
}

OUTPUT:-

You might also like