Sunday, August 7, 2011

3D-Translation & Scaling

#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<graphics.h>
int x1,x2,y1,y2,mx,my,depth,t;
int tx,ty;
void draw();
void trans();
void scale();
void main()
{
    int gd=DETECT,gm,c;
    initgraph(&gd,&gm,"");
    printf("\n3D Translation & Scaling\n\n");
    printf("\nEnter top value(x1,y1):");
    scanf("%d%d",&x1,&y1);
    printf("Enter right bottom value(x2,y2):");
    scanf("%d%d",&x2,&y2);
    depth=(x2-x1)/4;
    draw();
    getch();
    while(1)
    {
    printf("\nPress 1 to translatio,2 to scaling:");
    scanf("%d",&t);
    switch(t)
    {
    case 1:
    trans();
    break;
    case 2:
    scale();
    break;
    default:
    exit(0);
    }
    }
}
void draw()
{
    cleardevice();
    bar3d(x1,y1,x2,y2,depth,1);
}
void trans()
{
    int a1,b1,a2,b2,dep;
    cleardevice();
    printf("Enter the translation vector");
    scanf("%d%d",&tx,&ty);
    a1=x1+tx;
    a2=x2+tx;
    b1=y1+ty;
    b2=y2+ty;
    dep=abs((a1-a2)/4);
    draw();
    sleep(2);
    cleardevice();
    bar3d(a1,b1,a2,b2,dep,1);
    setcolor(5);
    getch();
}

void scale()
{
    int a1,b1,a2,b2,dep;
    cleardevice();
    printf("Enter the scaling factor");
    scanf("%d%d",&tx,&ty);
    a1=x1*tx;
    a2=x2*tx;
    b1=y1*ty;
    b2=y2*ty;
    dep=abs((a1-a2)/4);
    draw();
    sleep(2);
    cleardevice();
    bar3d(a1,b1,a2,b2,dep,1);
    setcolor(5);
}

No comments:

Post a Comment

Please put your valuable comments