00001
00008 #ifndef _UTIL_H
00009 #define _UTIL_H
00010
00011 #include "main.h"
00012 #include "material.h"
00013
00014 #include <string>
00015 using namespace std;
00016
00017 #include <gfx/mat4.h>
00018 #include <gfx/vec3.h>
00019
00020 #include <ClanLib/core.h>
00021
00023 Vec3 world_to_screen(Vec3 world);
00025 Vec3 screen_to_world(Vec3 screen);
00026
00032 Mat4 rotation_matrix_angles_rad( const Vec3& angles );
00033
00037 void set_translation( Mat4& mat, const Vec3& translate );
00038
00043 Mat4 inverse_t_r( const Mat4& mat );
00044
00049 void draw_cylinder( Vec3 center, Vec3 dir, const Material& mat, double width, double height );
00050
00051
00052
00053 inline string get_string( const CL_DomElement& element, string name )
00054 {
00055 return element.get_attribute( name );
00056 }
00057
00058 inline int get_int( const CL_DomElement& element, string name )
00059 {
00060 return CL_String::to_int( element.get_attribute( name ) );
00061 }
00062
00063 inline float get_float( const CL_DomElement& element, string name )
00064 {
00065 return CL_String::to_float( element.get_attribute( name ) );
00066 }
00067
00068 inline double get_double( const CL_DomElement& element, string name )
00069 {
00070 return CL_String::to_double( element.get_attribute( name ) );
00071 }
00072
00073 inline bool get_bool( const CL_DomElement& element, string name )
00074 {
00075 return CL_String::to_bool( element.get_attribute( name ) );
00076 }
00077
00078 inline Vec3 get_vec3( const CL_DomElement& element, string name )
00079 {
00080 vector<string> tokens =
00081 CL_String::tokenize( element.get_attribute( name ), " " );
00082
00083 return Vec3( CL_String::to_double( tokens[ 0 ] ),
00084 CL_String::to_double( tokens[ 1 ] ),
00085 CL_String::to_double( tokens[ 2 ] ) );
00086 }
00087
00088 inline CL_DomElement get_element( CL_ResourceManager& manager, string resource )
00089 {
00090 return manager.get_resource( resource ).get_element();
00091 }
00092
00094 inline Vec3 vec_mult( Vec3 a, Vec3 b )
00095 {
00096 return Vec3( a[0] * b[0], a[1] * b[1], a[2] * b[2] );
00097 }
00098
00099 inline Vec3 vec_dropw( Vec4 a )
00100 {
00101 return Vec3( a[0], a[1], a[2] );
00102 }
00103
00104 inline string to_string( bool x )
00105 {
00106 return CL_String::from_bool( x );
00107 }
00108
00109 inline string to_string( int x )
00110 {
00111 return CL_String::from_int( x );
00112 }
00113
00114 inline string to_string( double x )
00115 {
00116 return CL_String::from_double( x );
00117 }
00118
00119 inline string to_string( Vec3 v )
00120 {
00121 return CL_String::from_double(v[0]) + " " +
00122 CL_String::from_double(v[1]) + " " +
00123 CL_String::from_double(v[2]);
00124 }
00125
00126
00127 string convert_path( string path );
00128
00129 #endif // header guard