//ROMTEAM WorldEditor //////////////////////////////////////////////////////////////////////////////////////// // File : ITcon3D.cpp: implementation of the ITcon3D class. // Author : Ionut Grozea // Date : 97.11 // Description : //////////////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ACP_Base.h" #include "ITF.h" #include "incGAM.h" #include "GLI.h" #include "DPT.h" #undef CPA_WANTS_IMPORT #undef CPA_EXPORT #define CPA_WANTS_EXPORT #include "OGD.h" #undef CPA_WANTS_EXPORT #define CPA_WANTS_IMPORT #include "3dinterf.hpp" #include "DlgITCone.h" ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::ITCon3D // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : constructor to create a new object // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// ITCon3D::ITCon3D (CPA_EditorBase *_p_oEditor,float radius /* = 1.f */ , float height /* = 1.f */ , const CString _csName , tdeSaveStatus _eStatus ) :ParamSurface3D(TRUE, _p_oEditor, 1, 1, _csName , _eStatus) { CommonITCon3D (radius , height, 10, 10); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::ITCon3D // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : constructor to create a new object // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// ITCon3D::ITCon3D (CPA_EditorBase *_p_oEditor,float radius /* = 1.f */ , float height /* = 1.f */, int ns, int nt, const CString _csName , tdeSaveStatus _eStatus ) :ParamSurface3D(TRUE, _p_oEditor, 1, 1, _csName , _eStatus) { CommonITCon3D (radius , height, ns, nt); } #define PI 3.14159265359f ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::x // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : set x coordonates of ITBox3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// float ITCon3D::x(float s, float t) { float result; float s0 = (1-s)*m_fHeight; float t0 = 2*PI-t*2*PI; if (s0!=m_fHeight) { if (s0 == resultold || m_Flag2<2) { resultold = s0; result = m_fRadius*(float) cos(t0); m_Flag2++; } else { result =(s0/m_fHeight)*m_fRadius*(float) cos(t0); } } else { result = 0; } return result; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::y // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : set y coordonates of ITBox3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// float ITCon3D::y(float s, float t) { float result; float s0 = (1-s)*m_fHeight; float t0 = 2*PI-t*2*PI; if (s0!=m_fHeight) { if (s0 == resultold || m_Flag3<2) { resultold = s0; result = m_fRadius*(float)sin(t0); m_Flag3++; } else { result = (s0 / m_fHeight)*m_fRadius*(float)sin(t0); } } else { result = 0; } return result; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::z // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : set z coordonates of ITBox3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// float ITCon3D::z(float s, float t) { float result; float s0 = (1-s)*m_fHeight; float t0 = 2*PI-t*2*PI; if (s0!=m_fHeight) { if (s0 == resultold || m_Flag1<2) { resultold = s0; result = 0; m_Flag1++; } else { result = m_fHeight - s0; } } else { result = 0; } return result; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::CommonITCon3D // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : construct of ITcon3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void ITCon3D::CommonITCon3D( float radius , float height, int ns, int nt) { m_fHeight = height; m_fRadius = radius; m_Ns = ns; m_Nt = nt; GEO_tdstGeometricObject *x = GetStruct(); m_Flag1=0; m_Flag2=0; m_Flag3=0; resultold=-1; m_hElement = NewElement(0, m_Ns, m_Nt); } ITCon3D::~ITCon3D() { } ACP_tdxHandleOfElement ITCon3D::GetHElement() { return m_hElement; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::SetRadius // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : SetRadius of ITcon3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL ITCon3D::SetRadius(GLI_tdxValue Radius) { i=0; if(Radius<0.1) Radius = (float)0.1; m_fRadius = Radius; m_Flag1=0; m_Flag2=0; m_Flag3=0; resultold=-1; NewElement(m_hElement, m_Ns, m_Nt); return TRUE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::SetHeight // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : SetHeight of ITcon3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL ITCon3D::SetHeight(GLI_tdxValue Height) { i=0; if(Height<0.1) Height = (float)0.1; m_fHeight = Height; m_Flag1=0; m_Flag2=0; m_Flag3=0; resultold=-1; NewElement(m_hElement, m_Ns, m_Nt); return TRUE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::GetRadius() // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : return radius of ITCon3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// GLI_tdxValue ITCon3D::GetRadius() { return m_fRadius; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::GetHeight() // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : return height of ITCon3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// GLI_tdxValue ITCon3D::GetHeight() { return m_fHeight; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::SetSamplingRate // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : set sampling rate of ITCon3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void ITCon3D::SetSamplingRate(int Ns, int Nt) { i=0; if(Ns < 4) Ns = 4; if(Nt < 4) Nt = 4; if(Ns > 20) Ns = 20; if(Nt > 20) Nt = 20; m_Nt = Nt; m_Ns = Ns; m_Flag1=0; m_Flag2=0; m_Flag3=0; resultold=-1; NewElement(m_hElement, m_Ns, m_Nt); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : ITCon3D::GetSamplingRate // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : return sampling rate of ITCon3D // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void ITCon3D::GetSamplingRate(int &Ns, int &Nt) { Nt = m_Nt; Ns = m_Ns; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :ITCon3D::_OnLButtonDblClk // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : launch the modal dialog // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL ITCon3D::_OnLButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo) { HINSTANCE hOldInst = AfxGetResourceHandle(); AfxSetResourceHandle ( ((CPA_DLLBase*)(GetEditor()))->GetDLLIdentity()->hModule ); DlgITCone dlg(this ,m_fRadius , m_fHeight ,m_Ns , m_Nt ); BOOL retval = dlg.DoModal() == IDOK; AfxSetResourceHandle(hOldInst); return retval; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :ITCon3D::_OnMouseMove // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : adjust the box size according to the mouse input // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL ITCon3D::_OnMouseMove(UINT nFlags, tdstMousePos * p_stPos, MTH3D_tdstVector * pDeplacement) { if (Shape3D::_OnMouseMove (nFlags, p_stPos, pDeplacement)) { // we make the movement MTH3D_M_vAddVector (& m_stGlobalSelectedPoint , & m_stGlobalSelectedPoint , pDeplacement); MTH3D_tdstVector RadiusVertex; MTH3D_M_vSubVector (& RadiusVertex , & m_stGlobalSelectedPoint , & m_stCenterInMousePlane); GLI_tdxValue NewRadius = MTH3D_M_xNormVector (& RadiusVertex); if (!m_Flag) { SetRadius (m_fRadiusold*NewRadius/m_fGlobal); SetHeight (m_fHeightold*NewRadius/m_fGlobal); } else { m_fGlobal = NewRadius; m_Flag = FALSE; } return TRUE; } else return FALSE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :ITCon3D::_OnLButtonDown // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Init the resizing // Author : Ionut Grozea ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL ITCon3D::_OnLButtonDown(UINT nFlags, tdstMousePos * p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo * p_stObject) { if (Shape3D::_OnLButtonDown(nFlags, p_stPos, xIndex, p_stObject)) { // resizing is allowed MTH3D_tdstVector SphereCenter; // Compute coordinates in the global repere ConvertPointLocalToGlobal (& SphereCenter, HIE_fn_hGetSuperObjectGlobalMatrix (m_pSuperObject->GetStruct ()) , & GetCenter ()); // Get the matrix of the camera GLI_tdxHandleToCamera hHandleToCamera = m_pGeometry3DDLL->GetInterface () -> GetMultiDevice () -> GetFocusDevice () -> GetCamera (); POS_tdstCompletePosition CameraMatrix , InvMatrix; GLI_xGetCameraMatrix (hHandleToCamera , & CameraMatrix); POS_fn_vInvertIsoMatrix(& InvMatrix , & CameraMatrix); // Get the coordinates of the Z axe MTH3D_tdstVector ZAxe , DummyVector; POS_fn_vGetRotationMatrix(& InvMatrix , & DummyVector , & DummyVector , & ZAxe); // Compute the sphere center, projected into the plane where the mouse moves into MTH3D_M_vSubVector (& SphereCenter , & SphereCenter , & m_stGlobalSelectedPoint); GLI_tdxValue DotProduct = MTH3D_M_xDotProductVector (& ZAxe , & SphereCenter); MTH3D_M_vMulScalarVector (& ZAxe , DotProduct , & ZAxe); MTH3D_M_vSubVector (& SphereCenter , & SphereCenter , & ZAxe); MTH3D_M_vAddVector (& m_stCenterInMousePlane , & SphereCenter , & m_stGlobalSelectedPoint); m_Flag = TRUE; m_fRadiusold = m_fRadius; m_fHeightold = m_fHeight; return TRUE; } else return FALSE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : mfn_vLoad // Date : 98-01 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : // Author : Cristian Stegaru CPA2 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void ITCon3D::mfn_vLoad (CString csEPOFile, CString csEPOName) { Shape3D::mfn_vLoad (csEPOFile, csEPOName); char szRadius [NB_LENGTH], szHeight [NB_LENGTH], szNs [NB_LENGTH], szNt [NB_LENGTH]; BOOL bReadOK = GetPrivateProfileString (csEPOName, "RADIUS", NULL, szRadius, NB_LENGTH, csEPOFile); float fRadius = (float)atof (szRadius); bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "HEIGHT", NULL, szHeight, NB_LENGTH, csEPOFile); float fHeight = (float)atof (szHeight); bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "NS", NULL, szNs, NB_LENGTH, csEPOFile); int iNs = atoi (szNs); bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "NT", NULL, szNt, NB_LENGTH, csEPOFile); int iNt = atoi (szNt); ASSERT (bReadOK); SetRadius(fRadius); SetHeight(fHeight); SetSamplingRate(iNs, iNt); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : mfn_vSave // Date : 98-01 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : // Author : Cristian Stegaru CPA2 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void ITCon3D::mfn_vSave (CString csEPOFile, CString csEPOName, int iIdx) { Shape3D::mfn_vSave (csEPOFile, csEPOName, iIdx); char szRadius [NB_LENGTH], szHeight [NB_LENGTH], szNs [NB_LENGTH], szNt [NB_LENGTH]; _gcvt (m_fRadius, 4, szRadius); BOOL bWriteOK = WritePrivateProfileString (csEPOName, "RADIUS", szRadius, csEPOFile); _gcvt (m_fHeight, 4, szHeight); bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "HEIGHT", szHeight, csEPOFile); itoa (m_Ns, szNs, 10); bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "NS", szNs, csEPOFile); itoa (m_Nt, szNt, 10); bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "NT", szNt, csEPOFile); ASSERT (bWriteOK); } //------------------------------------------ ITConUndo --------------------------------------------- #define M_RedrawWorld() (((DEV_MultiDevice*)g_oFrameGest.ma_p_oWinArray[2][2]->GetActiveView())->DrawObject()) ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :ITConUndo::ITConUndo // Date : 98.01 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Init the undo data // Author : N Suparatu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// ITConUndo::ITConUndo(ITCon3D *con) : CPA_Modif(0, "Set Cone Parameters", FALSE) { m_pCon = con; con->GetSamplingRate(m_Ns, m_Nt); m_fRadius = con->GetRadius(); m_fHeight = con->GetHeight(); m_bFirst = TRUE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :ITConUndo::Undo // Date : 98.01 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Undo con parameters // Author : N Suparatu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL ITConUndo::Undo() { m_bFirst = FALSE; int s, t; m_pCon->GetSamplingRate(s, t); float r = m_pCon->GetRadius(); float h = m_pCon->GetHeight(); m_pCon->SetRadius(m_fRadius); m_pCon->SetHeight(m_fHeight); m_pCon->SetSamplingRate(m_Ns, m_Nt); m_fRadius = r; m_fHeight = h; m_Ns = s; m_Nt = t; m_pCon->fn_vNotifySaveObject(); M_RedrawWorld(); return TRUE; }