Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / tools / 3d / object_viewer / main_frame.cpp
blob78f8e5798563f4ca560b09a42fd12fd62231d6fc
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program 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 Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // main_frame.cpp : implementation file
23 #include "std_afx.h"
24 #include "object_viewer.h"
25 #include "main_frame.h"
26 #include "set_value_dlg.h"
27 #include "particle_dlg.h"
28 #include "about_dialog.h"
29 #include "choose_frame_delay.h"
30 #include "choose_bg_color_dlg.h"
31 #include "choose_sun_color_dlg.h"
32 #include "day_night_dlg.h"
33 #include "water_pool_editor.h"
34 #include "vegetable_dlg.h"
35 #include "global_wind_dlg.h"
36 #include "sound_anim_dlg.h"
37 #include "fog_dlg.h"
38 #include "scene_rot_dlg.h"
39 #include "skeleton_scale_dlg.h"
40 #include "light_group_factor.h"
41 #include "tune_mrm_dlg.h"
42 #include "snapshot_tool_dlg.h"
43 #include "nel/misc/file.h"
44 #include "nel/3d/nelu.h"
45 #include "nel/3d/mesh.h"
46 #include "nel/3d/transform_shape.h"
47 #include "nel/3d/mesh_instance.h"
48 #include "nel/3d/skeleton_model.h"
51 using namespace NLMISC;
52 using namespace NL3D;
55 void CSceneDlgMouseListener::addToServer (NLMISC::CEventServer& server)
57 server.addListener (EventMouseDownId, this);
60 void CSceneDlgMouseListener::releaseFromServer (NLMISC::CEventServer& server)
62 server.removeListener (EventMouseDownId, this);
65 void CSceneDlgMouseListener::operator ()(const CEvent& event)
67 if (event == EventMouseDownId)
69 CEventMouse* mouseEvent=(CEventMouse*)&event;
70 if (mouseEvent->Button == rightButton)
72 const CEvent3dMouseListener &ml = ObjViewerDlg->getMouseListener() ;
74 CMenu menu ;
75 CMenu* subMenu ;
77 menu.LoadMenu(IDR_MOVE_ELEMENT) ;
81 menu.CheckMenuItem(ID_ENABLE_ELEMENT_XROTATE, ml.getModelMatrixRotationAxis() == CEvent3dMouseListener::xAxis
82 ? MF_CHECKED : MF_UNCHECKED ) ;
83 menu.CheckMenuItem(ID_ENABLE_ELEMENT_YROTATE, ml.getModelMatrixRotationAxis() == CEvent3dMouseListener::yAxis
84 ? MF_CHECKED : MF_UNCHECKED ) ;
85 menu.CheckMenuItem(ID_ENABLE_ELEMENT_ZROTATE, ml.getModelMatrixRotationAxis() == CEvent3dMouseListener::zAxis
86 ? MF_CHECKED : MF_UNCHECKED ) ;
89 subMenu = menu.GetSubMenu(0);
90 nlassert(subMenu) ;
92 // compute the screen coordinate from the main window
94 HWND wnd = (HWND) CNELU::Driver->getDisplay() ;
95 nlassert(::IsWindow(wnd)) ;
96 RECT r ;
97 ::GetWindowRect(wnd, &r) ;
99 sint x = r.left + (sint) (mouseEvent->X * (r.right - r.left)) ;
100 sint y = r.top + (sint) ((1.f - mouseEvent->Y) * (r.bottom - r.top)) ;
102 ::TrackPopupMenu(subMenu->m_hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, SceneDlg->m_hWnd, NULL) ;
107 /////////////////////////////////////////////////////////////////////////////
108 // CMainFrame
110 //IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
112 CMainFrame::CMainFrame( CObjectViewer *objView, winProc windowProc )
114 DriverWindowProc=windowProc;
115 ObjView=objView;
116 AnimationWindow=false;
117 AnimationSetWindow=false;
118 MixerSlotsWindow=false;
119 ParticlesWindow=false;
120 DayNightWindow=false;
121 WaterPoolWindow=false;
122 VegetableWindow=false;
123 GlobalWindWindow= false;
124 SoundAnimWindow=false;
125 LightGroupWindow=false;
126 ChooseFrameDelayWindow=false;
127 ChooseBGColorWindow=false;
128 ChooseSunColorWindow=false;
129 SkeletonScaleWindow= false;
130 TuneMRMWindow= false;
131 MouseMoveType= MoveCamera;
132 MoveMode=ObjectMode;
133 X=true;
134 Y=true;
135 Z=true;
136 Euler=false;
137 GlobalWindPower= 1.f;
138 FogActive = false;
139 FogStart = 0.f;
140 FogEnd = 100.f;
141 _LastSceneRotX= 0.0f;
142 _LastSceneRotY= 0.0f;
143 _LastSceneRotZ= 0.0f;
145 _RightButtonMouseListener.ObjViewerDlg = ObjView ;
146 _RightButtonMouseListener.SceneDlg = this ;
147 _RightButtonMouseListener.addToServer(CNELU::EventServer) ;
150 CMainFrame::~CMainFrame()
152 _RightButtonMouseListener.releaseFromServer (CNELU::EventServer);
156 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
157 //{{AFX_MSG_MAP(CMainFrame)
158 ON_COMMAND(IDC_RELOAD_TEXTURES, OnReloadTextures)
159 ON_COMMAND(ID_CLEAR, OnClear)
160 ON_COMMAND(ID_EDIT_MOVEELEMENT, OnEditMoveelement)
161 ON_COMMAND(ID_EDIT_MOVE_FX, OnEditMoveFX)
162 ON_COMMAND(ID_EDIT_MOVE_FX_USER_MATRIX, OnEditMoveFXUserMatrix)
163 ON_COMMAND(ID_EDIT_X, OnEditX)
164 ON_COMMAND(ID_EDIT_Y, OnEditY)
165 ON_COMMAND(ID_EDIT_Z, OnEditZ)
166 ON_COMMAND(ID_ENABLE_ELEMENT_XROTATE, OnEnableElementXrotate)
167 ON_COMMAND(ID_ENABLE_ELEMENT_YROTATE, OnEnableElementYrotate)
168 ON_COMMAND(ID_ENABLE_ELEMENT_ZROTATE, OnEnableElementZrotate)
169 ON_COMMAND(ID_FILE_EXIT, OnFileExit)
170 ON_COMMAND(ID_FILE_LOADCONFIG, OnFileLoadconfig)
171 ON_COMMAND(IDM_SNAPSHOT_TOOL, OnSnapShotTool)
172 ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
173 ON_COMMAND(ID_FILE_SAVECONFIG, OnFileSaveconfig)
174 ON_COMMAND(ID_VIEW_FIRSTPERSONMODE, OnViewFirstpersonmode)
175 ON_COMMAND(ID_VIEW_CAMERAMODE, OnViewCamera)
176 ON_COMMAND(ID_VIEW_OBJECTMODE, OnViewObjectmode)
177 ON_COMMAND(ID_VIEW_RESET_CAMERA, OnResetCamera)
178 ON_COMMAND(ID_VIEW_SETBACKGROUND, OnViewSetbackground)
179 ON_COMMAND(ID_VIEW_SETMOVESPEED, OnViewSetmovespeed)
180 ON_COMMAND(IDM_ACTIVATE_FOG, OnActivateFog)
181 ON_COMMAND(IDM_SETUP_FOG, OnSetupFog)
182 ON_COMMAND(ID_WINDOW_ANIMATION, OnWindowAnimation)
183 ON_COMMAND(ID_WINDOW_ANIMATIONSET, OnWindowAnimationset)
184 ON_COMMAND(ID_WINDOW_MIXERSSLOTS, OnWindowMixersslots)
185 ON_COMMAND(ID_WINDOW_PARTICLES, OnWindowParticles)
186 ON_COMMAND(ID_WINDOW_DAYNIGHT, OnWindowDayNight)
187 ON_COMMAND(ID_WINDOW_WATER_POOL, OnWindowWaterPool)
188 ON_COMMAND(ID_WINDOW_ANIMSOUND, OnWindowSoundAnim)
189 ON_COMMAND(ID_WINDOW_CHOOSE_FRAME_DELAY, OnWindowChooseFrameDelay)
190 ON_COMMAND(ID_WINDOW_CHOOSE_BG_COLOR, OnWindowChooseBGColor)
191 ON_COMMAND(ID_WINDOW_CHOOSE_SUN_COLOR, OnWindowChooseSunColor)
192 ON_COMMAND(ID_SCENE_SETLIGHTGROUPFACTOR, OnSetLightGroupFactor)
193 ON_COMMAND(IDM_SHOW_SCENE_MATRIX, OnShowSceneMatrix)
194 ON_COMMAND(iDM_SHOW_OCCLUSION_TEST_MESHS, OnShowOcclusionTestMeshs)
195 ON_COMMAND(IDM_SHOW_FX_MATRIX, OnShowFXMatrix)
196 ON_COMMAND(IDM_SHOW_FX_USER_MATRIX, OnShowFXUserMatrix)
197 ON_UPDATE_COMMAND_UI(IDM_SHOW_SCENE_MATRIX, OnUpdateShowSceneMatrix)
198 ON_UPDATE_COMMAND_UI(IDM_SHOW_FX_MATRIX, OnUpdateShowFXMatrix)
199 ON_UPDATE_COMMAND_UI(IDM_SHOW_FX_USER_MATRIX, OnUpdateShowFXUserMatrix)
200 ON_UPDATE_COMMAND_UI(iDM_SHOW_OCCLUSION_TEST_MESHS, OnUpdateShowOcclusionTestMeshs)
201 ON_WM_CREATE()
202 ON_WM_ERASEBKGND()
203 ON_UPDATE_COMMAND_UI(ID_WINDOW_ANIMATION, OnUpdateWindowAnimation)
204 ON_UPDATE_COMMAND_UI(ID_WINDOW_ANIMATIONSET, OnUpdateWindowAnimationset)
205 ON_UPDATE_COMMAND_UI(ID_WINDOW_MIXERSSLOTS, OnUpdateWindowMixersslots)
206 ON_UPDATE_COMMAND_UI(ID_WINDOW_PARTICLES, OnUpdateWindowParticles)
207 ON_UPDATE_COMMAND_UI(ID_WINDOW_DAYNIGHT, OnUpdateWindowDayNight)
208 ON_UPDATE_COMMAND_UI(ID_WINDOW_WATER_POOL, OnUpdateWindowWaterPool)
209 ON_UPDATE_COMMAND_UI(ID_WINDOW_ANIMSOUND, OnUpdateWindowSoundAnim)
210 ON_UPDATE_COMMAND_UI(ID_WINDOW_CHOOSE_FRAME_DELAY, OnUpdateWindowChooseFrameDelay)
211 ON_UPDATE_COMMAND_UI(ID_WINDOW_CHOOSE_BG_COLOR, OnUpdateWindowBGColor)
212 ON_UPDATE_COMMAND_UI(ID_WINDOW_CHOOSE_SUN_COLOR, OnUpdateWindowSunColor)
213 ON_UPDATE_COMMAND_UI(ID_VIEW_OBJECTMODE, OnUpdateViewObjectmode)
214 ON_UPDATE_COMMAND_UI(ID_VIEW_FIRSTPERSONMODE, OnUpdateViewFirstpersonmode)
215 ON_UPDATE_COMMAND_UI(ID_VIEW_CAMERAMODE, OnUpdateViewCamera)
216 ON_UPDATE_COMMAND_UI(ID_EDIT_X, OnUpdateEditX)
217 ON_UPDATE_COMMAND_UI(ID_EDIT_Y, OnUpdateEditY)
218 ON_UPDATE_COMMAND_UI(ID_EDIT_Z, OnUpdateEditZ)
219 ON_UPDATE_COMMAND_UI(ID_EDIT_MOVEELEMENT, OnUpdateEditMoveelement)
220 ON_UPDATE_COMMAND_UI(ID_EDIT_MOVE_FX, OnUpdateEditMoveFX)
221 ON_UPDATE_COMMAND_UI(ID_EDIT_MOVE_FX_USER_MATRIX, OnUpdateEditMoveFXUserMatrix)
222 ON_UPDATE_COMMAND_UI(ID_SCENE_SETLIGHTGROUPFACTOR, OnUpdateWindowLightGroup)
223 ON_COMMAND(ID_HELP_ABOUTOBJECTVIEWER, OnHelpAboutobjectviewer)
224 ON_COMMAND(IDM_REMOVE_ALL_INSTANCES_FROM_SCENE, OnRemoveAllInstancesFromScene)
225 ON_COMMAND_RANGE(IDM_ACTIVATE_TEXTURE_SET_1, IDM_ACTIVATE_TEXTURE_SET_8, OnActivateTextureSet)
226 ON_COMMAND(IDM_SHUFFLE_TEXTURE_SET, OnShuffleTextureSet)
227 ON_COMMAND(ID_WINDOW_VEGETABLE, OnWindowVegetable)
228 ON_UPDATE_COMMAND_UI(ID_WINDOW_VEGETABLE, OnUpdateWindowVegetable)
229 ON_COMMAND(ID_WINDOW_GLOBALWIND, OnWindowGlobalwind)
230 ON_UPDATE_COMMAND_UI(ID_WINDOW_GLOBALWIND, OnUpdateWindowGlobalwind)
231 ON_COMMAND(ID_EDIT_MOVE_OBJECT_LIGHT_TEST, OnEditMoveObjectLightTest)
232 ON_UPDATE_COMMAND_UI(ID_EDIT_MOVE_OBJECT_LIGHT_TEST, OnUpdateEditMoveObjectLightTest)
233 ON_COMMAND(ID_EDIT_MOVECAMERA, OnEditMovecamera)
234 ON_UPDATE_COMMAND_UI(ID_EDIT_MOVECAMERA, OnUpdateEditMovecamera)
235 ON_COMMAND(ID_EDIT_MOVESCENE, OnEditMovescene)
236 ON_UPDATE_COMMAND_UI(ID_EDIT_MOVESCENE, OnUpdateEditMovescene)
237 ON_COMMAND(ID_VIEW_RESET_SCENE_ROOT, OnViewResetSceneRoot)
238 ON_COMMAND(ID_VIEW_RESET_FX_ROOT, OnViewResetFXRoot)
239 ON_COMMAND(IDM_RESET_FX_USER_MATRIX, OnViewResetFXUserMatrix)
240 ON_COMMAND(ID_VIEW_SET_SCENE_ROTATION, OnViewSetSceneRotation)
241 ON_COMMAND(ID_SHOOT_SCENE, OnShootScene)
242 ON_COMMAND(ID_WINDOW_SKELETON_SCALE, OnWindowSkeletonScale)
243 ON_UPDATE_COMMAND_UI(ID_WINDOW_SKELETON_SCALE, OnUpdateWindowSkeletonScale)
244 ON_COMMAND(ID_WINDOW_TUNE_MRM, OnWindowTuneMRM)
245 ON_UPDATE_COMMAND_UI(ID_WINDOW_TUNE_MRM, OnUpdateWindowTuneMRM)
246 //}}AFX_MSG_MAP
247 ON_COMMAND_RANGE(ID_SCENE_CAMERA_FIRST, ID_SCENE_CAMERA_LAST, OnSceneCamera)
248 ON_UPDATE_COMMAND_UI_RANGE(ID_SCENE_CAMERA_FIRST, ID_SCENE_CAMERA_LAST, OnUpdateSceneCamera)
249 END_MESSAGE_MAP()
253 /////////////////////////////////////////////////////////////////////////////
254 // CMainFrame message handlers
256 LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
258 // TODO: Add your specialized code here and/or call the base class
259 if (CNELU::Driver)
260 DriverWindowProc (CNELU::Driver, m_hWnd, message, wParam, lParam);
262 return CFrameWnd::WindowProc(message, wParam, lParam);
265 // ***************************************************************************
267 void CMainFrame::update ()
269 ObjView->_AnimationDlg->ShowWindow (AnimationWindow?SW_SHOW:SW_HIDE);
270 ObjView->_AnimationSetDlg->ShowWindow (AnimationSetWindow?SW_SHOW:SW_HIDE);
271 ObjView->_SlotDlg->ShowWindow (MixerSlotsWindow?SW_SHOW:SW_HIDE);
272 ObjView->_ParticleDlg->ShowWindow (ParticlesWindow?SW_SHOW:SW_HIDE);
273 ObjView->_DayNightDlg->ShowWindow (DayNightWindow?SW_SHOW:SW_HIDE);
274 ObjView->_WaterPoolDlg->ShowWindow (WaterPoolWindow?SW_SHOW:SW_HIDE);
275 ObjView->_VegetableDlg->ShowWindow (VegetableWindow?SW_SHOW:SW_HIDE);
276 ObjView->_GlobalWindDlg->ShowWindow (GlobalWindWindow?SW_SHOW:SW_HIDE);
277 ObjView->_SoundAnimDlg->ShowWindow (SoundAnimWindow?SW_SHOW:SW_HIDE);
278 ObjView->_LightGroupDlg->ShowWindow (LightGroupWindow?SW_SHOW:SW_HIDE);
279 ObjView->_ChooseFrameDelayDlg->ShowWindow (ChooseFrameDelayWindow?SW_SHOW:SW_HIDE);
280 ObjView->_ChooseBGColorDlg->ShowWindow (ChooseBGColorWindow?SW_SHOW:SW_HIDE);
281 ObjView->_ChooseSunColorDlg->ShowWindow (ChooseSunColorWindow?SW_SHOW:SW_HIDE);
282 ObjView->_SkeletonScaleDlg->ShowWindow (SkeletonScaleWindow?SW_SHOW:SW_HIDE);
283 ObjView->_TuneMRMDlg->ShowWindow (TuneMRMWindow?SW_SHOW:SW_HIDE);
286 // ***************************************************************************
288 void CMainFrame::registerValue (bool read)
290 if (read)
292 // Get value from the register
293 HKEY hKey;
294 if (RegOpenKeyEx(HKEY_CURRENT_USER, REGKEY_OBJ_VIEW_SCENE_DLG, 0, KEY_READ, &hKey)==ERROR_SUCCESS)
296 DWORD len=sizeof (BOOL);
297 DWORD type;
298 NLMISC::CRGBA bgCol ;
299 RegQueryValueEx (hKey, _T("ViewAnimation"), 0, &type, (LPBYTE)&AnimationWindow, &len);
300 len=sizeof (BOOL);
301 RegQueryValueEx (hKey, _T("ViewAnimationSet"), 0, &type, (LPBYTE)&AnimationSetWindow, &len);
302 len=sizeof (BOOL);
303 RegQueryValueEx (hKey, _T("ViewSlots"), 0, &type, (LPBYTE)&MixerSlotsWindow, &len);
304 len=sizeof (BOOL);
305 RegQueryValueEx (hKey, _T("ViewParticles"), 0, &type, (LPBYTE)&ParticlesWindow, &len);
306 len=sizeof (BOOL);
307 RegQueryValueEx (hKey, _T("ViewDayNight"), 0, &type, (LPBYTE)&DayNightWindow, &len);
308 len=sizeof (BOOL);
309 RegQueryValueEx (hKey, _T("ViewWaterPool"), 0, &type, (LPBYTE)&WaterPoolWindow, &len);
310 len=sizeof (BOOL);
311 RegQueryValueEx (hKey, _T("ViewVegetable"), 0, &type, (LPBYTE)&VegetableWindow, &len);
312 len=sizeof (BOOL);
313 RegQueryValueEx (hKey, _T("ViewGlobalWind"), 0, &type, (LPBYTE)&GlobalWindWindow, &len);
314 len=sizeof (BOOL);
315 RegQueryValueEx (hKey, _T("ViewSoundAnimWind"), 0, &type, (LPBYTE)&GlobalWindWindow, &len);
316 len=sizeof (float);
317 RegQueryValueEx (hKey, _T("MoveSpeed"), 0, &type, (LPBYTE)&MoveSpeed, &len);
318 len=sizeof (uint);
319 RegQueryValueEx (hKey, _T("ObjectMode"), 0, &type, (LPBYTE)&MoveMode, &len);
320 len=sizeof(NLMISC::CRGBA) ;
321 RegQueryValueEx (hKey, _T("BackGroundColor"), 0, &type, (LPBYTE)&BgColor, &len);
322 len=sizeof (float);
323 RegQueryValueEx (hKey, _T("GlobalWindPower"), 0, &type, (LPBYTE)&GlobalWindPower, &len);
324 len=sizeof (BOOL);
325 RegQueryValueEx (hKey, _T("ViewChooseFrameDelay"), 0, &type, (LPBYTE)&ChooseFrameDelayWindow, &len);
326 len=sizeof (BOOL);
327 RegQueryValueEx (hKey, _T("ViewChooseBGColor"), 0, &type, (LPBYTE)&ChooseBGColorWindow, &len);
328 len=sizeof (BOOL);
329 RegQueryValueEx (hKey, _T("ViewChooseSunColor"), 0, &type, (LPBYTE)&ChooseSunColorWindow, &len);
330 len=sizeof (BOOL);
331 RegQueryValueEx (hKey, _T("ViewSkeletonScaleWindow"), 0, &type, (LPBYTE)&SkeletonScaleWindow, &len);
332 len=sizeof (BOOL);
333 RegQueryValueEx (hKey, _T("ViewTuneMRMWindow"), 0, &type, (LPBYTE)&TuneMRMWindow, &len);
336 else
338 HKEY hKey;
339 if (RegCreateKey(HKEY_CURRENT_USER, REGKEY_OBJ_VIEW_SCENE_DLG, &hKey)==ERROR_SUCCESS)
341 RegSetValueEx(hKey, _T("ViewAnimation"), 0, REG_BINARY, (LPBYTE)&AnimationWindow, sizeof(bool));
342 RegSetValueEx(hKey, _T("ViewAnimationSet"), 0, REG_BINARY, (LPBYTE)&AnimationSetWindow, sizeof(bool));
343 RegSetValueEx(hKey, _T("ViewSlots"), 0, REG_BINARY, (LPBYTE)&MixerSlotsWindow, sizeof(bool));
344 RegSetValueEx(hKey, _T("ViewParticles"), 0, REG_BINARY, (LPBYTE)&ParticlesWindow, sizeof(bool));
345 RegSetValueEx(hKey, _T("ViewDayNight"), 0, REG_BINARY, (LPBYTE)&DayNightWindow, sizeof(bool));
346 RegSetValueEx(hKey, _T("ViewWaterPool"), 0, REG_BINARY, (LPBYTE)&WaterPoolWindow, sizeof(bool));
347 RegSetValueEx(hKey, _T("ViewDayNight"), 0, REG_BINARY, (LPBYTE)&DayNightWindow, sizeof(bool));
348 RegSetValueEx(hKey, _T("ViewVegetable"), 0, REG_BINARY, (LPBYTE)&VegetableWindow, sizeof(bool));
349 RegSetValueEx(hKey, _T("ViewGlobalWind"), 0, REG_BINARY, (LPBYTE)&GlobalWindWindow, sizeof(bool));
350 RegSetValueEx(hKey, _T("ViewSoundAnimWind"), 0, REG_BINARY, (LPBYTE)&SoundAnimWindow, sizeof(bool));
351 RegSetValueEx(hKey, _T("ViewLightGroupWind"), 0, REG_BINARY, (LPBYTE)&LightGroupWindow, sizeof(bool));
352 RegSetValueEx(hKey, _T("ViewChooseFrameDelay"), 0, REG_BINARY, (LPBYTE)&ChooseFrameDelayWindow, sizeof(bool));
353 RegSetValueEx(hKey, _T("ViewChooseBGColor"), 0, REG_BINARY, (LPBYTE)&ChooseBGColorWindow, sizeof(bool));
354 RegSetValueEx(hKey, _T("ViewChooseSunColor"), 0, REG_BINARY, (LPBYTE)&ChooseSunColorWindow, sizeof(bool));
355 RegSetValueEx(hKey, _T("MoveSpeed"), 0, REG_BINARY, (LPBYTE)&MoveSpeed, sizeof(float));
356 RegSetValueEx(hKey, _T("ObjectMode"), 0, REG_BINARY, (LPBYTE)&MoveMode, sizeof(uint));
357 RegSetValueEx(hKey, _T("BackGroundColor"), 0, REG_BINARY, (LPBYTE)&BgColor, sizeof(NLMISC::CRGBA));
358 RegSetValueEx(hKey, _T("GlobalWindPower"), 0, REG_BINARY, (LPBYTE)&GlobalWindPower, sizeof(float));
359 RegSetValueEx(hKey, _T("ViewSkeletonScaleWindow"), 0, REG_BINARY, (LPBYTE)&SkeletonScaleWindow, sizeof(bool));
360 RegSetValueEx(hKey, _T("ViewTuneMRMWindow"), 0, REG_BINARY, (LPBYTE)&TuneMRMWindow, sizeof(bool));
365 // ***************************************************************************
367 void CMainFrame::OnResetCamera()
369 // One object found at least
370 bool found=false;
372 // Pointer on the CMesh;
373 CVector hotSpot=CVector (0,0,0);
375 // Reset the radius
376 float radius=10.f;
378 // Look for a first mesh
379 uint m;
380 for (m=0; m<ObjView->_ListInstance.size(); m++)
382 CTransformShape *pTransform=dynamic_cast<CTransformShape*>(ObjView->_ListInstance[m]->TransformShape);
383 if (pTransform)
385 IShape *pShape=pTransform->Shape;
386 CSkeletonModel *pSkelModel=pTransform->getSkeletonModel ();
388 // Get bounding box
389 CAABBox boundingBox;
390 pShape->getAABBox(boundingBox);
392 if (!pSkelModel)
394 // Reset the hotspot
395 hotSpot=pTransform->getMatrix()*boundingBox.getCenter();
397 // Reset the radius
398 radius=boundingBox.getRadius();
399 radius=pTransform->getMatrix().mulVector (CVector (radius, 0, 0)).norm();
400 found=true;
401 m++;
402 break;
404 else
406 // Get first bone
407 if (pSkelModel->Bones.size())
409 // Ok, it is the root.
410 hotSpot=pSkelModel->Bones[0].getMatrix()*boundingBox.getCenter();
412 // Reset the radius
413 radius=boundingBox.getRadius();
414 radius=pSkelModel->Bones[0].getMatrix().mulVector (CVector (radius, 0, 0)).norm();
415 found=true;
416 m++;
417 break;
423 // For each model in the list
424 for (; m<ObjView->_ListInstance.size(); m++)
426 // Pointer on the CTransformShape;
427 CTransformShape *pTransform=dynamic_cast<CTransformShape*>(ObjView->_ListInstance[m]->TransformShape);
428 if (pTransform)
430 IShape *pShape=pTransform->Shape;
431 CSkeletonModel *pSkelModel=pTransform->getSkeletonModel ();
433 // New radius and hotSpot
434 CVector hotSpot2;
435 float radius2;
436 bool setuped=false;
438 // Get the bounding box
439 CAABBox boundingBox;
440 pShape->getAABBox(boundingBox);
442 if (!pSkelModel)
444 // Get the hotspot
445 hotSpot2=pTransform->getMatrix()*boundingBox.getCenter();
447 // Get the radius
448 radius2=boundingBox.getRadius();
449 radius2=pTransform->getMatrix().mulVector (CVector (radius2, 0, 0)).norm();
451 // Ok found it
452 setuped=true;
454 else
456 // Get first bone
457 if (pSkelModel->Bones.size())
459 // Get the hotspot
460 hotSpot2=pSkelModel->Bones[0].getMatrix()*boundingBox.getCenter();
462 // Get the radius
463 radius2=boundingBox.getRadius();
464 radius2=pSkelModel->Bones[0].getMatrix().mulVector (CVector (radius2, 0, 0)).norm();
466 // Ok found it
467 setuped=true;
471 if (setuped)
473 // *** Merge with previous
475 // Get vector center to center
476 CVector vect=hotSpot-hotSpot2;
477 vect.normalize();
479 // Get the right position
480 CVector right=hotSpot+vect*radius;
481 if ((right-hotSpot2).norm()<radius2)
482 right=hotSpot2+vect*radius2;
484 // Get the left position
485 CVector left=hotSpot2-vect*radius2;
486 if ((left-hotSpot).norm()<radius)
487 left=hotSpot-vect*radius;
489 // Get new center
490 hotSpot=(left+right)/2.f;
492 // Get new size
493 radius=(left-right).norm()/2.f;
498 // Setup scene center
499 ObjView->_SceneCenter=hotSpot;
501 // Setup camera
502 CNELU::Camera->lookAt (hotSpot+CVector(0.57735f,0.57735f,0.57735f)*radius, hotSpot);
504 // Setup mouse listener
505 ObjView->_MouseListener.setMatrix (CNELU::Camera->getMatrix());
506 ObjView->_MouseListener.setFrustrum (CNELU::Camera->getFrustum());
507 ObjView->_MouseListener.setViewport (CViewport());
508 ObjView->_MouseListener.setHotSpot (hotSpot);
509 ObjView->_MouseListener.setMouseMode (CEvent3dMouseListener::edit3d);
511 // reset ObjectLightTest.
512 ObjView->_ObjectLightTestMatrix.setPos(hotSpot);
515 void CMainFrame::OnClear()
517 // *** Clear the scene.
519 // Remove all the instance
520 ObjView->removeAllInstancesFromScene();
521 ToolBar.Invalidate();
524 void CMainFrame::OnReloadTextures()
526 // Reload all the textures
527 ObjView->reloadTextures ();
530 void CMainFrame::OnEditX()
532 X^=true;
533 ObjView->getMouseListener().enableModelTranslationAxis(CEvent3dMouseListener::xAxis, X!=0);
536 void CMainFrame::OnEditY()
538 Y^=true;
539 ObjView->getMouseListener().enableModelTranslationAxis(CEvent3dMouseListener::yAxis, Y!=0);
542 void CMainFrame::OnEditZ()
544 Z^=true;
545 ObjView->getMouseListener().enableModelTranslationAxis(CEvent3dMouseListener::zAxis, Z!=0);
548 void CMainFrame::OnEnableElementXrotate()
550 ObjView->getMouseListener().setModelMatrixRotationAxis(CEvent3dMouseListener::xAxis);
553 void CMainFrame::OnEnableElementYrotate()
555 ObjView->getMouseListener().setModelMatrixRotationAxis(CEvent3dMouseListener::yAxis);
558 void CMainFrame::OnEnableElementZrotate()
560 ObjView->getMouseListener().setModelMatrixRotationAxis(CEvent3dMouseListener::zAxis);
563 void CMainFrame::OnFileExit()
565 DestroyWindow ();
568 void CMainFrame::OnFileLoadconfig()
570 // Update UI
571 update ();
573 // Create a dialog
574 static TCHAR BASED_CODE szFilter[] = _T("NeL Object viewer config (*.ovcgf)|*.ovcgf|All Files (*.*)|*.*||");
575 CFileDialog fileDlg( TRUE, _T(".ovcgf"), _T("*.ovcgf"), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter);
576 if (fileDlg.DoModal()==IDOK)
578 // Open the file
579 CIFile file;
580 if (file.open(tStrToUtf8(fileDlg.GetPathName())))
584 ObjView->serial (file);
585 if (!ObjView->ParticleWorkspaceFilename.empty())
587 CParticleDlg *pd = ObjView->getParticleDialog();
588 pd->checkModifiedWorkSpace();
589 pd->loadWorkspace(ObjView->ParticleWorkspaceFilename);
590 if (pd->getParticleWorkspace())
592 pd->getParticleWorkspace()->restickAllObjects(ObjView);
596 catch (const Exception& e)
598 MessageBox(nlUtf8ToTStr(e.what()), _T("NeL object viewer"), MB_OK | MB_ICONEXCLAMATION);
601 else
603 // Create a message
604 CString msg;
605 msg.Format(_T("Can't open the file %s for reading."), (LPCTSTR)fileDlg.GetPathName());
606 MessageBox (msg, _T("NeL object viewer"), MB_OK|MB_ICONEXCLAMATION);
611 #include <dlgs.h> // for standard control IDs for commdlg
613 void CMainFrame::OnFileOpen()
615 // update UI
616 update ();
618 // Create a dialog
619 static TCHAR BASED_CODE szFilter[] =
620 _T("All NeL Files (*.shape;*.ps;*.ig)\0*.shape;*.ps;*.ig\0")
621 _T("NeL Shape Files (*.shape)\0*.shape\0")
622 _T("NeL Particule System Files (*.ps)\0*.ps\0")
623 _T("NeL Instance Group Files (*.ig)\0*.ig\0")
624 _T("All Files (*.*)\0*.*\0\0");
626 // Filename buffer
627 TCHAR buffer[65535];
628 buffer[0]=0;
630 OPENFILENAME openFile;
631 memset (&openFile, 0, sizeof (OPENFILENAME));
632 openFile.lStructSize = sizeof (OPENFILENAME);
633 openFile.hwndOwner = this->m_hWnd;
634 openFile.lpstrFilter = szFilter;
635 openFile.nFilterIndex = 0;
636 openFile.lpstrFile = buffer;
637 openFile.nMaxFile = 65535;
638 openFile.Flags = OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT|OFN_ENABLESIZING|OFN_EXPLORER;
639 openFile.lpstrDefExt = _T("*.shape;*.ig;*.ps");
642 if (GetOpenFileName(&openFile))
644 // Build an array of name
645 std::vector<std::string> meshFilename;
647 // Filename pointer
648 TCHAR *c=buffer;
650 // Read the path
651 CString path = buffer;
652 if (path.GetLength()>openFile.nFileOffset)
654 // Double zero at the end
655 c[path.GetLength()+1]=0;
657 // Path is empty
658 path.Empty();
660 else
662 // Adda slash
663 path += "\\";
665 // Look for the next string
666 while (*(c++)) {}
669 // For each file selected
670 while (*c)
672 // File name
673 char filename[256];
674 char *ptr=filename;
676 // Read a file name
677 while (*c)
679 *(ptr++)=*(c++);
681 *ptr=0;
682 c++;
684 // File name
685 CString name = path + filename;
687 // file is an ig ?
688 if (name.Find(_T(".ig")) != -1)
690 // Load the instance group
691 if (ObjView->loadInstanceGroup (tStrToUtf8(name)))
693 // Reset the camera
694 OnResetCamera();
696 // Touch the channel mixer
697 ObjView->reinitChannels ();
700 else
702 // Add it in the array
703 meshFilename.push_back (tStrToUtf8(name));
707 // Some mesh to load ?
708 if ( !meshFilename.empty() )
710 // Create a dialog for the skel
711 static TCHAR BASED_CODE szFilter2[] = _T("NeL Skeleton Files (*.skel)|*.skel|All Files (*.*)|*.*||");
712 CFileDialog fileDlg2 ( TRUE, _T(".skel"), _T("*.skel"), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter2);
713 if (fileDlg2.DoModal()==IDOK)
715 // Load the shape with a skeleton
716 if (ObjView->loadMesh (meshFilename, tStrToUtf8(fileDlg2.GetPathName())))
718 // Reset the camera
719 OnResetCamera();
721 // Touch the channel mixer
722 ObjView->reinitChannels ();
725 else
727 // Load the shape without skeleton
728 if (ObjView->loadMesh (meshFilename, ""))
730 // Reset the camera
731 OnResetCamera();
733 // Touch the channel mixer
734 ObjView->reinitChannels ();
741 void CMainFrame::OnFileSaveconfig()
743 // Update UI
744 update ();
746 // Create a dialog
747 static TCHAR BASED_CODE szFilter[] = _T("NeL Object viewer config (*.ovcgf)|*.ovcgf|All Files (*.*)|*.*||");
748 CFileDialog fileDlg( FALSE, _T(".ovcgf"), _T("*.ovcgf"), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter);
749 if (fileDlg.DoModal()==IDOK)
751 ObjView->ParticleWorkspaceFilename.clear();
752 CParticleWorkspace *pw = ObjView->getParticleDialog()->getParticleWorkspace();
753 if (pw && pw->getNumNode() != 0)
755 if (localizedMessageBox(*this, IDS_INCLUDE_PARTICLE_WORKSPACE_INFOS, IDS_OBJECT_VIEWER, MB_YESNO|MB_ICONQUESTION) == IDYES)
757 ObjView->ParticleWorkspaceFilename = pw->getFilename();
760 // Open the file
761 COFile file;
762 if (file.open (tStrToUtf8(fileDlg.GetPathName())))
766 ObjView->serial(file);
768 catch (const Exception& e)
770 MessageBox(nlUtf8ToTStr(e.what()), _T("NeL object viewer"), MB_OK | MB_ICONEXCLAMATION);
773 else
775 // Create a message
776 CString msg;
777 msg.Format(_T("Can't open the file %s for writing"), (LPCTSTR)fileDlg.GetPathName());
778 MessageBox (msg, _T("NeL object viewer"), MB_OK|MB_ICONEXCLAMATION);
785 void CMainFrame::OnViewFirstpersonmode()
787 MoveMode=FirstMode;
788 ToolBar.Invalidate ();
791 void CMainFrame::OnViewObjectmode()
793 MoveMode=ObjectMode;
794 ToolBar.Invalidate ();
797 void CMainFrame::OnViewCamera()
799 MoveMode=CameraMode;
800 ToolBar.Invalidate ();
803 void CMainFrame::OnViewSetbackground()
805 static COLORREF colTab[16] = { 0, 0xff0000, 0x00ff00, 0xffff00, 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff
806 , 0x7f7f7f, 0xff7f7f, 0x7fff7f, 0xffff7f, 0x7f7fff, 0xff7fff, 0x7fffff, 0xff7f00 } ;
807 BgColor = ObjView->getBackGroundColor() ;
808 CHOOSECOLOR cc ;
809 cc.lStructSize = sizeof(CHOOSECOLOR) ;
810 cc.hwndOwner = this->m_hWnd ;
811 cc.Flags = CC_RGBINIT | CC_ANYCOLOR | CC_FULLOPEN ;
812 cc.rgbResult = RGB(BgColor.R, BgColor.G, BgColor.B) ;
813 cc.lpCustColors = colTab ;
815 if (::ChooseColor(&cc) == IDOK)
817 BgColor.R = (uint8) (cc.rgbResult & 0xff) ;
818 BgColor.G = (uint8) ((cc.rgbResult & 0xff00) >> 8) ;
819 BgColor.B = (uint8) ((cc.rgbResult & 0xff0000) >> 16) ;
821 ObjView->setBackGroundColor(BgColor) ;
825 void CMainFrame::OnViewSetmovespeed()
827 // Set value
828 CSetValueDlg valueDlg;
830 // Set default value
831 valueDlg.Value=toString (MoveSpeed).c_str();
832 valueDlg.Title="Select your move speed";
834 // Open dialog
835 if (valueDlg.DoModal ()==IDOK)
837 // Get deflaut value
838 NLMISC::fromString(tStrToUtf8(valueDlg.Value), MoveSpeed);
842 void CMainFrame::OnActivateFog()
844 FogActive = !FogActive;
845 if (FogActive)
847 CNELU::Driver->setupFog(FogStart, FogEnd, ObjView->getBackGroundColor());
848 CNELU::Driver->enableFog(true);
850 else
852 CNELU::Driver->enableFog(false);
854 CMenu *menu = GetMenu();
855 menu->CheckMenuItem(IDM_ACTIVATE_FOG, MF_BYCOMMAND | (FogActive ? MF_CHECKED : MF_UNCHECKED));
858 void CMainFrame::OnSetupFog()
860 CFogDlg fogDlg;
861 fogDlg.setFogStart(FogStart);
862 fogDlg.setFogEnd(FogEnd);
864 if (fogDlg.DoModal() == IDOK)
866 FogStart = fogDlg.getFogStart();
867 FogEnd = fogDlg.getFogEnd();
868 NLMISC::clamp(FogStart, 0.f, 1000.f);
869 NLMISC::clamp(FogEnd, 0.f, 1000.f);
870 CNELU::Driver->setupFog(FogStart, FogEnd, ObjView->getBackGroundColor());
875 void CMainFrame::OnShowSceneMatrix()
877 ObjView->setSceneMatrixVisible(!ObjView->getSceneMatrixVisible());
880 void CMainFrame::OnShowFXMatrix()
882 ObjView->setFXMatrixVisible(!ObjView->getFXMatrixVisible());
885 void CMainFrame::OnShowFXUserMatrix()
887 ObjView->setFXUserMatrixVisible(!ObjView->getFXUserMatrixVisible());
890 void CMainFrame::OnShowOcclusionTestMeshs()
892 ObjView->setOcclusionTestMeshsVisible(!ObjView->getOcclusionTestMeshsVisible());
896 void CMainFrame::OnUpdateShowSceneMatrix(CCmdUI* pCmdUI)
898 pCmdUI->SetCheck(ObjView->getSceneMatrixVisible());
901 void CMainFrame::OnUpdateShowFXMatrix(CCmdUI* pCmdUI)
903 pCmdUI->SetCheck(ObjView->getFXMatrixVisible());
906 void CMainFrame::OnUpdateShowFXUserMatrix(CCmdUI* pCmdUI)
908 pCmdUI->SetCheck(ObjView->getFXUserMatrixVisible());
911 void CMainFrame::OnUpdateShowOcclusionTestMeshs(CCmdUI* pCmdUI)
913 pCmdUI->SetCheck(ObjView->getOcclusionTestMeshsVisible());
918 void CMainFrame::OnWindowAnimation()
920 AnimationWindow^=true;
921 update ();
924 void CMainFrame::OnWindowAnimationset()
926 AnimationSetWindow^=true;
927 update ();
930 void CMainFrame::OnWindowMixersslots()
932 MixerSlotsWindow^=true;
933 update ();
936 void CMainFrame::OnWindowParticles()
938 ParticlesWindow^=true;
939 update ();
942 void CMainFrame::OnWindowDayNight()
944 DayNightWindow^=true;
945 update ();
948 void CMainFrame::OnWindowVegetable()
950 VegetableWindow^=true;
951 update ();
955 void CMainFrame::OnWindowWaterPool()
957 WaterPoolWindow^=true;
958 update ();
962 void CMainFrame::OnWindowGlobalwind()
964 GlobalWindWindow^= true;
965 update ();
968 void CMainFrame::OnWindowSoundAnim()
970 SoundAnimWindow^= true;
971 update ();
974 void CMainFrame::OnWindowChooseFrameDelay()
976 ChooseFrameDelayWindow^= true;
977 update ();
980 void CMainFrame::OnWindowChooseBGColor()
982 ChooseBGColorWindow^= true;
983 update ();
986 void CMainFrame::OnWindowChooseSunColor()
988 ChooseSunColorWindow^= true;
989 update ();
995 void CMainFrame::OnSetLightGroupFactor()
997 LightGroupWindow^= true;
998 update ();
1001 static UINT indicators[] =
1003 ID_SEPARATOR, // status line indicator
1004 /*ID_INDICATOR_CAPS,
1005 ID_INDICATOR_NUM,
1006 ID_INDICATOR_SCRL,*/
1009 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
1011 // Parent create
1012 if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
1013 return -1;
1015 // Create tool bar
1016 if (!ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
1017 | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
1018 !ToolBar.LoadToolBar(IDR_TOOL_EDIT))
1020 return -1; // fail to create
1023 // Create the status bar
1024 StatusBar.Create (this);
1025 StatusBar.SetIndicators (indicators,
1026 sizeof(indicators)/sizeof(UINT));
1028 // Docking
1029 ToolBar.SetButtonStyle (0, TBBS_CHECKGROUP);
1030 ToolBar.SetButtonStyle (1, TBBS_CHECKGROUP);
1031 ToolBar.SetButtonStyle (2, TBBS_CHECKGROUP);
1032 ToolBar.SetButtonStyle (4, TBBS_CHECKBOX);
1033 ToolBar.SetButtonStyle (5, TBBS_CHECKBOX);
1034 ToolBar.SetButtonStyle (6, TBBS_CHECKBOX);
1035 ToolBar.SetButtonStyle (8, TBBS_CHECKGROUP);
1036 ToolBar.SetButtonStyle (9, TBBS_CHECKGROUP);
1037 ToolBar.SetButtonStyle (10, TBBS_CHECKGROUP);
1038 ToolBar.SetButtonStyle (11, TBBS_CHECKGROUP);
1039 ToolBar.EnableDocking(CBRS_ALIGN_ANY);
1041 InitialUpdateFrame (NULL, TRUE);
1042 EnableDocking(CBRS_ALIGN_ANY);
1043 DockControlBar(&ToolBar);
1045 return 0;
1048 BOOL CMainFrame::OnEraseBkgnd(CDC* pDC)
1050 // TODO: Add your message handler code here and/or call default
1051 return TRUE;
1054 void CMainFrame::OnUpdateWindowAnimation(CCmdUI* pCmdUI)
1056 pCmdUI->SetCheck (AnimationWindow);
1059 void CMainFrame::OnUpdateWindowAnimationset(CCmdUI* pCmdUI)
1061 pCmdUI->SetCheck (AnimationSetWindow);
1064 void CMainFrame::OnUpdateWindowMixersslots(CCmdUI* pCmdUI)
1066 pCmdUI->SetCheck (MixerSlotsWindow);
1069 void CMainFrame::OnUpdateWindowParticles(CCmdUI* pCmdUI)
1071 pCmdUI->SetCheck (ParticlesWindow);
1074 void CMainFrame::OnUpdateWindowDayNight(CCmdUI* pCmdUI)
1076 pCmdUI->SetCheck (DayNightWindow);
1079 void CMainFrame::OnUpdateWindowWaterPool(CCmdUI* pCmdUI)
1081 pCmdUI->SetCheck (WaterPoolWindow);
1084 void CMainFrame::OnUpdateWindowVegetable(CCmdUI* pCmdUI)
1086 pCmdUI->SetCheck (VegetableWindow);
1089 void CMainFrame::OnUpdateWindowGlobalwind(CCmdUI* pCmdUI)
1091 pCmdUI->SetCheck (GlobalWindWindow);
1094 void CMainFrame::OnUpdateWindowSoundAnim(CCmdUI* pCmdUI)
1096 pCmdUI->SetCheck (SoundAnimWindow);
1099 void CMainFrame::OnUpdateWindowChooseFrameDelay(CCmdUI* pCmdUI)
1101 pCmdUI->SetCheck (ChooseFrameDelayWindow);
1104 void CMainFrame::OnUpdateWindowBGColor(CCmdUI* pCmdUI)
1106 pCmdUI->SetCheck (ChooseBGColorWindow);
1109 void CMainFrame::OnUpdateWindowSunColor(CCmdUI* pCmdUI)
1111 pCmdUI->SetCheck (ChooseSunColorWindow);
1114 void CMainFrame::OnUpdateWindowLightGroup(CCmdUI* pCmdUI)
1116 pCmdUI->SetCheck (LightGroupWindow);
1119 void CMainFrame::OnUpdateViewObjectmode(CCmdUI* pCmdUI)
1121 pCmdUI->SetCheck (MoveMode == ObjectMode);
1124 void CMainFrame::OnUpdateViewFirstpersonmode(CCmdUI* pCmdUI)
1126 pCmdUI->SetCheck (MoveMode == FirstMode);
1129 void CMainFrame::OnUpdateViewCamera(CCmdUI* pCmdUI)
1131 pCmdUI->SetCheck (MoveMode == CameraMode);
1132 pCmdUI->Enable (ObjView->getNumCamera () != 0);
1135 void CMainFrame::OnUpdateEditX(CCmdUI* pCmdUI)
1137 pCmdUI->SetCheck (X);
1140 void CMainFrame::OnUpdateEditY(CCmdUI* pCmdUI)
1142 pCmdUI->SetCheck (Y);
1145 void CMainFrame::OnUpdateEditZ(CCmdUI* pCmdUI)
1147 pCmdUI->SetCheck (Z);
1150 void CMainFrame::OnHelpAboutobjectviewer()
1152 CAboutDialog about;
1153 about.DoModal();
1157 ///===========================================================================================
1158 void CMainFrame::OnRemoveAllInstancesFromScene()
1160 if (MessageBox(_T("Delete all instances from scene ?"), _T("Object Viewer"), MB_YESNO) == IDYES)
1162 ObjView->removeAllInstancesFromScene();
1164 // Reset the camera
1165 OnResetCamera();
1167 // Touch the channel mixer
1168 ObjView->reinitChannels ();
1172 ///===========================================================================================
1173 void CMainFrame::OnActivateTextureSet(UINT nID)
1175 /// convert ID to index
1176 static const uint convIndex[] =
1178 0, 3, 1, 2, 4, 5, 6, 7
1181 ObjView->activateTextureSet(convIndex[nID - IDM_ACTIVATE_TEXTURE_SET_1]);
1185 void CMainFrame::OnShuffleTextureSet()
1187 ObjView->shuffleTextureSet();
1191 // ***************************************************************************
1192 // ***************************************************************************
1193 // Mouse Edit Mode
1194 // ***************************************************************************
1195 // ***************************************************************************
1198 // ***************************************************************************
1199 void CMainFrame::OnEditMovecamera()
1201 // no op if already the case
1202 if(isMoveCamera())
1203 return;
1205 MouseMoveType= MoveCamera;
1206 UpdateData() ;
1207 ToolBar.Invalidate ();
1209 ObjView->getMouseListener().enableModelMatrixEdition(false) ;
1210 ObjView->getMouseListener().enableTranslateXYInWorld(false);
1213 void CMainFrame::OnEditMovescene()
1215 // no op if already the case
1216 if(isMoveSceneRoot())
1217 return;
1219 MouseMoveType= MoveSceneRoot;
1220 UpdateData() ;
1221 ToolBar.Invalidate ();
1223 ObjView->getMouseListener().enableModelMatrixEdition(true) ;
1224 ObjView->getMouseListener().enableTranslateXYInWorld(false);
1225 ObjView->getMouseListener().setModelMatrix(ObjView->_SceneRoot->getMatrix()) ;
1226 // Each move must be multiplied by identity
1227 ObjView->getMouseListener().setModelMatrixTransformMove(CMatrix::Identity);
1230 void CMainFrame::OnEditMoveelement()
1232 // no op if already the case
1233 if(isMoveElement())
1234 return;
1236 MouseMoveType= MoveElement;
1237 UpdateData() ;
1238 ToolBar.Invalidate ();
1240 ObjView->getMouseListener().enableModelMatrixEdition(true) ;
1241 ObjView->getMouseListener().enableTranslateXYInWorld(false);
1242 ObjView->getMouseListener().setModelMatrix(ObjView->getParticleDialog()->getElementMatrix()) ;
1243 // Each move must be multiplied by inverse of scene root matrix.
1244 //ObjView->getMouseListener().setModelMatrixTransformMove(ObjView->_SceneRoot->getMatrix().inverted());
1245 ObjView->getMouseListener().setModelMatrixTransformMove(CMatrix::Identity);
1247 /*ctrl->EnableXCtrl.EnableWindow(MoveElement) ;
1248 EnableYCtrl.EnableWindow(MoveElement) ;
1249 EnableZCtrl.EnableWindow(MoveElement) ;*/
1252 void CMainFrame::OnEditMoveFX()
1254 // no op if already the case
1255 if(isMoveFX())
1256 return;
1258 MouseMoveType= MoveFX;
1259 UpdateData() ;
1260 ToolBar.Invalidate ();
1262 ObjView->getMouseListener().enableModelMatrixEdition(true) ;
1263 ObjView->getMouseListener().enableTranslateXYInWorld(false);
1264 ObjView->getMouseListener().setModelMatrix(ObjView->getParticleDialog()->getPSWorldMatrix()) ;
1265 // Each move must be multiplied by inverese of scene root matrix.
1266 //ObjView->getMouseListener().setModelMatrixTransformMove(ObjView->_SceneRoot->getMatrix().inverted());
1267 ObjView->getMouseListener().setModelMatrixTransformMove(CMatrix::Identity);
1269 /*ctrl->EnableXCtrl.EnableWindow(MoveElement) ;
1270 EnableYCtrl.EnableWindow(MoveElement) ;
1271 EnableZCtrl.EnableWindow(MoveElement) ;*/
1274 void CMainFrame::OnEditMoveFXUserMatrix()
1276 // no op if already the case
1277 if(isMoveFXUserMatrix())
1278 return;
1280 MouseMoveType= MoveFXUserMatrix;
1281 UpdateData() ;
1282 ToolBar.Invalidate ();
1284 ObjView->getMouseListener().enableModelMatrixEdition(true) ;
1285 ObjView->getMouseListener().enableTranslateXYInWorld(false);
1286 ObjView->getMouseListener().setModelMatrix(ObjView->getFXUserMatrix());
1287 // Each move must be multiplied by inverese of scene root matrix.
1288 //ObjView->getMouseListener().setModelMatrixTransformMove(ObjView->_SceneRoot->getMatrix().inverted());
1289 ObjView->getMouseListener().setModelMatrixTransformMove(CMatrix::Identity);
1291 /*ctrl->EnableXCtrl.EnableWindow(MoveElement) ;
1292 EnableYCtrl.EnableWindow(MoveElement) ;
1293 EnableZCtrl.EnableWindow(MoveElement) ;*/
1298 void CMainFrame::OnEditMoveObjectLightTest()
1300 // no op if already the case
1301 if(isMoveObjectLightTest())
1302 return;
1304 MouseMoveType= MoveObjectLightTest;
1305 UpdateData() ;
1306 ToolBar.Invalidate ();
1308 ObjView->getMouseListener().enableModelMatrixEdition(true) ;
1309 // Better to move in XY world plane.
1310 ObjView->getMouseListener().enableTranslateXYInWorld(true);
1311 ObjView->getMouseListener().setModelMatrix(ObjView->_ObjectLightTestMatrix) ;
1312 // Each move must be multiplied by inverese of scene root matrix.
1313 ObjView->getMouseListener().setModelMatrixTransformMove(ObjView->_SceneRoot->getMatrix().inverted());
1316 // ***************************************************************************
1317 void CMainFrame::OnUpdateEditMovecamera(CCmdUI* pCmdUI)
1319 pCmdUI->SetCheck (isMoveCamera());
1322 void CMainFrame::OnUpdateEditMovescene(CCmdUI* pCmdUI)
1324 pCmdUI->SetCheck (isMoveSceneRoot());
1327 void CMainFrame:: OnUpdateEditMoveelement(CCmdUI* pCmdUI)
1329 pCmdUI->SetCheck (isMoveElement());
1332 void CMainFrame::OnUpdateEditMoveFX(CCmdUI* pCmdUI)
1334 pCmdUI->SetCheck (isMoveFX());
1335 if (ObjView->getParticleDialog())
1337 pCmdUI->Enable(!ObjView->getParticleDialog()->isPSStickedToSkeleton());
1341 void CMainFrame::OnUpdateEditMoveFXUserMatrix(CCmdUI* pCmdUI)
1343 pCmdUI->SetCheck (isMoveFXUserMatrix());
1347 void CMainFrame::OnUpdateEditMoveObjectLightTest(CCmdUI* pCmdUI)
1349 pCmdUI->SetCheck (isMoveObjectLightTest());
1353 void CMainFrame::OnViewResetSceneRoot()
1355 CMatrix ident;
1356 ObjView->_SceneRoot->setTransformMode(ITransformable::DirectMatrix);
1357 ObjView->_SceneRoot->setMatrix(ident);
1359 if(isMoveSceneRoot())
1361 ObjView->_MouseListener.setModelMatrix (ident);
1365 // ***************************************************************************
1366 void CMainFrame::OnViewResetFXRoot()
1368 CMatrix ident;
1369 ObjView->_ParticleDlg->setPSMatrix(ident);
1370 if(isMoveFX())
1372 ObjView->_MouseListener.setModelMatrix (ident);
1376 // ***************************************************************************
1377 void CMainFrame::OnViewResetFXUserMatrix()
1379 CMatrix ident;
1380 ObjView->setFXUserMatrix(ident);
1381 if(isMoveFXUserMatrix())
1383 ObjView->_MouseListener.setModelMatrix (ident);
1388 // ***************************************************************************
1389 void CMainFrame::OnViewSetSceneRotation()
1391 CSceneRotDlg sceneRotDlg(this);
1392 sceneRotDlg.RotX= toString(_LastSceneRotX).c_str();
1393 sceneRotDlg.RotY= toString(_LastSceneRotY).c_str();
1394 sceneRotDlg.RotZ= toString(_LastSceneRotZ).c_str();
1395 if (sceneRotDlg.DoModal() == IDOK)
1397 // read value.
1398 NLMISC::fromString(tStrToUtf8(sceneRotDlg.RotX), _LastSceneRotX);
1399 NLMISC::fromString(tStrToUtf8(sceneRotDlg.RotY), _LastSceneRotY);
1400 NLMISC::fromString(tStrToUtf8(sceneRotDlg.RotZ), _LastSceneRotZ);
1402 float rotx= degToRad(_LastSceneRotX);
1403 float roty= degToRad(_LastSceneRotY);
1404 float rotz= degToRad(_LastSceneRotZ);
1406 CMatrix mat;
1407 mat.rotate(CVector(rotx, roty, rotz), CMatrix::ZXY);
1408 ObjView->_SceneRoot->setTransformMode(ITransformable::DirectMatrix);
1409 ObjView->_SceneRoot->setMatrix(mat);
1411 if(isMoveSceneRoot())
1413 ObjView->_MouseListener.setModelMatrix (mat);
1418 // ***************************************************************************
1420 void CMainFrame::OnShootScene()
1422 ObjView->shootScene ();
1425 // ***************************************************************************
1427 void CMainFrame::OnSceneCamera (UINT id)
1429 MoveMode = CameraMode;
1430 ObjView->setCurrentCamera (id-ID_SCENE_CAMERA_FIRST);
1431 ToolBar.UpdateDialogControls (this, TRUE);
1432 UpdateDialogControls (this, TRUE);
1433 UpdateData (FALSE);
1436 // ***************************************************************************
1438 void CMainFrame::OnUpdateSceneCamera(CCmdUI* pCmdUI)
1440 bool checked = ObjView->getCurrentCamera () == (sint)(pCmdUI->m_nID - ID_SCENE_CAMERA_FIRST);
1441 bool exist = (pCmdUI->m_nID - ID_SCENE_CAMERA_FIRST) < ObjView->getNumCamera ();
1442 pCmdUI->SetCheck ((checked && exist)?TRUE:FALSE);
1443 pCmdUI->Enable (exist?TRUE:FALSE);
1444 if (exist)
1446 CInstanceInfo *instance = ObjView->getInstance (ObjView->getCameraInstance (pCmdUI->m_nID - ID_SCENE_CAMERA_FIRST));
1447 nlassert (instance->Camera);
1448 std::string text = NLMISC::toString("Camera %s", instance->Saved.ShapeFilename.c_str());
1449 pCmdUI->SetText(nlUtf8ToTStr(text));
1451 else
1453 pCmdUI->SetText (_T("No camera"));
1457 // ***************************************************************************
1460 void CMainFrame::OnWindowSkeletonScale()
1462 SkeletonScaleWindow^= true;
1463 update ();
1466 void CMainFrame::OnUpdateWindowSkeletonScale(CCmdUI* pCmdUI)
1468 pCmdUI->SetCheck (SkeletonScaleWindow);
1471 // ***************************************************************************
1473 void CMainFrame::OnWindowTuneMRM()
1475 TuneMRMWindow^= true;
1476 update ();
1479 void CMainFrame::OnUpdateWindowTuneMRM(CCmdUI* pCmdUI)
1481 pCmdUI->SetCheck (TuneMRMWindow);
1484 void CMainFrame::OnSnapShotTool()
1486 CSnapshotToolDlg snapshotTool(ObjView);
1487 snapshotTool.DoModal();