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

utilities.h

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 #ifndef TOXIC_RENDERER_UTILITIES_H
00024 #define TOXIC_RENDERER_UTILITIES_H
00025 
00026 #include "common/math/real.h"
00027 #include "common/math/vector3.h"
00028 #include "common/misc/types.h"
00029 #include "globals.h"
00030 
00031 #include <cassert>
00032 #include <cmath>
00033 
00034 namespace toxic {
00035 
00036     int IntSquareRoot(int n);
00037     bool IsSquare(int n);
00038 
00039     struct ConversionTables {
00040         static sheep::Real m_cos_phi[256];
00041         static sheep::Real m_sin_phi[256];
00042         static sheep::Real m_cos_theta[256];
00043         static sheep::Real m_sin_theta[256];
00044         static sheep::Vector3 m_direction[256];
00045 
00046         ConversionTables();
00047     };
00048 
00049     //! Converts from cartesian coordinates to spherical coordinates.
00050     //! v must be a unit-length vector.
00051     //! phi is in [0, 2*Pi], theta is in [0, Pi].
00052     void VectorToSphericalCoords(
00053         const sheep::Vector3 &v,
00054         sheep::Real *phi,
00055         sheep::Real *theta);
00056 
00057     //! Converts from spherical coordinates to cartesian coordinates.
00058     //! Returned vector is unit-length.
00059     sheep::Vector3 SphericalCoordsToVector(sheep::Real phi, sheep::Real theta);
00060 
00061     //! Packs a direction expressed in spherical coordinates to a compact
00062     //! 16-bit representation.
00063     void PackSphericalCoords(
00064         sheep::Real phi, sheep::Real theta,
00065         sheep::uint8 *qphi, sheep::uint8 *qtheta);
00066 
00067     //! Unpacks spherical coordinates from the 16-bit representation.
00068     //! phi is in [0, 2*Pi], theta is in [0, Pi].
00069     void UnpackSphericalCoords(
00070         sheep::uint8 qphi, sheep::uint8 qtheta,
00071         sheep::Real *phi, sheep::Real *theta);
00072 
00073     //! Packs a direction expressed in spherical coordinates to a compact
00074     //! 8-bit representation.
00075     void PackSphericalCoords(
00076         sheep::Real phi, sheep::Real theta,
00077         sheep::uint8 *q);
00078 
00079     //! Unpacks spherical coordinates from the 16-bit representation.
00080     //! phi is in [0, 2*Pi], theta is in [0, Pi].
00081     void UnpackSphericalCoords(
00082         sheep::uint8 q,
00083         sheep::Real *phi, sheep::Real *theta);
00084 
00085     //! Helper function.
00086     void PackDirection(
00087         const sheep::Vector3 &v,
00088         sheep::uint8 *qphi, sheep::uint8 *qtheta);
00089 
00090     //! Helper function.
00091     void PackDirection(const sheep::Vector3 &v, sheep::uint8 *q);
00092 
00093     //! Not a helper function. Same as UnpackSphericalCoords() followed by
00094     //! SphericalCoordsToVector(), but much faster.
00095     sheep::Vector3 UnpackDirection(sheep::uint8 qphi, sheep::uint8 qtheta);
00096 
00097     //! Not a helper function. Same as UnpackSphericalCoords() followed by
00098     //! SphericalCoordsToVector(), but much faster.
00099     sheep::Vector3 UnpackDirection(sheep::uint8 q);
00100 
00101 #include "utilities.inl"
00102 
00103 }
00104 
00105 #endif  // !TOXIC_RENDERER_UTILITIES_H

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