COSC-3P93-Project/Step 2/src/world.cpp

25 lines
743 B
C++
Raw Normal View History

2022-10-16 19:24:37 -04:00
/*
* Created by Brett Terpstra 6920201 on 16/10/22.
* Copyright (c) 2022 Brett Terpstra. All Rights Reserved.
*/
#include <world.h>
namespace Raytracing {
World::~World() {
for (auto* p : objects)
delete(p);
}
Object::HitData World::checkIfHit(const Ray& ray, PRECISION_TYPE min, PRECISION_TYPE max) const {
auto hResult = Object::HitData{false, vec4(), vec4(), max};
for (auto* obj : objects){
// check up to the point of the last closest hit,
// will give the closest object's hit result
auto cResult = obj->checkIfHit(ray, min, hResult.length);
if (cResult.hit)
hResult = cResult;
}
return hResult;
}
}