00001 // VasiSector.cxx 00002 // 00003 // Copyright (C) 2006 Tim Moore timoore@redhat.com 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License as 00007 // published by the Free Software Foundation; either version 2 of the 00008 // License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, but 00011 // WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 // 00019 // $Id: VasiSector_8cxx_source.html,v 1.3 2010/02/23 22:10:07 curt Exp $ 00020 00021 #include "VasiSector.hxx" 00022 00023 // Calculate a local coordinate system for the VASI light. The Z axis 00024 // is the up vector. The direction vector lies in the positive YZ plane. 00025 void VasiSector::computeMatrix() 00026 { 00027 osg::Vec3 perp = direction ^ up; 00028 perp.normalize(); 00029 osg::Vec3 coordSysY = up ^ perp; 00030 coordSysY.normalize(); 00031 local_to_LP.set(perp[0], perp[1], perp[2], 0.0, 00032 coordSysY[0], coordSysY[1], coordSysY[2], 0.0, 00033 up[0], up[1], up[2], 0.0, 00034 0.0, 0.0, 0.0, 1.0); 00035 // Project direction vector into the VASI coordinate system, then 00036 // into YZ plane. 00037 osg::Vec3 dirLocal = local_to_LP * direction; 00038 tanDirection = dirLocal[2] / dirLocal[1]; 00039 } 00040 00041 float VasiSector::operator() (const osg::Vec3& eyeLocal) const 00042 { 00043 // Tranform eyeLocal into the LightPoint frame 00044 osg::Vec3 EPlp = local_to_LP * eyeLocal; 00045 // In the Azimuth? 00046 if (EPlp[1] <= 0.0f) 00047 return 0.0f; 00048 double tanEPlp = EPlp[2] / EPlp[1]; 00049 if (tanEPlp >= tanDirection) 00050 return topSector ? 1.0f : 0.0f; 00051 else 00052 return topSector ? 0.0f : 1.0f; 00053 } 00054