mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-28 11:08:36 +02:00
+ Parsing object system
This commit is contained in:
@ -22,40 +22,71 @@ Scene::~Scene()
|
||||
delete (_camera);
|
||||
}
|
||||
|
||||
Camera *Scene::getCamera(void) const
|
||||
bool Scene::parseScene(char *name)
|
||||
{
|
||||
return (_camera);
|
||||
std::ifstream file(name);
|
||||
std::string line;
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
std::cout << "Error opening the file" << std::endl;
|
||||
file.close();
|
||||
return (false);
|
||||
}
|
||||
|
||||
SceneParser scene_parser(this);
|
||||
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (!scene_parser.parseLine(line))
|
||||
{
|
||||
std::cerr << line << std::endl;
|
||||
file.close();
|
||||
return (false);
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
void Scene::addObject(Object *object)
|
||||
{
|
||||
_objects.push_back(object);
|
||||
|
||||
this->updateGPUData();
|
||||
}
|
||||
|
||||
void Scene::updateGPUData()
|
||||
{
|
||||
_gpuObjects.clear();
|
||||
|
||||
_gpu_objects.clear();
|
||||
for (const auto& obj : _objects)
|
||||
{
|
||||
GPUObject gpuObj;
|
||||
gpuObj.position = obj->getPosition();
|
||||
gpuObj.color = obj->getMaterial()->color;
|
||||
gpuObj.roughness = obj->getMaterial()->roughness;
|
||||
gpuObj.specular = obj->getMaterial()->specular;
|
||||
gpuObj.type = static_cast<int>(obj->getType());
|
||||
GPUObject gpu_obj;
|
||||
gpu_obj.position = obj->getPosition();
|
||||
gpu_obj.color = obj->getMaterial()->color;
|
||||
gpu_obj.roughness = obj->getMaterial()->roughness;
|
||||
gpu_obj.specular = obj->getMaterial()->specular;
|
||||
gpu_obj.type = static_cast<int>(obj->getType());
|
||||
|
||||
if (obj->getType() == Object::Type::SPHERE) {
|
||||
if (obj->getType() == Object::Type::SPHERE)
|
||||
{
|
||||
auto sphere = static_cast<const Sphere*>(obj);
|
||||
gpuObj.radius = sphere->getRadius();
|
||||
gpu_obj.radius = sphere->getRadius();
|
||||
}
|
||||
|
||||
_gpuObjects.push_back(gpuObj);
|
||||
std::cout << gpu_obj.position.x << " " << gpu_obj.position.y << " " << gpu_obj.position.z << " " << gpu_obj.radius << " " << gpu_obj.roughness << " " << gpu_obj.specular << std::endl;
|
||||
|
||||
_gpu_objects.push_back(gpu_obj);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<GPUObject>& Scene::getGPUData() const
|
||||
{
|
||||
return (_gpuObjects);
|
||||
return (_gpu_objects);
|
||||
}
|
||||
|
||||
Camera *Scene::getCamera(void) const
|
||||
{
|
||||
return (_camera);
|
||||
}
|
Reference in New Issue
Block a user