sorttest.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // skeleton.cpp : Defines the entry point for the application.
  20. //
  21. // Skeleton WW3D code, Hector Yee, 8/31/00
  22. #include "resource.h"
  23. #include "wwmath.h"
  24. #include "ww3d.h"
  25. #include "scene.h"
  26. #include "rendobj.h"
  27. #include "camera.h"
  28. #include "assetmgr.h"
  29. #include "msgloop.h"
  30. #include "part_ldr.h"
  31. #include "rendobj.h"
  32. #include "hanim.h"
  33. #include "dx8wrapper.h"
  34. #include "dx8indexbuffer.h"
  35. #include "dx8vertexbuffer.h"
  36. #include "dx8fvf.h"
  37. #include "vertmaterial.h"
  38. #include "font3d.h"
  39. #include "render2d.h"
  40. #include "textdraw.h"
  41. #include "rect.h"
  42. #include "mesh.h"
  43. #include "meshmdl.h"
  44. #include "vector2i.h"
  45. #include "bmp2d.h"
  46. #include "decalsys.h"
  47. #include "shattersystem.h"
  48. #include "light.h"
  49. #include "keyboard.h"
  50. #include "wwmouse.h"
  51. #include "predlod.h"
  52. #include "sphere.h"
  53. #include <stdio.h>
  54. #include "dx8renderer.h"
  55. #include "ini.h"
  56. #define MAX_LOADSTRING 100
  57. static void Log_Statistics();
  58. static void Init_3D_Scene();
  59. // Global Variables:
  60. HINSTANCE hInst; // current instance
  61. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  62. TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
  63. WW3DAssetManager * AssetManager=NULL;
  64. SimpleSceneClass * my_scene = NULL;
  65. CameraClass * my_camera = NULL;
  66. Render2DTextClass * mytext = NULL;
  67. RenderObjClass * orig_object = NULL;
  68. MaterialPassClass * mat_pass = NULL;
  69. HAnimClass * my_anim = NULL;
  70. Font3DInstanceClass *my_font_a=NULL;
  71. Font3DInstanceClass *my_font_b=NULL;
  72. DecalSystemClass TheDecalSystem;
  73. bool running=true;
  74. bool rotate=false;
  75. bool sort=true;
  76. float sep;
  77. // Foward declarations of functions included in this code module:
  78. ATOM MyRegisterClass(HINSTANCE hInstance);
  79. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  80. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  81. void Render();
  82. void WWDebug_Message_Callback(DebugType type, const char * message);
  83. void WWAssert_Callback(const char * message);
  84. void Debug_Refs(void);
  85. void LoadAssets();
  86. // Scene class to use mat_pass:
  87. class MatPassSceneClass : public SimpleSceneClass {
  88. protected:
  89. virtual void Customized_Render(RenderInfoClass & rinfo);
  90. };
  91. void MatPassSceneClass::Customized_Render(RenderInfoClass &rinfo)
  92. {
  93. if (mat_pass) {
  94. rinfo.Push_Material_Pass(mat_pass);
  95. bool hide_mesh = false;
  96. int hide_flag = hide_mesh ? ((int)RenderInfoClass::RINFO_OVERRIDE_FORCE_SORTING |
  97. (int)RenderInfoClass::RINFO_OVERRIDE_ADDITIONAL_PASSES_ONLY) : 0;
  98. rinfo.Push_Override_Flags((RenderInfoClass::RINFO_OVERRIDE_FLAGS) ((int)rinfo.Current_Override_Flags() | hide_flag));
  99. }
  100. SimpleSceneClass::Customized_Render(rinfo);
  101. if (mat_pass) {
  102. rinfo.Pop_Override_Flags();
  103. rinfo.Pop_Material_Pass();
  104. }
  105. }
  106. // ----------------------------------------------------------------------------
  107. //
  108. // FPS counter class counts how many times Update() has been called during the
  109. // last second. The fps counter caps at MAX_FPS which is the maximum fps count
  110. // that can be measured.
  111. //
  112. // ----------------------------------------------------------------------------
  113. const unsigned MAX_FPS=2000;
  114. class FPSCounterClass
  115. {
  116. unsigned frame_times[MAX_FPS];
  117. unsigned frame_time_count;
  118. public:
  119. FPSCounterClass();
  120. void Update();
  121. unsigned Get_FPS();
  122. };
  123. static FPSCounterClass fps_counter;
  124. // ----------------------------------------------------------------------------
  125. FPSCounterClass::FPSCounterClass()
  126. :
  127. frame_time_count(0)
  128. {
  129. }
  130. // ----------------------------------------------------------------------------
  131. void FPSCounterClass::Update()
  132. {
  133. unsigned frame_time=timeGetTime();
  134. unsigned limit=frame_time-1000;
  135. for (unsigned i=0;i<frame_time_count;++i) {
  136. if (frame_times[i]<limit) {
  137. frame_times[i]=frame_times[frame_time_count-1];
  138. frame_time_count--;
  139. }
  140. }
  141. if (frame_time_count<MAX_FPS) {
  142. frame_times[frame_time_count++]=frame_time;
  143. }
  144. }
  145. // ----------------------------------------------------------------------------
  146. unsigned FPSCounterClass::Get_FPS()
  147. {
  148. return frame_time_count;
  149. }
  150. // ----------------------------------------------------------------------------
  151. //
  152. //
  153. //
  154. // ----------------------------------------------------------------------------
  155. int APIENTRY WinMain(HINSTANCE hInstance,
  156. HINSTANCE hPrevInstance,
  157. LPSTR lpCmdLine,
  158. int nCmdShow)
  159. {
  160. HACCEL hAccelTable;
  161. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SKELETON);
  162. // install debug callbacks
  163. WWDebug_Install_Message_Handler(WWDebug_Message_Callback);
  164. WWDebug_Install_Assert_Handler(WWAssert_Callback);
  165. // Initialize global strings
  166. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  167. LoadString(hInstance, IDC_SKELETON, szWindowClass, MAX_LOADSTRING);
  168. MyRegisterClass(hInstance);
  169. // Perform application initialization:
  170. hInst = hInstance; // Store instance handle in our global variable
  171. HWND hWnd = CreateWindow(
  172. szWindowClass,
  173. szTitle,
  174. WS_OVERLAPPEDWINDOW,
  175. CW_USEDEFAULT,
  176. 0,
  177. CW_USEDEFAULT,
  178. 0,
  179. NULL,
  180. NULL,
  181. hInstance,
  182. NULL);
  183. ShowWindow(hWnd, nCmdShow);
  184. UpdateWindow(hWnd);
  185. // WW Inits
  186. WWMath::Init ();
  187. AssetManager=new WW3DAssetManager;
  188. AssetManager->Register_Prototype_Loader(&_ParticleEmitterLoader);
  189. WW3D::Init(hWnd);
  190. WW3D::Enable_Munge_Sort_On_Load(true);
  191. WW3D::Set_Texture_Thumbnail_Mode(WW3D::TEXTURE_THUMBNAIL_MODE_ON);
  192. // WW3D::Set_Prelit_Mode(WW3D::PRELIT_MODE_VERTEX);
  193. WW3D::Set_Prelit_Mode(WW3D::PRELIT_MODE_LIGHTMAP_MULTI_PASS);
  194. // WW3D::Set_Prelit_Mode(WW3D::PRELIT_MODE_LIGHTMAP_MULTI_TEXTURE);
  195. WW3D::Set_Collision_Box_Display_Mask(0xFF);
  196. if (WW3D::Set_Render_Device(0,800,600,32,1,true)!=WW3D_ERROR_OK) {
  197. WW3D::Shutdown();
  198. WWMath::Shutdown ();
  199. Debug_Refs();
  200. return 0;
  201. }
  202. Init_3D_Scene();
  203. WW3D::Enable_Sorting(sort);
  204. // main loop
  205. int time=timeGetTime();
  206. float theta = 0.0f;
  207. while (running)
  208. {
  209. if (rotate) {
  210. theta += DEG_TO_RADF(0.5f);
  211. Matrix3D tm(1);
  212. tm.Rotate_Z(theta);
  213. if (orig_object) orig_object->Set_Transform(tm);
  214. }
  215. Render();
  216. Windows_Message_Handler();
  217. WW3D::Sync(timeGetTime()-time);
  218. Log_Statistics();
  219. }
  220. REF_PTR_RELEASE(my_scene);
  221. REF_PTR_RELEASE(my_camera);
  222. delete mytext;
  223. REF_PTR_RELEASE(my_font_a);
  224. REF_PTR_RELEASE(my_font_b);
  225. REF_PTR_RELEASE(orig_object);
  226. REF_PTR_RELEASE(my_anim);
  227. PredictiveLODOptimizerClass::Free();
  228. // shutdown
  229. AssetManager->Free_Assets ();
  230. delete AssetManager;
  231. WW3D::Shutdown ();
  232. WWMath::Shutdown ();
  233. Debug_Refs();
  234. return 0;
  235. }
  236. // ----------------------------------------------------------------------------
  237. //
  238. // Render everything. Rendering stars with Begin_Scene() and ends to End_Scene().
  239. //
  240. // ----------------------------------------------------------------------------
  241. void Render()
  242. {
  243. // Predictive LOD optimizer optimizes the mesh LOD levels to match the given polygon budget
  244. my_scene->Visibility_Check(my_camera);
  245. PredictiveLODOptimizerClass::Optimize_LODs(150000);
  246. WW3D::Begin_Render(true,true,Vector3(0.5f,0.5f,0.5f));
  247. // Render 3D scene
  248. WW3D::Render(my_scene,my_camera);
  249. if (mytext) mytext->Render();
  250. WW3D::End_Render();
  251. fps_counter.Update();
  252. }
  253. // ----------------------------------------------------------------------------
  254. //
  255. // FUNCTION: MyRegisterClass()
  256. //
  257. // PURPOSE: Registers the window class.
  258. //
  259. // COMMENTS:
  260. //
  261. // This function and its usage is only necessary if you want this code
  262. // to be compatible with Win32 systems prior to the 'RegisterClassEx'
  263. // function that was added to Windows 95. It is important to call this function
  264. // so that the application will get 'well formed' small icons associated
  265. // with it.
  266. //
  267. // ----------------------------------------------------------------------------
  268. ATOM MyRegisterClass(HINSTANCE hInstance)
  269. {
  270. WNDCLASSEX wcex;
  271. wcex.cbSize = sizeof(WNDCLASSEX);
  272. wcex.style = CS_HREDRAW | CS_VREDRAW;
  273. wcex.lpfnWndProc = (WNDPROC)WndProc;
  274. wcex.cbClsExtra = 0;
  275. wcex.cbWndExtra = 0;
  276. wcex.hInstance = hInstance;
  277. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SKELETON);
  278. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  279. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  280. wcex.lpszMenuName = (LPCSTR)IDC_SKELETON;
  281. wcex.lpszClassName = szWindowClass;
  282. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  283. return RegisterClassEx(&wcex);
  284. }
  285. // ----------------------------------------------------------------------------
  286. //
  287. // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
  288. //
  289. // PURPOSE: Processes messages for the main window.
  290. //
  291. // WM_COMMAND - process the application menu
  292. // WM_PAINT - Paint the main window
  293. // WM_DESTROY - post a quit message and return
  294. //
  295. //
  296. // ----------------------------------------------------------------------------
  297. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  298. {
  299. int wmId, wmEvent;
  300. PAINTSTRUCT ps;
  301. HDC hdc;
  302. switch (message)
  303. {
  304. case WM_COMMAND:
  305. wmId = LOWORD(wParam);
  306. wmEvent = HIWORD(wParam);
  307. // Parse the menu selections:
  308. switch (wmId)
  309. {
  310. case IDM_ABOUT:
  311. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
  312. break;
  313. case IDM_EXIT:
  314. DestroyWindow(hWnd);
  315. break;
  316. case IDM_RELOAD:
  317. LoadAssets();
  318. break;
  319. default:
  320. return DefWindowProc(hWnd, message, wParam, lParam);
  321. }
  322. break;
  323. case WM_ACTIVATEAPP:
  324. if (wParam) WW3D::On_Activate_App();
  325. else WW3D::On_Deactivate_App();
  326. return DefWindowProc(hWnd, message, wParam, lParam);
  327. case WM_PAINT:
  328. hdc = BeginPaint(hWnd, &ps);
  329. // TODO: Add any drawing code here...
  330. EndPaint(hWnd, &ps);
  331. break;
  332. case WM_DESTROY:
  333. running=false;
  334. PostQuitMessage(0);
  335. break;
  336. case WM_KEYUP:
  337. if ((wParam&0xff)==VK_ESCAPE) {
  338. DestroyWindow(hWnd);
  339. return 0;
  340. }
  341. return DefWindowProc(hWnd, message, wParam, lParam);
  342. case WM_CHAR:
  343. {
  344. char key=LOWORD(wParam);
  345. switch (key)
  346. {
  347. case '-':
  348. WW3D::Make_Screen_Shot("screen");
  349. break;
  350. case '+':
  351. WW3D::Toggle_Movie_Capture();
  352. break;
  353. case ' ':
  354. rotate=!rotate;
  355. break;
  356. case 's':
  357. sort=!sort;
  358. WW3D::Enable_Sorting(sort);
  359. WW3D::Enable_Static_Sort_Lists(!sort);
  360. TheDX8MeshRenderer.Invalidate();
  361. break;
  362. case 'm':
  363. {
  364. SceneClass::PolyRenderType type = my_scene->Get_Polygon_Mode();
  365. type = (type == SceneClass::POINT) ? SceneClass::LINE : ((type == SceneClass::LINE) ? SceneClass::FILL : SceneClass::POINT);
  366. my_scene->Set_Polygon_Mode(type);
  367. }
  368. break;
  369. }
  370. }
  371. default:
  372. return DefWindowProc(hWnd, message, wParam, lParam);
  373. }
  374. return 0;
  375. }
  376. // Mesage handler for about box.
  377. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  378. {
  379. switch (message)
  380. {
  381. case WM_INITDIALOG:
  382. return TRUE;
  383. case WM_COMMAND:
  384. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  385. {
  386. EndDialog(hDlg, LOWORD(wParam));
  387. return TRUE;
  388. }
  389. break;
  390. }
  391. return FALSE;
  392. }
  393. // ----------------------------------------------------------------------------
  394. //
  395. // WWDebug message callback defines the behavior of WWDEBUG_SAY().
  396. //
  397. // ----------------------------------------------------------------------------
  398. void WWDebug_Message_Callback(DebugType type, const char * message)
  399. {
  400. OutputDebugString(message);
  401. }
  402. // ----------------------------------------------------------------------------
  403. //
  404. // WWAssert callback defines the behavior of WWASSERT().
  405. //
  406. // ----------------------------------------------------------------------------
  407. void WWAssert_Callback(const char * message)
  408. {
  409. OutputDebugString(message);
  410. _asm int 0x03
  411. }
  412. // ----------------------------------------------------------------------------
  413. void Debug_Refs(void)
  414. {
  415. #ifdef _DEBUG
  416. WWDEBUG_SAY(("Dumping Un-Released Ref-Counted objects...\r\n"));
  417. RefBaseNodeClass * first = RefBaseClass::ActiveRefList.First();
  418. RefBaseNodeClass * node = first;
  419. while (node->Is_Valid())
  420. {
  421. RefBaseClass * obj = node->Get();
  422. ActiveRefStruct * ref = &(obj->ActiveRefInfo);
  423. bool display = true;
  424. int count = 0;
  425. RefBaseNodeClass * search = first;
  426. while (search->Is_Valid()) {
  427. if (search == node) { // if this is not the first one
  428. if (count != 0) {
  429. display = false;
  430. break;
  431. }
  432. }
  433. RefBaseClass * search_obj = search->Get();
  434. ActiveRefStruct * search_ref = &(search_obj->ActiveRefInfo);
  435. if ( ref->File && search_ref->File &&
  436. !strcmp(search_ref->File, ref->File) &&
  437. (search_ref->Line == ref->Line) ) {
  438. count++;
  439. } else if ( (ref->File == NULL) && (search_ref->File == NULL) ) {
  440. count++;
  441. }
  442. search = search->Next();
  443. }
  444. if ( display ) {
  445. WWDEBUG_SAY(( "%d Active Ref: %s %d %p\n", count, ref->File,ref->Line,obj));
  446. static int num_printed = 0;
  447. if (++num_printed > 20) {
  448. WWDEBUG_SAY(( "And Many More......\n"));
  449. break;
  450. }
  451. }
  452. node = node->Next();
  453. }
  454. WWDEBUG_SAY(("Done.\r\n"));
  455. #endif
  456. }
  457. // ----------------------------------------------------------------------
  458. //
  459. // Ugly statistics block!!!
  460. //
  461. // ----------------------------------------------------------------------
  462. void Log_Statistics()
  463. {
  464. StringClass format(255,true);
  465. StringClass status_text(500,true);
  466. // static unsigned last_frame_time=0;
  467. // unsigned frame_time=timeGetTime();
  468. // unsigned time=frame_time-last_frame_time;
  469. // last_frame_time=frame_time;
  470. // if (time>1000) time=1000;
  471. // float fps=1000.0f/float(time);
  472. // static float time_fps;
  473. // static float current_fps;
  474. // static unsigned fps_count;
  475. // time_fps+=fps;
  476. // fps_count++;
  477. // if (fps_count==20) {
  478. // fps_count=0;
  479. // current_fps=time_fps/20.0f;
  480. // time_fps=0.0f;
  481. // }
  482. unsigned current_fps=fps_counter.Get_FPS();
  483. static unsigned stats_mode=1;
  484. static bool tab_pressed;
  485. if (GetAsyncKeyState(VK_TAB)) {
  486. if (!tab_pressed) {
  487. stats_mode++;
  488. stats_mode%=3;
  489. }
  490. tab_pressed=true;
  491. }
  492. else {
  493. tab_pressed=false;
  494. }
  495. switch (stats_mode) {
  496. case 0:
  497. Debug_Statistics::Record_Texture_Mode(Debug_Statistics::RECORD_TEXTURE_NONE);
  498. break;
  499. case 1:
  500. Debug_Statistics::Record_Texture_Mode(Debug_Statistics::RECORD_TEXTURE_NONE);
  501. format.Format("%d FPS\n",current_fps);
  502. status_text+=format;
  503. format.Format("%d Polys/frame (%dk pps)\n",Debug_Statistics::Get_DX8_Polygons(),unsigned(Debug_Statistics::Get_DX8_Polygons()*float(current_fps))/1000);
  504. status_text+=format;
  505. if (sort)
  506. format.Format("Sorting On\n");
  507. else
  508. format.Format("Sorting Off\n");
  509. status_text+=format;
  510. break;
  511. case 2:
  512. Debug_Statistics::Record_Texture_Mode(Debug_Statistics::RECORD_TEXTURE_NONE);
  513. format.Format("%d FPS\n",current_fps);
  514. status_text+=format;
  515. format.Format("%d Polys/frame (%dk pps)\n",Debug_Statistics::Get_DX8_Polygons(),unsigned(Debug_Statistics::Get_DX8_Polygons()*float(current_fps))/1000);
  516. status_text+=format;
  517. format.Format("%d Verts/frame (%dk vps)\n",Debug_Statistics::Get_DX8_Vertices(),unsigned(Debug_Statistics::Get_DX8_Vertices()*float(current_fps))/1000);
  518. status_text+=format;
  519. format.Format("%d DX8 calls\n",DX8Wrapper::Get_Last_Frame_DX8_Calls());
  520. status_text+=format;
  521. format.Format("%d VB changes\n",DX8Wrapper::Get_Last_Frame_Vertex_Buffer_Changes());
  522. status_text+=format;
  523. format.Format("%d IB changes\n",DX8Wrapper::Get_Last_Frame_Index_Buffer_Changes());
  524. status_text+=format;
  525. format.Format("%d texture changes\n",DX8Wrapper::Get_Last_Frame_Texture_Changes());
  526. status_text+=format;
  527. format.Format("%d material changes\n",DX8Wrapper::Get_Last_Frame_Material_Changes());
  528. status_text+=format;
  529. format.Format("%d light changes\n",DX8Wrapper::Get_Last_Frame_Light_Changes());
  530. status_text+=format;
  531. format.Format("%d RS changes\n",DX8Wrapper::Get_Last_Frame_Render_State_Changes());
  532. status_text+=format;
  533. format.Format("%d TSS changes\n",DX8Wrapper::Get_Last_Frame_Texture_Stage_State_Changes());
  534. status_text+=format;
  535. format.Format("%d Mtx changes\n",DX8Wrapper::Get_Last_Frame_Matrix_Changes());
  536. status_text+=format;
  537. if (sort)
  538. format.Format("Sorting On\n");
  539. else
  540. format.Format("Sorting Off\n");
  541. status_text+=format;
  542. break;
  543. }
  544. mytext->Reset();
  545. mytext->Set_Location(Vector2(0.0,0.0));
  546. mytext->Draw_Text(status_text,0xffff0000);
  547. }
  548. void LoadAssets()
  549. {
  550. if (orig_object)
  551. {
  552. my_scene->Remove_Render_Object(orig_object);
  553. REF_PTR_RELEASE(orig_object);
  554. }
  555. INIClass ini;
  556. ini.Load("sorttest.ini");
  557. StringClass asset=ini.Get_String("GENERAL","ASSET");
  558. AssetManager->Load_3D_Assets(asset+".w3d");
  559. orig_object = AssetManager->Create_Render_Obj(asset);
  560. float rad=1;
  561. if (orig_object)
  562. {
  563. my_scene->Add_Render_Object(orig_object);
  564. rad=orig_object->Get_Bounding_Sphere().Radius;
  565. }
  566. Matrix3D camtransform(1);
  567. camtransform.Look_At(Vector3(4*rad,0,0),Vector3(0,0,0),0);
  568. my_camera->Set_Transform(camtransform);
  569. my_camera->Set_Clip_Planes(1.0f,10*rad);
  570. // Load swatch for material pass
  571. if (mat_pass)
  572. {
  573. REF_PTR_RELEASE(mat_pass);
  574. }
  575. StringClass swatch=ini.Get_String("GENERAL","SWATCH");
  576. AssetManager->Load_3D_Assets(swatch+".w3d");
  577. RenderObjClass *swatch_robj = AssetManager->Create_Render_Obj(swatch);
  578. if (swatch_robj) {
  579. if (swatch_robj->Class_ID() == RenderObjClass::CLASSID_MESH) {
  580. // Create pass from swatch mesh
  581. MeshModelClass *meshmdl = ((MeshClass *)swatch_robj)->Get_Model();
  582. mat_pass = new MaterialPassClass();
  583. mat_pass->Set_Texture(meshmdl->Peek_Single_Texture());
  584. mat_pass->Set_Shader(meshmdl->Get_Single_Shader());
  585. mat_pass->Set_Material(meshmdl->Peek_Single_Material());
  586. }
  587. swatch_robj->Release_Ref();
  588. }
  589. }
  590. void Init_3D_Scene()
  591. {
  592. my_font_a = AssetManager->Get_Font3DInstance("font12x16.tga");
  593. my_font_b = AssetManager->Get_Font3DInstance("fontnew4.tga");
  594. mytext=new Render2DTextClass(my_font_a);
  595. mytext->Set_Coordinate_Range( Render2DClass::Get_Screen_Resolution() );
  596. // build scene
  597. my_scene=NEW_REF(MatPassSceneClass,());
  598. my_scene->Set_Ambient_Light(Vector3(1.0f,1.0f,1.0f));
  599. my_camera=NEW_REF(CameraClass,());
  600. LoadAssets();
  601. }