]> icculus.org git repositories - taylor/freespace2.git/blob - src/pofview/pofviewview.cpp
SDL2 port - stage 2
[taylor/freespace2.git] / src / pofview / pofviewview.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 // PofViewView.cpp : implementation of the CPofViewView class
10 //
11
12 #include "stdafx.h"
13 #include "pofview.h"
14
15 #include "pofviewdoc.h"
16 #include "pofviewview.h"
17
18 #include "2d.h"
19 #include "3d.h"
20 #include "model.h"
21 #include "vecmat.h"
22 #include "bmpman.h"
23 #include "floating.h"
24 #include "key.h"
25 #include "physics.h"
26 #include "lighting.h"
27
28 #ifdef _DEBUG
29 #define new DEBUG_NEW
30 #undef THIS_FILE
31 static char THIS_FILE[] = __FILE__;
32 #endif
33
34 /////////////////////////////////////////////////////////////////////////////
35 // CPofViewView
36
37 IMPLEMENT_DYNCREATE(CPofViewView, CView)
38
39 BEGIN_MESSAGE_MAP(CPofViewView, CView)
40         //{{AFX_MSG_MAP(CPofViewView)
41         ON_WM_KEYDOWN()
42         ON_WM_KEYUP()
43         ON_WM_KILLFOCUS()
44         ON_WM_SETFOCUS()
45         ON_WM_SIZE()
46         ON_COMMAND(ID_POF_OUTLINE, OnPofOutline)
47         ON_UPDATE_COMMAND_UI(ID_POF_OUTLINE, OnUpdatePofOutline)
48         ON_COMMAND(ID_POF_LIGHTING, OnPofLighting)
49         ON_UPDATE_COMMAND_UI(ID_POF_LIGHTING, OnUpdatePofLighting)
50         ON_COMMAND(ID_POF_PIVOTS, OnPofPivots)
51         ON_UPDATE_COMMAND_UI(ID_POF_PIVOTS, OnUpdatePofPivots)
52         ON_UPDATE_COMMAND_UI(ID_DETAIL_1, OnUpdateDetail1)
53         ON_COMMAND(ID_DETAIL_1, OnDetail1)
54         ON_COMMAND(ID_DETAIL_2, OnDetail2)
55         ON_UPDATE_COMMAND_UI(ID_DETAIL_2, OnUpdateDetail2)
56         ON_COMMAND(ID_DETAIL_3, OnDetail3)
57         ON_UPDATE_COMMAND_UI(ID_DETAIL_3, OnUpdateDetail3)
58         ON_COMMAND(ID_DETAIL_4, OnDetail4)
59         ON_UPDATE_COMMAND_UI(ID_DETAIL_4, OnUpdateDetail4)
60         ON_COMMAND(ID_DETAIL_5, OnDetail5)
61         ON_UPDATE_COMMAND_UI(ID_DETAIL_5, OnUpdateDetail5)
62         ON_COMMAND(ID_DETAIL_6, OnDetail6)
63         ON_UPDATE_COMMAND_UI(ID_DETAIL_6, OnUpdateDetail6)
64         ON_COMMAND(ID_SHOW_TREE, OnShowTree)
65         ON_UPDATE_COMMAND_UI(ID_SHOW_TREE, OnUpdateShowTree)
66         ON_COMMAND(ID_POF_PATHS, OnPofPaths)
67         ON_UPDATE_COMMAND_UI(ID_POF_PATHS, OnUpdatePofPaths)
68         ON_COMMAND(ID_POF_RADIUS, OnPofRadius)
69         ON_UPDATE_COMMAND_UI(ID_POF_RADIUS, OnUpdatePofRadius)
70         ON_COMMAND(ID_POF_OVERWRITE, OnPofOverwrite)
71         ON_UPDATE_COMMAND_UI(ID_POF_OVERWRITE, OnUpdatePofOverwrite)
72         ON_COMMAND(IDC_SHOW_DAMAGED_SUBOBJECTS, OnShowDamagedSubobjects)
73         ON_UPDATE_COMMAND_UI(IDC_SHOW_DAMAGED_SUBOBJECTS, OnUpdateShowDamagedSubobjects)
74         ON_COMMAND(IDC_SHOW_DEBRIS, OnShowDebris)
75         ON_UPDATE_COMMAND_UI(IDC_SHOW_DEBRIS, OnUpdateShowDebris)
76         ON_WM_MOUSEMOVE()
77         ON_WM_LBUTTONDOWN()
78         ON_WM_LBUTTONUP()
79         ON_COMMAND(ID_POF_SMOOTHING, OnPofSmoothing)
80         ON_UPDATE_COMMAND_UI(ID_POF_SMOOTHING, OnUpdatePofSmoothing)
81         ON_COMMAND(ID_POF_TEXTURING, OnPofTexturing)
82         ON_UPDATE_COMMAND_UI(ID_POF_TEXTURING, OnUpdatePofTexturing)
83         ON_COMMAND(ID_POF_SHIELDS, OnPofShields)
84         ON_UPDATE_COMMAND_UI(ID_POF_SHIELDS, OnUpdatePofShields)
85         ON_COMMAND(IDC_TOGGLE_LIGHTING, OnToggleLighting)
86         ON_UPDATE_COMMAND_UI(IDC_TOGGLE_LIGHTING, OnUpdateToggleLighting)
87         ON_COMMAND(ID_INVISIBLEFACES, OnInvisiblefaces)
88         ON_UPDATE_COMMAND_UI(ID_INVISIBLEFACES, OnUpdateInvisiblefaces) 
89         ON_COMMAND(ID_BAY_PATHS, OnBayPaths)
90         ON_UPDATE_COMMAND_UI(ID_BAY_PATHS, OnUpdateBayPaths)
91         ON_COMMAND(ID_AUTOCEN, OnAutocenter)
92         ON_UPDATE_COMMAND_UI(ID_AUTOCEN, OnUpdateAutocenter)
93         //}}AFX_MSG_MAP
94         // Standard printing commands
95         ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
96         ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
97         ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
98 END_MESSAGE_MAP()
99
100 /////////////////////////////////////////////////////////////////////////////
101 // CPofViewView construction/destruction
102
103 CPofViewView::CPofViewView()
104 {
105         // TODO: add construction code here
106 //      m_ViewerPos = 
107 //      m_ViewerOrient = 
108
109         matrix temp_orient = IDENTITY_MATRIX;
110         vector temp_pos = {0.0f, 0.0f, -10.0f};
111
112         m_ViewerZoom = 0.8f;
113         m_ViewerPos = temp_pos;
114         m_ViewerOrient = temp_orient;
115         m_ObjectOrient = vmd_identity_matrix;
116         
117 //      m_ViewerPos.x=f2fl(0xadd3); m_ViewerPos.y = f2fl(0x32cbb); m_ViewerPos.z =f2fl(0x10006e);
118 //      m_ViewerOrient.rvec.x=f2fl(0xffff40e2); m_ViewerOrient.rvec.y=f2fl(0x2b3); m_ViewerOrient.rvec.z = f2fl(0xffff55b4);
119 //      m_ViewerOrient.uvec.x=f2fl(0x5cba); m_ViewerOrient.uvec.y=f2fl(0xd859); m_ViewerOrient.uvec.z = f2fl(0xffff9b5d);
120 //      m_ViewerOrient.fvec.x=f2fl(0x8edd); m_ViewerOrient.fvec.y=f2fl(0xffff772f); m_ViewerOrient.fvec.z=f2fl(0xffff5d80);
121
122         physics_init( &m_ViewerPhysics );
123         m_ViewerPhysics.flags |= PF_ACCELERATES | PF_SLIDE_ENABLED;
124
125         memset( &m_Viewer_ci, 0, sizeof(control_info) );
126
127         m_show_outline = 0;
128         m_dolighting = 0;
129         m_show_pivots = 0;
130         m_current_detail_level = 1;             // If 0, show debris
131         m_show_paths = 0;
132         m_show_radius = 0;
133         m_show_overwrite = 0;
134         m_show_destroyed_subobjects = 0;
135         m_show_shields = 0;
136         m_show_invisible_faces = 0;     
137         m_show_bay_paths = 0;
138         m_autocenter = 0;
139         
140         m_lights_on = 1;
141
142         m_mouse_inited = 0;
143         m_mouse_x = m_mouse_y = 0;
144         m_mouse_dx = m_mouse_dy = 0;
145         m_mouse_down = 0;
146         
147         m_texturing = 1;
148         m_smoothing = 1;
149         
150 //      CObjectTree m_subobjects;       
151 }
152
153 void CPofViewView::MoveViewer(float FrameTime, BOOL is_active, int key )
154 {
155         control_info * ci = &m_Viewer_ci;
156         float kh;
157         polymodel *pm = NULL;
158
159         CPofViewDoc* pDoc = GetDocument();
160         ASSERT_VALID(pDoc);
161
162         int n_detail_levels = 0;
163         if ( pDoc->m_model_num > -1 )   {
164                 pm = model_get(pDoc->m_model_num);
165                 n_detail_levels = pm->n_detail_levels;
166         }
167          
168         switch(key)     {
169         case SDLK_1:
170                 if ( n_detail_levels >= 1){
171                         m_current_detail_level = 1;
172                 }
173                 break;
174         case SDLK_2:
175                 if ( n_detail_levels >= 2){
176                         m_current_detail_level = 2;
177                 }
178                 break;
179         case SDLK_3:
180                 if ( n_detail_levels >= 3){ 
181                         m_current_detail_level = 3;
182                 }
183                 break;
184         case SDLK_4:
185                 if ( n_detail_levels >= 4){
186                         m_current_detail_level = 4;
187                 }
188                 break;
189         case SDLK_5:
190                 if ( n_detail_levels >= 5){
191                         m_current_detail_level = 5;
192                 }
193                 break;
194         case SDLK_6:
195                 if ( n_detail_levels >= 6){
196                         m_current_detail_level = 6;
197                 }
198                 break;
199         case SDLK_MINUS:
200                 // Scales the engines thrusters by this much
201                 model_thrust -= 0.1f;
202                 if ( model_thrust < 0.0f ){
203                         model_thrust = 0.0f;
204                 }
205                 break;
206         case SDLK_EQUALS:
207                 // Scales the engines thrusters by this much
208                 model_thrust += 0.1f;
209                 if ( model_thrust > 1.0f ){
210                         model_thrust = 1.0f;
211                 }
212                 break;
213         }
214
215         float c_scale = 1.0f;
216
217         if((pm != NULL) && (pm->core_radius < 200.0f)){
218                 c_scale = 1.0f / 6.0f;
219         }
220         
221         // From keyboard...
222         if ( is_active )        {
223                 float temp = ci->heading;
224                 float temp1 = ci->pitch;
225                 memset( ci, 0, sizeof(control_info) );
226                 ci->heading = temp;
227                 ci->pitch = temp1;
228
229                 if ( key_pressed(SDLK_BACKSPACE) )      {
230                         model_afterburner = 1;
231                 } else {
232                         model_afterburner = 0;
233                 }
234
235         
236                 kh = (key_down_timef(SDLK_KP_6) - key_down_timef(SDLK_KP_4)) / 32.0f;
237                 if (kh == 0.0f){
238                         ci->heading = 0.0f;
239                 } else if (kh > 0.0f) {
240                         if (ci->heading < 0.0f){
241                                 ci->heading = 0.0f;
242                         }
243                 } else {// kh < 0
244                         if (ci->heading > 0.0f){
245                                 ci->heading = 0.0f;
246                         }
247                 }
248                 ci->heading += kh;
249
250                 kh = (key_down_timef(SDLK_KP_8) - key_down_timef(SDLK_KP_2)) / 32.0f;
251                 if (kh == 0.0f){
252                         ci->pitch = 0.0f;
253                 } else if (kh > 0.0f) {
254                         if (ci->pitch < 0.0f){
255                                 ci->pitch = 0.0f;
256                         }
257                 } else { // kh < 0
258                         if (ci->pitch > 0.0f){
259                                 ci->pitch = 0.0f;
260                         }
261                 }
262                 ci->pitch += kh;
263
264                 ci->bank = (key_down_timef(SDLK_KP_7) - key_down_timef(SDLK_KP_9)) / 8.0f;
265                 ci->forward = (key_down_timef(SDLK_a) - key_down_timef(SDLK_z)) * c_scale;
266                 ci->sideways = (key_down_timef(SDLK_KP_3) - key_down_timef(SDLK_KP_1)) * c_scale;
267                 ci->vertical = (key_down_timef(SDLK_KP_MINUS) - key_down_timef(SDLK_KP_PLUS)) * c_scale;
268         } else {
269                 memset( ci, 0, sizeof(control_info) );
270         }
271         physics_read_flying_controls( &m_ViewerOrient, &m_ViewerPhysics, &m_Viewer_ci, FrameTime );
272
273         physics_sim(&m_ViewerPos, &m_ViewerOrient, &m_ViewerPhysics, FrameTime * 6 );           
274
275
276         // Rotate object:
277         if ( m_mouse_down )     {
278                 matrix tempm, mousem;
279
280                 if ( m_mouse_dx || m_mouse_dy ) {
281                         vm_trackball( -m_mouse_dx, m_mouse_dy, &mousem );
282                         vm_matrix_x_matrix(&tempm, &m_ObjectOrient, &mousem);
283                         m_ObjectOrient = tempm;
284
285                         m_mouse_dx = m_mouse_dy = 0;
286                 }
287         }
288
289         
290 }
291
292 CPofViewView::~CPofViewView()
293 {
294 }
295
296
297
298 extern int shipp_thruster_glow_bitmap;
299 extern float shipp_thruster_glow_noise;
300 extern int      shipp_thruster_bitmap;          // In PofView.cpp                               // What frame the current thruster bitmap is at for this ship
301 extern int Tmap_show_layers;
302 extern float Ambient_light;
303
304
305 /////////////////////////////////////////////////////////////////////////////
306 // CPofViewView drawing
307 void CPofViewView::OnDraw(CDC* pDC)
308 {
309         CPofViewDoc* pDoc = GetDocument();
310         ASSERT_VALID(pDoc);
311         polymodel * pm = NULL;
312
313         // TODO: add draw code for native data here
314
315         if ( pDoc->m_model_num >= 0 ) {
316                 RECT client;
317                 int w, h;
318
319                 pm = model_get(pDoc->m_model_num);
320
321
322                 GetClientRect(&client);
323                 w = client.right - client.left + 1;
324                 h = client.bottom - client.top + 1;
325                 if (w>= gr_screen.max_w ) w = gr_screen.max_w-1;
326                 if (h>= gr_screen.max_h ) h = gr_screen.max_h-1;
327
328                 gr_reset_clip();
329                 gr_set_clip(0,0,w,h);
330
331
332                 gr_set_color(0,0,0);
333                 gr_clear();
334                 gr_set_color( 127, 127, 127 );
335
336                 float saved_Ambient_light = Ambient_light;
337
338                 {
339                         static vector Global_light_world = { -0.208758f, -0.688253f, 0.694782f };
340                         light_reset();
341
342                         if ( m_lights_on )      {
343                                 light_add_directional( &Global_light_world, 1.0f, 1.0f, 1.0f, 1.0f );
344                         } else {
345                                 Ambient_light = 0.0f;
346                         }
347                 }
348
349                 g3_start_frame(1);
350                 
351                 g3_set_view_matrix(&m_ViewerPos, &m_ViewerOrient, m_ViewerZoom);
352
353                 uint render_flags = 0;
354                 if ( !m_dolighting ) render_flags |= MR_NO_LIGHTING;
355                 if ( m_show_outline ) {
356                         render_flags |= MR_SHOW_OUTLINE;
357                         model_set_outline_color(0,0,0);
358                 }
359
360                 if ( m_show_shields ){
361                         render_flags |= MR_SHOW_SHIELDS;
362                 }
363
364                 if ( m_show_invisible_faces )   {
365                         render_flags |= MR_SHOW_INVISIBLE_FACES;
366                 }
367                 
368                 if (m_show_overwrite){
369                         Tmap_show_layers = 1;
370                 } else {
371                         Tmap_show_layers = 0;
372                 }
373
374                 if ( m_show_pivots ) render_flags |= MR_SHOW_PIVOTS;
375                 if ( m_show_paths ) render_flags |= MR_SHOW_PATHS;
376                 if ( m_show_radius ) render_flags |= MR_SHOW_RADIUS;
377                 if ( !m_smoothing ) render_flags |= MR_NO_SMOOTHING;
378                 if ( !m_texturing ) render_flags |= MR_NO_TEXTURING;
379                 if ( m_current_detail_level > 0 ) {
380                         render_flags |= MR_LOCK_DETAIL;
381                         model_set_detail_level(m_current_detail_level-1);
382                 }
383
384                 if(m_show_bay_paths) render_flags |= MR_BAY_PATHS;              
385                 
386                 if(m_autocenter) render_flags |= MR_AUTOCENTER;
387
388                 vector temp_pos = {0.0f, 0.0f, 0.0f };
389
390                 model_clear_instance( pDoc->m_model_num );
391
392                 model_show_damaged(pDoc->m_model_num, m_show_destroyed_subobjects );
393
394                 if ( model_afterburner ){
395                         model_set_thrust( pDoc->m_model_num, 1.0f, shipp_thruster_bitmap, shipp_thruster_glow_bitmap, shipp_thruster_glow_noise );
396                 } else {
397                         model_set_thrust( pDoc->m_model_num, model_thrust, shipp_thruster_bitmap, shipp_thruster_glow_bitmap, shipp_thruster_glow_noise );
398                 }
399
400                 render_flags |= MR_SHOW_THRUSTERS;                              
401
402                 static int whee = -1;           
403                 if(whee == -1){
404                         whee = bm_load("helvig.pcx");
405                 } 
406                 if(whee != -1){
407                         model_set_insignia_bitmap(whee);
408                 }
409                 
410                 if ( m_current_detail_level > 0 )       {
411                         model_render( pDoc->m_model_num, &m_ObjectOrient, &temp_pos, render_flags );
412                 } else {
413                         int i;
414                         for (i=0; i<pm->num_debris_objects; i++ )       {
415                                 vector tmp = {0.0f, 0.0f, 0.0f };               
416                                 vector tmp1 = pm->submodel[pm->debris_objects[i]].offset;
417                                 model_find_world_point(&tmp, &tmp1, pDoc->m_model_num, -1,&m_ObjectOrient, &temp_pos );
418                                 submodel_render( pDoc->m_model_num, pm->debris_objects[i],&m_ObjectOrient, &tmp, render_flags );
419                         }
420                 }
421
422 #if 0
423                 vector hitpos;
424                 vector tmp1;
425                 vm_vec_scale_add( &tmp1, &m_ViewerPos, &m_ViewerOrient.fvec, 100.0f );
426                 int hit = model_check_collision(pDoc->m_model_num,&vmd_identity_matrix,&temp_pos, &m_ViewerPos, &tmp1, &hitpos, 0 );
427
428                 if ( hit )      {
429                         vertex pt;
430                         ubyte flags;
431
432                         flags = g3_rotate_vertex(&pt,&hitpos);
433
434                         if (flags == 0) {
435                                 g3_project_vertex(&pt);
436                                 if (!(pt.flags & PF_OVERFLOW))  {
437                                         gr_set_color(128,0,0);
438                                         g3_draw_sphere( &pt, 1.0f );
439                                 }
440                         }
441                 }
442 #endif
443                 g3_end_frame();
444                 
445                 gr_flip_window((uint) pDC->m_hDC, 0, 0, w, h );
446
447                 Ambient_light = saved_Ambient_light;            
448         }
449 }
450
451 /////////////////////////////////////////////////////////////////////////////
452 // CPofViewView printing
453
454 BOOL CPofViewView::OnPreparePrinting(CPrintInfo* pInfo)
455 {
456         // default preparation
457         return DoPreparePrinting(pInfo);
458 }
459
460 void CPofViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
461 {
462         // TODO: add extra initialization before printing
463 }
464
465 void CPofViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
466 {
467         // TODO: add cleanup after printing
468 }
469
470 /////////////////////////////////////////////////////////////////////////////
471 // CPofViewView diagnostics
472
473 #ifdef _DEBUG
474 void CPofViewView::AssertValid() const
475 {
476         CView::AssertValid();
477 }
478
479 void CPofViewView::Dump(CDumpContext& dc) const
480 {
481         CView::Dump(dc);
482 }
483
484 CPofViewDoc* CPofViewView::GetDocument() // non-debug version is inline
485 {
486         ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPofViewDoc)));
487         return (CPofViewDoc*)m_pDocument;
488 }
489 #endif //_DEBUG
490
491 /////////////////////////////////////////////////////////////////////////////
492 // CPofViewView message handlers
493
494 void CPofViewView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
495 {
496         // TODO: Add your message handler code here and/or call default
497         key_mark( nFlags&0x7F, 1, 0 );
498         
499         CView::OnKeyDown(nChar, nRepCnt, nFlags);
500 }
501
502 void CPofViewView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
503 {
504         // TODO: Add your message handler code here and/or call default
505         key_mark( nFlags&0x7F, 0, 0 );
506         
507         CView::OnKeyUp(nChar, nRepCnt, nFlags);
508 }
509
510 extern int pofview_focus;
511
512 void CPofViewView::OnSetFocus(CWnd* pOldWnd) 
513 {
514         CView::OnSetFocus(pOldWnd);
515         
516         // TODO: Add your message handler code here
517         key_got_focus();
518
519         pofview_focus++;
520 }
521
522 void CPofViewView::OnKillFocus(CWnd* pNewWnd) 
523 {
524         CView::OnKillFocus(pNewWnd);
525         
526         // TODO: Add your message handler code here
527         key_lost_focus();
528
529         pofview_focus--;
530
531 }
532
533
534 void CPofViewView::OnPofOutline() 
535 {
536         m_show_outline = !m_show_outline;
537 }
538
539
540 void CPofViewView::OnUpdatePofOutline(CCmdUI* pCmdUI) 
541 {
542         pCmdUI->SetCheck( m_show_outline );
543 }
544
545 void CPofViewView::OnPofLighting() 
546 {
547         m_dolighting = !m_dolighting;
548 }
549
550 void CPofViewView::OnUpdatePofLighting(CCmdUI* pCmdUI) 
551 {
552         pCmdUI->SetCheck( m_dolighting );
553 }
554
555 void CPofViewView::OnPofPivots() 
556 {
557         m_show_pivots = !m_show_pivots;
558         
559 }
560
561 void CPofViewView::OnUpdatePofPivots(CCmdUI* pCmdUI) 
562 {
563         pCmdUI->SetCheck( m_show_pivots );
564 }
565
566 void CPofViewView::OnDetail1() 
567 {
568         m_current_detail_level = 1;
569 }
570
571 void CPofViewView::OnUpdateDetail1(CCmdUI* pCmdUI) 
572 {
573         CPofViewDoc* pDoc = GetDocument();
574         if ( pDoc->m_model_num > -1 )   {
575                 polymodel * pm = model_get(pDoc->m_model_num);
576                 if ( (pm->n_detail_levels >= 1) && (m_current_detail_level!=1) )
577                         pCmdUI->Enable(TRUE);
578                 else
579                         pCmdUI->Enable(FALSE);
580         }
581 }
582
583 void CPofViewView::OnDetail2() 
584 {
585         m_current_detail_level = 2;
586 }
587
588 void CPofViewView::OnUpdateDetail2(CCmdUI* pCmdUI) 
589 {
590         CPofViewDoc* pDoc = GetDocument();
591         if ( pDoc->m_model_num > -1 )   {
592                 polymodel * pm = model_get(pDoc->m_model_num);
593                 if ( (pm->n_detail_levels >= 2) && (m_current_detail_level!=2) )
594                         pCmdUI->Enable(TRUE);
595                 else
596                         pCmdUI->Enable(FALSE);
597         }
598 }
599
600 void CPofViewView::OnDetail3() 
601 {
602         m_current_detail_level = 3;
603 }
604
605 void CPofViewView::OnUpdateDetail3(CCmdUI* pCmdUI) 
606 {
607         CPofViewDoc* pDoc = GetDocument();
608         if ( pDoc->m_model_num > -1 )   {
609                 polymodel * pm = model_get(pDoc->m_model_num);
610                 if ( (pm->n_detail_levels >= 3) && (m_current_detail_level!=3) )
611                         pCmdUI->Enable(TRUE);
612                 else
613                         pCmdUI->Enable(FALSE);
614         }
615 }
616
617 void CPofViewView::OnDetail4() 
618 {
619         m_current_detail_level = 4;
620 }
621
622 void CPofViewView::OnUpdateDetail4(CCmdUI* pCmdUI) 
623 {
624         CPofViewDoc* pDoc = GetDocument();
625         if ( pDoc->m_model_num > -1 )   {
626                 polymodel * pm = model_get(pDoc->m_model_num);
627                 if ( (pm->n_detail_levels >= 4) && (m_current_detail_level!=4) )
628                         pCmdUI->Enable(TRUE);
629                 else
630                         pCmdUI->Enable(FALSE);
631         }
632 }
633
634 void CPofViewView::OnDetail5() 
635 {
636         m_current_detail_level = 5;
637 }
638
639 void CPofViewView::OnUpdateDetail5(CCmdUI* pCmdUI) 
640 {
641         CPofViewDoc* pDoc = GetDocument();
642         if ( pDoc->m_model_num > -1 )   {
643                 polymodel * pm = model_get(pDoc->m_model_num);
644                 if ( (pm->n_detail_levels >= 5) && (m_current_detail_level!=5) )
645                         pCmdUI->Enable(TRUE);
646                 else
647                         pCmdUI->Enable(FALSE);
648         }
649 }
650
651
652
653 void CPofViewView::OnDetail6() 
654 {
655         m_current_detail_level = 6;
656 }
657
658 void CPofViewView::OnUpdateDetail6(CCmdUI* pCmdUI) 
659 {
660         CPofViewDoc* pDoc = GetDocument();
661         if ( pDoc->m_model_num > -1 )   {
662                 polymodel * pm = model_get(pDoc->m_model_num);
663                 if ( (pm->n_detail_levels >= 6) && (m_current_detail_level!=6) )
664                         pCmdUI->Enable(TRUE);
665                 else
666                         pCmdUI->Enable(FALSE);
667         }
668 }
669
670 void CPofViewView::OnInitialUpdate() 
671 {
672         CView::OnInitialUpdate();
673         
674         // TODO: Add your specialized code here and/or call the base class
675 }
676
677
678 void CPofViewView::OnShowTree() 
679 {
680         // TODO: Add your command handler code here
681         CPofViewDoc* pDoc = GetDocument();
682         if ( pDoc->m_model_num > -1 )   {
683                 m_TreeDialog.MyCreate(this);
684         }
685         
686 }
687
688 void CPofViewView::OnUpdateShowTree(CCmdUI* pCmdUI) 
689 {
690         // TODO: Add your command update UI handler code here
691
692 }
693
694 void CPofViewView::OnPofPaths() 
695 {
696         m_show_paths = !m_show_paths;
697 }
698
699 void CPofViewView::OnUpdatePofPaths(CCmdUI* pCmdUI) 
700 {
701         pCmdUI->SetCheck( m_show_paths );
702 }
703
704 void CPofViewView::OnPofRadius() 
705 {
706         m_show_radius = !m_show_radius;
707
708 }
709
710 void CPofViewView::OnUpdatePofRadius(CCmdUI* pCmdUI) 
711 {
712         pCmdUI->SetCheck( m_show_radius );
713 }
714
715 void CPofViewView::OnPofOverwrite() 
716 {
717         m_show_overwrite = !m_show_overwrite;
718         
719 }
720
721 void CPofViewView::OnUpdatePofOverwrite(CCmdUI* pCmdUI) 
722 {
723         pCmdUI->Enable(TRUE);
724         pCmdUI->SetCheck( m_show_destroyed_subobjects );
725 }
726
727 void CPofViewView::OnShowDamagedSubobjects() 
728 {
729         m_show_destroyed_subobjects = !m_show_destroyed_subobjects;
730 }
731
732 void CPofViewView::OnUpdateShowDamagedSubobjects(CCmdUI* pCmdUI) 
733 {
734         // TODO: Add your command update UI handler code here
735         
736 }
737
738 void CPofViewView::OnShowDebris() 
739 {
740         m_current_detail_level = 0;
741 }
742
743 void CPofViewView::OnUpdateShowDebris(CCmdUI* pCmdUI) 
744 {
745         CPofViewDoc* pDoc = GetDocument();
746         if ( pDoc->m_model_num > -1 )   {
747                 polymodel * pm = model_get(pDoc->m_model_num);
748                 if ( (pm->num_debris_objects >= 1) && (m_current_detail_level!=0) )
749                         pCmdUI->Enable(TRUE);
750                 else
751                         pCmdUI->Enable(FALSE);
752         }
753 }
754
755 void CPofViewView::OnMouseMove(UINT nFlags, CPoint point) 
756 {
757         if (m_mouse_inited)     {
758                 m_mouse_dx = point.x - m_mouse_x;
759                 m_mouse_dy = point.y - m_mouse_y;
760         } else {
761                 m_mouse_inited = 1;
762         }
763
764         m_mouse_x = point.x;
765         m_mouse_y = point.y;
766         
767         CView::OnMouseMove(nFlags, point);
768 }
769
770 void CPofViewView::OnLButtonDown(UINT nFlags, CPoint point) 
771 {
772         m_mouse_down = 1;
773
774         CView::OnLButtonDown(nFlags, point);
775 }
776
777 void CPofViewView::OnLButtonUp(UINT nFlags, CPoint point) 
778 {
779         m_mouse_down = 0;
780         
781         CView::OnLButtonUp(nFlags, point);
782 }
783
784 void CPofViewView::OnPofSmoothing() 
785 {
786         m_smoothing = !m_smoothing;
787 }
788
789 void CPofViewView::OnUpdatePofSmoothing(CCmdUI* pCmdUI) 
790 {
791         pCmdUI->SetCheck( m_smoothing );
792 }
793
794 void CPofViewView::OnPofTexturing() 
795 {
796         m_texturing = !m_texturing;
797 }
798
799 void CPofViewView::OnUpdatePofTexturing(CCmdUI* pCmdUI) 
800 {
801         pCmdUI->SetCheck( m_texturing );
802 }
803
804 void CPofViewView::OnPofShields() 
805 {
806         m_show_shields = !m_show_shields;
807 }
808
809 void CPofViewView::OnUpdatePofShields(CCmdUI* pCmdUI) 
810 {
811         pCmdUI->SetCheck( m_show_shields );
812 }
813
814 void CPofViewView::OnToggleLighting() 
815 {
816         m_lights_on = !m_lights_on;
817 }
818
819 void CPofViewView::OnUpdateToggleLighting(CCmdUI* pCmdUI) 
820 {
821         pCmdUI->SetCheck( m_lights_on    );
822 }
823
824
825 void CPofViewView::OnInvisiblefaces() 
826 {
827         m_show_invisible_faces = !m_show_invisible_faces;
828 }
829
830 void CPofViewView::OnUpdateInvisiblefaces(CCmdUI* pCmdUI) 
831 {
832         pCmdUI->SetCheck( m_show_invisible_faces );
833 }
834
835 void CPofViewView::OnBayPaths() 
836 {
837         m_show_bay_paths = !m_show_bay_paths;
838 }
839
840 void CPofViewView::OnUpdateBayPaths(CCmdUI* pCmdUI) 
841 {
842         pCmdUI->SetCheck( m_show_bay_paths );
843 }
844
845 void CPofViewView::OnAutocenter() 
846 {
847         m_autocenter = !m_autocenter;
848 }
849
850 void CPofViewView::OnUpdateAutocenter(CCmdUI* pCmdUI) 
851 {
852         pCmdUI->SetCheck( m_autocenter );
853 }
854
855 void CPofViewView::OnSize(UINT nType, int cx, int cy) 
856 {
857         CView::OnSize(nType, cx, cy);
858         
859         if ((cx > 0) && (cy > 0)) {
860                 gr_init(GR_640, GR_SOFTWARE, 8, cx, cy);
861         }
862 }