scene.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "scene.h"
  2. #include "objParser.h"
  3. Scene::Scene(std::string path){
  4. emptyScene = loadSceneModels(path);
  5. }
  6. Scene::~Scene(){
  7. //Making sure you don't attempt to delete models that don't exist
  8. if (!emptyScene){
  9. for(Model *models : modelsInScene){
  10. delete models;
  11. }
  12. }
  13. }
  14. void Scene::update(){
  15. mainCamera.update();
  16. for(Model *models : modelsInScene){
  17. models->update();
  18. }
  19. frustrumCulling();
  20. }
  21. bool Scene::loadSceneModels(std::string &path){
  22. //In the future I want to read all o the models in the model folder
  23. //And build them here. For now only one is loaded.
  24. std::string fullPath = "../models/";
  25. fullPath = fullPath + path;
  26. if(!OBJ::fileExists(fullPath)){
  27. printf("Error! File:%s does not exist.\n",path.c_str());
  28. return true;
  29. }
  30. else{
  31. TransformParameters initParameters;
  32. //initParameters.rotation = Vector3f(90*M_PI/180.0f, 0 , 0);
  33. initParameters.translation = Vector3f(0, 0, 0);
  34. modelsInScene.push_back(new Model(fullPath, initParameters));
  35. return false;
  36. }
  37. }
  38. void Scene::frustrumCulling(){
  39. bool visible = true;
  40. for(Model *model : modelsInScene){
  41. visible = mainCamera.checkVisibility(model->getBounds());
  42. if (visible) {
  43. visibleModels.push(model);
  44. }
  45. }
  46. }
  47. std::queue<Model*>* Scene::getVisiblemodels(){
  48. return &visibleModels;
  49. }
  50. Camera* Scene::getCurrentCamera(){
  51. return &mainCamera;
  52. }
  53. bool Scene::checkIfEmpty(){
  54. return emptyScene;
  55. }