szene mit vier roten kugeln aufgebaut. der renderer unterstuetzt jetzt bis zu 100 objekte
This commit is contained in:
+13
-4
@@ -36,8 +36,16 @@ void exampleSphere( int width, int height, int channels, unsigned char *image) {
|
||||
cam1.width = 1.920;
|
||||
cam1.height = 1.080;
|
||||
vec3 sphereOrigin = (vec3){0,0,5};
|
||||
double sphereRadius = 2.0;
|
||||
sphere obj = (sphere){sphereOrigin, sphereRadius};
|
||||
double sphereRadius = 1.0;
|
||||
sphere obj1 = (sphere){sphereOrigin, sphereRadius};
|
||||
sphere **objectList = (sphere **) calloc(4+1, sizeof(sphere*));;
|
||||
objectList[0] = &obj1;
|
||||
sphere obj2 = (sphere){vec3Add(sphereOrigin, (vec3){3,0,0}), sphereRadius};
|
||||
objectList[1] = &obj2;
|
||||
sphere obj3 = (sphere){vec3Add(sphereOrigin, (vec3){-3,0,0}), sphereRadius};
|
||||
objectList[2] = &obj3;
|
||||
sphere obj4 = (sphere){vec3Add(sphereOrigin, (vec3){1,1,3}), sphereRadius};
|
||||
objectList[3] = &obj4;
|
||||
|
||||
vec3 worldUp = (vec3){0, 1, 0};
|
||||
vec3 screenX = vec3Cross(worldUp, cam1.direction);
|
||||
@@ -45,7 +53,7 @@ void exampleSphere( int width, int height, int channels, unsigned char *image) {
|
||||
vec3 screenMiddlePoint = vec3Add(cam1.origin, vec3Scale(cam1.direction, cam1.screenDistance));
|
||||
vec3 screenTopLeft = vec3Add(
|
||||
vec3Add(screenMiddlePoint,
|
||||
vec3Scale(screenY, -cam1.height/2.0)),
|
||||
vec3Scale(screenY, -cam1.height/2.0)),///////////////////////////////////////////////////////////////////////////////////////////////////////////////aendern minus weg
|
||||
vec3Scale(screenX, -cam1.width/2.0)
|
||||
);
|
||||
double pixelStepX = cam1.width / cam1.resolutionX;
|
||||
@@ -71,7 +79,7 @@ void exampleSphere( int width, int height, int channels, unsigned char *image) {
|
||||
|
||||
lightRay->direction = vec3Normalize(vec3Subtract(*pixelOrigin, cam1.origin));
|
||||
|
||||
pixelColor = raytraceSphere(&obj, lightRay);
|
||||
pixelColor = raytraceSphere(objectList, lightRay);
|
||||
free(pixelOrigin);
|
||||
free(lightRay);
|
||||
|
||||
@@ -82,4 +90,5 @@ void exampleSphere( int width, int height, int channels, unsigned char *image) {
|
||||
image[step+3] = 255;
|
||||
}
|
||||
}
|
||||
free(objectList);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user