Add rayman2 source files
This commit is contained in:
217
Rayman_X/cpa/tempgrp/OGD/src/Paramsurface3D.cpp
Normal file
217
Rayman_X/cpa/tempgrp/OGD/src/Paramsurface3D.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
//ROMTEAM WorldEditor
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// File : ParamSurface3D.cpp: implementation of the ParamSurface3Dclass.
|
||||
// Author : Viorel Preoteasa
|
||||
// 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
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Method : Construction/Destruction of ParamSurface3D
|
||||
// Date : 97-11
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Description :
|
||||
// Author : Viorel Preoteasa - CPA2
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Modification :
|
||||
// Date :
|
||||
// By :
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ParamSurface3D::ParamSurface3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, ACP_tdxIndex xNbPoints, ACP_tdxIndex xNbElements, const CString _csName, tdeSaveStatus _eStatus)
|
||||
: Shape3D (bModifiable, _p_oEditor, xNbPoints, xNbElements, _csName, _eStatus)
|
||||
{
|
||||
CommonParamSurface3D();
|
||||
}
|
||||
|
||||
ParamSurface3D::ParamSurface3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, ACP_tdxIndex xNbPoints, ACP_tdxIndex xNbElements, CPA_BaseObject *_p_oOwnerFile, const CString _csName, char *_p_cRefPath, tdeSaveStatus _eStatus)
|
||||
: Shape3D(bModifiable, _p_oEditor, xNbPoints, xNbElements, _p_oOwnerFile, _csName, _p_cRefPath, _eStatus)
|
||||
{
|
||||
CommonParamSurface3D();
|
||||
}
|
||||
|
||||
ParamSurface3D::ParamSurface3D (BOOL bModifiable, CPA_EditorBase *_p_oEditor, CPA_BaseObject *_p_oOwnerFile, ACP_tdxHandleOfObject _hObject, const CString _csName, char *_p_cRefPath, tdeSaveStatus _eStatus)
|
||||
: Shape3D (bModifiable, _p_oEditor, _p_oOwnerFile, _hObject, _csName, _p_cRefPath, _eStatus)
|
||||
{
|
||||
CommonParamSurface3D();
|
||||
}
|
||||
|
||||
ParamSurface3D::~ParamSurface3D()
|
||||
{
|
||||
if(GetStruct()->d_stListOfPoints) free(GetStruct()->d_stListOfPoints);
|
||||
if(GetStruct()->d_stListOfPointsNormals) free(GetStruct()->d_stListOfPointsNormals);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Method : ParamSurface3D
|
||||
// Date : 97-11
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Description : Common initialisation
|
||||
// Author : Viorel Preoteasa - CPA2
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Modification :
|
||||
// Date :
|
||||
// By :
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void ParamSurface3D::CommonParamSurface3D()
|
||||
{
|
||||
m_IndexTriangleNb = 0;
|
||||
GetStruct()->xNbPoints = 0;
|
||||
GetStruct()->d_stListOfPoints = NULL;
|
||||
GetStruct()->d_stListOfPointsNormals = NULL;
|
||||
//ROMTEAM WorldEditor (Cristian Stegaru 12/97)
|
||||
m_bFirstInit = TRUE;
|
||||
//ENDROMTEAM WorldEditor (Cristian Stegaru)
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Method : Dist
|
||||
// Date : 97-11
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Description : the distance between two points.
|
||||
// Author : Viorel Preoteasa - CPA2
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Modification :
|
||||
// Date :
|
||||
// By :
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
float ParamSurface3D::Dist(MTH3D_tdstVector &a, MTH3D_tdstVector &b)
|
||||
{
|
||||
return (float)(fabs(a.xX-b.xX)+fabs(a.xY-b.xY)+fabs(a.xZ-b.xZ));
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Method : NewElement
|
||||
// Date : 97-11
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Description : calculation of object points and triangles from parametrisation.
|
||||
// Author : Viorel Preoteasa - CPA2
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Modification :
|
||||
// Date :
|
||||
// By :
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ACP_tdxHandleOfElement ParamSurface3D::NewElement(ACP_tdxHandleOfElement hElement, int ns, int nt)
|
||||
{
|
||||
int i,j,k,l,m, Nb_T;
|
||||
float t, s, ds, dt;
|
||||
float s0=0, s1=1, t0=0, t1=1;
|
||||
GEO_tdstGeometricObject *U = GetStruct();
|
||||
|
||||
GMT_tdxHandleToGameMaterial hMaterial=NULL;
|
||||
|
||||
MTH3D_tdstVector *stPoint = (MTH3D_tdstVector *)malloc(ns*nt*sizeof(MTH3D_tdstVector));
|
||||
int *Pos = (int *)malloc(ns*nt*sizeof(int));
|
||||
int *New_Point = (int *)malloc(ns*nt*sizeof(int));
|
||||
|
||||
ds = (s1-s0)/(ns-1);
|
||||
dt = (t1-t0)/(nt-1);
|
||||
s = s0;
|
||||
for(i=0, k=0, m=0; i<ns; i++)
|
||||
{
|
||||
t = t0;
|
||||
for(j=0; j<nt; j++)
|
||||
{
|
||||
MTH3D_M_vSetVectorElements ( stPoint+k, x(s, t), y(s, t), z(s, t));
|
||||
for(l=0; Dist(stPoint[l], stPoint[k])>0.00001; l++);
|
||||
if(l==k)
|
||||
{
|
||||
New_Point[m] = k;
|
||||
Pos[k] = m;
|
||||
m++;
|
||||
}
|
||||
else
|
||||
Pos[k] = Pos[l];
|
||||
|
||||
t += dt;
|
||||
k++;
|
||||
}
|
||||
s += ds;
|
||||
}
|
||||
|
||||
for(i=0, k=0, Nb_T=0; i<ns-1; i++)
|
||||
for(j=0; j<nt-1; j++)
|
||||
{
|
||||
if((Pos[i*nt+j+1]!=Pos[i*nt+j]) && (Pos[i*nt+j]!=Pos[(i+1)*nt+j]) && (Pos[(i+1)*nt+j]!=Pos[i*nt+j+1]))Nb_T++;
|
||||
if((Pos[(i+1)*nt+j+1]!=Pos[i*nt+j+1]) && (Pos[i*nt+j+1]!=Pos[(i+1)*nt+j]) && (Pos[(i+1)*nt+j]!=Pos[(i+1)*nt+j+1]))Nb_T++;
|
||||
}
|
||||
|
||||
if(m != U->xNbPoints)
|
||||
{
|
||||
if(U->d_stListOfPoints) free(U->d_stListOfPoints);
|
||||
U->d_stListOfPoints = (MTH3D_tdstVector *)malloc(m*sizeof(MTH3D_tdstVector));
|
||||
memset(U->d_stListOfPoints, 0, m*sizeof(MTH3D_tdstVector));
|
||||
}
|
||||
if(U->d_xListOfElementsTypes[0])
|
||||
GEO_vGetGameMaterialOfIndexedTriangles (GetStruct(), hElement , &hMaterial);
|
||||
if((m != U->xNbPoints) || (m_IndexTriangleNb!=Nb_T))
|
||||
{
|
||||
U->d_stListOfElements[0] = NULL;
|
||||
U->d_xListOfElementsTypes[0] = NULL;
|
||||
//ROMTEAM WorldEditor (Cristian Stegaru 12/97)
|
||||
if (m_bFirstInit)
|
||||
{
|
||||
m_bFirstInit = FALSE;
|
||||
hElement = fn_hCreateElementIndexedTriangle(Nb_T, m);
|
||||
}
|
||||
else
|
||||
{
|
||||
GEO_vCreateElementIndexedTriangles (GetStruct(), &hElement, Nb_T, m);
|
||||
// default mat<61>rial
|
||||
fn_vSetEngineGameMaterial(hElement,0, fn_hGetDefaultGameMaterial() );
|
||||
}
|
||||
|
||||
//ENDROMTEAM WorldEditor (Cristian Stegaru)
|
||||
U->xNbPoints = m;
|
||||
m_IndexTriangleNb = Nb_T;
|
||||
}
|
||||
|
||||
for(i=0; i<m; i++)
|
||||
{
|
||||
MTH3D_M_vSetVectorElements (stPoint+i, stPoint[New_Point[i]].xX, stPoint[New_Point[i]].xY, stPoint[New_Point[i]].xZ);
|
||||
ACP_tdst2DUVValues q = { ds*(New_Point[i]/nt), dt*(New_Point[i]%nt) };
|
||||
GEO_vSetUVOfIndexedTriangles(GetStruct(), hElement, i, &q);
|
||||
}
|
||||
|
||||
fn_vSetListOfPoints(m, stPoint);
|
||||
|
||||
for(i=0, k=0; i<ns-1; i++)
|
||||
for(j=0; j<nt-1; j++)
|
||||
{
|
||||
if((Pos[i*nt+j+1]!=Pos[i*nt+j]) && (Pos[i*nt+j]!=Pos[(i+1)*nt+j]) && (Pos[(i+1)*nt+j]!=Pos[i*nt+j+1]))
|
||||
{
|
||||
fn_eSetIndexedTriangle ( hElement, k, Pos[i*nt+j+1], Pos[i*nt+j], Pos[(i+1)*nt+j]);
|
||||
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, k, Pos[i*nt+j+1], Pos[i*nt+j], Pos[(i+1)*nt+j]);
|
||||
k++;
|
||||
}
|
||||
if((Pos[(i+1)*nt+j+1]!=Pos[i*nt+j+1]) && (Pos[i*nt+j+1]!=Pos[(i+1)*nt+j]) && (Pos[(i+1)*nt+j]!=Pos[(i+1)*nt+j+1]))
|
||||
{
|
||||
fn_eSetIndexedTriangle ( hElement, k, Pos[(i+1)*nt+j+1], Pos[i*nt+j+1], Pos[(i+1)*nt+j]);
|
||||
GEO_vSetIndexedUVOfFaceOfIndexedTriangles( GetStruct(), hElement, k, Pos[(i+1)*nt+j+1], Pos[i*nt+j+1], Pos[(i+1)*nt+j]);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
free(stPoint);
|
||||
free(Pos);
|
||||
free(New_Point);
|
||||
if(hMaterial)
|
||||
GEO_vSetGameMaterialOfIndexedTriangles (GetStruct(), hElement , hMaterial);
|
||||
EndCreate();
|
||||
return hElement;
|
||||
}
|
Reference in New Issue
Block a user