Add a way to remove shapes from groups
This commit is contained in:
@@ -37,7 +37,10 @@ public:
|
||||
bool isEmpty();
|
||||
|
||||
void addObject(Shape *s);
|
||||
Shape *operator[](const int p) { return this->objectList[p]; }
|
||||
void removeObject(Shape *s);
|
||||
|
||||
Shape *operator[](const int p) { return this->objectList[p]; };
|
||||
Shape *getUnboxable(const int p) { return this->unboxableObjectList[p]; };
|
||||
|
||||
Intersect intersect(Ray r);
|
||||
BoundingBox getLocalBounds();
|
||||
@@ -48,7 +51,8 @@ public:
|
||||
|
||||
bool includes(Shape *b);
|
||||
|
||||
uint32_t getObjectCount() { return this->objectCount + this->unboxableObjectCount; };
|
||||
uint32_t getObjectCount() { return this->objectCount; };
|
||||
uint32_t getUnboxableCount() { return this->unboxableObjectCount; };
|
||||
|
||||
Group(const char *name = nullptr);
|
||||
|
||||
|
||||
@@ -149,6 +149,37 @@ void Group::addObject(Shape *s)
|
||||
}
|
||||
}
|
||||
|
||||
void Group::removeObject(Shape *s)
|
||||
{
|
||||
int i;
|
||||
if (s->haveFiniteBounds())
|
||||
{
|
||||
for (i = 0; i < this->objectCount; i++)
|
||||
{
|
||||
if (this->objectList[i] == s)
|
||||
{
|
||||
this->objectCount --;
|
||||
this->objectList[i] = this->objectList[this->objectCount];
|
||||
this->objectList[this->objectCount] = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < this->unboxableObjectCount; i++)
|
||||
{
|
||||
if (this->unboxableObjectList[i] == s)
|
||||
{
|
||||
this->unboxableObjectCount --;
|
||||
this->unboxableObjectList[i] = this->unboxableObjectList[this->unboxableObjectCount];
|
||||
this->unboxableObjectList[this->unboxableObjectCount] = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Group::isEmpty()
|
||||
{
|
||||
return (this->objectCount == 0) && (this->unboxableObjectCount == 0);
|
||||
|
||||
Reference in New Issue
Block a user