Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.96 KB | None | 0 0
  1. #include <windows.h>
  2. #include <math.h>
  3. #include<windows.h>
  4. #include <GL/glut.h>
  5. //#include <fstream.h>
  6. #include <stdlib.h>
  7.  
  8. typedef struct {
  9. float m[4][4];
  10. } matrix3D_t;
  11.  
  12. typedef struct {
  13. float v[4];
  14. } vector3D_t;
  15.  
  16. typedef struct {
  17. float x;
  18. float y;
  19. float z;
  20. } point3D_t;
  21.  
  22. typedef struct {
  23. float x;
  24. float y;
  25. } point2D_t;
  26.  
  27. typedef struct {
  28. float r;
  29. float g;
  30. float b;
  31. } color_t;
  32.  
  33. ////////////////// matrices and vectors 3D ver 2 /////////////////
  34. matrix3D_t createIdentity(void){
  35. matrix3D_t u;
  36. int i,j;
  37. for (i=0;i<4;i++) {
  38. for(j=0;j<4;j++) u.m[i][j]=0.;
  39. u.m[i][i]=1.;
  40. }
  41. return u;
  42. }
  43.  
  44. matrix3D_t operator * (matrix3D_t a,matrix3D_t b){
  45. matrix3D_t c;//c=a*b
  46. int i,j,k;
  47. for (i=0;i<4;i++) for (j=0;j<4;j++) {
  48. c.m[i][j]=0;
  49. for (k=0;k<4;k++) c.m[i][j]+=a.m[i][k]*b.m[k][j];
  50. }
  51. return c;
  52. }
  53.  
  54. vector3D_t operator * (matrix3D_t a, vector3D_t b){
  55. vector3D_t c;//c=a*b
  56. int i,j;
  57. for (i=0;i<4;i++) {
  58. c.v[i]=0;
  59. for (j=0;j<4;j++) c.v[i]+=a.m[i][j]*b.v[j];
  60. }
  61. return c;
  62. }
  63.  
  64. matrix3D_t translationMTX(float dx,float dy,float dz){
  65. matrix3D_t trans=createIdentity();
  66. trans.m[0][3]=dx;
  67. trans.m[1][3]=dy;
  68. trans.m[2][3]=dz;
  69. return trans;
  70. }
  71.  
  72. matrix3D_t rotationXMTX(float theta){
  73. matrix3D_t rotate=createIdentity();
  74. float cs=cos(theta);
  75. float sn=sin(theta);
  76. rotate.m[1][1]=cs; rotate.m[1][2]=-sn;
  77. rotate.m[2][1]=sn; rotate.m[2][2]=cs;
  78. return rotate;
  79. }
  80.  
  81. matrix3D_t rotationYMTX(float theta){
  82. matrix3D_t rotate=createIdentity();
  83. float cs=cos(theta);
  84. float sn=sin(theta);
  85. rotate.m[0][0]=cs; rotate.m[0][2]=sn;
  86. rotate.m[2][0]=-sn; rotate.m[2][2]=cs;
  87. return rotate;
  88. }
  89.  
  90. matrix3D_t rotationZMTX(float theta){
  91. matrix3D_t rotate=createIdentity();
  92. float cs=cos(theta);
  93. float sn=sin(theta);
  94. rotate.m[0][0]=cs; rotate.m[0][1]=-sn;
  95. rotate.m[1][0]=sn; rotate.m[1][1]=cs;
  96. return rotate;
  97. }
  98.  
  99. matrix3D_t scalingMTX(float factorx,float factory,float factorz){
  100. matrix3D_t scale=createIdentity();
  101. scale.m[0][0]=factorx;
  102. scale.m[1][1]=factory;
  103. scale.m[2][2]=factorz;
  104. return scale;
  105. }
  106.  
  107. matrix3D_t perspectiveMTX(float eyelength){
  108. matrix3D_t perspective=createIdentity();
  109. perspective.m[3][2]=-1./eyelength;
  110. return perspective;
  111. }
  112.  
  113. point2D_t Vector2Point2D(vector3D_t vec){
  114. point2D_t pnt;
  115. pnt.x=vec.v[0];
  116. pnt.y=vec.v[1];
  117. return pnt;
  118. }
  119.  
  120. point3D_t Vector2Point3D(vector3D_t vec){
  121. point3D_t pnt;
  122. pnt.x=vec.v[0];
  123. pnt.y=vec.v[1];
  124. pnt.z=vec.v[2];
  125. return pnt;
  126. }
  127.  
  128. vector3D_t Point2Vector(point3D_t pnt){
  129. vector3D_t vec;
  130. vec.v[0]=pnt.x;
  131. vec.v[1]=pnt.y;
  132. vec.v[2]=pnt.z;
  133. vec.v[3]=1.;
  134. return vec;
  135. }
  136.  
  137. vector3D_t homogenizeVector(vector3D_t vec){
  138. int i;
  139. for (i=0;i<3;i++) {
  140. vec.v[i]/=vec.v[3];
  141. }
  142. vec.v[3]=1.;
  143. return vec;
  144. }
  145.  
  146. vector3D_t unitVector(vector3D_t vec){
  147. int i;
  148. float vec2=0.;
  149. float vec1,invvec1;
  150. for (i=0;i<3;i++) {
  151. vec2+=vec.v[i]*vec.v[i];
  152. }
  153. vec1=sqrt(vec2);
  154. if (vec1!=0.) {
  155. invvec1=1./vec1;
  156. for (i=0;i<3;i++) {
  157. vec.v[i]*=invvec1;
  158. }
  159. }
  160. vec.v[3]=1.;
  161. return vec;
  162. }
  163.  
  164. // inner product (dot product) of homogeneous vector
  165. float operator * (vector3D_t a, vector3D_t b){
  166. float c;//c=a*b
  167. int i;
  168. c=0;
  169. for (i=0;i<3;i++) {
  170. c+=a.v[i]*b.v[i];
  171. }
  172. return c;
  173. }
  174.  
  175. // outer product (cross product ) of homogeneous vector
  176. // i j k
  177. // a0 a1 a2
  178. // b0 b1 b2
  179. vector3D_t operator ^ (vector3D_t a, vector3D_t b){
  180. vector3D_t c;//c=a*b
  181. c.v[0]=a.v[1]*b.v[2]-a.v[2]*b.v[1];
  182. c.v[1]=a.v[2]*b.v[0]-a.v[0]*b.v[2];
  183. c.v[2]=a.v[0]*b.v[1]-a.v[1]*b.v[0];
  184. c.v[3]=1.;
  185. return c;
  186. }
  187.  
  188. vector3D_t operator - (vector3D_t v1,vector3D_t v0){
  189. vector3D_t c;//c=v1-v0
  190. c.v[0]=v1.v[0]-v0.v[0];
  191. c.v[1]=v1.v[1]-v0.v[1];
  192. c.v[2]=v1.v[2]-v0.v[2];
  193. c.v[3]=1.;
  194. return c;
  195. }
  196.  
  197. vector3D_t operator - (vector3D_t v){
  198. vector3D_t c;//c=-v
  199. c.v[0]=-v.v[0];
  200. c.v[1]=-v.v[1];
  201. c.v[2]=-v.v[2];
  202. c.v[3]=1.;
  203. return c;
  204. }
  205.  
  206. vector3D_t operator * (float r, vector3D_t b){
  207. vector3D_t c;//c=r*b
  208. int i;
  209. for (i=0;i<3;i++) {
  210. c.v[i]=r*b.v[i];
  211. }
  212. c.v[3]=1.;
  213. return c;
  214. }
  215.  
  216. vector3D_t operator * (vector3D_t b, float r){
  217. vector3D_t c;//c=r*b
  218. int i;
  219. for (i=0;i<3;i++) {
  220. c.v[i]=r*b.v[i];
  221. }
  222. c.v[3]=1.;
  223. return c;
  224. }
  225.  
  226. float funcPositive(float x){
  227. if (0.<x) return x;
  228. else return 0.;
  229. }
  230.  
  231. // x to yth power
  232. float power(float x,float y){
  233. //ln z = y ln x z = exp (y ln x)
  234. if (x==0.) return 0;
  235. return exp(y*log(x));
  236. }
  237.  
  238. color_t operator + (color_t c1, color_t c2){
  239. color_t col;
  240. col.r=c1.r+c2.r;
  241. col.g=c1.g+c2.g;
  242. col.b=c1.b+c2.b;
  243. return col;
  244. }
  245.  
  246. color_t operator * (float r, color_t c){
  247. color_t col;
  248. col.r=r*c.r;
  249. col.g=r*c.g;
  250. col.b=r*c.b;
  251. return col;
  252. }
  253.  
  254. color_t operator * (color_t c, float r){
  255. color_t col;
  256. col.r=r*c.r;
  257. col.g=r*c.g;
  258. col.b=r*c.b;
  259. return col;
  260. }
  261.  
  262. //PhongModel color calculation
  263. // LightVector, NormalVector, ViewVector, ColorofObject
  264. color_t PhongModel(vector3D_t Light,vector3D_t Normal,vector3D_t View,color_t col){
  265. float kspe=0.8; // specular reflection coefficient
  266. float kdif=0.5; // diffuse reflection coefficient
  267. float kamb=0.3; // ambient light coefficient
  268. float tmp,NL,RV;
  269. color_t ColWhite={1,0,0};
  270. vector3D_t ReflectionVector=(2.*(Light*Normal)*Normal)-Light;
  271. tmp=Normal*Light;
  272. NL=funcPositive(tmp);
  273. tmp=ReflectionVector*View;
  274. RV=funcPositive(tmp);
  275. return kdif*NL*col+kspe*power(RV,4)*ColWhite+kamb*col;
  276. //return kdif*NL*col+kamb*col;
  277. }
  278.  
  279. color_t PhongModel2(vector3D_t Light,vector3D_t Normal,vector3D_t View,color_t col){
  280. float kspe=0.8; // specular reflection coefficient
  281. float kdif=0.5; // diffuse reflection coefficient
  282. float kamb=0.3; // ambient light coefficient
  283. float tmp,NL,RV;
  284. color_t ColWhite={1,1,1};
  285. vector3D_t ReflectionVector=(2.*(Light*Normal)*Normal)-Light;
  286. tmp=Normal*Light;
  287. NL=funcPositive(tmp);
  288. tmp=ReflectionVector*View;
  289. RV=funcPositive(tmp);
  290. return kdif*NL*col+kspe*power(RV,4)*ColWhite+kamb*col;
  291. //return kdif*NL*col+kamb*col;
  292. }
  293.  
  294. ////////////// End of matrices and vectors 3D ver 2 //////////////
  295.  
  296. ////////////// OpenGL drawShape Functions ver 1 /////////////////
  297. void setColor(float red,float green,float blue){
  298. glColor3f(red, green, blue);
  299. }
  300.  
  301. void setColor(color_t col){
  302. glColor3f(col.r, col.g, col.b);
  303. }
  304.  
  305. void drawDot(float x,float y){
  306. glBegin(GL_POINTS);
  307. glVertex2f(x, y);
  308. glEnd();
  309. }
  310.  
  311. void drawLine(float x1, float y1, float x2, float y2){
  312. glBegin(GL_LINES);
  313. glVertex2f(x1, y1);
  314. glVertex2f(x2, y2);
  315. glEnd();
  316. }
  317.  
  318. void drawLine(point2D_t p1,point2D_t p2){
  319. drawLine(p1.x,p1.y,p2.x,p2.y);
  320. }
  321.  
  322. //n: number of points
  323. void drawPolyline(point2D_t pnt[],int n){
  324. int i;
  325. glBegin(GL_LINE_STRIP);
  326. for (i=0;i<n;i++) {
  327. glVertex2f(pnt[i].x, pnt[i].y);
  328. }
  329. glEnd();
  330. }
  331.  
  332. //n: number of vertices
  333. void drawPolygon(point2D_t pnt[],int n){
  334. int i;
  335. glBegin(GL_LINE_LOOP);
  336. for (i=0;i<n;i++) {
  337. glVertex2f(pnt[i].x, pnt[i].y);
  338. }
  339. glEnd();
  340. }
  341.  
  342. // The function fillPolygon can fills only convex polygons
  343. //n: number of vertices
  344. void fillPolygon(point2D_t pnt[],int n,color_t color){
  345. int i;
  346. setColor(color);
  347. glBegin(GL_POLYGON);
  348. for (i=0;i<n;i++) {
  349. glVertex2f(pnt[i].x, pnt[i].y);
  350. }
  351. glEnd();
  352. }
  353.  
  354. // The function gradatePolygon can fills only convex polygons
  355. // The vertices will be painted with corresponding given colors.
  356. // The points inside the polygon will be painted with the mixed color.
  357. //n: number of vertices
  358. void gradatePolygon(point2D_t pnt[],int num,color_t col[]){
  359. int i;
  360. glBegin(GL_POLYGON);
  361. for (i=0;i<num;i++) {
  362. setColor(col[i]);
  363. glVertex2f(pnt[i].x, pnt[i].y);
  364. }
  365. glEnd();
  366. }
  367.  
  368. //////////// End of OpenGL drawShape Functions ver 1 ////////////
  369.  
  370. void userdraw(void);
  371.  
  372. void display(void){
  373. glClear( GL_COLOR_BUFFER_BIT);
  374. userdraw();
  375. glutSwapBuffers();
  376. }
  377.  
  378. //////////////////////////////////////////////////////////////////
  379. void drawcharX(float x,float y){
  380. drawLine(x,y,x+10,y+12);drawLine(x,y+12,x+10,y);
  381. }
  382.  
  383. void drawcharY(float x,float y){
  384. drawLine(x+5,y,x+5,y+7);drawLine(x,y+12,x+5,y+7);drawLine(x+10,y+12,x+5,y+7);
  385. }
  386.  
  387. void drawcharZ(float x,float y){
  388. drawLine(x,y+12,x+10,y+12);drawLine(x+10,y+12,x,y);drawLine(x,y,x+10,y);
  389. }
  390.  
  391. void drawAxes(matrix3D_t view){
  392. #define HALFAXIS 220
  393. #define HALFAXIS1 (HALFAXIS-10)
  394. point3D_t axes[14]={
  395. {-HALFAXIS,0,0},{HALFAXIS,0,0},{HALFAXIS1,5,0},{HALFAXIS1,0,0},{0,0,0},
  396. {0,-HALFAXIS,0},{0,HALFAXIS,0},{0,HALFAXIS1,5},{0,HALFAXIS1,0},{0,0,0},
  397. {0,0,-HALFAXIS},{0,0,HALFAXIS},{5,0,HALFAXIS1},{0,0,HALFAXIS1}
  398. };
  399. vector3D_t vec[14];
  400. point2D_t buff[14];
  401. int i;
  402. for (i=0;i<14;i++) {
  403. vec[i]=Point2Vector(axes[i]);
  404. vec[i]=view*vec[i];
  405. buff[i]=Vector2Point2D(vec[i]);
  406. }
  407. drawPolyline(buff,14);
  408. drawcharX(buff[1].x,buff[1].y);
  409. drawcharY(buff[6].x,buff[6].y);
  410. drawcharZ(buff[11].x-14,buff[11].y);
  411. }
  412.  
  413. //////////////////////////////////////////////////////////////////
  414. typedef struct {
  415. int NumberofVertices; //in the face
  416. short int pnt[50];
  417. color_t col;
  418. } face_t;
  419. typedef struct {
  420. int NumberofVertices; //of the object
  421. point3D_t pnt[1600];
  422. color_t col[1600];
  423. int NumberofFaces; //of the object
  424. face_t fc[1000];
  425. } object3D_t;
  426.  
  427. float zRata(object3D_t obyek,matrix3D_t mat){
  428. int i;
  429. float z=0;
  430. vector3D_t vec;
  431.  
  432. for(i=0;i<obyek.NumberofVertices;i++){
  433. vec=Point2Vector(obyek.pnt[i]);
  434. vec=mat*vec;
  435. z=z+vec.v[2];
  436. }
  437. z=z/obyek.NumberofVertices;
  438. return z;
  439. }
  440.  
  441.  
  442. void draw3D(object3D_t obyek,matrix3D_t mat){
  443. vector3D_t vec[1600], vecbuff[50];
  444. vector3D_t vecNormal;
  445. point2D_t p[50];
  446. int i,j;
  447. for(i=0;i<obyek.NumberofVertices;i++){
  448. vec[i]=Point2Vector(obyek.pnt[i]);
  449. vec[i]=mat*vec[i];
  450. }
  451. setColor(1,0,0);
  452. for(i=0;i<obyek.NumberofFaces;i++){
  453. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  454. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  455. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  456. if(vecNormal.v[2]<0){
  457. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  458. p[j]=Vector2Point2D(vecbuff[j]);
  459. }
  460. drawPolygon(p,obyek.fc[i].NumberofVertices);
  461. }
  462. }
  463. setColor(1,1,1);
  464. for(i=0;i<obyek.NumberofFaces;i++){
  465. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  466. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  467. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  468. if(vecNormal.v[2]>=0){
  469. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  470. p[j]=Vector2Point2D(vecbuff[j]);
  471. }
  472. drawPolygon(p,obyek.fc[i].NumberofVertices);
  473. }
  474. }
  475. }
  476.  
  477. void draw3Da(object3D_t obyek,matrix3D_t mat){
  478. vector3D_t vec[1600], vecbuff[50];
  479. vector3D_t vecNormal;
  480. point2D_t p[50];
  481. int i,j;
  482. for(i=0;i<obyek.NumberofVertices;i++){
  483. vec[i]=Point2Vector(obyek.pnt[i]);
  484. vec[i]=mat*vec[i];
  485. }
  486. setColor(1,1,1);
  487. for(i=0;i<obyek.NumberofFaces;i++){
  488. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  489. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  490. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  491. p[j]=Vector2Point2D(vecbuff[j]);
  492. drawPolygon(p,obyek.fc[i].NumberofVertices);
  493. }
  494. }
  495.  
  496. void draw3Dw(object3D_t obyek,matrix3D_t mat,color_t col){
  497. vector3D_t vec[1600], vecbuff[50];
  498. vector3D_t vecNormal;
  499. vector3D_t lightVector={1,0,1,1},viewVector={0,0,1,1}, lightVector2={-1,0,-1,1};
  500. color_t colbuff, colbuff2;
  501. point2D_t p[50];
  502. int i,j;
  503. for(i=0;i<obyek.NumberofVertices;i++){
  504. vec[i]=Point2Vector(obyek.pnt[i]);
  505. vec[i]=mat*vec[i];
  506. }
  507. for(i=0;i<obyek.NumberofFaces;i++){
  508. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  509. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  510. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  511. if(vecNormal.v[2]<0){
  512. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  513. p[j]=Vector2Point2D(vecbuff[j]);
  514. }
  515. vecNormal=unitVector(vecNormal);
  516. colbuff=PhongModel(lightVector,vecNormal,viewVector,col);
  517. colbuff2=PhongModel2(lightVector2,vecNormal,viewVector,col);
  518. fillPolygon(p,obyek.fc[i].NumberofVertices,colbuff);
  519. fillPolygon(p,obyek.fc[i].NumberofVertices,colbuff2);
  520. }
  521. }
  522. for(i=0;i<obyek.NumberofFaces;i++){
  523. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  524. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  525. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  526. if(vecNormal.v[2]>=0){
  527. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  528. p[j]=Vector2Point2D(vecbuff[j]);
  529. }
  530. vecNormal=unitVector(vecNormal);
  531. colbuff=PhongModel(lightVector,vecNormal,viewVector,col);
  532. fillPolygon(p,obyek.fc[i].NumberofVertices,colbuff);
  533. }
  534. }
  535. }
  536.  
  537. void draw3Dc(object3D_t obyek,matrix3D_t mat){
  538. vector3D_t vec[1600], vecbuff[50];
  539. vector3D_t vecNormal;
  540. vector3D_t lightVector={0,0,1,1},viewVector={0,0,1,1};
  541. color_t colbuff;
  542. point2D_t p[50];
  543. int i,j;
  544. for(i=0;i<obyek.NumberofVertices;i++){
  545. vec[i]=Point2Vector(obyek.pnt[i]);
  546. vec[i]=mat*vec[i];
  547. }
  548. for(i=0;i<obyek.NumberofFaces;i++){
  549. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  550. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  551. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  552. if(vecNormal.v[2]<0){
  553. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  554. p[j]=Vector2Point2D(vecbuff[j]);
  555. }
  556. vecNormal=unitVector(vecNormal);
  557. colbuff=PhongModel(lightVector,vecNormal,viewVector,obyek.fc[i].col);
  558. fillPolygon(p,obyek.fc[i].NumberofVertices,colbuff);
  559. }
  560. }
  561. for(i=0;i<obyek.NumberofFaces;i++){
  562. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  563. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  564. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  565. if(vecNormal.v[2]>=0){
  566. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  567. p[j]=Vector2Point2D(vecbuff[j]);
  568. }
  569. vecNormal=unitVector(vecNormal);
  570. colbuff=PhongModel(lightVector,vecNormal,viewVector,obyek.fc[i].col);
  571. fillPolygon(p,obyek.fc[i].NumberofVertices,colbuff);
  572. }
  573. }
  574. }
  575.  
  576. void draw3Dcg(object3D_t obyek,matrix3D_t mat){
  577. vector3D_t vec[1600], vecbuff[50];
  578. vector3D_t vecNormal;
  579. vector3D_t lightVector={0,0,1,1},viewVector={0,0,1,1};
  580. color_t colbuff[50];
  581. point2D_t p[50];
  582. int i,j;
  583. for(i=0;i<obyek.NumberofVertices;i++){
  584. vec[i]=Point2Vector(obyek.pnt[i]);
  585. vec[i]=mat*vec[i];
  586. }
  587. for(i=0;i<obyek.NumberofFaces;i++){
  588. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  589. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  590. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  591. if(vecNormal.v[2]<0){
  592. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  593. p[j]=Vector2Point2D(vecbuff[j]);
  594. vecNormal=unitVector(vecbuff[j]);
  595. colbuff[j]=PhongModel(lightVector,vecNormal,viewVector,obyek.col[obyek.fc[i].pnt[j]]);
  596. }
  597. gradatePolygon(p,obyek.fc[i].NumberofVertices,colbuff);
  598. }
  599. }
  600. for(i=0;i<obyek.NumberofFaces;i++){
  601. for(j=0;j<obyek.fc[i].NumberofVertices;j++)
  602. vecbuff[j]=vec[obyek.fc[i].pnt[j]];
  603. vecNormal=(vecbuff[1]-vecbuff[0])^(vecbuff[2]-vecbuff[0]);
  604. if(vecNormal.v[2]>=0){
  605. for(j=0;j<obyek.fc[i].NumberofVertices;j++){
  606. p[j]=Vector2Point2D(vecbuff[j]);
  607. vecNormal=unitVector(vecbuff[j]);
  608. colbuff[j]=PhongModel(lightVector,vecNormal,viewVector,obyek.col[obyek.fc[i].pnt[j]]);
  609. }
  610. gradatePolygon(p,obyek.fc[i].NumberofVertices,colbuff);
  611. }
  612. }
  613. }
  614.  
  615. void makeCube(object3D_t &kubus, float d){
  616. object3D_t obyek={8,
  617. {{0,0,0},{d,0,0},{d,0,d},{0,0,d},{0,d,0},{d,d,0},{d,d,d},{0,d,d}},
  618. {{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0},{1,1,0}},
  619. 6,
  620. {{4,{0,1,2,3},{1,1,0}},{4,{4,7,6,5},{1,1,0}},{4,{1,5,6,2},{1,1,0}},{4,{0,3,7,4},{1,1,0}},{4,{2,6,7,3},{1,1,0}},{4,{0,4,5,1},{1,1,0}}}};
  621. matrix3D_t mat=translationMTX(-d/2,-d/2,-d/2);
  622. vector3D_t vec;
  623. kubus=obyek;
  624. for(int i=0;i<kubus.NumberofVertices;i++){
  625. vec=Point2Vector(kubus.pnt[i]);
  626. vec=mat*vec;
  627. kubus.pnt[i]=Vector2Point3D(vec);
  628. }
  629. }
  630.  
  631. void makeCylinder(object3D_t &silinder, int n, float r, float h){
  632. float a=6.28/n;
  633. int i;
  634. for(i=0;i<n;i++){
  635. silinder.pnt[i].x=r*cos(i*a);
  636. silinder.pnt[i].y=0;
  637. silinder.pnt[i].z=r*sin(i*a);
  638. silinder.pnt[n+i].x=r*cos(i*a);
  639. silinder.pnt[n+i].y=h;
  640. silinder.pnt[n+i].z=r*sin(i*a);
  641. }
  642. silinder.NumberofVertices=2*n;
  643. for(i=0;i<n;i++){
  644. silinder.fc[i].NumberofVertices=4;
  645. silinder.fc[i].pnt[0]=i;
  646. silinder.fc[i].pnt[1]=n+i;
  647. silinder.fc[i].pnt[2]=n+i+1;
  648. silinder.fc[i].pnt[3]=i+1;
  649. if(i==(n-1)){
  650. silinder.fc[i].pnt[2]=n;
  651. silinder.fc[i].pnt[3]=0;
  652. }
  653. }
  654. silinder.fc[n].NumberofVertices=n;
  655. for(i=0;i<n;i++) silinder.fc[n].pnt[i]=i;
  656. silinder.fc[n+1].NumberofVertices=n;
  657. for(i=0;i<n;i++) silinder.fc[n+1].pnt[i]=2*n-1-i;
  658. silinder.NumberofFaces=n+2;
  659. color_t c={1,1,0};
  660. for(i=0;i<silinder.NumberofFaces;i++) silinder.fc[i].col=c;
  661. for(i=0;i<silinder.NumberofVertices;i++)
  662. silinder.col[i]=c;
  663. }
  664.  
  665. void makeCylinderAwur(object3D_t &silinder, int n, float r, float h){
  666. float a=6.28/n;
  667. int i;
  668. float f;
  669. for(i=0;i<n;i++){
  670. f=3*i/n;
  671. silinder.pnt[i].x=r*f*cos(i*a);
  672. silinder.pnt[i].y=0;
  673. silinder.pnt[i].z=r*f*sin(i*a);
  674. silinder.pnt[n+i].x=r*f*cos(i*a);
  675. silinder.pnt[n+i].y=h;
  676. silinder.pnt[n+i].z=r*f*sin(i*a);
  677. }
  678. silinder.NumberofVertices=2*n;
  679. for(i=0;i<n;i++){
  680. silinder.fc[i].NumberofVertices=4;
  681. silinder.fc[i].pnt[0]=i;
  682. silinder.fc[i].pnt[1]=n+i;
  683. silinder.fc[i].pnt[2]=n+i+1;
  684. silinder.fc[i].pnt[3]=i+1;
  685. if(i==(n-1)){
  686. silinder.fc[i].pnt[2]=n;
  687. silinder.fc[i].pnt[3]=0;
  688. }
  689. }
  690. silinder.fc[n].NumberofVertices=n;
  691. for(i=0;i<n;i++) silinder.fc[n].pnt[i]=i;
  692. silinder.fc[n+1].NumberofVertices=n;
  693. for(i=0;i<n;i++) silinder.fc[n+1].pnt[i]=2*n-1-i;
  694. silinder.NumberofFaces=n+2;
  695. color_t c={1,1,0};
  696. for(i=0;i<silinder.NumberofFaces;i++) silinder.fc[i].col=c;
  697. for(i=0;i<silinder.NumberofVertices;i++)
  698. silinder.col[i]=c;
  699. }
  700.  
  701. void makeCone(object3D_t &kerucut, int n, float r,float h){
  702. float a=6.28/n;
  703. int i;
  704. kerucut.pnt[0].x=0;
  705. kerucut.pnt[0].y=h;
  706. kerucut.pnt[0].z=0;
  707. for(i=1;i<=n;i++){
  708. kerucut.pnt[i].x=r*cos(i*a);
  709. kerucut.pnt[i].y=0;
  710. kerucut.pnt[i].z=r*sin(i*a);
  711. }
  712. for(i=0;i<n;i++){
  713. kerucut.fc[i].NumberofVertices=3;
  714. kerucut.fc[i].pnt[0]=0;
  715. kerucut.fc[i].pnt[1]=i+2;
  716. kerucut.fc[i].pnt[2]=i+1;
  717. if(i==(n-1)) kerucut.fc[i].pnt[1]=1;
  718. }
  719. kerucut.fc[n].NumberofVertices=n;
  720. for(i=0;i<n;i++) kerucut.fc[n].pnt[i]=i+1;
  721. kerucut.NumberofVertices=n+1;
  722. kerucut.NumberofFaces=n+1;
  723. color_t c={1,1,0};
  724. for(i=0;i<kerucut.NumberofFaces;i++) kerucut.fc[i].col=c;
  725. for(i=0;i<kerucut.NumberofVertices;i++)
  726. kerucut.col[i]=c;
  727. }
  728.  
  729. void makeCylinderN(object3D_t &silinder,int m,int n,float r[],float h[],int sw){
  730. float a=6.26/n;
  731. float b=0;
  732. int i,j;
  733. silinder.NumberofVertices=(m+1)*n;
  734. for(i=0;i<=m;i++){
  735. if(i>0) b=b+h[i-1];
  736. for(j=0;j<n;j++){
  737. silinder.pnt[i*n+j].x=r[i]*cos(j*a);
  738. silinder.pnt[i*n+j].y=b;
  739. silinder.pnt[i*n+j].z=r[i]*sin(j*a);
  740. }
  741. }
  742. silinder.NumberofFaces=m*n+2;
  743. for(i=0;i<m;i++){
  744. for(j=0;j<n;j++){
  745. silinder.fc[i*n+j].NumberofVertices=4;
  746. silinder.fc[i*n+j].pnt[0]=i*n+j;
  747. silinder.fc[i*n+j].pnt[1]=(i+1)*n+j;
  748. silinder.fc[i*n+j].pnt[2]=(i+1)*n+j+1;
  749. silinder.fc[i*n+j].pnt[3]=i*n+j+1;
  750. if(j==(n-1)){
  751. silinder.fc[i*n+j].pnt[2]=i*n+j+1;
  752. silinder.fc[i*n+j].pnt[3]=(i-1)*n+j+1;
  753. }
  754. }
  755. }
  756. if(sw==0 || sw==1){
  757. silinder.NumberofFaces=m*n+1;
  758. silinder.fc[m*n].NumberofVertices=n;
  759. for(i=0;i<n;i++) silinder.fc[m*n].pnt[i]=i;
  760. }
  761. if(sw==0 || sw==2){
  762. silinder.NumberofFaces=m*n+1;
  763. silinder.fc[m*n+1].NumberofVertices=n;
  764. for(i=0;i<n;i++) silinder.fc[m*n+1].pnt[i]=(m+1)*n-1-i;
  765. }
  766. color_t c={1,1,0};
  767. for(i=0;i<silinder.NumberofFaces;i++) silinder.fc[i].col=c;
  768. for(i=0;i<silinder.NumberofVertices;i++)
  769. silinder.col[i]=c;
  770. }
  771.  
  772. void makeSphere(object3D_t &sphere,int n,float r){
  773. float a=6.28/n;
  774. float b=6.28/n;
  775. int i,j;
  776. sphere.NumberofVertices=(n+1)*n;
  777. for(i=0;i<=n;i++){
  778. for(j=0;j<n;j++){
  779. sphere.pnt[i*n+j].x=r*cos(j*a)*sin(i*b);
  780. sphere.pnt[i*n+j].y=r*cos(i*b);
  781. sphere.pnt[i*n+j].z=r*sin(j*a)*sin(i*b);
  782. }
  783. }
  784. sphere.NumberofFaces=n*n+2;
  785. for(i=0;i<n;i++){
  786. for(j=0;j<n;j++){
  787. sphere.fc[i*n+j].NumberofVertices=4;
  788. sphere.fc[i*n+j].pnt[0]=i*n+j;
  789. sphere.fc[i*n+j].pnt[1]=(i+1)*n+j;
  790. sphere.fc[i*n+j].pnt[2]=(i+1)*n+j+1;
  791. sphere.fc[i*n+j].pnt[3]=i*n+j+1;
  792. if(j==(n-1)){
  793. sphere.fc[i*n+j].pnt[2]=i*n+j+1;
  794. sphere.fc[i*n+j].pnt[3]=(i-1)*n+j+1;
  795. }
  796. }
  797. }
  798. sphere.fc[n*n].NumberofVertices=n;
  799. for(i=0;i<n;i++) sphere.fc[n*n].pnt[i]=i;
  800. sphere.fc[n*n+1].NumberofVertices=n;
  801. for(i=0;i<n;i++) sphere.fc[n*n+1].pnt[i]=(n+1)*n-1-i;
  802. color_t c={1,1,0};
  803. for(i=0;i<sphere.NumberofFaces;i++) sphere.fc[i].col=c;
  804. for(i=0;i<sphere.NumberofVertices;i++)
  805. sphere.col[i]=c;
  806. }
  807.  
  808. void makeApple(object3D_t &sphere,int n,float r){
  809. float a=6.28/n;
  810. float b=6.28/n;
  811. int i,j,k;
  812. sphere.NumberofVertices=(n+1)*n;
  813. for(i=0;i<=n;i++){
  814. for(j=0;j<n;j++){
  815. sphere.pnt[i*n+j].x=r*cos(j*a)*sin(i*b);
  816. sphere.pnt[i*n+j].y=r*cos(i*b);
  817. if(i>n-1){
  818. k=i-(n-1);
  819. sphere.pnt[i*n+j].y-=20*k;
  820. }
  821. sphere.pnt[i*n+j].z=r*sin(j*a)*sin(i*b);
  822. }
  823. }
  824. sphere.NumberofFaces=n*n+2;
  825. for(i=0;i<n;i++){
  826. for(j=0;j<n;j++){
  827. sphere.fc[i*n+j].NumberofVertices=4;
  828. sphere.fc[i*n+j].pnt[0]=i*n+j;
  829. sphere.fc[i*n+j].pnt[1]=(i+1)*n+j;
  830. sphere.fc[i*n+j].pnt[2]=(i+1)*n+j+1;
  831. sphere.fc[i*n+j].pnt[3]=i*n+j+1;
  832. if(j==(n-1)){
  833. sphere.fc[i*n+j].pnt[2]=i*n+j+1;
  834. sphere.fc[i*n+j].pnt[3]=(i-1)*n+j+1;
  835. }
  836. }
  837. }
  838. sphere.fc[n*n].NumberofVertices=n;
  839. for(i=0;i<n;i++) sphere.fc[n*n].pnt[i]=i;
  840. sphere.fc[n*n+1].NumberofVertices=n;
  841. for(i=0;i<n;i++) sphere.fc[n*n+1].pnt[i]=(n+1)*n-1-i;
  842. color_t c={1,1,0};
  843. for(i=0;i<sphere.NumberofFaces;i++) sphere.fc[i].col=c;
  844. for(i=0;i<sphere.NumberofVertices;i++)
  845. sphere.col[i]=c;
  846. }
  847.  
  848. void makeCheese(object3D_t &o,int n,float d){
  849. o.NumberofVertices=(n+1)*(n+1);
  850. int i,j,k;
  851. for(i=0;i<n+1;i++)
  852. for(j=0;j<n+1;j++){
  853. k=(n+1)*i+j;
  854. o.pnt[k].x=j*d;
  855. o.pnt[k].y=0;
  856. o.pnt[k].z=i*d;
  857. }
  858. o.NumberofFaces = n*n;
  859. color_t w1={1,1,1},w2={0,0,0};
  860. for(i=0;i<n;i++)
  861. for(j=0;j<n;j++){
  862. k=n*i+j;
  863. o.fc[k].NumberofVertices=4;
  864. o.fc[k].pnt[0]=(n+1)*i+j;
  865. o.fc[k].pnt[1]=(n+1)*i+j+n+1;
  866. o.fc[k].pnt[2]=(n+1)*i+j+n+2;
  867. o.fc[k].pnt[3]=(n+1)*i+j+1;
  868. if((i+j)%2==0) o.fc[k].col=w1;
  869. else o.fc[k].col=w2;
  870. }
  871. for(i=0;i<o.NumberofVertices;i++)
  872. o.col[i]=w1;
  873. }
  874.  
  875. point3D_t interpolate(point3D_t p1,point3D_t p2,float a){
  876. point3D_t p;
  877. p.x=(1-a)*p1.x+a*p2.x;
  878. p.y=(1-a)*p1.y+a*p2.y;
  879. p.z=(1-a)*p1.z+a*p2.z;
  880. return p;
  881. }
  882.  
  883. //Merubah arah cahaya
  884. void shading() {
  885.  
  886. }
  887.  
  888. void userdraw(void){
  889.  
  890. static float a = 0;
  891. matrix3D_t tilting = rotationYMTX(a)*rotationXMTX(0.2);
  892. setColor(1,1,0);
  893. drawAxes(tilting);
  894.  
  895.  
  896. /*
  897. static float d=0;
  898. matrix3D_t tilting = rotationXMTX(0.5)*rotationYMTX(d);
  899. setColor(0, 1, 0);
  900. drawAxes(tilting);
  901. */
  902.  
  903. /*
  904. float z[3];
  905. object3D_t obj[3];
  906. makeSphere(obj[0], 20, 80);
  907. color_t w[3] = {{1,1,0},{0,1,0},{1,0,0}};
  908. matrix3D_t mat[3];
  909. mat[0] = tilting;
  910.  
  911. makeSphere(obj[1], 20, 50);
  912. mat[1] = tilting*translationMTX(300, 0, 0);
  913.  
  914. makeSphere(obj[2], 20, 25);
  915. mat[2] = tilting*translationMTX(300, 0, 0)*rotationYMTX(2*d)*
  916. translationMTX(150, 0, 0);
  917.  
  918. z[0]=zRata(obj[0], mat[0]);
  919. z[1]=zRata(obj[1], mat[1]);
  920. z[2]=zRata(obj[2], mat[2]);
  921.  
  922. float zt;
  923. object3D_t objt;
  924. matrix3D_t matt;
  925. color_t wt;
  926. for(int i=0; i<2; i++)
  927. for(int j=0; j<2; j++){
  928. if(z[j]>z[j+1]){
  929. objt = obj[j]; zt=z[j]; matt=mat[j];
  930. obj[j]=obj[j+1];z[j]=z[j+1]; mat[j]=mat[j+1];
  931. obj[j+1]=objt; z[j+1]=zt; mat[j+1]=matt;
  932. wt=w[j]; w[j]=w[j+1]; w[j+1]=wt;
  933. }
  934. }
  935. for(int i=0; i<3; i++){
  936. draw3Dw(obj[i], mat[i], w[i]);
  937. }
  938.  
  939. d+=0.0005;
  940. */
  941.  
  942.  
  943. /*
  944. object3D_t kerucut;
  945. makeCone(kerucut, 30, 40, 120);
  946. color_t w1 = { 0.7, 0.7, 0 };
  947. draw3Dw(kerucut, tilting, w1);
  948.  
  949. object3D_t silinder;
  950. makeCylinder(silinder, 30, 40, 200);
  951. matrix3D_t mat = tilting*translationMTX(0,-200,0);
  952. color_t w2 = { 0, 0, 1 };
  953. draw3Dw(silinder, mat, w2);
  954.  
  955. object3D_t silinder1;
  956. makeCylinder(silinder1, 30, 40, 20);
  957. matrix3D_t mat1 = tilting*translationMTX(0,-220,0);
  958. color_t w3 = { 1, 1, 1 };
  959. draw3Dw(silinder1, mat1, w3);
  960.  
  961. object3D_t silinder2;
  962. makeCylinder(silinder2, 30, 40, 60);
  963. matrix3D_t mat2 = tilting*translationMTX(0,-280,0);
  964. color_t w4 = { 1, 0, 0 };
  965. draw3Dw(silinder2, mat2, w4);
  966. */
  967.  
  968.  
  969. object3D_t cawan;
  970. float hCawan[2] = { 5, 10};
  971. float rCawan[3] = { 50, 50, 150};
  972. makeCylinderN(cawan, 2, 30, rCawan, hCawan, 1);
  973. matrix3D_t matCawan = tilting*translationMTX(0, -50, 0);
  974. color_t wCawan = { 0, 1, 0 };
  975. //draw3Dw(cawan, matCawan, wCawan);
  976.  
  977. object3D_t silinders;
  978. float h[14] = { 5, 15, 5, 5, 5, 40, 5, 5, 5, 20, 10, 5, 5, 10 };
  979. float r[15] = { 15, 20, 20, 15, 15, 20, 20, 15, 15, 20, 20, 5, 5, 10, 10 };
  980. makeCylinderN(silinders, 14, 20, r, h, 0);
  981. matrix3D_t mats = tilting*translationMTX(-100, 0, 0);
  982. color_t ws = { 0, 0, 1 };
  983. //draw3Dw(silinders, mats, ws);
  984.  
  985. object3D_t wine;
  986. float hWine[4] = { 25, 30, 30, 40 };
  987. float rWine[5] = { 40, 5, 5, 30, 35 };
  988. makeCylinderN(wine, 4, 30, rWine, hWine, 1);
  989. matrix3D_t matWine = tilting*translationMTX(0, 0, 0);
  990. color_t wWine = { 1, 0, 0 };
  991. //draw3Dw(wine, matWine, wWine);
  992.  
  993. object3D_t obj[3] = {cawan, silinders, wine};
  994. matrix3D_t mat[3] = {matCawan, mats, matWine};
  995. color_t w[3] = {wCawan, ws, wWine};
  996. draw3Dw(obj[0],mat[0],w[0]);
  997. draw3Dw(obj[1],mat[1],w[1]);
  998. draw3Dw(obj[2],mat[2],w[2]);
  999.  
  1000. float z[3], zt;
  1001. object3D_t objt;
  1002. matrix3D_t matt;
  1003. color_t wt;
  1004. z[0]=zRata(obj[0], mat[0]);
  1005. z[1]=zRata(obj[1], mat[1]);
  1006. z[2]=zRata(obj[2], mat[2]);
  1007.  
  1008. for(int i=0; i<2; i++)
  1009. for(int j=0; j<2; j++){
  1010. if(z[j]>z[j+1]){
  1011. objt = obj[j]; zt=z[j]; matt=mat[j];
  1012. obj[j]=obj[j+1];z[j]=z[j+1]; mat[j]=mat[j+1];
  1013. obj[j+1]=objt; z[j+1]=zt; mat[j+1]=matt;
  1014. wt=w[j]; w[j]=w[j+1]; w[j+1]=wt;
  1015. }
  1016. }
  1017. for(int i=0; i<3; i++){
  1018. draw3Dw(obj[i], mat[i], w[i]);
  1019. }
  1020.  
  1021. a = a+0.001;
  1022.  
  1023.  
  1024. /*
  1025. //draw points
  1026. point3D_t p={100,100,50};
  1027. vector3D_t vec;
  1028. point2D_t p2;
  1029. vec= Point2Vector(p);
  1030. vec=tilting*vec;
  1031. p2=Vector2Point2D(vec);
  1032. glPointSize(4);
  1033. glBegin(GL_POINTS);
  1034. glVertex2f(p2.x,p2.y);
  1035. glEnd();
  1036.  
  1037. //draw line
  1038. point3D_t q[2]= {{100,0,0},{0,100,0}};
  1039. point2D_t q2[2];
  1040. for(int i=0;i<2;i++){
  1041. vec= Point2Vector(q[i]);
  1042. vec=tilting*vec;
  1043. q2[i]=Vector2Point2D(vec);
  1044. drawLine(q2[0],q2[1]);
  1045. }
  1046.  
  1047. //draw triangle
  1048. point3D_t qs[3]= {{0,0,0},{-100,0,0},{0,-100,0}};
  1049. point2D_t qs2[3];
  1050. for(int i=0;i<3;i++){
  1051. vec= Point2Vector(qs[i]);
  1052. vec=tilting*vec;
  1053. qs2[i]=Vector2Point2D(vec);
  1054. }
  1055. setColor(1,0,0);
  1056. glBegin(GL_TRIANGLES);
  1057. glVertex2f(qs2[0].x,qs2[0].y);
  1058. glVertex2f(qs2[1].x,qs2[1].y);
  1059. glVertex2f(qs2[2].x,qs2[2].y);
  1060. glEnd();
  1061.  
  1062. //draw cube wirh function
  1063. object3D_t obj;
  1064. makeCube(obj,50);
  1065. draw3D(obj,tilting);
  1066.  
  1067. object3D_t kubus={8,
  1068. {{0,0,0},{100,0,0},{100,0,100},{0,0,100},
  1069. {0,100,0},{100,100,0},{100,100,100},
  1070. {0,100,100}},
  1071. {{1,1,1},{1,1,1},{1,1,1},{1,1,1},{1,1,1},
  1072. {1,1,1},{1,1,1},{1,1,1}},
  1073. 6,
  1074. {{4,{0,1,2,3},{1,1,1}},{4,{7,6,5,4},{1,1,1}},{4,{6,7,3,2},{1,1,1}},
  1075. {4,{4,5,1,0},{1,1,1}},{4,{0,3,7,4},{1,1,1}},{4,{2,1,5,6},{1,1,1}}}
  1076. };
  1077. setColor(1,1,1);
  1078. color_t biru = {0,0,1};
  1079. draw3Dw(kubus,tilting,biru);
  1080.  
  1081. */
  1082.  
  1083. /*
  1084. object3D_t prisma={6,
  1085. {{0,0,0},{100,0,0},{100,0,100},{0,0,100},
  1086. {0,100,0},{0,100,100}},
  1087. {{1,1,1},{1,1,1},{1,1,1},{1,1,1},{1,1,1},
  1088. {1,1,1}},
  1089. 5,
  1090. {{4,{0,1,2,3},{1,1,1}},{4,{5,3,1,4},{1,1,1}},{3,{5,3,2}},
  1091. {3,{4,0,1}},{4,{5,3,0,4}}}
  1092. };
  1093. setColor(1,1,1);
  1094. color_t biru = {0,0,1};
  1095. draw3Dw(prisma,tilting,biru);
  1096. */
  1097.  
  1098. /*
  1099. object3D_t obj;
  1100. makeCone(obj,3,120,180);
  1101. obj.col[0].r=1; obj.col[0].g=1; obj.col[0].b=1;
  1102. obj.col[1].r=1; obj.col[1].g=0; obj.col[1].b=0;
  1103. obj.col[2].r=0; obj.col[2].g=0; obj.col[2].b=1;
  1104. obj.col[3].r=1; obj.col[3].g=0; obj.col[3].b=1;
  1105.  
  1106. draw3Dcg(obj,tilting);
  1107. */
  1108.  
  1109. /*
  1110. object3D_t obj;
  1111. object3D_t obj1;
  1112. makeCube(obj,100);
  1113. color_t w1={1,1,1};
  1114. matrix3D_t mat=tilting*translationMTX(0,50,0)*rotationYMTX(3.14/4);
  1115. makeCone(obj1,4,100,80);
  1116. color_t w2={1,0.5,0};
  1117.  
  1118. float z1=zRata(obj,tilting);
  1119. float z2=zRata(obj1,mat);
  1120. if(z1<z2){
  1121. draw3Dw(obj,tilting,w1);
  1122. }
  1123.  
  1124. a+=0.001;
  1125. */
  1126. }
  1127.  
  1128. int main(int argc, char **argv){
  1129. glutInit(&argc,argv);
  1130. glutInitDisplayMode ( GLUT_DOUBLE | GLUT_RGB );
  1131. glutInitWindowPosition(100,100);
  1132. glutInitWindowSize(640,480);
  1133. glutCreateWindow ("cube");
  1134. glClearColor(0.0, 0.0, 0.0, 0.0);
  1135. gluOrtho2D(-320., 320., -240.0, 240.0);
  1136. // Define the dimensions of the Orthographic Viewing Volume
  1137. glutIdleFunc(display); // idle event call back
  1138. glutDisplayFunc(display);
  1139. glutMainLoop();
  1140. return 0;
  1141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement