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