Add locking mechanism to prevent updating transform/parent
This commit is contained in:
@@ -48,6 +48,8 @@ public:
|
||||
|
||||
void updateTransform();
|
||||
|
||||
void lock();
|
||||
|
||||
void dumpMe(FILE *fp);
|
||||
};
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ public:
|
||||
|
||||
Group(const char *name = nullptr);
|
||||
|
||||
void lock();
|
||||
|
||||
const char *getName() { return this->name; };
|
||||
|
||||
void dumpMe(FILE * fp);
|
||||
|
||||
@@ -70,6 +70,8 @@ public:
|
||||
void updateBoundingBox();
|
||||
void updateTransform();
|
||||
|
||||
void lock();
|
||||
|
||||
void dumpMe(FILE * fp);
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
protected:
|
||||
ShapeType type;
|
||||
Matrix localTransformMatrix;
|
||||
bool locked;
|
||||
|
||||
protected:
|
||||
virtual Intersect localIntersect(Ray r) = 0;
|
||||
@@ -75,10 +76,20 @@ public:
|
||||
|
||||
virtual void dumpMe(FILE *fp);
|
||||
|
||||
/* When an object is locked, the matrix transformation and bounding box can't be updated. This is
|
||||
* usefull to move object between group without changing the real hierarchy between them.
|
||||
* It will also not change the parent member.
|
||||
* This is supposed to be used only before a render is going to start so we can optimise the
|
||||
* way the object are stored to prefer lots of un-needed intersections.
|
||||
*/
|
||||
virtual void lock() { this->locked = true; };
|
||||
|
||||
Tuple worldToObject(Tuple point) { return this->inverseTransform * point; };
|
||||
Tuple objectToWorld(Tuple point) { return this->transformMatrix * point; };
|
||||
Tuple normalToWorld(Tuple normalVector);
|
||||
|
||||
void setParent(Shape *parent) { if (!this->locked) { this->parent = parent; };};
|
||||
|
||||
void setTransform(Matrix transform);
|
||||
void setMaterial(Material material) { this->material = material; this->materialSet = true; };
|
||||
Ray transform(Ray r) { return Ray(this->transformMatrix * r.origin, this->transformMatrix * r.direction); };
|
||||
|
||||
Reference in New Issue
Block a user