Files
CPU-Raytracer/examples.c
T

59 lines
1.8 KiB
C

//
// Created by ary on 19.07.2026.
//
#include "examples.h"
#include "structs.h"
#include "vectorOp.h"
#include "raytrace.h"
#include <stdlib.h>
#include "interface.h"
void example_color(int width, int height, int channels, unsigned char **image) {
for (int i = 0; i < height * width; i++) {
int step = i *channels;
int x = i % width;
int y = i / width;
(*image)[step] = 0 + (int)((((double)x)/width) * 255);
(*image)[step+1] = 0 + (int)((((double)y)/width) * 255);
(*image)[step+2] = 0;
if (channels == 4) {
(*image)[step+3] = 255;
}
}
}
void exampleSphere( int width, int height, int channels, unsigned char **image) {
camera cam1;
cam1.origin.x = 0;
cam1.origin.y = 0;
cam1.origin.z = 0;
cam1.direction.x = 0;
cam1.direction.y = 0;
cam1.direction.z = 1;
cam1.resolutionX = width;
cam1.resolutionY = height;
cam1.screenDistance = 1;
cam1.width = 1.920;
cam1.height = 1.080;
vec3 sphereOrigin = (vec3){0,0,5};
double sphereRadius = 1.0;
sphere obj1 = (sphere){sphereOrigin, sphereRadius,(RGBA){1,0.5,1,1},0};
sphere **objectList = (sphere **) calloc(5+1, sizeof(sphere*));;
objectList[0] = &obj1;
sphere obj2 = (sphere){vec3Add(sphereOrigin, (vec3){3,0,0}), sphereRadius, (RGBA){1,1,0.5,1},0};
objectList[1] = &obj2;
sphere obj3 = (sphere){vec3Add(sphereOrigin, (vec3){-2,1,0}), sphereRadius, (RGBA){1,1,1,1},0};
objectList[2] = &obj3;
sphere obj4 = (sphere){vec3Add(sphereOrigin, (vec3){1,1,3}), sphereRadius, (RGBA){0.5,1,1,1},0};
objectList[3] = &obj4;
sphere light1 = (sphere){(vec3){2,1,0}, sphereRadius, (RGBA){1,1,1,1},1};
objectList[4] = &light1;
int objectCount = 5;
displaySzene(objectList, objectCount, cam1, width, height, channels, image);
free(objectList);
}