Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void rayTracer(List *objectList, Light *lightList, Plane observer, Point imageOrigin, int resolution, double tetaX, double tetaY, tetaZ){
- BMP *imageFile;
- imageFile = newBMP(resolution, resolution);
- char* imageFileName = "bitmapImage.bmp";
- Rgb white;
- white.red = 255;
- white.green = 255;
- white.blue = 255;
- Rgb black;
- black.red = 0;
- black.green = 0;
- black.blue = 0;
- Line firstRay;
- firstRay = calculateFirstRay(observer,imageOrigin);
- Line tmpLine = firstRay;
- Line rotatedLine;
- double x, y;
- Point rayOrigin;
- Point nearestPoint;
- Point *contactPoint;
- contactPoint = (Point*)malloc(objectList->nbElement * sizeof(Point));
- Element *currentElement = objectList->head;
- for (int i = 0; i < resolution * resolution; i++){
- /* tmpLine.pt.x += x * vectorA.x;
- tmpLine.pt.y += x * vectorA.y;
- tmpLine.pt.z += x * vectorA.z;
- tmpLine.pt.x += y * vectorB.x;
- tmpLine.pt.y += y * vectorB.y;
- tmpLine.pt.z += y * vectorB.z;
- */
- x = i % (resolution);
- y = (i - x)/resolution;
- tmpLine.pt.x += x;
- tmpLine.pt.y -= y;
- Vector V;
- V.x = tmpLine.pt.x;
- V.y = tmpLine.pt.y;
- V.z = tmpLine.pt.z;
- Vector rotatedV = matriceRotation(V, tetaX, tetaY, tetaZ);
- rotatedLine = tmpLine;
- rotatedLine.pt.x = rotatedV.x;
- rotatedLine.pt.y = rotatedV.y;
- rotatedLine.pt.z = rotatedV.z;
- rotatedLine.directionVector = matriceRotation(tmpLine.directionVector, tetaX, tetaY, tetaZ);
- currentElement = objectList->head;
- for(int j = 0; j < objectList->nbElement; j++){
- switch (currentElement->type) {
- case BRICK_TYPE :
- contactPoint[j] = contactBrickWithLine(decodeBrick(currentElement->object), rotatedLine);
- break;
- case ELLIPSE_TYPE :
- contactPoint[j] = contactEllipseWithLine(decodeEllipse(currentElement->object), rotatedLine);
- break;
- case TETRAHEDRON_TYPE :
- contactPoint[j] = contactTetrahedronWithLine(decodeTetrahedron(currentElement->object), rotatedLine);
- break;
- }
- if(currentElement->next != NULL) {
- currentElement = currentElement->next;
- }
- }
- tmpLine = firstRay;
- nearestPoint = contactPoint[0];
- for(int k = 0; k < objectList->nbElement; k++){
- if (!isPointNaN(contactPoint[k])){
- if ( norm(pointsToVector(tmpLine.pt, contactPoint[k])) < norm(pointsToVector(tmpLine.pt, nearestPoint)) ){
- nearestPoint = contactPoint[k];
- }
- if (isPointNaN(nearestPoint)){
- nearestPoint = contactPoint[k];
- }
- }
- }
- if( isPointNaN(nearestPoint)) {
- BMPSetColor(imageFile , x, y, black);
- }
- else{
- // if(isLit(nearestPoint, objectList, lightList, 1)){
- // TODO: Votre isLit
- BMPSetColor(imageFile, x, y, white);
- // }
- }
- }
- exportBMPImageToFile(imageFile, imageFileName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement