GotoLocationDialog.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // GotoLocationDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "GotoLocationDialog.h"
  23. #include "CameraMgr.h"
  24. #include "Utils.h"
  25. #include "euler.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. //
  33. // GotoLocationDialogClass
  34. //
  35. /////////////////////////////////////////////////////////////////////////////
  36. GotoLocationDialogClass::GotoLocationDialogClass (CWnd* pParent /*=NULL*/)
  37. : CDialog(GotoLocationDialogClass::IDD, pParent)
  38. {
  39. //{{AFX_DATA_INIT(GotoLocationDialogClass)
  40. // NOTE: the ClassWizard will add member initialization here
  41. //}}AFX_DATA_INIT
  42. return ;
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. //
  46. // DoDataExchange
  47. //
  48. /////////////////////////////////////////////////////////////////////////////
  49. void
  50. GotoLocationDialogClass::DoDataExchange (CDataExchange* pDX)
  51. {
  52. CDialog::DoDataExchange(pDX);
  53. //{{AFX_DATA_MAP(GotoLocationDialogClass)
  54. DDX_Control(pDX, IDC_ZPOS_SPIN, m_ZPosSpin);
  55. DDX_Control(pDX, IDC_YPOS_SPIN, m_YPosSpin);
  56. DDX_Control(pDX, IDC_XPOS_SPIN, m_XPosSpin);
  57. DDX_Control(pDX, IDC_FACING_SPIN, m_FacingSpin);
  58. //}}AFX_DATA_MAP
  59. return ;
  60. }
  61. BEGIN_MESSAGE_MAP(GotoLocationDialogClass, CDialog)
  62. //{{AFX_MSG_MAP(GotoLocationDialogClass)
  63. //}}AFX_MSG_MAP
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. //
  67. // OnInitDialog
  68. //
  69. /////////////////////////////////////////////////////////////////////////////
  70. BOOL
  71. GotoLocationDialogClass::OnInitDialog (void)
  72. {
  73. CDialog::OnInitDialog ();
  74. //
  75. // Turn all the edit controls into 'float' controls that will
  76. // allow the user to type only numbers (with decimals and signs)
  77. //
  78. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_XPOS_EDIT));
  79. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_YPOS_EDIT));
  80. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_ZPOS_EDIT));
  81. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_FACING_EDIT));
  82. //
  83. // Set the float control ranges
  84. //
  85. m_XPosSpin.SetRange32 (-1000000, 1000000);
  86. m_YPosSpin.SetRange32 (-1000000, 1000000);
  87. m_ZPosSpin.SetRange32 (-1000000, 1000000);
  88. m_FacingSpin.SetRange32 (-1000000, 1000000);
  89. //
  90. // Get the camera's position and rotation
  91. //
  92. CameraClass *camera = ::Get_Camera_Mgr ()->Get_Camera ();
  93. Vector3 position = camera->Get_Position ();
  94. Matrix3D tm = camera->Get_Transform ();
  95. Vector3 look_at_pos = tm.Get_Z_Vector ();
  96. float facing = WWMath::Wrap ((float)::atan2 (look_at_pos.Y, look_at_pos.X), 0.0F, DEG_TO_RADF (360));
  97. //
  98. // Put the camera's current position and rotation into the
  99. // dialog controls.
  100. //
  101. ::SetDlgItemFloat (m_hWnd, IDC_XPOS_EDIT, position.X);
  102. ::SetDlgItemFloat (m_hWnd, IDC_YPOS_EDIT, position.Y);
  103. ::SetDlgItemFloat (m_hWnd, IDC_ZPOS_EDIT, position.Z);
  104. ::SetDlgItemFloat (m_hWnd, IDC_FACING_EDIT, RAD_TO_DEG (facing));
  105. return TRUE;
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. //
  109. // OnOK
  110. //
  111. /////////////////////////////////////////////////////////////////////////////
  112. void
  113. GotoLocationDialogClass::OnOK (void)
  114. {
  115. //
  116. // Get the new settings for the camera from the dialog
  117. //
  118. Vector3 pos (0, 0, 0);
  119. pos.X = ::GetDlgItemFloat (m_hWnd, IDC_XPOS_EDIT, true);
  120. pos.Y = ::GetDlgItemFloat (m_hWnd, IDC_YPOS_EDIT, true);
  121. pos.Z = ::GetDlgItemFloat (m_hWnd, IDC_ZPOS_EDIT, true);
  122. float facing = ::GetDlgItemFloat (m_hWnd, IDC_FACING_EDIT, true);
  123. //
  124. // Create a transform for the camera using these new settings
  125. //
  126. float x_val = ::cos (DEG_TO_RADF (facing));
  127. float y_val = ::sin (DEG_TO_RADF (facing));
  128. Vector3 y_axis = Vector3 (0, 0, 1);
  129. Vector3 z_axis = Vector3 (x_val, y_val, 0);
  130. Vector3 x_axis = Vector3::Cross_Product (y_axis, z_axis);
  131. Matrix3D tm (x_axis, y_axis, z_axis, pos);
  132. //
  133. // Pass the new transform onto the camera
  134. //
  135. ::Get_Camera_Mgr ()->Set_Transform (tm);
  136. CDialog::OnOK ();
  137. return ;
  138. }