Home › Forums › C Programming › 3D Shape
- This topic has 1 reply, 2 voices, and was last updated 17 years, 7 months ago by arshi.
Viewing 1 reply thread
- AuthorPosts
- February 25, 2005 at 9:28 am #1886willParticipant123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127/*Author: Mohammed Ali Akbani<br />Level : Intermediate<br />E-mail: [email protected]<br />Web Site: http://www.akbani.20m.com<br />Please do not repost it in your name.<br />*/<br />#include <math.h><br />#include <conio.h><br />#include <iostream.h><br />#include "svga256.h"<br />const float pi = 3.142;<br />struct coordinate<br />{<br />unsigned int x;<br />unsigned int y;<br />};<br />struct dimension<br />{<br />int x;<br />int y;<br />int z;<br />};<br />class cube_3d<br />{<br />private:<br />dimension dimension;<br />coordinate ini;<br />coordinate front[4];<br />coordinate back [4];<br />public:<br />cube_3d()<br />{<br />get_dimensions();<br />ini.x = 100;<br />ini.y = 700;<br />for(int i=0; i<4; i++)<br />{<br />front.x = ini.x;<br />front.y = ini.y;<br />}<br />for(int j=0; j<4; j++)<br />{<br />back[j].x = ini.x;<br />back[j].y = ini.y;<br />}<br />}<br />void get_dimensions()<br />{<br />clrscr();<br />cout << "Enter x dimension : ";<br />cin >> dimension.x;<br />cout << "Enter y dimension : ";<br />cin >> dimension.y;<br />cout << "Enter z dimension : ";<br />cin >> dimension.z;<br />}<br />void calculate_points()<br />{<br />calculate_front();<br />calculate_back();<br />}<br />void draw_cube()<br />{<br />draw_front();<br />draw_back();<br />draw_sides();<br />}<br />void calculate_front()<br />{<br />front[1].x += dimension.x;<br />front[2].x += dimension.x;<br />front[2].y -= dimension.y;<br />front[3].y -= dimension.y;<br />}<br />void calculate_back()<br />{<br />back[0].y -= (int)(dimension.z * sin(pi/4));<br />back[0].x += (int)(dimension.z * sin(pi/4));<br />back[1].x = back[0].x + dimension.x;<br />back[1].y = back[0].y;<br />back[2].x = back[0].x + dimension.x;<br />back[2].y = back[0].y - dimension.y;<br />back[3].x = back[0].x;<br />back[3].y = back[0].y - dimension.y;<br />}<br />void draw_front()<br />{<br />setcolor(RED);<br />line(front[0].x, front[0].y, front[1].x, front[1].y);<br />setcolor(BLUE);<br />line(front[1].x, front[1].y, front[2].x, front[2].y);<br />setcolor(RED);<br />line(front[2].x, front[2].y, front[3].x, front[3].y);<br />setcolor(BLUE);<br />line(front[3].x, front[3].y, front[0].x, front[0].y);<br />}<br />void draw_back()<br />{<br />setcolor(RED);<br />line(back[0].x, back[0].y, back[1].x, back[1].y);<br />setcolor(BLUE);<br />line(back[1].x, back[1].y, back[2].x, back[2].y);<br />setcolor(RED);<br />line(back[2].x, back[2].y, back[3].x, back[3].y);<br />setcolor(BLUE);<br />line(back[3].x, back[3].y, back[0].x, back[0].y);<br />}<br />void draw_sides()<br />{<br />setcolor(GREEN);<br />line(back[0].x, back[0].y, front[0].x, front[0].y);<br />setcolor(GREEN);<br />line(back[1].x, back[1].y, front[1].x, front[1].y);<br />setcolor(GREEN);<br />line(back[2].x, back[2].y, front[2].x, front[2].y);<br />setcolor(GREEN);<br />line(back[3].x, back[3].y, front[3].x, front[3].y);<br />}<br />};<br />void main()<br />{<br />cube_3d cube;<br />SVGAinitgraph("e:\tc\bgi");<br />cube.calculate_points();<br />cube.draw_cube();<br />getch();<br />}
- May 19, 2007 at 2:55 pm #3139arshiParticipant
Hello ! I Want to Know about more 3D- Graphics Functions
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.