objfile.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. private:
  26. Intersect localIntersect(Ray r);
  27. Tuple localNormalAt(Tuple point);
  28. public:
  29. /* Some stats */
  30. uint32_t ignoredLines;
  31. protected:
  32. void addGroup(Group *group);
  33. void addVertex(Point *vertex);
  34. void parseLine(char *line, uint32_t currentLine);
  35. int execLine(int argc, char *argv[], uint32_t currentLine);
  36. BoundingBox bounds;
  37. public:
  38. OBJFile();
  39. OBJFile(const char *filepath);
  40. int parseOBJFile(const char *content);
  41. /* OBJ file expect the first vertice to be 1 and not 0 */
  42. Point vertices(uint32_t i) { return *this->vertexList[i - 1]; };
  43. Group *groups(uint32_t i) { return this->faceGroupList[i]; };
  44. Intersect intersect(Ray r);
  45. BoundingBox getLocalBounds();
  46. BoundingBox getBounds();
  47. void updateBoundingBox();
  48. void updateTransform();
  49. void dumpMe(FILE * fp);
  50. };
  51. #endif /* DORAYME_OBJFILE_H */