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_SCALE_H )
23 #define INCLUDED_SCALE_H
27 #include "math/matrix.h"
28 #include "generic/callback.h"
31 const Vector3 SCALEKEY_IDENTITY = Vector3( 1, 1, 1 );
33 inline void default_scale( Vector3& scale ){
34 scale = SCALEKEY_IDENTITY;
36 inline void read_scale( Vector3& scalevec, const char* value ){
38 if ( !string_parse_float( value, scale )
40 default_scale( scalevec );
44 scalevec = Vector3( scale, scale, scale );
47 inline void read_scalevec( Vector3& scale, const char* value ){
48 if ( !string_parse_vector3( value, scale )
52 default_scale( scale );
55 inline void write_scale( const Vector3& scale, Entity* entity ){
56 if ( scale[0] == 1 && scale[1] == 1 && scale[2] == 1 ) {
57 entity->setKeyValue( "modelscale", "" );
58 entity->setKeyValue( "modelscale_vec", "" );
64 if ( scale[0] == scale[1] && scale[0] == scale[2] ) {
65 sprintf( value, "%f", scale[0] );
66 entity->setKeyValue( "modelscale_vec", "" );
67 entity->setKeyValue( "modelscale", value );
71 sprintf( value, "%f %f %f", scale[0], scale[1], scale[2] );
72 entity->setKeyValue( "modelscale", "" );
73 entity->setKeyValue( "modelscale_vec", value );
78 inline Vector3 scale_scaled( const Vector3& scale, const Vector3& scaling ){
79 return matrix4_get_scale_vec3(
80 matrix4_multiplied_by_matrix4(
81 matrix4_scale_for_vec3( scale ),
82 matrix4_scale_for_vec3( scaling )
90 Callback<void()> m_scaleChanged;
95 ScaleKey( const Callback<void()>& scaleChanged )
96 : m_scaleChanged( scaleChanged ), m_scale( SCALEKEY_IDENTITY ){
99 void uniformScaleChanged( const char* value ){
100 read_scale( m_scale, value );
103 typedef MemberCaller<ScaleKey, void(const char*), &ScaleKey::uniformScaleChanged> UniformScaleChangedCaller;
105 void scaleChanged( const char* value ){
106 read_scalevec( m_scale, value );
109 typedef MemberCaller<ScaleKey, void(const char*), &ScaleKey::scaleChanged> ScaleChangedCaller;
111 void write( Entity* entity ) const {
112 write_scale( m_scale, entity );