DlgAllignVertices.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // DlgAllignVertices.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include "WorldEditor.h"
  16. #include "DlgAllignVertices.h"
  17. #ifdef _DEBUG
  18. #undef new
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CDlgAllignVertices dialog
  25. CDlgAllignVertices::CDlgAllignVertices(CWnd* pParent /*=NULL*/)
  26. : CDialog(CDlgAllignVertices::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CDlgAllignVertices)
  29. // NOTE: the ClassWizard will add member initialization here
  30. //}}AFX_DATA_INIT
  31. }
  32. void CDlgAllignVertices::DoDataExchange(CDataExchange* pDX)
  33. {
  34. CDialog::DoDataExchange(pDX);
  35. //{{AFX_DATA_MAP(CDlgAllignVertices)
  36. // NOTE: the ClassWizard will add DDX and DDV calls here
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CDlgAllignVertices, CDialog)
  40. //{{AFX_MSG_MAP(CDlgAllignVertices)
  41. ON_BN_CLICKED(IDC_ALLIGN_X, OnAllignX)
  42. ON_BN_CLICKED(IDC_ALLIGN_Y, OnAllignY)
  43. ON_BN_CLICKED(IDC_ALLIGN_Z, OnAllignZ)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDlgAllignVertices message handlers
  48. DOUBLE3D CDlgAllignVertices::GetLastSelectedVertex(void)
  49. {
  50. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  51. DOUBLE3D vNew=DOUBLE3D(0,0,0);
  52. FOREACHINDYNAMICCONTAINER( pDoc->m_selVertexSelection, CBrushVertex, itvtx)
  53. {
  54. vNew=FLOATtoDOUBLE(itvtx->bvx_vAbsolute);
  55. }
  56. return vNew;
  57. }
  58. void CDlgAllignVertices::OnAllignX()
  59. {
  60. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  61. pDoc->RememberUndo();
  62. pDoc->m_woWorld.TriangularizeForVertices( pDoc->m_selVertexSelection);
  63. DOUBLE3D vVtx=GetLastSelectedVertex();
  64. FOREACHINDYNAMICCONTAINER( pDoc->m_selVertexSelection, CBrushVertex, itvtx)
  65. {
  66. DOUBLE3D vNew=FLOATtoDOUBLE(itvtx->bvx_vAbsolute);
  67. vNew(1)=vVtx(1);
  68. itvtx->SetAbsolutePosition(vNew);
  69. }
  70. pDoc->m_woWorld.UpdateSectorsDuringVertexChange( pDoc->m_selVertexSelection);
  71. pDoc->m_woWorld.UpdateSectorsAfterVertexChange( pDoc->m_selVertexSelection);
  72. pDoc->SetModifiedFlag();
  73. EndDialog(IDOK);
  74. }
  75. void CDlgAllignVertices::OnAllignY()
  76. {
  77. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  78. pDoc->RememberUndo();
  79. pDoc->m_woWorld.TriangularizeForVertices( pDoc->m_selVertexSelection);
  80. DOUBLE3D vVtx=GetLastSelectedVertex();
  81. FOREACHINDYNAMICCONTAINER( pDoc->m_selVertexSelection, CBrushVertex, itvtx)
  82. {
  83. DOUBLE3D vNew=FLOATtoDOUBLE(itvtx->bvx_vAbsolute);
  84. vNew(2)=vVtx(2);
  85. itvtx->SetAbsolutePosition(vNew);
  86. }
  87. pDoc->m_woWorld.UpdateSectorsDuringVertexChange( pDoc->m_selVertexSelection);
  88. pDoc->m_woWorld.UpdateSectorsAfterVertexChange( pDoc->m_selVertexSelection);
  89. pDoc->SetModifiedFlag();
  90. EndDialog(IDOK);
  91. }
  92. void CDlgAllignVertices::OnAllignZ()
  93. {
  94. CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
  95. pDoc->RememberUndo();
  96. pDoc->m_woWorld.TriangularizeForVertices( pDoc->m_selVertexSelection);
  97. DOUBLE3D vVtx=GetLastSelectedVertex();
  98. FOREACHINDYNAMICCONTAINER( pDoc->m_selVertexSelection, CBrushVertex, itvtx)
  99. {
  100. DOUBLE3D vNew=FLOATtoDOUBLE(itvtx->bvx_vAbsolute);
  101. vNew(3)=vVtx(3);
  102. itvtx->SetAbsolutePosition(vNew);
  103. }
  104. pDoc->m_woWorld.UpdateSectorsDuringVertexChange( pDoc->m_selVertexSelection);
  105. pDoc->m_woWorld.UpdateSectorsAfterVertexChange( pDoc->m_selVertexSelection);
  106. pDoc->SetModifiedFlag();
  107. EndDialog(IDOK);
  108. }
  109. BOOL CDlgAllignVertices::PreTranslateMessage(MSG* pMsg)
  110. {
  111. if(pMsg->message==WM_KEYDOWN)
  112. {
  113. if( pMsg->wParam=='X') OnAllignX();
  114. if( pMsg->wParam=='Y') OnAllignY();
  115. if( pMsg->wParam=='Z') OnAllignZ();
  116. }
  117. return CDialog::PreTranslateMessage(pMsg);
  118. }