/* * Ray++ - Object-oriented ray tracing library * Copyright (C) 1998-2001 Martin Reinecke and others. * See the AUTHORS file for more information. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * See the README file for more information. */ #include "cameras/std_camera.h" namespace RAYPP { extern HANDLE World; extern HANDLE Renderer; STD_CAMERA::STD_CAMERA () : Location (0,0,0), Sky (0,1,0), LookAt (0,0,1), u_fov (45), v_fov (34), Aspect_Ratio (4.0/3.0) {} STD_CAMERA::STD_CAMERA (const VECTOR &Loc, const VECTOR &Look) : Location (Loc), Sky (0,1,0), LookAt (Look), u_fov (45), v_fov (34), Aspect_Ratio (4.0/3.0) {} //virtual void STD_CAMERA::Init () { if (initialized) return; Direction = (LookAt - Location).Norm(); Right = (Cross (Direction, Sky)).Norm(); Up = Cross (Right, Direction); Right *= -tan (u_fov/2.0 * Pi/180.0)*2.0; Up *= tan (v_fov/2.0 * Pi/180.0)*2.0; World->Get_Surrounding_Volume (Location, MyVolume); initialized = true; } //virtual void STD_CAMERA::Transform (const TRANSFORM &trans) { cni(); Location = trans.TransPoint (Location); LookAt = trans.TransPoint (LookAt); } //virtual COLOUR STD_CAMERA::Calc_Intensity (float8 u, float8 v) const { ci(); VECTOR Dir = (Direction + Right*(u-0.5) + Up*(0.5-v)).Norm(); RAY Ray (Location, Dir, 0.0, Huge_float8, MyVolume, COLOUR (1,1,1)); return Renderer->Trace_Ray (Ray); } void STD_CAMERA::Set_Sky (const VECTOR &new_sky) { cni(); Sky = new_sky; } void STD_CAMERA::Set_Location (const VECTOR &new_loc) { cni(); Location = new_loc; } void STD_CAMERA::Set_LookAt (const VECTOR &new_look) { cni(); LookAt = new_look; } void STD_CAMERA::Set_Fov (float8 new_ufov, float8 new_vfov) { cni(); u_fov = new_ufov; v_fov = new_vfov; // a sanity check wouldn't be bad } void STD_CAMERA::Set_Fov (float8 new_ufov) { cni(); u_fov = new_ufov; v_fov = 180.0/Pi * 2 * atan (tan(Pi/180.0 * 0.5*u_fov)/Aspect_Ratio); // a sanity check wouldn't be bad } void STD_CAMERA::Set_Aspect_Ratio (float8 new_AR) { cni(); Aspect_Ratio = new_AR; } } // namespace RAYPP