-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorldEditorView.cpp
13874 lines (12790 loc) · 445 KB
/
WorldEditorView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
// WorldEditorView.cpp : implementation of the CWorldEditorView class
//
#include "StdH.h"
#include "WorldEditor.h"
#include <Engine/Base/Profiling.h>
#include <Engine/Base/Statistics.h>
#include <Engine/Templates/Stock_CTextureData.h>
#ifdef _DEBUG
#undef new
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CTimerValue _tvLastTerrainBrushingApplied;
static INDEX aiForCreationOfSizingVertices[14][6] =
{
{0,0,2,2,5,5},
{1,1,2,2,5,5},
{1,1,2,2,4,4},
{0,0,2,2,4,4},
{0,0,3,3,5,5},
{1,1,3,3,5,5},
{1,1,3,3,4,4},
{0,0,3,3,4,4},
{0,1,2,3,5,5},
{1,1,2,3,4,5},
{0,1,2,3,4,4},
{0,0,2,3,4,5},
{0,1,2,2,4,5},
{0,1,3,3,4,5},
};
static INDEX aiForAllowedSizing[14][6] =
{
{1,0,1,0,0,1},
{0,1,1,0,0,1},
{0,1,1,0,1,0},
{1,0,1,0,1,0},
{1,0,0,1,0,1},
{0,1,0,1,0,1},
{0,1,0,1,1,0},
{1,0,0,1,1,0},
{0,0,0,0,0,1},
{0,1,0,0,0,0},
{0,0,0,0,1,0},
{1,0,0,0,0,0},
{0,0,1,0,0,0},
{0,0,0,1,0,0},
};
/////////////////////////////////////////////////////////////////////////////
// CWorldEditorView
IMPLEMENT_DYNCREATE(CWorldEditorView, CView)
BEGIN_MESSAGE_MAP(CWorldEditorView, CView)
//{{AFX_MSG_MAP(CWorldEditorView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_KILLFOCUS()
ON_WM_LBUTTONDOWN()
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONUP()
ON_WM_DROPFILES()
ON_COMMAND(ID_ISOMETRIC_FRONT, OnIsometricFront)
ON_COMMAND(ID_ISOMETRIC_BACK, OnIsometricBack)
ON_COMMAND(ID_ISOMETRIC_BOTTOM, OnIsometricBottom)
ON_COMMAND(ID_ISOMETRIC_LEFT, OnIsometricLeft)
ON_COMMAND(ID_ISOMETRIC_RIGHT, OnIsometricRight)
ON_COMMAND(ID_ISOMETRIC_TOP, OnIsometricTop)
ON_COMMAND(ID_PERSPECTIVE, OnPerspective)
ON_COMMAND(ID_ZOOM_LESS, OnZoomLess)
ON_COMMAND(ID_ZOOM_MORE, OnZoomMore)
ON_COMMAND(ID_MOVE_DOWN, OnMoveDown)
ON_COMMAND(ID_MOVE_UP, OnMoveUp)
ON_WM_LBUTTONDBLCLK()
ON_COMMAND(ID_MEASUREMENT_TAPE, OnMeasurementTape)
ON_UPDATE_COMMAND_UI(ID_MEASUREMENT_TAPE, OnUpdateMeasurementTape)
ON_COMMAND(ID_CIRCLE_MODES, OnCircleModes)
ON_UPDATE_COMMAND_UI(ID_CIRCLE_MODES, OnUpdateCircleModes)
ON_COMMAND(ID_DESELECT_ALL, OnDeselectAll)
ON_COMMAND(ID_DELETE_ENTITIES, OnDeleteEntities)
ON_UPDATE_COMMAND_UI(ID_DELETE_ENTITIES, OnUpdateDeleteEntities)
ON_WM_SETCURSOR()
ON_COMMAND(ID_TAKE_SS, OnTakeSs)
ON_UPDATE_COMMAND_UI(ID_ENTITY_MODE, OnUpdateEntityMode)
ON_COMMAND(ID_SECTOR_MODE, OnSectorMode)
ON_UPDATE_COMMAND_UI(ID_SECTOR_MODE, OnUpdateSectorMode)
ON_COMMAND(ID_POLYGON_MODE, OnPolygonMode)
ON_UPDATE_COMMAND_UI(ID_POLYGON_MODE, OnUpdatePolygonMode)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_CLONE_CSG, OnCloneCSG)
ON_UPDATE_COMMAND_UI(ID_CLONE_CSG, OnUpdateCloneCsg)
ON_COMMAND(ID_MEASURE_ON, OnMeasureOn)
ON_UPDATE_COMMAND_UI(ID_MEASURE_ON, OnUpdateMeasureOn)
ON_COMMAND(ID_RESET_VIEWER, OnResetViewer)
ON_COMMAND(ID_COPY_TEXTURE, OnCopyTexture)
ON_COMMAND(ID_PASTE_TEXTURE, OnPasteTexture)
ON_COMMAND(ID_CENTER_ENTITY, OnCenterEntity)
ON_COMMAND(ID_FUNCTION, OnFunction)
ON_UPDATE_COMMAND_UI(ID_CENTER_ENTITY, OnUpdateCenterEntity)
ON_COMMAND(ID_DROP_MARKER, OnDropMarker)
ON_UPDATE_COMMAND_UI(ID_DROP_MARKER, OnUpdateDropMarker)
ON_COMMAND(ID_TEST_CONNECTIONS, OnTestConnections)
ON_UPDATE_COMMAND_UI(ID_TEST_CONNECTIONS, OnUpdateTestConnections)
ON_COMMAND(ID_ALIGN_VOLUME, OnAlignVolume)
ON_UPDATE_COMMAND_UI(ID_ALIGN_VOLUME, OnUpdateAlignVolume)
ON_COMMAND(ID_CURRENT_VIEW_PROPERTIES, OnCurrentViewProperties)
ON_COMMAND(ID_DELETE_MIP, OnDeleteMip)
ON_UPDATE_COMMAND_UI(ID_DELETE_MIP, OnUpdateDeleteMip)
ON_COMMAND(ID_PREVIOUS_MIP_BRUSH, OnPreviousMipBrush)
ON_UPDATE_COMMAND_UI(ID_PREVIOUS_MIP_BRUSH, OnUpdatePreviousMipBrush)
ON_COMMAND(ID_NEXT_MIP_BRUSH, OnNextMipBrush)
ON_UPDATE_COMMAND_UI(ID_NEXT_MIP_BRUSH, OnUpdateNextMipBrush)
ON_COMMAND(ID_CROSSROAD_FOR_C, OnCrossroadForC)
ON_COMMAND(ID_CHOOSE_COLOR, OnChooseColor)
ON_UPDATE_COMMAND_UI(ID_CHOOSE_COLOR, OnUpdateChooseColor)
ON_COMMAND(ID_MENU_COPY_MAPPING, OnMenuCopyMapping)
ON_COMMAND(ID_MENU_PASTE_MAPPING, OnMenuPasteMapping)
ON_COMMAND(ID_SET_AS_CSG_TARGET, OnSetAsCsgTarget)
ON_COMMAND(ID_KEY_PASTE, OnKeyPaste)
ON_WM_RBUTTONDBLCLK()
ON_COMMAND(ID_SELECT_BY_TEXTURE_ADJACENT, OnSelectByTextureAdjacent)
ON_COMMAND(ID_SELECT_BY_TEXTURE_IN_SECTOR, OnSelectByTextureInSector)
ON_COMMAND(ID_SELECT_BY_COLOR_IN_SECTOR, OnSelectByColorInSector)
ON_COMMAND(ID_CONUS_PRIMITIVE, OnConusPrimitive)
ON_COMMAND(ID_TORUS_PRIMITIVE, OnTorusPrimitive)
ON_COMMAND(ID_TERRAIN_PRIMITIVE, OnTerrainPrimitive)
ON_COMMAND(ID_SPHERE_PRIMITIVE, OnSpherePrimitive)
ON_COMMAND(ID_STAIRCASE_PRIMITIVE, OnStaircasePrimitive)
ON_UPDATE_COMMAND_UI(ID_CONUS_PRIMITIVE, OnUpdateConusPrimitive)
ON_UPDATE_COMMAND_UI(ID_SPHERE_PRIMITIVE, OnUpdateSpherePrimitive)
ON_UPDATE_COMMAND_UI(ID_TERRAIN_PRIMITIVE, OnUpdateTerrainPrimitive)
ON_UPDATE_COMMAND_UI(ID_TORUS_PRIMITIVE, OnUpdateTorusPrimitive)
ON_UPDATE_COMMAND_UI(ID_STAIRCASE_PRIMITIVE, OnUpdateStaircasePrimitive)
ON_COMMAND(ID_POPUP_CONUS, OnPopupConus)
ON_COMMAND(ID_POPUP_SPHERE, OnPopupSphere)
ON_COMMAND(ID_POPUP_STAIRS, OnPopupStairs)
ON_COMMAND(ID_POPUP_TERRAIN, OnPopupTerrain)
ON_COMMAND(ID_POPUP_TORUS, OnPopupTorus)
ON_UPDATE_COMMAND_UI(ID_MOVE_DOWN, OnUpdateMoveDown)
ON_UPDATE_COMMAND_UI(ID_MOVE_UP, OnUpdateMoveUp)
ON_COMMAND(ID_SELECT_LIGHTS, OnSelectLights)
ON_COMMAND(ID_DISCARD_SHADOWS, OnDiscardShadows)
ON_COMMAND(ID_COPY_SECTOR_AMBIENT, OnCopySectorAmbient)
ON_COMMAND(ID_PASTE_SECTOR_AMBIENT, OnPasteSectorAmbient)
ON_COMMAND(ID_SELECT_ALL_POLYGONS, OnSelectAllPolygons)
ON_COMMAND(ID_COPY_SECTORS, OnCopySectors)
ON_COMMAND(ID_DELETE_SECTORS, OnDeleteSectors)
ON_COMMAND(ID_PASTE_SECTORS, OnPasteSectors)
ON_COMMAND(ID_CENTER_BCG_VIEWER, OnCenterBcgViewer)
ON_COMMAND(ID_MENU_PASTE_AS_PROJECTED_MAPPING, OnMenuPasteAsProjectedMapping)
ON_COMMAND(ID_KEY_PASTE_AS_PROJECTED, OnKeyPasteAsProjected)
ON_COMMAND(ID_SELECT_ALL_ENTITIES, OnSelectAllEntitiesInSectors)
ON_COMMAND(ID_SELECT_ALL_SECTORS, OnSelectAllSectors)
ON_COMMAND(ID_LAST_PRIMITIVE, OnLastPrimitive)
ON_UPDATE_COMMAND_UI(ID_LAST_PRIMITIVE, OnUpdateLastPrimitive)
ON_COMMAND(ID_CLONE_TO_MORE_PRECISE_MIP, OnCloneToMorePreciseMip)
ON_COMMAND(ID_CLONE_TO_ROUGHER_MIP_LEVEL, OnCloneToRougherMipLevel)
ON_COMMAND(ID_CREATE_EMPTY_MORE_PRECISE_MIP, OnCreateEmptyMorePreciseMip)
ON_COMMAND(ID_CREATE_EMPTY_ROUGHER_MIP, OnCreateEmptyRougherMip)
ON_UPDATE_COMMAND_UI(ID_CLONE_TO_MORE_PRECISE_MIP, OnUpdateCloneToMorePreciseMip)
ON_UPDATE_COMMAND_UI(ID_CLONE_TO_ROUGHER_MIP_LEVEL, OnUpdateCloneToRougherMipLevel)
ON_UPDATE_COMMAND_UI(ID_CREATE_EMPTY_MORE_PRECISE_MIP, OnUpdateCreateEmptyMorePreciseMip)
ON_UPDATE_COMMAND_UI(ID_CREATE_EMPTY_ROUGHER_MIP, OnUpdateCreateEmptyRougherMip)
ON_COMMAND(ID_EDIT_PASTE_ALTERNATIVE, OnEditPasteAlternative)
ON_COMMAND(ID_SELECT_ALL_ENTITIES_IN_WORLD, OnSelectAllEntitiesInWorld)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_ALTERNATIVE, OnUpdateEditPasteAlternative)
ON_COMMAND(ID_ENTITY_MODE, OnEntityMode)
ON_COMMAND(ID_FIND_TEXTURE, OnFindTexture)
ON_COMMAND(ID_SELECT_SECTORS_WITH_SAME_NAME, OnSelectSectorsWithSameName)
ON_COMMAND(ID_SELECT_SECTORS_ARROUND_ENTITY, OnSelectSectorsArroundEntity)
ON_COMMAND(ID_SELECT_SECTORS_ARROUND_ENTITY_ON_CONTEXT, OnSelectSectorsArroundEntityOnContext)
ON_COMMAND(ID_INSERT_VERTEX, OnInsertVertex)
ON_COMMAND(ID_DELETE_VERTEX, OnDeleteVertex)
ON_COMMAND(ID_SAVE_PICTURES_FOR_ENVIRONMENT, OnSavePicturesForEnvironment)
ON_UPDATE_COMMAND_UI(ID_SAVE_PICTURES_FOR_ENVIRONMENT, OnUpdateSavePicturesForEnvironment)
ON_WM_ERASEBKGND()
ON_COMMAND(ID_CSG_SELECT_SECTOR, OnCsgSelectSector)
ON_COMMAND(ID_MENU_ALIGN_MAPPING_U, OnMenuAlignMappingU)
ON_COMMAND(ID_MENU_ALIGN_MAPPING_V, OnMenuAlignMappingV)
ON_WM_DESTROY()
ON_COMMAND(ID_FALL_DOWN, OnFallDown)
ON_COMMAND(ID_PREVIOUS, OnPrevious)
ON_COMMAND(ID_NEXT, OnNext)
ON_UPDATE_COMMAND_UI(ID_PREVIOUS, OnUpdatePrevious)
ON_UPDATE_COMMAND_UI(ID_NEXT, OnUpdateNext)
ON_COMMAND(ID_REMOVE_UNUSED_TEXTURES, OnRemoveUnusedTextures)
ON_COMMAND(ID_ROTATE, OnRotate)
ON_COMMAND(ID_ROTATE_BACK, OnRotateBack)
ON_COMMAND(ID_SELECT_VISIBLE_SECTORS, OnSelectVisibleSectors)
ON_COMMAND(ID_EDIT_COPY_ALTERNATIVE, OnEditCopyAlternative)
ON_COMMAND(ID_ROTATE_LEFT, OnRotateLeft)
ON_COMMAND(ID_ROTATE_RIGHT, OnRotateRight)
ON_COMMAND(ID_ROTATE_UP, OnRotateUp)
ON_COMMAND(ID_ROTATE_DOWN, OnRotateDown)
ON_COMMAND(ID_SELECT_WHO_TARGETS, OnSelectWhoTargets)
ON_COMMAND(ID_SELECT_INVALIDTRIS, OnSelectInvalidTris)
ON_COMMAND(ID_TEST_CONNECTIONS_BACK, OnTestConnectionsBack)
ON_UPDATE_COMMAND_UI(ID_TEST_CONNECTIONS_BACK, OnUpdateTestConnectionsBack)
ON_WM_MOUSEWHEEL()
ON_COMMAND(ID_SELECT_SECTORS_OTHER_SIDE, OnSelectSectorsOtherSide)
ON_COMMAND(ID_SELECT_LINKS_TO_SECTOR, OnSelectLinksToSector)
ON_COMMAND(ID_REMAIN_SELECTEDBY_ORIENTATION, OnRemainSelectedByOrientation)
ON_COMMAND(ID_DESELECT_BY_ORIENTATION, OnDeselectByOrientation)
ON_COMMAND(ID_VERTEX_MODE, OnVertexMode)
ON_COMMAND(ID_REOPTIMIZE_BRUSHES, OnReoptimizeBrushes)
ON_COMMAND(ID_MERGE_VERTICES, OnMergeVertices)
ON_COMMAND(ID_EXPORT_DISPLACE_MAP, OnExportDisplaceMap)
ON_COMMAND(ID_CUT_MODE, OnCutMode)
ON_UPDATE_COMMAND_UI(ID_CUT_MODE, OnUpdateCutMode)
ON_COMMAND(ID_SELECT_ALL_TARGETS, OnSelectAllTargets)
ON_COMMAND(ID_SELECT_ALL_TARGETS_ON_CONTEXT, OnSelectAllTargetsOnContext)
ON_COMMAND(ID_SELECT_CLONES, OnSelectClones)
ON_COMMAND(ID_SELECT_CLONES_ON_CONTEXT, OnSelectClonesOnContext)
ON_UPDATE_COMMAND_UI(ID_SELECT_CLONES, OnUpdateSelectClones)
ON_COMMAND(ID_SELECT_ALL_VERTICES, OnSelectAllVertices)
ON_COMMAND(ID_SELECT_OF_SAME_CLASS, OnSelectOfSameClass)
ON_COMMAND(ID_SELECT_OF_SAME_CLASS_ON_CONTEXT, OnSelectOfSameClassOnContext)
ON_COMMAND(ID_ALTERNATIVE_MOVING_MODE, OnAlternativeMovingMode)
ON_COMMAND(ID_RE_TRIPLE, OnReTriple)
ON_COMMAND(ID_SELECT_WHO_TARGETS_ON_CONTEXT, OnSelectWhoTargetsOnContext)
ON_COMMAND(ID_CLEAR_ALL_TARGETS, OnClearAllTargets)
ON_COMMAND(ID_SELECT_CSG_TARGET, OnSelectCsgTarget)
ON_UPDATE_COMMAND_UI(ID_SELECT_CSG_TARGET, OnUpdateSelectCsgTarget)
ON_COMMAND(ID_REMAIN_SELECTEDBY_ORIENTATION_SINGLE, OnRemainSelectedbyOrientationSingle)
ON_UPDATE_COMMAND_UI(ID_RE_TRIPLE, OnUpdateReTriple)
ON_COMMAND(ID_TRIANGULARIZE_POLYGON, OnTriangularizePolygon)
ON_COMMAND(ID_ENTITY_CONTEXT_HELP, OnEntityContextHelp)
ON_COMMAND(ID_POPUP_AUTO_FIT_MAPPING, OnPopupAutoFitMapping)
ON_COMMAND(ID_TRIANGULARIZE_SELECTION, OnTriangularizeSelection)
ON_UPDATE_COMMAND_UI(ID_TRIANGULARIZE_SELECTION, OnUpdateTriangularizeSelection)
ON_COMMAND(ID_POPUP_AUTO_FIT_MAPPING_SMALL, OnPopupAutoFitMappingSmall)
ON_COMMAND(ID_POPUP_AUTO_FIT_MAPPING_BOTH, OnPopupAutoFitMappingBoth)
ON_COMMAND(ID_RESET_MAPPING_OFFSET, OnResetMappingOffset)
ON_COMMAND(ID_RESET_MAPPING_ROTATION, OnResetMappingRotation)
ON_COMMAND(ID_RESET_MAPPING_STRETCH, OnResetMappingStretch)
ON_COMMAND(ID_CROSSROAD_FOR_L, OnCrossroadForL)
ON_COMMAND(ID_SELECT_USING_TARGET_TREE, OnSelectUsingTargetTree)
ON_COMMAND(ID_TARGET_TREE, OnTargetTree)
ON_UPDATE_COMMAND_UI(ID_TARGET_TREE, OnUpdateTargetTree)
ON_COMMAND(ID_SWAP_LAYERS_12, OnSwapLayers12)
ON_COMMAND(ID_SWAP_LAYERS_23, OnSwapLayers23)
ON_COMMAND(ID_SELECT_DESCENDANTS, OnSelectDescendants)
ON_COMMAND(ID_CROSSROAD_FOR_CTRL_F, OnCrossroadForCtrlF)
ON_COMMAND(ID_ROTATE_TO_TARGET_CENTER, OnRotateToTargetCenter)
ON_COMMAND(ID_ROTATE_TO_TARGET_ORIGIN, OnRotateToTargetOrigin)
ON_COMMAND(ID_COPY_ORIENTATION, OnCopyOrientation)
ON_COMMAND(ID_COPY_PLACEMENT, OnCopyPlacement)
ON_COMMAND(ID_COPY_POSITION, OnCopyPosition)
ON_COMMAND(ID_PASTE_ORIENTATION, OnPasteOrientation)
ON_COMMAND(ID_PASTE_PLACEMENT, OnPastePlacement)
ON_COMMAND(ID_PASTE_POSITION, OnPastePosition)
ON_COMMAND(ID_ALIGN_B, OnAlignB)
ON_COMMAND(ID_ALIGN_H, OnAlignH)
ON_COMMAND(ID_ALIGN_P, OnAlignP)
ON_COMMAND(ID_ALIGN_X, OnAlignX)
ON_COMMAND(ID_ALIGN_Y, OnAlignY)
ON_COMMAND(ID_ALIGN_Z, OnAlignZ)
ON_COMMAND(ID_AUTOTEXTURIZE_MIPS, OnAutotexturizeMips)
ON_UPDATE_COMMAND_UI(ID_AUTOTEXTURIZE_MIPS, OnUpdateAutotexturizeMips)
ON_COMMAND(ID_RANDOM_OFFSET_U, OnRandomOffsetU)
ON_COMMAND(ID_RANDOM_OFFSET_V, OnRandomOffsetV)
ON_COMMAND(ID_STRETCH_RELATIVE_OFFSET, OnStretchRelativeOffset)
ON_COMMAND(ID_DESELECT_HIDDEN, OnDeselectHidden)
ON_COMMAND(ID_SELECT_HIDDEN, OnSelectHidden)
ON_COMMAND(ID_SECTORS_TO_BRUSH, OnSectorsToBrush)
ON_COMMAND(ID_POLYGONS_TO_BRUSH, OnPolygonsToBrush)
ON_COMMAND(ID_CLONE_POLYGONS, OnClonePolygons)
ON_COMMAND(ID_DELETE_POLYGONS, OnDeletePolygons)
ON_COMMAND(ID_KEY_U, OnKeyU)
ON_COMMAND(ID_KEY_D, OnKeyD)
ON_COMMAND(ID_FLIP_POLYGON, OnFlipPolygon)
ON_COMMAND(ID_KEY_M, OnKeyM)
ON_COMMAND(ID_KEY_BACKSLASH, OnKeyBackslash)
ON_COMMAND(ID_KEY_O, OnKeyO)
ON_UPDATE_COMMAND_UI(ID_KEY_O, OnUpdateKeyO)
ON_COMMAND(ID_KEY_CTRL_SHIFT_E, OnKeyCtrlShiftE)
ON_COMMAND(ID_KEY_CTRL_SHIFT_G, OnKeyCtrlShiftG)
ON_UPDATE_COMMAND_UI(ID_KEY_CTRL_SHIFT_G, OnUpdateKeyCtrlShiftG)
ON_COMMAND(ID_KEY_CTRL_SHIFT_K, OnKeyCtrlShiftK)
#if SE1_TERRAINS
ON_COMMAND(ID_TERRAIN_MODE, OnTerrainMode)
ON_UPDATE_COMMAND_UI(ID_TERRAIN_MODE, OnUpdateTerrainMode)
ON_COMMAND(ID_SELECT_BRUSH, OnSelectBrush)
ON_COMMAND(ID_SELECT_TERRAIN, OnSelectTerrain)
ON_COMMAND(ID_ALTITUDE_EDIT_MODE, OnAltitudeEditMode)
ON_COMMAND(ID_LAYER_TEXTURE_EDIT_MODE, OnLayerTextureEditMode)
ON_COMMAND(ID_TBRUSH_ALTITUDE, OnTbrushAltitude)
ON_COMMAND(ID_TBRUSH_EQUILAZE, OnTbrushEquilaze)
ON_COMMAND(ID_TBRUSH_ERASE, OnTbrushErase)
ON_COMMAND(ID_TBRUSH_NOISE, OnTbrushNoise)
ON_COMMAND(ID_TBRUSH_SMOOTH, OnTbrushSmooth)
ON_COMMAND(ID_OPTIMIZE_TERRAIN, OnOptimizeTerrain)
ON_COMMAND(ID_RECALCULATE_TERRAIN_SHADOWS, OnRecalculateTerrainShadows)
ON_COMMAND(ID_VIEW_HEIGHTMAP, OnViewHeightmap)
ON_COMMAND(ID_IMPORT_HEIGHTMAP, OnImportHeightmap)
ON_COMMAND(ID_EXPORT_HEIGHTMAP, OnExportHeightmap)
ON_COMMAND(ID_IMPORT_HEIGHTMAP16, OnImportHeightmap16)
ON_COMMAND(ID_EXPORT_HEIGHTMAP16, OnExportHeightmap16)
ON_COMMAND(ID_EXPORT_B2WHEIGHTMAP, OnExportB2WHeightmap) // [Cecil]
ON_COMMAND(ID_SELECT_LAYER, OnSelectLayer)
ON_COMMAND(ID_PICK_LAYER, OnPickLayer)
ON_COMMAND(ID_POSTERIZE, OnPosterize)
ON_COMMAND(ID_EQUILIZE, OnFlatten)
ON_COMMAND(ID_APPLY_FILTER, OnApplyFilter)
ON_COMMAND(ID_TE_SMOOTH, OnTeSmooth)
ON_COMMAND(ID_EDIT_TERRAIN_PREFS, OnEditTerrainPrefs)
ON_UPDATE_COMMAND_UI(ID_EDIT_TERRAIN_PREFS, OnUpdateEditTerrainPrefs)
ON_COMMAND(ID_TERRAIN_LAYER_OPTIONS, OnTerrainLayerOptions)
ON_UPDATE_COMMAND_UI(ID_TERRAIN_LAYER_OPTIONS, OnUpdateTerrainLayerOptions)
ON_COMMAND(ID_APPLY_CONTINOUS_NOISE, OnApplyContinousNoise)
ON_COMMAND(ID_APPLY_MINIMUM, OnApplyMinimum)
ON_COMMAND(ID_APPLY_MAXIMUM, OnApplyMaximum)
ON_COMMAND(ID_APPLY_FLATTEN, OnApplyFlatten)
ON_COMMAND(ID_APPLY_POSTERIZE, OnApplyPosterize)
ON_COMMAND(ID_OPTIMIZE_LAYERS, OnOptimizeLayers)
ON_COMMAND(ID_TBRUSH_CONTINOUS_NOISE, OnTbrushContinousNoise)
ON_COMMAND(ID_TBRUSH_FILTER, OnTbrushFilter)
ON_COMMAND(ID_TBRUSH_FLATTEN, OnTbrushFlatten)
ON_COMMAND(ID_TBRUSH_MAXIMUM, OnTbrushMaximum)
ON_COMMAND(ID_TBRUSH_MINIMUM, OnTbrushMinimum)
ON_COMMAND(ID_TBRUSH_POSTERIZE, OnTbrushPosterize)
ON_COMMAND(ID_TERRAIN_PROPERTIES, OnTerrainProperties)
#endif
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(ID_BUFFER01, ID_BUFFER10, OnKeyBuffer)
ON_COMMAND_RANGE(ID_EDIT_BUFFER01, ID_EDIT_BUFFER10, OnKeyEditBuffer)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWorldEditorView construction/destruction
CWorldEditorView::CWorldEditorView()
{
m_iaInputAction = IA_NONE;
m_iaLastInputAction=IA_NONE;
m_pbpoTranslationPlane = NULL;
m_vpViewPrefs = theApp.m_vpViewPrefs[ 0];
m_ptProjectionType = CSlaveViewer::PT_PERSPECTIVE;
m_pdpDrawPort = NULL;
m_pvpViewPort = NULL;
m_fGridInMeters = 10.0f;
m_pbpoRightClickedPolygon = NULL;
m_penEntityHitOnContext = NULL;
m_iDragVertice = -1;
m_iDragEdge = -1;
_pselbvxtSelectOnRender = NULL;
_pselenSelectOnRender = NULL;
m_bRequestVtxClickSelect = FALSE;
m_bRequestVtxLassoSelect = FALSE;
m_bRequestEntityLassoSelect = FALSE;
m_strTest="";
}
CWorldEditorView::~CWorldEditorView()
{
}
BOOL CWorldEditorView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
static void GetToolTipText(void *pView, char *pToolTipText)
{
CWorldEditorView *pWorldEditorView = (CWorldEditorView *) pView;
pWorldEditorView->GetToolTipText( pToolTipText);
}
/////////////////////////////////////////////////////////////////////////////
// CWorldEditorView drawing
void CWorldEditorView::RenderBackdropTexture(CDrawPort *pDP,
FLOAT3D v0, FLOAT3D v1, FLOAT3D v2, FLOAT3D v3,
CTextureObject &to)
{
if( to.GetData() == NULL) return;
CWorldEditorDoc* pDoc = GetDocument();
FLOAT3D v0p, v1p, v2p, v3p;
// create a slave viewer
CSlaveViewer svViewer(GetChildFrame()->m_mvViewer, m_ptProjectionType, pDoc->m_plGrid, pDP);
// create a projection for slave viewer
CAnyProjection3D prProjection;
svViewer.MakeProjection(prProjection);
prProjection->Prepare();
// project current base vertice and convert y coordinate from mathemathical representation
// into screen representation
prProjection->ProjectCoordinate( v0, v0p); v0p(2) = pDP->GetHeight() - v0p(2);
prProjection->ProjectCoordinate( v1, v1p); v1p(2) = pDP->GetHeight() - v1p(2);
prProjection->ProjectCoordinate( v2, v2p); v2p(2) = pDP->GetHeight() - v2p(2);
prProjection->ProjectCoordinate( v3, v3p); v3p(2) = pDP->GetHeight() - v3p(2);
FLOATaabbox3D box;
box |= v0p;
box |= v1p;
box |= v2p;
box |= v3p;
if( (box.Size()(1) > 2) && (box.Size()(2) > 2) )
{
// create rectangle for backdrop picture
PIXaabbox2D rectPict;
rectPict = PIXaabbox2D( PIX2D((SLONG)box.Min()(1), (SLONG)box.Min()(2)),
PIX2D((SLONG)box.Max()(1), (SLONG)box.Max()(2)) );
pDP->PutTexture( &to, rectPict);
}
}
BOOL _bCursorMoved=FALSE;
void CWorldEditorView::RenderView( CDrawPort *pDP)
{
CWorldEditorDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CMainFrame* pMainFrame = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
CChildFrame *pChild = GetChildFrame();
BOOL bCSGOn = pDoc->m_pwoSecondLayer != NULL;
BOOL bAlt = (GetKeyState( VK_MENU)&0x8000) != 0;
BOOL bSpace = (GetKeyState( VK_SPACE)&0x8000) != 0;
BOOL bCtrl = (GetKeyState( VK_CONTROL)&0x8000) != 0;
// create a slave viewer
CSlaveViewer svViewer(GetChildFrame()->m_mvViewer, m_ptProjectionType,
pDoc->m_plGrid, pDP);
// copy view's world rendering preferences to global world rendering preferences
_wrpWorldRenderPrefs = m_vpViewPrefs.m_wrpWorldRenderPrefs;
_wrpWorldRenderPrefs.SetTextureLayerOn( theApp.m_bTexture1, 0);
_wrpWorldRenderPrefs.SetTextureLayerOn( theApp.m_bTexture2, 1);
_wrpWorldRenderPrefs.SetTextureLayerOn( theApp.m_bTexture3, 2);
// set shadow type from child frame
_wrpWorldRenderPrefs.SetShadowsType( GetChildFrame()->m_stShadowType);
// copy view's model rendering preferences to global model rendering preferences
_mrpModelRenderPrefs = m_vpViewPrefs.m_mrpModelRenderPrefs;
// copy auto mip modeling flag from child frame
_wrpWorldRenderPrefs.SetAutoMipBrushingOn( GetChildFrame()->m_bAutoMipBrushingOn);
// and manual mip factor
_wrpWorldRenderPrefs.SetManualMipBrushingFactor( GetChildFrame()->m_fManualMipBrushingFactor);
// view visibility tweaking
_wrpWorldRenderPrefs.SetVisTweaksOn(GetChildFrame()->m_bShowVisibilityTweaks);
_wrpWorldRenderPrefs.DisableVisTweaks(GetChildFrame()->m_bDisableVisibilityTweaks);
_pselbscVisTweaks=&pDoc->m_selSectorSelection;
_wrpWorldRenderPrefs.SetSelectedEntityModel( theApp.m_pEntityMarkerModelObject);
_wrpWorldRenderPrefs.SetSelectedPortalModel( theApp.m_pPortalMarkerModelObject);
_wrpWorldRenderPrefs.SetEmptyBrushModel( theApp.m_pEmptyBrushModelObject);
// if we are using automatic rendering range
if( m_vpViewPrefs.m_bAutoRenderingRange)
{
// set rendering range of 1.5 x viewer's target distance
FLOAT fTargetDistance = svViewer.GetTargetDistance();
// we have to take second layer distance in considiration also
FLOAT fMinimumRenderRange = fTargetDistance;
// if second layer's world exists
if( pDoc->m_pwoSecondLayer != NULL)
{
CPlacement3D plViewer = GetChildFrame()->m_mvViewer.GetViewerPlacement();
// calculate viewer-layer distance
FLOAT fViewerLayerDistance =
(plViewer.pl_PositionVector - pDoc->m_plSecondLayer.pl_PositionVector).Length();
// if current minimum rendering range is smaller than one that viewer-layer
// distance would request
if( fMinimumRenderRange < fViewerLayerDistance )
{
fMinimumRenderRange = fViewerLayerDistance;
}
}
// don't allow minimum rendering range to drop below 1.5 m
if( fMinimumRenderRange < 1.5f)
{
fMinimumRenderRange = 1.5f;
}
_wrpWorldRenderPrefs.SetMinimumRenderRange( fMinimumRenderRange * 1.5f);
}
// we are using fixed rendering range
else
{
// set global rendering range from fixed one remembered in prefs
_wrpWorldRenderPrefs.SetMinimumRenderRange( m_vpViewPrefs.m_fRenderingRange);
}
// set visibility of link lines
_wrpWorldRenderPrefs.SetShowTargetsOn(pChild->m_bShowTargets);
// set visibility of entity names
_wrpWorldRenderPrefs.SetShowEntityNamesOn(pChild->m_bShowEntityNames);
// find out if z buffer clearing should occure
BOOL bClearZBuffer = FALSE;
BOOL bClearScreen = TRUE;
// get world and model polygon fill flags
BOOL bModelPolygonFilling =
(_mrpModelRenderPrefs.GetRenderType() & RT_TEXTURE_MASK) != RT_NO_POLYGON_FILL;
// find out if any of isometric projection modes is currently on
BOOL bPerspectiveOn = m_ptProjectionType == CSlaveViewer::PT_PERSPECTIVE;
BOOL bPolygonFillOn = _wrpWorldRenderPrefs.GetPolygonsFillType() != CWorldRenderPrefs::FT_NONE;
// if something requires clearing of z-buffer
if( bPolygonFillOn ||
pDoc->m_bOrientationIcons ||
((!bCSGOn && bPerspectiveOn) && GetChildFrame()->m_bSceneRenderingTime) ||
m_vpViewPrefs.m_bMeasurementTape ||
theApp.m_bMeasureModeOn || theApp.m_bCutModeOn)
{
bClearZBuffer = TRUE;
}
// if we will render models using polygon fill, we must clear z-buffer
if( bModelPolygonFilling)
{
bClearZBuffer = TRUE;
}
// if rendering will fill whole screen along with z-buffer
if( bPolygonFillOn && bPerspectiveOn)
{
bClearZBuffer = FALSE;
bClearScreen = FALSE;
}
COLOR colBcgFill=m_vpViewPrefs.m_PaperColor;
if(_wrpWorldRenderPrefs.IsBackgroundTextureOn())
{
bClearScreen = TRUE;
colBcgFill=pDoc->m_woWorld.wo_colBackground;
}
// set selected entity model
_wrpWorldRenderPrefs.SetSelectedEntityModel( theApp.m_pEntityMarkerModelObject);
// set selected portal model
_wrpWorldRenderPrefs.SetSelectedPortalModel( theApp.m_pPortalMarkerModelObject);
// set empty brush model
_wrpWorldRenderPrefs.SetEmptyBrushModel( theApp.m_pEmptyBrushModelObject);
switch( pDoc->GetEditingMode())
{
case POLYGON_MODE:
{
_wrpWorldRenderPrefs.SetSelectionType( CWorldRenderPrefs::ST_POLYGONS);
break;
}
case SECTOR_MODE:
{
_wrpWorldRenderPrefs.SetSelectionType( CWorldRenderPrefs::ST_SECTORS);
break;
}
case ENTITY_MODE:
{
_wrpWorldRenderPrefs.SetSelectionType( CWorldRenderPrefs::ST_ENTITIES);
break;
}
case VERTEX_MODE:
{
_wrpWorldRenderPrefs.SetSelectionType( CWorldRenderPrefs::ST_VERTICES);
break;
}
#if SE1_TERRAINS
case TERRAIN_MODE:
{
_wrpWorldRenderPrefs.SetSelectionType( CWorldRenderPrefs::ST_NONE);
break;
}
#endif
case CSG_MODE:
{
_wrpWorldRenderPrefs.SetSelectionType( CWorldRenderPrefs::ST_NONE);
break;
}
default: { FatalError("Unknown editing mode."); break;};
}
// if selection shouldn't be rendered and we are not in vertex mode (selection should always be rendered)
if( !GetChildFrame()->m_bSelectionVisible && (pDoc->GetEditingMode()!= VERTEX_MODE) )
{
_wrpWorldRenderPrefs.SetSelectionType( CWorldRenderPrefs::ST_NONE);
}
// create a projection for slave viewer
CAnyProjection3D prProjection;
svViewer.MakeProjection(prProjection);
// set object placement
prProjection->ObjectPlacementL() = pDoc->m_plGrid;
#if SE1_WRP_FARCLIP
if( !bPerspectiveOn && !_wrpWorldRenderPrefs.wrp_bApplyFarClipPlaneInIsometricProjection)
{
prProjection->FarClipDistanceL() = -1;
}
else
{
prProjection->FarClipDistanceL() = _wrpWorldRenderPrefs.wrp_fFarClipPlane;
}
#endif
// prepare the projection
prProjection->Prepare();
// if screen clearance is required
if( bClearScreen)
{
try
{
m_toBcgPicture.SetData_t(CTString(m_vpViewPrefs.m_achrBcgPicture));
}
// if failed
catch (char *strError)
{
(void) strError;
}
if( m_toBcgPicture.GetData() != NULL)
{
// fill background with bcg picture
PIXaabbox2D screenBox;
screenBox = PIXaabbox2D( PIX2D(0,0), PIX2D(pDP->GetWidth(), pDP->GetHeight()) );
pDP->PutTexture( &m_toBcgPicture, screenBox);
}
else
{
// clear background using current color form rendering preferences
pDP->Fill(colBcgFill | CT_OPAQUE);
}
if( pDoc->m_woWorld.wo_strBackdropUp != "" && GetChildFrame()->m_bRenderViewPictures)
{
FLOAT3D v0 = FLOAT3D(pDoc->m_woWorld.wo_fUpCX-pDoc->m_woWorld.wo_fUpW/2.0f, 0.0f,
pDoc->m_woWorld.wo_fUpCZ-pDoc->m_woWorld.wo_fUpL/2.0f);
FLOAT3D v1 = FLOAT3D(pDoc->m_woWorld.wo_fUpCX+pDoc->m_woWorld.wo_fUpW/2.0f, 0.0f,
pDoc->m_woWorld.wo_fUpCZ-pDoc->m_woWorld.wo_fUpL/2.0f);
FLOAT3D v2 = FLOAT3D(pDoc->m_woWorld.wo_fUpCX+pDoc->m_woWorld.wo_fUpW/2.0f, 0.0f,
pDoc->m_woWorld.wo_fUpCZ+pDoc->m_woWorld.wo_fUpL/2.0f);
FLOAT3D v3 = FLOAT3D(pDoc->m_woWorld.wo_fUpCX-pDoc->m_woWorld.wo_fUpW/2.0f, 0.0f,
pDoc->m_woWorld.wo_fUpCZ+pDoc->m_woWorld.wo_fUpL/2.0f);
RenderBackdropTexture( pDP, v0, v1, v2, v3, pDoc->m_toBackdropUp);
}
if( pDoc->m_woWorld.wo_strBackdropFt != "" && GetChildFrame()->m_bRenderViewPictures)
{
FLOAT3D v0 = FLOAT3D(pDoc->m_woWorld.wo_fFtCX-pDoc->m_woWorld.wo_fFtW/2.0f,
pDoc->m_woWorld.wo_fFtCY-pDoc->m_woWorld.wo_fFtH/2.0f, 0.0f);
FLOAT3D v1 = FLOAT3D(pDoc->m_woWorld.wo_fFtCX+pDoc->m_woWorld.wo_fFtW/2.0f,
pDoc->m_woWorld.wo_fFtCY-pDoc->m_woWorld.wo_fFtH/2.0f, 0.0f);
FLOAT3D v2 = FLOAT3D(pDoc->m_woWorld.wo_fFtCX+pDoc->m_woWorld.wo_fFtW/2.0f,
pDoc->m_woWorld.wo_fFtCY+pDoc->m_woWorld.wo_fFtH/2.0f, 0.0f);
FLOAT3D v3 = FLOAT3D(pDoc->m_woWorld.wo_fFtCX-pDoc->m_woWorld.wo_fFtW/2.0f,
pDoc->m_woWorld.wo_fFtCY+pDoc->m_woWorld.wo_fFtH/2.0f, 0.0f);
RenderBackdropTexture( pDP, v0, v1, v2, v3, pDoc->m_toBackdropFt);
}
if( pDoc->m_woWorld.wo_strBackdropRt != "" && GetChildFrame()->m_bRenderViewPictures)
{
FLOAT3D v0 = FLOAT3D(0.0f, pDoc->m_woWorld.wo_fRtCY-pDoc->m_woWorld.wo_fRtH/2.0f,
pDoc->m_woWorld.wo_fRtCZ-pDoc->m_woWorld.wo_fRtL/2.0f);
FLOAT3D v1 = FLOAT3D(0.0f, pDoc->m_woWorld.wo_fRtCY+pDoc->m_woWorld.wo_fRtH/2.0f,
pDoc->m_woWorld.wo_fRtCZ-pDoc->m_woWorld.wo_fRtL/2.0f);
FLOAT3D v2 = FLOAT3D(0.0f, pDoc->m_woWorld.wo_fRtCY+pDoc->m_woWorld.wo_fRtH/2.0f,
pDoc->m_woWorld.wo_fRtCZ+pDoc->m_woWorld.wo_fRtL/2.0f);
FLOAT3D v3 = FLOAT3D(0.0f, pDoc->m_woWorld.wo_fRtCY-pDoc->m_woWorld.wo_fRtH/2.0f,
pDoc->m_woWorld.wo_fRtCZ+pDoc->m_woWorld.wo_fRtL/2.0f);
RenderBackdropTexture( pDP, v0, v1, v2, v3, pDoc->m_toBackdropRt);
}
// if object should me rendered as backdrop
if( GetChildFrame()->m_bRenderViewPictures)
{
CObject3D &ob = pDoc->m_o3dBackdropObject;
FOREACHINDYNAMICARRAY(ob.ob_aoscSectors, CObjectSector, itosc)
{
FOREACHINDYNAMICARRAY(itosc->osc_aoedEdges, CObjectEdge, itoe)
{
FLOAT3D vtx0 = DOUBLEtoFLOAT(*itoe->oed_Vertex0);
FLOAT3D vtx1 = DOUBLEtoFLOAT(*itoe->oed_Vertex1);
prProjection->PreClip( vtx0, vtx0);
prProjection->PreClip( vtx1, vtx1);
prProjection->ClipLine(vtx0, vtx1);
// apply perspective
FLOAT3D vtx0p, vtx1p;
prProjection->PostClip( vtx0, vtx0p);
prProjection->PostClip( vtx1, vtx1p);
// draw one line of bounding box
pDP->DrawLine( (PIX)vtx0p(1), (PIX)vtx0p(2), (PIX)vtx1p(1), (PIX)vtx1p(2),
C_dGRAY|CT_OPAQUE);
}
}
}
}
// if z-buffer clearance is required
if( bClearZBuffer)
{
// erase z-buffer
pDP->FillZBuffer(ZBUF_BACK);
}
FLOAT3D fGridOrigin;
// project grid origin
prProjection->ProjectCoordinate( FLOAT3D( 0.0f, 0.0f, 0.0f), fGridOrigin);
// convert y coordinate form mathematical form info screen space
fGridOrigin(2) = pDP->GetHeight() - fGridOrigin(2);
// calculate grid in pixels but there must be bigger than given minimal size
#define SMALLEST_ALLOWED_GRID_IN_PIXELS 30
// get zoom factor
FLOAT fZoom = svViewer.GetZoomFactor();
// declare decadic grid in meters
FLOAT afDecadicGridInMeters[] = {0.25f,0.50f,1.0f,2.5f,5.0f,10.0f,25.0f,50.0f,100.0f,
250.0f,500.0f,1000.0f,10000.0f,100000.0f};
FLOAT afBinaryGridInMeters[] = {0.25f,0.50f,1.0f,2.0f,4.0f,8.0f,16.0f,32.0f,64.0f,128.0f,256.0f,
512.0f,1024.0f,2048.0f,4096.0f,8192.0f,16384.0f,32768.0f,65536.0f};
// select max grid value
if( theApp.m_bDecadicGrid)
{
m_fGridInMeters = afDecadicGridInMeters[ sizeof( afDecadicGridInMeters)/sizeof(FLOAT)-1];
}
else
{
m_fGridInMeters = afBinaryGridInMeters[ sizeof( afBinaryGridInMeters)/sizeof(FLOAT)-1];
}
// ptr to curently active grid table
FLOAT *pafGridInMeters;
INDEX ctTableMembers;
// select active table
if( theApp.m_bDecadicGrid)
{
pafGridInMeters = afDecadicGridInMeters;
ctTableMembers = sizeof( afDecadicGridInMeters)/sizeof(FLOAT);
}
else
{
pafGridInMeters = afBinaryGridInMeters;
ctTableMembers = sizeof( afBinaryGridInMeters)/sizeof(FLOAT);
}
// for all members in precalculated grid in meters array
for( INDEX i=0; i<ctTableMembers; i++)
{
// calculate grid steep
m_fpixGridSteep = fZoom * pafGridInMeters[ i];
// is it bigger than smallest allowed grid size in pixels
if( m_fpixGridSteep >= SMALLEST_ALLOWED_GRID_IN_PIXELS)
{
m_fGridInMeters = pafGridInMeters[ i];
break;
}
}
// we have calculated wanted grid in pixels, value is stored in pixGridSteep
// if grid on, draw it
if( GetChildFrame()->m_bGridOn && !bPerspectiveOn && !bPolygonFillOn)
{
// get grid's origin projected point
FLOAT fGridOriginX = fGridOrigin(1);
FLOAT fGridOriginY = fGridOrigin(2);
// calculate starting coordinates of left-up grid line
FLOAT fGridX = fGridOriginX - (m_fpixGridSteep * (int)(fGridOriginX / m_fpixGridSteep));
FLOAT fGridY = fGridOriginY - (m_fpixGridSteep * (int)(fGridOriginY / m_fpixGridSteep));
// remember these start grid values so they can be used for measurement
m_fGridX = fGridX;
m_fGridY = fGridY;
// style of grid line
ULONG ulLineStyle;
// loop all vertical grid lines
#define LINE_EPSILON 0.05f
FOREVER
{
// does this grid lines touch origin point
if( Abs(fGridX - fGridOriginX) < LINE_EPSILON )
{
// if so, draw full line
ulLineStyle = _FULL_;
}
else
{
// does not, draw point line
ulLineStyle = _POINT_;
}
// draw one vertical grid line
pDP->DrawLine( (int) fGridX, 0, (int) fGridX, pDP->GetHeight()-1,
m_vpViewPrefs.m_GridColor|CT_OPAQUE, ulLineStyle);
// move to next grid line
fGridX += m_fpixGridSteep;
// is coordinate passed draw port's width
if( fGridX > pDP->GetWidth())
{
// if so, vertical grid is drawn, stop endless loop
break;
}
}
// loop all horizontal grid lines
FOREVER
{
// does this grid lines touch origin point
if( Abs(fGridY - fGridOriginY) < LINE_EPSILON )
{
// if so, draw full line
ulLineStyle = _FULL_;
}
else
{
// does not, draw point line
ulLineStyle = _POINT_;
}
// draw one vertical grid line
pDP->DrawLine( 0, (int) fGridY, pDP->GetWidth()-1, (int) fGridY,
m_vpViewPrefs.m_GridColor|CT_OPAQUE, ulLineStyle);
// move to next grid line
fGridY += m_fpixGridSteep;
// is coordinate passed draw port's height
if( fGridY > pDP->GetHeight())
{
// if so, vertical grid is drawn, stop endless loop
break;
}
}
}
// if we should draw measurement tape
if( m_vpViewPrefs.m_bMeasurementTape && !bPerspectiveOn)
{
// define tape in meters for decadic grid type
FLOAT afDecadicTapeInMeters[] =
{ 0.01f, 0.1f, 1.0f, 10.0f, 100.0f, 1000.0f, 10000.0f, 100000.0f};
CTString astrDecadicTapeInMeters[] =
{ "1 mm", "1 cm", "1 m", "10 m", "100 m", "1 km", "10 km", "100 km"};
// define tape in meters for binary grid type
FLOAT afBinaryTapeInMeters[] =
{ 1.0f/64, 1.0f/8, 1.0f, 8.0f, 64.0f, 256.0f, 1024.0f, 4096.0f, 16484.0f, 65536.0f};
CTString astrBinaryTapeInMeters[] =
{ "1/64 m", "1/8 m", "1 m", "8 m", "64 m", "256 m", "1024 m", "4096 m", "16384 m", "65536 m"};
CTString *pastrTapeInMetersTable;
FLOAT *pafTapeInMetersTable;
INDEX ctTableMembers;
// select active table
if( theApp.m_bDecadicGrid)
{
pafTapeInMetersTable = afDecadicTapeInMeters;
pastrTapeInMetersTable = astrDecadicTapeInMeters;
ctTableMembers = sizeof( afDecadicTapeInMeters)/sizeof(FLOAT);
}
else
{
pafTapeInMetersTable = afBinaryTapeInMeters;
pastrTapeInMetersTable = astrBinaryTapeInMeters;
ctTableMembers = sizeof( afBinaryTapeInMeters)/sizeof(FLOAT);
}
// here we will calculate our tape lenght in meters
FLOAT fTapeLenMeters;
// here we will calculate our tape lenght in pixels
PIX pixTapeLen;
// here we will place appropriate text saying tape's lenght in meters
CTString strTapeLen;
// for all possible dimensions of measurement tape
for( INDEX i=ctTableMembers-1; i>=0; i--)
{
// get tape len in meters
fTapeLenMeters = pafTapeInMetersTable[ i];
// get appropriate descriptive string
strTapeLen = pastrTapeInMetersTable[ i];
// calculate tape in pixels
pixTapeLen = (PIX)(fZoom * fTapeLenMeters);
// is it smaller than 75% of draw port's width
if( pixTapeLen <= pDP->GetWidth()*3/4)
{
// it is, we found our tape dimension
break;
}
}
// calculate tape position on screen
PIX x = (PIX) ( pDP->GetWidth() * 0.05f); // x starts at 5% of draw port's width
PIX y = (PIX) ( pDP->GetHeight()* 0.95f); // y starts at 95% of draw port's height
// draw tape's left end, little vertical line
pDP->DrawLine( x, y-2, x, y+2, C_BLACK|CT_OPAQUE);
// draw tape's main, horizontal little
pDP->DrawLine( x, y, x+pixTapeLen, y, C_BLACK|CT_OPAQUE);
// draw tape's right end, little vertical line
pDP->DrawLine( x+pixTapeLen, y-2, x+pixTapeLen, y+2, C_BLACK|CT_OPAQUE);
// type appropriate text, lenght in meters
pDP->SetFont( theApp.m_pfntSystem);
pDP->SetTextAspect( 1.0f);
pDP->SetTextScaling( 1.0f);
pDP->PutText( strTapeLen, x, y-16);
}
// we are not rendering scene over already rendered scene (used for CSG layer)
pDP->SetOverlappedRendering(FALSE);
// print grid size (or no grid)
char strPaneText[ 128];
sprintf( strPaneText, "Grid: %g m", m_fGridInMeters);
pMainFrame->m_wndStatusBar.SetPaneText( GRID_PANE, CString(strPaneText), TRUE);
// create renderer and render world
CEntity *penOnlySelected = NULL;
if( pDoc->m_selEntitySelection.Count() == 1)
{
pDoc->m_selEntitySelection.Lock();
penOnlySelected = &pDoc->m_selEntitySelection[0];
pDoc->m_selEntitySelection.Unlock();
}
// request vertex selecting from renderer
if( m_bRequestVtxClickSelect)
{
_bSelectAlternative = m_bOnSelectVertexShiftDown;
_pselbvxtSelectOnRender = &pDoc->m_selVertexSelection;
}
if( m_bRequestVtxLassoSelect)
{
_bSelectAlternative = m_bOnSelectVertexAltDown;
_pselbvxtSelectOnRender = &pDoc->m_selVertexSelection;
_pavpixSelectLasso = &m_avpixLaso;
}
if( m_bRequestEntityLassoSelect)
{
_bSelectAlternative = m_bOnSelectEntityAltDown;
_pselenSelectOnRender = &pDoc->m_selEntitySelection;
_pavpixSelectLasso = &m_avpixLaso;
}
#if SE1_TERRAINS
if(pDoc->GetEditingMode()==TERRAIN_MODE &&
theApp.m_penLastTerrainHit==GetTerrainEntity() &&
!_pInput->IsInputEnabled())
{
RenderAndApplyTerrainEditBrush(theApp.m_vLastTerrainHit);
}
#endif
if( GetChildFrame()->m_bViewFromEntity &&
(penOnlySelected != NULL) &&
!(penOnlySelected->GetFlags()&ENF_ANCHORED) &&
bPerspectiveOn )
{
// create a projection for slave viewer
CAnyProjection3D prProjection;
svViewer.MakeProjection(prProjection);
prProjection->ViewerPlacementL() = penOnlySelected->GetPlacement();
prProjection->Prepare();
::RenderView(pDoc->m_woWorld, *penOnlySelected, prProjection, *pDP);
}
else
{
// create renderer and render world
::RenderView(pDoc->m_woWorld, *(CEntity*) NULL, prProjection, *pDP);
}
// don't allow further laso select tests
if( m_bRequestVtxLassoSelect || m_bRequestEntityLassoSelect)
{
m_avpixLaso.Clear();
}
_pselbvxtSelectOnRender = NULL;
_pselenSelectOnRender = NULL;
m_bRequestVtxClickSelect = FALSE;
m_bRequestVtxLassoSelect = FALSE;
m_bRequestEntityLassoSelect = FALSE;
_pavpixSelectLasso = NULL;
INDEX ctLasoPts = m_avpixLaso.Count();
if(((m_iaInputAction == IA_SELECT_LASSO_BRUSH_VERTEX) ||
(m_iaInputAction == IA_SELECT_LASSO_ENTITY)) && (ctLasoPts>1) )
{
for( INDEX iKnot=0; iKnot<ctLasoPts-1; iKnot++)