model_t
object
tar.gz
archive of your lab12/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
sendlab
notes
model_t
class in the model.h
interface, providing
the following class member functions:
// constructors (overloaded)
model_t();
// copy constructor
model_t(const model_t& rhs);
// destructors (default ok)
~model_t();
// assignment operator (does nothing, just return *this)
const model_t& operator=(const model_t& rhs);
// friend i/o
friend std::ostream& operator<<(std::ostream& s, model_t& rhs);
friend std::ostream& operator<<(std::ostream& s, model_t *rhs)
{ return(s << (*rhs)); }
friend std::istream& operator>>(std::istream& s, model_t& rhs);
friend std::istream& operator>>(std::istream& s, model_t *rhs)
{ return(s >> (*rhs)); }
// members
object_t* find_closest(vec_t&,vec_t&,object_t*,double&);
// data members
private:
list_t mats;
list_t objs;
operator<<
and operator>>
must be implemented in the model_t
implementation mocdel.cpp
find_closest()
must also be implemented in the model_t
implementation mocdel.cpp
; this
function calls the polymorphic obj->hits()
function (which must be provided by the
object_t
and plane_t
objects)
main()
routine works unaltered:
int main(int argc, char *argv[])
{
model_t model;
object_t *obj;
vec_t pos(4.0, 3.0, 5.0);
vec_t dir(0.0, 0.0, -1.0);
double dist;
std::ifstream model_ifs;
std::ifstream hits_ifs;
if(argc != 3) {
std::cerr << "Usage " << argv[0] << " " << std::endl;
return 1;
}
model_ifs.open(argv[1],std::ifstream::in);
model_ifs >> model;
model_ifs.close();
std::cout << model;
hits_ifs.open(argv[2],std::ifstream::in);
while((hits_ifs >> dir).good()) {
std::cerr << std::endl << std::endl;
std::cerr << "Ray direction: " << dir << std::endl;
dir = dir.norm();
obj = model.find_closest(pos,dir,(object_t *)NULL,dist);
if(dist > 0) {
std::cerr << "Hit: " << obj->getname();
std::cerr << " Dist = " << dist;
std::cerr << " Loc = " << obj->getlast_hit() << std::endl;
} else
std::cerr << " Dist = " << dist << std::endl;
std::cerr << std::endl << std::endl;
obj = model.find_closest(pos,dir,(object_t *)obj,dist);
if(dist > 0) {
std::cerr << "Hit: " << obj->getname();
std::cerr << " Dist = " << dist;
std::cerr << " Loc = " << obj->getlast_hit() << std::endl;
} else
std::cerr << " Dist = " << dist << std::endl;
}
hits_ifs.close();
}
material green { ambient 0 5 0 } material yellow { ambient 6 5 0 } material gray { ambient 4 4 4 } plane leftwall { material green normal 3 0 1 point 0 0 0 } plane rightwall { material yellow normal -3 0 1 point 8 0 0 } plane floor { material gray normal 0 1 0 point 0 0 0 }
-0.5 -0.1 -1 0.5 -0.1 -1 0 -0.5 -1.0 1 1 1
loaded green loaded yellow loaded gray loaded leftwall loaded rightwall loaded floor material green { ambient 0 5 0 } material yellow { ambient 6 5 0 } material gray { ambient 4 4 4 } plane leftwall { material green normal 3 0 1 point 0 0 0 } plane rightwall { material yellow normal -3 0 1 point 8 0 0 } plane floor { material gray normal 0 1 0 point 0 0 0 } Ray direction: -0.5 -0.1 -1 Hit: leftwall Dist = 7.63298 Loc = 0.6 2.32 -1.8 Hit: floor Dist = 33.6749 Loc = -11 0 -25 Ray direction: 0.5 -0.1 -1 Hit: rightwall Dist = 7.63298 Loc = 7.4 2.32 -1.8 Hit: floor Dist = 33.6749 Loc = 19 0 -25 Ray direction: 0 -0.5 -1 Hit: floor Dist = 6.7082 Loc = 4 0 -1 Hit: leftwall Dist = 19.0066 Loc = 4 -5.5 -12 Ray direction: 1 1 1 Dist = -1 Dist = -1