top of page

Computer Graphics Lab

CSE:3016

Faculty In charge : Prof. Rajesh Kanna

Home: Welcome
Home: Blog2
Search

3D Projections

Writer: theBloggers
theBloggers
Mar 24, 2019
1 min read

Updated: Apr 2, 2019


#include <stdio.h>

#include <stdlib.h>

#include<graphics.h>

#include<conio.h>

void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d);

void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d)

{

int i,j,k=0;

for(j=0;j<2;j++)

{

for(i=0;i<fs;i++)

{

if(i!=fs-1)

line(x[i]+tx+k,y[i]+ty-k,x[i+1]+tx+k,y[i+1]+ty-k);

else

line(x[i]+tx+k,y[i]+ty-k,x[0]+tx+k,y[0]+ty-k);

}

k=d;

}

for(i=0;i<fs;i++)

{

line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty-d);

}

}


int main()

{

int gd=DETECT,gm;

int x[20],y[20],tx=0,ty=0,i,fs,d;

initgraph(&gd,&gm,"");

printf("No of sides (front view only) : ");

scanf("%d",&fs);

printf("Co-ordinates : \n");

for(i=0;i<fs;i++)

{

printf("(x%d,y%d)",i,i);

scanf("%d%d",&x[i],&y[i]);

}

printf("Depth :");

scanf("%d",&d);

draw3d(fs,x,y,tx,ty,d);

getch();//front view

setcolor(14);

outtextxy(420,50,"Front view");

for(i=0;i<fs;i++)

{

if(i!=fs-1)

line(x[i]+200,y[i],x[i+1]+200,y[i+1]);

else

line(x[i]+200,y[i],x[0]+200,y[0]);

}

getch();//top view

outtextxy(100,270,"Top view");

for(i=0;i<fs-1;i++)

{

line(x[i],300,x[i+1],300);

line(x[i],300+d*2,x[i+1],300+d*2);

line(x[i],300,x[i],300+d*2);

line(x[i+1],300,x[i+1],300+d*2);

}

getch();//side view

outtextxy(20,30,"Side view");

for(i=0;i<fs-1;i++)

{

line(10,y[i],10,y[i+1]);

line(10+d*2,y[i],10+d*2,y[i+1]);

line(10,y[i],10+d*2,y[i]);

line(10,y[i+1],10+d*2,y[i+1]);

}

getch();

closegraph();

return 0;

}












 
 
 

Comments


Home: Blog Feed

Meet theBloggers !

This Blog was created by students of Computer Graphics and Design Class (CSE3016) with sole purpose of relaying information of the different activities performed throughout the course period.

​

theBloggers
Ibra Nafis - 17BCE1230

Bhavya S Chauhan - 17BCE1270

Home: About

© Proudly created with Wix.com

bottom of page