00001 #include "AffineObject.h" 00002 00003 using namespace std; 00004 00005 namespace rcrt 00006 { 00007 00008 AffineObject::AffineObject(string name):SolidObject(name) 00009 { 00010 } 00011 00012 AffineObject::~AffineObject() 00013 { 00014 } 00015 00016 void AffineObject::updateWorldBox() 00017 { 00018 worldBox = localTree.getBoundingBox().transformed(worldMatrix); 00019 } 00020 00021 void AffineObject::setPrimitives(std::vector<Primitive*>* prList) 00022 { 00023 cout << "building: " << name << endl; 00024 localTree.setTraceables(prList); 00025 updateWorldBox(); 00026 } 00027 00028 void AffineObject::setWorldMatrix(const Matrix4D& mat) 00029 { 00030 worldMatrix = mat; 00031 invWorldMatrix = worldMatrix.inverse(); 00032 updateWorldBox(); 00033 } 00034 00035 Intersection AffineObject::intersect(Ray& r) const 00036 { 00037 Intersection wIns = worldBox.intersect(r); 00038 if(!wIns.isValid()){ 00039 return Intersection(); 00040 } 00041 Point3D org = invWorldMatrix*r.org();//wIns.getPosition(); 00042 Vec3D dir = invWorldMatrix*r.dir(); 00043 Ray newRay(org, dir, 0, false); 00044 newRay.setMinDist(0); 00045 Intersection lIns = localTree.intersect(newRay); 00046 r.tris += newRay.tris; 00047 if(!lIns.isValid()) 00048 return Intersection(); 00049 float dist = (worldMatrix * (org-lIns.getPosition())).norm(); 00050 Intersection is(dist, lIns.getPrimitive(), r.atDistance(dist), 00051 lIns.getParams().x(), lIns.getParams().y(), lIns.backSide()); 00052 is.setGNormalL(lIns.getGNormalL()); 00053 is.setSNormalL(lIns.getSNormalL()); 00054 return is; 00055 } 00056 00057 const AABB& AffineObject::getBoundingBox() const 00058 { 00059 return worldBox; 00060 } 00061 00062 const Point3D& AffineObject::getCentroid() const 00063 { 00064 return worldBox.getCentroid(); 00065 } 00066 00067 }