Guest User

Untitled

a guest
Apr 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. //srand ( time(NULL) );
  2.  
  3. //---init virtual camera---
  4. //point eye = {10.0f,400.0f,1000.0f};
  5. //point eye = {0.0f,2.0f,-20.0f};
  6. eye.x = 0.0f;
  7. eye.y = 2.0f;
  8. eye.z = -20.0f;
  9.  
  10. //point lookat = {0.5f,0.0f,0.0f};
  11. lookat.x = 0.5f;
  12. lookat.y = 0.0f;
  13. lookat.z = 0.0f;
  14.  
  15. initCamera(&c,eye,lookat,WID,HEI);
  16. setupCamera(&c);
  17.  
  18. //---malloc the image frame---
  19. image = (uchar *) malloc(c.view.width * c.view.height * 3 * sizeof(uchar));
  20. if(image == NULL)
  21. {
  22. fprintf(stderr,"Error. Cannot malloc image frame.n");
  23. return 0;
  24. }
  25.  
  26. //---just init the image frame with some data---
  27. initImage(&c,image);
  28.  
  29. //---insert random N_SPHERES into the 'data' array
  30. //generateRandomSpheres();
  31. generateScene();
  32.  
  33. //---insert random N_LIGHTS into the 'lights' array
  34. generateRandomLightSources();
  35.  
  36. //---create a 1D array with primary rays coordinates
  37. //rays = generatePrimaryRays(&c);
  38.  
  39. for(i=0; i<NRAN; i++) urand[i].x = (double)rand() / RAND_MAX - 0.5;
  40. for(i=0; i<NRAN; i++) urand[i].y = (double)rand() / RAND_MAX - 0.5;
  41. for(i=0; i<NRAN; i++) irand[i] = (int)(NRAN * ((double)rand() / RAND_MAX));
  42.  
  43. //---ray tracing loop---
  44.  
  45. samples = 8;
  46. s = 0;
  47. rcp_samples = 1.0 / (float)samples;
  48.  
  49. for(i = 0 ; i < c.view.width ; i++)
  50. {
  51. for(j = 0 ; j < c.view.height ; j++)
  52. {
  53. float r, g, b;
  54. r = g = b = 0.0;
  55.  
  56. for(s=0; s<samples; s++) {
  57. ray rr = get_primary_ray(&c,i,j,s);
  58. color col = trace(c,&rr,0);
  59. r += col.r;
  60. g += col.g;
  61. b += col.b;
  62. }
  63.  
  64. r = r * rcp_samples;
  65. g = g * rcp_samples;
  66. b = b * rcp_samples;
  67.  
  68. //ray rr = get_primary_ray(&c, i, j, samples);
  69. //color clr = trace(c,&rr,0);
  70.  
  71. //red green blue color components
  72. image[ 3* (i * c.view.height + j) + 0] = floatToIntColor(r);
  73. image[ 3* (i * c.view.height + j) + 1] = floatToIntColor(g);
  74. image[ 3* (i * c.view.height + j) + 2] = floatToIntColor(b);
  75. }
  76. }
  77.  
  78. //printPrimaryRays(rays,c.view.width*c.view.height); //for testing only
  79.  
  80. if(save_bmp("output_rt.bmp",&c,image) != 0)
  81. {
  82. fprintf(stderr,"Cannot write image 'output.bmp'.n");
  83. return 0;
  84. }
Add Comment
Please, Sign In to add comment