414 lines
15 KiB
C++
414 lines
15 KiB
C++
//ROMTEAM WorldEditor
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// File : ITBox3D.cpp: implementation of the ITBox3D 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"
|
|
#include "3dinterf.hpp"
|
|
|
|
#undef CPA_WANTS_IMPORT
|
|
#undef CPA_EXPORT
|
|
#define CPA_WANTS_EXPORT
|
|
#include "OGD.h"
|
|
#undef CPA_WANTS_EXPORT
|
|
#define CPA_WANTS_IMPORT
|
|
|
|
|
|
#include "DlgITBox.h"
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITBox3D::ITBox3D
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : constructor to create a new object
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
ITBox3D::ITBox3D (CPA_EditorBase *_p_oEditor, float scale ,const CString _csName , tdeSaveStatus _eStatus )
|
|
: Shape3D (TRUE, _p_oEditor, 8, 1, _csName , _eStatus)
|
|
{
|
|
m_fX = scale;
|
|
m_fY = scale;
|
|
m_fZ = scale;
|
|
CommonITBox3D ();
|
|
}
|
|
|
|
|
|
ITBox3D::~ITBox3D()
|
|
{
|
|
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITBox3D::CreateITBox3D()
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : set vertices of ITBox3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void ITBox3D::CreateITBox3D()
|
|
{
|
|
MTH3D_tdstVector a8_stPoint [8];
|
|
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint, m_fX/2.f , -m_fY/2.f ,-m_fZ/2.f );
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint+1, m_fX/2.f , m_fY/2.f , -m_fZ/2.f );
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint+2, m_fX/2.f , m_fY/2.f , m_fZ/2.f );
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint+3, m_fX/2.f , -m_fY/2.f , m_fZ/2.f );
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint+4, -m_fX/2.f , -m_fY/2.f , -m_fZ/2.f );
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint+5, -m_fX/2.f , m_fY/2.f , -m_fZ/2.f );
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint+6, -m_fX/2.f , m_fY/2.f , m_fZ/2.f );
|
|
MTH3D_M_vSetVectorElements ( a8_stPoint+7, -m_fX/2.f , -m_fY/2.f , m_fZ/2.f );
|
|
fn_vSetListOfPoints(8,a8_stPoint);
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITBox3D::CommonITBox3D()
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : set texture vertices of ITBox3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void ITBox3D::CommonITBox3D()
|
|
{
|
|
|
|
CreateITBox3D();
|
|
|
|
ACP_tdxHandleOfElement hElement = fn_hCreateElementIndexedTriangle(12,4);
|
|
|
|
/////////////////////
|
|
|
|
ACP_tdst2DUVValues q1 = { 0.f, 0.f};
|
|
ACP_tdst2DUVValues q2 = { 1.f, 0.f};
|
|
ACP_tdst2DUVValues q3 = { 0.f, 1.f};
|
|
ACP_tdst2DUVValues q4 = { 1.f, 1.f};
|
|
|
|
GEO_vSetUVOfIndexedTriangles(GetStruct(), hElement, 0, &q1);
|
|
GEO_vSetUVOfIndexedTriangles(GetStruct(), hElement, 1, &q2);
|
|
GEO_vSetUVOfIndexedTriangles(GetStruct(), hElement, 2, &q3);
|
|
GEO_vSetUVOfIndexedTriangles(GetStruct(), hElement, 3, &q4);
|
|
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 0, 0, 1, 3);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 0, 0, 1, 2);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 1, 1, 2, 3);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 1, 1, 3, 2);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 2, 4, 5, 1);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 2, 0, 2, 1);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 3, 1, 0, 4);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 3, 3, 0, 1);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 4, 1, 5, 6);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 4, 1 ,0, 2);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 5, 1, 6, 2);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 5, 1, 2, 3);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 6, 3, 2, 6);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 6, 1, 3, 2);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 7, 6, 7, 3);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 7, 2, 0, 1);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 8, 0, 3, 7);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 8, 1, 3, 2);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 9, 7, 4, 0);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 9, 2, 0, 1);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 10, 4, 7, 5);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 10, 1, 3, 0);
|
|
//
|
|
fn_eSetIndexedTriangle ( hElement, 11, 6, 5, 7);
|
|
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, 11, 2, 0, 3);
|
|
//
|
|
|
|
|
|
///////////////////////
|
|
|
|
EndCreate();
|
|
}
|
|
|
|
ACP_tdxHandleOfElement ITBox3D::GetHElement()
|
|
{
|
|
return m_hElement;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITBox3D::_OnLButtonDblClk
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : launch the modal dialog
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL ITBox3D::_OnLButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)
|
|
{
|
|
HINSTANCE hOldInst = AfxGetResourceHandle();
|
|
AfxSetResourceHandle ( ((CPA_DLLBase*)(GetEditor()))->GetDLLIdentity()->hModule );
|
|
|
|
CDlgITBox dlg(m_fX , m_fY , m_fZ , this);
|
|
BOOL retval = dlg.DoModal() == IDOK;
|
|
|
|
AfxSetResourceHandle(hOldInst);
|
|
return retval;
|
|
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITBox3D::_OnMouseMove
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : adjust the box size according to the mouse input
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL ITBox3D::_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)
|
|
{
|
|
SetScaleX (m_fXold*NewRadius/m_fGlobal);
|
|
SetScaleY (m_fYold*NewRadius/m_fGlobal);
|
|
SetScaleZ (m_fZold*NewRadius/m_fGlobal);
|
|
|
|
}
|
|
else
|
|
{
|
|
m_fGlobal = NewRadius;
|
|
m_Flag = FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITBox3D::_OnLButtonDown
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : Init the resizing
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL ITBox3D::_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_fXold = m_fX;
|
|
m_fYold = m_fY;
|
|
m_fZold = m_fZ;
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
m_Flag = TRUE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
void ITBox3D::SetScaleX(float fScale)
|
|
{
|
|
m_fX = fScale;
|
|
CreateITBox3D();
|
|
}
|
|
void ITBox3D::SetScaleY(float fScale)
|
|
{
|
|
m_fY = fScale;
|
|
CreateITBox3D();
|
|
}
|
|
void ITBox3D::SetScaleZ(float fScale)
|
|
{
|
|
m_fZ = fScale;
|
|
CreateITBox3D();
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : SetScaleXYZ
|
|
// Date : 98- 01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description :
|
|
// Author : Cristian Stegaru - CPA2
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void ITBox3D::SetScaleXYZ (float fXScale, float fYScale, float fZScale)
|
|
{
|
|
m_fX = fXScale;
|
|
m_fY = fYScale;
|
|
m_fZ = fZScale;
|
|
CreateITBox3D();
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : mfn_vLoad
|
|
// Date : 98-01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description :
|
|
// Author : Cristian Stegaru - CPA2
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void ITBox3D::mfn_vLoad (CString csEPOFile, CString csEPOName)
|
|
{
|
|
Shape3D::mfn_vLoad (csEPOFile, csEPOName);
|
|
char szX [NB_LENGTH], szY [NB_LENGTH], szZ [NB_LENGTH];
|
|
BOOL bReadOK = GetPrivateProfileString (csEPOName, "X", NULL, szX, NB_LENGTH, csEPOFile);
|
|
float fXScale = (float)atof (szX);
|
|
bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "Y", NULL, szY, NB_LENGTH, csEPOFile);
|
|
float fYScale = (float)atof (szY);
|
|
bReadOK = bReadOK && GetPrivateProfileString (csEPOName, "Z", NULL, szZ, NB_LENGTH, csEPOFile);
|
|
float fZScale = (float)atof (szZ);
|
|
ASSERT (bReadOK);
|
|
SetScaleXYZ (fXScale, fYScale, fZScale);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : mfn_vSave
|
|
// Date : 98-01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description :
|
|
// Author : Cristian Stegaru - CPA2
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void ITBox3D::mfn_vSave (CString csEPOFile, CString csEPOName, int iIdx)
|
|
{
|
|
Shape3D::mfn_vSave (csEPOFile, csEPOName, iIdx);
|
|
char szX [NB_LENGTH], szY [NB_LENGTH], szZ [NB_LENGTH];
|
|
_gcvt (m_fX, 4, szX);
|
|
BOOL bWriteOK = WritePrivateProfileString (csEPOName, "X", szX, csEPOFile);
|
|
_gcvt (m_fY, 4, szY);
|
|
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "Y", szY, csEPOFile);
|
|
_gcvt (m_fZ, 4, szZ);
|
|
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "Z", szZ, csEPOFile);
|
|
ASSERT (bWriteOK);
|
|
}
|
|
|
|
|
|
//------------------------------------------ ITBoxUndo ---------------------------------------------
|
|
#define M_RedrawWorld() (((DEV_MultiDevice*)g_oFrameGest.ma_p_oWinArray[2][2]->GetActiveView())->DrawObject())
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITBoxUndo::ITBoxUndo
|
|
// Date : 98.01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : Init the undo data
|
|
// Author : N Suparatu
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
ITBoxUndo::ITBoxUndo(ITBox3D *box) : CPA_Modif(0, "Set Box Parameters", FALSE)
|
|
{
|
|
m_pBox = box;
|
|
m_fX = box->m_fX;
|
|
m_fY = box->m_fY;
|
|
m_fZ = box->m_fZ;
|
|
m_bFirst = TRUE;
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITBoxUndo::Undo
|
|
// Date : 98.01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : Undo box parameters
|
|
// Author : N Suparatu
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
BOOL ITBoxUndo::Undo()
|
|
{
|
|
m_bFirst = FALSE;
|
|
float x = m_pBox->m_fX;
|
|
float y = m_pBox->m_fY;
|
|
float z = m_pBox->m_fZ;
|
|
m_pBox->SetScaleX(m_fX);
|
|
m_pBox->SetScaleY(m_fY);
|
|
m_pBox->SetScaleZ(m_fZ);
|
|
m_fX = x;
|
|
m_fY = y;
|
|
m_fZ = z;
|
|
m_pBox->fn_vNotifySaveObject();
|
|
M_RedrawWorld();
|
|
return TRUE;
|
|
}
|
|
|