Add to Favorites    Make Home Page 1295 Online  
 Language Categories  
 Our Services  

Home » C++ Home » Computer Graphics Home » Program for 3-D Transformation.

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Program for 3-D Transformation.
Description
Category C++ » Computer Graphics
Hits 374443
Code Select and Copy the Code
#include<iostream.h> #include<dos.h> #include<stdio.h> #include<math.h> #include<conio.h> #include<graphics.h> #include<process.h> int gd=DETECT,gm; double x1,x2,y1,y2; void show_message() { char *mess[]={"-","=","["," ","3","D","-","T","r","a","n","s", "f","o","r","m","a","t","i","o","n"," ","]","=","-"}; int xx=28,xxx=52,i,j; _setcursortype(_NOCURSOR); for(i=0,j=24;i<15,j>=12;i++,j--) { gotoxy(xx,1); cout<<mess[i]; xx++; gotoxy(xxx,1); cout<<mess[j]; xxx--; delay(50); } _setcursortype(_NORMALCURSOR); } void draw_cube(double edge[20][3]) { initgraph(&gd,&gm,"..\bgi"); int i; clearviewport(); for(i=0;i<19;i++) { x1=edge[i][0]+edge[i][2]*(cos(2.3562)); y1=edge[i][1]-edge[i][2]*(sin(2.3562)); x2=edge[i+1][0]+edge[i+1][2]*(cos(2.3562)); y2=edge[i+1][1]-edge[i+1][2]*(sin(2.3562)); line(x1+320,240-y1,x2+320,240-y2); } line(320,240,320,25); line(320,240,550,240); line(320,240,150,410); getch(); closegraph(); } void scale(double edge[20][3]) { double a,b,c; int i; cout<<" " Enter The Scaling Factors ":="; cin>>a>>b>>c; initgraph(&gd,&gm,"..\bgi"); clearviewport(); for(i=0;i<20;i++) { edge[i][0]=edge[i][0]*a; edge[i][1]=edge[i][1]*b; edge[i][2]=edge[i][2]*c; } draw_cube(edge); closegraph(); } void translate(double edge[20][3]) { int a,b,c; int i; cout<<" " Enter The Translation Factors ":="; cin>>a>>b>>c; initgraph(&gd,&gm,"..\bgi"); clearviewport(); for(i=0;i<20;i++) { edge[i][0]+=a; edge[i][0]+=b; edge[i][0]+=c; } draw_cube(edge); closegraph(); } void rotate(double edge[20][3]) { int ch; int i; double temp,theta,temp1; clrscr(); cout<<" -=[ Rotation About ]=-"; cout<<" 1:==>" X-Axis ""; cout<<" 2:==>" Y-Axis ""; cout<<" 3:==>" Z-Axis ""; cout<<" " Enter Your Choice ":="; cin>>ch; switch(ch) { case 1: cout<<" " Enter The Angle ":="; cin>>theta; theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge[i][0]=edge[i][0]; temp=edge[i][1]; temp1=edge[i][2]; edge[i][1]=temp*cos(theta)-temp1*sin(theta); edge[i][2]=temp*sin(theta)+temp1*cos(theta); } draw_cube(edge); break; case 2: cout<<" " Enter The Angle ":="; cin>>theta; theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge[i][1]=edge[i][1]; temp=edge[i][0]; temp1=edge[i][2]; edge[i][0]=temp*cos(theta)+temp1*sin(theta); edge[i][2]=-temp*sin(theta)+temp1*cos(theta); } draw_cube(edge); break; case 3: cout<<" " Enter The Angle ":="; cin>>theta; theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge[i][2]=edge[i][2]; temp=edge[i][0]; temp1=edge[i][1]; edge[i][0]=temp*cos(theta)-temp1*sin(theta); edge[i][1]=temp*sin(theta)+temp1*cos(theta); } draw_cube(edge); break; } } void reflect(double edge[20][3]) { int ch; int i; clrscr(); cout<<" -=[ Reflection About ]=-"; cout<<" 1:==>" X-Axis ""; cout<<" 2:==>" Y-Axis ""; cout<<" 3:==>" Z-Axis ""; cout<<" " Enter Your Choice ":="; cin>>ch; switch(ch) { case 1: for(i=0;i<20;i++) { edge[i][0]=edge[i][0]; edge[i][1]=-edge[i][1]; edge[i][2]=-edge[i][2]; } draw_cube(edge); break; case 2: for(i=0;i<20;i++) { edge[i][1]=edge[i][1]; edge[i][0]=-edge[i][0]; edge[i][2]=-edge[i][2]; } draw_cube(edge); break; case 3: for(i=0;i<20;i++) { edge[i][2]=edge[i][2]; edge[i][0]=-edge[i][0]; edge[i][1]=-edge[i][1]; } draw_cube(edge); break; } } void perspect(double edge[20][3]) { int ch; int i; double p,q,r; clrscr(); cout<<" -=[ Perspective Projection About ]=-"; cout<<" 1:==>" X-Axis ""; cout<<" 2:==>" Y-Axis ""; cout<<" 3:==>" Z-Axis ""; cout<<" " Enter Your Choice ":="; cin>>ch; switch(ch) { case 1: cout<<" " Enter P ":="; cin>>p; for(i=0;i<20;i++) { edge[i][0]=edge[i][0]/(p*edge[i][0]+1); edge[i][1]=edge[i][1]/(p*edge[i][0]+1); edge[i][2]=edge[i][2]/(p*edge[i][0]+1); } draw_cube(edge); break; case 2: cout<<" " Enter Q ":="; cin>>q; for(i=0;i<20;i++) { edge[i][1]=edge[i][1]/(edge[i][1]*q+1); edge[i][0]=edge[i][0]/(edge[i][1]*q+1); edge[i][2]=edge[i][2]/(edge[i][1]*q+1); } draw_cube(edge); break; case 3: cout<<" " Enter R ":="; cin>>r; for(i=0;i<20;i++) { edge[i][2]=edge[i][2]/(edge[i][2]*r+1); edge[i][0]=edge[i][0]/(edge[i][2]*r+1); edge[i][1]=edge[i][1]/(edge[i][2]*r+1); } draw_cube(edge); break; } closegraph(); } void main() { int choice; double edge[20][3]= { 100,0,0, 100,100,0, 0,100,0, 0,100,100, 0,0,100, 0,0,0, 100,0,0, 100,0,100, 100,75,100, 75,100,100, 100,100,75, 100,100,0, 100,100,75, 100,75,100, 75,100,100, 0,100,100, 0,100,0, 0,0,0, 0,0,100, 100,0,100 }; while(1) { clrscr(); show_message(); cout<<" 1:==>" Draw Cube ""; cout<<" 2:==>" Scaling ""; cout<<" 3:==>" Rotation ""; cout<<" 4:==>" Reflection ""; cout<<" 5:==>" Translation ""; cout<<" 6:==>" Perspective Projection ""; cout<<" 7:==>" Exit ""; cout<<" " Enter Your Choice ":="; cin>>choice; switch(choice) { case 1: draw_cube(edge); break; case 2: scale(edge); break; case 3: rotate(edge); break; case 4: reflect(edge); break; case 5: translate(edge); break; case 6: perspect(edge); break; case 7: exit(0); default: cout<<" a" Press A Valid Key...!!! ""; getch(); break; } closegraph(); } }

Related Source Codes

Script Name Author
Moving ball screen saver karlmarx
The Classic Game of Snake & Ladder Lakshmi Narayana .A
Railway seat reservation question which comes in sapient VyomWorld
To calculate percentile Ravi Mathur
Send to folder ANIMESH SAHU
Analog clock and calendar Nazia & Rida
HIGH/LOW GAME MOLLY ARORA
Data structure (stack Implimentation) Swapnil B Adsure
Memory Game AnirudhSanyal
Easy Calc Anirudh Sanyal
GK Quiz Anirudh Sanyal
Hangman Game Manish Jain
Snakeman Manish Jain
Full month Calendar Nigi
Cursor shapes nigi

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=109


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review