Add Write methods to scene objects
Write methods are polymorphic, overridden by subclasses. There is a single operator<< for Objects that calls the right Write() method for the object. Neat.
This commit is contained in:
parent
b56bbf4ced
commit
4828cb313f
8 changed files with 64 additions and 1 deletions
|
@ -70,4 +70,21 @@ Object::SetMaterial(const Material& material)
|
||||||
mMaterial = material;
|
mMaterial = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Object::Write(std::ostream& ost)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
ost << "[Object]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::ostream&
|
||||||
|
operator<<(std::ostream& ost,
|
||||||
|
const Object& object)
|
||||||
|
{
|
||||||
|
object.Write(ost);
|
||||||
|
return ost;
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
||||||
|
|
12
src/object.h
12
src/object.h
|
@ -47,6 +47,8 @@ struct Object
|
||||||
virtual bool point_is_on_surface(const Vector3 &p) const = 0;
|
virtual bool point_is_on_surface(const Vector3 &p) const = 0;
|
||||||
virtual Vector3 compute_normal(const Vector3 &p) const = 0;
|
virtual Vector3 compute_normal(const Vector3 &p) const = 0;
|
||||||
|
|
||||||
|
virtual void Write(std::ostream& ost) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** The location of this object. */
|
/** The location of this object. */
|
||||||
Vector3 mOrigin;
|
Vector3 mOrigin;
|
||||||
|
@ -55,6 +57,16 @@ private:
|
||||||
Material mMaterial;
|
Material mMaterial;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a string representation of the Object to an output stream.
|
||||||
|
*
|
||||||
|
* @param [in] ost The output stream
|
||||||
|
* @param [in] object The object
|
||||||
|
* @returns The output stream
|
||||||
|
*/
|
||||||
|
std::ostream& operator<<(std::ostream& ost, const Object& object);
|
||||||
|
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -195,5 +195,13 @@ Box::IntersectSlab(const Double& slabLow,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Box::Write(std::ostream& ost)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
ost << "[Box near=" << mNear << " far=" << mFar << "]";
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ struct Box
|
||||||
bool point_is_on_surface(const Vector3 &p) const;
|
bool point_is_on_surface(const Vector3 &p) const;
|
||||||
Vector3 compute_normal(const Vector3 &p) const;
|
Vector3 compute_normal(const Vector3 &p) const;
|
||||||
|
|
||||||
|
/** @see charles::Object::Write */
|
||||||
|
void Write(std::ostream& ost) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Perform the intersection test on a slab, defined by `slabHigh` and
|
* Perform the intersection test on a slab, defined by `slabHigh` and
|
||||||
|
|
|
@ -153,4 +153,12 @@ Plane::compute_normal(const Vector3 &p)
|
||||||
|
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Plane::Write(std::ostream& ost)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
ost << "[Plane normal=" << mNormal << " distance=" << mDistance << "]";
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
||||||
|
|
|
@ -34,6 +34,9 @@ public:
|
||||||
bool point_is_on_surface(const Vector3 &p) const;
|
bool point_is_on_surface(const Vector3 &p) const;
|
||||||
Vector3 compute_normal(const Vector3 &p) const;
|
Vector3 compute_normal(const Vector3 &p) const;
|
||||||
|
|
||||||
|
/** @see charles::Object::Write */
|
||||||
|
void Write(std::ostream& ost) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** A normal vector, which specified the orientation of the plane. */
|
/** A normal vector, which specified the orientation of the plane. */
|
||||||
Vector3 mNormal;
|
Vector3 mNormal;
|
||||||
|
|
|
@ -161,4 +161,12 @@ Sphere::compute_normal(const Vector3 &p)
|
||||||
return normal;
|
return normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Sphere::Write(std::ostream& ost)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
ost << "[Sphere origin=" << GetOrigin() << " r=" << radius << "]";
|
||||||
|
}
|
||||||
|
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
||||||
|
|
|
@ -29,6 +29,10 @@ public:
|
||||||
bool DoesIntersect(const Ray& ray, TVector& t, Stats& stats) const;
|
bool DoesIntersect(const Ray& ray, TVector& t, Stats& stats) const;
|
||||||
bool point_is_on_surface(const Vector3 &p) const;
|
bool point_is_on_surface(const Vector3 &p) const;
|
||||||
Vector3 compute_normal(const Vector3 &p) const;
|
Vector3 compute_normal(const Vector3 &p) const;
|
||||||
|
|
||||||
|
/** @see charles::Object::Write */
|
||||||
|
void Write(std::ostream& ost) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float radius;
|
float radius;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue