reman3/Rayman_X/cpa/tempgrp/OGD/src/Shape3D.cpp

373 lines
16 KiB
C++

//ROMTEAM WorldEditor
////////////////////////////////////////////////////////////////////////////////////////
// File : Shape3D.cpp: implementation of the Shape3D 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"
BOOL Shape3D::m_bSizeKeyPressed = FALSE;
Geometry3D_Interface *Shape3D::m_pGeometry3DDLL = NULL;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : Shape3D::Shape3D
// 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 :
//////////////////////////////////////////////////////////////////////////////////////////////////////
Shape3D::Shape3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, ACP_tdxIndex xNbPoints, ACP_tdxIndex xNbElements, const CString _csName, tdeSaveStatus _eStatus)
: Geometry3D (_p_oEditor, xNbPoints, xNbElements, _csName , _eStatus)
{
m_bModifiable = bModifiable;
CommonShape3D ();
}
Shape3D::Shape3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, ACP_tdxIndex xNbPoints, ACP_tdxIndex xNbElements, CPA_BaseObject *_p_oOwnerFile, const CString _csName, char *_p_cRefPath, tdeSaveStatus _eStatus)
: Geometry3D (_p_oEditor, xNbPoints, xNbElements, _p_oOwnerFile, _csName, _p_cRefPath, _eStatus)
{
m_bModifiable = bModifiable;
CommonShape3D ();
}
Shape3D::Shape3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, CPA_BaseObject *_p_oOwnerFile, ACP_tdxHandleOfObject _hObject, const CString _csName, char *_p_cRefPath, tdeSaveStatus _eStatus)
: Geometry3D (_p_oEditor, _p_oOwnerFile, _hObject, _csName, _p_cRefPath, _eStatus)
{
m_bModifiable = bModifiable;
CommonShape3D ();
}
Shape3D::~Shape3D()
{
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - _OnKeyDown
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : check for size key pressed
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL Shape3D::_OnKeyDown(UINT nChar, UINT nRepCnt /* = 0 */, UINT nFlags /* = 0 */)
{
ASSERT (m_pGeometry3DDLL);
if(m_pGeometry3DDLL->GetKeyActionConfiguration ()->mfn_uwKeyToAction(nChar) == KA_3DG_SIZE)
m_bSizeKeyPressed = TRUE;
return FALSE;
}
//ionut
BOOL Shape3D::_OnLButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)
{
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - _OnKeyUp
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : check for size key pressed
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL Shape3D::_OnKeyUp(UINT nChar, UINT nRepCnt /* = 0 */, UINT nFlags /* = 0 */)
{
ASSERT (m_pGeometry3DDLL);
if(m_pGeometry3DDLL->GetKeyActionConfiguration ()->mfn_uwKeyToAction(nChar) == KA_3DG_SIZE)
m_bSizeKeyPressed = FALSE;
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - _OnMouseMove
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : are we ready ?!
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL Shape3D::_OnMouseMove(UINT nFlags, tdstMousePos * p_stPos, MTH3D_tdstVector * pDeplacement)
{
if (m_bModifiable && m_bSizeKeyPressed & m_bActiveMode)
return TRUE;
else
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - _OnLButtonDown
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Init mouse move structures
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL Shape3D::_OnLButtonDown(UINT nFlags, tdstMousePos * p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo * p_stObject)
{
if (m_bModifiable && m_bSizeKeyPressed)
{
m_bActiveMode = TRUE;
m_stGlobalSelectedPoint = p_stObject->stPickedObject.aDEF_stDataOfElement->stHit;
return TRUE;
}
else
return FALSE;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - _OnLButtonUp
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Default: we do not use the message
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL Shape3D::_OnLButtonUp(UINT nFlags, tdstMousePos * p_stPos)
{
m_bActiveMode = FALSE;
return FALSE;
}
// ----------------------------------------------------------------------------
// Description : common implementation for the constructors
// ----------------------------------------------------------------------------
void Shape3D::CommonShape3D()
{
m_bSizeKeyPressed = FALSE;
m_bActiveMode = FALSE;
m_hElement = 0;
m_pSuperObject = NULL;
//ROMTEAM WorldEditor (Cristian Stegaru 12/97)
SetCallBackSave (Geometry3D::CallBackSaveGeometricObject);
SetSectionData (this);
//ENDROMTEAM WorldEditor (Cristian Stegaru)
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - ConvertPointGlobalToLocal
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Temporary function to convert a point from the global repere to a local repere
// pSource and pDest must be different
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Shape3D::ConvertPointGlobalToLocal (MTH3D_tdstVector * pDest , POS_tdstCompletePosition * pAbsoluteMatrix , MTH3D_tdstVector * pSource)
{
// Compute the invert matrix
POS_tdstCompletePosition InvMatrix;
POS_fn_vInvertIsoMatrix(& InvMatrix , pAbsoluteMatrix);
POS_fn_vMulMatrixVertex(pDest , & InvMatrix , pSource);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - ConvertPointLocalToGlobal
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Temporary function to convert a point from a local repere to the global repere
// pSource and pDest must be different
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Shape3D::ConvertPointLocalToGlobal (MTH3D_tdstVector * pDest , POS_tdstCompletePosition * pAbsoluteMatrix , MTH3D_tdstVector * pSource)
{
POS_fn_vMulMatrixVertex(pDest , pAbsoluteMatrix , pSource);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - ConvertVectorGlobalToLocal
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Temporary function to convert a vector from the global repere to a local repere
// pSource and pDest must be different
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Shape3D::ConvertVectorGlobalToLocal (MTH3D_tdstVector * pDest , POS_tdstCompletePosition * pAbsoluteMatrix , MTH3D_tdstVector * pSource)
{
// Compute the invert matrix
POS_tdstCompletePosition InvMatrix;
POS_fn_vInvertIsoMatrix(& InvMatrix , pAbsoluteMatrix);
// Put the translation to 0
MTH3D_tdstVector NullVector;
MTH3D_M_vNullVector (& NullVector);
POS_fn_vSetTranslationVector(& InvMatrix , & NullVector);
POS_fn_vMulMatrixVertex(pDest , & InvMatrix , pSource);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method :Shape3D - ConvertVectorLocalToGlobal
// Date : 97.11
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description : Temporary function to convert a vector from a local repere to the global repere
// pSource and pDest must be different
// Author : Cristi Petrescu
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Shape3D::ConvertVectorLocalToGlobal (MTH3D_tdstVector * pDest , POS_tdstCompletePosition * pAbsoluteMatrix , MTH3D_tdstVector * pSource)
{
// Keep a copy of the translation vector
MTH3D_tdstVector BackupTranslation;
POS_fn_vGetTranslationVector (pAbsoluteMatrix , & BackupTranslation);
// Put the translation to 0
MTH3D_tdstVector NullVector;
MTH3D_M_vNullVector (& NullVector);
POS_fn_vSetTranslationVector(pAbsoluteMatrix , & NullVector);
POS_fn_vMulMatrixVertex(pDest , pAbsoluteMatrix , pSource);
POS_fn_vSetTranslationVector(pAbsoluteMatrix , & BackupTranslation);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : mfn_vLoad
// Date : 98-01
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description :
// Author : Cristian Stegaru - CPA2
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Shape3D::mfn_vLoad (CString csEPOFile, CString csEPOName)
{
char *szName = new char[STR_LENGTH], *szReferencedSectionName = new char[STR_LENGTH], *szDataPath = new char[STR_LENGTH],
*szElementReferencedSectionName = new char[STR_LENGTH], *szElementDataPath = new char[STR_LENGTH];
BOOL bReadOK = GetPrivateProfileString (csEPOName, "REFERENCED_SECTION_NAME", NULL, szReferencedSectionName, STR_LENGTH, csEPOFile);
bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "DATA_PATH", NULL, szDataPath, STR_LENGTH, csEPOFile);
bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "ELEMENT_REFERENCED_SECTION_NAME", NULL, szElementReferencedSectionName, STR_LENGTH, csEPOFile);
bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "ELEMENT_DATA_PATH", NULL, szElementDataPath, STR_LENGTH, csEPOFile);
ASSERT (bReadOK);
SetReferencedSectionName (szReferencedSectionName);
fn_vUpdateSectionName ();
SetDataPath (szDataPath);
mfn_vInitElement (szElementReferencedSectionName, szElementDataPath, TRUE);
fn_vNotifySave ();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : mfn_vSave
// Date : 98-01
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description :
// Author : Cristian Stegaru - CPA2
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Shape3D::mfn_vSave (CString csEPOFile, CString csEPOName, int iIdx)
{
BOOL bWriteOK = WritePrivateProfileString (csEPOName, "NAME", GetName (), csEPOFile);
char szIdx [NB_LENGTH];
itoa (iIdx, szIdx, 10);
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "IDX", szIdx, csEPOFile);
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "REFERENCED_SECTION_NAME", GetReferencedSectionName (), csEPOFile);
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "DATA_PATH", GetDataPath (), csEPOFile);
SectionElement *pSectionElement = m_oListOfElementSections.GetHead ();
ASSERT (pSectionElement);
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "ELEMENT_REFERENCED_SECTION_NAME", pSectionElement->GetReferencedSectionName (), csEPOFile);
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "ELEMENT_DATA_PATH", pSectionElement->GetDataPath (), csEPOFile);
ASSERT (bWriteOK);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Method : EndCreate()
// Date : 98-01-20
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Description :
// Author : N Suparatu - CPA2
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Modification :
// Date :
// By :
//////////////////////////////////////////////////////////////////////////////////////////////////////
void Shape3D::EndCreate()
{
if(GetStruct()->d_stListOfPointsNormals) GEO_M_CPAFree(GetStruct()->d_stListOfPointsNormals);
if(GetStruct()->d_hListOfPointsMaterial) GEO_M_CPAFree(GetStruct()->d_hListOfPointsMaterial);
if(GetStruct()->d_stListOfEdges) GEO_M_CPAFree(GetStruct()->d_stListOfEdges);
GetStruct()->d_hListOfPointsMaterial = NULL;
GetStruct()->d_stListOfEdges = NULL;
GetStruct()->d_stListOfPointsNormals = NULL;
GEO_xCreateObjectPointNormals (GetStruct());
GEO_vCreateObjectListOfPointsMaterial(GetStruct());
GEO_xCreateObjectListOfEdges(GetStruct());
GEO_xComputeObjectNormals2(GetStruct());
GEO_vComputeObjectListOfPointsMaterial(GetStruct());
GEO_xComputeObjectListOfEdges(GetStruct());
}