Saturday, 8 March 2014

3D TRANSFORMATION AND ROTATION

/*CSEMATTER.BLOGSPOT.IN
PROGRAM-3D TRANSFORMATION AND ROTATION*/



#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<process.h>

#include<graphics.h>




void draw();

void rotate();

int x12,x22,y12,y22,mx,my,depth;

int main()

{


    int gd=DETECT,gm,c;

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

    printf("\n3D Transformation Rotating\n\n");

    printf("\nEnter 1st top value(x12,y12):");

    scanf("%d%d",&x12,&y12);

    printf("Enter right bottom value(x2,y2):");

    scanf("%d%d",&x22,&y22);

    depth=(x22-x12)/4;

    mx=(x12+x22)/2;

    my=(y12+y22)/2;

    draw();

    getch();

    cleardevice();

    rotate();

    getch();

}



void draw()

{

    bar3d(x12,y12,x22,y22,depth,1);

}



void rotate()

{

    float t;

    int a1,b1,a2,b2,dep;

    printf("Enter the angle to rotate=");

    scanf("%f",&t);

    t=t*(3.14/180);

    a1=mx+(x12-mx)*cos(t)-(y12-my)*sin(t);

    a2=mx+(x22-mx)*cos(t)-(y22-my)*sin(t);

    b1=my+(x12-mx)*sin(t)-(y12-my)*cos(t);

    b2=my+(x22-mx)*sin(t)-(y22-my)*cos(t);

    if(a2>a1)

       dep=(a2-a1)/4;

    else

      dep=(a1-a2)/4;

    bar3d(a1,b1,a2,b2,dep,1);

    setcolor(5);

    //draw();

}


No comments:

Post a Comment