Add support for naming groups

This commit is contained in:
Godzil
2020-03-09 15:58:32 +00:00
parent 8437ab8753
commit 314da11005
2 changed files with 12 additions and 0 deletions

View File

@@ -25,6 +25,8 @@ private:
Shape* *unboxableObjectList; Shape* *unboxableObjectList;
uint32_t unboxableObjectCount; uint32_t unboxableObjectCount;
char name[32 + 1];
protected: protected:
Intersect localIntersect(Ray r); Intersect localIntersect(Ray r);
Tuple localNormalAt(Tuple point, Intersection *hit = nullptr); Tuple localNormalAt(Tuple point, Intersection *hit = nullptr);

View File

@@ -11,6 +11,7 @@
#include <group.h> #include <group.h>
#include <math_helper.h> #include <math_helper.h>
#include <renderstat.h> #include <renderstat.h>
#include <string.h>
#define MIN_ALLOC (2) #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->unboxableObjectList = (Shape **)calloc(sizeof(Shape **), MIN_ALLOC);
this->unboxableObjectCount = 0; this->unboxableObjectCount = 0;
if (name != nullptr)
{
strncpy(this->name, name, 32);
}
else
{
strncpy(this->name, "untitled", 32);
}
} }
Intersect Group::intersect(Ray r) Intersect Group::intersect(Ray r)
@@ -204,6 +213,7 @@ void Group::dumpMe(FILE *fp)
{ {
int i; int i;
fprintf(fp, "\"Type\": \"Group\",\n"); fprintf(fp, "\"Type\": \"Group\",\n");
fprintf(fp, "\"Name\": \"%s\",\n", this->name);
if (this->objectCount > 0) if (this->objectCount > 0)
{ {
fprintf(fp, "\"Objects\": {\n"); fprintf(fp, "\"Objects\": {\n");