Advertisement
Guest User

Untitled

a guest
May 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. void rayTracer(List *objectList, Light *lightList, Plane observer, Point imageOrigin, int resolution, double tetaX, double tetaY, tetaZ){
  2. BMP *imageFile;
  3. imageFile = newBMP(resolution, resolution);
  4. char* imageFileName = "bitmapImage.bmp";
  5.  
  6. Rgb white;
  7. white.red = 255;
  8. white.green = 255;
  9. white.blue = 255;
  10.  
  11. Rgb black;
  12. black.red = 0;
  13. black.green = 0;
  14. black.blue = 0;
  15.  
  16. Line firstRay;
  17. firstRay = calculateFirstRay(observer,imageOrigin);
  18. Line tmpLine = firstRay;
  19. Line rotatedLine;
  20.  
  21. double x, y;
  22.  
  23. Point rayOrigin;
  24. Point nearestPoint;
  25. Point *contactPoint;
  26. contactPoint = (Point*)malloc(objectList->nbElement * sizeof(Point));
  27.  
  28. Element *currentElement = objectList->head;
  29.  
  30. for (int i = 0; i < resolution * resolution; i++){
  31. /* tmpLine.pt.x += x * vectorA.x;
  32. tmpLine.pt.y += x * vectorA.y;
  33. tmpLine.pt.z += x * vectorA.z;
  34. tmpLine.pt.x += y * vectorB.x;
  35. tmpLine.pt.y += y * vectorB.y;
  36. tmpLine.pt.z += y * vectorB.z;
  37. */
  38.  
  39. x = i % (resolution);
  40. y = (i - x)/resolution;
  41.  
  42. tmpLine.pt.x += x;
  43. tmpLine.pt.y -= y;
  44.  
  45. Vector V;
  46. V.x = tmpLine.pt.x;
  47. V.y = tmpLine.pt.y;
  48. V.z = tmpLine.pt.z;
  49.  
  50. Vector rotatedV = matriceRotation(V, tetaX, tetaY, tetaZ);
  51.  
  52. rotatedLine = tmpLine;
  53. rotatedLine.pt.x = rotatedV.x;
  54. rotatedLine.pt.y = rotatedV.y;
  55. rotatedLine.pt.z = rotatedV.z;
  56.  
  57. rotatedLine.directionVector = matriceRotation(tmpLine.directionVector, tetaX, tetaY, tetaZ);
  58.  
  59. currentElement = objectList->head;
  60. for(int j = 0; j < objectList->nbElement; j++){
  61. switch (currentElement->type) {
  62. case BRICK_TYPE :
  63. contactPoint[j] = contactBrickWithLine(decodeBrick(currentElement->object), rotatedLine);
  64. break;
  65. case ELLIPSE_TYPE :
  66. contactPoint[j] = contactEllipseWithLine(decodeEllipse(currentElement->object), rotatedLine);
  67. break;
  68. case TETRAHEDRON_TYPE :
  69. contactPoint[j] = contactTetrahedronWithLine(decodeTetrahedron(currentElement->object), rotatedLine);
  70. break;
  71. }
  72.  
  73. if(currentElement->next != NULL) {
  74. currentElement = currentElement->next;
  75. }
  76. }
  77.  
  78. tmpLine = firstRay;
  79.  
  80. nearestPoint = contactPoint[0];
  81. for(int k = 0; k < objectList->nbElement; k++){
  82. if (!isPointNaN(contactPoint[k])){
  83. if ( norm(pointsToVector(tmpLine.pt, contactPoint[k])) < norm(pointsToVector(tmpLine.pt, nearestPoint)) ){
  84. nearestPoint = contactPoint[k];
  85. }
  86. if (isPointNaN(nearestPoint)){
  87. nearestPoint = contactPoint[k];
  88. }
  89. }
  90. }
  91. if( isPointNaN(nearestPoint)) {
  92. BMPSetColor(imageFile , x, y, black);
  93. }
  94. else{
  95. // if(isLit(nearestPoint, objectList, lightList, 1)){
  96. // TODO: Votre isLit
  97. BMPSetColor(imageFile, x, y, white);
  98. // }
  99. }
  100.  
  101. }
  102. exportBMPImageToFile(imageFile, imageFileName);
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement