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

3D Pro

PRO

Uploaded by

v2299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

3D Pro

PRO

Uploaded by

v2299
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT-9

AIM-Draw a cube on screen using Matrix Multiplication


1.Find orthographic projection onto x=0;
2.Find oblique projection when cabinet projection is
done.
3.perspective projection when projectors are at z-axis.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
float pt[8][3];
float mat[3][3];
float draw[8][3];
void orth()
{
int i,j,k;
for(i=0;i<7;i++)
{for(j=0;j<3;j++)
{draw[i][j]=0;
for(k=0;k<3;k++)
{draw[i][j]=draw[i][j]+pt[i][k]*mat[k][j];}
}}
for(i=0;i<6;i++)
{
//printf("%f\t%f\t%f\n",draw[i][0],draw[i][1],draw[i][2]);
setcolor(RED);
if(i!=3){
line(draw[i][0],draw[i][1],draw[i+1][0],draw[i+1][1]);}
}
line(draw[0][0],draw[0][1],draw[4][0],draw[4][1]) ;
line(draw[1][0],draw[1][1],draw[5][0],draw[5][1]) ;
line(draw[2][0],draw[2][1],draw[6][0],draw[6][1])
;
line(draw[0][0],draw[0][1],draw[3][0],draw[3][1])
;
}
void matrix()
{
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i==j&&i!=0)
mat[i][j]=1;
else
mat[i][j]=0;

}
orth();
}

void matrixhi()
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
mat[i][j]=0;
if(i==j)
{mat[i][j]=1;}
}
}
mat[0][2]=0.5*0.5;
//printf("%f\n",mat[0][2]);
mat[1][2]=0.5*1.732*0.5;
//printf("%f\n",mat[0][2]);
orth();
}
void change()
{
int i;
printf("Enter the option.\n 1.Orthographic\n2.Oblique \n3.Perspective");
scanf("%d",&i);
switch(i)
{case 1:matrix();
break;
case 2:matrixhi();
break;
case 3:matrixhi();
break;
}
}
void main()
{
int i=0,j=0;
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"");
bar3d(100,100,200,200,40,1);
//line(100,100,140,70);
pt[0][0]=100;
pt[0][1]=100;
pt[1][0]=200;
pt[1][1]=100;
pt[2][0]=200;
pt[2][1]=200;
pt[3][0]=100;
pt[3][1]=200;
pt[4][0]=140;
pt[4][1]=70;
pt[5][0]=240;
pt[5][1]=70;
pt[6][0]=240;
pt[6][1]=170;
pt[7][0]=140;

pt[7][1]=170;
pt[0][2]=1;
pt[1][2]=1;
pt[2][2]=1;
pt[3][2]=1;
pt[4][2]=1;
pt[5][2]=1;
pt[6][2]=1;
pt[7][2]=1;
change();
getch();
}

You might also like