angle.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined(INCLUDED_ANGLE_H)
00023 #define INCLUDED_ANGLE_H
00024 
00025 #include "ientity.h"
00026 
00027 #include "math/quaternion.h"
00028 #include "generic/callback.h"
00029 #include "stringio.h"
00030 
00031 const float ANGLEKEY_IDENTITY = 0;
00032 
00033 inline void default_angle (float& angle)
00034 {
00035     angle = ANGLEKEY_IDENTITY;
00036 }
00037 inline void normalise_angle (float& angle)
00038 {
00039     angle = static_cast<float> (float_mod(angle, 360.0));
00040 }
00041 inline void read_angle (float& angle, const std::string& value)
00042 {
00043     if (!string_parse_float(value.c_str(), angle)) {
00044         angle = 0;
00045     } else {
00046         normalise_angle(angle);
00047     }
00048 }
00049 inline void write_angle (float angle, Entity* entity)
00050 {
00051     if (angle == 0) {
00052         entity->setKeyValue("angle", "");
00053     } else {
00054         char value[64];
00055         sprintf(value, "%g", angle);
00056         entity->setKeyValue("angle", value);
00057     }
00058 }
00059 
00060 class AngleKey
00061 {
00062         Callback m_angleChanged;
00063     public:
00064         float m_angle;
00065 
00066         AngleKey (const Callback& angleChanged) :
00067             m_angleChanged(angleChanged), m_angle(ANGLEKEY_IDENTITY)
00068         {
00069         }
00070 
00071         void angleChanged (const std::string& value)
00072         {
00073             read_angle(m_angle, value);
00074             m_angleChanged();
00075         }
00076         typedef MemberCaller1<AngleKey, const std::string&, &AngleKey::angleChanged> AngleChangedCaller;
00077 
00078         void write (Entity* entity) const
00079         {
00080             write_angle(m_angle, entity);
00081         }
00082 };
00083 
00084 inline float angle_rotated (float angle, const Quaternion& rotation)
00085 {
00086     return matrix4_get_rotation_euler_xyz_degrees(matrix4_multiplied_by_matrix4(matrix4_rotation_for_z_degrees(angle),
00087             matrix4_rotation_for_quaternion_quantised(rotation))).z();
00088 }
00089 
00090 #endif

Generated by  doxygen 1.6.2