madzik4113

grafika_zajecia_zalegle

May 27th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.11 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include<iostream>
  4. #include<cmath>
  5. #include <cstdlib>
  6. #include <GL\glut.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. void Draw() {
  12. glClear(GL_COLOR_BUFFER_BIT);
  13. glColor3f(0,0,0);
  14. int wybor;
  15.  
  16. cout<<"#######ZALEGLE ZAJECIA#######\n"<<endl;
  17. cout<<"1) rysuj czworokat"<<endl;
  18. cout<<"2) rysuj trojkat"<<endl;
  19. cout<<"3) rysuj punkt"<<endl;
  20.  
  21. cout<<"4) rysuj wstege trojatow"<<endl;
  22. cout<<"5) rysuj linie"<<endl;
  23. cout<<"6) rysuj wachlarz\n"<<endl;
  24. cout<<"#############################\n"<<endl;
  25.  
  26. cin>>wybor;
  27.  
  28. switch(wybor)
  29. {
  30. case 1://czworokąt
  31. {
  32. double x1, y1, x2, y2, x3, y3, x4, y4;
  33. /*x1=-0.2;
  34. y1=-0.2;
  35. x2=0.2;
  36. y2=-0.2;
  37. x3=0.2;
  38. y3=0.2;
  39. x4=-0.2;
  40. y4=0.2;*/
  41. cout<< "podaj wspolrzede punktu 1: "<<endl;
  42. cout << "x1 : " ;
  43. cin>>x1;
  44. cout << "y1 : ";
  45. cin>>y1;
  46. cout<< "podaj wspolrzede punktu 2: "<<endl;
  47. cout << "x2 : " ;
  48. cin>>x2;
  49. cout << "y2 : ";
  50. cin>>y2;
  51. cout<< "podaj wspolrzede punktu 3: "<<endl;
  52. cout << "x3 : " ;
  53. cin>>x3;
  54. cout << "y3 : ";
  55. cin>>y3;
  56. cout<< "podaj wspolrzede punktu 4: "<<endl;
  57. cout << "x4 : " ;
  58. cin>>x4;
  59. cout << "y4 : ";
  60. cin>>y4;
  61. glColor3f(1,0,0);
  62. glBegin(GL_POLYGON);
  63. glVertex2d(x1,y1);
  64. glVertex2d(x2,y2);
  65. glVertex2d(x3,y3);
  66. glVertex2d(x4,y4);
  67. glEnd();
  68. break;
  69.  
  70. }
  71. case 2://trójkąt
  72. {
  73. double x1, x2, x3, y1, y2, y3;
  74. /* x1=0;
  75. y1=0;
  76. x2=0;
  77. y2=0.2;
  78. x3=0.3;
  79. y3=0;*/
  80.  
  81. cout<< "podaj wspolrzede punktu 1: "<<endl;
  82. cout << "x1 : " ;
  83. cin>>x1;
  84. cout << "y1 : ";
  85. cin>>y1;
  86. cout<< "podaj wspolrzede punktu 2: "<<endl;
  87. cout << "x2 : " ;
  88. cin>>x2;
  89. cout << "y2 : ";
  90. cin>>y2;
  91. cout<< "podaj wspolrzede punktu 3: "<<endl;
  92. cout << "x3 : " ;
  93. cin>>x3;
  94. cout << "y3 : ";
  95. cin>>y3;
  96.  
  97. glColor3f(1,0,0);
  98. glBegin(GL_TRIANGLES);
  99. glVertex2d(x1, y1);
  100. glVertex2d(x2, y2);
  101. glVertex2d(x3, y3);
  102. glEnd();
  103. break;
  104. }
  105.  
  106. case 3://punkty o różnej szerokości
  107. {
  108. double x,y;
  109. //cin>>x>>y;
  110. x=0;
  111. y=0;
  112. cout<<"podaj ilosc punktow : "<<endl;
  113. int ilosc;
  114. cin>>ilosc;
  115. cout<<"podaj wielkosc punktow : "<<endl;
  116. float rozmiar;
  117. cin>>rozmiar;
  118. glPointSize(rozmiar);
  119. glColor3f(1,0,0);
  120. for(int i=0;i<ilosc;i++)
  121. {
  122. glBegin(GL_POINTS);
  123. glVertex2d(x,y);
  124. glEnd();
  125. glTranslated(0.1,0,0);
  126. }
  127. }
  128. break;
  129.  
  130.  
  131. case 4://wstęga trójtątów
  132. {
  133. int ilosc;
  134. double delta=0.1;
  135. cout<<"podaj ilosc trojkatow : "<<endl;
  136. cin>>ilosc;
  137. double x1, x2, x3, y1, y2, y3;
  138. //cin>>x1>>y1;
  139. //
  140.  
  141.  
  142. x1=-0.5;
  143. y1=-0.5;
  144. x2=-0.5;
  145. y2=0.3;
  146. x3=-0.3;
  147. y3=-0.5;
  148.  
  149. // glColor3f(0,0,0);
  150. glBegin(GL_TRIANGLE_STRIP);
  151. glVertex2d(x1, y1);
  152. glVertex2d(x2, y2);
  153. glVertex2d(x3, y3);
  154. glEnd();
  155.  
  156. for(int i=0; i<ilosc; i++)
  157. {
  158. if(i%2==1)
  159. {
  160.  
  161. glColor3f(1,0,0);
  162. glBegin(GL_TRIANGLE_STRIP);
  163. glVertex2d(x2,y2);
  164. glVertex2d(x2+delta,y2);
  165. glVertex2d(x3,y3);
  166. glEnd();
  167. x2+=delta;
  168.  
  169. }
  170. else
  171. {
  172. glColor3d(0,1,0);
  173. glBegin(GL_TRIANGLE_STRIP);
  174. glVertex2d(x3,y3);
  175. glVertex2d(x2,y2);
  176. glVertex2d(x3+delta,y3);
  177. glEnd();
  178. x3+=delta;
  179. }
  180. }
  181.  
  182. }
  183. break;
  184.  
  185. case 5://linie o róznej grubości i wzorze
  186. {
  187.  
  188. double grubosc;
  189. cout<<"podaj grubosc lini : "<<endl;
  190. cin>>grubosc;
  191. glLineWidth(grubosc);
  192. double x1, x2, y1, y2;
  193. x1=-0.5;
  194. y1=-0.5;
  195. x2=0.2;
  196. y2=0.2;
  197. //cin>>x1>>y1;
  198. //cin>>x2>>y2;
  199.  
  200. glBegin(GL_LINES);
  201. glVertex2d(x1, y1);
  202. glVertex2d(x2, y2);
  203. glEnd();
  204.  
  205. glFlush();
  206. glEnable(GL_LINE_STIPPLE);
  207. double wzor, factor;
  208. cout<<"podaj pattern : "<<endl; //czyli wzor rysowanej linii
  209. cin>>wzor;
  210. cout<<"podaj factor : "<<endl;
  211. cin>>factor;
  212.  
  213. //glColor3f(0.7,0.2,0.1);
  214. //glLineStipple(1, 0x00FF);
  215. glColor3f(1,0,0);
  216. glLineStipple(factor, wzor);
  217. glBegin(GL_LINES);
  218. glVertex2d(x1, y1);
  219. glVertex2d(x2, y2);
  220. glEnd();
  221. glFlush();
  222.  
  223.  
  224.  
  225. }
  226. break;
  227. case 6:
  228. {
  229. glColor3f(0,1,0);
  230. double delta = 0.09;
  231. double r; //promien
  232. r=0.7;
  233. double n;
  234. cout<<"podaj ilosc trojkatow : "<<endl;
  235. cin>>n;
  236. double angle;
  237. double PI = 22/7;
  238. double a,b;
  239. a=-0.2;
  240. b=-0.2;
  241. //cin>>a>>b;
  242.  
  243. double pom_x, pom_y;
  244. pom_x=0;
  245. pom_y=0;
  246.  
  247. double x, y; //wsp
  248. glBegin(GL_TRIANGLE_FAN);
  249. for(double i=0; i<=n; i++)
  250. {
  251. glColor3d(0.1+(i*2),0.1+(i*2),0.1+(i*2));
  252. glVertex2d(a,b);
  253. glVertex2d(pom_x, pom_y);
  254. angle = 2*i*PI/n;
  255. x=r*cos(angle)*1.4;
  256. pom_x=x;
  257. y=r*sin(angle)*1.4;
  258. pom_y=y;
  259.  
  260. glVertex2f(x, y);
  261. }
  262. glEnd();
  263. }
  264. break;
  265. }
  266.  
  267. glFlush();
  268. }
  269. void Initialize() {
  270. glClearColor(0.0, 0.0, 0.0, 0.0);
  271. glMatrixMode(GL_PROJECTION);
  272. glLoadIdentity();
  273. }
  274.  
  275. int main(int argc, char** argv) {
  276. glutInit(&argc, argv);
  277. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  278. glutInitWindowSize(500, 500);
  279. glutInitWindowPosition(200, 200);
  280. glutCreateWindow("zalegle zajecia");
  281. Initialize();
  282. glutDisplayFunc(Draw);
  283. glutMainLoop();
  284. return 0;
  285. }
Advertisement
Add Comment
Please, Sign In to add comment