home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / DimensionsDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  5.5 KB  |  249 lines

  1. // DimensionsDlg.cpp : implementation file
  2. //
  3.  
  4. #include "precompile.h"
  5. #include "modeledit.h"
  6. #include "dimensionsdlg.h"
  7. #include "model_ops.h"
  8. #include "gl_modelrender.h"
  9. #include "modeleditdlg.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CDimensionsDlg dialog
  19.  
  20.  
  21. CDimensionsDlg::CDimensionsDlg(CWnd* pParent /*=NULL*/)
  22.     : CDialog(CDimensionsDlg::IDD, pParent),
  23.     m_pModel(NULL)
  24. {
  25.     //{{AFX_DATA_INIT(CDimensionsDlg)
  26.     //}}AFX_DATA_INIT
  27. }
  28.  
  29.  
  30. void CDimensionsDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32.     CDialog::DoDataExchange(pDX);
  33.     //{{AFX_DATA_MAP(CDimensionsDlg)
  34.     DDX_Control(pDX, IDC_ZDIM, m_ZDim);
  35.     DDX_Control(pDX, IDC_YDIM, m_YDim);
  36.     DDX_Control(pDX, IDC_XDIM, m_XDim);
  37.     //}}AFX_DATA_MAP
  38. }
  39.  
  40.  
  41. BEGIN_MESSAGE_MAP(CDimensionsDlg, CDialog)
  42.     //{{AFX_MSG_MAP(CDimensionsDlg)
  43.     ON_BN_CLICKED(ID_APPLY, OnApply)
  44.     ON_WM_SHOWWINDOW()
  45.     ON_BN_CLICKED(ID_DONE, OnDone)
  46.     ON_BN_CLICKED(ID_USEANIMDIMS, OnUseCurAnim)
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CDimensionsDlg message handlers
  52.  
  53. BOOL CDimensionsDlg::OnInitDialog() 
  54. {
  55.     CDialog::OnInitDialog();
  56.  
  57.     UpdateControls();
  58.     
  59.     return TRUE;  // return TRUE unless you set the focus to a control
  60.                   // EXCEPTION: OCX Property Pages should return FALSE
  61. }
  62.  
  63.  
  64. void CDimensionsDlg::PostNcDestroy() 
  65. {
  66.     CDialog::PostNcDestroy();
  67.  
  68.     //delete this modeless dialog to prevent a memory lead
  69.     delete this;
  70.  
  71. }
  72.  
  73. void CDimensionsDlg::OnApply() 
  74. {
  75.     SetDimensions();
  76. }
  77.  
  78. void CDimensionsDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
  79. {
  80.     CDialog::OnShowWindow(bShow, nStatus);
  81.     
  82.     //need to reset these when the window is hid or shown so that
  83.     //when the user hits enter it won't hide the dialog -JohnO
  84.     GotoDlgCtrl( GetDlgItem(ID_APPLY) );
  85.     SetDefID(ID_APPLY);
  86.  
  87.     UpdateControls();
  88. }
  89.  
  90. void CDimensionsDlg::OnDone() 
  91. {
  92.     SetDimensions();
  93.     ShowWindow(SW_HIDE);    
  94. }
  95.  
  96. void CDimensionsDlg::UpdateControls( void )
  97. {
  98.     CString str;
  99.     AnimInfo *pAnim;
  100.  
  101.     ASSERT(m_pModel);
  102.     if( !m_pModel )
  103.         return;
  104.  
  105.     if(m_Anims[0] < (int)m_pModel->m_Anims.GetSize())
  106.     {
  107.         pAnim = &m_pModel->m_Anims[m_Anims[0]];
  108.  
  109.         str.Format( "%f", pAnim->m_vDims.x );
  110.         m_XDim.SetWindowText( str );
  111.         str.Format( "%f", pAnim->m_vDims.y );
  112.         m_YDim.SetWindowText( str );
  113.         str.Format( "%f", pAnim->m_vDims.z );
  114.         m_ZDim.SetWindowText( str );
  115.     }
  116. }
  117.  
  118. void CDimensionsDlg::SetDimensions( void )
  119. {
  120.     CString str;
  121.     int i, iAnim;
  122.     AnimInfo *pAnim;
  123.  
  124.     ASSERT( m_pModel );
  125.     if( !m_pModel )
  126.         return;
  127.  
  128.     for(i=0; i < m_nAnims; i++)
  129.     {
  130.         iAnim = m_Anims[i];
  131.         
  132.         if(iAnim >= (int)m_pModel->m_Anims.GetSize())
  133.             continue;
  134.  
  135.         pAnim = &m_pModel->m_Anims[iAnim];
  136.  
  137.         m_XDim.GetWindowText( str );
  138.         pAnim->m_vDims.x = ( float )atof(( LPCTSTR )str );
  139.         m_YDim.GetWindowText( str );
  140.         pAnim->m_vDims.y = ( float )atof(( LPCTSTR )str );
  141.         m_ZDim.GetWindowText( str );
  142.         pAnim->m_vDims.z = ( float )atof(( LPCTSTR )str );
  143.     }
  144. }
  145.  
  146. //given an animation and a keyframe, this will find the dims that encompass the
  147. //model
  148. bool CDimensionsDlg::FindAnimDims(Model* pModel, uint32 nAnim, uint32 nKeyFrame, LTVector& vDims)
  149. {
  150.     //clear out the dims to start out with in case we fail
  151.     vDims.Init();
  152.  
  153.     AnimTracker tracker, *pTracker;
  154.     tracker.m_TimeRef.Init(pModel, nAnim, nKeyFrame, nAnim, nKeyFrame, 0.0f);
  155.  
  156.     AnimInfo *pAnim = &pModel->m_Anims[nAnim];
  157.  
  158.     pTracker = &tracker;//pAnim->m_pAnim;
  159.  
  160.     static CMoArray<TVert> tVerts;
  161.  
  162.     // Use the model code to setup the vertices.
  163.  
  164.     int nTrackers = 1;
  165.     nTrackers = DMIN(nTrackers, MAX_GVP_ANIMS);
  166.  
  167.     GVPStruct gvp;
  168.     
  169.     gvp.m_nAnims = 0;
  170.     for(int i = 0; i < nTrackers; i++)
  171.     {
  172.         gvp.m_Anims[i] = pTracker[i].m_TimeRef;
  173.         gvp.m_nAnims++;
  174.     }
  175.  
  176.     LTMatrix m;
  177.     m.Identity();
  178.  
  179.     int nWantedVerts = pModel->GetTotalNumVerts() * 2;
  180.     if(tVerts.GetSize() < nWantedVerts)
  181.     {
  182.         if(!tVerts.SetSize(nWantedVerts))
  183.             return false;
  184.     }
  185.  
  186.     gvp.m_VertexStride = sizeof(TVert);
  187.     gvp.m_Vertices = tVerts.GetArray();
  188.     gvp.m_BaseTransform = m;
  189.     gvp.m_CurrentLODDist = 0;
  190.     
  191.     if (AlternateGetVertexPositions(pModel, &gvp, true, false, false, false))
  192.     {
  193.         LTVector vMax(0, 0, 0);
  194.  
  195.         for (i = 0; i < pModel->GetTotalNumVerts(); i ++)
  196.         {
  197.             TVert v = tVerts[i];
  198.  
  199.             if (fabs(v.m_vPos.x) > vMax.x) vMax.x = (float)fabs(v.m_vPos.x);
  200.             if (fabs(v.m_vPos.y) > vMax.y) vMax.y = (float)fabs(v.m_vPos.y);
  201.             if (fabs(v.m_vPos.z) > vMax.z) vMax.z = (float)fabs(v.m_vPos.z);
  202.         }
  203.  
  204.         // Setup the new dims....
  205.  
  206.         //round max up to the .1 decimal place
  207.         vMax.x = (float)(ceil(vMax.x * 10.0) / 10.0);
  208.         vMax.y = (float)(ceil(vMax.y * 10.0) / 10.0);
  209.         vMax.z = (float)(ceil(vMax.z * 10.0) / 10.0);
  210.  
  211.         vDims = vMax;
  212.  
  213.         return true;
  214.     }
  215.  
  216.     //failure
  217.     return false;
  218. }
  219.  
  220. void CDimensionsDlg::OnUseCurAnim()
  221. {
  222.     
  223.     DWORD dwAnimIndex;
  224.     DWORD dwKeyframeIndex;
  225.  
  226.     CModelEditDlg *pDlg;
  227.     pDlg = (CModelEditDlg *)AfxGetApp()->GetMainWnd();
  228.  
  229.     if (!pDlg->GetEditAnimInfo(&dwAnimIndex, &dwKeyframeIndex, false)) return;
  230.  
  231.     LTVector vMax;
  232.     if(FindAnimDims(m_pModel, dwAnimIndex, dwKeyframeIndex, vMax))
  233.     {
  234.         AnimInfo *pAnim = &m_pModel->m_Anims[dwAnimIndex];
  235.         pAnim->m_vDims = vMax;
  236.  
  237.         CString sTxt;
  238.  
  239.         sTxt.Format("%f", pAnim->m_vDims.x);
  240.         m_XDim.SetWindowText(sTxt);
  241.  
  242.         sTxt.Format("%f", pAnim->m_vDims.y);
  243.         m_YDim.SetWindowText(sTxt);
  244.  
  245.         sTxt.Format("%f", pAnim->m_vDims.z);
  246.         m_ZDim.SetWindowText(sTxt);
  247.     } 
  248. }
  249.