428 lines
16 KiB
C++
428 lines
16 KiB
C++
//ROMTEAM WorldEditor
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
// File : ITSphere3D.cpp: implementation of the ITSphere3D 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
|
|
#ifndef CPA_WANTS_IMPORT
|
|
#define CPA_WANTS_IMPORT
|
|
#endif
|
|
|
|
#include "3dinterf.hpp"
|
|
#include "DlgITSphere.h"
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::ITSphere3D
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : constructor to create a new object
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ITSphere3D::ITSphere3D (CPA_EditorBase *_p_oEditor,float radius /* = 1.f */ , const CString _csName , tdeSaveStatus _eStatus )
|
|
:ParamSurface3D(TRUE, _p_oEditor, 1, 1, _csName , _eStatus)
|
|
{
|
|
CommonITSphere3D (radius , 10, 10);
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::ITSphere3D
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : constructor to create a new object
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
ITSphere3D::ITSphere3D (CPA_EditorBase *_p_oEditor,float radius /* = 1.f */, int ns, int nt, const CString _csName , tdeSaveStatus _eStatus )
|
|
:ParamSurface3D(TRUE, _p_oEditor, 1, 1, _csName , _eStatus)
|
|
{
|
|
CommonITSphere3D (radius , ns, nt);
|
|
}
|
|
|
|
//Sphere parametrisation
|
|
|
|
#define PI 3.14159265359f
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::x
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : set x coordonates of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
float ITSphere3D::x(float s, float t)
|
|
{
|
|
float s0 = -PI/2 + s*PI;
|
|
float t0 = t*2*PI;
|
|
return (float)(m_fRadius*cos(s0)*cos(t0));
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::y
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : set y coordonates of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
float ITSphere3D::y(float s, float t)
|
|
{
|
|
float s0 = -PI/2 + s*PI;
|
|
float t0 = t*2*PI;
|
|
return (float)(m_fRadius*cos(s0)*sin(t0));
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::z
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : set z coordonates of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
float ITSphere3D::z(float s, float t)
|
|
{
|
|
float s0 = -PI/2 + s*PI;
|
|
return (float)(-m_fRadius*sin(s0));
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::CommonITSphere3D
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : construct of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void ITSphere3D::CommonITSphere3D( float radius, int ns, int nt)
|
|
{
|
|
m_fRadius = radius;
|
|
m_Ns = ns;
|
|
m_Nt = nt;
|
|
m_hElement = NewElement(0, m_Ns, m_Nt);
|
|
}
|
|
|
|
ITSphere3D::~ITSphere3D()
|
|
{
|
|
|
|
}
|
|
|
|
ACP_tdxHandleOfElement ITSphere3D::GetHElement()
|
|
{
|
|
return m_hElement;
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::SetRadius
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : SetRadius of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL ITSphere3D::SetRadius(GLI_tdxValue Radius)
|
|
{
|
|
if(Radius<0.1) Radius = (float)0.1;
|
|
m_fRadius = Radius;
|
|
NewElement(m_hElement, m_Ns, m_Nt);
|
|
return TRUE;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::GetRadius()
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : return radius of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
GLI_tdxValue ITSphere3D::GetRadius()
|
|
{
|
|
return m_fRadius;
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::SetSamplingRate
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : set sampling rate of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void ITSphere3D::SetSamplingRate(int Ns, int Nt)
|
|
{
|
|
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;
|
|
NewElement(m_hElement, m_Ns, m_Nt);
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : ITSphere3D::GetSamplingRate
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : return sampling rate of ITSphere3D
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void ITSphere3D::GetSamplingRate(int &Ns, int &Nt)
|
|
{
|
|
Nt = m_Nt;
|
|
Ns = m_Ns;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITSphere3D::_OnLButtonDblClk
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : launch the modal dialog
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL ITSphere3D::_OnLButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo)
|
|
{
|
|
HINSTANCE hOldInst = AfxGetResourceHandle();
|
|
AfxSetResourceHandle ( ((CPA_DLLBase*)(GetEditor()))->GetDLLIdentity()->hModule );
|
|
|
|
CDlgITSphere dlg(m_fRadius,m_Ns, m_Nt, this);
|
|
BOOL retval = dlg.DoModal() == IDOK;
|
|
|
|
AfxSetResourceHandle(hOldInst);
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITSphere3D::_OnMouseMove
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : adjust the sphere size according to the mouse input
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
BOOL ITSphere3D::_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);
|
|
SetRadius (NewRadius);
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITSphere3D::_OnLButtonDown
|
|
// Date : 97.11
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : Init the resizing
|
|
// Author : Ionut Grozea
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
BOOL ITSphere3D::_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);
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : mfn_vLoad
|
|
// Date : 98-01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description :
|
|
// Author : Cristian Stegaru - CPA2
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void ITSphere3D::mfn_vLoad (CString csEPOFile, CString csEPOName)
|
|
{
|
|
Shape3D::mfn_vLoad (csEPOFile, csEPOName);
|
|
char szRadius [NB_LENGTH], szNs [NB_LENGTH], szNt [NB_LENGTH];
|
|
BOOL bReadOK = GetPrivateProfileString (csEPOName, "RADIUS", NULL, szRadius, NB_LENGTH, csEPOFile);
|
|
float fRadius = (float)atof (szRadius);
|
|
SetRadius (fRadius);
|
|
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);
|
|
SetSamplingRate (iNs, iNt);
|
|
ASSERT (bReadOK);
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method : mfn_vSave
|
|
// Date : 98-01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description :
|
|
// Author : Cristian Stegaru - CPA2
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void ITSphere3D::mfn_vSave (CString csEPOFile, CString csEPOName, int iIdx)
|
|
{
|
|
Shape3D::mfn_vSave (csEPOFile, csEPOName, iIdx);
|
|
char szRadius [NB_LENGTH], szNs [NB_LENGTH], szNt [NB_LENGTH];
|
|
itoa (m_Ns, szNs, 10);
|
|
BOOL bWriteOK = WritePrivateProfileString (csEPOName, "NS", szNs, csEPOFile);
|
|
itoa (m_Nt, szNt, 10);
|
|
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "NT", szNt, csEPOFile);
|
|
_gcvt (m_fRadius, 4, szRadius);
|
|
bWriteOK = bWriteOK && WritePrivateProfileString (csEPOName, "RADIUS", szRadius, csEPOFile);
|
|
ASSERT (bWriteOK);
|
|
}
|
|
|
|
|
|
//------------------------------------------ ITSphereUndo ---------------------------------------------
|
|
#define M_RedrawWorld() (((DEV_MultiDevice*)g_oFrameGest.ma_p_oWinArray[2][2]->GetActiveView())->DrawObject())
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITSphereUndo::ITSphereUndo
|
|
// Date : 98.01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : Init the undo data
|
|
// Author : N Suparatu
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
ITSphereUndo::ITSphereUndo(ITSphere3D *sphere) : CPA_Modif(0, "Set Sphere Parameters", FALSE)
|
|
{
|
|
m_pSphere = sphere;
|
|
m_fRadius = m_pSphere->GetRadius();
|
|
m_pSphere->GetSamplingRate(m_Ns, m_Nt);
|
|
m_bFirst = TRUE;
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Method :ITSphereUndo::Undo
|
|
// Date : 98.01
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Description : undo sphere parameters
|
|
// Author : N Suparatu
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Modification :
|
|
// Date :
|
|
// By :
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
BOOL ITSphereUndo::Undo()
|
|
{
|
|
m_bFirst = FALSE;
|
|
float r = m_pSphere->GetRadius();
|
|
int s, t;
|
|
m_pSphere->GetSamplingRate(s, t);
|
|
m_pSphere->SetRadius(m_fRadius);
|
|
m_pSphere->SetSamplingRate(m_Ns, m_Nt);
|
|
m_fRadius = r;
|
|
m_Ns = s;
|
|
m_Nt = t;
|
|
m_pSphere->fn_vNotifySaveObject();
|
|
M_RedrawWorld();
|
|
return TRUE;
|
|
}
|
|
|
|
|