objfile.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * OBJ File header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_OBJFILE_H
  10. #define DORAYME_OBJFILE_H
  11. #include <stdint.h>
  12. #include <tuple.h>
  13. #include <shape.h>
  14. #include <group.h>
  15. #include <renderstat.h>
  16. class OBJFile : public Shape
  17. {
  18. private:
  19. uint32_t allocatedFaceGroupCount;
  20. Group* *faceGroupList;
  21. uint32_t faceGroupCount;
  22. uint32_t allocatedVertexCount;
  23. Point* *vertexList;
  24. uint32_t vertexCount;
  25. uint32_t allocatedVertexNormalCount;
  26. Vector* *vertexNormalList;
  27. uint32_t vertexNormalCount;
  28. private:
  29. Intersect localIntersect(Ray r);
  30. Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);
  31. public:
  32. /* Some stats */
  33. uint32_t ignoredLines;
  34. protected:
  35. void addGroup(Group *group);
  36. void addVertex(Point *vertex);
  37. void addVertexNormal(Vector *vertexNormal);
  38. void parseLine(char *line, uint32_t currentLine);
  39. int execLine(int argc, char *argv[], uint32_t currentLine);
  40. BoundingBox bounds;
  41. public:
  42. OBJFile();
  43. OBJFile(const char *filepath);
  44. int parseOBJFile(const char *content);
  45. /* OBJ file expect the first vertice to be 1 and not 0 */
  46. Point vertices(uint32_t i) { return *this->vertexList[i - 1]; };
  47. Vector verticesNormal(uint32_t i) { return *this->vertexNormalList[i - 1]; };
  48. Group *groups(uint32_t i) { return this->faceGroupList[i]; };
  49. Intersect intersect(Ray r);
  50. BoundingBox getLocalBounds();
  51. BoundingBox getBounds();
  52. void updateBoundingBox();
  53. void updateTransform();
  54. void dumpMe(FILE * fp);
  55. };
  56. #endif /* DORAYME_OBJFILE_H */