From 314da11005710e558db54431af09628787289464 Mon Sep 17 00:00:00 2001 From: Godzil Date: Mon, 9 Mar 2020 15:58:32 +0000 Subject: [PATCH] Add support for naming groups --- source/include/group.h | 2 ++ source/shapes/group.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/source/include/group.h b/source/include/group.h index 74d8705..65bc4a6 100644 --- a/source/include/group.h +++ b/source/include/group.h @@ -25,6 +25,8 @@ private: Shape* *unboxableObjectList; uint32_t unboxableObjectCount; + char name[32 + 1]; + protected: Intersect localIntersect(Ray r); Tuple localNormalAt(Tuple point, Intersection *hit = nullptr); diff --git a/source/shapes/group.cpp b/source/shapes/group.cpp index 1e5cf23..f3d7308 100644 --- a/source/shapes/group.cpp +++ b/source/shapes/group.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #define MIN_ALLOC (2) @@ -25,6 +26,14 @@ Group::Group(const char *name) : Shape(Shape::GROUP) this->unboxableObjectList = (Shape **)calloc(sizeof(Shape **), MIN_ALLOC); this->unboxableObjectCount = 0; + if (name != nullptr) + { + strncpy(this->name, name, 32); + } + else + { + strncpy(this->name, "untitled", 32); + } } Intersect Group::intersect(Ray r) @@ -204,6 +213,7 @@ void Group::dumpMe(FILE *fp) { int i; fprintf(fp, "\"Type\": \"Group\",\n"); + fprintf(fp, "\"Name\": \"%s\",\n", this->name); if (this->objectCount > 0) { fprintf(fp, "\"Objects\": {\n");