Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pinholecamera.cpp

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #include "pinholecamera.h"  // include first
00024 #include "context.h"
00025 #include "ray.h"
00026 
00027 #include <cassert>
00028 #include <cmath>
00029 
00030 using namespace sheep;
00031 using namespace toxic;
00032 
00033 PinholeCamera::PinholeCamera(const Matrix4 &m, Real hfov, Real aspect_ratio) :
00034     ICamera(m, hfov, aspect_ratio)
00035 {
00036 }
00037 
00038 Ray PinholeCamera::ComputeRay(const Context &context,
00039                               const Point2 &p) const
00040 {
00041     assert(p.m_x >= -0.5 && p.m_x <= 0.5);
00042     assert(p.m_y >= -0.5 && p.m_y <= 0.5);
00043 
00044     // Create a ray with origin at the camera position and directed toward
00045     // the specified location on the film plane.
00046     Ray ray(Ray::PRIMARY_RAY);
00047     ray.m_origin = m_location;
00048     ray.m_direction =
00049         p.m_x * m_u +   // m_u = m_ex * m_aspect_ratio
00050         p.m_y * m_ey +
00051         m_w;            // m_w = m_ez * (-m_focal_length)
00052     ray.m_direction.Normalize();
00053 
00054     return ray;
00055 }
00056 
00057 Point2 PinholeCamera::Project(const Point3 &p) const {
00058     Vector3 xi = p - m_location;
00059     assert(xi * m_ez != 0.0);
00060 
00061     xi *= -m_focal_length / (xi * m_ez);
00062 
00063     return Point2(xi * m_ex / m_aspect_ratio, xi * m_ey);
00064 }

Generated on Tue May 11 01:31:51 2004 for toxic by doxygen 1.3.6