scale.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_SCALE_H)
00023 #define INCLUDED_SCALE_H
00024 
00025 #include "ientity.h"
00026 
00027 #include "math/matrix.h"
00028 #include "generic/callback.h"
00029 #include "stringio.h"
00030 
00031 const Vector3 SCALEKEY_IDENTITY = Vector3(1, 1, 1);
00032 
00033 inline void default_scale (Vector3& scale)
00034 {
00035     scale = SCALEKEY_IDENTITY;
00036 }
00037 inline void read_scale (Vector3& scalevec, const char* value)
00038 {
00039     float scale;
00040     if (!string_parse_float(value, scale) || scale == 0) {
00041         default_scale(scalevec);
00042     } else {
00043         scalevec = Vector3(scale, scale, scale);
00044     }
00045 }
00046 inline void read_scalevec (Vector3& scale, const char* value)
00047 {
00048     if (!string_parse_vector3(value, scale) || scale[0] == 0 || scale[1] == 0 || scale[2] == 0)
00049         default_scale(scale);
00050 }
00051 inline void write_scale (const Vector3& scale, Entity* entity)
00052 {
00053     if (scale[0] == 1 && scale[1] == 1 && scale[2] == 1) {
00054         entity->setKeyValue("modelscale_vec", "");
00055     } else {
00056         char value[64];
00057 
00058         sprintf(value, "%g %g %g", scale[0], scale[1], scale[2]);
00059         entity->setKeyValue("modelscale_vec", value);
00060     }
00061 }
00062 
00063 inline Vector3 scale_scaled (const Vector3& scale, const Vector3& scaling)
00064 {
00065     return matrix4_get_scale_vec3(matrix4_multiplied_by_matrix4(matrix4_scale_for_vec3(scale), matrix4_scale_for_vec3(
00066             scaling)));
00067 }
00068 
00069 class ScaleKey
00070 {
00071         Callback m_scaleChanged;
00072     public:
00073         Vector3 m_scale;
00074 
00075         ScaleKey (const Callback& scaleChanged) :
00076             m_scaleChanged(scaleChanged), m_scale(SCALEKEY_IDENTITY)
00077         {
00078         }
00079 
00080         void scaleChanged (const std::string& value)
00081         {
00082             read_scalevec(m_scale, value.c_str());
00083             m_scaleChanged();
00084         }
00085         typedef MemberCaller1<ScaleKey, const std::string&, &ScaleKey::scaleChanged> ScaleChangedCaller;
00086 
00087         void write (Entity* entity) const
00088         {
00089             write_scale(m_scale, entity);
00090         }
00091 };
00092 
00093 #endif

Generated by  doxygen 1.6.2