/* object.cc * by Will Wagner * last updated 20 Sep 1997, 17:23:26 wwagner * * This file contains the definition of the basic Object class, on * which all POVRay objects will be based. * * Changes * 30 Jul 1997 * - Wrote this comment block, a bunch of other stuff; see * object.H for details. * * 20 Aug 1997 * - Now the type-method mapping structure is inserted into the * registry's structure one element at a time, so walking the list * is simpler. * * 20 Sep 1997 * - Slightly modified the BoundingObject, with no real impact here. * * Things to do * */ #include "frame.h" #include "registry.h" #include "object.h" /* These next items are the structures which register the object types * in this file with POV's global type registry. */ /* This is the list of local keywords. */ static RESERVED_WORD Object_Reserved_Words[] = { { BOUNDED_BY_TOKEN, "bounded_by" }, { CLIPPED_BY_TOKEN, "clipped_by" }, { HIERARCHY_TOKEN, "hierarchy" }, { HOLLOW_TOKEN, "hollow" }, { INVERSE_TOKEN, "inverse" }, { NO_SHADOW_TOKEN, "no_shadow" }, { OBJECT_TOKEN, "object" }, { OPEN_TOKEN, "open" }, { STURM_TOKEN, "sturm" }, { LAST_TOKEN, NULL } }; /* This is the list of the new types in this file, which will be * inserted in the global object type registry. */ static object_registry Object_Registry_List[] = { /* CompoundObject is never instantiated, so we don't map it here. */ { OBJECT_TOKEN, OBJECT_ID_TOKEN, Object::Parse, Object::Stats }, { LAST_TOKEN, LAST_TOKEN, NULL, NULL }, }; static void Register_Objects(void) __attribute__ ((constructor)) { RESERVED_WORD *orwl = Object_Reserved_Words; struct object_registry *orgl = Object_Registry_List; while (orwl->Token_Number != LAST_TOKEN) { /* register the local keywords with the reserved-word table */ registry.res().Add(orwl->Token_Name, orwl->Token_Number); ++orwl; } while (orgl->keyword != LAST_TOKEN) { /* register our objects with the object table */ registry.object_list().push_back(*orgl); ++orgl; } } Object *Object::Parse(Parser& p) { /* this is just a stopgap; some actual token-examination should * be done here as well. */ return (Object *)(new Object()); } /* This routine will print out the statistics we have collected to the * statistics stream (available from the registry). */ void Object::Stats(void) { registry.statistics_stream() << "Object\t" << Object::bound_tests << Object::bound_test_successes << Object::clip_tests << Object::clip_test_successes << Object::object_tests << Object::object_test_successes << "\n"; } /* Initialize the static intersection test counters. */ Counter Object::bound_tests; Counter Object::bound_test_successes; Counter Object::clip_tests; Counter Object::clip_test_successes; Counter Object::object_tests; Counter Object::object_test_successes; Object::Object() : sibling(), bound(), clip(), texture() { bound_obj = NULL; flags = 0; } Object::Object(const Object& o) : sibling(o.sibling), bound(o.bound), clip(o.clip), texture(o.texture) { bound_obj = new BoundingObject(o.bound_obj); flags = o.flags; } Object::~Object(); { delete bound_obj; } int Object::Intersects(Ray &r) { IStack *is = get_istack(); if (All_Intersections(r, is)) return TRUE; return FALSE; } int Object::All_Intersections(Ray& r, IStack& i) { ++object_tests; return FALSE; } int Object::Inside(pov_vector& v) { for (list::const_iterator p = sibling.begin(); p != NULL; ++p) if (!((*p).Inside(v))) return FALSE; return TRUE; } pov_vector Object::Normal(Intersection& i) { } Object *Object::Copy(void) { return (Object *)(new Object(*this)); } void Object::Translate(pov_vector& v, Transformation& t) { } void Object::Rotate(pov_vector& v, Transformation& t) { } void Object::Scale(pov_vector& v, Transformation& t) { } void Object::Transform(Transformation& t) { } void Object::Invert(void) { } CompoundObject::CompoundObject() : children(); { } CompoundObject::CompoundObject(const CompoundObject& c) : children(c.children) { } CompountObject::~CompoundObject() { } Object *CompoundObject::Parse(void) { return (Object *)(new CompoundObject()); }