www.pudn.com > 3DmaxSLoader.rar > TriObject.cpp
// TriObject.cpp: implementation of the CTriObject class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "3DSLoader.h" #include "TriObject.h" #include#ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CTriObject::CTriObject() { x = y = z = nx = ny = nz = NULL; matfaces = faces = NULL; materials = NULL; numvertices = 0; numnormals = 0; numfaces = 0; nummatfacesapplied = 0; i = 0; nummaterials=0; pivot[0] = 0.0f; pivot[1] = 0.0f; pivot[2] = 0.0f; pivotrot[0] = 0.0f; pivotrot[1] = 0.0f; pivotrot[2] = 0.0f; pivotrot[3] = 0.0f; normalapplied = FALSE; materialsapplied = FALSE; } CTriObject::~CTriObject() { delete [] x; delete [] y; delete [] z; delete [] nx; delete [] ny; delete [] nz; delete [] faces; delete [] matfaces; delete [] materials; } void CTriObject::applyNormals() { if (numfaces == 0) return; delete [] nx; delete [] ny; delete [] nz; nx = new float[numfaces/3]; ny = new float[numfaces/3]; nz = new float[numfaces/3]; if( nx==NULL || ny==NULL || nz==NULL ) { delete [] nx; delete [] ny; delete [] nz; normalapplied = FALSE; return; } float normal[3]; for ( int i=0 ; i ambientColor[0]; materials[nummaterials-1].ambientColor[1] = _material->ambientColor[1]; materials[nummaterials-1].ambientColor[2] = _material->ambientColor[2]; materials[nummaterials-1].diffuseColor[0] = _material->diffuseColor[0]; materials[nummaterials-1].diffuseColor[1] = _material->diffuseColor[1]; materials[nummaterials-1].diffuseColor[2] = _material->diffuseColor[2]; materials[nummaterials-1].specularColor[0] = _material->specularColor[0]; materials[nummaterials-1].specularColor[1] = _material->specularColor[1]; materials[nummaterials-1].specularColor[2] = _material->specularColor[2]; materials[nummaterials-1].emissiveColor[0] = _material->emissiveColor[0]; materials[nummaterials-1].emissiveColor[1] = _material->emissiveColor[1]; materials[nummaterials-1].emissiveColor[2] = _material->emissiveColor[2]; materials[nummaterials-1].shininess = _material->shininess; materials[nummaterials-1].transparency = _material->transparency; materialsapplied = TRUE; return (nummaterials -1); } void CTriObject::setId(int _id) { id = _id; }