szene mit vier roten kugeln aufgebaut. der renderer unterstuetzt jetzt bis zu 100 objekte
This commit is contained in:
+28
-10
@@ -1,18 +1,36 @@
|
||||
#include <stdlib.h>
|
||||
#include "structs.h"
|
||||
#include "collision.h"
|
||||
#include "vectorOp.h"
|
||||
#define MAXSPHERES 100
|
||||
|
||||
RGBA raytraceSphere(sphere *obj, ray *lightray) {
|
||||
RGBA pixel;
|
||||
pixel.r = 0;
|
||||
pixel.g = 0;
|
||||
pixel.b = 0;
|
||||
pixel.a = 1;
|
||||
RGBA raytraceSphere(sphere **objectList, ray *lightray) {
|
||||
RGBA pixel = (RGBA){0,0,0,1};
|
||||
const int lightBounces = 1;
|
||||
sphere **spheresHitList = (sphere **)calloc( (lightBounces + 1),sizeof(sphere*) );
|
||||
|
||||
vec3 collisionPoint = collisionPointSphere(lightray, obj);
|
||||
if (collisionPoint.x == -1) {return pixel;}
|
||||
vec3 sphereNormal = vec3Normalize(vec3Subtract(collisionPoint, obj->origin));
|
||||
pixel.r = -vec3Product(sphereNormal, lightray->direction);
|
||||
sphere *nearestSphere = nullptr;
|
||||
vec3 nearestCollisionPoint = {10000,10000,10000};
|
||||
for (int i = 0; i < 100 && objectList[i] != nullptr; i++) {
|
||||
vec3 collisionPoint = collisionPointSphere(lightray, objectList[i]);
|
||||
if (collisionPoint.x == -10000000) {
|
||||
|
||||
}
|
||||
else{
|
||||
if (vec3Length(collisionPoint)< vec3Length(nearestCollisionPoint)) {
|
||||
nearestCollisionPoint = collisionPoint;
|
||||
nearestSphere = objectList[i];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (nearestSphere != nullptr) {
|
||||
vec3 sphereNormal = vec3Normalize(vec3Subtract(nearestCollisionPoint, nearestSphere->origin));
|
||||
pixel.r = -vec3Product(sphereNormal, lightray->direction);
|
||||
}
|
||||
|
||||
|
||||
free(spheresHitList);
|
||||
return pixel;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user