object_t
and plane_t
objects
tar.gz
archive of your lab11/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
sendlab
notes
object_t
class in the object.h
interface, providing
the following class member functions:
// constructors (overloaded)
object_t(std::string itype = std::string("unknown"));
// copy constructor
object_t(const object_t& rhs);
// destructor (default ok)
~object_t();
// assignment operator
const object_t& operator=(const object_t& rhs);
// friends (i/o)
friend std::ostream& operator<<(std::ostream& s, const object_t& rhs)
{ return rhs.put(s); }
friend std::ostream& operator<<(std::ostream& s, object_t *rhs)
{ return(s << (*rhs)); }
friend std::istream& operator>>(std::istream& s, object_t& rhs)
{ return rhs.get(s); }
friend std::istream& operator>>(std::istream& s, object_t *rhs)
{ return(s >> (*rhs)); }
// methods
int getcookie();
std::string gettype();
std::string getname();
virtual std::ostream& put(std::ostream& s) const;
virtual std::istream& get(std::istream& s);
// protected data members
protected:
int cookie; // magic number
std::string type; // e.g., plane, sphere, etc.
std::string name; // e.g., left_wall, center_sphere, etc.
std::string material; // material
put()
and get()
must be implemented in the object_t
implementation object.cpp
plane_t
class in the plane_t.h
interface, providing
the following class member functions:
// constructors (overloaded)
plane_t(std::string token);
// copy constructor
plane_t(const plane_t& rhs);
// destructors (default ok)
~plane_t();
// assignment operator
const plane_t& operator=(const plane_t& rhs);
// friends
std::ostream& put(std::ostream& s) const;
std::istream& get(std::istream& s);
private:
vec_t normal;
vec_t point;
double ndotq;
put()
and get()
must be implemented in the plane_t
implementation plane.cpp
main()
routine works unaltered:
int main(int argc, char *argv[])
{
list_t mats;
list_t objs;
material_t *mat;
object_t *obj;
std::string token,name;
// input should consist only of material definitions
// but there can be any number of material defs in the file
while(!std::cin.eof()) {
if((std::cin >> token).good()) {
if(token == "material") {
std::cin >> (mat = new material_t());
std::cerr << "loaded " << mat->getname() << std::endl;
mats.add((void *)mat);
}
if(token == "plane") {
std::cin >> (obj = new plane_t(token));
std::cerr << "loaded " << obj->getname() << std::endl;
objs.add((void *)obj);
}
}
}
// verify that we have all materials
material_list_print(mats);
// verify that we have all materials
object_list_print(objs);
}
main.cpp
void object_list_print(list_t& objs);
void material_list_print(list_t& mats);
material_t* material_getbyname(list_t& mats, std::string name);
material green { ambient 0 5 0 } material brown { ambient 3 3 0 } plane wall { material green normal 0 0 1 point 0 0 -7 } plane floor { material brown normal 0 1 1 point 0 0 -7 }
loaded green loaded brown loaded wall loaded floor material green { ambient 0 5 0 } material brown { ambient 3 3 0 } plane wall { material green normal 0 0 1 point 0 0 -7 } plane floor { material brown normal 0 1 1 point 0 0 -7 }