Advertisement
PrincessFumi

Untitled

Jun 10th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <GL/glut.h>
  4.  
  5. #include <stdlib.h>
  6.  
  7. #include <GL/SOIL.h>
  8.  
  9. #include <cmath>
  10. #include "materials.h"
  11. GLfloat material[] = { 0.5, 0.5, 0.5, 1.0};
  12. using namespace std;
  13.  
  14. GLfloat spot_direction[ 3 ] =
  15. {
  16. 0.0, 0.0, - 1.0
  17. };
  18.  
  19. // kąt odcięcia reflektora
  20.  
  21. GLfloat spot_cutoff = 180.0;
  22.  
  23. // wykładnik tłumienia kątowego reflektora
  24.  
  25. GLfloat spot_exponent = 128.0;
  26.  
  27. // stały współczynnik tłumienia światła
  28.  
  29. GLfloat constant_attenuation = 1.0;
  30.  
  31. // liniowy współczynnik tłumienia światła
  32.  
  33. GLfloat linear_attenuation = 0.0;
  34.  
  35. // kwadratowy współczynnik tłumienia światła
  36.  
  37. GLfloat quadratic_attenuation = 0.0;
  38.  
  39. // funkcja rysująca napis w wybranym miejscu
  40. // (wersja korzystająca z funkcji glWindowPos2i)
  41.  
  42. float swiatlo_otoczenia[] = {-0.2f, -0.2f, -0.2f, 1.0f};
  43. float swiatlo_rozproszone[] = {0.5f, 0.5f, 0.5f, 1.0f};
  44. float swiatlo_odbite[] = { 0.9, 0.9, 0.9, 1.0};
  45. float swiatlo_pozycja[] = { 0.0, 0.0, 0.0, 1.0};
  46. const GLfloat * ambient = BrassAmbient;
  47. const GLfloat * diffuse = BrassDiffuse;
  48. const GLfloat * specular = BrassSpecular;
  49. GLfloat shininess = BrassShininess;
  50. static float p_na_orbicie = 0.0f, obrot = 0.0f, autom=0.0f;
  51.  
  52. GLuint _textureId;
  53.  
  54. GLuint _textureId2;
  55.  
  56. GLuint _textureIdmerkury;
  57. GLuint _textureIdvenus;
  58. GLuint _textureIdmars;
  59. GLuint _textureIdjowisz;
  60. GLuint _textureIdsaturn;
  61. GLuint _textureIduran;
  62. GLuint _textureIdneptun;
  63.  
  64. GLuint img;
  65.  
  66. GLUquadricObj *sphere = NULL;
  67.  
  68. GLfloat obrr[16]={1,0,1,0,0,1,0,0,1,0,1,0,0,0,0,1};
  69.  
  70. GLfloat rotatex = 0.0;
  71.  
  72. GLfloat rotatey = 0.0;
  73.  
  74. GLfloat translatex = 0.0;
  75.  
  76. GLfloat translatey = 0.0;
  77.  
  78. int czas=1;
  79.  
  80. int button_state = GLUT_UP;
  81.  
  82.  
  83.  
  84. // położenie kursora myszki
  85.  
  86.  
  87.  
  88. int button_x, button_y;
  89.  
  90. GLfloat skala = 1.0;
  91.  
  92. void obrotY(){
  93.  
  94. obrr[0]=cos(obrot);
  95.  
  96. obrr[2]=-sin(obrot);
  97.  
  98. obrr[8]=sin(obrot);
  99.  
  100. obrr[10]=cos(obrot);
  101.  
  102.  
  103.  
  104. }
  105.  
  106. void initRendering() {
  107.  
  108. glEnable(GL_DEPTH_TEST);
  109.  
  110. // glEnable(GL_LIGHTING);
  111.  
  112. // glEnable(GL_LIGHT0);
  113.  
  114. glShadeModel(GL_SMOOTH);
  115.  
  116. glEnable(GL_COLOR_MATERIAL);
  117.  
  118. glDisable(GL_CULL_FACE);
  119.  
  120. glEnable(GL_TEXTURE_2D);
  121.  
  122.  
  123.  
  124.  
  125.  
  126. //Image* img = loadBMP("sky.bmp");
  127.  
  128. //_textureId = loadTextureFromImage(img);
  129.  
  130. //delete img;
  131.  
  132.  
  133.  
  134. _textureId = SOIL_load_OGL_texture
  135.  
  136. (
  137.  
  138. "test.bmp",
  139.  
  140. SOIL_LOAD_AUTO,
  141.  
  142. SOIL_CREATE_NEW_ID,
  143.  
  144. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  145.  
  146. );
  147.  
  148.  
  149.  
  150. if( 0 == _textureId )
  151.  
  152. {
  153.  
  154. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  155.  
  156. }
  157.  
  158. _textureId2 = SOIL_load_OGL_texture
  159.  
  160. (
  161.  
  162. "test2.bmp",
  163.  
  164. SOIL_LOAD_AUTO,
  165.  
  166. SOIL_CREATE_NEW_ID,
  167.  
  168. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  169.  
  170. );
  171.  
  172.  
  173.  
  174. if( 0 == _textureId2 )
  175.  
  176. {
  177.  
  178. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  179.  
  180. }
  181.  
  182. _textureIdmerkury = SOIL_load_OGL_texture
  183.  
  184. (
  185.  
  186. "merkury1.bmp",
  187.  
  188. SOIL_LOAD_AUTO,
  189.  
  190. SOIL_CREATE_NEW_ID,
  191.  
  192. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  193.  
  194. );
  195.  
  196.  
  197.  
  198. if( 0 == _textureIdmerkury )
  199.  
  200. {
  201.  
  202. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  203.  
  204. }
  205. _textureIdvenus = SOIL_load_OGL_texture
  206.  
  207. (
  208.  
  209. "venus.bmp",
  210.  
  211. SOIL_LOAD_AUTO,
  212.  
  213. SOIL_CREATE_NEW_ID,
  214.  
  215. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  216.  
  217. );
  218.  
  219.  
  220.  
  221. if( 0 == _textureIdvenus )
  222.  
  223. {
  224.  
  225. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  226.  
  227. }
  228.  
  229. _textureIdmars = SOIL_load_OGL_texture
  230.  
  231. (
  232.  
  233. "mars.bmp",
  234.  
  235. SOIL_LOAD_AUTO,
  236.  
  237. SOIL_CREATE_NEW_ID,
  238.  
  239. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  240.  
  241. );
  242.  
  243.  
  244.  
  245. if( 0 == _textureIdjowisz)
  246.  
  247. {
  248.  
  249. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  250.  
  251. }
  252.  
  253. _textureIdmerkury = SOIL_load_OGL_texture
  254.  
  255. (
  256.  
  257. "jowisz.bmp",
  258.  
  259. SOIL_LOAD_AUTO,
  260.  
  261. SOIL_CREATE_NEW_ID,
  262.  
  263. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  264.  
  265. );
  266.  
  267.  
  268.  
  269. if( 0 == _textureIdjowisz)
  270.  
  271. {
  272.  
  273. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  274.  
  275. }
  276.  
  277. _textureIdsaturn = SOIL_load_OGL_texture
  278.  
  279. (
  280.  
  281. "saturn.bmp",
  282.  
  283. SOIL_LOAD_AUTO,
  284.  
  285. SOIL_CREATE_NEW_ID,
  286.  
  287. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  288.  
  289. );
  290.  
  291.  
  292.  
  293. if( 0 == _textureIdsaturn )
  294.  
  295. {
  296.  
  297. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  298.  
  299. }
  300. _textureIduran = SOIL_load_OGL_texture
  301.  
  302. (
  303.  
  304. "uran.bmp",
  305.  
  306. SOIL_LOAD_AUTO,
  307.  
  308. SOIL_CREATE_NEW_ID,
  309.  
  310. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  311.  
  312. );
  313.  
  314.  
  315.  
  316. if( 0 == _textureIduran )
  317.  
  318. {
  319.  
  320. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  321.  
  322. }
  323. _textureIdneptun = SOIL_load_OGL_texture
  324.  
  325. (
  326.  
  327. "neptun.bmp",
  328.  
  329. SOIL_LOAD_AUTO,
  330.  
  331. SOIL_CREATE_NEW_ID,
  332.  
  333. SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
  334.  
  335. );
  336.  
  337.  
  338.  
  339. if( 0 == _textureIdneptun )
  340.  
  341. {
  342.  
  343. printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
  344.  
  345. }
  346.  
  347.  
  348.  
  349.  
  350.  
  351. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  352.  
  353.  
  354.  
  355. sphere = gluNewQuadric();
  356.  
  357. gluQuadricDrawStyle(sphere, GLU_FILL);
  358.  
  359. gluQuadricTexture(sphere, GL_TRUE);
  360.  
  361. gluQuadricNormals(sphere, GLU_SMOOTH);
  362.  
  363.  
  364.  
  365.  
  366. }
  367.  
  368. void handleResize(int w, int h) {
  369.  
  370. glViewport(0, 0, w, h);
  371.  
  372. glMatrixMode(GL_PROJECTION);
  373.  
  374. glLoadIdentity();
  375.  
  376. gluPerspective(45.0, (float)w / (float)h, 1.0, 200.0);
  377.  
  378. }
  379.  
  380.  
  381.  
  382. void rysuj(){ // 1
  383.  
  384. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  385.  
  386. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  387.  
  388. //glClear(GL_COLOR_BUFFER_BIT);
  389. glEnable( GL_DEPTH_TEST );
  390.  
  391. // włączenie oświetlenia
  392. glEnable( GL_LIGHTING );
  393.  
  394. // włączenie światła GL_LIGHT0
  395.  
  396. // włączenie automatycznej normalizacji wektorów normalnych
  397. glEnable( GL_NORMALIZE );
  398. glLightf( GL_LIGHT1, GL_SPOT_CUTOFF, 180 );
  399.  
  400. // wykładnik tłumienia kątowego reflektora
  401. // glLightf( GL_LIGHT1, GL_SPOT_EXPONENT, spot_exponent );
  402.  
  403. // stały współczynnik tłumienia światła,
  404. // glLightf( GL_LIGHT0, GL_CONSTANT_ATTENUATION, constant_attenuation );
  405.  
  406. // liniowy współczynnik tłumienia światła
  407. // glLightf( GL_LIGHT0, GL_LINEAR_ATTENUATION, linear_attenuation );
  408.  
  409. // kwadratowy współczynnik tłumienia światła
  410. // glLightf( GL_LIGHT0, GL_QUADRATIC_ATTENUATION, quadratic_attenuation );
  411.  
  412. glLightfv( GL_LIGHT1, GL_AMBIENT, swiatlo_otoczenia);
  413. glLightfv( GL_LIGHT1, GL_DIFFUSE, swiatlo_rozproszone);
  414. glLightfv( GL_LIGHT1, GL_SPECULAR, swiatlo_odbite);
  415. glLightfv( GL_LIGHT1, GL_POSITION, swiatlo_pozycja);
  416.  
  417. glEnable( GL_LIGHT0 );
  418. glDisable( GL_LIGHT1 );
  419.  
  420.  
  421. glPushMatrix();
  422.  
  423. glBindTexture(GL_TEXTURE_2D, _textureId2);
  424.  
  425.  
  426.  
  427. glMatrixMode(GL_MODELVIEW);
  428.  
  429.  
  430.  
  431. glLoadIdentity();
  432.  
  433.  
  434.  
  435.  
  436.  
  437. glTranslatef( 0, 0, -5); //
  438.  
  439. //glutWireSphere(1.0, 20, 16);
  440.  
  441. glTranslatef( translatex, translatey, 0.0 );
  442.  
  443. glScalef( skala, skala, skala );
  444.  
  445. glRotatef( rotatex, 1.0, 0, 0 );
  446.  
  447. glRotatef( rotatey, 0, 1.0, 0 );
  448.  
  449. gluSphere(sphere, 1.0, 20, 20);
  450. glDisable( GL_LIGHT0 );
  451. //glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  452. glEnable( GL_LIGHT1 );
  453. glBindTexture(GL_TEXTURE_2D, _textureId);
  454.  
  455. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  456.  
  457.  
  458.  
  459.  
  460. glTranslatef (2.4, 0.0, 0.0);
  461.  
  462.  
  463.  
  464. obrotY();
  465.  
  466. glMultMatrixf( obrr );
  467.  
  468. glRotatef ( -90, 1.0, 0.0, 0.0);
  469.  
  470. //obrotY();
  471.  
  472. gluSphere(sphere, 0.2, 15, 15);
  473. glTranslatef (-2.4, 0.0, 0.0);
  474. glPopMatrix() ;
  475. // glutWireSphere(0.2, 10, 8);
  476.  
  477.  
  478. glPushMatrix();
  479.  
  480. glRotatef ( 90, 1.0, 0.0, 0.0);
  481. glTranslatef( translatex, translatey, 0.0 );
  482.  
  483. glScalef( skala, skala, skala );
  484. //glRotatef ( 90, 1.0, 0.0, 0.0);
  485. glRotatef( rotatex, 1.0, 0, 0 );
  486.  
  487. glRotatef( rotatey, 0, 1.0, 0 );
  488.  
  489.  
  490. glBindTexture(GL_TEXTURE_2D, _textureIdmerkury);
  491. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  492. glTranslatef (1.2, 0.0, 0.0);
  493. // //glRotatef ( -90, 1.0, 0.0, 0.0);
  494. obrotY();
  495.  
  496. glMultMatrixf( obrr );
  497. glRotatef ( -90, 1.0, 0.0, 0.0);
  498. gluSphere(sphere, 0.2*0.4, 15, 15);
  499. glTranslatef (-1.2, 0.0, 0.0);
  500. glPopMatrix() ;
  501.  
  502. glPushMatrix();
  503.  
  504. glRotatef ( 90, 1.0, 0.0, 0.0);
  505. glTranslatef( translatex, translatey, 0.0 );
  506.  
  507. glScalef( skala, skala, skala );
  508. //glRotatef ( 90, 1.0, 0.0, 0.0);
  509. glRotatef( rotatex, 1.0, 0, 0 );
  510.  
  511. glRotatef( rotatey, 0, 1.0, 0 );
  512.  
  513.  
  514. glBindTexture(GL_TEXTURE_2D, _textureIdvenus);
  515. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  516. glTranslatef (1.8, 0.0, 0.0);
  517. // //glRotatef ( -90, 1.0, 0.0, 0.0);
  518. obrotY();
  519.  
  520. glMultMatrixf( obrr );
  521. glRotatef ( -90, 1.0, 0.0, 0.0);
  522. gluSphere(sphere, 0.2*0.7, 15, 15);
  523. glTranslatef (-1.8, 0.0, 0.0);
  524. glPopMatrix() ;
  525.  
  526.  
  527. glPushMatrix();
  528.  
  529. glRotatef ( 90, 1.0, 0.0, 0.0);
  530. glTranslatef( translatex, translatey, 0.0 );
  531.  
  532. glScalef( skala, skala, skala );
  533. //glRotatef ( 90, 1.0, 0.0, 0.0);
  534. glRotatef( rotatex, 1.0, 0, 0 );
  535.  
  536. glRotatef( rotatey, 0, 1.0, 0 );
  537.  
  538.  
  539. glBindTexture(GL_TEXTURE_2D, _textureIdmars);
  540. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  541. glTranslatef (2.8, 0.0, 0.0);
  542. // //glRotatef ( -90, 1.0, 0.0, 0.0);
  543. obrotY();
  544.  
  545. glMultMatrixf( obrr );
  546. glRotatef ( -90, 1.0, 0.0, 0.0);
  547. gluSphere(sphere, 0.2*0.5, 15, 15);
  548.  
  549. glTranslatef (-2.8, 0.0, 0.0);
  550. glPopMatrix() ;
  551.  
  552.  
  553. glPushMatrix();
  554.  
  555. glRotatef ( 90, 1.0, 0.0, 0.0);
  556. glTranslatef( translatex, translatey, 0.0 );
  557.  
  558. glScalef( skala, skala, skala );
  559. //glRotatef ( 90, 1.0, 0.0, 0.0);
  560. glRotatef( rotatex, 1.0, 0, 0 );
  561.  
  562. glRotatef( rotatey, 0, 1.0, 0 );
  563.  
  564.  
  565. glBindTexture(GL_TEXTURE_2D, _textureIdjowisz);
  566. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  567. glTranslatef (3.6, 0.0, 0.0);
  568. // //glRotatef ( -90, 1.0, 0.0, 0.0);
  569. obrotY();
  570.  
  571. glMultMatrixf( obrr );
  572. glRotatef ( -90, 1.0, 0.0, 0.0);
  573. gluSphere(sphere, 0.2*2, 15, 15);
  574.  
  575. glTranslatef (-3.6, 0.0, 0.0);
  576. glPopMatrix() ;
  577.  
  578.  
  579. glPushMatrix();
  580.  
  581. glRotatef ( 90, 1.0, 0.0, 0.0);
  582. glTranslatef( translatex, translatey, 0.0 );
  583.  
  584. glScalef( skala, skala, skala );
  585. //glRotatef ( 90, 1.0, 0.0, 0.0);
  586. glRotatef( rotatex, 1.0, 0, 0 );
  587.  
  588. glRotatef( rotatey, 0, 1.0, 0 );
  589.  
  590.  
  591. glBindTexture(GL_TEXTURE_2D, _textureIdsaturn);
  592. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  593. glTranslatef (4.5, 0.0, 0.0);
  594. // //glRotatef ( -90, 1.0, 0.0, 0.0);
  595. obrotY();
  596.  
  597. glMultMatrixf( obrr );
  598. glRotatef ( -90, 1.0, 0.0, 0.0);
  599. gluSphere(sphere, 0.2*1.5, 15, 15);
  600.  
  601. glTranslatef (-4.5, 0.0, 0.0);
  602. glPopMatrix() ;
  603.  
  604.  
  605. glPushMatrix();
  606.  
  607. glRotatef ( 90, 1.0, 0.0, 0.0);
  608. glTranslatef( translatex, translatey, 0.0 );
  609.  
  610. glScalef( skala, skala, skala );
  611. //glRotatef ( 90, 1.0, 0.0, 0.0);
  612. glRotatef( rotatex, 1.0, 0, 0 );
  613.  
  614. glRotatef( rotatey, 0, 1.0, 0 );
  615.  
  616.  
  617. glBindTexture(GL_TEXTURE_2D, _textureIduran);
  618. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  619. glTranslatef (5.3, 0.0, 0.0);
  620. // //glRotatef ( -90, 1.0, 0.0, 0.0);
  621. obrotY();
  622.  
  623. glMultMatrixf( obrr );
  624. glRotatef ( -90, 1.0, 0.0, 0.0);
  625. gluSphere(sphere, 0.2*1.3, 15, 15);
  626.  
  627. glTranslatef (-5.3, 0.0, 0.0);
  628. glPopMatrix() ;
  629.  
  630.  
  631. glPushMatrix();
  632.  
  633. glRotatef ( 90, 1.0, 0.0, 0.0);
  634. glTranslatef( translatex, translatey, 0.0 );
  635.  
  636. glScalef( skala, skala, skala );
  637. //glRotatef ( 90, 1.0, 0.0, 0.0);
  638. glRotatef( rotatex, 1.0, 0, 0 );
  639.  
  640. glRotatef( rotatey, 0, 1.0, 0 );
  641.  
  642.  
  643. glBindTexture(GL_TEXTURE_2D, _textureIdneptun);
  644. glRotatef (p_na_orbicie, 0.0, 1.0, 0.0);
  645. glTranslatef (6.0, 0.0, 0.0);
  646. // //glRotatef ( -90, 1.0, 0.0, 0.0);
  647. obrotY();
  648.  
  649. glMultMatrixf( obrr );
  650. glRotatef ( -90, 1.0, 0.0, 0.0);
  651. gluSphere(sphere, 0.2*1.2, 15, 15);
  652.  
  653. glPopMatrix() ;
  654.  
  655.  
  656.  
  657.  
  658. glutPostRedisplay();
  659.  
  660. glutSwapBuffers();
  661.  
  662. }
  663.  
  664. void keyboard (unsigned char key, int x, int y)
  665.  
  666. {
  667.  
  668. switch (key) {
  669.  
  670. case 'd':
  671.  
  672. if(obrot>350.0) obrot=0.0f;
  673.  
  674. obrot = obrot + 10.0f;
  675.  
  676. glutPostRedisplay();
  677.  
  678. break;
  679.  
  680. case 'D':
  681.  
  682. if(obrot<10.0) obrot=360.0f;
  683.  
  684. obrot = obrot - 10.0 ;
  685.  
  686. glutPostRedisplay();
  687.  
  688. break;
  689.  
  690. case 's':
  691.  
  692. if(p_na_orbicie>350.0) p_na_orbicie=0.0f;
  693.  
  694. p_na_orbicie = p_na_orbicie + 5.0;
  695.  
  696. glutPostRedisplay();
  697.  
  698. break;
  699.  
  700. case 'S':
  701.  
  702. if(p_na_orbicie<10.0) p_na_orbicie=360.0f;
  703.  
  704. p_na_orbicie = p_na_orbicie - 5.0 ;
  705.  
  706. glutPostRedisplay();
  707.  
  708. break;
  709.  
  710. case 'a':
  711.  
  712. if(autom){
  713.  
  714. autom=0;
  715.  
  716. }else{
  717.  
  718. autom=1;
  719.  
  720. }
  721.  
  722. break;
  723.  
  724. case '+':
  725.  
  726. skala+=0.1;
  727.  
  728. break;
  729.  
  730. case '-':
  731.  
  732. if(skala>0.1)
  733.  
  734. skala-=0.1;
  735.  
  736. break;
  737.  
  738. case 27:
  739.  
  740. exit(0);
  741.  
  742. break;
  743.  
  744. default:
  745.  
  746. break;
  747.  
  748. }
  749.  
  750. }
  751.  
  752. void SpecialKeys( int key, int x, int y )
  753.  
  754. {
  755.  
  756. switch( key )
  757.  
  758. {
  759.  
  760. // kursor w lewo
  761.  
  762. case GLUT_KEY_LEFT:
  763.  
  764. rotatey -= 1;
  765.  
  766. break;
  767.  
  768.  
  769.  
  770. // kursor w górę
  771.  
  772. case GLUT_KEY_UP:
  773.  
  774. rotatex -= 1;
  775.  
  776. break;
  777.  
  778.  
  779.  
  780. // kursor w prawo
  781.  
  782. case GLUT_KEY_RIGHT:
  783.  
  784. rotatey += 1;
  785.  
  786. break;
  787.  
  788.  
  789.  
  790. // kursor w dół
  791.  
  792. case GLUT_KEY_DOWN:
  793.  
  794. rotatex += 1;
  795.  
  796. break;
  797.  
  798. }
  799.  
  800. }
  801.  
  802. void MouseButton( int button, int state, int x, int y )
  803.  
  804. {
  805.  
  806. if( button == GLUT_LEFT_BUTTON )
  807.  
  808. {
  809.  
  810. // zapamiętanie stanu lewego przycisku myszki
  811.  
  812. button_state = state;
  813.  
  814.  
  815.  
  816. // zapamiętanie położenia kursora myszki
  817.  
  818. if( state == GLUT_DOWN )
  819.  
  820. {
  821.  
  822. button_x = x;
  823.  
  824. button_y = y;
  825.  
  826. }
  827.  
  828. }
  829.  
  830. }
  831.  
  832. // odrysowanie okna
  833.  
  834. // Reshape( glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ) );
  835.  
  836.  
  837.  
  838. void MouseMotion( int x, int y )
  839.  
  840. {
  841.  
  842. if( button_state == GLUT_DOWN )
  843.  
  844. {
  845.  
  846. translatex += 1.1 *( 5 ) / glutGet( GLUT_WINDOW_WIDTH ) *( x - button_x );
  847. swiatlo_pozycja[0]+=1.1 *( 5 ) / glutGet( GLUT_WINDOW_WIDTH ) *( x - button_x );
  848. button_x = x;
  849.  
  850. translatey += 1.1 *( 5 ) / glutGet( GLUT_WINDOW_HEIGHT ) *( button_y - y );
  851. swiatlo_pozycja[1]+= 1.1 *( 5 ) / glutGet( GLUT_WINDOW_HEIGHT ) *( button_y - y );
  852. button_y = y;
  853.  
  854. glutPostRedisplay();
  855.  
  856. }
  857.  
  858. }
  859.  
  860.  
  861.  
  862. void obracanie(int value) {
  863.  
  864. if(autom){
  865.  
  866. p_na_orbicie+=0.1f;
  867.  
  868. obrot+=0.1f;
  869.  
  870. }
  871.  
  872. if(p_na_orbicie>=360.0) p_na_orbicie-=360.0;
  873.  
  874. if(obrot>=360.0) obrot-=360.0;
  875.  
  876. glutPostRedisplay();
  877.  
  878. glutTimerFunc(50, obracanie, 0);
  879.  
  880. }
  881.  
  882.  
  883.  
  884. int main(int argc, char **argv)
  885.  
  886. {
  887.  
  888. glutInit(&argc,argv);
  889.  
  890. glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
  891.  
  892. glutInitWindowSize (1000, 500);
  893.  
  894. glutCreateWindow("Hello World");
  895.  
  896. initRendering();
  897.  
  898. glutDisplayFunc(rysuj);
  899.  
  900. glutReshapeFunc(handleResize);
  901.  
  902. glutKeyboardFunc(keyboard);
  903.  
  904. glutSpecialFunc( SpecialKeys );
  905.  
  906. glutMouseFunc( MouseButton );
  907.  
  908.  
  909.  
  910. // obsługa ruchu kursora myszki
  911.  
  912. glutMotionFunc( MouseMotion );
  913.  
  914. glutTimerFunc(50, obracanie, 0);
  915.  
  916. glutMainLoop();
  917.  
  918. return 0;
  919.  
  920. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement