InertiaDialog.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. // InertiaDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "phystest.h"
  22. #include "InertiaDialog.h"
  23. #include "rbody.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. const int MIN_IBODY = 0;
  30. const int MAX_IBODY = 255;
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CInertiaDialog dialog
  33. CInertiaDialog::CInertiaDialog(CWnd* pParent,RigidBodyClass * obj) :
  34. CDialog(CInertiaDialog::IDD, pParent),
  35. Object(obj)
  36. {
  37. //{{AFX_DATA_INIT(CInertiaDialog)
  38. // NOTE: the ClassWizard will add member initialization here
  39. //}}AFX_DATA_INIT
  40. ASSERT(Object != NULL);
  41. }
  42. void CInertiaDialog::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CInertiaDialog)
  46. DDX_Control(pDX, IDC_IBODYZ_SPIN, m_IBodyZSpin);
  47. DDX_Control(pDX, IDC_IBODYY_SPIN, m_IBodyYSpin);
  48. DDX_Control(pDX, IDC_IBODYX_SPIN, m_IBodyXSpin);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CInertiaDialog, CDialog)
  52. //{{AFX_MSG_MAP(CInertiaDialog)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CInertiaDialog message handlers
  57. BOOL CInertiaDialog::OnInitDialog()
  58. {
  59. CDialog::OnInitDialog();
  60. m_IBodyXSpin.SetRange(MIN_IBODY * 100,MAX_IBODY * 100);
  61. m_IBodyYSpin.SetRange(MIN_IBODY * 100,MAX_IBODY * 100);
  62. m_IBodyZSpin.SetRange(MIN_IBODY * 100,MAX_IBODY * 100);
  63. Matrix3 ibody;
  64. Object->Get_Inertia(&ibody);
  65. m_IBodyXSpin.SetPos(ibody[0][0] * 100);
  66. m_IBodyYSpin.SetPos(ibody[1][1] * 100);
  67. m_IBodyZSpin.SetPos(ibody[2][2] * 100);
  68. SetDlgItemFloat(IDC_IBODYX_EDIT,ibody[0][0]);
  69. SetDlgItemFloat(IDC_IBODYY_EDIT,ibody[1][1]);
  70. SetDlgItemFloat(IDC_IBODYZ_EDIT,ibody[2][2]);
  71. return TRUE;
  72. }
  73. BOOL CInertiaDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  74. {
  75. // make the spin controls work...
  76. switch(wParam)
  77. {
  78. case IDC_IBODYX_SPIN:
  79. case IDC_IBODYY_SPIN:
  80. case IDC_IBODYZ_SPIN:
  81. LPNMUPDOWN lpnmud = (LPNMUPDOWN) lParam;
  82. if (lpnmud->hdr.code == UDN_DELTAPOS) {
  83. HWND hwnd = (HWND)SendDlgItemMessage(LOWORD(wParam),UDM_GETBUDDY);
  84. float curval = GetDlgItemFloat(GetWindowLong(hwnd,GWL_ID));
  85. curval += (float)lpnmud->iDelta / 100.0f;
  86. SetDlgItemFloat(GetWindowLong(hwnd,GWL_ID), curval);
  87. }
  88. break;
  89. }
  90. return CDialog::OnNotify(wParam, lParam, pResult);
  91. }
  92. void CInertiaDialog::OnOK()
  93. {
  94. Matrix3 ibody(1);
  95. ibody[0][0] = GetDlgItemFloat(IDC_IBODYX_EDIT);
  96. ibody[1][1] = GetDlgItemFloat(IDC_IBODYY_EDIT);
  97. ibody[2][2] = GetDlgItemFloat(IDC_IBODYZ_EDIT);
  98. Object->Set_Inertia(ibody);
  99. CDialog::OnOK();
  100. }
  101. float CInertiaDialog::GetDlgItemFloat(int controlid)
  102. {
  103. CString string;
  104. GetDlgItemText(controlid,string);
  105. return atof(string);
  106. }
  107. void CInertiaDialog::SetDlgItemFloat(int controlid,float val)
  108. {
  109. CString string;
  110. string.Format("%.2f",val);
  111. SetDlgItemText(controlid,string);
  112. }