Sunday, June 7, 2009

C Program For Oblique projection of a 3D object

#include<stdio.h>
#include<math.h>
#include<graphics.h>

main()
{

int x1,y1,x2,y2,gd,gm;
int ymax,a[4][8];
float par[4][4],b[4][8];
int i,j,k,m,n,p;
double L1,phi;


a[0][0] = 100; a[1][0] = 100; a[2][0] = 100;
a[0][1] = 200; a[1][1] = 100; a[2][1] = 100;

a[0][2] = 200; a[1][2] = 200; a[2][2] = 100;
a[0][3] = 100; a[1][3] = 200; a[2][3] = 100;

a[0][4] = 100; a[1][4] = 100; a[2][4] = 200;
a[0][5] = 200; a[1][5] = 100; a[2][5] = 200;

a[0][6] = 200; a[1][6] = 200; a[2][6] = 200;
a[0][7] = 100; a[1][7] = 200; a[2][7] = 200;

phi = (double) (3.14*45.0)/180 ;
L1 = 0.5;

par[0][0] = 1; par[0][1] = 0;
par[0][2] = L1*cos(phi); par[0][3] = 0;

par[1][0] = 0; par[1][1] = 1;
par[1][2] = L1*sin(phi); par[1][3] = 0;

par[2][0] = 0; par[2][1] = 0;
par[2][2] = 0; par[2][3] = 0;

par[3][0] = 0; par[3][1] = 0;
par[3][2] = 0; par[3][3] = 1;

m=4; n=4; p=8;


for(i=0; i<m; i++)
for(k=0; k<p; k++)
b[i][k] = 0;

for(i=0; i<m; i++)
for(k=0; k<p; k++)
for(j=0; j<n; j++)
b[i][k] += (float)par[i][j] * a[j][k];

detectgraph(&gd,&gm);
initgraph(&gd,&gm, "c:\\tc\\bgi");

ymax = getmaxy();

/*- front plane display -*/

for(j=0;j<3;j++)
{
x1=(int) b[0][j]; y1=(int) b[1][j];
x2=(int) b[0][j+1]; y2=(int) b[1][j+1];
line( x1,ymax-y1,x2,ymax-y2);

}
x1=(int) b[0][3]; y1=(int) b[1][3];
x2=(int) b[0][0]; y2=(int) b[1][0];
line( x1,ymax-y1,x2,ymax-y2);

/*- back plane display -*/

setcolor(11);
for(j=4;j<7;j++)
{
x1=(int) b[0][j]; y1=(int) b[1][j];
x2=(int) b[0][j+1]; y2=(int) b[1][j+1];
line( x1,ymax-y1,x2,ymax-y2);

}
x1=(int) b[0][7]; y1=(int) b[1][7];
x2=(int) b[0][4]; y2=(int) b[1][4];
line( x1,ymax-y1,x2,ymax-y2);

setcolor(13);
for(i=0;i<4;i++)
{
x1=(int) b[0][i]; y1=(int) b[1][i];
x2=(int) b[0][4+i]; y2=(int) b[1][4+i];
line( x1,ymax-y1,x2,ymax-y2);
}


getch(); getch();

}

4 comments:

Anonymous said...

hey ! thanks for your codes! awesome yaaa..by the way our professor has given us YOUR codes saying that those are his codes.. :-O .... his name is S.S.SANGLE from rajiv gandhi institute of Technology,versova...we'd be very happy if you screw him for doing this :-)

Anonymous said...

hey ! thanks for your codes! awesome yaaa..by the way our professor has given us YOUR codes saying that those are his codes.. :-O .... his name is S.S.SANGLE from rajiv gandhi institute of Technology,versova...we'd be very happy if you screw him for doing this :-)

Angad said...

Hello,
this is the internet and there is no copyright on my codes, there are quiet a few other people who claim that the posted codes are theirs, i simply cant do anything about it.They are even making profit out of it.This is the only reason why I have stopped posting new codes!I started this blog to help other fellow students because I myself know the quality of education that is provided to the students in Indian colleges. Moreover these codes are the building blocks for complex applications that use graphic programming so the basic logic is the same and code styles are common for many programmers. Anyways people do send me e-mails with their queries (I do not entertain direct code requests), I try to solve their doubts and help them with whatever knowledge I have regarding the subject, i.e. if I am not busy. I don't need to prove anything to the world, Please feel free to use and modify the existing program codes as per your convenience.

regards,
Angad.

Anonymous said...

Want output of this program..plz send pic of the output