//ROMTEAM WorldEditor //////////////////////////////////////////////////////////////////////////////////////// // File : Cone3D.cpp: implementation of the Cone3D class. // Author : Cristi Petrescu // 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 #ifndef CPA_WANTS_IMPORT #define CPA_WANTS_IMPORT #endif #include "3dinterf.hpp" #include "DlgCon3D.hpp" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method : Cone3D::Cone3D // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : constructors to create a new object // make one for each Geometry3D one. No general constructor :-( // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// Cone3D::Cone3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, /*ACP_tdxIndex xNbPoints, ACP_tdxIndex xNbElements,*/ const CString _csName , tdeSaveStatus _eStatus ) : Shape3D (bModifiable, _p_oEditor, 2, 1, _csName , _eStatus) { CommonCone3D (); } Cone3D::Cone3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, /*ACP_tdxIndex xNbPoints, ACP_tdxIndex xNbElements,*/ CPA_BaseObject *_p_oOwnerFile, const CString _csName /*= ""*/, char *_p_cRefPath /*= NULL*/, tdeSaveStatus _eStatus /*= E_ss_Responsible*/) : Shape3D (bModifiable, _p_oEditor, 2, 1, _p_oOwnerFile, _csName, _p_cRefPath, _eStatus) { CommonCone3D (); } /****????*****///rezolvat ?? ionut Cone3D::Cone3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, CPA_BaseObject *_p_oOwnerFile, ACP_tdxHandleOfObject _hObject, const CString _csName /*= ""*/, char *_p_cRefPath /*= NULL*/, tdeSaveStatus _eStatus /*= E_ss_Modify*/) : Shape3D (bModifiable, _p_oEditor, _p_oOwnerFile, _hObject, _csName, _p_cRefPath, _eStatus) { // this seems to be used at load time. // so do not alter the data! // CommonCone3D (); } // ---------------------------------------------------------------------------- // Description : common implementation for the constructors // ---------------------------------------------------------------------------- void Cone3D::CommonCone3D( ) { // initialise with dummy data MTH3D_tdstVector stPoints [2] = {{ 0 , 0 , 0 } , { 0 , 0 , 1 }}; fn_vSetListOfPoints (2 , stPoints); m_hElement = fn_hCreateElementCone (1); fn_eSetCone (m_hElement, 0 , 0 , 1 , (float) 0.1); fn_vEndCreation (); } Cone3D::~Cone3D() { } /* ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method Cone3D - _OnKeyDown // Date 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Default: we do not use the message // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL Cone3D::_OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { return FALSE; } //----------------------------------------------------------------------------- // Class Cone3D - _OnKeyUp // Default: we do not use the message //----------------------------------------------------------------------------- BOOL Cone3D::_OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { return FALSE; } */ ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D - _OnMouseMove // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : adjust the box size according to the mouse input // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL Cone3D::_OnMouseMove(UINT nFlags, tdstMousePos * p_stPos, MTH3D_tdstVector * pDeplacement) { if (Shape3D::_OnMouseMove (nFlags, p_stPos, pDeplacement)) { MTH3D_tdstVector LocalDeplacement; ConvertVectorGlobalToLocal (& LocalDeplacement , HIE_fn_hGetSuperObjectGlobalMatrix (m_pSuperObject->GetStruct ()) , pDeplacement); if (m_bChangeTopPointOfCone) // We change the top point { MTH3D_tdstVector TopPoint = GetTopPoint (); MTH3D_M_vAddVector (& TopPoint , & TopPoint , & LocalDeplacement); SetTopPoint (& TopPoint); } else // We change the radius and the base point { MTH3D_tdstVector BasePoint = GetBasePoint (); MTH3D_tdstVector TopPoint = GetTopPoint (); // We splt the deplacement into radius change and base point change MTH3D_tdstVector BaseTopVector; MTH3D_M_vSubVector (& BaseTopVector , & TopPoint , & BasePoint); MTH_tdxReal DotProduct = MTH3D_M_xDotProductVector (& BaseTopVector , & LocalDeplacement); MTH3D_tdstVector ProjectedVector; // Projected into the axe MTH3D_M_vMulScalarVector (& ProjectedVector , DotProduct , & BaseTopVector); MTH3D_M_vDivScalarVector (& ProjectedVector , & ProjectedVector , MTH3D_M_xSqrVector (& BaseTopVector)); // We change the base point MTH3D_M_vAddVector (& BasePoint , & BasePoint , & ProjectedVector); SetBasePoint (& BasePoint); // We change the radius MTH3D_M_vAddVector (& m_stLocalSelectedPoint , & m_stLocalSelectedPoint , & LocalDeplacement); MTH3D_M_vSubVector (& m_stLocalSelectedPoint , & m_stLocalSelectedPoint , & ProjectedVector); MTH_tdxReal NewRadius = MTH3D_M_xVectorGap (& m_stLocalSelectedPoint , & BasePoint); SetRadius (& NewRadius); } return TRUE; } else return FALSE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D - _OnLButtonDown // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Init the resizing // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL Cone3D::_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 ConvertPointGlobalToLocal (& m_stLocalSelectedPoint , HIE_fn_hGetSuperObjectGlobalMatrix (m_pSuperObject -> GetStruct ()) , & m_stGlobalSelectedPoint); // We see if we must change the top point or the radius of the cone MTH3D_tdstVector TopPoint = GetTopPoint (); MTH3D_tdstVector BasePoint = GetBasePoint (); MTH_tdxReal SquareDistanceToTopPoint = MTH3D_M_xVectorGapSqr (& m_stLocalSelectedPoint , & TopPoint); MTH_tdxReal SquareDistanceToBasePoint = MTH3D_M_xVectorGapSqr (& m_stLocalSelectedPoint , & BasePoint); if (SquareDistanceToTopPoint < SquareDistanceToBasePoint) { m_bChangeTopPointOfCone = TRUE; } else { m_bChangeTopPointOfCone = FALSE; // We project the picked point into the base plane MTH3D_tdstVector BaseTopVector; MTH3D_M_vSubVector (& BaseTopVector , & TopPoint , & BasePoint); MTH3D_tdstVector BasePointVector; MTH3D_M_vSubVector (& BasePointVector , & m_stLocalSelectedPoint , & BasePoint); MTH_tdxReal DotProduct = MTH3D_M_xDotProductVector (& BaseTopVector , & BasePointVector); MTH3D_tdstVector ProjectedVector; MTH3D_M_vMulScalarVector (& ProjectedVector , DotProduct , & BaseTopVector); MTH3D_M_vDivScalarVector (& ProjectedVector , & ProjectedVector , MTH3D_M_xSqrVector (& BaseTopVector)); MTH3D_M_vAddVector (& m_stLocalSelectedPoint , & m_stLocalSelectedPoint , & ProjectedVector); } return TRUE; } else return FALSE; } /* //----------------------------------------------------------------------------- // Class Cone3D - _OnLButtonUp // Default: we do not use the message //----------------------------------------------------------------------------- BOOL Cone3D::_OnLButtonUp(UINT nFlags, tdstMousePos * p_stPos) { return FALSE; } */ ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D - _OnLButtonDblClk // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : launch the modal dialog // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL Cone3D::_OnLButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo) { int iDlgResult; HINSTANCE hOldInst = AfxGetResourceHandle(); AfxSetResourceHandle ( ((CPA_DLLBase*)(GetEditor()))->GetDLLIdentity()->hModule ); CDlgCone3D dlgCone3D(this); iDlgResult = dlgCone3D.DoModal(); AfxSetResourceHandle(hOldInst); if (iDlgResult == IDOK) return TRUE; else return FALSE; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : GetBasePoint // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Return the 3D coordinates of the base point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// MTH3D_tdstVector Cone3D::GetBasePoint () { ACP_tdxIndex IndexOfTopPoint , IndexOfBasePoint; MTH3D_tdstVector BasePoint; fn_eGetConePoints (m_hElement , 0 , & IndexOfTopPoint , & IndexOfBasePoint); fn_vGetPoint (IndexOfBasePoint , & BasePoint); return BasePoint; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : GetTopPoint // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Return the 3D coordinates of the top point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// MTH3D_tdstVector Cone3D::GetTopPoint () { ACP_tdxIndex IndexOfTopPoint , IndexOfBasePoint; MTH3D_tdstVector TopPoint; fn_eGetConePoints (m_hElement , 0 , & IndexOfTopPoint , & IndexOfBasePoint); fn_vGetPoint (IndexOfTopPoint , & TopPoint); return TopPoint; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetBasePoint // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the 3D coordinates of the base point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetBasePoint (MTH3D_tdstVector * _pBasePoint) { ACP_tdxIndex IndexOfTopPoint , IndexOfBasePoint; fn_eGetConePoints (m_hElement , 0 , & IndexOfTopPoint , & IndexOfBasePoint); fn_vSetPoint (IndexOfBasePoint , _pBasePoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetTopPoint // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the 3D coordinates of the top point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetTopPoint (MTH3D_tdstVector * _pTopPoint) { ACP_tdxIndex IndexOfTopPoint , IndexOfBasePoint; fn_eGetConePoints (m_hElement , 0 , & IndexOfTopPoint , & IndexOfBasePoint); fn_vSetPoint (IndexOfTopPoint , _pTopPoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetBasePointX // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the X coordinate of the base point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetBasePointX (GLI_tdxValue _X) { MTH3D_tdstVector BasePoint = GetBasePoint (); MTH3D_M_vSetXofVector (& BasePoint , _X); SetBasePoint (& BasePoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetBasePointY // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the Y coordinate of the base point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetBasePointY (GLI_tdxValue _Y) { MTH3D_tdstVector BasePoint = GetBasePoint (); MTH3D_M_vSetYofVector (& BasePoint , _Y); SetBasePoint (& BasePoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetBasePointZ // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the Z coordinate of the base point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetBasePointZ (GLI_tdxValue _Z) { MTH3D_tdstVector BasePoint = GetBasePoint (); MTH3D_M_vSetZofVector (& BasePoint , _Z); SetBasePoint (& BasePoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetTopPointX // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the X coordinate of the top point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetTopPointX (GLI_tdxValue _X) { MTH3D_tdstVector TopPoint = GetTopPoint (); MTH3D_M_vSetXofVector (& TopPoint , _X); SetTopPoint (& TopPoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetTopPointY // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the Y coordinate of the top point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetTopPointY (GLI_tdxValue _Y) { MTH3D_tdstVector TopPoint = GetTopPoint (); MTH3D_M_vSetYofVector (& TopPoint , _Y); SetTopPoint (& TopPoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetTopPointZ // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the Z coordinate of the top point // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- void Cone3D::SetTopPointZ (GLI_tdxValue _Z) { MTH3D_tdstVector TopPoint = GetTopPoint (); MTH3D_M_vSetZofVector (& TopPoint , _Z); SetTopPoint (& TopPoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : GetCenter // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : return the 3D coordinates of the center of the cone (in fact, the middle of BasePoint and TopPoint) // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// MTH3D_tdstVector Cone3D::GetCenter () { MTH3D_tdstVector stBasePoint = GetBasePoint (); MTH3D_tdstVector stTopPoint = GetTopPoint (); MTH3D_tdstVector stCenter; MTH3D_M_vAddVector (& stCenter , & stBasePoint , & stTopPoint); MTH3D_M_vMulScalarVector (& stCenter , MTH_M_xFloatToReal ((float) 0.5) , & stCenter); return stCenter; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetCenter // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : set the 3D coordinates of the center of the cone (in fact, the middle of BasePoint and TopPoint) // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// void Cone3D::SetCenter (MTH3D_tdstVector * _pCenter) { MTH3D_tdstVector stOldCenter = GetCenter (); MTH3D_tdstVector stTranslation; MTH3D_M_vSubVector (& stTranslation , _pCenter , & stOldCenter); MTH3D_tdstVector stOldBasePoint = GetBasePoint (); MTH3D_tdstVector stNewBasePoint; MTH3D_M_vAddVector (& stNewBasePoint , & stOldBasePoint , & stTranslation); SetBasePoint (& stNewBasePoint); MTH3D_tdstVector stOldTopPoint = GetTopPoint (); MTH3D_tdstVector stNewTopPoint; MTH3D_M_vAddVector (& stNewTopPoint , & stOldTopPoint , & stTranslation); SetTopPoint ( & stNewTopPoint); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : GetRadius // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Return the radius of the cone // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// GLI_tdxValue Cone3D::GetRadius () { return fn_xGetConeBaseRadius (m_hElement , 0); } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetRadius // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the radius of the cone // If the value is not correct (negative), return FALSE and set the value to 0 // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL Cone3D::SetRadius (GLI_tdxValue * _pRadius) { BOOL Correct = * _pRadius >= 0; if (! Correct) _pRadius = 0; fn_eSetConeBaseRadius (m_hElement , 0 , * _pRadius); return Correct; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : GetAngle // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Return the angle of the cone // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// GLI_tdxValue Cone3D::GetAngle () { MTH3D_tdstVector BasePoint = GetBasePoint (); MTH3D_tdstVector TopPoint = GetTopPoint (); double Length = MTH3D_M_xVectorGap (& BasePoint , & TopPoint); return (GLI_tdxValue) atan2 ((double)GetRadius () , Length) * MTH_C_180ByPi; } ////////////////////////////////////////////////////////////////////////////////////////////////////// // Method :Cone3D : SetAngle // Date : 97.11 ////////////////////////////////////////////////////////////////////////////////////////////////////// // Description : Set the angle of the cone // If the value is not correct, return FALSE and set a correct value // Author : Cristi Petrescu ////////////////////////////////////////////////////////////////////////////////////////////////////// // Modification : // Date : // By : ////////////////////////////////////////////////////////////////////////////////////////////////////// BOOL Cone3D::SetAngle (GLI_tdxValue * _pAngle) { BOOL bCorrect; if (* _pAngle < 0.) { * _pAngle = 0.; bCorrect = FALSE; } else if (* _pAngle > 90.) { * _pAngle = 90.; bCorrect = FALSE; } else bCorrect = TRUE; MTH3D_tdstVector BasePoint = GetBasePoint (); MTH3D_tdstVector TopPoint = GetTopPoint (); float Length = MTH3D_M_xVectorGap (& BasePoint , & TopPoint); float Radius = (float) (Length * tan (* _pAngle * MTH_C_PiBy180)); SetRadius (& Radius); return bCorrect; }