RbodyPropertiesDialog.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. // RbodyPropertiesDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "phystest.h"
  22. #include "RbodyPropertiesDialog.h"
  23. #include "movephys.h"
  24. #include "rbody.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. const int MIN_MASS = 1;
  31. const int MAX_MASS = 255;
  32. const int MIN_ELASTICITY = 0;
  33. const int MAX_ELASTICITY = 1;
  34. const int MIN_GRAVITY = 0;
  35. const int MAX_GRAVITY = 1;
  36. const int MIN_POS = -255;
  37. const int MAX_POS = 255;
  38. const int MIN_CONTACT_STIFFNESS = 0;
  39. const int MAX_CONTACT_STIFFNESS = 255;
  40. const int MIN_CONTACT_DAMPING = 0;
  41. const int MAX_CONTACT_DAMPING = 255;
  42. const int MIN_CONTACT_LENGTH = 0;
  43. const int MAX_CONTACT_LENGTH = 2;
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CRbodyPropertiesDialog dialog
  46. CRbodyPropertiesDialog::CRbodyPropertiesDialog(CWnd* pParent,MoveablePhysClass * object) :
  47. CDialog(CRbodyPropertiesDialog::IDD, pParent),
  48. Object(object)
  49. {
  50. //{{AFX_DATA_INIT(CRbodyPropertiesDialog)
  51. //}}AFX_DATA_INIT
  52. ASSERT(Object != NULL);
  53. }
  54. void CRbodyPropertiesDialog::DoDataExchange(CDataExchange* pDX)
  55. {
  56. CDialog::DoDataExchange(pDX);
  57. //{{AFX_DATA_MAP(CRbodyPropertiesDialog)
  58. DDX_Control(pDX, IDC_LENGTH_SPIN, m_LengthSpin);
  59. DDX_Control(pDX, IDC_STIFFNESS_SPIN, m_StiffnessSpin);
  60. DDX_Control(pDX, IDC_DAMPING_SPIN, m_DampingSpin);
  61. DDX_Control(pDX, IDC_POSITIONZ_SPIN, m_PositionZSpin);
  62. DDX_Control(pDX, IDC_POSITIONY_SPIN, m_PositionYSpin);
  63. DDX_Control(pDX, IDC_POSITIONX_SPIN, m_PositionXSpin);
  64. DDX_Control(pDX, IDC_MASS_SPIN, m_MassSpin);
  65. DDX_Control(pDX, IDC_GRAVITY_SPIN, m_GravitySpin);
  66. DDX_Control(pDX, IDC_ELASTICITY_SPIN, m_ElasticitySpin);
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CRbodyPropertiesDialog, CDialog)
  70. //{{AFX_MSG_MAP(CRbodyPropertiesDialog)
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CRbodyPropertiesDialog message handlers
  75. void CRbodyPropertiesDialog::OnOK()
  76. {
  77. Object->Set_Mass(GetDlgItemFloat(IDC_MASS_EDIT));
  78. Object->Set_Gravity_Multiplier(GetDlgItemFloat(IDC_GRAVITY_EDIT));
  79. Object->Set_Elasticity(GetDlgItemFloat(IDC_ELASTICITY_EDIT));
  80. Vector3 pos;
  81. pos.X = GetDlgItemFloat(IDC_POSITIONX_EDIT);
  82. pos.Y = GetDlgItemFloat(IDC_POSITIONY_EDIT);
  83. pos.Z = GetDlgItemFloat(IDC_POSITIONZ_EDIT);
  84. Object->Set_Position(pos);
  85. float length = GetDlgItemFloat(IDC_LENGTH_EDIT);
  86. // not letting the user override stiffness and damping for now
  87. ((RigidBodyClass *)Object)->Set_Contact_Parameters(length);
  88. CDialog::OnOK();
  89. }
  90. BOOL CRbodyPropertiesDialog::OnInitDialog()
  91. {
  92. ASSERT(Object != NULL);
  93. CDialog::OnInitDialog();
  94. m_MassSpin.SetRange(MIN_MASS * 100,MAX_MASS * 100);
  95. m_GravitySpin.SetRange(MIN_GRAVITY * 100,MAX_GRAVITY * 100);
  96. m_ElasticitySpin.SetRange(MIN_ELASTICITY * 100,MAX_ELASTICITY * 100);
  97. m_PositionXSpin.SetRange(MIN_POS * 100,MAX_POS * 100);
  98. m_PositionYSpin.SetRange(MIN_POS * 100,MAX_POS * 100);
  99. m_PositionZSpin.SetRange(MIN_POS * 100,MAX_POS * 100);
  100. m_StiffnessSpin.SetRange(MIN_CONTACT_STIFFNESS * 100,MAX_CONTACT_STIFFNESS * 100);
  101. m_DampingSpin.SetRange(MIN_CONTACT_DAMPING * 100,MAX_CONTACT_DAMPING * 100);
  102. m_LengthSpin.SetRange(MIN_CONTACT_LENGTH * 100,MAX_CONTACT_LENGTH * 100);
  103. m_MassSpin.SetPos(Object->Get_Mass() * 100);
  104. m_GravitySpin.SetPos(Object->Get_Gravity_Multiplier() * 100);
  105. m_ElasticitySpin.SetPos(Object->Get_Elasticity() * 100);
  106. Vector3 position = Object->Get_Transform().Get_Translation();
  107. m_PositionXSpin.SetPos(position.X * 100);
  108. m_PositionYSpin.SetPos(position.Y * 100);
  109. m_PositionZSpin.SetPos(position.Z * 100);
  110. float stiffness,damping,length;
  111. ((RigidBodyClass *)Object)->Get_Contact_Parameters(&stiffness,&damping,&length);
  112. m_StiffnessSpin.SetPos(stiffness * 100);
  113. m_DampingSpin.SetPos(damping * 100);
  114. m_LengthSpin.SetPos(length * 100);
  115. SetDlgItemFloat(IDC_MASS_EDIT,Object->Get_Mass());
  116. SetDlgItemFloat(IDC_GRAVITY_EDIT,Object->Get_Gravity_Multiplier());
  117. SetDlgItemFloat(IDC_ELASTICITY_EDIT,Object->Get_Elasticity());
  118. SetDlgItemFloat(IDC_POSITIONX_EDIT,position.X);
  119. SetDlgItemFloat(IDC_POSITIONY_EDIT,position.Y);
  120. SetDlgItemFloat(IDC_POSITIONZ_EDIT,position.Z);
  121. SetDlgItemFloat(IDC_STIFFNESS_EDIT,stiffness);
  122. SetDlgItemFloat(IDC_DAMPING_EDIT,damping);
  123. SetDlgItemFloat(IDC_LENGTH_EDIT,length);
  124. return TRUE;
  125. }
  126. float CRbodyPropertiesDialog::GetDlgItemFloat(int controlid)
  127. {
  128. CString string;
  129. GetDlgItemText(controlid,string);
  130. return atof(string);
  131. }
  132. void CRbodyPropertiesDialog::SetDlgItemFloat(int controlid,float val)
  133. {
  134. CString string;
  135. string.Format("%.2f",val);
  136. SetDlgItemText(controlid,string);
  137. }
  138. BOOL CRbodyPropertiesDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  139. {
  140. // make the spin controls work...
  141. switch(wParam)
  142. {
  143. case IDC_MASS_SPIN:
  144. case IDC_GRAVITY_SPIN:
  145. case IDC_ELASTICITY_SPIN:
  146. case IDC_POSITIONX_SPIN:
  147. case IDC_POSITIONY_SPIN:
  148. case IDC_POSITIONZ_SPIN:
  149. case IDC_STIFFNESS_SPIN:
  150. case IDC_DAMPING_SPIN:
  151. case IDC_LENGTH_SPIN:
  152. LPNMUPDOWN lpnmud = (LPNMUPDOWN) lParam;
  153. if (lpnmud->hdr.code == UDN_DELTAPOS) {
  154. HWND hwnd = (HWND)SendDlgItemMessage(LOWORD(wParam),UDM_GETBUDDY);
  155. float curval = GetDlgItemFloat(GetWindowLong(hwnd,GWL_ID));
  156. curval += (float)lpnmud->iDelta / 100.0f;
  157. SetDlgItemFloat(GetWindowLong(hwnd,GWL_ID), curval);
  158. }
  159. break;
  160. }
  161. return CDialog::OnNotify(wParam, lParam, pResult);
  162. }