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_ORIGIN_H )
23 #define INCLUDED_ORIGIN_H
27 #include "math/matrix.h"
28 #include "generic/callback.h"
31 const Vector3 ORIGINKEY_IDENTITY = Vector3(0, 0, 0);
33 inline void default_origin(Vector3 &origin)
35 origin = ORIGINKEY_IDENTITY;
38 inline void read_origin(Vector3 &origin, const char *value)
40 if (!string_parse_vector3(value, origin)) {
41 default_origin(origin);
45 inline void write_origin(const Vector3 &origin, Entity *entity, const char *key)
48 sprintf(value, "%f %f %f", origin[0], origin[1], origin[2]);
49 entity->setKeyValue(key, value);
52 inline Vector3 origin_translated(const Vector3 &origin, const Vector3 &translation)
54 return matrix4_get_translation_vec3(
55 matrix4_multiplied_by_matrix4(
56 matrix4_translation_for_vec3(origin),
57 matrix4_translation_for_vec3(translation)
62 inline Vector3 origin_snapped(const Vector3 &origin, float snap)
64 return vector3_snapped(origin, snap);
68 Callback<void()> m_originChanged;
73 OriginKey(const Callback<void()> &originChanged)
74 : m_originChanged(originChanged), m_origin(ORIGINKEY_IDENTITY)
78 void originChanged(const char *value)
80 read_origin(m_origin, value);
84 typedef MemberCaller<OriginKey, void(const char *), &OriginKey::originChanged> OriginChangedCaller;
87 void write(Entity *entity) const
89 write_origin(m_origin, entity, "origin");
96 inline BrushDoom3 *Node_getBrushDoom3(scene::Node &node)
98 return NodeTypeCast<BrushDoom3>::cast(node);
101 inline void BrushDoom3_setDoom3GroupOrigin(scene::Node &node, const Vector3 &origin)
103 BrushDoom3 *brush = Node_getBrushDoom3(node);
105 brush->setDoom3GroupOrigin(origin);
109 class SetDoom3GroupOriginWalker : public scene::Traversable::Walker {
110 const Vector3 &m_origin;
112 SetDoom3GroupOriginWalker(const Vector3 &origin) : m_origin(origin)
116 bool pre(scene::Node &node) const
118 BrushDoom3_setDoom3GroupOrigin(node, m_origin);
123 class Doom3GroupOrigin : public scene::Traversable::Observer {
124 scene::Traversable &m_set;
125 const Vector3 &m_origin;
129 Doom3GroupOrigin(scene::Traversable &set, const Vector3 &origin) : m_set(set), m_origin(origin), m_enabled(false)
147 m_set.traverse(SetDoom3GroupOriginWalker(m_origin));
151 void insert(scene::Node &node)
154 BrushDoom3_setDoom3GroupOrigin(node, m_origin);
158 void erase(scene::Node &node)
161 BrushDoom3_setDoom3GroupOrigin(node, Vector3(0, 0, 0));