00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Teddy/SpaceGame/ObjectManager.h"
00026 #include "Teddy/Graphics/View.h"
00027 #include "Teddy/Imports/LWMesh.h"
00028 #include "Teddy/Models/ModelInstance.h"
00029 #include "Teddy/Scenes/Scene.h"
00030 #include "Teddy/SysSupport/FileScan.h"
00031 #include "Teddy/SysSupport/Messages.h"
00032 #include <cstdio>
00033 using namespace Teddy::Graphics;
00034 using namespace Teddy::Imports;
00035 using namespace Teddy::Models;
00036 using namespace Teddy::Scenes;
00037
00038
00039 namespace Teddy {
00040 namespace SpaceGame {
00041
00042
00043 #define SPACE 5
00044
00045
00051 void ObjectManager::loadLWO(){
00052 lwo_debug_msg( "UI::loadLWO..." );
00053
00054 DoubleVector v;
00055 double cursor = -400.0;
00056 int i;
00057
00058 FileScan lwos( "lwo/*.lwo" );
00059 int num = lwos.get_files().size();
00060
00061 if( num >0 ){
00062
00063
00064 }else{
00065
00066
00067 return;
00068 }
00069
00070 list<char*>::iterator f_it = lwos.get_files().begin();
00071 char *fname;
00072
00073
00074 double line_z[1000];
00075 double line_x[1000];
00076 Mesh *lwom [1000];
00077
00078 int per_line = (int)(::sqrt( num ));
00079 int lines = num/per_line+1;
00080 int count = 0;
00081 int cur_line = 0;
00082 int items_on_line = 0;
00083
00084
00085 for( i=0; i<lines; i++ ){
00086 line_z[i] = 0;
00087 line_x[i] = 0;
00088 }
00089 for( i=0; i<num; i++ ){
00090 lwom[i] = NULL;
00091 }
00092
00093 double total_z = 0;
00094 double prev_ob_size = 0;
00095
00096
00097 while( f_it != lwos.get_files().end() ){
00098 double ob_rad;
00099 fname = new char[ strlen((*f_it))+5 ];
00100 # if defined( _MSC_VER )
00101
00102 sprintf( fname, "lwo/%s", *f_it );
00103
00104 # else
00105
00106 sprintf( fname, "%s", *f_it );
00107
00108 # endif
00109
00110 lwom[count] = new LWMesh( fname, 0 );
00111 if( lwom[count] != NULL ){
00112 ob_rad = lwom[count]->getClipRadius();
00113 }else{
00114 ob_rad = 0;
00115 }
00116 count++;
00117 items_on_line++;
00118
00119
00120 if( items_on_line > per_line ){
00121 line_z[cur_line] += SPACE;
00122 total_z += line_z[cur_line];
00123 cur_line++;
00124 items_on_line = 0;
00125 }
00126
00127
00128 line_x[cur_line] += ob_rad + SPACE;
00129 if( line_z[cur_line] < ob_rad*2 ){
00130 line_z[cur_line] = ob_rad*2;
00131 }
00132
00133
00134
00135 f_it++;
00136 }
00137 total_z += line_z[cur_line];
00138
00139
00140
00141
00142 cur_line = 0;
00143 items_on_line = 0;
00144 double z_offset = -total_z / 2;
00145 double x_offset = -line_x[cur_line] / 2;
00146
00147 z_offset -= line_z[cur_line]/2;
00148
00149 for( i=0; i<num; i++ ){
00150 if( lwom[i] == NULL ){
00151 lwo_debug_msg( "NULL Mesh\n" );
00152 continue;
00153 }
00154 ModelInstance *mi = new ModelInstance(
00155 lwom[i]->getName(),
00156 lwom[i]
00157 );
00158 x_offset += lwom[i]->getClipRadius()*1.1f + SPACE;
00159 mi->setPosition( x_offset, 0, z_offset );
00160
00161
00162
00163
00164
00165
00166
00167
00168 scene->addInstance( mi );
00169
00170 x_offset += lwom[i]->getClipRadius()*1.1f + SPACE;
00171 items_on_line++;
00172 if( items_on_line > per_line ){
00173 z_offset += line_z[cur_line]/2;
00174 cur_line++;
00175 z_offset += line_z[cur_line]/2;
00176 items_on_line = 0;
00177 x_offset = -line_x[cur_line] / 2;
00178 }
00179
00180 }
00181
00182
00183
00184 }
00185
00186
00187 };
00188 };
00189