src/rcrt/tracing/StereoMetaTracer.cpp

Go to the documentation of this file.
00001 #include "StereoMetaTracer.h"
00002 
00003 namespace rcrt
00004 {
00005 
00006 StereoMetaTracer::StereoMetaTracer(PerspectiveCamera* cam, float eyeDistance, TracingStrategy* ts):TracingStrategy(ts->getScene()),strategy(ts)
00007 {
00008         const Vec3D& xAxis = cam->getXAxis();
00009         const Vec3D& dir = cam->getDirection();
00010         const Vec3D& up = cam->getUp();
00011         const float& angle = cam->getAngle();
00012         const Point3D& pos = cam->getPosition();
00013         const int& resX = cam->getResolutionX();
00014         const int& resY = cam->getResolutionY();
00015         const float& focus = cam->getFocus();
00016         
00017         Point3D posLeft = pos - (xAxis * (eyeDistance / 2));
00018         Point3D posRight = pos + (xAxis * (eyeDistance / 2));
00019         
00020         Point3D focusPoint = pos + dir * focus;
00021         
00022         Vec3D dirLeft = (focusPoint - posLeft).normalize();
00023         Vec3D dirRight = (focusPoint - posRight).normalize();
00024         
00025         camLeft = new PerspectiveCamera(angle,posLeft,dirLeft,up,resX,resY);
00026         camRight = new PerspectiveCamera(angle,posRight,dirRight,up,resX,resY);
00027 }
00028 
00029 StereoMetaTracer::~StereoMetaTracer()
00030 {
00031         delete camLeft;
00032         delete camRight;
00033 }
00034 
00035 RGBColor StereoMetaTracer::trace(Ray& r) const
00036 {
00037         return RGBColor::BLACK;
00038 }
00039 Image StereoMetaTracer::trace(Camera* cam) const
00040 {
00041         return trace(cam, 0, 0, camLeft->getResolutionX()-1, camLeft->getResolutionY()-1);
00042 }
00043 
00044 
00045 Image StereoMetaTracer::trace(Camera* cam, const int& x0, const int& y0,
00046                 const int& x1, const int& y1) const
00047 {
00048         Image imgLeft = strategy->trace(camLeft, x0, y0, x1, y1);
00049         Image imgRight = strategy->trace(camRight, x0, y0, x1, y1);
00050                 
00051         Image stereoImage(imgLeft.getWidth(),imgLeft.getHeight());
00052                 
00053         for (int i = 0; i < imgLeft.getWidth(); i++) {
00054                 for (int j = 0; j < imgLeft.getHeight(); j++) {
00055                         const RGBAColor& pixelLeft = imgLeft.getPixel(i,j);
00056                         const RGBAColor& pixelRight = imgRight.getPixel(i,j);
00057                         stereoImage.setPixel(RGBAColor(pixelLeft.r(),pixelRight.g(),pixelRight.b(),pixelRight.a()),i,j);
00058                 }
00059         }
00060                 
00061         return stereoImage;
00062 }
00063 
00064 }

Generated on Thu Jan 31 19:26:20 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3