2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined( INCLUDED_ANGLE_H )
23 #define INCLUDED_ANGLE_H
27 #include "math/quaternion.h"
28 #include "generic/callback.h"
31 const float ANGLEKEY_IDENTITY = 0;
33 inline void default_angle(float &angle)
35 angle = ANGLEKEY_IDENTITY;
38 inline void normalise_angle(float &angle)
40 angle = static_cast<float>( float_mod(angle, 360.0));
43 inline void read_angle(float &angle, const char *value)
45 if (!string_parse_float(value, angle)) {
48 normalise_angle(angle);
52 inline void write_angle(float angle, Entity *entity)
55 entity->setKeyValue("angle", "");
58 sprintf(value, "%f", angle);
59 entity->setKeyValue("angle", value);
64 Callback<void()> m_angleChanged;
69 AngleKey(const Callback<void()> &angleChanged)
70 : m_angleChanged(angleChanged), m_angle(ANGLEKEY_IDENTITY)
74 void angleChanged(const char *value)
76 read_angle(m_angle, value);
80 typedef MemberCaller<AngleKey, void(const char *), &AngleKey::angleChanged> AngleChangedCaller;
82 void write(Entity *entity) const
84 write_angle(m_angle, entity);
88 inline float angle_rotated(float angle, const Quaternion &rotation)
90 return matrix4_get_rotation_euler_xyz_degrees(
91 matrix4_multiplied_by_matrix4(
92 matrix4_rotation_for_z_degrees(angle),
93 matrix4_rotation_for_quaternion_quantised(rotation)